# HG changeset patch # User Paul Boddie # Date 1636244331 -3600 # Node ID 28b43ef743aebfd642116eb128fee97150c8338f # Parent c7bd72a6309b4e5a4f74f8b0f98110dc0aeef4e0 Introduced a value stack, currently unused, referenced by a function parameter alongside the ubiquitous context parameter. diff -r c7bd72a6309b -r 28b43ef743ae generator.py --- a/generator.py Sat Nov 06 17:06:01 2021 +0100 +++ b/generator.py Sun Nov 07 01:18:51 2021 +0100 @@ -320,7 +320,11 @@ # Signature: __attr (...); parameters = self.importer.function_parameters[path] - l = ["__attr"] * (len(parameters) + 1) + + # Include the stack parameter and context plus the original + # parameters. + + l = ["__attr"] * (len(parameters) + 2) print >>f_signatures, "__attr %s(%s);" % (encode_function_pointer(path), ", ".join(l)) # Generate parameter table size data. @@ -1244,9 +1248,9 @@ if path == self.int_type: print >>f_code, """\ -__attr %s(__attr __self, __attr number_or_string, __attr base) +__attr %s(__attr __stack, __attr __self, __attr number_or_string, __attr base) { - return __fn___builtins___int_new_int(__NULL, number_or_string, base); + return __fn___builtins___int_new_int(__stack, __NULL, number_or_string, base); } """ % ( encode_instantiator_pointer(path), @@ -1259,9 +1263,9 @@ elif path == self.string_type: print >>f_code, """\ -__attr %s(__attr __self, __attr obj) +__attr %s(__attr __stack, __attr __self, __attr obj) { - return __fn___builtins___str_new_str(__NULL, obj); + return __fn___builtins___str_new_str(__stack, __NULL, obj); } """ % ( encode_instantiator_pointer(path), @@ -1271,9 +1275,9 @@ else: print >>f_code, """\ -__attr %s(__attr __self%s) +__attr %s(__attr __stack, __attr __self%s) { - return %s(__NEWINSTANCE(%s)%s); + return %s(__stack, __NEWINSTANCE(%s)%s); } """ % ( encode_instantiator_pointer(path), @@ -1283,9 +1287,9 @@ parameters and ", %s" % ", ".join(parameters) or "" ) - # Signature: __new_typename(__attr __self, ...) + # Signature: __new_typename(__attr __stack, __attr __self, ...) - print >>f_signatures, "__attr %s(__attr __self%s);" % ( + print >>f_signatures, "__attr %s(__attr __stack, __attr __self%s);" % ( encode_instantiator_pointer(path), l and ", %s" % ", ".join(l) or "" ) @@ -1302,6 +1306,7 @@ print >>f_code, """\ int main(int argc, char *argv[]) { + __attr __stack = (__attr) {.stack=0}; __exc __tmp_exc; GC_INIT(); @@ -1311,17 +1316,20 @@ __Try {""" + # Write a main function invocation for all but the native modules. + for name in self.importer.order_modules(): - function_name = "__main_%s" % encode_path(name) - print >>f_signatures, "void %s();" % function_name - - # Omit the native modules. - parts = name.split(".") - if parts[0] != "native": - print >>f_code, """\ - %s();""" % function_name + if parts[0] == "native": + continue + + function_name = "__main_%s" % encode_path(name) + print >>f_signatures, "void %s(__attr __stack);" % function_name + print >>f_code, """\ + %s(__stack);""" % function_name + + # Finish the main section with an exception handler. print >>f_code, """\ } @@ -1332,7 +1340,7 @@ fprintf(stderr, "Program terminated due to exception: %%s.\\n", __load_via_object( - __VALUE(%s(__NULL, __tmp_exc.arg)), + __VALUE(%s(__stack, __NULL, __tmp_exc.arg)), __data__).strvalue); return 1; } diff -r c7bd72a6309b -r 28b43ef743ae templates/native/buffer.c --- a/templates/native/buffer.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/buffer.c Sun Nov 07 01:18:51 2021 +0100 @@ -26,7 +26,7 @@ #include "progtypes.h" #include "main.h" -__attr __fn_native_buffer_buffer_str(__attr __self, __attr _data) +__attr __fn_native_buffer_buffer_str(__attr __stack, __attr __self, __attr _data) { /* _data interpreted as buffer.__data__ */ __fragment *data = _data.seqvalue; diff -r c7bd72a6309b -r 28b43ef743ae templates/native/buffer.h --- a/templates/native/buffer.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/buffer.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for buffer operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,7 +23,7 @@ /* Buffer operations. */ -__attr __fn_native_buffer_buffer_str(__attr __self, __attr _data); +__attr __fn_native_buffer_buffer_str(__attr __stack, __attr __self, __attr _data); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/common.c --- a/templates/native/common.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/common.c Sun Nov 07 01:18:51 2021 +0100 @@ -26,7 +26,7 @@ /* Utility functions. */ -__attr __new_int(__int n) +__attr __new_int(__attr __stack, __int n) { /* Create a new int and set the trailing data. */ __attr attr = __NEWINSTANCEIM(__builtins___int_int); @@ -52,7 +52,7 @@ return attr; } -__attr __new_float(__float n) +__attr __new_float(__attr __stack, __float n) { /* Create a new float and set the trailing data. */ __attr attr = __NEWINSTANCEIM(__builtins___float_float); diff -r c7bd72a6309b -r 28b43ef743ae templates/native/common.h --- a/templates/native/common.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/common.h Sun Nov 07 01:18:51 2021 +0100 @@ -23,10 +23,10 @@ /* Utility functions. */ -__attr __new_int(__int n); +__attr __new_int(__attr __stack, __int n); __attr __new_str(char *s, __int size); __attr __new_list(__fragment *f); -__attr __new_float(__float n); +__attr __new_float(__attr __stack, __float n); __fragment *__fragment_append(__fragment *data, __attr value); #endif /* __NATIVE_COMMON_H__ */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/float.c --- a/templates/native/float.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/float.c Sun Nov 07 01:18:51 2021 +0100 @@ -65,54 +65,54 @@ /* Floating point operations. Exceptions are raised in the signal handler. */ -__attr __fn_native_float_float_add(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_add(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); __float j = __TOFLOAT(other); - return __new_float(i + j); + return __new_float(__stack, i + j); } -__attr __fn_native_float_float_sub(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_sub(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); __float j = __TOFLOAT(other); - return __new_float(i - j); + return __new_float(__stack, i - j); } -__attr __fn_native_float_float_mul(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_mul(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); __float j = __TOFLOAT(other); - return __new_float(i * j); + return __new_float(__stack, i * j); } -__attr __fn_native_float_float_div(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_div(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); __float j = __TOFLOAT(other); - return __new_float(i / j); + return __new_float(__stack, i / j); } -__attr __fn_native_float_float_mod(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_mod(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); __float j = __TOFLOAT(other); - return __new_float(fmod(i, j)); + return __new_float(__stack, fmod(i, j)); } -__attr __fn_native_float_float_neg(__attr __self, __attr self) +__attr __fn_native_float_float_neg(__attr __stack, __attr __self, __attr self) { /* self interpreted as float */ __float i = __TOFLOAT(self); - return __new_float(-i); + return __new_float(__stack, -i); } -__attr __fn_native_float_float_pow(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_pow(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); @@ -128,10 +128,10 @@ __raise_overflow_error(); /* Return the result. */ - return __new_float(result); + return __new_float(__stack, result); } -__attr __fn_native_float_float_le(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_le(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); @@ -141,7 +141,7 @@ return i <= j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_float_float_lt(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_lt(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); @@ -151,7 +151,7 @@ return i < j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_float_float_ge(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_ge(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); @@ -161,7 +161,7 @@ return i >= j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_float_float_gt(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_gt(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); @@ -171,7 +171,7 @@ return i > j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_float_float_eq(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_eq(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); @@ -181,7 +181,7 @@ return i == j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_float_float_ne(__attr __self, __attr self, __attr other) +__attr __fn_native_float_float_ne(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as float */ __float i = __TOFLOAT(self); @@ -191,7 +191,7 @@ return i != j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_float_float_str(__attr __self, __attr self) +__attr __fn_native_float_float_str(__attr __stack, __attr __self, __attr self) { /* self interpreted as float */ __float i = __TOFLOAT(self); @@ -200,13 +200,13 @@ return format_number(i, 64); } -__attr __fn_native_float_float_int(__attr __self, __attr self) +__attr __fn_native_float_float_int(__attr __stack, __attr __self, __attr self) { /* self interpreted as float */ __float i = __TOFLOAT(self); /* NOTE: Test for conversion failure. */ - return __new_int((int) i); + return __new_int(__stack, (int) i); } /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/float.h --- a/templates/native/float.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/float.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for floating point operations. -Copyright (C) 2018 Paul Boddie +Copyright (C) 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,23 +23,23 @@ /* Floating point operations. */ -__attr __fn_native_float_float_add(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_sub(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_mul(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_div(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_mod(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_neg(__attr __self, __attr self); -__attr __fn_native_float_float_pow(__attr __self, __attr self, __attr other); +__attr __fn_native_float_float_add(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_sub(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_mul(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_div(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_mod(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_neg(__attr __stack, __attr __self, __attr self); +__attr __fn_native_float_float_pow(__attr __stack, __attr __self, __attr self, __attr other); -__attr __fn_native_float_float_le(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_lt(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_ge(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_gt(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_eq(__attr __self, __attr self, __attr other); -__attr __fn_native_float_float_ne(__attr __self, __attr self, __attr other); +__attr __fn_native_float_float_le(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_lt(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_ge(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_gt(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_eq(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_float_float_ne(__attr __stack, __attr __self, __attr self, __attr other); -__attr __fn_native_float_float_str(__attr __self, __attr self); -__attr __fn_native_float_float_int(__attr __self, __attr self); +__attr __fn_native_float_float_str(__attr __stack, __attr __self, __attr self); +__attr __fn_native_float_float_int(__attr __stack, __attr __self, __attr self); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/iconv.c --- a/templates/native/iconv.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/iconv.c Sun Nov 07 01:18:51 2021 +0100 @@ -33,20 +33,20 @@ static void __raise_incomplete_sequence_error(__attr value, __attr arg) { #ifdef __HAVE_posix_iconv_IncompleteSequenceError - __Raise(__new_posix_iconv_IncompleteSequenceError(__NULL, value, arg)); + __Raise(__new_posix_iconv_IncompleteSequenceError(__NULL, __NULL, value, arg)); #endif /* __HAVE_posix_iconv_IncompleteSequenceError */ } static void __raise_invalid_sequence_error(__attr value, __attr arg) { #ifdef __HAVE_posix_iconv_InvalidSequenceError - __Raise(__new_posix_iconv_InvalidSequenceError(__NULL, value, arg)); + __Raise(__new_posix_iconv_InvalidSequenceError(__NULL, __NULL, value, arg)); #endif /* __HAVE_posix_iconv_InvalidSequenceError */ } /* Character set conversion. */ -__attr __fn_native_iconv_iconv(__attr __self, __attr cd, __attr state) +__attr __fn_native_iconv_iconv(__attr __stack, __attr __self, __attr cd, __attr state) { /* cd interpreted as iconv_t */ iconv_t c = (iconv_t) cd.datavalue; @@ -87,13 +87,13 @@ /* Mutate the state to indicate the next input buffer position. */ - f->attrs[1] = __new_int(start + remaining - inbytesleft); - f->attrs[2] = __new_int(inbytesleft); + f->attrs[1] = __new_int(__stack, start + remaining - inbytesleft); + f->attrs[2] = __new_int(__stack, inbytesleft); /* Incomplete sequence: raise the string in an OSError instead. */ if (errno == EINVAL) - __raise_incomplete_sequence_error(__new_int(errno), __new_str(resultbuf, outbytestotal)); + __raise_incomplete_sequence_error(__new_int(__stack, errno), __new_str(resultbuf, outbytestotal)); return __new_str(resultbuf, outbytestotal); } @@ -104,20 +104,20 @@ { resultbuf = __ALLOCATE(inbytesleft + 1, sizeof(char)); memcpy(resultbuf, inbuf, inbytesleft); - __raise_invalid_sequence_error(__new_int(errno), __new_str(resultbuf, inbytesleft)); + __raise_invalid_sequence_error(__new_int(__stack, errno), __new_str(resultbuf, inbytesleft)); } /* General failure. */ else - __raise_os_error(__new_int(errno), __builtins___none_None); + __raise_os_error(__new_int(__stack, errno), __builtins___none_None); /* Should never be reached: included to satisfy the compiler. */ return __builtins___none_None; } -__attr __fn_native_iconv_iconv_close(__attr __self, __attr cd) +__attr __fn_native_iconv_iconv_close(__attr __stack, __attr __self, __attr cd) { /* cd interpreted as iconv_t */ iconv_t c = (iconv_t) cd.datavalue; @@ -125,12 +125,12 @@ errno = 0; if (iconv_close(c) == -1) - __raise_os_error(__new_int(errno), __builtins___none_None); + __raise_os_error(__new_int(__stack, errno), __builtins___none_None); return __builtins___none_None; } -__attr __fn_native_iconv_iconv_open(__attr __self, __attr tocode, __attr fromcode) +__attr __fn_native_iconv_iconv_open(__attr __stack, __attr __self, __attr tocode, __attr fromcode) { /* tocode.__data__ interpreted as string */ char *t = __load_via_object(__VALUE(tocode), __data__).strvalue; @@ -143,7 +143,7 @@ result = iconv_open(t, f); if (result == (iconv_t) -1) - __raise_os_error(__new_int(errno), __builtins___none_None); + __raise_os_error(__new_int(__stack, errno), __builtins___none_None); /* Return the descriptor as an opaque value. */ @@ -151,7 +151,7 @@ return attr; } -__attr __fn_native_iconv_iconv_reset(__attr __self, __attr cd) +__attr __fn_native_iconv_iconv_reset(__attr __stack, __attr __self, __attr cd) { /* cd interpreted as iconv_t */ iconv_t c = (iconv_t) cd.datavalue; diff -r c7bd72a6309b -r 28b43ef743ae templates/native/iconv.h --- a/templates/native/iconv.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/iconv.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for character set conversion. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,10 +23,10 @@ /* Input/output. */ -__attr __fn_native_iconv_iconv(__attr __self, __attr cd, __attr state); -__attr __fn_native_iconv_iconv_close(__attr __self, __attr cd); -__attr __fn_native_iconv_iconv_open(__attr __self, __attr tocode, __attr fromcode); -__attr __fn_native_iconv_iconv_reset(__attr __self, __attr cd); +__attr __fn_native_iconv_iconv(__attr __stack, __attr __self, __attr cd, __attr state); +__attr __fn_native_iconv_iconv_close(__attr __stack, __attr __self, __attr cd); +__attr __fn_native_iconv_iconv_open(__attr __stack, __attr __self, __attr tocode, __attr fromcode); +__attr __fn_native_iconv_iconv_reset(__attr __stack, __attr __self, __attr cd); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/identity.c --- a/templates/native/identity.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/identity.c Sun Nov 07 01:18:51 2021 +0100 @@ -26,12 +26,12 @@ /* Identity testing. */ -__attr __fn_native_identity_is_(__attr __self, __attr x, __attr y) +__attr __fn_native_identity_is_(__attr __stack, __attr __self, __attr x, __attr y) { return x.value == y.value ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_identity_is_not(__attr __self, __attr x, __attr y) +__attr __fn_native_identity_is_not(__attr __stack, __attr __self, __attr x, __attr y) { return x.value != y.value ? __builtins___boolean_True : __builtins___boolean_False; } diff -r c7bd72a6309b -r 28b43ef743ae templates/native/identity.h --- a/templates/native/identity.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/identity.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for identity operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,8 +23,8 @@ /* Identity testing. */ -__attr __fn_native_identity_is_(__attr __self, __attr x, __attr y); -__attr __fn_native_identity_is_not(__attr __self, __attr x, __attr y); +__attr __fn_native_identity_is_(__attr __stack, __attr __self, __attr x, __attr y); +__attr __fn_native_identity_is_not(__attr __stack, __attr __self, __attr x, __attr y); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/int.c --- a/templates/native/int.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/int.c Sun Nov 07 01:18:51 2021 +0100 @@ -31,12 +31,12 @@ /* Integer operations. */ -__attr __fn_native_int_is_int(__attr __self, __attr obj) +__attr __fn_native_int_is_int(__attr __stack, __attr __self, __attr obj) { return __INTEGER(obj) ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_int_int_add(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_add(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -49,10 +49,10 @@ __raise_overflow_error(); /* Return the new integer. */ - return __new_int(i + j); + return __new_int(__stack, i + j); } -__attr __fn_native_int_int_sub(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_sub(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -65,10 +65,10 @@ __raise_overflow_error(); /* Return the new integer. */ - return __new_int(i - j); + return __new_int(__stack, i - j); } -__attr __fn_native_int_int_mul(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_mul(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -83,10 +83,10 @@ __raise_overflow_error(); /* Return the new integer. */ - return __new_int(i * j); + return __new_int(__stack, i * j); } -__attr __fn_native_int_int_div(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_div(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -99,10 +99,10 @@ __raise_overflow_error(); /* Return the new integer. */ - return __new_int(i / j); + return __new_int(__stack, i / j); } -__attr __fn_native_int_int_mod(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_mod(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -115,10 +115,10 @@ __raise_overflow_error(); /* Return the new integer. */ - return __new_int(i % j); + return __new_int(__stack, i % j); } -__attr __fn_native_int_int_neg(__attr __self, __attr self) +__attr __fn_native_int_int_neg(__attr __stack, __attr __self, __attr self) { /* self interpreted as int */ __int i = __TOINT(self); @@ -128,10 +128,10 @@ __raise_overflow_error(); /* Return the new integer. */ - return __new_int(-i); + return __new_int(__stack, -i); } -__attr __fn_native_int_int_pow(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_pow(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -151,10 +151,10 @@ __raise_overflow_error(); /* Return the new integer. */ - return __new_int(k); + return __new_int(__stack, k); } -__attr __fn_native_int_int_and(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_and(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -162,19 +162,19 @@ /* Return the new integer. */ /* NOTE: No overflow test applied. */ - return __new_int(i & j); + return __new_int(__stack, i & j); } -__attr __fn_native_int_int_not(__attr __self, __attr self) +__attr __fn_native_int_int_not(__attr __stack, __attr __self, __attr self) { /* self interpreted as int */ __int i = __TOINT(self); /* Return the new integer. */ - return __new_int(~i); + return __new_int(__stack, ~i); } -__attr __fn_native_int_int_or(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_or(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -182,10 +182,10 @@ /* Return the new integer. */ /* NOTE: No overflow test applied. */ - return __new_int(i | j); + return __new_int(__stack, i | j); } -__attr __fn_native_int_int_xor(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_xor(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -193,10 +193,10 @@ /* Return the new integer. */ /* NOTE: No overflow test applied. */ - return __new_int(i ^ j); + return __new_int(__stack, i ^ j); } -__attr __fn_native_int_int_lshift(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_lshift(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -204,10 +204,10 @@ /* Return the new integer. */ /* NOTE: No overflow test applied. */ - return __new_int(i << j); + return __new_int(__stack, i << j); } -__attr __fn_native_int_int_rshift(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_rshift(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -215,10 +215,10 @@ /* Return the new integer. */ /* NOTE: No overflow test applied. */ - return __new_int(i >> j); + return __new_int(__stack, i >> j); } -__attr __fn_native_int_int_le(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_le(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -228,7 +228,7 @@ return i <= j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_int_int_lt(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_lt(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -238,7 +238,7 @@ return i < j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_int_int_ge(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_ge(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -248,7 +248,7 @@ return i >= j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_int_int_gt(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_gt(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -258,7 +258,7 @@ return i > j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_int_int_eq(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_eq(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -268,7 +268,7 @@ return i == j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_int_int_ne(__attr __self, __attr self, __attr other) +__attr __fn_native_int_int_ne(__attr __stack, __attr __self, __attr self, __attr other) { /* self and other interpreted as int */ __int i = __TOINT(self); @@ -278,7 +278,7 @@ return i != j ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_int_int_str(__attr __self, __attr self) +__attr __fn_native_int_int_str(__attr __stack, __attr __self, __attr self) { /* self interpreted as int */ __int i = __TOINT(self); @@ -294,12 +294,12 @@ return __new_str(s, strlen(s)); } -__attr __fn_native_int_int_float(__attr __self, __attr self) +__attr __fn_native_int_int_float(__attr __stack, __attr __self, __attr self) { /* self interpreted as int */ int i = __TOINT(self); - return __new_float((double) i); + return __new_float(__stack, (double) i); } /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/int.h --- a/templates/native/int.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/int.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for integer operations. -Copyright (C) 2016, 2017, 2018 Paul Boddie +Copyright (C) 2016, 2017, 2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,32 +23,32 @@ /* Integer operations. */ -__attr __fn_native_int_is_int(__attr __self, __attr obj); -__attr __fn_native_int_int_add(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_sub(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_mul(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_div(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_mod(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_neg(__attr __self, __attr _data); -__attr __fn_native_int_int_pow(__attr __self, __attr _data, __attr other); +__attr __fn_native_int_is_int(__attr __stack, __attr __self, __attr obj); +__attr __fn_native_int_int_add(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_sub(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_mul(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_div(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_mod(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_neg(__attr __stack, __attr __self, __attr _data); +__attr __fn_native_int_int_pow(__attr __stack, __attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_and(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_not(__attr __self, __attr _data); -__attr __fn_native_int_int_or(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_xor(__attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_and(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_not(__attr __stack, __attr __self, __attr _data); +__attr __fn_native_int_int_or(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_xor(__attr __stack, __attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_lshift(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_rshift(__attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_lshift(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_rshift(__attr __stack, __attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_eq(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_ge(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_gt(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_le(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_lt(__attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_ne(__attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_eq(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_ge(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_gt(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_le(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_lt(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_int_int_ne(__attr __stack, __attr __self, __attr _data, __attr other); -__attr __fn_native_int_int_str(__attr __self, __attr _data); -__attr __fn_native_int_int_float(__attr __self, __attr _data); +__attr __fn_native_int_int_str(__attr __stack, __attr __self, __attr _data); +__attr __fn_native_int_int_float(__attr __stack, __attr __self, __attr _data); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/introspection.c --- a/templates/native/introspection.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/introspection.c Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for introspection operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -26,7 +26,7 @@ /* Introspection. */ -__attr __fn_native_introspection_object_getattr(__attr __self, __attr obj, __attr name, __attr _default) +__attr __fn_native_introspection_object_getattr(__attr __stack, __attr __self, __attr obj, __attr name, __attr _default) { /* name interpreted as string */ __attr key = __load_via_object(__VALUE(name), __key__); @@ -54,7 +54,7 @@ return out; } -__attr __fn_native_introspection_isinstance(__attr __self, __attr obj, __attr cls) +__attr __fn_native_introspection_isinstance(__attr __stack, __attr __self, __attr obj, __attr cls) { /* cls must be a class. */ if (__is_instance_subclass(__VALUE(obj), cls)) @@ -63,7 +63,7 @@ return __builtins___boolean_False; } -__attr __fn_native_introspection_issubclass(__attr __self, __attr obj, __attr cls) +__attr __fn_native_introspection_issubclass(__attr __stack, __attr __self, __attr obj, __attr cls) { /* obj and cls must be classes. */ if (__is_subclass(__VALUE(obj), cls)) diff -r c7bd72a6309b -r 28b43ef743ae templates/native/introspection.h --- a/templates/native/introspection.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/introspection.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for introspection. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,9 +23,9 @@ /* Introspection. */ -__attr __fn_native_introspection_object_getattr(__attr __self, __attr obj, __attr name, __attr _default); -__attr __fn_native_introspection_isinstance(__attr __self, __attr obj, __attr cls); -__attr __fn_native_introspection_issubclass(__attr __self, __attr obj, __attr cls); +__attr __fn_native_introspection_object_getattr(__attr __stack, __attr __self, __attr obj, __attr name, __attr _default); +__attr __fn_native_introspection_isinstance(__attr __stack, __attr __self, __attr obj, __attr cls); +__attr __fn_native_introspection_issubclass(__attr __stack, __attr __self, __attr obj, __attr cls); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/io.c --- a/templates/native/io.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/io.c Sun Nov 07 01:18:51 2021 +0100 @@ -31,31 +31,31 @@ /* Input/output. */ -__attr __fn_native_io_fclose(__attr __self, __attr fp) +__attr __fn_native_io_fclose(__attr __stack, __attr __self, __attr fp) { /* fp interpreted as FILE reference */ FILE *f = (FILE *) fp.datavalue; errno = 0; if (fclose(f)) - __raise_io_error(__new_int(errno)); + __raise_io_error(__new_int(__stack, errno)); return __builtins___none_None; } -__attr __fn_native_io_fflush(__attr __self, __attr fp) +__attr __fn_native_io_fflush(__attr __stack, __attr __self, __attr fp) { /* fp interpreted as FILE reference */ FILE *f = (FILE *) fp.datavalue; errno = 0; if (fflush(f)) - __raise_io_error(__new_int(errno)); + __raise_io_error(__new_int(__stack, errno)); return __builtins___none_None; } -__attr __fn_native_io_fopen(__attr __self, __attr filename, __attr mode) +__attr __fn_native_io_fopen(__attr __stack, __attr __self, __attr filename, __attr mode) { /* filename.__data__ interpreted as string */ char *fn = __load_via_object(__VALUE(filename), __data__).strvalue; @@ -70,7 +70,7 @@ /* Produce an exception if the operation failed. */ if (f == NULL) - __raise_io_error(__new_int(errno)); + __raise_io_error(__new_int(__stack, errno)); /* Return the __data__ attribute. */ @@ -85,7 +85,7 @@ return __builtins___none_None; } -__attr __fn_native_io_fdopen(__attr __self, __attr fd, __attr mode) +__attr __fn_native_io_fdopen(__attr __stack, __attr __self, __attr fd, __attr mode) { /* fd interpreted as int */ int i = __TOINT(fd); @@ -100,7 +100,7 @@ /* Produce an exception if the operation failed. */ if (f == NULL) - __raise_io_error(__new_int(errno)); + __raise_io_error(__new_int(__stack, errno)); /* Return the __data__ attribute. */ @@ -115,7 +115,7 @@ return __builtins___none_None; } -__attr __fn_native_io_fread(__attr __self, __attr fp, __attr size) +__attr __fn_native_io_fread(__attr __stack, __attr __self, __attr fp, __attr size) { /* fp interpreted as FILE reference */ FILE *f = (FILE *) fp.datavalue; @@ -133,7 +133,7 @@ if (feof(f) && (have_read == 0)) __raise_eof_error(); else if ((error = ferror(f))) - __raise_io_error(__new_int(error)); + __raise_io_error(__new_int(__stack, error)); } /* Reserve space for a new string. */ @@ -143,7 +143,7 @@ return __new_str(s, have_read); } -__attr __fn_native_io_fwrite(__attr __self, __attr fp, __attr str) +__attr __fn_native_io_fwrite(__attr __stack, __attr __self, __attr fp, __attr str) { /* fp interpreted as FILE reference */ FILE *f = (FILE *) fp.datavalue; @@ -159,25 +159,25 @@ if (feof(f)) __raise_eof_error(); else if ((error = ferror(f))) - __raise_io_error(__new_int(error)); + __raise_io_error(__new_int(__stack, error)); } return __builtins___none_None; } -__attr __fn_native_io_close(__attr __self, __attr fd) +__attr __fn_native_io_close(__attr __stack, __attr __self, __attr fd) { /* fd interpreted as int */ int i = __TOINT(fd); errno = 0; if (close(i) == -1) - __raise_io_error(__new_int(errno)); + __raise_io_error(__new_int(__stack, errno)); return __builtins___none_None; } -__attr __fn_native_io_read(__attr __self, __attr fd, __attr n) +__attr __fn_native_io_read(__attr __stack, __attr __self, __attr fd, __attr n) { /* fd interpreted as int */ int i = __TOINT(fd); @@ -191,7 +191,7 @@ have_read = read(i, buf, to_read * sizeof(char)); if (have_read == -1) - __raise_io_error(__new_int(errno)); + __raise_io_error(__new_int(__stack, errno)); /* Reserve space for a new string. */ @@ -200,7 +200,7 @@ return __new_str(s, have_read); } -__attr __fn_native_io_write(__attr __self, __attr fd, __attr str) +__attr __fn_native_io_write(__attr __stack, __attr __self, __attr fd, __attr str) { /* fd interpreted as int */ int i = __TOINT(fd); @@ -214,9 +214,9 @@ have_written = write(i, s, sizeof(char) * size); if (have_written == -1) - __raise_io_error(__new_int(errno)); + __raise_io_error(__new_int(__stack, errno)); - return __new_int(have_written); + return __new_int(__stack, have_written); } /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/io.h --- a/templates/native/io.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/io.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for input/output. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,15 +23,15 @@ /* Input/output. */ -__attr __fn_native_io_fclose(__attr __self, __attr fp); -__attr __fn_native_io_fflush(__attr __self, __attr fp); -__attr __fn_native_io_fopen(__attr __self, __attr filename, __attr mode); -__attr __fn_native_io_fdopen(__attr __self, __attr fd, __attr mode); -__attr __fn_native_io_fread(__attr __self, __attr fp, __attr size); -__attr __fn_native_io_fwrite(__attr __self, __attr fp, __attr str); -__attr __fn_native_io_close(__attr __self, __attr fd); -__attr __fn_native_io_read(__attr __self, __attr fd, __attr n); -__attr __fn_native_io_write(__attr __self, __attr fd, __attr str); +__attr __fn_native_io_fclose(__attr __stack, __attr __self, __attr fp); +__attr __fn_native_io_fflush(__attr __stack, __attr __self, __attr fp); +__attr __fn_native_io_fopen(__attr __stack, __attr __self, __attr filename, __attr mode); +__attr __fn_native_io_fdopen(__attr __stack, __attr __self, __attr fd, __attr mode); +__attr __fn_native_io_fread(__attr __stack, __attr __self, __attr fp, __attr size); +__attr __fn_native_io_fwrite(__attr __stack, __attr __self, __attr fp, __attr str); +__attr __fn_native_io_close(__attr __stack, __attr __self, __attr fd); +__attr __fn_native_io_read(__attr __stack, __attr __self, __attr fd, __attr n); +__attr __fn_native_io_write(__attr __stack, __attr __self, __attr fd, __attr str); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/limits.c --- a/templates/native/limits.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/limits.c Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for limit definition. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -27,14 +27,16 @@ /* Limit definition. */ -__attr __fn_native_limits_get_maxint(__attr __self) +/* NOTE: Could have statically allocated limits. */ + +__attr __fn_native_limits_get_maxint(__attr __stack, __attr __self) { - return __new_int(__MAXINT); + return __new_int(__stack, __MAXINT); } -__attr __fn_native_limits_get_minint(__attr __self) +__attr __fn_native_limits_get_minint(__attr __stack, __attr __self) { - return __new_int(__MININT); + return __new_int(__stack, __MININT); } /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/limits.h --- a/templates/native/limits.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/limits.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for limit definition. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,8 +23,8 @@ /* Limit definition. */ -__attr __fn_native_limits_get_maxint(__attr __self); -__attr __fn_native_limits_get_minint(__attr __self); +__attr __fn_native_limits_get_maxint(__attr __stack, __attr __self); +__attr __fn_native_limits_get_minint(__attr __stack, __attr __self); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/list.c --- a/templates/native/list.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/list.c Sun Nov 07 01:18:51 2021 +0100 @@ -27,7 +27,7 @@ /* List operations. */ -__attr __fn_native_list_list_init(__attr __self, __attr size) +__attr __fn_native_list_list_init(__attr __stack, __attr __self, __attr size) { /* size interpreted as int */ __int n = __TOINT(size); @@ -37,7 +37,7 @@ return attr; } -__attr __fn_native_list_list_setsize(__attr __self, __attr _data, __attr size) +__attr __fn_native_list_list_setsize(__attr __stack, __attr __self, __attr _data, __attr size) { /* _data interpreted as list.__data__ */ __fragment *data = _data.seqvalue; @@ -48,7 +48,7 @@ return __builtins___none_None; } -__attr __fn_native_list_list_append(__attr __self, __attr self, __attr value) +__attr __fn_native_list_list_append(__attr __stack, __attr __self, __attr self, __attr value) { /* self.__data__ interpreted as list */ __fragment *data = __load_via_object(__VALUE(self), __data__).seqvalue; @@ -60,7 +60,7 @@ return __builtins___none_None; } -__attr __fn_native_list_list_concat(__attr __self, __attr self, __attr other) +__attr __fn_native_list_list_concat(__attr __stack, __attr __self, __attr self, __attr other) { /* self, interpreted as list, other interpreted as list.__data__ */ __fragment *data = __load_via_object(__VALUE(self), __data__).seqvalue; @@ -88,21 +88,21 @@ return __builtins___none_None; } -__attr __fn_native_list_list_len(__attr self, __attr _data) +__attr __fn_native_list_list_len(__attr __stack, __attr __self, __attr _data) { /* _data interpreted as list.__data__ */ __int size = _data.seqvalue->size; /* Return the new integer. */ - return __new_int(size); + return __new_int(__stack, size); } -__attr __fn_native_list_list_nonempty(__attr __self, __attr _data) +__attr __fn_native_list_list_nonempty(__attr __stack, __attr __self, __attr _data) { return _data.seqvalue->size ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_list_list_element(__attr __self, __attr _data, __attr index) +__attr __fn_native_list_list_element(__attr __stack, __attr __self, __attr _data, __attr index) { /* _data interpreted as list.__data__ */ __attr *elements = _data.seqvalue->attrs; @@ -112,7 +112,7 @@ return elements[i]; } -__attr __fn_native_list_list_setelement(__attr __self, __attr _data, __attr index, __attr value) +__attr __fn_native_list_list_setelement(__attr __stack, __attr __self, __attr _data, __attr index, __attr value) { /* _data interpreted as list.__data__ */ __attr *elements = _data.seqvalue->attrs; diff -r c7bd72a6309b -r 28b43ef743ae templates/native/list.h --- a/templates/native/list.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/list.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for list operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,14 +23,14 @@ /* List operations. */ -__attr __fn_native_list_list_init(__attr __self, __attr size); -__attr __fn_native_list_list_setsize(__attr __self, __attr _data, __attr size); -__attr __fn_native_list_list_append(__attr __self, __attr self, __attr value); -__attr __fn_native_list_list_concat(__attr __self, __attr self, __attr other); -__attr __fn_native_list_list_len(__attr self, __attr _data); -__attr __fn_native_list_list_nonempty(__attr __self, __attr _data); -__attr __fn_native_list_list_element(__attr __self, __attr _data, __attr index); -__attr __fn_native_list_list_setelement(__attr __self, __attr _data, __attr index, __attr value); +__attr __fn_native_list_list_init(__attr __stack, __attr __self, __attr size); +__attr __fn_native_list_list_setsize(__attr __stack, __attr __self, __attr _data, __attr size); +__attr __fn_native_list_list_append(__attr __stack, __attr __self, __attr self, __attr value); +__attr __fn_native_list_list_concat(__attr __stack, __attr __self, __attr self, __attr other); +__attr __fn_native_list_list_len(__attr __stack, __attr __self, __attr _data); +__attr __fn_native_list_list_nonempty(__attr __stack, __attr __self, __attr _data); +__attr __fn_native_list_list_element(__attr __stack, __attr __self, __attr _data, __attr index); +__attr __fn_native_list_list_setelement(__attr __stack, __attr __self, __attr _data, __attr index, __attr value); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/locale.c --- a/templates/native/locale.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/locale.c Sun Nov 07 01:18:51 2021 +0100 @@ -29,7 +29,7 @@ /* Locales. */ -__attr __fn_native_locale_getlocale(__attr __self, __attr category) +__attr __fn_native_locale_getlocale(__attr __stack, __attr __self, __attr category) { /* category interpreted as int */ int cat = __TOINT(category); @@ -48,7 +48,7 @@ return __new_str(result, length); } -__attr __fn_native_locale_setlocale(__attr __self, __attr category, __attr value) +__attr __fn_native_locale_setlocale(__attr __stack, __attr __self, __attr category, __attr value) { /* category interpreted as int */ int cat = __TOINT(category); diff -r c7bd72a6309b -r 28b43ef743ae templates/native/locale.h --- a/templates/native/locale.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/locale.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for locale handling. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,8 +23,8 @@ /* Input/output. */ -__attr __fn_native_locale_getlocale(__attr __self, __attr category); -__attr __fn_native_locale_setlocale(__attr __self, __attr category, __attr value); +__attr __fn_native_locale_getlocale(__attr __stack, __attr __self, __attr category); +__attr __fn_native_locale_setlocale(__attr __stack, __attr __self, __attr category, __attr value); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/program.c --- a/templates/native/program.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/program.c Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for program operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -26,7 +26,7 @@ /* Method binding. */ -__attr __fn_native_program_get_using(__attr __self, __attr callable, __attr instance) +__attr __fn_native_program_get_using(__attr __stack, __attr __self, __attr callable, __attr instance) { return __test_context(instance, callable); } diff -r c7bd72a6309b -r 28b43ef743ae templates/native/program.h --- a/templates/native/program.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/program.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for program operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -21,7 +21,7 @@ /* Method binding. */ -__attr __fn_native_program_get_using(__attr __self, __attr callable, __attr instance); +__attr __fn_native_program_get_using(__attr __stack, __attr __self, __attr callable, __attr instance); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/str.c --- a/templates/native/str.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/str.c Sun Nov 07 01:18:51 2021 +0100 @@ -28,7 +28,7 @@ /* String operations. */ -__attr __fn_native_str_str_add(__attr __self, __attr _data, __attr other, __attr _size, __attr othersize) +__attr __fn_native_str_str_add(__attr __stack, __attr __self, __attr _data, __attr other, __attr _size, __attr othersize) { /* _data, other interpreted as string.__data__ */ char *s = _data.strvalue; @@ -45,7 +45,7 @@ return __new_str(r, n); } -__attr __fn_native_str_str_chr(__attr __self, __attr _data) +__attr __fn_native_str_str_chr(__attr __stack, __attr __self, __attr _data) { /* data interpreted as int */ int n = __TOINT(_data); @@ -55,7 +55,7 @@ return __new_str(s, 1); } -__attr __fn_native_str_str_lt(__attr __self, __attr _data, __attr other) +__attr __fn_native_str_str_lt(__attr __stack, __attr __self, __attr _data, __attr other) { /* _data, other interpreted as string.__data__ */ char *s = _data.strvalue; @@ -65,7 +65,7 @@ return strcmp(s, o) < 0 ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_str_str_gt(__attr __self, __attr _data, __attr other) +__attr __fn_native_str_str_gt(__attr __stack, __attr __self, __attr _data, __attr other) { /* _data, other interpreted as string.__data__ */ char *s = _data.strvalue; @@ -75,7 +75,7 @@ return strcmp(s, o) > 0 ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_str_str_eq(__attr __self, __attr _data, __attr other) +__attr __fn_native_str_str_eq(__attr __stack, __attr __self, __attr _data, __attr other) { /* _data, other interpreted as string.__data__ */ char *s = _data.strvalue; @@ -85,20 +85,20 @@ return strcmp(s, o) == 0 ? __builtins___boolean_True : __builtins___boolean_False; } -__attr __fn_native_str_str_ord(__attr __self, __attr _data) +__attr __fn_native_str_str_ord(__attr __stack, __attr __self, __attr _data) { /* _data interpreted as string.__data__ */ char *s = _data.strvalue; - return __new_int((__int) s[0]); + return __new_int(__stack, (__int) s[0]); } -__attr __fn_native_str_str_size(__attr __self, __attr _size) +__attr __fn_native_str_str_size(__attr __stack, __attr __self, __attr _size) { - return __new_int(_size.sizevalue); + return __new_int(__stack, _size.sizevalue); } -__attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step) +__attr __fn_native_str_str_substr(__attr __stack, __attr __self, __attr _data, __attr start, __attr end, __attr step) { /* _data interpreted as string.__data__ */ char *s = _data.strvalue, *sub; diff -r c7bd72a6309b -r 28b43ef743ae templates/native/str.h --- a/templates/native/str.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/str.h Sun Nov 07 01:18:51 2021 +0100 @@ -21,14 +21,14 @@ /* String operations. */ -__attr __fn_native_str_str_add(__attr __self, __attr _data, __attr other, __attr _size, __attr othersize); -__attr __fn_native_str_str_chr(__attr __self, __attr _data); -__attr __fn_native_str_str_lt(__attr __self, __attr _data, __attr other); -__attr __fn_native_str_str_gt(__attr __self, __attr _data, __attr other); -__attr __fn_native_str_str_eq(__attr __self, __attr _data, __attr other); -__attr __fn_native_str_str_ord(__attr __self, __attr _data); -__attr __fn_native_str_str_size(__attr __self); -__attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step); +__attr __fn_native_str_str_add(__attr __stack, __attr __self, __attr _data, __attr other, __attr _size, __attr othersize); +__attr __fn_native_str_str_chr(__attr __stack, __attr __self, __attr _data); +__attr __fn_native_str_str_lt(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_str_str_gt(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_str_str_eq(__attr __stack, __attr __self, __attr _data, __attr other); +__attr __fn_native_str_str_ord(__attr __stack, __attr __self, __attr _data); +__attr __fn_native_str_str_size(__attr __stack, __attr __self); +__attr __fn_native_str_str_substr(__attr __stack, __attr __self, __attr _data, __attr start, __attr end, __attr step); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/system.c --- a/templates/native/system.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/system.c Sun Nov 07 01:18:51 2021 +0100 @@ -27,19 +27,19 @@ /* Environment support. */ -__attr __fn_native_system_exit(__attr __self, __attr status) +__attr __fn_native_system_exit(__attr __stack, __attr __self, __attr status) { exit(__TOINT(status)); return __builtins___none_None; } -__attr __fn_native_system_get_argv(__attr __self) +__attr __fn_native_system_get_argv(__attr __stack, __attr __self) { /* NOTE: To be written. */ return __builtins___none_None; } -__attr __fn_native_system_get_path(__attr __self) +__attr __fn_native_system_get_path(__attr __stack, __attr __self) { /* NOTE: To be written. */ return __builtins___none_None; diff -r c7bd72a6309b -r 28b43ef743ae templates/native/system.h --- a/templates/native/system.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/system.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for system operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,9 +23,9 @@ /* Environment support. */ -__attr __fn_native_system_exit(__attr __self, __attr status); -__attr __fn_native_system_get_argv(__attr __self); -__attr __fn_native_system_get_path(__attr __self); +__attr __fn_native_system_exit(__attr __stack, __attr __self, __attr status); +__attr __fn_native_system_get_argv(__attr __stack, __attr __self); +__attr __fn_native_system_get_path(__attr __stack, __attr __self); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/tuple.c --- a/templates/native/tuple.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/tuple.c Sun Nov 07 01:18:51 2021 +0100 @@ -29,7 +29,7 @@ static __fragment __empty_fragment = {.size=0, .capacity=0}; -__attr __fn_native_tuple_tuple_init(__attr __self, __attr size) +__attr __fn_native_tuple_tuple_init(__attr __stack, __attr __self, __attr size) { /* size interpreted as int */ __int n = __TOINT(size); diff -r c7bd72a6309b -r 28b43ef743ae templates/native/tuple.h --- a/templates/native/tuple.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/tuple.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for tuple operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -23,7 +23,7 @@ /* List operations. */ -__attr __fn_native_tuple_tuple_init(__attr __self, __attr size); +__attr __fn_native_tuple_tuple_init(__attr __stack, __attr __self, __attr size); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/native/unicode.c --- a/templates/native/unicode.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/unicode.c Sun Nov 07 01:18:51 2021 +0100 @@ -69,7 +69,7 @@ /* Unicode operations. */ -__attr __fn_native_unicode_unicode_len(__attr __self, __attr _data, __attr _size) +__attr __fn_native_unicode_unicode_len(__attr __stack, __attr __self, __attr _data, __attr _size) { /* _data interpreted as string.__data__ */ char *s = _data.strvalue; @@ -82,10 +82,10 @@ c++; /* Return the new integer. */ - return __new_int(c); + return __new_int(__stack, c); } -__attr __fn_native_unicode_unicode_ord(__attr __self, __attr _data, __attr _size) +__attr __fn_native_unicode_unicode_ord(__attr __stack, __attr __self, __attr _data, __attr _size) { /* _data interpreted as string.__data__ */ char *s = _data.strvalue; @@ -116,10 +116,10 @@ } /* Return the new integer. */ - return __new_int(c); + return __new_int(__stack, c); } -__attr __fn_native_unicode_unicode_substr(__attr __self, __attr _data, __attr _size, __attr start, __attr end, __attr step) +__attr __fn_native_unicode_unicode_substr(__attr __stack, __attr __self, __attr _data, __attr _size, __attr start, __attr end, __attr step) { /* _data interpreted as string.__data__ */ char *s = _data.strvalue, *sub; @@ -193,7 +193,7 @@ return __new_str(sub, resultsize); } -__attr __fn_native_unicode_unicode_unichr(__attr __self, __attr value) +__attr __fn_native_unicode_unicode_unichr(__attr __stack, __attr __self, __attr value) { /* value interpreted as int */ int i = __TOINT(value); diff -r c7bd72a6309b -r 28b43ef743ae templates/native/unicode.h --- a/templates/native/unicode.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/native/unicode.h Sun Nov 07 01:18:51 2021 +0100 @@ -1,6 +1,6 @@ /* Native functions for Unicode operations. -Copyright (C) 2016, 2017 Paul Boddie +Copyright (C) 2016, 2017, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -21,10 +21,10 @@ /* Unicode operations. */ -__attr __fn_native_unicode_unicode_len(__attr __self, __attr _data, __attr _size); -__attr __fn_native_unicode_unicode_ord(__attr __self, __attr _data, __attr _size); -__attr __fn_native_unicode_unicode_substr(__attr __self, __attr _data, __attr _size, __attr start, __attr end, __attr step); -__attr __fn_native_unicode_unicode_unichr(__attr __self, __attr value); +__attr __fn_native_unicode_unicode_len(__attr __stack, __attr __self, __attr _data, __attr _size); +__attr __fn_native_unicode_unicode_ord(__attr __stack, __attr __self, __attr _data, __attr _size); +__attr __fn_native_unicode_unicode_substr(__attr __stack, __attr __self, __attr _data, __attr _size, __attr start, __attr end, __attr step); +__attr __fn_native_unicode_unicode_unichr(__attr __stack, __attr __self, __attr value); /* Module initialisation. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/progops.c --- a/templates/progops.c Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/progops.c Sun Nov 07 01:18:51 2021 +0100 @@ -44,7 +44,7 @@ __attr __new_wrapper(__attr context, __attr attr) { - return __new___builtins___core_wrapper(__NULL, context, attr); + return __new___builtins___core_wrapper(__NULL, __NULL, context, attr); } /* Generic internal data allocation. */ @@ -113,7 +113,7 @@ /* Call __init__ with the dict object and list argument. */ - __fn___builtins___dict_dict___init__(self, tmp); + __fn___builtins___dict_dict___init__(__NULL, self, tmp); return self; } #endif /* __HAVE___builtins___dict_dict */ @@ -123,73 +123,73 @@ void __raise_eof_error() { #ifdef __HAVE___builtins___exception_io_EOFError - __Raise(__new___builtins___exception_io_EOFError(__NULL)); + __Raise(__new___builtins___exception_io_EOFError(__NULL, __NULL)); #endif /* __HAVE___builtins___exception_io_EOFError */ } void __raise_floating_point_error() { - __Raise(__new___builtins___core_FloatingPointError(__NULL)); + __Raise(__new___builtins___core_FloatingPointError(__NULL, __NULL)); } void __raise_io_error(__attr value) { #ifdef __HAVE___builtins___exception_io_IOError - __Raise(__new___builtins___exception_io_IOError(__NULL, value)); + __Raise(__new___builtins___exception_io_IOError(__NULL, __NULL, value)); #endif /* __HAVE___builtins___exception_io_IOError */ } void __raise_memory_error() { - __Raise(__new___builtins___core_MemoryError(__NULL)); + __Raise(__new___builtins___core_MemoryError(__NULL, __NULL)); } void __raise_os_error(__attr value, __attr arg) { #ifdef __HAVE___builtins___exception_system_OSError - __Raise(__new___builtins___exception_system_OSError(__NULL, value, arg)); + __Raise(__new___builtins___exception_system_OSError(__NULL, __NULL, value, arg)); #endif /* __HAVE___builtins___exception_system_OSError */ } void __raise_overflow_error() { - __Raise(__new___builtins___core_OverflowError(__NULL)); + __Raise(__new___builtins___core_OverflowError(__NULL, __NULL)); } void __raise_unbound_method_error() { - __Raise(__new___builtins___core_UnboundMethodInvocation(__NULL)); + __Raise(__new___builtins___core_UnboundMethodInvocation(__NULL, __NULL)); } void __raise_type_error() { - __Raise(__new___builtins___core_TypeError(__NULL)); + __Raise(__new___builtins___core_TypeError(__NULL, __NULL)); } void __raise_underflow_error() { - __Raise(__new___builtins___core_UnderflowError(__NULL)); + __Raise(__new___builtins___core_UnderflowError(__NULL, __NULL)); } void __raise_value_error(__attr value) { #ifdef __HAVE___builtins___exception_base_ValueError - __Raise(__new___builtins___exception_base_ValueError(__NULL, value)); + __Raise(__new___builtins___exception_base_ValueError(__NULL, __NULL, value)); #endif /* __HAVE___builtins___exception_base_ValueError */ } void __raise_zero_division_error() { - __Raise(__new___builtins___core_ZeroDivisionError(__NULL)); + __Raise(__new___builtins___core_ZeroDivisionError(__NULL, __NULL)); } /* Helper for raising exception instances. */ -__attr __ensure_instance(__attr arg) +__attr __ensure_instance(__attr __stack, __attr arg) { - /* Reserve space for the instance. */ + /* Reserve space for the stack and instance. */ - __attr args[1] = {__NULL}; + __attr args[2] = {__stack, __NULL}; /* Return instances as provided. */ @@ -199,7 +199,7 @@ /* Invoke non-instances to produce instances. */ else - return __invoke(arg, 0, 0, 0, 0, 1, args); + return __invoke(arg, 0, 0, 0, 0, 2, args); } /* Generic invocation operations. */ @@ -207,8 +207,10 @@ /* Invoke the given callable, supplying keyword argument details in the given codes and arguments arrays, indicating the number of arguments described. The number of positional arguments is specified, and such arguments then - follow as conventional function arguments. Typically, at least one argument - is specified, starting with any context argument. + follow as conventional function arguments. + + Typically, at least two arguments are specified, starting with the stack + argument and any context argument. */ __attr __invoke(__attr callable, int always_callable, @@ -220,10 +222,13 @@ __attr target = __unwrap_callable(callable); /* Obtain the __args__ special member, referencing the parameter table. */ - /* Refer to the table and minimum/maximum. */ const __ptable *ptable = __check_and_load_via_object(__VALUE(target), __args__).ptable; - const unsigned int min = ptable->min, max = ptable->max; + + /* Refer to the table and minimum/maximum, adjusting for the stack + argument. */ + + unsigned int min = ptable->min + 1, max = ptable->max + 1; /* Reserve enough space for the arguments. */ @@ -269,15 +274,20 @@ /* Check the table entry against the supplied argument details. Set the argument but only if it does not overwrite positional - arguments. */ - /* NOTE: Should use a more specific exception. */ + arguments. Here, the position is adjusted for the stack + argument. */ - if ((pos == -1) || (pos < nargs)) + if ((pos == -1) || (pos + 1 < nargs)) + { + /* NOTE: Should use a more specific exception. */ + __raise_type_error(); + } - /* Set the argument using the appropriate position. */ + /* Set the argument using the appropriate position, adjusting for + the stack argument. */ - allargs[pos] = kwargs[kwpos]; + allargs[pos + 1] = kwargs[kwpos]; } /* Fill the defaults. */ @@ -290,20 +300,21 @@ } /* Call with the prepared arguments via a special adaptor function that - converts the array to an argument list. */ + converts the array to an argument list. The stack argument occupies + position #0, with the context occupying position #1. */ return __call_with_args( always_callable ? - __get_function_unwrapped(allargs[0], target) : - __check_and_get_function_unwrapped(allargs[0], target), + __get_function_unwrapped(allargs[1], target) : + __check_and_get_function_unwrapped(allargs[1], target), allargs, max); } /* Error routines. */ -__attr __unbound_method(__attr __self) +__attr __unbound_method(__attr __stack, __attr __self) { - __Raise(__new___builtins___core_UnboundMethodInvocation(__NULL)); + __Raise(__new___builtins___core_UnboundMethodInvocation(__stack, __NULL)); return __builtins___none_None; /* superfluous */ } @@ -336,7 +347,8 @@ return value == (__ref) &__predefined___builtins___boolean_True ? 1 : value == (__ref) &__predefined___builtins___boolean_False ? 0 : - __VALUE(__fn___builtins___boolean_bool(__NULL, attr)) == (__ref) &__predefined___builtins___boolean_True; + __VALUE(__fn___builtins___boolean_bool(__NULL, __NULL, attr)) == + (__ref) &__predefined___builtins___boolean_True; } /* Conversion of trailing data to an integer. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/progops.h --- a/templates/progops.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/progops.h Sun Nov 07 01:18:51 2021 +0100 @@ -61,7 +61,7 @@ /* Helper for raising exception instances. */ -__attr __ensure_instance(__attr arg); +__attr __ensure_instance(__attr __stack, __attr arg); /* Generic invocation operations. */ @@ -71,7 +71,7 @@ /* Error routines. */ -__attr __unbound_method(__attr __self); +__attr __unbound_method(__attr __stack, __attr __self); /* Generic operations depending on specific program details. */ @@ -86,7 +86,7 @@ #define __INSTANCETABLE(CLS) (__InstanceTable_##CLS) #define __NEWINSTANCE(CLS) __new(&__INSTANCETABLE(CLS), &CLS, __INSTANCESIZE(CLS), 0) #define __NEWINSTANCEIM(CLS) __new(&__INSTANCETABLE(CLS), &CLS, __INSTANCESIZE(CLS), 1) -#define __ISINSTANCE(ATTR, TYPE) __BOOL(__fn_native_introspection_isinstance(__NULL, ATTR, TYPE)) +#define __ISINSTANCE(ATTR, TYPE) __BOOL(__fn_native_introspection_isinstance(__NULL, __NULL, ATTR, TYPE)) /* Operations for accessing trailing data. */ diff -r c7bd72a6309b -r 28b43ef743ae templates/types.h --- a/templates/types.h Sat Nov 06 17:06:01 2021 +0100 +++ b/templates/types.h Sun Nov 07 01:18:51 2021 +0100 @@ -101,6 +101,11 @@ __fragment * seqvalue; /* sequence data */ void * datavalue; /* object-specific data */ __int sizevalue; /* object-specific size */ + + /* Value stack pointer for parameter usage. */ + + __attr **stack; + } __attr; typedef struct __obj diff -r c7bd72a6309b -r 28b43ef743ae translator.py --- a/translator.py Sat Nov 06 17:06:01 2021 +0100 +++ b/translator.py Sun Nov 07 01:18:51 2021 +0100 @@ -3,7 +3,7 @@ """ Translate programs. -Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie +Copyright (C) 2015-2018, 2021 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -1281,8 +1281,8 @@ self.record_temp("__tmp_values") # Arguments are presented in a temporary frame array with any context - # always being the first argument. Where it would be unused, it may be - # set to null. + # always being the first argument after the value stack. Where the + # context would be unused, it may be set to null. if context_required: if have_access_context: @@ -1292,7 +1292,10 @@ else: context_arg = "__NULL" - args = [context_arg] + # Introduce the value stack and any context. + + args = ["__stack", context_arg] + reserved_args = 2 # Complete the array with null values, permitting tests for a complete # set of arguments. @@ -1337,7 +1340,7 @@ except ValueError: raise TranslateError("Argument %s is not recognised." % arg.name, self.get_namespace_path(), n) - args[argnum+1] = str(argexpr) + args[argnum + reserved_args] = str(argexpr) # Otherwise, store the details in a separate collection. @@ -1351,7 +1354,7 @@ else: try: - args[i+1] = str(argexpr) + args[i + reserved_args] = str(argexpr) except IndexError: raise TranslateError("Too many arguments specified.", self.get_namespace_path(), n) @@ -1375,8 +1378,8 @@ for i, (argname, default) in enumerate(function_defaults): argnum = parameters.index(argname) - if not args[argnum+1]: - args[argnum+1] = "__GETDEFAULT(%s, %d)" % (target_structure, i) + if not args[argnum + reserved_args]: + args[argnum + reserved_args] = "__GETDEFAULT(%s, %d)" % (target_structure, i) elif known_parameters: @@ -1387,7 +1390,7 @@ i = len(n.args) pos = i - (num_parameters - num_defaults) while i < num_parameters: - args[i+1] = "__GETDEFAULT(%s.value, %d)" % (target_var, pos) + args[i + reserved_args] = "__GETDEFAULT(%s.value, %d)" % (target_var, pos) i += 1 pos += 1 @@ -1400,10 +1403,10 @@ # Encode the arguments. # Where literal instantiation is occurring, add an argument indicating - # the number of values. The context is excluded. + # the number of values. The stack and context are excluded. if literal_instantiation: - argstr = "%d, %s" % (len(args) - 1, ", ".join(args[1:])) + argstr = "%d, %s" % (len(args) - reserved_args, ", ".join(args[reserved_args:])) else: argstr = ", ".join(args) @@ -1738,7 +1741,7 @@ if isinstance(exc, TrInstanceRef): self.writestmt("__Raise(%s);" % exc) else: - self.writestmt("__Raise(__ensure_instance(%s));" % exc) + self.writestmt("__Raise(__ensure_instance(__stack, %s));" % exc) else: self.writestmt("__Throw(__tmp_exc);") @@ -2049,7 +2052,7 @@ "Write the start of each module's main function." - print >>self.out, "void __main_%s()" % encode_path(self.name) + print >>self.out, "void __main_%s(__attr __stack)" % encode_path(self.name) print >>self.out, "{" self.indent += 1 @@ -2142,10 +2145,14 @@ parameters found in the arguments array. """ + l = [] + + # Generate the parallel value stack reference. + + l.append("__attr __stack") + # Generate any self reference. - l = [] - if self.is_method(name): l.append("__attr self") else: