Esempio n. 1
0
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
Esempio n. 2
0
def RETURN_EVAL(next):
    app = stack.pop()

    oldapp = get_app()
    code = pop_frame()
    stack.push(app)
    return oldapp.setValue(code, app)
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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
Esempio n. 6
0
def PUSH_ARG(next, val):
    #print "Pushing arg", val, get_app().args
    stack.push(get_app().args[val])
    return next
Esempio n. 7
0
def ZAP_ARG(next, val):
    get_app().args[val] = Application(
        lookup(FakeFullyQualifId("Prelude", "_zap_arg")), [])
    return next
Esempio n. 8
0
def RETURN(next):
    val = stack.pop()
    app = get_app()
    code = pop_frame()
    stack.push(val)
    return app.setValue(code, val)
Esempio n. 9
0
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