1.1 --- a/templates/progops.c Sat Mar 25 23:06:55 2017 +0100
1.2 +++ b/templates/progops.c Sat Mar 25 23:20:16 2017 +0100
1.3 @@ -28,12 +28,17 @@
1.4
1.5 /* Generic instantiation operations, defining common members. */
1.6
1.7 +void __init(__ref obj, const __table * table, __ref cls)
1.8 +{
1.9 + obj->table = table;
1.10 + obj->pos = __INSTANCEPOS;
1.11 + __store_via_object(obj, __class__, __ATTRVALUE(cls));
1.12 +}
1.13 +
1.14 __attr __new(const __table * table, __ref cls, size_t size, int immutable)
1.15 {
1.16 __ref obj = (__ref) (immutable ? __ALLOCATEIM : __ALLOCATE)(1, size);
1.17 - obj->table = table;
1.18 - obj->pos = __INSTANCEPOS;
1.19 - __store_via_object(obj, __class__, __ATTRVALUE(cls));
1.20 + __init(obj, table, cls);
1.21 return __ATTRVALUE(obj);
1.22 }
1.23
1.24 @@ -57,11 +62,8 @@
1.25 return data;
1.26 }
1.27
1.28 -__attr __newdata_sequence(__attr self, __attr args[], unsigned int number)
1.29 +void __newdata_sequence(__attr self, __attr args[], unsigned int number, __fragment *data)
1.30 {
1.31 - /* Calculate the size of the fragment. */
1.32 -
1.33 - __fragment *data = __new_fragment(number);
1.34 __attr attr = {.seqvalue=data};
1.35 unsigned int i;
1.36
1.37 @@ -75,12 +77,35 @@
1.38 /* Store a reference to the data in the object's __data__ attribute. */
1.39
1.40 __store_via_object(__VALUE(self), __data__, attr);
1.41 +}
1.42 +
1.43 +__attr __newdata_list(__attr args[], unsigned int number)
1.44 +{
1.45 + __attr self = __NEWINSTANCE(__builtins___list_list);
1.46 + __fragment *data = __new_fragment(number);
1.47 + __newdata_sequence(self, args, number, data);
1.48 + return self;
1.49 +}
1.50 +
1.51 +__attr __newdata_tuple(__attr args[], unsigned int number)
1.52 +{
1.53 + /* Allocate the tuple and fragment together. */
1.54 +
1.55 + __ref obj = (__ref) __ALLOCATE(1, __INSTANCESIZE(__builtins___tuple_tuple) + __FRAGMENT_SIZE(number));
1.56 + __attr self = __ATTRVALUE(obj);
1.57 +
1.58 + /* Initialise the instance and fragment. */
1.59 +
1.60 + __init(obj, &__INSTANCETABLE(__builtins___tuple_tuple), &__builtins___tuple_tuple);
1.61 + __newdata_sequence(self, args, number, (__fragment *) ((void *) obj + __INSTANCESIZE(__builtins___tuple_tuple)));
1.62 return self;
1.63 }
1.64
1.65 #ifdef __HAVE___builtins___dict_dict
1.66 -__attr __newdata_mapping(__attr self, __attr args[], unsigned int number)
1.67 +__attr __newdata_dict(__attr args[], unsigned int number)
1.68 {
1.69 + __attr self = __NEWINSTANCE(__builtins___dict_dict);
1.70 +
1.71 /* Create a temporary list using the arguments. */
1.72
1.73 __attr tmp = __newliteral___builtins___list_list(args, number);