# HG changeset patch # User Paul Boddie # Date 1477765034 -7200 # Node ID b682af24443c8d000bbacda35e4a87d17c04943d # Parent abfbc8b8f4718e5c196e985c2ab4b6b17cba561d Added missing main function, fixed instantiators to invoke initialisers. diff -r abfbc8b8f471 -r b682af24443c generator.py --- a/generator.py Sat Oct 29 00:48:27 2016 +0200 +++ b/generator.py Sat Oct 29 20:17:14 2016 +0200 @@ -309,6 +309,10 @@ for value, n in self.optimiser.constants.items(): self.make_literal_constant(f_decls, f_defs, n, value) + # Finish the main source file. + + self.write_main_program(f_code, f_signatures) + # Output more boilerplate. print >>f_consts, """\ @@ -813,7 +817,7 @@ __attr %s(__attr __args[]) { __args[0] = __new(&%s, &%s, sizeof(%s)); - %s + %s(__args); return __args[0]; } """ % ( @@ -822,6 +826,33 @@ encode_function_pointer(init_ref.get_origin()) ) + def write_main_program(self, f_code, f_signatures): + + """ + Write the main program to 'f_code', invoking the program's modules. Also + write declarations for module main functions to 'f_signatures'. + """ + + print >>f_code, """\ +int main(int argc, char *argv[]) +{""" + + for name in self.importer.modules.keys(): + function_name = "__main_%s" % encode_path(name) + print >>f_signatures, "void %s();" % function_name + + # Emit the main module's function last. + + if name != "__main__": + print >>f_code, """\ + %s();""" % function_name + + print >>f_code, """\ + __main___main__(); + return 0; +} +""" + def encode_size(table_type, path=None): return "__%ssize%s" % (table_type, path and "_%s" % encode_path(path) or "") diff -r abfbc8b8f471 -r b682af24443c templates/Makefile --- a/templates/Makefile Sat Oct 29 00:48:27 2016 +0200 +++ b/templates/Makefile Sat Oct 29 20:17:14 2016 +0200 @@ -1,4 +1,4 @@ -SRC = exceptions.c progops.c progtypes.c ops.c $(wildcard src/*.c) +SRC = exceptions.c main.c ops.c progops.c progtypes.c $(wildcard src/*.c) OBJ = $(SRC:.c=.o) CFLAGS = -I.