diff --git a/lang/compile.py b/lang/compile.py index 03ebb5c..dbd98db 100755 --- a/lang/compile.py +++ b/lang/compile.py @@ -449,12 +449,12 @@ }\n\n""" return header -def generate_footer(): - footer = """ -\nstatic struct object_call calls[] = { - {.name = "MakeNumber", .handler = module_call, .priv = (void *)bytecode_MakeNumber}, - {.name = NULL, /* end */}}; - +def generate_footer(verbs): + footer = """\nstatic struct object_call calls[] = {\n""" + for verb in verbs: + footer += "\t" + verb + "\n" + footer += "\t{.name = NULL, /* end */}\n};" + footer += """\n static struct object_class module_class = { .cleanup = module_cleanup, .calls = &calls[0], @@ -480,17 +480,24 @@ output += "};" return output +def generate_call(node): + call = '{.name = "%s", .handler = module_call, ' % (node.name) + call += '.priv = (void *)bytecode_%s},' % (node.name) + return call + def generate_c_file(ir, source): output = generate_header(source) + verbs = [] for node in ir: next = None if isinstance(node, IRFunction): next = generate_bytecode(node) + verbs.append(generate_call(node)) if next is None: print("Can't generate node: %s" % (node)) return None output += next - footer = generate_footer() + footer = generate_footer(verbs) if footer is None: print("Can't generate footer") return None