#include "errors/errors.h" #include "errors/exceptions.h" #include "interpreter/contexts.h" #include "object.h" #include "operators/operands.h" #include "operators/operators.h" #include "resources/resources.h" #include "stacks.h" #include "types/attributes.h" #include "types/boolean.h" #include "types/composites/composites.h" #include "types/composites/load.h" #include "types/numbers/integer.h" #include "types/operator.h" static void resourcecontext_(void) { object * const operand = require(operandstack, booleantype); const object blame = pop(executionstack); const object Category = pop(dictionarystack); if (Category.type != dicttype) throw (typecheck); if (operand->boolean) { const object systemdict = bottomof(dictionarystack); assert(systemdict.type == dicttype); const object errorinformation = get[dicttype](string("$error"), systemdict); assert(errorinformation.type == dicttype); put[dicttype](string("command"), executable(blame), errorinformation); *operand = get[dicttype](string("Category"), Category); stop(); } else { clearto(operandstack, operand); } } const object resourcecontext = staticoperator("@resource", resourcecontext_); static void execute(const object category, const object entry) { const object Instances = get[dicttype](string("globalinstances"), resources); if (known(category, Instances) == 0) ; // find external resource const object Category = get[dicttype](category, Instances); const object procedure = get[dicttype](entry, Category); if (isfull(dictionarystack)) throw (dictionarystack->overflow); if (spaceon(executionstack) < 4) throw (executionstack->overflow); push(Category, dictionarystack); push(literal(exception.blame), executionstack); push(resourcecontext, executionstack); push(stoppedcontext, executionstack); push(procedure, executionstack); } static void defineresource_(void) { const object * const operand = require(operandstack, anytype, anytype, nametype); execute(operand[2], string("DefineResource")); clearto(operandstack, &operand[2]); } static void undefineresource_(void) { const object * const operand = require(operandstack, anytype, nametype); execute(operand[1], string("UndefineResource")); clearto(operandstack, &operand[1]); } static void findresource_(void) { const object * const operand = require(operandstack, anytype, nametype); execute(operand[1], string("FindResource")); clearto(operandstack, &operand[1]); } static void resourcestatus_(void) { const object * const operand = require(operandstack, anytype, nametype); execute(operand[1], string("ResourceStatus")); clearto(operandstack, &operand[1]); } static void resourceforall_(void) { const object * const operand = require(operandstack, stringtype, proctype, stringtype, nametype); execute(operand[3], string("ResourceForAll")); clearto(operandstack, &operand[3]); } const object ResourceOperators = staticarray(((object []){ staticoperator("defineresource", defineresource_), staticoperator("undefineresource", undefineresource_), staticoperator("findresource", findresource_), staticoperator("resourcestatus", resourcestatus_), staticoperator("resourceforall", resourceforall_) }));