def PRIMITIVE(next): name = get_app().func.consts[0].item #print stack #print get_app().args assert hasattr(primitives, name), "Primitive %s not yet implemented" % (name, ) stack.push(getattr(primitives, name)(*(get_app().args))) return next
def RETURN_EVAL(next): app = stack.pop() oldapp = get_app() code = pop_frame() stack.push(app) return oldapp.setValue(code, app)
def PUSH_CONST(next, val): const = get_app().func.consts[val] if hasattr(const, "module"): const = lookup(const) stack.push(Application(const, [])) else: stack.push(Value(const)) return next
def MK_AP(next, val): func = lookup(get_app().func.consts[val]) if isinstance(func, tuple): func = func[1] if len(stack) < func.arity: raise SystemError, "MK_AP tried to pop %i arguments from a stack with %i elements for function %s. Stack contents = %s" % ( func.arity, len(stack), str(func), str(stack)) args = [stack.pop() for x in range(func.arity)] stack.push(Application(func, args)) return next
def MK_PAP(next, val, arity): #print lookup(get_app().func.consts[val]) args = [stack.pop() for x in range(arity)] stack.push(Application(lookup(get_app().func.consts[val]), args)) return next
def PUSH_ARG(next, val): #print "Pushing arg", val, get_app().args stack.push(get_app().args[val]) return next
def ZAP_ARG(next, val): get_app().args[val] = Application( lookup(FakeFullyQualifId("Prelude", "_zap_arg")), []) return next
def RETURN(next): val = stack.pop() app = get_app() code = pop_frame() stack.push(val) return app.setValue(code, val)
def MK_CON(next, val): func = lookup(get_app().func.consts[val]) args = [stack.pop() for x in range(func.arity)] app = Application(func, args) stack.push(app) return next