1.1 --- a/generator.py Thu Mar 23 16:40:57 2017 +0100 1.2 +++ b/generator.py Thu Mar 23 23:36:32 2017 +0100 1.3 @@ -43,6 +43,7 @@ 1.4 # NOTE: These must be synchronised with the library. 1.5 1.6 function_type = "__builtins__.core.function" 1.7 + int_type = "__builtins__.int.int" 1.8 none_type = "__builtins__.none.NoneType" 1.9 string_type = "__builtins__.str.string" 1.10 type_type = "__builtins__.core.type" 1.11 @@ -359,6 +360,11 @@ 1.12 for constant, n in self.optimiser.constants.items(): 1.13 self.make_literal_constant(f_decls, f_defs, n, constant) 1.14 1.15 + # Generate a common integer instance object, referenced when integer 1.16 + # attributes are accessed. 1.17 + 1.18 + self.make_common_integer(f_decls, f_defs) 1.19 + 1.20 # Finish the main source file. 1.21 1.22 self.write_main_program(f_code, f_signatures) 1.23 @@ -504,6 +510,11 @@ 1.24 1.25 value, value_type, encoding = constant 1.26 1.27 + # Do not generate individual integer constants. 1.28 + 1.29 + if value_type == self.int_type: 1.30 + return 1.31 + 1.32 const_path = encode_literal_constant(n) 1.33 structure_name = encode_literal_reference(n) 1.34 1.35 @@ -526,13 +537,23 @@ 1.36 1.37 self.make_constant(f_decls, f_defs, ref, attr_path, structure_name) 1.38 1.39 + def make_common_integer(self, f_decls, f_defs): 1.40 + 1.41 + """ 1.42 + Write common integer instance details to 'f_decls' (to declare a 1.43 + structure) and to 'f_defs' (to define the contents). 1.44 + """ 1.45 + 1.46 + ref = Reference("<instance>", self.int_type) 1.47 + self.make_constant(f_decls, f_defs, ref, "__common_integer", "__common_integer_obj") 1.48 + 1.49 def make_constant(self, f_decls, f_defs, ref, const_path, structure_name, data=None, encoding=None): 1.50 1.51 """ 1.52 Write constant details to 'f_decls' (to declare a structure) and to 1.53 'f_defs' (to define the contents) for the constant described by 'ref' 1.54 - having the given 'path' and 'structure_name' (for the constant structure 1.55 - itself). 1.56 + having the given 'const_path' (providing an attribute for the constant) 1.57 + and 'structure_name' (for the constant structure itself). 1.58 1.59 The additional 'data' and 'encoding' are used to describe specific 1.60 values. 1.61 @@ -974,7 +995,7 @@ 1.62 # Special internal size member. 1.63 1.64 elif attrname == "__size__": 1.65 - structure.append("{.intvalue=%d}" % attr) 1.66 + structure.append("__INTVALUE(%d)" % attr) 1.67 continue 1.68 1.69 # Special internal key member. 1.70 @@ -1081,6 +1102,13 @@ 1.71 # Obtain a constant value directly assigned to the attribute. 1.72 1.73 if self.optimiser.constant_numbers.has_key(alias): 1.74 + 1.75 + # Encode integer constants differently. 1.76 + 1.77 + value, value_type, encoding = self.importer.all_constant_values[alias] 1.78 + if value_type == self.int_type: 1.79 + return "__INTVALUE(%s) /* %s */" % (value, name) 1.80 + 1.81 constant_number = self.optimiser.constant_numbers[alias] 1.82 constant_value = encode_literal_constant(constant_number) 1.83 return "%s /* %s */" % (constant_value, name) 1.84 @@ -1213,13 +1241,11 @@ 1.85 __Catch(__tmp_exc) 1.86 { 1.87 if (__ISINSTANCE(__tmp_exc.arg, __ATTRVALUE(&__builtins___exception_system_SystemExit))) 1.88 - return __load_via_object( 1.89 - __load_via_object(__tmp_exc.arg.value, __data__).value, 1.90 - value).intvalue; 1.91 + return __TOINT(__load_via_object(__VALUE(__tmp_exc.arg), value)); 1.92 1.93 fprintf(stderr, "Program terminated due to exception: %%s.\\n", 1.94 __load_via_object( 1.95 - %s(__ARGS(__NULL, __tmp_exc.arg)).value, 1.96 + __VALUE(%s(__ARGS(__NULL, __tmp_exc.arg))), 1.97 __data__).strvalue); 1.98 return 1; 1.99 }
2.1 --- a/lib/__builtins__/character.py Thu Mar 23 16:40:57 2017 +0100 2.2 +++ b/lib/__builtins__/character.py Thu Mar 23 23:36:32 2017 +0100 2.3 @@ -29,7 +29,7 @@ 2.4 check_int(i) 2.5 2.6 if 0 <= i <= 255: 2.7 - return str_chr(i.__data__) 2.8 + return str_chr(i) 2.9 else: 2.10 raise ValueError, i 2.11 2.12 @@ -94,7 +94,7 @@ 2.13 check_int(i) 2.14 2.15 if 0 <= i <= 2097151: 2.16 - return utf8string(unicode_unichr(i.__data__)) 2.17 + return utf8string(unicode_unichr(i)) 2.18 else: 2.19 raise ValueError, i 2.20
3.1 --- a/lib/__builtins__/int.py Thu Mar 23 16:40:57 2017 +0100 3.2 +++ b/lib/__builtins__/int.py Thu Mar 23 23:36:32 2017 +0100 3.3 @@ -3,7 +3,7 @@ 3.4 """ 3.5 Integer objects. 3.6 3.7 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> 3.8 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk> 3.9 3.10 This program is free software; you can redistribute it and/or modify it under 3.11 the terms of the GNU General Public License as published by the Free Software 3.12 @@ -34,11 +34,9 @@ 3.13 3.14 "Initialise the integer with the given 'number_or_string'." 3.15 3.16 - if _isinstance(number_or_string, int): 3.17 - self.__data__ = number_or_string.__data__ 3.18 - else: 3.19 - # NOTE: To be implemented. 3.20 - self.__data__ = None 3.21 + # NOTE: To be implemented. 3.22 + 3.23 + pass 3.24 3.25 def __hash__(self): 3.26 3.27 @@ -51,7 +49,7 @@ 3.28 "Perform 'op' on this int and 'other' if appropriate." 3.29 3.30 if _isinstance(other, int): 3.31 - return op(self.__data__, other.__data__) 3.32 + return op(self, other) 3.33 else: 3.34 return NotImplemented 3.35 3.36 @@ -60,7 +58,7 @@ 3.37 "Perform 'op' on 'other' and this int if appropriate." 3.38 3.39 if _isinstance(other, int): 3.40 - return op(other.__data__, self.__data__) 3.41 + return op(other, self) 3.42 else: 3.43 return NotImplemented 3.44 3.45 @@ -122,7 +120,7 @@ 3.46 3.47 "Return the inversion of this int." 3.48 3.49 - return int_not(self.__data__) 3.50 + return int_not(self) 3.51 3.52 __add__ = __radd__ = __iadd__ 3.53 __sub__ = __isub__ 3.54 @@ -206,7 +204,7 @@ 3.55 3.56 "Apply the unary negation operator." 3.57 3.58 - return int_neg(self.__data__) 3.59 + return int_neg(self) 3.60 3.61 def __pos__(self): 3.62 3.63 @@ -218,7 +216,7 @@ 3.64 3.65 "Return a string representation." 3.66 3.67 - return utf8string(int_str(self.__data__)) 3.68 + return utf8string(int_str(self)) 3.69 3.70 __repr__ = __str__ 3.71 3.72 @@ -233,8 +231,7 @@ 3.73 3.74 "Return whether this int is non-zero." 3.75 3.76 - zero = 0 3.77 - return int_ne(self.__data__, zero.__data__) 3.78 + return int_ne(self, 0) 3.79 3.80 # Limits. 3.81
4.1 --- a/lib/__builtins__/str.py Thu Mar 23 16:40:57 2017 +0100 4.2 +++ b/lib/__builtins__/str.py Thu Mar 23 23:36:32 2017 +0100 4.3 @@ -22,7 +22,7 @@ 4.4 from __builtins__.operator import _negate 4.5 from __builtins__.sequence import hashable, itemaccess 4.6 from __builtins__.types import check_int 4.7 -from native import int_new, str_add, str_lt, str_gt, str_eq, str_ord, \ 4.8 +from native import str_add, str_lt, str_gt, str_eq, str_ord, \ 4.9 str_substr 4.10 4.11 WHITESPACE = (" ", "\f", "\n", "\r", "\t") 4.12 @@ -53,7 +53,7 @@ 4.13 else: 4.14 self.__data__ = None 4.15 self.__key__ = None 4.16 - self.__size__ = None 4.17 + self.__size__ = 0 4.18 4.19 # Internal methods. 4.20 4.21 @@ -157,7 +157,7 @@ 4.22 4.23 "Return the number of bytes in this string." 4.24 4.25 - return int_new(self.__size__) 4.26 + return self.__size__ 4.27 4.28 # General type methods. 4.29 4.30 @@ -165,7 +165,7 @@ 4.31 4.32 "Return whether the string provides any data." 4.33 4.34 - return int_new(self.__size__).__bool__() 4.35 + return self.__size__.__bool__() 4.36 4.37 def __contains__(self, value): 4.38
5.1 --- a/lib/native/__init__.py Thu Mar 23 16:40:57 2017 +0100 5.2 +++ b/lib/native/__init__.py Thu Mar 23 23:36:32 2017 +0100 5.3 @@ -23,8 +23,7 @@ 5.4 5.5 from native.identity import is_, is_not 5.6 5.7 -from native.int import int_new, \ 5.8 - int_add, int_div, int_mod, int_mul, int_neg, int_pow, \ 5.9 +from native.int import int_add, int_div, int_mod, int_mul, int_neg, int_pow, \ 5.10 int_sub, int_and, int_not, int_or, int_xor, int_lt, \ 5.11 int_gt, int_eq, int_ne, int_str 5.12
6.1 --- a/lib/native/int.py Thu Mar 23 16:40:57 2017 +0100 6.2 +++ b/lib/native/int.py Thu Mar 23 23:36:32 2017 +0100 6.3 @@ -24,8 +24,6 @@ 6.4 this program. If not, see <http://www.gnu.org/licenses/>. 6.5 """ 6.6 6.7 -def int_new(data): pass 6.8 - 6.9 def int_add(self, other): pass 6.10 def int_div(self, other): pass 6.11 def int_mod(self, other): pass
7.1 --- a/templates/native/buffer.c Thu Mar 23 16:40:57 2017 +0100 7.2 +++ b/templates/native/buffer.c Thu Mar 23 23:36:32 2017 +0100 7.3 @@ -37,7 +37,7 @@ 7.4 7.5 /* Calculate the size of the string. */ 7.6 for (i = 0; i < data->size; i++) 7.7 - size += __load_via_object(data->attrs[i].value, __size__).intvalue; 7.8 + size += __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__)); 7.9 7.10 /* Reserve space for a new string. */ 7.11 s = (char *) __ALLOCATE(size + 1, sizeof(char)); 7.12 @@ -45,8 +45,8 @@ 7.13 /* Build a single string from the buffer contents. */ 7.14 for (i = 0, j = 0; i < data->size; i++) 7.15 { 7.16 - o = __load_via_object(data->attrs[i].value, __data__); 7.17 - n = __load_via_object(data->attrs[i].value, __size__).intvalue; 7.18 + o = __load_via_object(__VALUE(data->attrs[i]), __data__); 7.19 + n = __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__)); 7.20 memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */ 7.21 j += n; 7.22 }
8.1 --- a/templates/native/common.c Thu Mar 23 16:40:57 2017 +0100 8.2 +++ b/templates/native/common.c Thu Mar 23 23:36:32 2017 +0100 8.3 @@ -26,20 +26,12 @@ 8.4 8.5 /* Utility functions. */ 8.6 8.7 -__attr __new_int(int i) 8.8 -{ 8.9 - /* Create a new integer and mutate the __data__ attribute. */ 8.10 - __attr attr = __NEWINSTANCEIM(__builtins___int_int); 8.11 - attr.value->attrs[__ATTRPOS(__data__)].intvalue = i; 8.12 - return attr; 8.13 -} 8.14 - 8.15 __attr __new_str(char *s, int size) 8.16 { 8.17 /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */ 8.18 __attr attr = __NEWINSTANCE(__builtins___str_string); 8.19 attr.value->attrs[__ATTRPOS(__data__)].strvalue = s; 8.20 - attr.value->attrs[__ATTRPOS(__size__)].intvalue = size; 8.21 + attr.value->attrs[__ATTRPOS(__size__)] = __INTVALUE(size); 8.22 attr.value->attrs[__ATTRPOS(__key__)] = __NULL; 8.23 return attr; 8.24 }
9.1 --- a/templates/native/common.h Thu Mar 23 16:40:57 2017 +0100 9.2 +++ b/templates/native/common.h Thu Mar 23 23:36:32 2017 +0100 9.3 @@ -23,7 +23,7 @@ 9.4 9.5 /* Utility functions. */ 9.6 9.7 -__attr __new_int(int i); 9.8 +#define __new_int(VALUE) __INTVALUE(VALUE) 9.9 __attr __new_str(char *s, int size); 9.10 __attr __new_list(__fragment *f); 9.11 __fragment *__fragment_append(__fragment *data, __attr * const value);
10.1 --- a/templates/native/iconv.c Thu Mar 23 16:40:57 2017 +0100 10.2 +++ b/templates/native/iconv.c Thu Mar 23 23:36:32 2017 +0100 10.3 @@ -57,13 +57,13 @@ 10.4 /* cd interpreted as iconv_t */ 10.5 iconv_t c = (iconv_t) cd->datavalue; 10.6 /* state.__data__ interpreted as list */ 10.7 - __fragment *f = __load_via_object(state->value, __data__).seqvalue; 10.8 + __fragment *f = __load_via_object(__VALUE(*state), __data__).seqvalue; 10.9 10.10 /* Obtain the string, start position, and remaining bytes from the state. */ 10.11 10.12 - char *inbuf = __load_via_object(f->attrs[0].value, __data__).strvalue; 10.13 - int start = __load_via_object(f->attrs[1].value, __data__).intvalue; 10.14 - int remaining = __load_via_object(f->attrs[2].value, __data__).intvalue; 10.15 + char *inbuf = __load_via_object(__VALUE(f->attrs[0]), __data__).strvalue; 10.16 + int start = __TOINT(f->attrs[1]); 10.17 + int remaining = __TOINT(f->attrs[2]); 10.18 10.19 /* Allocate a string for the output buffer using the remaining input size 10.20 as a guide. */ 10.21 @@ -142,9 +142,9 @@ 10.22 __attr * const tocode = &__args[1]; 10.23 __attr * const fromcode = &__args[2]; 10.24 /* tocode.__data__ interpreted as string */ 10.25 - char *t = __load_via_object(tocode->value, __data__).strvalue; 10.26 + char *t = __load_via_object(__VALUE(*tocode), __data__).strvalue; 10.27 /* fromcode.__data__ interpreted as string */ 10.28 - char *f = __load_via_object(fromcode->value, __data__).strvalue; 10.29 + char *f = __load_via_object(__VALUE(*fromcode), __data__).strvalue; 10.30 iconv_t result; 10.31 __attr attr; 10.32
11.1 --- a/templates/native/identity.c Thu Mar 23 16:40:57 2017 +0100 11.2 +++ b/templates/native/identity.c Thu Mar 23 23:36:32 2017 +0100 11.3 @@ -1,6 +1,6 @@ 11.4 /* Native functions for identity operations. 11.5 11.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 11.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk> 11.8 11.9 This program is free software; you can redistribute it and/or modify it under 11.10 the terms of the GNU General Public License as published by the Free Software 11.11 @@ -31,6 +31,8 @@ 11.12 __attr * const x = &__args[1]; 11.13 __attr * const y = &__args[2]; 11.14 11.15 + /* NOTE: value member assumed equivalent to intvalue for comparison. */ 11.16 + 11.17 return x->value == y->value ? __builtins___boolean_True : __builtins___boolean_False; 11.18 } 11.19 11.20 @@ -39,6 +41,8 @@ 11.21 __attr * const x = &__args[1]; 11.22 __attr * const y = &__args[2]; 11.23 11.24 + /* NOTE: value member assumed equivalent to intvalue for comparison. */ 11.25 + 11.26 return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False; 11.27 } 11.28
12.1 --- a/templates/native/int.c Thu Mar 23 16:40:57 2017 +0100 12.2 +++ b/templates/native/int.c Thu Mar 23 23:36:32 2017 +0100 12.3 @@ -16,7 +16,6 @@ 12.4 this program. If not, see <http://www.gnu.org/licenses/>. 12.5 */ 12.6 12.7 -#include <limits.h> /* INT_MAX, INT_MIN */ 12.8 #include <math.h> /* ceil, log10, pow */ 12.9 #include <stdio.h> /* fdopen, snprintf */ 12.10 #include <errno.h> /* errno */ 12.11 @@ -32,24 +31,17 @@ 12.12 12.13 /* Integer operations. */ 12.14 12.15 -__attr __fn_native_int_int_new(__attr __args[]) 12.16 -{ 12.17 - __attr * const _data = &__args[1]; 12.18 - 12.19 - return __new_int(_data->intvalue); 12.20 -} 12.21 - 12.22 __attr __fn_native_int_int_add(__attr __args[]) 12.23 { 12.24 - __attr * const _data = &__args[1]; 12.25 + __attr * const self = &__args[1]; 12.26 __attr * const other = &__args[2]; 12.27 - /* _data and other interpreted as int */ 12.28 - int i = _data->intvalue; 12.29 - int j = other->intvalue; 12.30 + /* self and other interpreted as int */ 12.31 + int i = __TOINT(*self); 12.32 + int j = __TOINT(*other); 12.33 12.34 /* Test for overflow. */ 12.35 - if (((i > 0) && (j > 0) && (i > INT_MAX - j)) || 12.36 - ((i < 0) && (j < 0) && (i < INT_MIN - j))) 12.37 + if (((i > 0) && (j > 0) && (i > __MAXINT - j)) || 12.38 + ((i < 0) && (j < 0) && (i < __MININT - j))) 12.39 12.40 __raise_overflow_error(); 12.41 12.42 @@ -59,15 +51,15 @@ 12.43 12.44 __attr __fn_native_int_int_sub(__attr __args[]) 12.45 { 12.46 - __attr * const _data = &__args[1]; 12.47 + __attr * const self = &__args[1]; 12.48 __attr * const other = &__args[2]; 12.49 - /* _data and other interpreted as int */ 12.50 - int i = _data->intvalue; 12.51 - int j = other->intvalue; 12.52 + /* self and other interpreted as int */ 12.53 + int i = __TOINT(*self); 12.54 + int j = __TOINT(*other); 12.55 12.56 /* Test for overflow. */ 12.57 - if (((i < 0) && (j > 0) && (i < INT_MIN + j)) || 12.58 - ((i > 0) && (j < 0) && (i > INT_MAX + j))) 12.59 + if (((i < 0) && (j > 0) && (i < __MININT + j)) || 12.60 + ((i > 0) && (j < 0) && (i > __MAXINT + j))) 12.61 12.62 __raise_overflow_error(); 12.63 12.64 @@ -77,17 +69,17 @@ 12.65 12.66 __attr __fn_native_int_int_mul(__attr __args[]) 12.67 { 12.68 - __attr * const _data = &__args[1]; 12.69 + __attr * const self = &__args[1]; 12.70 __attr * const other = &__args[2]; 12.71 - /* _data and other interpreted as int */ 12.72 - int i = _data->intvalue; 12.73 - int j = other->intvalue; 12.74 + /* self and other interpreted as int */ 12.75 + int i = __TOINT(*self); 12.76 + int j = __TOINT(*other); 12.77 12.78 /* Test for overflow. */ 12.79 - if (((i > 0) && (j > 0) && (i > INT_MAX / j)) || 12.80 - ((i < 0) && (j < 0) && (i > INT_MAX / j)) || 12.81 - ((i < 0) && (j > 0) && (i < INT_MIN / j)) || 12.82 - ((i > 0) && (j < 0) && (j < INT_MIN / i))) 12.83 + if (((i > 0) && (j > 0) && (i > __MAXINT / j)) || 12.84 + ((i < 0) && (j < 0) && (i > __MAXINT / j)) || 12.85 + ((i < 0) && (j > 0) && (i < __MININT / j)) || 12.86 + ((i > 0) && (j < 0) && (j < __MININT / i))) 12.87 12.88 __raise_overflow_error(); 12.89 12.90 @@ -97,16 +89,16 @@ 12.91 12.92 __attr __fn_native_int_int_div(__attr __args[]) 12.93 { 12.94 - __attr * const _data = &__args[1]; 12.95 + __attr * const self = &__args[1]; 12.96 __attr * const other = &__args[2]; 12.97 - /* _data and other interpreted as int */ 12.98 - int i = _data->intvalue; 12.99 - int j = other->intvalue; 12.100 + /* self and other interpreted as int */ 12.101 + int i = __TOINT(*self); 12.102 + int j = __TOINT(*other); 12.103 12.104 /* Test for division by zero or overflow. */ 12.105 if (j == 0) 12.106 __raise_zero_division_error(); 12.107 - else if ((j == -1) && (i == INT_MIN)) 12.108 + else if ((j == -1) && (i == __MININT)) 12.109 __raise_overflow_error(); 12.110 12.111 /* Return the new integer. */ 12.112 @@ -115,16 +107,16 @@ 12.113 12.114 __attr __fn_native_int_int_mod(__attr __args[]) 12.115 { 12.116 - __attr * const _data = &__args[1]; 12.117 + __attr * const self = &__args[1]; 12.118 __attr * const other = &__args[2]; 12.119 - /* _data and other interpreted as int */ 12.120 - int i = _data->intvalue; 12.121 - int j = other->intvalue; 12.122 + /* self and other interpreted as int */ 12.123 + int i = __TOINT(*self); 12.124 + int j = __TOINT(*other); 12.125 12.126 /* Test for division by zero or overflow. */ 12.127 if (j == 0) 12.128 __raise_zero_division_error(); 12.129 - else if ((j == -1) && (i == INT_MIN)) 12.130 + else if ((j == -1) && (i == __MININT)) 12.131 __raise_overflow_error(); 12.132 12.133 /* Return the new integer. */ 12.134 @@ -133,12 +125,12 @@ 12.135 12.136 __attr __fn_native_int_int_neg(__attr __args[]) 12.137 { 12.138 - __attr * const _data = &__args[1]; 12.139 - /* _data interpreted as int */ 12.140 - int i = _data->intvalue; 12.141 + __attr * const self = &__args[1]; 12.142 + /* self interpreted as int */ 12.143 + int i = __TOINT(*self); 12.144 12.145 /* Test for overflow. */ 12.146 - if (i == INT_MIN) 12.147 + if (i == __MININT) 12.148 __raise_overflow_error(); 12.149 12.150 /* Return the new integer. */ 12.151 @@ -147,11 +139,11 @@ 12.152 12.153 __attr __fn_native_int_int_pow(__attr __args[]) 12.154 { 12.155 - __attr * const _data = &__args[1]; 12.156 + __attr * const self = &__args[1]; 12.157 __attr * const other = &__args[2]; 12.158 - /* _data and other interpreted as int */ 12.159 - int i = _data->intvalue; 12.160 - int j = other->intvalue; 12.161 + /* self and other interpreted as int */ 12.162 + int i = __TOINT(*self); 12.163 + int j = __TOINT(*other); 12.164 int k; 12.165 12.166 errno = 0; 12.167 @@ -168,11 +160,11 @@ 12.168 12.169 __attr __fn_native_int_int_and(__attr __args[]) 12.170 { 12.171 - __attr * const _data = &__args[1]; 12.172 + __attr * const self = &__args[1]; 12.173 __attr * const other = &__args[2]; 12.174 - /* _data and other interpreted as int */ 12.175 - int i = _data->intvalue; 12.176 - int j = other->intvalue; 12.177 + /* self and other interpreted as int */ 12.178 + int i = __TOINT(*self); 12.179 + int j = __TOINT(*other); 12.180 12.181 /* Return the new integer. */ 12.182 /* NOTE: No overflow test applied. */ 12.183 @@ -181,9 +173,9 @@ 12.184 12.185 __attr __fn_native_int_int_not(__attr __args[]) 12.186 { 12.187 - __attr * const _data = &__args[1]; 12.188 - /* _data interpreted as int */ 12.189 - int i = _data->intvalue; 12.190 + __attr * const self = &__args[1]; 12.191 + /* self interpreted as int */ 12.192 + int i = __TOINT(*self); 12.193 12.194 /* Return the new integer. */ 12.195 return __new_int(~i); 12.196 @@ -191,11 +183,11 @@ 12.197 12.198 __attr __fn_native_int_int_or(__attr __args[]) 12.199 { 12.200 - __attr * const _data = &__args[1]; 12.201 + __attr * const self = &__args[1]; 12.202 __attr * const other = &__args[2]; 12.203 - /* _data and other interpreted as int */ 12.204 - int i = _data->intvalue; 12.205 - int j = other->intvalue; 12.206 + /* self and other interpreted as int */ 12.207 + int i = __TOINT(*self); 12.208 + int j = __TOINT(*other); 12.209 12.210 /* Return the new integer. */ 12.211 /* NOTE: No overflow test applied. */ 12.212 @@ -204,11 +196,11 @@ 12.213 12.214 __attr __fn_native_int_int_xor(__attr __args[]) 12.215 { 12.216 - __attr * const _data = &__args[1]; 12.217 + __attr * const self = &__args[1]; 12.218 __attr * const other = &__args[2]; 12.219 - /* _data and other interpreted as int */ 12.220 - int i = _data->intvalue; 12.221 - int j = other->intvalue; 12.222 + /* self and other interpreted as int */ 12.223 + int i = __TOINT(*self); 12.224 + int j = __TOINT(*other); 12.225 12.226 /* Return the new integer. */ 12.227 /* NOTE: No overflow test applied. */ 12.228 @@ -217,11 +209,11 @@ 12.229 12.230 __attr __fn_native_int_int_lt(__attr __args[]) 12.231 { 12.232 - __attr * const _data = &__args[1]; 12.233 + __attr * const self = &__args[1]; 12.234 __attr * const other = &__args[2]; 12.235 - /* _data and other interpreted as int */ 12.236 - int i = _data->intvalue; 12.237 - int j = other->intvalue; 12.238 + /* self and other interpreted as int */ 12.239 + int i = __TOINT(*self); 12.240 + int j = __TOINT(*other); 12.241 12.242 /* Return a boolean result. */ 12.243 return i < j ? __builtins___boolean_True : __builtins___boolean_False; 12.244 @@ -229,11 +221,11 @@ 12.245 12.246 __attr __fn_native_int_int_gt(__attr __args[]) 12.247 { 12.248 - __attr * const _data = &__args[1]; 12.249 + __attr * const self = &__args[1]; 12.250 __attr * const other = &__args[2]; 12.251 - /* _data and other interpreted as int */ 12.252 - int i = _data->intvalue; 12.253 - int j = other->intvalue; 12.254 + /* self and other interpreted as int */ 12.255 + int i = __TOINT(*self); 12.256 + int j = __TOINT(*other); 12.257 12.258 /* Return a boolean result. */ 12.259 return i > j ? __builtins___boolean_True : __builtins___boolean_False; 12.260 @@ -241,11 +233,11 @@ 12.261 12.262 __attr __fn_native_int_int_eq(__attr __args[]) 12.263 { 12.264 - __attr * const _data = &__args[1]; 12.265 + __attr * const self = &__args[1]; 12.266 __attr * const other = &__args[2]; 12.267 - /* _data and other interpreted as int */ 12.268 - int i = _data->intvalue; 12.269 - int j = other->intvalue; 12.270 + /* self and other interpreted as int */ 12.271 + int i = __TOINT(*self); 12.272 + int j = __TOINT(*other); 12.273 12.274 /* Return a boolean result. */ 12.275 return i == j ? __builtins___boolean_True : __builtins___boolean_False; 12.276 @@ -253,11 +245,11 @@ 12.277 12.278 __attr __fn_native_int_int_ne(__attr __args[]) 12.279 { 12.280 - __attr * const _data = &__args[1]; 12.281 + __attr * const self = &__args[1]; 12.282 __attr * const other = &__args[2]; 12.283 - /* _data and other interpreted as int */ 12.284 - int i = _data->intvalue; 12.285 - int j = other->intvalue; 12.286 + /* self and other interpreted as int */ 12.287 + int i = __TOINT(*self); 12.288 + int j = __TOINT(*other); 12.289 12.290 /* Return a boolean result. */ 12.291 return i != j ? __builtins___boolean_True : __builtins___boolean_False; 12.292 @@ -265,12 +257,12 @@ 12.293 12.294 __attr __fn_native_int_int_str(__attr __args[]) 12.295 { 12.296 - __attr * const _data = &__args[1]; 12.297 - /* _data interpreted as int */ 12.298 - int i = _data->intvalue; 12.299 + __attr * const self = &__args[1]; 12.300 + /* self interpreted as int */ 12.301 + int i = __TOINT(*self); 12.302 /* Employ a buffer big enough to fit the largest integer plus an extra 12.303 character, a minus sign, and the null terminator. */ 12.304 - unsigned int n = (int) log10(INT_MAX) + 3; 12.305 + unsigned int n = (int) log10(__MAXINT) + 3; 12.306 char *s = (char *) __ALLOCATE(n, sizeof(char)); 12.307 12.308 snprintf(s, n, "%d", i);
13.1 --- a/templates/native/int.h Thu Mar 23 16:40:57 2017 +0100 13.2 +++ b/templates/native/int.h Thu Mar 23 23:36:32 2017 +0100 13.3 @@ -23,8 +23,6 @@ 13.4 13.5 /* Integer operations. */ 13.6 13.7 -__attr __fn_native_int_int_new(__attr __args[]); 13.8 - 13.9 __attr __fn_native_int_int_add(__attr __args[]); 13.10 __attr __fn_native_int_int_div(__attr __args[]); 13.11 __attr __fn_native_int_int_mod(__attr __args[]);
14.1 --- a/templates/native/introspection.c Thu Mar 23 16:40:57 2017 +0100 14.2 +++ b/templates/native/introspection.c Thu Mar 23 23:36:32 2017 +0100 14.3 @@ -32,7 +32,7 @@ 14.4 __attr * const name = &__args[2]; 14.5 __attr * const _default = &__args[3]; 14.6 /* name.__data__ interpreted as string */ 14.7 - __attr key = __load_via_object(name->value, __key__); 14.8 + __attr key = __load_via_object(__VALUE(*name), __key__); 14.9 __attr out; 14.10 14.11 if ((key.code == 0) && (key.pos == 0)) 14.12 @@ -40,13 +40,13 @@ 14.13 14.14 /* Attempt to get the attribute from the object. */ 14.15 14.16 - out = __check_and_load_via_object_null(obj->value, key.pos, key.code); 14.17 - if (out.value == 0) 14.18 + out = __check_and_load_via_object_null(__VALUE(*obj), key.pos, key.code); 14.19 + if (__ISNULL(out)) 14.20 { 14.21 /* Inspect the object's class if this failed. */ 14.22 14.23 - out = __check_and_load_via_class__(obj->value, key.pos, key.code); 14.24 - if (out.value == 0) 14.25 + out = __check_and_load_via_class__(__VALUE(*obj), key.pos, key.code); 14.26 + if (__ISNULL(out)) 14.27 return *_default; 14.28 14.29 /* Update the context to the object if it is a method. */ 14.30 @@ -63,7 +63,7 @@ 14.31 __attr * const cls = &__args[2]; 14.32 14.33 /* cls must be a class. */ 14.34 - if (__is_instance_subclass(obj->value, *cls)) 14.35 + if (__is_instance_subclass(__VALUE(*obj), *cls)) 14.36 return __builtins___boolean_True; 14.37 else 14.38 return __builtins___boolean_False; 14.39 @@ -75,7 +75,7 @@ 14.40 __attr * const cls = &__args[2]; 14.41 14.42 /* obj and cls must be classes. */ 14.43 - if (__is_subclass(obj->value, *cls)) 14.44 + if (__is_subclass(__VALUE(*obj), *cls)) 14.45 return __builtins___boolean_True; 14.46 else 14.47 return __builtins___boolean_False;
15.1 --- a/templates/native/io.c Thu Mar 23 16:40:57 2017 +0100 15.2 +++ b/templates/native/io.c Thu Mar 23 23:36:32 2017 +0100 15.3 @@ -62,9 +62,9 @@ 15.4 __attr * const filename = &__args[1]; 15.5 __attr * const mode = &__args[2]; 15.6 /* filename.__data__ interpreted as string */ 15.7 - char *fn = __load_via_object(filename->value, __data__).strvalue; 15.8 + char *fn = __load_via_object(__VALUE(*filename), __data__).strvalue; 15.9 /* mode.__data__ interpreted as string */ 15.10 - char *s = __load_via_object(mode->value, __data__).strvalue; 15.11 + char *s = __load_via_object(__VALUE(*mode), __data__).strvalue; 15.12 FILE *f; 15.13 __attr attr; 15.14 15.15 @@ -93,10 +93,10 @@ 15.16 { 15.17 __attr * const fd = &__args[1]; 15.18 __attr * const mode = &__args[2]; 15.19 - /* fd.__data__ interpreted as int */ 15.20 - int i = __load_via_object(fd->value, __data__).intvalue; 15.21 + /* fd interpreted as int */ 15.22 + int i = __TOINT(*fd); 15.23 /* mode.__data__ interpreted as string */ 15.24 - char *s = __load_via_object(mode->value, __data__).strvalue; 15.25 + char *s = __load_via_object(__VALUE(*mode), __data__).strvalue; 15.26 FILE *f; 15.27 __attr attr; 15.28 15.29 @@ -127,8 +127,8 @@ 15.30 __attr * const size = &__args[2]; 15.31 /* fp interpreted as FILE reference */ 15.32 FILE *f = (FILE *) fp->datavalue; 15.33 - /* size.__data__ interpreted as int */ 15.34 - int to_read = __load_via_object(size->value, __data__).intvalue; 15.35 + /* size interpreted as int */ 15.36 + int to_read = __TOINT(*size); 15.37 char buf[to_read]; 15.38 size_t have_read; 15.39 int error; 15.40 @@ -158,9 +158,9 @@ 15.41 /* fp interpreted as FILE reference */ 15.42 FILE *f = (FILE *) fp->datavalue; 15.43 /* str.__data__ interpreted as string */ 15.44 - char *s = __load_via_object(str->value, __data__).strvalue; 15.45 + char *s = __load_via_object(__VALUE(*str), __data__).strvalue; 15.46 /* str.__size__ interpreted as int */ 15.47 - int to_write = __load_via_object(str->value, __size__).intvalue; 15.48 + int to_write = __TOINT(__load_via_object(__VALUE(*str), __size__)); 15.49 size_t have_written = fwrite(s, sizeof(char), to_write, f); 15.50 int error; 15.51 15.52 @@ -178,8 +178,8 @@ 15.53 __attr __fn_native_io_close(__attr __args[]) 15.54 { 15.55 __attr * const fd = &__args[1]; 15.56 - /* fd.__data__ interpreted as int */ 15.57 - int i = __load_via_object(fd->value, __data__).intvalue; 15.58 + /* fd interpreted as int */ 15.59 + int i = __TOINT(*fd); 15.60 15.61 errno = 0; 15.62 if (close(i) == -1) 15.63 @@ -192,10 +192,10 @@ 15.64 { 15.65 __attr * const fd = &__args[1]; 15.66 __attr * const n = &__args[2]; 15.67 - /* fd.__data__ interpreted as int */ 15.68 - int i = __load_via_object(fd->value, __data__).intvalue; 15.69 - /* n.__data__ interpreted as int */ 15.70 - int to_read = __load_via_object(n->value, __data__).intvalue; 15.71 + /* fd interpreted as int */ 15.72 + int i = __TOINT(*fd); 15.73 + /* n interpreted as int */ 15.74 + int to_read = __TOINT(*n); 15.75 char buf[to_read]; 15.76 ssize_t have_read; 15.77 char *s; 15.78 @@ -217,12 +217,12 @@ 15.79 { 15.80 __attr * const fd = &__args[1]; 15.81 __attr * const str = &__args[2]; 15.82 - /* fd.__data__ interpreted as int */ 15.83 - int i = __load_via_object(fd->value, __data__).intvalue; 15.84 + /* fd interpreted as int */ 15.85 + int i = __TOINT(*fd); 15.86 /* str.__data__ interpreted as string */ 15.87 - char *s = __load_via_object(str->value, __data__).strvalue; 15.88 + char *s = __load_via_object(__VALUE(*str), __data__).strvalue; 15.89 /* str.__size__ interpreted as int */ 15.90 - int size = __load_via_object(str->value, __size__).intvalue; 15.91 + int size = __TOINT(__load_via_object(__VALUE(*str), __size__)); 15.92 ssize_t have_written; 15.93 15.94 errno = 0;
16.1 --- a/templates/native/limits.c Thu Mar 23 16:40:57 2017 +0100 16.2 +++ b/templates/native/limits.c Thu Mar 23 23:36:32 2017 +0100 16.3 @@ -1,6 +1,6 @@ 16.4 /* Native functions for limit definition. 16.5 16.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 16.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk> 16.8 16.9 This program is free software; you can redistribute it and/or modify it under 16.10 the terms of the GNU General Public License as published by the Free Software 16.11 @@ -16,7 +16,6 @@ 16.12 this program. If not, see <http://www.gnu.org/licenses/>. 16.13 */ 16.14 16.15 -#include <limits.h> /* INT_MAX, INT_MIN */ 16.16 #include "native/common.h" 16.17 #include "types.h" 16.18 #include "exceptions.h" 16.19 @@ -30,12 +29,12 @@ 16.20 16.21 __attr __fn_native_limits_get_maxint(__attr __args[]) 16.22 { 16.23 - return __new_int(INT_MAX); 16.24 + return __new_int(__MAXINT); 16.25 } 16.26 16.27 __attr __fn_native_limits_get_minint(__attr __args[]) 16.28 { 16.29 - return __new_int(INT_MIN); 16.30 + return __new_int(__MININT); 16.31 } 16.32 16.33 /* Module initialisation. */
17.1 --- a/templates/native/list.c Thu Mar 23 16:40:57 2017 +0100 17.2 +++ b/templates/native/list.c Thu Mar 23 23:36:32 2017 +0100 17.3 @@ -30,8 +30,8 @@ 17.4 __attr __fn_native_list_list_init(__attr __args[]) 17.5 { 17.6 __attr * const size = &__args[1]; 17.7 - /* size.__data__ interpreted as int */ 17.8 - unsigned int n = __load_via_object(size->value, __data__).intvalue; 17.9 + /* size interpreted as int */ 17.10 + unsigned int n = __TOINT(*size); 17.11 __attr attr = {.seqvalue=__new_fragment(n)}; 17.12 17.13 /* Return the __data__ attribute. */ 17.14 @@ -44,8 +44,8 @@ 17.15 __attr * const size = &__args[2]; 17.16 /* _data interpreted as list */ 17.17 __fragment *data = _data->seqvalue; 17.18 - /* size.__data__ interpreted as int */ 17.19 - unsigned int n = __load_via_object(size->value, __data__).intvalue; 17.20 + /* size interpreted as int */ 17.21 + unsigned int n = __TOINT(*size); 17.22 17.23 data->size = n; 17.24 return __builtins___none_None; 17.25 @@ -56,12 +56,12 @@ 17.26 __attr * const self = &__args[1]; 17.27 __attr * const value = &__args[2]; 17.28 /* self.__data__ interpreted as list */ 17.29 - __fragment *data = __load_via_object(self->value, __data__).seqvalue; 17.30 + __fragment *data = __load_via_object(__VALUE(*self), __data__).seqvalue; 17.31 __fragment *newdata = __fragment_append(data, value); 17.32 17.33 /* Replace the __data__ attribute if appropriate. */ 17.34 if (newdata != data) 17.35 - __store_via_object(self->value, __data__, ((__attr) {.seqvalue=newdata})); 17.36 + __store_via_object(__VALUE(*self), __data__, ((__attr) {.seqvalue=newdata})); 17.37 return __builtins___none_None; 17.38 } 17.39 17.40 @@ -70,7 +70,7 @@ 17.41 __attr * const self = &__args[1]; 17.42 __attr * const other = &__args[2]; 17.43 /* self.__data__, other interpreted as list */ 17.44 - __fragment *data = __load_via_object(self->value, __data__).seqvalue; 17.45 + __fragment *data = __load_via_object(__VALUE(*self), __data__).seqvalue; 17.46 __fragment *other_data = other->seqvalue; 17.47 __fragment *newdata = data; 17.48 unsigned int size = data->size, capacity = data->capacity; 17.49 @@ -91,7 +91,7 @@ 17.50 17.51 /* Replace the __data__ attribute if appropriate. */ 17.52 if (newdata != data) 17.53 - __store_via_object(self->value, __data__, ((__attr) {.seqvalue=newdata})); 17.54 + __store_via_object(__VALUE(*self), __data__, ((__attr) {.seqvalue=newdata})); 17.55 return __builtins___none_None; 17.56 } 17.57 17.58 @@ -118,8 +118,8 @@ 17.59 __attr * const index = &__args[2]; 17.60 /* _data interpreted as fragment */ 17.61 __attr *elements = _data->seqvalue->attrs; 17.62 - /* index.__data__ interpreted as int */ 17.63 - int i = __load_via_object(index->value, __data__).intvalue; 17.64 + /* index interpreted as int */ 17.65 + int i = __TOINT(*index); 17.66 17.67 return elements[i]; 17.68 } 17.69 @@ -131,8 +131,8 @@ 17.70 __attr * const value = &__args[3]; 17.71 /* _data interpreted as fragment */ 17.72 __attr *elements = _data->seqvalue->attrs; 17.73 - /* index.__data__ interpreted as int */ 17.74 - int i = __load_via_object(index->value, __data__).intvalue; 17.75 + /* index interpreted as int */ 17.76 + int i = __TOINT(*index); 17.77 17.78 /* Set the element. */ 17.79 elements[i] = *value;
18.1 --- a/templates/native/locale.c Thu Mar 23 16:40:57 2017 +0100 18.2 +++ b/templates/native/locale.c Thu Mar 23 23:36:32 2017 +0100 18.3 @@ -32,8 +32,8 @@ 18.4 __attr __fn_native_locale_getlocale(__attr __args[]) 18.5 { 18.6 __attr * const category = &__args[1]; 18.7 - /* category.__data__ interpreted as int */ 18.8 - int cat = __load_via_object(category->value, __data__).intvalue; 18.9 + /* category interpreted as int */ 18.10 + int cat = __TOINT(*category); 18.11 char *result, *out; 18.12 size_t length; 18.13 18.14 @@ -53,10 +53,10 @@ 18.15 { 18.16 __attr * const category = &__args[1]; 18.17 __attr * const value = &__args[2]; 18.18 - /* category.__data__ interpreted as int */ 18.19 - int cat = __load_via_object(category->value, __data__).intvalue; 18.20 + /* category interpreted as int */ 18.21 + int cat = __TOINT(*category); 18.22 /* value.__data__ interpreted as string */ 18.23 - char *s = __load_via_object(value->value, __data__).strvalue; 18.24 + char *s = __load_via_object(__VALUE(*value), __data__).strvalue; 18.25 char *result, *out; 18.26 size_t length; 18.27
19.1 --- a/templates/native/str.c Thu Mar 23 16:40:57 2017 +0100 19.2 +++ b/templates/native/str.c Thu Mar 23 23:36:32 2017 +0100 19.3 @@ -37,7 +37,7 @@ 19.4 /* _data, other interpreted as string */ 19.5 char *s = _data->strvalue; 19.6 char *o = other->strvalue; 19.7 - int ss = _size->intvalue, os = othersize->intvalue; 19.8 + int ss = __TOINT(*_size), os = __TOINT(*othersize); 19.9 int n = ss + os; 19.10 char *r = (char *) __ALLOCATE(n + 1, sizeof(char)); 19.11 19.12 @@ -50,9 +50,9 @@ 19.13 19.14 __attr __fn_native_str_str_chr(__attr __args[]) 19.15 { 19.16 - __attr * const _data = &__args[1]; 19.17 - /* _data interpreted as int */ 19.18 - int n = _data->intvalue; 19.19 + __attr * const data = &__args[1]; 19.20 + /* data interpreted as int */ 19.21 + int n = __TOINT(*data); 19.22 char *s = (char *) __ALLOCATE(2, sizeof(char)); 19.23 19.24 s[0] = (char) n; 19.25 @@ -112,12 +112,12 @@ 19.26 __attr * const step = &__args[4]; 19.27 /* _data interpreted as string */ 19.28 char *s = _data->strvalue, *sub; 19.29 - /* start.__data__ interpreted as int */ 19.30 - int istart = __load_via_object(start->value, __data__).intvalue; 19.31 - /* end.__data__ interpreted as int */ 19.32 - int iend = __load_via_object(end->value, __data__).intvalue; 19.33 - /* step.__data__ interpreted as int */ 19.34 - int istep = __load_via_object(step->value, __data__).intvalue; 19.35 + /* start interpreted as int */ 19.36 + int istart = __TOINT(*start); 19.37 + /* end interpreted as int */ 19.38 + int iend = __TOINT(*end); 19.39 + /* step interpreted as int */ 19.40 + int istep = __TOINT(*step); 19.41 19.42 /* Calculate the size of the substring. */ 19.43 size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
20.1 --- a/templates/native/system.c Thu Mar 23 16:40:57 2017 +0100 20.2 +++ b/templates/native/system.c Thu Mar 23 23:36:32 2017 +0100 20.3 @@ -31,7 +31,7 @@ 20.4 { 20.5 __attr * const status = &__args[1]; 20.6 20.7 - exit(__load_via_object(status->value, __data__).intvalue); 20.8 + exit(__VALUE(*status)); 20.9 return __builtins___none_None; 20.10 } 20.11
21.1 --- a/templates/native/unicode.c Thu Mar 23 16:40:57 2017 +0100 21.2 +++ b/templates/native/unicode.c Thu Mar 23 23:36:32 2017 +0100 21.3 @@ -76,7 +76,7 @@ 21.4 /* _data interpreted as string */ 21.5 char *s = _data->strvalue; 21.6 /* _size interpreted as int */ 21.7 - int size = _size->intvalue; 21.8 + int size = __TOINT(*_size); 21.9 unsigned int i, c = 0; 21.10 21.11 for (i = 0; i < size; i++) 21.12 @@ -94,7 +94,7 @@ 21.13 /* _data interpreted as string */ 21.14 char *s = _data->strvalue; 21.15 /* _size interpreted as int */ 21.16 - int size = _size->intvalue; 21.17 + int size = __TOINT(*_size); 21.18 unsigned int i, c = 0, v; 21.19 21.20 for (i = 0; i < size; i++) 21.21 @@ -133,13 +133,13 @@ 21.22 /* _data interpreted as string */ 21.23 char *s = _data->strvalue, *sub; 21.24 /* _size interpreted as int */ 21.25 - int ss = _size->intvalue; 21.26 - /* start.__data__ interpreted as int */ 21.27 - int istart = __load_via_object(start->value, __data__).intvalue; 21.28 - /* end.__data__ interpreted as int */ 21.29 - int iend = __load_via_object(end->value, __data__).intvalue; 21.30 - /* step.__data__ interpreted as int */ 21.31 - int istep = __load_via_object(step->value, __data__).intvalue; 21.32 + int ss = __TOINT(*_size); 21.33 + /* start interpreted as int */ 21.34 + int istart = __TOINT(*start); 21.35 + /* end interpreted as int */ 21.36 + int iend = __TOINT(*end); 21.37 + /* step interpreted as int */ 21.38 + int istep = __TOINT(*step); 21.39 21.40 /* Calculate the number of characters. */ 21.41 size_t nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1; 21.42 @@ -206,7 +206,7 @@ 21.43 { 21.44 __attr * const value = &__args[1]; 21.45 /* value interpreted as int */ 21.46 - int i = value->intvalue; 21.47 + int i = __TOINT(*value); 21.48 unsigned int resultsize; 21.49 char *s; 21.50
22.1 --- a/templates/ops.c Thu Mar 23 16:40:57 2017 +0100 22.2 +++ b/templates/ops.c Thu Mar 23 23:36:32 2017 +0100 22.3 @@ -27,7 +27,10 @@ 22.4 22.5 __ref __VALUE(__attr attr) 22.6 { 22.7 - return attr.value; 22.8 + if (!__INTEGER(attr)) 22.9 + return attr.value; 22.10 + else 22.11 + return &__common_integer_obj; 22.12 } 22.13 22.14 /* Basic structure tests. */
23.1 --- a/templates/progops.c Thu Mar 23 16:40:57 2017 +0100 23.2 +++ b/templates/progops.c Thu Mar 23 23:36:32 2017 +0100 23.3 @@ -73,7 +73,7 @@ 23.4 23.5 /* Store a reference to the data in the object's __data__ attribute. */ 23.6 23.7 - __store_via_object(args[0].value, __data__, attr); 23.8 + __store_via_object(__VALUE(args[0]), __data__, attr); 23.9 } 23.10 23.11 #ifdef __HAVE___builtins___dict_dict 23.12 @@ -221,7 +221,7 @@ 23.13 /* Erase the remaining arguments. */ 23.14 23.15 for (pos = nargs; pos < max; pos++) 23.16 - allargs[pos].value = 0; 23.17 + __SETNULL(allargs[pos]); 23.18 23.19 /* Fill keyword arguments. */ 23.20 23.21 @@ -246,7 +246,7 @@ 23.22 23.23 for (pos = nargs; pos < max; pos++) 23.24 { 23.25 - if (allargs[pos].value == 0) 23.26 + if (__ISNULL(allargs[pos])) 23.27 allargs[pos] = __GETDEFAULT(__VALUE(target), pos - min); 23.28 } 23.29 }
24.1 --- a/templates/types.h Thu Mar 23 16:40:57 2017 +0100 24.2 +++ b/templates/types.h Thu Mar 23 23:36:32 2017 +0100 24.3 @@ -72,14 +72,19 @@ 24.4 24.5 typedef union __attr 24.6 { 24.7 + /* General attribute members. */ 24.8 + 24.9 __ref value; /* attribute value */ 24.10 + int intvalue; /* integer value data ((integer << 1) | 1) */ 24.11 + 24.12 + /* Special case attribute members. */ 24.13 + 24.14 const __ptable * ptable; /* parameter table */ 24.15 struct { 24.16 __pcode code; /* parameter table code for key */ 24.17 __ppos pos; /* parameter table position for key */ 24.18 }; 24.19 __attr (*fn)(); /* callable details */ 24.20 - int intvalue; /* integer value */ 24.21 float floatvalue; /* floating point value */ 24.22 char * strvalue; /* string value */ 24.23 __fragment * seqvalue; /* sequence data */ 24.24 @@ -106,10 +111,22 @@ 24.25 24.26 #define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(unsigned int)) 24.27 24.28 +/* Attribute interpretation. */ 24.29 + 24.30 +#define __INTEGER(ATTR) ((ATTR).intvalue % 2) 24.31 + 24.32 /* Attribute value setting. */ 24.33 24.34 #define __ATTRVALUE(VALUE) ((__attr) {.value=VALUE}) 24.35 #define __NULL __ATTRVALUE(0) 24.36 +#define __SETNULL(ATTR) ((ATTR).value = 0) 24.37 + 24.38 +/* Attribute as instance setting. */ 24.39 + 24.40 +#define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << 1) | 1}) 24.41 +#define __TOINT(ATTR) ((ATTR).intvalue >> 1) 24.42 +#define __MAXINT ((1 << ((sizeof(__attr) * 8) - 2)) - 1) 24.43 +#define __MININT (-(1 << ((sizeof(__attr) * 8) - 2))) 24.44 24.45 /* Argument lists. */ 24.46
25.1 --- a/tests/numbers.py Thu Mar 23 16:40:57 2017 +0100 25.2 +++ b/tests/numbers.py Thu Mar 23 23:36:32 2017 +0100 25.3 @@ -10,15 +10,15 @@ 25.4 print "# sys.maxint + sys.minint:", 25.5 print sys.maxint + sys.minint 25.6 25.7 -i = 2 ** 30 25.8 -print i # 1073741824 25.9 -print hex(i) # 0x40000000 25.10 -print oct(i) # 010000000000 25.11 +i = 2 ** 29 25.12 +print i # 536870912 25.13 +print hex(i) # 0x20000000 25.14 +print oct(i) # 04000000000 25.15 25.16 -j = -2 ** 30 25.17 -print j # -1073741824 25.18 -print hex(j) # -0x40000000 25.19 -print oct(j) # -010000000000 25.20 +j = -2 ** 29 25.21 +print j # -536870912 25.22 +print hex(j) # -0x20000000 25.23 +print oct(j) # -05000000000 25.24 25.25 print i + j # 0 25.26 25.27 @@ -39,9 +39,9 @@ 25.28 25.29 print i - i # 0 25.30 print j - j # 0 25.31 -print ~j # 1073741823 25.32 +print ~j # 536870911 25.33 print i & ~j # 0 25.34 -print i - 1 & ~j # 1073741823 25.35 +print i - 1 & ~j # 536870911 25.36 25.37 print hex(31) # 0x1f 25.38 print oct(31) # 037
26.1 --- a/transresults.py Thu Mar 23 16:40:57 2017 +0100 26.2 +++ b/transresults.py Thu Mar 23 23:36:32 2017 +0100 26.3 @@ -140,7 +140,13 @@ 26.4 "A constant value reference in the translation." 26.5 26.6 def __str__(self): 26.7 - return encode_literal_constant(self.number) 26.8 + 26.9 + # NOTE: Should reference a common variable for the type name. 26.10 + 26.11 + if self.ref.get_origin() == "__builtins__.int.int": 26.12 + return "__INTVALUE(%s)" % self.value 26.13 + else: 26.14 + return encode_literal_constant(self.number) 26.15 26.16 class TrLiteralSequenceRef(LiteralSequenceRef): 26.17