1.1 --- a/templates/native.c Tue Nov 22 17:20:56 2016 +0100
1.2 +++ b/templates/native.c Tue Nov 22 17:36:39 2016 +0100
1.3 @@ -33,258 +33,224 @@
1.4
1.5 __attr __fn_native__exit(__attr __args[])
1.6 {
1.7 - #define status (__args[1])
1.8 + __attr * const status = &__args[1];
1.9
1.10 - exit(__load_via_object(status.value, __pos___data__).intvalue);
1.11 + exit(__load_via_object(status->value, __pos___data__).intvalue);
1.12 return __builtins___none_None;
1.13 - #undef status
1.14 }
1.15
1.16 __attr __fn_native__get_argv(__attr __args[])
1.17 {
1.18 - #define status (__args[1])
1.19 + __attr * const status = &__args[1];
1.20
1.21 /* NOTE: To be written. */
1.22 return __builtins___none_None;
1.23 - #undef status
1.24 }
1.25
1.26 __attr __fn_native__get_path(__attr __args[])
1.27 {
1.28 - #define status (__args[1])
1.29 + __attr * const status = &__args[1];
1.30
1.31 /* NOTE: To be written. */
1.32 return __builtins___none_None;
1.33 - #undef status
1.34 }
1.35
1.36 __attr __fn_native__is(__attr __args[])
1.37 {
1.38 - #define x (__args[1])
1.39 - #define y (__args[2])
1.40 + __attr * const x = &__args[1];
1.41 + __attr * const y = &__args[2];
1.42
1.43 - return x.value == y.value ? __builtins___boolean_True : __builtins___boolean_False;
1.44 - #undef x
1.45 - #undef y
1.46 + return x->value == y->value ? __builtins___boolean_True : __builtins___boolean_False;
1.47 }
1.48
1.49 __attr __fn_native__is_not(__attr __args[])
1.50 {
1.51 - #define x (__args[1])
1.52 - #define y (__args[2])
1.53 + __attr * const x = &__args[1];
1.54 + __attr * const y = &__args[2];
1.55
1.56 - return x.value != y.value ? __builtins___boolean_True : __builtins___boolean_False;
1.57 - #undef x
1.58 - #undef y
1.59 + return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False;
1.60 }
1.61
1.62 __attr __fn_native__int_add(__attr __args[])
1.63 {
1.64 - #define self (__args[1])
1.65 - #define other (__args[2])
1.66 + __attr * const self = &__args[1];
1.67 + __attr * const other = &__args[2];
1.68 /* self.__data__ and other.__data__ interpreted as int */
1.69 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.70 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.71 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.72 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.73
1.74 /* Return the new integer. */
1.75 /* NOTE: No overflow test applied. */
1.76 return __new_int(i + j);
1.77 - #undef self
1.78 - #undef other
1.79 }
1.80
1.81 __attr __fn_native__int_sub(__attr __args[])
1.82 {
1.83 - #define self (__args[1])
1.84 - #define other (__args[2])
1.85 + __attr * const self = &__args[1];
1.86 + __attr * const other = &__args[2];
1.87 /* self.__data__ and other.__data__ interpreted as int */
1.88 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.89 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.90 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.91 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.92
1.93 /* Return the new integer. */
1.94 /* NOTE: No overflow test applied. */
1.95 return __new_int(i - j);
1.96 - #undef self
1.97 - #undef other
1.98 }
1.99
1.100 __attr __fn_native__int_mul(__attr __args[])
1.101 {
1.102 - #define self (__args[1])
1.103 - #define other (__args[2])
1.104 + __attr * const self = &__args[1];
1.105 + __attr * const other = &__args[2];
1.106 /* self.__data__ and other.__data__ interpreted as int */
1.107 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.108 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.109 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.110 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.111
1.112 /* Return the new integer. */
1.113 /* NOTE: No overflow test applied. */
1.114 return __new_int(i * j);
1.115 - #undef self
1.116 - #undef other
1.117 }
1.118
1.119 __attr __fn_native__int_div(__attr __args[])
1.120 {
1.121 - #define self (__args[1])
1.122 - #define other (__args[2])
1.123 + __attr * const self = &__args[1];
1.124 + __attr * const other = &__args[2];
1.125 /* self.__data__ and other.__data__ interpreted as int */
1.126 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.127 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.128 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.129 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.130
1.131 /* Return the new integer. */
1.132 /* NOTE: No overflow test applied. */
1.133 return __new_int(i / j);
1.134 - #undef self
1.135 - #undef other
1.136 }
1.137
1.138 __attr __fn_native__int_mod(__attr __args[])
1.139 {
1.140 - #define self (__args[1])
1.141 - #define other (__args[2])
1.142 + __attr * const self = &__args[1];
1.143 + __attr * const other = &__args[2];
1.144 /* self.__data__ and other.__data__ interpreted as int */
1.145 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.146 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.147 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.148 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.149
1.150 /* Return the new integer. */
1.151 /* NOTE: No overflow test applied. */
1.152 return __new_int(i % j);
1.153 - #undef self
1.154 - #undef other
1.155 }
1.156
1.157 __attr __fn_native__int_neg(__attr __args[])
1.158 {
1.159 - #define self (__args[1])
1.160 + __attr * const self = &__args[1];
1.161 /* self.__data__ interpreted as int */
1.162 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.163 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.164
1.165 /* Return the new integer. */
1.166 return __new_int(-i);
1.167 - #undef self
1.168 }
1.169
1.170 __attr __fn_native__int_pow(__attr __args[])
1.171 {
1.172 - #define self (__args[1])
1.173 - #define other (__args[2])
1.174 + __attr * const self = &__args[1];
1.175 + __attr * const other = &__args[2];
1.176 /* self.__data__ and other.__data__ interpreted as int */
1.177 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.178 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.179 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.180 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.181
1.182 /* Return the new integer. */
1.183 /* NOTE: No overflow test applied. */
1.184 return __new_int((int) pow(i, j));
1.185 - #undef self
1.186 - #undef other
1.187 }
1.188
1.189 __attr __fn_native__int_and(__attr __args[])
1.190 {
1.191 - #define self (__args[1])
1.192 - #define other (__args[2])
1.193 + __attr * const self = &__args[1];
1.194 + __attr * const other = &__args[2];
1.195 /* self.__data__ and other.__data__ interpreted as int */
1.196 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.197 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.198 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.199 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.200
1.201 /* Return the new integer. */
1.202 /* NOTE: No overflow test applied. */
1.203 return __new_int(i & j);
1.204 - #undef self
1.205 - #undef other
1.206 }
1.207
1.208 __attr __fn_native__int_or(__attr __args[])
1.209 {
1.210 - #define self (__args[1])
1.211 - #define other (__args[2])
1.212 + __attr * const self = &__args[1];
1.213 + __attr * const other = &__args[2];
1.214 /* self.__data__ and other.__data__ interpreted as int */
1.215 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.216 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.217 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.218 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.219
1.220 /* Return the new integer. */
1.221 /* NOTE: No overflow test applied. */
1.222 return __new_int(i | j);
1.223 - #undef self
1.224 - #undef other
1.225 }
1.226
1.227 __attr __fn_native__int_xor(__attr __args[])
1.228 {
1.229 - #define self (__args[1])
1.230 - #define other (__args[2])
1.231 + __attr * const self = &__args[1];
1.232 + __attr * const other = &__args[2];
1.233 /* self.__data__ and other.__data__ interpreted as int */
1.234 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.235 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.236 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.237 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.238
1.239 /* Return the new integer. */
1.240 /* NOTE: No overflow test applied. */
1.241 return __new_int(i ^ j);
1.242 - #undef self
1.243 - #undef other
1.244 }
1.245
1.246 __attr __fn_native__int_lt(__attr __args[])
1.247 {
1.248 - #define self (__args[1])
1.249 - #define other (__args[2])
1.250 + __attr * const self = &__args[1];
1.251 + __attr * const other = &__args[2];
1.252 /* self.__data__ and other.__data__ interpreted as int */
1.253 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.254 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.255 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.256 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.257
1.258 /* Return a boolean result. */
1.259 return i < j ? __builtins___boolean_True : __builtins___boolean_False;
1.260 - #undef self
1.261 - #undef other
1.262 }
1.263
1.264 __attr __fn_native__int_gt(__attr __args[])
1.265 {
1.266 - #define self (__args[1])
1.267 - #define other (__args[2])
1.268 + __attr * const self = &__args[1];
1.269 + __attr * const other = &__args[2];
1.270 /* self.__data__ and other.__data__ interpreted as int */
1.271 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.272 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.273 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.274 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.275
1.276 /* Return a boolean result. */
1.277 return i > j ? __builtins___boolean_True : __builtins___boolean_False;
1.278 - #undef self
1.279 - #undef other
1.280 }
1.281
1.282 __attr __fn_native__int_eq(__attr __args[])
1.283 {
1.284 - #define self (__args[1])
1.285 - #define other (__args[2])
1.286 + __attr * const self = &__args[1];
1.287 + __attr * const other = &__args[2];
1.288 /* self.__data__ and other.__data__ interpreted as int */
1.289 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.290 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.291 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.292 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.293
1.294 /* Return a boolean result. */
1.295 return i == j ? __builtins___boolean_True : __builtins___boolean_False;
1.296 - #undef self
1.297 - #undef other
1.298 }
1.299
1.300 __attr __fn_native__int_ne(__attr __args[])
1.301 {
1.302 - #define self (__args[1])
1.303 - #define other (__args[2])
1.304 + __attr * const self = &__args[1];
1.305 + __attr * const other = &__args[2];
1.306 /* self.__data__ and other.__data__ interpreted as int */
1.307 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.308 - int j = __load_via_object(other.value, __pos___data__).intvalue;
1.309 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.310 + int j = __load_via_object(other->value, __pos___data__).intvalue;
1.311
1.312 /* Return a boolean result. */
1.313 return i != j ? __builtins___boolean_True : __builtins___boolean_False;
1.314 - #undef self
1.315 - #undef other
1.316 }
1.317
1.318 __attr __fn_native__int_str(__attr __args[])
1.319 {
1.320 - #define self (__args[1])
1.321 + __attr * const self = &__args[1];
1.322 /* self.__data__ interpreted as int */
1.323 - int i = __load_via_object(self.value, __pos___data__).intvalue;
1.324 + int i = __load_via_object(self->value, __pos___data__).intvalue;
1.325 int n = i != 0 ? (int) ceil(log10(i+1)) + 1 : 2;
1.326 char *s = calloc(n, sizeof(char));
1.327
1.328 @@ -293,17 +259,15 @@
1.329
1.330 /* Return a new string. */
1.331 return __new_str(s);
1.332 - #undef self
1.333 - #undef other
1.334 }
1.335
1.336 __attr __fn_native__str_add(__attr __args[])
1.337 {
1.338 - #define self (__args[1])
1.339 - #define other (__args[2])
1.340 + __attr * const self = &__args[1];
1.341 + __attr * const other = &__args[2];
1.342 /* self.__data__, other.__data__ interpreted as string */
1.343 - char *s = __load_via_object(self.value, __pos___data__).strvalue;
1.344 - char *o = __load_via_object(other.value, __pos___data__).strvalue;
1.345 + char *s = __load_via_object(self->value, __pos___data__).strvalue;
1.346 + char *o = __load_via_object(other->value, __pos___data__).strvalue;
1.347 int n = strlen(s) + strlen(o) + 1;
1.348 char *r = calloc(n, sizeof(char));
1.349
1.350 @@ -312,78 +276,68 @@
1.351
1.352 /* Return a new string. */
1.353 return __new_str(r);
1.354 - #undef self
1.355 - #undef other
1.356 }
1.357
1.358 __attr __fn_native__str_lt(__attr __args[])
1.359 {
1.360 - #define self (__args[1])
1.361 - #define other (__args[2])
1.362 + __attr * const self = &__args[1];
1.363 + __attr * const other = &__args[2];
1.364 /* self.__data__, other.__data__ interpreted as string */
1.365 - char *s = __load_via_object(self.value, __pos___data__).strvalue;
1.366 - char *o = __load_via_object(other.value, __pos___data__).strvalue;
1.367 + char *s = __load_via_object(self->value, __pos___data__).strvalue;
1.368 + char *o = __load_via_object(other->value, __pos___data__).strvalue;
1.369
1.370 /* NOTE: Using simple byte-level string operations. */
1.371 return strcmp(s, o) < 0 ? __builtins___boolean_True : __builtins___boolean_False;
1.372 - #undef self
1.373 - #undef other
1.374 }
1.375
1.376 __attr __fn_native__str_gt(__attr __args[])
1.377 {
1.378 - #define self (__args[1])
1.379 - #define other (__args[2])
1.380 + __attr * const self = &__args[1];
1.381 + __attr * const other = &__args[2];
1.382 /* self.__data__, other.__data__ interpreted as string */
1.383 - char *s = __load_via_object(self.value, __pos___data__).strvalue;
1.384 - char *o = __load_via_object(other.value, __pos___data__).strvalue;
1.385 + char *s = __load_via_object(self->value, __pos___data__).strvalue;
1.386 + char *o = __load_via_object(other->value, __pos___data__).strvalue;
1.387
1.388 /* NOTE: Using simple byte-level string operations. */
1.389 return strcmp(s, o) > 0 ? __builtins___boolean_True : __builtins___boolean_False;
1.390 - #undef self
1.391 - #undef other
1.392 }
1.393
1.394 __attr __fn_native__str_eq(__attr __args[])
1.395 {
1.396 - #define self (__args[1])
1.397 - #define other (__args[2])
1.398 + __attr * const self = &__args[1];
1.399 + __attr * const other = &__args[2];
1.400 /* self.__data__, other.__data__ interpreted as string */
1.401 - char *s = __load_via_object(self.value, __pos___data__).strvalue;
1.402 - char *o = __load_via_object(other.value, __pos___data__).strvalue;
1.403 + char *s = __load_via_object(self->value, __pos___data__).strvalue;
1.404 + char *o = __load_via_object(other->value, __pos___data__).strvalue;
1.405
1.406 /* NOTE: Using simple byte-level string operations. */
1.407 return strcmp(s, o) == 0 ? __builtins___boolean_True : __builtins___boolean_False;
1.408 - #undef self
1.409 - #undef other
1.410 }
1.411
1.412 __attr __fn_native__str_len(__attr __args[])
1.413 {
1.414 - #define self (__args[1])
1.415 + __attr * const self = &__args[1];
1.416 /* self.__data__ interpreted as string */
1.417 - char *s = __load_via_object(self.value, __pos___data__).strvalue;
1.418 + char *s = __load_via_object(self->value, __pos___data__).strvalue;
1.419
1.420 /* Return the new integer. */
1.421 return __new_int(strlen(s));
1.422 - #undef self
1.423 }
1.424
1.425 __attr __fn_native__str_nonempty(__attr __args[])
1.426 {
1.427 - #define self (__args[1])
1.428 + __attr * const self = &__args[1];
1.429 /* self.__data__ interpreted as string */
1.430 - char *s = __load_via_object(self.value, __pos___data__).strvalue;
1.431 + char *s = __load_via_object(self->value, __pos___data__).strvalue;
1.432
1.433 return strlen(s) ? __builtins___boolean_True : __builtins___boolean_False;
1.434 - #undef self
1.435 }
1.436
1.437 __attr __fn_native__list_init(__attr __args[])
1.438 {
1.439 - #define __size (__args[1])
1.440 - /* __size.__data__ interpreted as int */
1.441 - unsigned int n = __load_via_object(__size.value, __pos___data__).intvalue;
1.442 + __attr * const size = &__args[1];
1.443 + /* size.__data__ interpreted as int */
1.444 + unsigned int n = __load_via_object(size->value, __pos___data__).intvalue;
1.445
1.446 /* Allocate space for the list. */
1.447 __fragment *data = calloc(1, __FRAGMENT_SIZE(n));
1.448 @@ -393,15 +347,14 @@
1.449 data->size = 0;
1.450 data->capacity = n;
1.451 return attr;
1.452 - #undef __size
1.453 }
1.454
1.455 __attr __fn_native__list_append(__attr __args[])
1.456 {
1.457 - #define self (__args[1])
1.458 - #define __value (__args[2])
1.459 + __attr * const self = &__args[1];
1.460 + __attr * const value = &__args[2];
1.461 /* self.__data__ interpreted as list */
1.462 - __fragment *data = __load_via_object(self.value, __pos___data__).data;
1.463 + __fragment *data = __load_via_object(self->value, __pos___data__).data;
1.464 unsigned int size = data->size, capacity = data->capacity;
1.465 unsigned int n;
1.466
1.467 @@ -415,20 +368,18 @@
1.468 }
1.469
1.470 /* Insert the new element and increment the list size. */
1.471 - data->attrs[size] = __value;
1.472 + data->attrs[size] = *value;
1.473 data->size = size + 1;
1.474 return __builtins___none_None;
1.475 - #undef self
1.476 - #undef __value
1.477 }
1.478
1.479 __attr __fn_native__list_concat(__attr __args[])
1.480 {
1.481 - #define self (__args[1])
1.482 - #define __other (__args[2])
1.483 + __attr * const self = &__args[1];
1.484 + __attr * const __other = &__args[2];
1.485 /* self.__data__, __other.__data__ interpreted as list */
1.486 - __fragment *data = __load_via_object(self.value, __pos___data__).data;
1.487 - __fragment *other_data = __load_via_object(__other.value, __pos___data__).data;
1.488 + __fragment *data = __load_via_object(self->value, __pos___data__).data;
1.489 + __fragment *other_data = __load_via_object(__other->value, __pos___data__).data;
1.490 unsigned int size = data->size, capacity = data->capacity;
1.491 unsigned int other_size = other_data->size;
1.492 unsigned int i, j, n;
1.493 @@ -446,57 +397,50 @@
1.494 data->attrs[i] = other_data->attrs[j];
1.495 data->size = n;
1.496 return __builtins___none_None;
1.497 - #undef self
1.498 - #undef __other
1.499 }
1.500
1.501 __attr __fn_native__list_len(__attr __args[])
1.502 {
1.503 - #define self (__args[1])
1.504 + __attr * const self = &__args[1];
1.505 /* self.__data__ interpreted as fragment */
1.506 - unsigned int size = __load_via_object(self.value, __pos___data__).data->size;
1.507 + unsigned int size = __load_via_object(self->value, __pos___data__).data->size;
1.508
1.509 /* Return the new integer. */
1.510 return __new_int(size);
1.511 - #undef self
1.512 }
1.513
1.514 __attr __fn_native__list_nonempty(__attr __args[])
1.515 {
1.516 - #define self (__args[1])
1.517 + __attr * const self = &__args[1];
1.518
1.519 - return __load_via_object(self.value, __pos___data__).data->size ? __builtins___boolean_True : __builtins___boolean_False;
1.520 - #undef self
1.521 + return __load_via_object(self->value, __pos___data__).data->size ? __builtins___boolean_True : __builtins___boolean_False;
1.522 }
1.523
1.524 __attr __fn_native__list_element(__attr __args[])
1.525 {
1.526 - #define self (__args[1])
1.527 - #define index (__args[2])
1.528 + __attr * const self = &__args[1];
1.529 + __attr * const index = &__args[2];
1.530 /* self.__data__ interpreted as fragment */
1.531 - __attr *elements = __load_via_object(self.value, __pos___data__).data->attrs;
1.532 + __attr *elements = __load_via_object(self->value, __pos___data__).data->attrs;
1.533 /* index.__data__ interpreted as int */
1.534 - int i = __load_via_object(index.value, __pos___data__).intvalue;
1.535 + int i = __load_via_object(index->value, __pos___data__).intvalue;
1.536
1.537 return elements[i];
1.538 - #undef self
1.539 - #undef index
1.540 }
1.541
1.542 __attr __fn_native__list_to_tuple(__attr __args[])
1.543 {
1.544 - #define l (__args[1])
1.545 + __attr * const l = &__args[1];
1.546
1.547 /* NOTE: To be written. */
1.548 return __builtins___none_None;
1.549 - #undef l
1.550 }
1.551
1.552 __attr __fn_native__buffer_str(__attr __args[])
1.553 {
1.554 - #define self (__args[1])
1.555 + __attr * const self = &__args[1];
1.556 /* self.__data__ interpreted as buffer */
1.557 - __fragment *data = __load_via_object(self.value, __pos___data__).data;
1.558 + __fragment *data = __load_via_object(self->value, __pos___data__).data;
1.559 unsigned int size = 0, i, j;
1.560 char *s;
1.561
1.562 @@ -513,82 +457,71 @@
1.563
1.564 /* Return a new string. */
1.565 return __new_str(s);
1.566 - #undef self
1.567 }
1.568
1.569 __attr __fn_native__tuple_init(__attr __args[])
1.570 {
1.571 - #define size (__args[1])
1.572 + __attr * const size = &__args[1];
1.573 /* size.__data__ interpreted as fragment */
1.574 - __fragment *data = calloc(__load_via_object(size.value, __pos___data__).intvalue, sizeof(__attr));
1.575 + __fragment *data = calloc(__load_via_object(size->value, __pos___data__).intvalue, sizeof(__attr));
1.576 __attr attr = {0, .data=data};
1.577
1.578 return attr;
1.579 - #undef size
1.580 }
1.581
1.582 __attr __fn_native__tuple_len(__attr __args[])
1.583 {
1.584 - #define self (__args[1])
1.585 + __attr * const self = &__args[1];
1.586 /* self.__data__ interpreted as fragment */
1.587 - unsigned int size = __load_via_object(self.value, __pos___data__).data->size;
1.588 + unsigned int size = __load_via_object(self->value, __pos___data__).data->size;
1.589
1.590 /* Return the new integer. */
1.591 return __new_int(size);
1.592 - #undef self
1.593 }
1.594
1.595 __attr __fn_native__tuple_element(__attr __args[])
1.596 {
1.597 - #define self (__args[1])
1.598 - #define index (__args[2])
1.599 + __attr * const self = &__args[1];
1.600 + __attr * const index = &__args[2];
1.601 /* self.__data__ interpreted as fragment */
1.602 - __attr *elements = __load_via_object(self.value, __pos___data__).data->attrs;
1.603 + __attr *elements = __load_via_object(self->value, __pos___data__).data->attrs;
1.604 /* index.__data__ interpreted as int */
1.605 - int i = __load_via_object(index.value, __pos___data__).intvalue;
1.606 + int i = __load_via_object(index->value, __pos___data__).intvalue;
1.607
1.608 return elements[i];
1.609 - #undef self
1.610 - #undef index
1.611 }
1.612
1.613 __attr __fn_native__isinstance(__attr __args[])
1.614 {
1.615 - #define obj (__args[1])
1.616 - #define cls (__args[2])
1.617 + __attr * const obj = &__args[1];
1.618 + __attr * const cls = &__args[2];
1.619
1.620 - if (__is_instance(obj.value) && __HASATTR(__get_class(obj.value), __TYPEPOS(cls.value), __TYPECODE(cls.value)))
1.621 + if (__is_instance(obj->value) && __HASATTR(__get_class(obj->value), __TYPEPOS(cls->value), __TYPECODE(cls->value)))
1.622 return __builtins___boolean_True;
1.623 else
1.624 return __builtins___boolean_False;
1.625 - #undef obj
1.626 - #undef cls
1.627 }
1.628
1.629 __attr __fn_native__read(__attr __args[])
1.630 {
1.631 - #define fd (__args[1])
1.632 - #define n (__args[2])
1.633 + __attr * const fd = &__args[1];
1.634 + __attr * const n = &__args[2];
1.635
1.636 /* NOTE: To be written. */
1.637 return __builtins___none_None;
1.638 - #undef fd
1.639 - #undef n
1.640 }
1.641
1.642 __attr __fn_native__write(__attr __args[])
1.643 {
1.644 - #define fd (__args[1])
1.645 - #define str (__args[2])
1.646 + __attr * const fd = &__args[1];
1.647 + __attr * const str = &__args[2];
1.648 /* fd.__data__ interpreted as int */
1.649 - int i = __load_via_object(fd.value, __pos___data__).intvalue;
1.650 + int i = __load_via_object(fd->value, __pos___data__).intvalue;
1.651 /* str.__data__ interpreted as string */
1.652 - char *s = __load_via_object(str.value, __pos___data__).strvalue;
1.653 + char *s = __load_via_object(str->value, __pos___data__).strvalue;
1.654
1.655 write(i, s, sizeof(char) * strlen(s));
1.656 return __builtins___none_None;
1.657 - #undef fd
1.658 - #undef str
1.659 }
1.660
1.661 /* Module initialisation. */
2.1 --- a/translator.py Tue Nov 22 17:20:56 2016 +0100
2.2 +++ b/translator.py Tue Nov 22 17:36:39 2016 +0100
2.3 @@ -78,6 +78,10 @@
2.4
2.5 "A reference to a name in the translation."
2.6
2.7 + def __init__(self, name, ref, expr=None, parameter=None):
2.8 + results.ResolvedNameRef.__init__(self, name, ref, expr)
2.9 + self.parameter = parameter
2.10 +
2.11 def __str__(self):
2.12
2.13 "Return an output representation of the referenced name."
2.14 @@ -114,7 +118,7 @@
2.15 # All other assignments involve the names as they were given.
2.16
2.17 else:
2.18 - return "%s = %s" % (attrname, self.expr)
2.19 + return "(%s%s) = %s" % (self.parameter and "*" or "", attrname, self.expr)
2.20
2.21 # Expressions.
2.22
2.23 @@ -132,7 +136,7 @@
2.24 # All other accesses involve the names as they were given.
2.25
2.26 else:
2.27 - return attrname
2.28 + return "(%s%s)" % (self.parameter and "*" or "", attrname)
2.29
2.30 class TrConstantValueRef(results.ConstantValueRef, TranslationResult):
2.31
2.32 @@ -298,6 +302,12 @@
2.33 class_name, method_name = path.rsplit(".", 1)
2.34 return self.importer.classes.has_key(class_name) and class_name
2.35
2.36 + def in_method(self):
2.37 +
2.38 + "Return whether the current namespace provides a method."
2.39 +
2.40 + return self.in_function and self.is_method(self.get_namespace_path())
2.41 +
2.42 # Namespace recording.
2.43
2.44 def record_namespaces(self, node):
2.45 @@ -1089,11 +1099,18 @@
2.46 locals = self.importer.function_locals.get(self.get_namespace_path())
2.47 ref = locals and locals.get(n.name)
2.48
2.49 + # Determine whether the name refers to a parameter. The generation of
2.50 + # parameter references is different from other names.
2.51 +
2.52 + parameters = self.importer.function_parameters.get(self.get_namespace_path())
2.53 + parameter = n.name == "self" and self.in_method() or \
2.54 + parameters and n.name in parameters
2.55 +
2.56 # Qualified names are used for resolved static references or for
2.57 # static namespace members. The reference should be configured to return
2.58 # such names.
2.59
2.60 - return TrResolvedNameRef(n.name, ref, expr=expr)
2.61 + return TrResolvedNameRef(n.name, ref, expr=expr, parameter=parameter)
2.62
2.63 def process_not_node(self, n):
2.64
2.65 @@ -1373,13 +1390,12 @@
2.66 names.sort()
2.67 self.writeline("__attr %s;" % ", ".join(names))
2.68
2.69 - self.write_parameters(name, True)
2.70 + self.write_parameters(name)
2.71
2.72 def end_function(self, name):
2.73
2.74 "End the function having the given 'name'."
2.75
2.76 - self.write_parameters(name, False)
2.77 self.indent -= 1
2.78 print >>self.out, "}"
2.79 print >>self.out
2.80 @@ -1397,12 +1413,11 @@
2.81 self.writeline("__attr %s__tmp_result;" % targets)
2.82 self.writeline("__exc __tmp_exc;")
2.83
2.84 - def write_parameters(self, name, define=True):
2.85 + def write_parameters(self, name):
2.86
2.87 """
2.88 For the function having the given 'name', write definitions of
2.89 - parameters found in the arguments array if 'define' is set to a true
2.90 - value, or write "undefinitions" if 'define' is set to a false value.
2.91 + parameters found in the arguments array.
2.92 """
2.93
2.94 parameters = self.importer.function_parameters[name]
2.95 @@ -1410,18 +1425,12 @@
2.96 # Generate any self reference.
2.97
2.98 if self.is_method(name):
2.99 - if define:
2.100 - self.writeline("#define self (__args[0])")
2.101 - else:
2.102 - self.writeline("#undef self")
2.103 + self.writeline("__attr * const self = &__args[0];")
2.104
2.105 # Generate aliases for the parameters.
2.106
2.107 for i, parameter in enumerate(parameters):
2.108 - if define:
2.109 - self.writeline("#define %s (__args[%d])" % (encode_path(parameter), i+1))
2.110 - else:
2.111 - self.writeline("#undef %s" % encode_path(parameter))
2.112 + self.writeline("__attr * const %s = &__args[%d];" % (encode_path(parameter), i+1))
2.113
2.114 def start_if(self, first, test_ref):
2.115 self.writestmt("%sif (__BOOL(%s))" % (not first and "else " or "", test_ref))