Пример #1
0
def function_lit(*args, **kwargs):
    if len(args) == 1:
        extra_statics = {}
        code, = args
        argument_type = local_type = no_value_type()
        break_types = infer_all()
        local_initializer = nop()
    elif len(args) == 2:
        extra_statics = {}
        argument_type, code = args
        local_type = no_value_type()
        break_types = infer_all()
        local_initializer = nop()
    elif len(args) == 3:
        extra_statics = {}
        argument_type, break_types, code = args
        local_type = no_value_type()
        local_initializer = nop()
    elif len(args) == 5:
        extra_statics = {}
        argument_type, break_types, local_type, local_initializer, code = args
    elif len(args) == 6:
        extra_statics, argument_type, break_types, local_type, local_initializer, code = args
    else:
        raise FatalError()

    check_is_opcode(local_initializer)
    check_is_opcode(argument_type)
    check_is_opcode(local_type)
    check_is_opcode(code)
    if not isinstance(break_types, dict):
        raise FatalError()

    static = spread_dict(
        {
            "argument": argument_type,
            "local": local_type,
            "outer": inferred_type(),
            "break_types": object_template_op(break_types)
        }, extra_statics)

    func = spread_dict(
        {
            "code": code,
            "static": object_template_op(static),
            "local_initializer": local_initializer
        }, **kwargs)

    return PythonObject(func)
Пример #2
0
def loop_op(opcode, **kwargs):
    check_is_opcode(opcode)
    return PythonObject(spread_dict({
        "opcode": "loop",
        "code": opcode
    }, **kwargs),
                        debug_reason="code")
Пример #3
0
def static_op(expression, **kwargs):
    check_is_opcode(expression)
    return PythonObject(spread_dict({
        "opcode": "static",
        "code": expression
    }, **kwargs),
                        debug_reason="code")
Пример #4
0
def prepare_op(function_expression, **kwargs):
    check_is_opcode(function_expression)
    return PythonObject(spread_dict(
        {
            "opcode": "prepare",
            "code": function_expression
        }, **kwargs),
                        debug_reason="code")
Пример #5
0
def dynamic_dereference_op(reference, **kwargs):
    if not isinstance(reference, basestring):
        raise FatalError()
    return PythonObject(spread_dict(
        {
            "opcode": "dynamic_dereference",
            "reference": reference
        }, **kwargs),
                        debug_reason="code")
Пример #6
0
def unbound_dereference(name, **kwargs):
    if not isinstance(name, basestring):
        raise FatalError()
    return PythonObject(spread_dict(
        {
            "opcode": "unbound_dereference",
            "reference": name
        }, **kwargs),
                        debug_reason="code")
Пример #7
0
def shift_op(code, restart_type, **kwargs):
    check_is_opcode(code)
    check_is_opcode(restart_type)
    return PythonObject(spread_dict(
        {
            "opcode": "shift",
            "code": code,
            "restart_type": restart_type
        }, **kwargs),
                        debug_reason="code")
Пример #8
0
def is_op(expression, type, **kwargs):
    check_is_opcode(expression)
    check_is_opcode(type)
    return PythonObject(spread_dict(
        {
            "opcode": "is",
            "expression": expression,
            "type": type
        }, **kwargs),
                        debug_reason="code")
Пример #9
0
def close_op(function, context, **kwargs):
    check_is_opcode(function)
    check_is_opcode(context)
    return PythonObject(spread_dict(
        {
            "opcode": "close",
            "function": function,
            "outer_context": context
        }, **kwargs),
                        debug_reason="code")
Пример #10
0
def dereference_op(of, reference, safe, **kwargs):
    check_is_opcode(of)
    check_is_opcode(reference)
    return PythonObject(spread_dict(
        {
            "opcode": "dereference",
            "of": of,
            "reference": reference,
            "safe": safe
        }, **kwargs),
                        debug_reason="code")
Пример #11
0
def assignment_op(of, reference, rvalue, **kwargs):
    check_is_opcode(of)
    check_is_opcode(reference)
    check_is_opcode(rvalue)
    return PythonObject(spread_dict(
        {
            "opcode": "assignment",
            "of": of,
            "reference": reference,
            "rvalue": rvalue
        }, **kwargs),
                        debug_reason="code")
Пример #12
0
def invoke_op(function_expression, argument_expression=None, **kwargs):
    if "line" not in kwargs:
        pass
    if argument_expression is None:
        argument_expression = nop()
    check_is_opcode(function_expression)
    check_is_opcode(argument_expression)
    return PythonObject(spread_dict(
        {
            "opcode": "invoke",
            "function": function_expression,
            "argument": argument_expression
        }, kwargs),
                        debug_reason="code")
Пример #13
0
def compile_ast_function_def(function_creator_ast, open_function_id, dependencies):
    ast.fix_missing_locations(function_creator_ast)

#    print "--- {} ---".format(open_function_id)
#    print to_source(function_creator_ast)

    function_creator = compile(function_creator_ast, "<string>", "exec")

    function_creation_context = spread_dict(
        dependencies, default_globals()
    )

    exec(function_creator, function_creation_context, function_creation_context)

    return function_creation_context[open_function_id]
Пример #14
0
def object_template_op(values, debug_reason="code", **kwargs):
    values_list = []

    for k, v in values.items():
        check_is_opcode(v)
        if isinstance(k, basestring):
            k = literal_op(k)

        values_list.append(PythonList([k, v]))

    return PythonObject(spread_dict(
        {
            "opcode": "template",
            "opcodes": PythonList(values_list, debug_reason=debug_reason)
        }, **kwargs),
                        debug_reason=debug_reason)
Пример #15
0
def reset_op(*args, **kwargs):
    if len(args) == 1:
        code, = args
        function = argument = None
        check_is_opcode(code)
    if len(args) == 2:
        code = None
        function, argument = args
        check_is_opcode(function)
        check_is_opcode(argument)

    result = {"opcode": "reset"}

    if code:
        result["code"] = code
    if function and argument:
        result["function"] = function
        result["argument"] = argument

    return PythonObject(spread_dict(result, **kwargs), debug_reason="code")
Пример #16
0
def transform_op(*args, **kwargs):
    if len(args) == 1:
        output, = args
        input = code = None
    elif len(args) == 3:
        input, output, code = args
    else:
        raise FatalError()
    if code:
        check_is_opcode(code)
    if input and not isinstance(input, basestring):
        raise FatalError()
    if not isinstance(output, basestring):
        raise FatalError()
    op = {
        "opcode": "transform",
        "output": output,
    }
    if input:
        op["input"] = input
        op["code"] = code
    return PythonObject(spread_dict(op, **kwargs), debug_reason="code")
Пример #17
0
def context_op(**kwargs):
    return PythonObject(spread_dict({
        "opcode": "context",
    }, **kwargs),
                        debug_reason="code")