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)
def loop_op(opcode, **kwargs): check_is_opcode(opcode) return PythonObject(spread_dict({ "opcode": "loop", "code": opcode }, **kwargs), debug_reason="code")
def static_op(expression, **kwargs): check_is_opcode(expression) return PythonObject(spread_dict({ "opcode": "static", "code": expression }, **kwargs), debug_reason="code")
def prepare_op(function_expression, **kwargs): check_is_opcode(function_expression) return PythonObject(spread_dict( { "opcode": "prepare", "code": function_expression }, **kwargs), debug_reason="code")
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")
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")
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")
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")
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")
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")
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")
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")
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]
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)
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")
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")
def context_op(**kwargs): return PythonObject(spread_dict({ "opcode": "context", }, **kwargs), debug_reason="code")