1.1 --- a/generator.py Sat Nov 06 17:06:01 2021 +0100
1.2 +++ b/generator.py Sun Nov 07 01:18:51 2021 +0100
1.3 @@ -320,7 +320,11 @@
1.4 # Signature: __attr <name>(...);
1.5
1.6 parameters = self.importer.function_parameters[path]
1.7 - l = ["__attr"] * (len(parameters) + 1)
1.8 +
1.9 + # Include the stack parameter and context plus the original
1.10 + # parameters.
1.11 +
1.12 + l = ["__attr"] * (len(parameters) + 2)
1.13 print >>f_signatures, "__attr %s(%s);" % (encode_function_pointer(path), ", ".join(l))
1.14
1.15 # Generate parameter table size data.
1.16 @@ -1244,9 +1248,9 @@
1.17
1.18 if path == self.int_type:
1.19 print >>f_code, """\
1.20 -__attr %s(__attr __self, __attr number_or_string, __attr base)
1.21 +__attr %s(__attr __stack, __attr __self, __attr number_or_string, __attr base)
1.22 {
1.23 - return __fn___builtins___int_new_int(__NULL, number_or_string, base);
1.24 + return __fn___builtins___int_new_int(__stack, __NULL, number_or_string, base);
1.25 }
1.26 """ % (
1.27 encode_instantiator_pointer(path),
1.28 @@ -1259,9 +1263,9 @@
1.29
1.30 elif path == self.string_type:
1.31 print >>f_code, """\
1.32 -__attr %s(__attr __self, __attr obj)
1.33 +__attr %s(__attr __stack, __attr __self, __attr obj)
1.34 {
1.35 - return __fn___builtins___str_new_str(__NULL, obj);
1.36 + return __fn___builtins___str_new_str(__stack, __NULL, obj);
1.37 }
1.38 """ % (
1.39 encode_instantiator_pointer(path),
1.40 @@ -1271,9 +1275,9 @@
1.41
1.42 else:
1.43 print >>f_code, """\
1.44 -__attr %s(__attr __self%s)
1.45 +__attr %s(__attr __stack, __attr __self%s)
1.46 {
1.47 - return %s(__NEWINSTANCE(%s)%s);
1.48 + return %s(__stack, __NEWINSTANCE(%s)%s);
1.49 }
1.50 """ % (
1.51 encode_instantiator_pointer(path),
1.52 @@ -1283,9 +1287,9 @@
1.53 parameters and ", %s" % ", ".join(parameters) or ""
1.54 )
1.55
1.56 - # Signature: __new_typename(__attr __self, ...)
1.57 + # Signature: __new_typename(__attr __stack, __attr __self, ...)
1.58
1.59 - print >>f_signatures, "__attr %s(__attr __self%s);" % (
1.60 + print >>f_signatures, "__attr %s(__attr __stack, __attr __self%s);" % (
1.61 encode_instantiator_pointer(path),
1.62 l and ", %s" % ", ".join(l) or ""
1.63 )
1.64 @@ -1302,6 +1306,7 @@
1.65 print >>f_code, """\
1.66 int main(int argc, char *argv[])
1.67 {
1.68 + __attr __stack = (__attr) {.stack=0};
1.69 __exc __tmp_exc;
1.70
1.71 GC_INIT();
1.72 @@ -1311,17 +1316,20 @@
1.73 __Try
1.74 {"""
1.75
1.76 + # Write a main function invocation for all but the native modules.
1.77 +
1.78 for name in self.importer.order_modules():
1.79 - function_name = "__main_%s" % encode_path(name)
1.80 - print >>f_signatures, "void %s();" % function_name
1.81 -
1.82 - # Omit the native modules.
1.83 -
1.84 parts = name.split(".")
1.85
1.86 - if parts[0] != "native":
1.87 - print >>f_code, """\
1.88 - %s();""" % function_name
1.89 + if parts[0] == "native":
1.90 + continue
1.91 +
1.92 + function_name = "__main_%s" % encode_path(name)
1.93 + print >>f_signatures, "void %s(__attr __stack);" % function_name
1.94 + print >>f_code, """\
1.95 + %s(__stack);""" % function_name
1.96 +
1.97 + # Finish the main section with an exception handler.
1.98
1.99 print >>f_code, """\
1.100 }
1.101 @@ -1332,7 +1340,7 @@
1.102
1.103 fprintf(stderr, "Program terminated due to exception: %%s.\\n",
1.104 __load_via_object(
1.105 - __VALUE(%s(__NULL, __tmp_exc.arg)),
1.106 + __VALUE(%s(__stack, __NULL, __tmp_exc.arg)),
1.107 __data__).strvalue);
1.108 return 1;
1.109 }