# HG changeset patch # User Paul Boddie # Date 1488202887 -3600 # Node ID c5371b8f4981642fa4163ed159fe1eed11fe1eaf # Parent 3bba67784f79851401e04ed7742f3ee64b0e68b2 Introduced convenience macros shadowing various run-time functions, eliminating the need to encode position and code information explicitly in the generated and native code. diff -r 3bba67784f79 -r c5371b8f4981 encoders.py --- a/encoders.py Mon Feb 27 11:57:15 2017 +0100 +++ b/encoders.py Mon Feb 27 14:41:27 2017 +0100 @@ -273,25 +273,10 @@ # Modify certain arguments. - # Convert attribute name arguments to position symbols. - - if op in attribute_ops: - arg = a[1] - a[1] = encode_pos(arg) - - # Convert attribute name arguments to position and code symbols. + # Convert type name arguments. - elif op in checked_ops: - arg = a[1] - a[1] = encode_pos(arg) - a.insert(2, encode_code(arg)) - - # Convert type name arguments to position and code symbols. - - elif op in typename_ops: - arg = encode_type_attribute(args[1]) - a[1] = encode_pos(arg) - a.insert(2, encode_code(arg)) + if op in typename_ops: + a[1] = encode_path(encode_type_attribute(args[1])) # Obtain addresses of type arguments. diff -r 3bba67784f79 -r c5371b8f4981 generator.py --- a/generator.py Mon Feb 27 11:57:15 2017 +0100 +++ b/generator.py Mon Feb 27 14:41:27 2017 +0100 @@ -1182,23 +1182,18 @@ { if (__ISINSTANCE(__tmp_exc.arg, ((__attr) {.value=&__builtins___exception_system_SystemExit}))) return __load_via_object( - __load_via_object(__tmp_exc.arg.value, %s).value, - %s).intvalue; + __load_via_object(__tmp_exc.arg.value, __data__).value, + value).intvalue; fprintf(stderr, "Program terminated due to exception: %%s.\\n", __load_via_object( %s((__attr[]) {__NULL, __tmp_exc.arg}).value, - %s).strvalue); + __data__).strvalue); return 1; } return 0; } -""" % ( - encode_pos("value"), - encode_pos("__data__"), - encode_function_pointer("__builtins__.str.str"), - encode_pos("__data__") - ) +""" % encode_function_pointer("__builtins__.str.str") # vim: tabstop=4 expandtab shiftwidth=4 diff -r 3bba67784f79 -r c5371b8f4981 templates/native/buffer.c --- a/templates/native/buffer.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/buffer.c Mon Feb 27 14:41:27 2017 +0100 @@ -37,7 +37,7 @@ /* Calculate the size of the string. */ for (i = 0; i < data->size; i++) - size += __load_via_object(data->attrs[i].value, __ATTRPOS(__size__)).intvalue; + size += __load_via_object(data->attrs[i].value, __size__).intvalue; /* Reserve space for a new string. */ s = (char *) __ALLOCATE(size + 1, sizeof(char)); @@ -45,8 +45,8 @@ /* Build a single string from the buffer contents. */ for (i = 0, j = 0; i < data->size; i++) { - o = __load_via_object(data->attrs[i].value, __ATTRPOS(__data__)); - n = __load_via_object(data->attrs[i].value, __ATTRPOS(__size__)).intvalue; + o = __load_via_object(data->attrs[i].value, __data__); + n = __load_via_object(data->attrs[i].value, __size__).intvalue; memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */ j += n; } diff -r 3bba67784f79 -r c5371b8f4981 templates/native/iconv.c --- a/templates/native/iconv.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/iconv.c Mon Feb 27 14:41:27 2017 +0100 @@ -57,13 +57,13 @@ /* cd interpreted as iconv_t */ iconv_t c = (iconv_t) cd->datavalue; /* state.__data__ interpreted as list */ - __fragment *f = __load_via_object(state->value, __ATTRPOS(__data__)).seqvalue; + __fragment *f = __load_via_object(state->value, __data__).seqvalue; /* Obtain the string, start position, and remaining bytes from the state. */ - char *inbuf = __load_via_object(f->attrs[0].value, __ATTRPOS(__data__)).strvalue; - int start = __load_via_object(f->attrs[1].value, __ATTRPOS(__data__)).intvalue; - int remaining = __load_via_object(f->attrs[2].value, __ATTRPOS(__data__)).intvalue; + char *inbuf = __load_via_object(f->attrs[0].value, __data__).strvalue; + int start = __load_via_object(f->attrs[1].value, __data__).intvalue; + int remaining = __load_via_object(f->attrs[2].value, __data__).intvalue; /* Allocate a string for the output buffer using the remaining input size as a guide. */ @@ -142,9 +142,9 @@ __attr * const tocode = &__args[1]; __attr * const fromcode = &__args[2]; /* tocode.__data__ interpreted as string */ - char *t = __load_via_object(tocode->value, __ATTRPOS(__data__)).strvalue; + char *t = __load_via_object(tocode->value, __data__).strvalue; /* fromcode.__data__ interpreted as string */ - char *f = __load_via_object(fromcode->value, __ATTRPOS(__data__)).strvalue; + char *f = __load_via_object(fromcode->value, __data__).strvalue; iconv_t result; __attr attr; diff -r 3bba67784f79 -r c5371b8f4981 templates/native/introspection.c --- a/templates/native/introspection.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/introspection.c Mon Feb 27 14:41:27 2017 +0100 @@ -32,7 +32,7 @@ __attr * const name = &__args[2]; __attr * const _default = &__args[3]; /* name.__data__ interpreted as string */ - __attr key = __load_via_object(name->value, __ATTRPOS(__key__)); + __attr key = __load_via_object(name->value, __key__); __attr out; if ((key.code == 0) && (key.pos == 0)) @@ -45,7 +45,7 @@ { /* Inspect the object's class if this failed. */ - out = __check_and_load_via_class(obj->value, key.pos, key.code); + out = __check_and_load_via_class__(obj->value, key.pos, key.code); if (out.value == 0) return *_default; diff -r 3bba67784f79 -r c5371b8f4981 templates/native/io.c --- a/templates/native/io.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/io.c Mon Feb 27 14:41:27 2017 +0100 @@ -62,9 +62,9 @@ __attr * const filename = &__args[1]; __attr * const mode = &__args[2]; /* filename.__data__ interpreted as string */ - char *fn = __load_via_object(filename->value, __ATTRPOS(__data__)).strvalue; + char *fn = __load_via_object(filename->value, __data__).strvalue; /* mode.__data__ interpreted as string */ - char *s = __load_via_object(mode->value, __ATTRPOS(__data__)).strvalue; + char *s = __load_via_object(mode->value, __data__).strvalue; FILE *f; __attr attr; @@ -94,9 +94,9 @@ __attr * const fd = &__args[1]; __attr * const mode = &__args[2]; /* fd.__data__ interpreted as int */ - int i = __load_via_object(fd->value, __ATTRPOS(__data__)).intvalue; + int i = __load_via_object(fd->value, __data__).intvalue; /* mode.__data__ interpreted as string */ - char *s = __load_via_object(mode->value, __ATTRPOS(__data__)).strvalue; + char *s = __load_via_object(mode->value, __data__).strvalue; FILE *f; __attr attr; @@ -128,7 +128,7 @@ /* fp interpreted as FILE reference */ FILE *f = (FILE *) fp->datavalue; /* size.__data__ interpreted as int */ - int to_read = __load_via_object(size->value, __ATTRPOS(__data__)).intvalue; + int to_read = __load_via_object(size->value, __data__).intvalue; char buf[to_read]; size_t have_read; int error; @@ -158,9 +158,9 @@ /* fp interpreted as FILE reference */ FILE *f = (FILE *) fp->datavalue; /* str.__data__ interpreted as string */ - char *s = __load_via_object(str->value, __ATTRPOS(__data__)).strvalue; + char *s = __load_via_object(str->value, __data__).strvalue; /* str.__size__ interpreted as int */ - int to_write = __load_via_object(str->value, __ATTRPOS(__size__)).intvalue; + int to_write = __load_via_object(str->value, __size__).intvalue; size_t have_written = fwrite(s, sizeof(char), to_write, f); int error; @@ -179,7 +179,7 @@ { __attr * const fd = &__args[1]; /* fd.__data__ interpreted as int */ - int i = __load_via_object(fd->value, __ATTRPOS(__data__)).intvalue; + int i = __load_via_object(fd->value, __data__).intvalue; errno = 0; if (close(i) == -1) @@ -193,9 +193,9 @@ __attr * const fd = &__args[1]; __attr * const n = &__args[2]; /* fd.__data__ interpreted as int */ - int i = __load_via_object(fd->value, __ATTRPOS(__data__)).intvalue; + int i = __load_via_object(fd->value, __data__).intvalue; /* n.__data__ interpreted as int */ - int to_read = __load_via_object(n->value, __ATTRPOS(__data__)).intvalue; + int to_read = __load_via_object(n->value, __data__).intvalue; char buf[to_read]; ssize_t have_read; char *s; @@ -218,11 +218,11 @@ __attr * const fd = &__args[1]; __attr * const str = &__args[2]; /* fd.__data__ interpreted as int */ - int i = __load_via_object(fd->value, __ATTRPOS(__data__)).intvalue; + int i = __load_via_object(fd->value, __data__).intvalue; /* str.__data__ interpreted as string */ - char *s = __load_via_object(str->value, __ATTRPOS(__data__)).strvalue; + char *s = __load_via_object(str->value, __data__).strvalue; /* str.__size__ interpreted as int */ - int size = __load_via_object(str->value, __ATTRPOS(__size__)).intvalue; + int size = __load_via_object(str->value, __size__).intvalue; ssize_t have_written; errno = 0; diff -r 3bba67784f79 -r c5371b8f4981 templates/native/list.c --- a/templates/native/list.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/list.c Mon Feb 27 14:41:27 2017 +0100 @@ -31,7 +31,7 @@ { __attr * const size = &__args[1]; /* size.__data__ interpreted as int */ - unsigned int n = __load_via_object(size->value, __ATTRPOS(__data__)).intvalue; + unsigned int n = __load_via_object(size->value, __data__).intvalue; __attr attr = {.seqvalue=__new_fragment(n)}; /* Return the __data__ attribute. */ @@ -45,7 +45,7 @@ /* _data interpreted as list */ __fragment *data = _data->seqvalue; /* size.__data__ interpreted as int */ - unsigned int n = __load_via_object(size->value, __ATTRPOS(__data__)).intvalue; + unsigned int n = __load_via_object(size->value, __data__).intvalue; data->size = n; return __builtins___none_None; @@ -56,12 +56,12 @@ __attr * const self = &__args[1]; __attr * const value = &__args[2]; /* self.__data__ interpreted as list */ - __fragment *data = __load_via_object(self->value, __ATTRPOS(__data__)).seqvalue; + __fragment *data = __load_via_object(self->value, __data__).seqvalue; __fragment *newdata = __fragment_append(data, value); /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __ATTRPOS(__data__), ((__attr) {.seqvalue=newdata})); + __store_via_object(self->value, __data__, ((__attr) {.seqvalue=newdata})); return __builtins___none_None; } @@ -70,7 +70,7 @@ __attr * const self = &__args[1]; __attr * const other = &__args[2]; /* self.__data__, other interpreted as list */ - __fragment *data = __load_via_object(self->value, __ATTRPOS(__data__)).seqvalue; + __fragment *data = __load_via_object(self->value, __data__).seqvalue; __fragment *other_data = other->seqvalue; __fragment *newdata = data; unsigned int size = data->size, capacity = data->capacity; @@ -92,7 +92,7 @@ /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __ATTRPOS(__data__), ((__attr) {.seqvalue=newdata})); + __store_via_object(self->value, __data__, ((__attr) {.seqvalue=newdata})); return __builtins___none_None; } @@ -120,7 +120,7 @@ /* _data interpreted as fragment */ __attr *elements = _data->seqvalue->attrs; /* index.__data__ interpreted as int */ - int i = __load_via_object(index->value, __ATTRPOS(__data__)).intvalue; + int i = __load_via_object(index->value, __data__).intvalue; return elements[i]; } @@ -133,7 +133,7 @@ /* _data interpreted as fragment */ __attr *elements = _data->seqvalue->attrs; /* index.__data__ interpreted as int */ - int i = __load_via_object(index->value, __ATTRPOS(__data__)).intvalue; + int i = __load_via_object(index->value, __data__).intvalue; /* Set the element. */ elements[i] = *value; diff -r 3bba67784f79 -r c5371b8f4981 templates/native/locale.c --- a/templates/native/locale.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/locale.c Mon Feb 27 14:41:27 2017 +0100 @@ -33,7 +33,7 @@ { __attr * const category = &__args[1]; /* category.__data__ interpreted as int */ - int cat = __load_via_object(category->value, __ATTRPOS(__data__)).intvalue; + int cat = __load_via_object(category->value, __data__).intvalue; char *result, *out; size_t length; @@ -54,9 +54,9 @@ __attr * const category = &__args[1]; __attr * const value = &__args[2]; /* category.__data__ interpreted as int */ - int cat = __load_via_object(category->value, __ATTRPOS(__data__)).intvalue; + int cat = __load_via_object(category->value, __data__).intvalue; /* value.__data__ interpreted as string */ - char *s = __load_via_object(value->value, __ATTRPOS(__data__)).strvalue; + char *s = __load_via_object(value->value, __data__).strvalue; char *result, *out; size_t length; diff -r 3bba67784f79 -r c5371b8f4981 templates/native/str.c --- a/templates/native/str.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/str.c Mon Feb 27 14:41:27 2017 +0100 @@ -113,11 +113,11 @@ /* _data interpreted as string */ char *s = _data->strvalue, *sub; /* start.__data__ interpreted as int */ - int istart = __load_via_object(start->value, __ATTRPOS(__data__)).intvalue; + int istart = __load_via_object(start->value, __data__).intvalue; /* end.__data__ interpreted as int */ - int iend = __load_via_object(end->value, __ATTRPOS(__data__)).intvalue; + int iend = __load_via_object(end->value, __data__).intvalue; /* step.__data__ interpreted as int */ - int istep = __load_via_object(step->value, __ATTRPOS(__data__)).intvalue; + int istep = __load_via_object(step->value, __data__).intvalue; /* Calculate the size of the substring. */ size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; diff -r 3bba67784f79 -r c5371b8f4981 templates/native/system.c --- a/templates/native/system.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/system.c Mon Feb 27 14:41:27 2017 +0100 @@ -31,7 +31,7 @@ { __attr * const status = &__args[1]; - exit(__load_via_object(status->value, __ATTRPOS(__data__)).intvalue); + exit(__load_via_object(status->value, __data__).intvalue); return __builtins___none_None; } diff -r 3bba67784f79 -r c5371b8f4981 templates/native/unicode.c --- a/templates/native/unicode.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/native/unicode.c Mon Feb 27 14:41:27 2017 +0100 @@ -135,11 +135,11 @@ /* _size interpreted as int */ int ss = _size->intvalue; /* start.__data__ interpreted as int */ - int istart = __load_via_object(start->value, __ATTRPOS(__data__)).intvalue; + int istart = __load_via_object(start->value, __data__).intvalue; /* end.__data__ interpreted as int */ - int iend = __load_via_object(end->value, __ATTRPOS(__data__)).intvalue; + int iend = __load_via_object(end->value, __data__).intvalue; /* step.__data__ interpreted as int */ - int istep = __load_via_object(step->value, __ATTRPOS(__data__)).intvalue; + int istep = __load_via_object(step->value, __data__).intvalue; /* Calculate the number of characters. */ size_t nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; diff -r 3bba67784f79 -r c5371b8f4981 templates/ops.c --- a/templates/ops.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/ops.c Mon Feb 27 14:41:27 2017 +0100 @@ -41,33 +41,33 @@ /* Direct retrieval operations, returning and setting attributes. */ -__attr __load_via_object(__ref obj, int pos) +__attr __load_via_object__(__ref obj, int pos) { return obj->attrs[pos]; } -__attr __load_via_class(__ref obj, int pos) +__attr __load_via_class__(__ref obj, int pos) { - return __load_via_object(__get_class(obj), pos); + return __load_via_object__(__get_class(obj), pos); } -__attr __get_class_and_load(__ref obj, int pos) +__attr __get_class_and_load__(__ref obj, int pos) { if (__is_instance(obj)) - return __load_via_class(obj, pos); + return __load_via_class__(obj, pos); else - return __load_via_object(obj, pos); + return __load_via_object__(obj, pos); } /* Direct storage operations. */ -int __store_via_object(__ref obj, int pos, __attr value) +int __store_via_object__(__ref obj, int pos, __attr value) { obj->attrs[pos] = value; return 1; } -int __get_class_and_store(__ref obj, int pos, __attr value) +int __get_class_and_store__(__ref obj, int pos, __attr value) { /* Forbid class-relative assignments. */ @@ -89,12 +89,12 @@ __ref __get_class(__ref obj) { - return __load_via_object(obj, __pos___class__).value; + return __load_via_object(obj, __class__).value; } __attr __get_class_attr(__ref obj) { - return __load_via_object(obj, __pos___class__); + return __load_via_object(obj, __class__); } /* Attribute testing operations. */ @@ -114,17 +114,17 @@ return obj == type ? obj : 0; } -__ref __test_common_instance(__ref obj, int pos, int code) +__ref __test_common_instance__(__ref obj, int pos, int code) { return __HASATTR(__get_class(obj), pos, code) ? obj : 0; } -__ref __test_common_object(__ref obj, int pos, int code) +__ref __test_common_object__(__ref obj, int pos, int code) { - return __test_common_type(obj, pos, code) || __test_common_instance(obj, pos, code) ? obj : 0; + return __test_common_type__(obj, pos, code) || __test_common_instance__(obj, pos, code) ? obj : 0; } -__ref __test_common_type(__ref obj, int pos, int code) +__ref __test_common_type__(__ref obj, int pos, int code) { return __HASATTR(obj, pos, code) ? obj : 0; } @@ -134,36 +134,36 @@ __attr __check_and_load_via_object_null(__ref obj, int pos, int code) { if (__HASATTR(obj, pos, code)) - return __load_via_object(obj, pos); + return __load_via_object__(obj, pos); else return __NULL; } -__attr __check_and_load_via_class(__ref obj, int pos, int code) +__attr __check_and_load_via_class__(__ref obj, int pos, int code) { - return __check_and_load_via_object(__get_class(obj), pos, code); + return __check_and_load_via_object__(__get_class(obj), pos, code); } -__attr __check_and_load_via_object(__ref obj, int pos, int code) +__attr __check_and_load_via_object__(__ref obj, int pos, int code) { if (__HASATTR(obj, pos, code)) - return __load_via_object(obj, pos); + return __load_via_object__(obj, pos); __raise_type_error(); return __NULL; } -__attr __check_and_load_via_any(__ref obj, int pos, int code) +__attr __check_and_load_via_any__(__ref obj, int pos, int code) { __attr out = __check_and_load_via_object_null(obj, pos, code); if (out.value == 0) - out = __check_and_load_via_class(obj, pos, code); + out = __check_and_load_via_class__(obj, pos, code); return out; } /* Attribute testing and storage operations. */ -int __check_and_store_via_class(__ref obj, int pos, int code, __attr value) +int __check_and_store_via_class__(__ref obj, int pos, int code, __attr value) { /* Forbid class-relative assignments. */ @@ -171,11 +171,11 @@ return 0; } -int __check_and_store_via_object(__ref obj, int pos, int code, __attr value) +int __check_and_store_via_object__(__ref obj, int pos, int code, __attr value) { if (__HASATTR(obj, pos, code)) { - __store_via_object(obj, pos, value); + __store_via_object__(obj, pos, value); return 1; } @@ -185,9 +185,9 @@ return 0; } -int __check_and_store_via_any(__ref obj, int pos, int code, __attr value) +int __check_and_store_via_any__(__ref obj, int pos, int code, __attr value) { - if (__check_and_store_via_object(obj, pos, code, value)) + if (__check_and_store_via_object__(obj, pos, code, value)) return 1; /* Forbid class-relative assignments. */ @@ -218,7 +218,7 @@ attribute context's class, inspecting the context instance for compatibility. */ - if (__test_common_instance(context, __TYPEPOS(attrcontext), __TYPECODE(attrcontext))) + if (__test_common_instance__(context, __TYPEPOS(attrcontext), __TYPECODE(attrcontext))) return 1; else __raise_type_error(); @@ -298,7 +298,7 @@ or type instance contexts for type methods. */ if ((context == 0) || __is_instance(context) || __type_method_invocation(context, target)) - return __load_via_object(target.value, __ATTRPOS(__fn__)).fn; + return __load_via_object(target.value, __fn__).fn; else return __unbound_method; } @@ -311,7 +311,7 @@ or type instance contexts for type methods. */ if ((context == 0) || __is_instance(context) || __type_method_invocation(context, target)) - return __check_and_load_via_object(target.value, __ATTRPOS(__fn__), __ATTRCODE(__fn__)).fn; + return __check_and_load_via_object__(target.value, __ATTRPOS(__fn__), __ATTRCODE(__fn__)).fn; else return __unbound_method; } diff -r 3bba67784f79 -r c5371b8f4981 templates/ops.h --- a/templates/ops.h Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/ops.h Mon Feb 27 14:41:27 2017 +0100 @@ -30,14 +30,21 @@ /* Direct retrieval operations, returning attributes. */ -__attr __load_via_class(__ref obj, int pos); -__attr __load_via_object(__ref obj, int pos); -__attr __get_class_and_load(__ref obj, int pos); +__attr __load_via_class__(__ref obj, int pos); +__attr __load_via_object__(__ref obj, int pos); +__attr __get_class_and_load__(__ref obj, int pos); + +#define __load_via_class(OBJ, ATTRNAME) (__load_via_class__(OBJ, __ATTRPOS(ATTRNAME))) +#define __load_via_object(OBJ, ATTRNAME) (__load_via_object__(OBJ, __ATTRPOS(ATTRNAME))) +#define __get_class_and_load(OBJ, ATTRNAME) (__get_class_and_load__(OBJ, __ATTRPOS(ATTRNAME))) /* Direct storage operations. */ -int __store_via_object(__ref obj, int pos, __attr value); -int __get_class_and_store(__ref obj, int pos, __attr value); +int __store_via_object__(__ref obj, int pos, __attr value); +int __get_class_and_store__(__ref obj, int pos, __attr value); + +#define __store_via_object(OBJ, ATTRNAME, VALUE) (__store_via_object__(OBJ, __ATTRPOS(ATTRNAME), VALUE)) +#define __get_class_and_store(OBJ, ATTRNAME, VALUE) (__get_class_and_store__(OBJ, __ATTRPOS(ATTRNAME), VALUE)) /* Introspection. */ @@ -51,22 +58,36 @@ __ref __test_specific_instance(__ref obj, __ref type); __ref __test_specific_object(__ref obj, __ref type); __ref __test_specific_type(__ref obj, __ref type); -__ref __test_common_instance(__ref obj, int pos, int code); -__ref __test_common_object(__ref obj, int pos, int code); -__ref __test_common_type(__ref obj, int pos, int code); + +__ref __test_common_instance__(__ref obj, int pos, int code); +__ref __test_common_object__(__ref obj, int pos, int code); +__ref __test_common_type__(__ref obj, int pos, int code); + +#define __test_common_instance(OBJ, TYPENAME) (__test_common_instance__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) +#define __test_common_object(OBJ, TYPENAME) (__test_common_object__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) +#define __test_common_type(OBJ, TYPENAME) (__test_common_type__(OBJ, __ATTRPOS(TYPENAME), __ATTRCODE(TYPENAME))) /* Attribute testing and retrieval operations. */ -__attr __check_and_load_via_class(__ref obj, int pos, int code); -__attr __check_and_load_via_object(__ref obj, int pos, int code); __attr __check_and_load_via_object_null(__ref obj, int pos, int code); -__attr __check_and_load_via_any(__ref obj, int pos, int code); + +__attr __check_and_load_via_class__(__ref obj, int pos, int code); +__attr __check_and_load_via_object__(__ref obj, int pos, int code); +__attr __check_and_load_via_any__(__ref obj, int pos, int code); + +#define __check_and_load_via_class(OBJ, ATTRNAME) (__check_and_load_via_class__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME))) +#define __check_and_load_via_object(OBJ, ATTRNAME) (__check_and_load_via_object__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME))) +#define __check_and_load_via_any(OBJ, ATTRNAME) (__check_and_load_via_any__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME))) /* Attribute testing and storage operations. */ -int __check_and_store_via_class(__ref obj, int pos, int code, __attr value); -int __check_and_store_via_object(__ref obj, int pos, int code, __attr value); -int __check_and_store_via_any(__ref obj, int pos, int code, __attr value); +int __check_and_store_via_class__(__ref obj, int pos, int code, __attr value); +int __check_and_store_via_object__(__ref obj, int pos, int code, __attr value); +int __check_and_store_via_any__(__ref obj, int pos, int code, __attr value); + +#define __check_and_store_via_class(OBJ, ATTRNAME, VALUE) (__check_and_store_via_class__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME), VALUE)) +#define __check_and_store_via_object(OBJ, ATTRNAME, VALUE) (__check_and_store_via_object__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME), VALUE)) +#define __check_and_store_via_any(OBJ, ATTRNAME, VALUE) (__check_and_store_via_any__(OBJ, __ATTRPOS(ATTRNAME), __ATTRCODE(ATTRNAME), VALUE)) /* Context-related operations. */ diff -r 3bba67784f79 -r c5371b8f4981 templates/progops.c --- a/templates/progops.c Mon Feb 27 11:57:15 2017 +0100 +++ b/templates/progops.c Mon Feb 27 14:41:27 2017 +0100 @@ -31,7 +31,7 @@ { __ref obj = (__ref) __ALLOCATE(1, size); obj->table = table; - __store_via_object(obj, __ATTRPOS(__class__), (__attr) {.value=cls}); + __store_via_object(obj, __class__, (__attr) {.value=cls}); return (__attr) {.value=obj}; } @@ -72,7 +72,7 @@ /* Store a reference to the data in the object's __data__ attribute. */ - __store_via_object(args[0].value, __ATTRPOS(__data__), attr); + __store_via_object(args[0].value, __data__, attr); } #ifdef __HAVE___builtins___dict_dict @@ -191,7 +191,7 @@ /* Obtain the __args__ special member, referencing the parameter table. */ /* Refer to the table and minimum/maximum. */ - const __ptable *ptable = __check_and_load_via_object(target.value, __ATTRPOS(__args__), __ATTRCODE(__args__)).ptable; + const __ptable *ptable = __check_and_load_via_object(target.value, __args__).ptable; const unsigned int min = ptable->min, max = ptable->max; /* Reserve enough space for the arguments. */ @@ -266,12 +266,12 @@ void __SETDEFAULT(__ref obj, int pos, __attr value) { - __store_via_object(obj, __FUNCTION_INSTANCE_SIZE + pos, value); + __store_via_object__(obj, __FUNCTION_INSTANCE_SIZE + pos, value); } __attr __GETDEFAULT(__ref obj, int pos) { - return __load_via_object(obj, __FUNCTION_INSTANCE_SIZE + pos); + return __load_via_object__(obj, __FUNCTION_INSTANCE_SIZE + pos); } int __BOOL(__attr attr) diff -r 3bba67784f79 -r c5371b8f4981 translator.py --- a/translator.py Mon Feb 27 11:57:15 2017 +0100 +++ b/translator.py Mon Feb 27 14:41:27 2017 +0100 @@ -23,9 +23,9 @@ first, get_builtin_class, init_item, is_newer, \ predefined_constants from encoders import encode_access_instruction, encode_access_instruction_arg, \ - encode_code, encode_function_pointer, encode_literal_constant, \ + encode_function_pointer, encode_literal_constant, \ encode_literal_instantiator, encode_instantiator_pointer, \ - encode_instructions, encode_path, encode_pos, \ + encode_instructions, encode_path, \ encode_symbol, encode_type_attribute, \ is_type_attribute from errors import InspectError, TranslateError @@ -142,7 +142,7 @@ elif parent: return "__store_via_object(&%s, %s, %s)" % ( - encode_path(parent), encode_pos(attrname), self.expr) + encode_path(parent), attrname, self.expr) # All other assignments involve the names as they were given. @@ -160,7 +160,7 @@ elif parent: return "__load_via_object(&%s, %s)" % ( - encode_path(parent), encode_pos(attrname)) + encode_path(parent), attrname) # All other accesses involve the names as they were given. @@ -979,8 +979,8 @@ parent, attrname = path.rsplit(".", 1) self.writestmt("__store_via_object(&%s, %s, __load_via_object(&%s, %s));" % ( - encode_path(class_name), encode_pos(name), - encode_path(parent), encode_pos(attrname) + encode_path(class_name), name, + encode_path(parent), attrname )) def process_from_node(self, n): @@ -1063,8 +1063,7 @@ argstr = "&%s" % encode_path(ref.get_origin()) elif guard == "common": ref = first(self.deducer.accessor_all_general_types[location]) - typeattr = encode_type_attribute(ref.get_origin()) - argstr = "%s, %s" % (encode_pos(typeattr), encode_code(typeattr)) + argstr = encode_path(encode_type_attribute(ref.get_origin())) else: return @@ -1447,8 +1446,7 @@ stages.append("__get_function(__CONTEXT_AS_VALUE(%s).value, %s)" % ( target_var, target_var)) else: - stages.append("__load_via_object(%s.value, %s).fn" % ( - target_var, encode_pos("__fn__"))) + stages.append("__load_via_object(%s.value, __fn__).fn" % target_var) # With a known target, the function is obtained directly and called. # By putting the invocation at the end of the final element in the