diff --git a/lang/compile.py b/lang/compile.py index 59474e7..d146404 100755 --- a/lang/compile.py +++ b/lang/compile.py @@ -966,53 +966,22 @@ return "\n\nstatic const unsigned char bytecode_%s_%s [] = {%s};" \ % (node.class_, node.name, c_bytecode) -def generate_class_boilerplate(): - return """static struct object_class CLASSNAME_class; - -static Object CLASSNAME_create(VmState state, Object use_modules) { - Object obj = object_create(state, &CLASSNAME_class, sizeof(Object)); - Object *args = (Object *)object_priv(state, obj, &CLASSNAME_class); - *args = use_modules; - return obj; -} - -static void CLASSNAME_cleanup(VmState state, Object obj) { - Object *args = (Object *)object_priv(state, obj, &CLASSNAME_class); - object_drop(state, args); -}""" - def generate_class_call(class_name, func_name, index): - call = '{.name = "%s", .handler = CLASSNAME_call_bytecode, .priv = %s },\n\t' % (func_name, index) - return call - -def generate_module_class_call(class_name, func_name, index): call = '{.name = "%s", .bytecode_index = %s },\n\t' % (func_name, index) return call def generate_class_structs(class_ir): calls = "" - module_calls = "" bytecodes = "" index = 0 for func in class_ir.functions: calls += generate_class_call(class_ir.name, func, index) - module_calls += generate_module_class_call(class_ir.name, func, index) bytecodes += "bytecode_%s_%s,\n\t" % (class_ir.name, func) index += 1 return """static const unsigned char *CLASSNAME_bytecodes[] = { %sNULL, }; -static void CLASSNAME_call_bytecode(VmState state, Object obj, int priv) { - Object *args = (Object*)object_priv(state, obj, &CLASSNAME_class); - const unsigned char *bytecode = CLASSNAME_bytecodes[priv]; - bytecode_run(state, obj, bytecode, *args); -} - -static struct object_call CLASSNAME_calls[] = { - %s{.name = NULL, /* end */ }, -}; - static ModuleClassCall CLASSNAME_module_calls[] = { %s{.name = NULL, /* end */ }, }; @@ -1021,18 +990,11 @@ .fields_count = 0, .bytecodes = CLASSNAME_bytecodes, .calls = CLASSNAME_module_calls, -}; - -static struct object_class CLASSNAME_class = { - .cleanup = CLASSNAME_cleanup, - .calls = &CLASSNAME_calls[0], -};""" % (bytecodes, calls, module_calls) +};""" % (bytecodes, calls) def generate_c_class(class_ir): functions = [] - output = generate_class_boilerplate() - output += "\n\n" - output += generate_class_structs(class_ir) + output = generate_class_structs(class_ir) output = output.replace('CLASSNAME', class_ir.name) return output @@ -1056,9 +1018,8 @@ .name = "%s", .uses = module_uses, .classes = module_classes, - .create = %s_create, }; -""" % (uses, classes_, node.id, node.name, node.name) +""" % (uses, classes_, node.id, node.name) def generate_c_file(module_args, ir, source): metadata = ""