# HG changeset patch # User Paul Boddie # Date 1480453792 -3600 # Node ID c498ceec120efde8dc8ffe7984c35d2b7fd90978 # Parent 22aea7bc1acd80b91a8cb7e7ad1c2a627ae0840e Renamed the data member of __attr to seqvalue and __newdata to __newfragment. Added some commentary in the native module. diff -r 22aea7bc1acd -r c498ceec120e generator.py --- a/generator.py Tue Nov 29 17:29:42 2016 +0100 +++ b/generator.py Tue Nov 29 22:09:52 2016 +0100 @@ -919,7 +919,7 @@ __args[0] = __new(&%s, &%s, sizeof(%s)); /* Allocate a structure for the data. */ - data = __newdata(__args, number); + data = __newfragment(__args, number); /* Store a reference to the data in the object's __data__ attribute. */ __store_via_object(__args[0].value, %s, data); diff -r 22aea7bc1acd -r c498ceec120e lib/native.py --- a/lib/native.py Tue Nov 29 17:29:42 2016 +0100 +++ b/lib/native.py Tue Nov 29 22:09:52 2016 +0100 @@ -1,7 +1,8 @@ #!/usr/bin/env python """ -Native library functions. +Native library functions. None of these are actually defined here. Instead, +native implementations are substituted when each program is built. Copyright (C) 2011, 2015, 2016 Paul Boddie @@ -19,13 +20,19 @@ this program. If not, see . """ +# Environment support. + def _exit(status): pass def _get_argv(): pass def _get_path(): pass +# Identity testing. + def _is(x, y): pass def _is_not(x, y): pass +# Integer operations. + def _int_add(self, other): pass def _int_div(self, other): pass def _int_mod(self, other): pass @@ -45,6 +52,8 @@ def _int_str(self): pass +# String operations. + def _str_add(self, other): pass def _str_lt(self, other): pass def _str_gt(self, other): pass @@ -52,6 +61,8 @@ def _str_len(self): pass def _str_nonempty(self): pass +# List operations. + def _list_init(size): pass def _list_setsize(self, size): pass def _list_append(self, value): pass @@ -61,15 +72,22 @@ def _list_element(self, index): pass def _list_setelement(self, index, value): pass +# Buffer operations. + def _buffer_str(self): pass +# Method binding. + def _get_using(callable, instance): pass +# Introspection. + def _object_getattr(obj, name, default): pass - def _isinstance(obj, cls): pass def _issubclass(obj, cls): pass +# Input/output. + def _read(fd, n): pass def _write(fd, str): pass diff -r 22aea7bc1acd -r c498ceec120e templates/native.c --- a/templates/native.c Tue Nov 29 17:29:42 2016 +0100 +++ b/templates/native.c Tue Nov 29 22:09:52 2016 +0100 @@ -341,7 +341,7 @@ /* Allocate space for the list. */ __fragment *data = (__fragment *) __ALLOCATE(1, __FRAGMENT_SIZE(n)); - __attr attr = {0, .data=data}; + __attr attr = {0, .seqvalue=data}; /* The initial capacity is the same as the given size. */ data->size = 0; @@ -354,7 +354,7 @@ __attr * const self = &__args[1]; __attr * const size = &__args[2]; /* self.__data__ interpreted as list */ - __fragment *data = __load_via_object(self->value, __pos___data__).data; + __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; /* size.__data__ interpreted as int */ unsigned int n = __load_via_object(size->value, __pos___data__).intvalue; @@ -367,7 +367,7 @@ __attr * const self = &__args[1]; __attr * const value = &__args[2]; /* self.__data__ interpreted as list */ - __fragment *data = __load_via_object(self->value, __pos___data__).data; + __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; __fragment *newdata = data; unsigned int size = data->size, capacity = data->capacity; unsigned int n; @@ -387,7 +387,7 @@ /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __pos___data__, ((__attr) {0, .data=newdata})); + __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); return __builtins___none_None; } @@ -396,8 +396,8 @@ __attr * const self = &__args[1]; __attr * const other = &__args[2]; /* self.__data__, other.__data__ interpreted as list */ - __fragment *data = __load_via_object(self->value, __pos___data__).data; - __fragment *other_data = __load_via_object(other->value, __pos___data__).data; + __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; + __fragment *other_data = __load_via_object(other->value, __pos___data__).seqvalue; __fragment *newdata = data; unsigned int size = data->size, capacity = data->capacity; unsigned int other_size = other_data->size; @@ -418,7 +418,7 @@ /* Replace the __data__ attribute if appropriate. */ if (newdata != data) - __store_via_object(self->value, __pos___data__, ((__attr) {0, .data=newdata})); + __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); return __builtins___none_None; } @@ -426,7 +426,7 @@ { __attr * const self = &__args[1]; /* self.__data__ interpreted as fragment */ - unsigned int size = __load_via_object(self->value, __pos___data__).data->size; + unsigned int size = __load_via_object(self->value, __pos___data__).seqvalue->size; /* Return the new integer. */ return __new_int(size); @@ -436,7 +436,7 @@ { __attr * const self = &__args[1]; - return __load_via_object(self->value, __pos___data__).data->size ? __builtins___boolean_True : __builtins___boolean_False; + return __load_via_object(self->value, __pos___data__).seqvalue->size ? __builtins___boolean_True : __builtins___boolean_False; } __attr __fn_native__list_element(__attr __args[]) @@ -444,7 +444,7 @@ __attr * const self = &__args[1]; __attr * const index = &__args[2]; /* self.__data__ interpreted as fragment */ - __attr *elements = __load_via_object(self->value, __pos___data__).data->attrs; + __attr *elements = __load_via_object(self->value, __pos___data__).seqvalue->attrs; /* index.__data__ interpreted as int */ int i = __load_via_object(index->value, __pos___data__).intvalue; @@ -457,7 +457,7 @@ __attr * const index = &__args[2]; __attr * const value = &__args[3]; /* self.__data__ interpreted as fragment */ - __attr *elements = __load_via_object(self->value, __pos___data__).data->attrs; + __attr *elements = __load_via_object(self->value, __pos___data__).seqvalue->attrs; /* index.__data__ interpreted as int */ int i = __load_via_object(index->value, __pos___data__).intvalue; @@ -470,7 +470,7 @@ { __attr * const self = &__args[1]; /* self.__data__ interpreted as buffer */ - __fragment *data = __load_via_object(self->value, __pos___data__).data; + __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; unsigned int size = 0, i, j, n; char *s, *o; diff -r 22aea7bc1acd -r c498ceec120e templates/progops.c --- a/templates/progops.c Tue Nov 29 17:29:42 2016 +0100 +++ b/templates/progops.c Tue Nov 29 22:09:52 2016 +0100 @@ -24,12 +24,12 @@ /* Generic internal data allocation. */ -__attr __newdata(__attr args[], unsigned int number) +__attr __newfragment(__attr args[], unsigned int number) { /* Calculate the size of the fragment. */ __fragment *data = (__fragment *) __ALLOCATE(1, __FRAGMENT_SIZE(number)); - __attr attr = {0, .data=data}; + __attr attr = {0, .seqvalue=data}; unsigned int i, j; /* Copy the given number of values, starting from the second element. */ diff -r 22aea7bc1acd -r c498ceec120e templates/progops.h --- a/templates/progops.h Tue Nov 29 17:29:42 2016 +0100 +++ b/templates/progops.h Tue Nov 29 22:09:52 2016 +0100 @@ -7,7 +7,7 @@ __attr __new(const __table *table, __ref cls, size_t size); -__attr __newdata(__attr args[], unsigned int number); +__attr __newfragment(__attr args[], unsigned int number); __attr __invoke(__attr callable, int always_callable, unsigned int nkwargs, __param kwcodes[], __attr kwargs[], diff -r 22aea7bc1acd -r c498ceec120e templates/types.h --- a/templates/types.h Tue Nov 29 17:29:42 2016 +0100 +++ b/templates/types.h Tue Nov 29 22:09:52 2016 +0100 @@ -53,7 +53,7 @@ int intvalue; /* integer value */ double floatvalue; /* floating point value */ char * strvalue; /* string value */ - __fragment * data; /* sequence data */ + __fragment * seqvalue; /* sequence data */ }; } __attr; @@ -66,7 +66,8 @@ typedef __obj * __ref; -/* Fragments are simple collections of attributes employed by sequence types. */ +/* Fragments are simple collections of attributes employed by sequence types. + They provide the basis of lists and tuples. */ typedef struct __fragment {