# HG changeset patch # User Paul Boddie # Date 1486855536 -3600 # Node ID b09f64a52daae4339ce007e5a3253c95b7a5c67f # Parent 7a6d39d57799626081fa524891dedae9bfa09634 Added a convenience macro for instantiation. diff -r 7a6d39d57799 -r b09f64a52daa generator.py --- a/generator.py Sat Feb 11 15:34:30 2017 +0100 +++ b/generator.py Sun Feb 12 00:25:36 2017 +0100 @@ -1055,7 +1055,7 @@ __attr %s(__attr __args[]) { /* Allocate the structure. */ - __args[0] = __new(&%s, &%s, sizeof(%s)); + __args[0] = __NEWINSTANCE(%s); /* Call the initialiser. */ %s(__args); @@ -1065,9 +1065,7 @@ } """ % ( encode_instantiator_pointer(path), - encode_tablename("", path), encode_path(path), - encode_symbol("obj", path), encode_function_pointer(init_ref.get_origin()) ) @@ -1087,7 +1085,7 @@ __attr %s(__attr __args[], __pos number) { /* Allocate the structure. */ - __args[0] = __new(&%s, &%s, sizeof(%s)); + __args[0] = __NEWINSTANCE(%s); /* Allocate a structure for the data and set it on the __data__ attribute. */ %s(__args, number); @@ -1097,9 +1095,7 @@ } """ % ( encode_literal_instantiator(path), - encode_tablename("", path), encode_path(path), - encode_symbol("obj", path), encode_literal_data_initialiser(style) ) diff -r 7a6d39d57799 -r b09f64a52daa templates/progops.h --- a/templates/progops.h Sat Feb 11 15:34:30 2017 +0100 +++ b/templates/progops.h Sun Feb 12 00:25:36 2017 +0100 @@ -75,6 +75,7 @@ /* Convenience definitions. */ +#define __NEWINSTANCE(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS)) #define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {__NULL, __ATTR, __TYPE})) #endif /* __PROGOPS_H__ */