#include "assert.h" #include "commandline/parameters.h" #include "errors/errors.h" #include "errors/exceptions.h" #include "interpreter/parameters/actions.h" #include "interpreter/parameters/current.h" #include "interpreter/parameters/globalised.h" #include "interpreter/parameters/parameters.h" #include "memory/virtualmemory.h" #include "methods.h" #include "object.h" #include "stacks.h" #include "types/attributes.h" #include "types/boolean.h" #include "types/composites/composites.h" #include "types/composites/dictionary.h" #include "types/equality.h" #include "types/numbers/integer.h" #include "types/numbers/representations.h" #include "unix/operatingsystem.h" object interpreterparameter(const object entry, const object dictionary) { const object * const parameter = current(entry, dictionary); return parameter ? (parameter[value].type == arraytype ? readaction(parameter) : parameter[value]) : null; } object copied(object thing) { if (can(copy, thing)) { const natural length = (thing.type == dicttype) ? maxlength(thing) : thing.length; thing = copy[thing.type](thing, create[thing.type](length)); } return thing; } object globalised(object thing) { assert(vm.allocationmode); if (global(thing) == false) { if (thing.type == arraytype && gcheckarray(thing) == false) throw (VMerror); thing = copied(thing); } if (addressof(thing)) assert(global(thing)); return thing; } static object nullterminate(object string) { assert(string.type == stringtype); if (string.length) { assert(string.string); for (natural length = 0; length < string.length; ++length) { if (string.string[length] == '\0') { string.length = length; break; } } } return string; } boolean setinterpreterparameter(const object entry[const pair], const object dictionary) { object * const parameter = writevm(current(entry[key], dictionary)); if (parameter) { const object thing = (entry[value].type == stringtype) ? nullterminate(entry[value]) : entry[value]; const boolean previous = vm.allocationmode; vm.allocationmode = global((object){.type = arraytype, .array = parameter, .access = none}); if (parameter[value].type == arraytype) writeaction(thing, parameter); else if (thing.type == parameter[value].type) parameter[value] = vm.allocationmode ? globalised(thing) : copied(thing); else throw (typecheck); vm.allocationmode = previous; return true; } else { return false; } }