1.1 --- a/common.py Fri Mar 24 18:52:59 2017 +0100
1.2 +++ b/common.py Sat Mar 25 14:26:26 2017 +0100
1.3 @@ -562,7 +562,6 @@
1.4
1.5 # <t0> = {n.list}
1.6 # <t1> = <t0>.__iter__()
1.7 - # <next> = <t1>.next
1.8
1.9 compiler.ast.Assign(
1.10 [compiler.ast.AssName(t0, "OP_ASSIGN")],
1.11 @@ -574,13 +573,9 @@
1.12 compiler.ast.Getattr(compiler.ast.Name(t0), "__iter__"),
1.13 [])),
1.14
1.15 - compiler.ast.Assign(
1.16 - [compiler.ast.AssName(i0, "OP_ASSIGN")],
1.17 - compiler.ast.Getattr(compiler.ast.Name(t1), "next")),
1.18 -
1.19 # try:
1.20 # while True:
1.21 - # <var>... = <next>()
1.22 + # <var>... = <t1>.next()
1.23 # ...
1.24 # except StopIteration:
1.25 # pass
1.26 @@ -592,7 +587,7 @@
1.27 compiler.ast.Assign(
1.28 [n.assign],
1.29 compiler.ast.CallFunc(
1.30 - compiler.ast.Name(i0),
1.31 + compiler.ast.Getattr(compiler.ast.Name(t1), "next"),
1.32 []
1.33 )),
1.34 n.body]),
2.1 --- a/generator.py Fri Mar 24 18:52:59 2017 +0100
2.2 +++ b/generator.py Sat Mar 25 14:26:26 2017 +0100
2.3 @@ -43,6 +43,7 @@
2.4 # NOTE: These must be synchronised with the library.
2.5
2.6 function_type = "__builtins__.core.function"
2.7 + int_type = "__builtins__.int.int"
2.8 none_type = "__builtins__.none.NoneType"
2.9 string_type = "__builtins__.str.string"
2.10 type_type = "__builtins__.core.type"
2.11 @@ -154,6 +155,8 @@
2.12 f_decls = open(join(self.output, "progtypes.h"), "w")
2.13 f_signatures = open(join(self.output, "main.h"), "w")
2.14 f_code = open(join(self.output, "main.c"), "w")
2.15 + f_calls = open(join(self.output, "calls.c"), "w")
2.16 + f_call_macros = open(join(self.output, "calls.h"), "w")
2.17
2.18 try:
2.19 # Output boilerplate.
2.20 @@ -193,6 +196,14 @@
2.21 #include "progtypes.h"
2.22 #include "main.h"
2.23 #include "progops.h"
2.24 +#include "calls.h"
2.25 +"""
2.26 +
2.27 + print >>f_call_macros, """\
2.28 +#ifndef __CALLS_H__
2.29 +#define __CALLS_H__
2.30 +
2.31 +#include "types.h"
2.32 """
2.33
2.34 # Generate table and structure data.
2.35 @@ -302,15 +313,18 @@
2.36 extra_function_instances.append(path)
2.37
2.38 # Write function declarations.
2.39 - # Signature: __attr <name>(__attr[]);
2.40 + # Signature: __attr <name>(...);
2.41
2.42 - print >>f_signatures, "__attr %s(__attr args[]);" % encode_function_pointer(path)
2.43 + parameters = self.importer.function_parameters[path]
2.44 + l = ["__attr"] * (len(parameters) + 1)
2.45 + print >>f_signatures, "__attr %s(%s);" % (encode_function_pointer(path), ", ".join(l))
2.46
2.47 # Generate parameter table size data.
2.48
2.49 min_parameters = {}
2.50 max_parameters = {}
2.51 size_parameters = {}
2.52 + all_max_parameters = set()
2.53
2.54 # Consolidate parameter tables for instantiators and functions.
2.55
2.56 @@ -339,6 +353,7 @@
2.57 min_parameters[signature] = argmin
2.58 max_parameters[signature] = argmax
2.59 size_parameters[signature] = len(parameters)
2.60 + all_max_parameters.add(argmax)
2.61
2.62 self.write_size_constants(f_consts, "pmin", min_parameters, 0)
2.63 self.write_size_constants(f_consts, "pmax", max_parameters, 0)
2.64 @@ -359,6 +374,11 @@
2.65 for constant, n in self.optimiser.constants.items():
2.66 self.make_literal_constant(f_decls, f_defs, n, constant)
2.67
2.68 + # Generate a common integer instance object, referenced when integer
2.69 + # attributes are accessed.
2.70 +
2.71 + self.make_common_integer(f_decls, f_defs)
2.72 +
2.73 # Finish the main source file.
2.74
2.75 self.write_main_program(f_code, f_signatures)
2.76 @@ -398,6 +418,42 @@
2.77 self.optimiser.locations,
2.78 "code", "pos", encode_code, encode_pos)
2.79
2.80 + # Generate macros for calls.
2.81 +
2.82 + all_max_parameters = list(all_max_parameters)
2.83 + all_max_parameters.sort()
2.84 +
2.85 + for argmax in all_max_parameters:
2.86 + l = []
2.87 + argnum = 0
2.88 + while argnum < argmax:
2.89 + l.append("ARGS[%d]" % argnum)
2.90 + argnum += 1
2.91 +
2.92 + print >>f_call_macros, "#define __CALL%d(FN, ARGS) (FN(%s))" % (argmax, ", ".join(l))
2.93 +
2.94 + # Generate a generic invocation function.
2.95 +
2.96 + print >>f_call_macros, "__attr __call_with_args(__attr (*fn)(), __attr args[], unsigned int n);"
2.97 +
2.98 + print >>f_calls, """\
2.99 +#include "types.h"
2.100 +#include "calls.h"
2.101 +
2.102 +__attr __call_with_args(__attr (*fn)(), __attr args[], unsigned int n)
2.103 +{
2.104 + switch (n)
2.105 + {"""
2.106 +
2.107 + for argmax in all_max_parameters:
2.108 + print >>f_calls, """\
2.109 + case %d: return __CALL%d(fn, args);""" % (argmax, argmax)
2.110 +
2.111 + print >>f_calls, """\
2.112 + default: return __NULL;
2.113 + }
2.114 +}"""
2.115 +
2.116 # Output more boilerplate.
2.117
2.118 print >>f_consts, """\
2.119 @@ -424,12 +480,18 @@
2.120
2.121 #endif /* __MAIN_H__ */"""
2.122
2.123 + print >>f_call_macros, """\
2.124 +
2.125 +#endif /* __CALLS_H__ */"""
2.126 +
2.127 finally:
2.128 f_consts.close()
2.129 f_defs.close()
2.130 f_decls.close()
2.131 f_signatures.close()
2.132 f_code.close()
2.133 + f_calls.close()
2.134 + f_call_macros.close()
2.135
2.136 def write_scripts(self, debug, gc_sections):
2.137
2.138 @@ -504,6 +566,11 @@
2.139
2.140 value, value_type, encoding = constant
2.141
2.142 + # Do not generate individual integer constants.
2.143 +
2.144 + if value_type == self.int_type:
2.145 + return
2.146 +
2.147 const_path = encode_literal_constant(n)
2.148 structure_name = encode_literal_reference(n)
2.149
2.150 @@ -526,13 +593,23 @@
2.151
2.152 self.make_constant(f_decls, f_defs, ref, attr_path, structure_name)
2.153
2.154 + def make_common_integer(self, f_decls, f_defs):
2.155 +
2.156 + """
2.157 + Write common integer instance details to 'f_decls' (to declare a
2.158 + structure) and to 'f_defs' (to define the contents).
2.159 + """
2.160 +
2.161 + ref = Reference("<instance>", self.int_type)
2.162 + self.make_constant(f_decls, f_defs, ref, "__common_integer", "__common_integer_obj")
2.163 +
2.164 def make_constant(self, f_decls, f_defs, ref, const_path, structure_name, data=None, encoding=None):
2.165
2.166 """
2.167 Write constant details to 'f_decls' (to declare a structure) and to
2.168 'f_defs' (to define the contents) for the constant described by 'ref'
2.169 - having the given 'path' and 'structure_name' (for the constant structure
2.170 - itself).
2.171 + having the given 'const_path' (providing an attribute for the constant)
2.172 + and 'structure_name' (for the constant structure itself).
2.173
2.174 The additional 'data' and 'encoding' are used to describe specific
2.175 values.
2.176 @@ -974,7 +1051,7 @@
2.177 # Special internal size member.
2.178
2.179 elif attrname == "__size__":
2.180 - structure.append("{.intvalue=%d}" % attr)
2.181 + structure.append("__INTVALUE(%d)" % attr)
2.182 continue
2.183
2.184 # Special internal key member.
2.185 @@ -1081,6 +1158,13 @@
2.186 # Obtain a constant value directly assigned to the attribute.
2.187
2.188 if self.optimiser.constant_numbers.has_key(alias):
2.189 +
2.190 + # Encode integer constants differently.
2.191 +
2.192 + value, value_type, encoding = self.importer.all_constant_values[alias]
2.193 + if value_type == self.int_type:
2.194 + return "__INTVALUE(%s) /* %s */" % (value, name)
2.195 +
2.196 constant_number = self.optimiser.constant_numbers[alias]
2.197 constant_value = encode_literal_constant(constant_number)
2.198 return "%s /* %s */" % (constant_value, name)
2.199 @@ -1127,57 +1211,52 @@
2.200 NOTE: where __call__ is provided by the class.
2.201 """
2.202
2.203 - parameters = self.importer.function_parameters[init_ref.get_origin()]
2.204 + initialiser = init_ref.get_origin()
2.205 + parameters = self.importer.function_parameters[initialiser]
2.206 + argmin, argmax = self.get_argument_limits(initialiser)
2.207 +
2.208 + l = []
2.209 + for name in parameters:
2.210 + l.append("__attr %s" % name)
2.211
2.212 print >>f_code, """\
2.213 -__attr %s(__attr __args[])
2.214 +__attr %s(__attr __self%s)
2.215 {
2.216 - /* Allocate the structure. */
2.217 - __args[0] = __NEWINSTANCE(%s);
2.218 -
2.219 - /* Call the initialiser. */
2.220 - %s(__args);
2.221 -
2.222 - /* Return the allocated object details. */
2.223 - return __args[0];
2.224 + return %s(__NEWINSTANCE(%s)%s);
2.225 }
2.226 """ % (
2.227 - encode_instantiator_pointer(path),
2.228 - encode_path(path),
2.229 - encode_function_pointer(init_ref.get_origin())
2.230 - )
2.231 + encode_instantiator_pointer(path),
2.232 + l and ", %s" % ",".join(l) or "",
2.233 + encode_function_pointer(initialiser),
2.234 + encode_path(path),
2.235 + parameters and ", %s" % ", ".join(parameters) or ""
2.236 + )
2.237 +
2.238 + # Signature: __new_typename(__attr __self, ...)
2.239 +
2.240 + print >>f_signatures, "__attr %s(__attr __self%s);" % (
2.241 + encode_instantiator_pointer(path),
2.242 + l and ", %s" % ", ".join(l) or ""
2.243 + )
2.244
2.245 print >>f_signatures, "#define __HAVE_%s" % encode_path(path)
2.246 - print >>f_signatures, "__attr %s(__attr[]);" % encode_instantiator_pointer(path)
2.247
2.248 # Write additional literal instantiators. These do not call the
2.249 # initialisers but instead populate the structures directly.
2.250
2.251 + # Signature: __newliteral_sequence(ARGS, NUM)
2.252 +
2.253 if path in self.literal_instantiator_types:
2.254 if path in self.literal_mapping_types:
2.255 style = "mapping"
2.256 else:
2.257 style = "sequence"
2.258
2.259 - print >>f_code, """\
2.260 -__attr %s(__attr __args[], __pos number)
2.261 -{
2.262 - /* Allocate the structure. */
2.263 - __args[0] = __NEWINSTANCE(%s);
2.264 -
2.265 - /* Allocate a structure for the data and set it on the __data__ attribute. */
2.266 - %s(__args, number);
2.267 -
2.268 - /* Return the allocated object details. */
2.269 - return __args[0];
2.270 -}
2.271 -""" % (
2.272 - encode_literal_instantiator(path),
2.273 - encode_path(path),
2.274 - encode_literal_data_initialiser(style)
2.275 - )
2.276 -
2.277 - print >>f_signatures, "__attr %s(__attr[], __pos);" % encode_literal_instantiator(path)
2.278 + print >>f_signatures, "#define %s(ARGS, NUM) (%s(__NEWINSTANCE(%s), ARGS, NUM))" % (
2.279 + encode_literal_instantiator(path),
2.280 + encode_literal_data_initialiser(style),
2.281 + encode_path(path)
2.282 + )
2.283
2.284 def write_main_program(self, f_code, f_signatures):
2.285
2.286 @@ -1213,13 +1292,11 @@
2.287 __Catch(__tmp_exc)
2.288 {
2.289 if (__ISINSTANCE(__tmp_exc.arg, __ATTRVALUE(&__builtins___exception_system_SystemExit)))
2.290 - return __load_via_object(
2.291 - __load_via_object(__tmp_exc.arg.value, __data__).value,
2.292 - value).intvalue;
2.293 + return __TOINT(__load_via_object(__VALUE(__tmp_exc.arg), value));
2.294
2.295 fprintf(stderr, "Program terminated due to exception: %%s.\\n",
2.296 __load_via_object(
2.297 - %s(__ARGS(__NULL, __tmp_exc.arg)).value,
2.298 + __VALUE(%s(__NULL, __tmp_exc.arg)),
2.299 __data__).strvalue);
2.300 return 1;
2.301 }
3.1 --- a/lib/__builtins__/character.py Fri Mar 24 18:52:59 2017 +0100
3.2 +++ b/lib/__builtins__/character.py Sat Mar 25 14:26:26 2017 +0100
3.3 @@ -29,7 +29,7 @@
3.4 check_int(i)
3.5
3.6 if 0 <= i <= 255:
3.7 - return str_chr(i.__data__)
3.8 + return str_chr(i)
3.9 else:
3.10 raise ValueError, i
3.11
3.12 @@ -94,7 +94,7 @@
3.13 check_int(i)
3.14
3.15 if 0 <= i <= 2097151:
3.16 - return utf8string(unicode_unichr(i.__data__))
3.17 + return utf8string(unicode_unichr(i))
3.18 else:
3.19 raise ValueError, i
3.20
4.1 --- a/lib/__builtins__/int.py Fri Mar 24 18:52:59 2017 +0100
4.2 +++ b/lib/__builtins__/int.py Sat Mar 25 14:26:26 2017 +0100
4.3 @@ -3,7 +3,7 @@
4.4 """
4.5 Integer objects.
4.6
4.7 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
4.8 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
4.9
4.10 This program is free software; you can redistribute it and/or modify it under
4.11 the terms of the GNU General Public License as published by the Free Software
4.12 @@ -34,11 +34,9 @@
4.13
4.14 "Initialise the integer with the given 'number_or_string'."
4.15
4.16 - if _isinstance(number_or_string, int):
4.17 - self.__data__ = number_or_string.__data__
4.18 - else:
4.19 - # NOTE: To be implemented.
4.20 - self.__data__ = None
4.21 + # NOTE: To be implemented.
4.22 +
4.23 + pass
4.24
4.25 def __hash__(self):
4.26
4.27 @@ -51,7 +49,7 @@
4.28 "Perform 'op' on this int and 'other' if appropriate."
4.29
4.30 if _isinstance(other, int):
4.31 - return op(self.__data__, other.__data__)
4.32 + return op(self, other)
4.33 else:
4.34 return NotImplemented
4.35
4.36 @@ -60,7 +58,7 @@
4.37 "Perform 'op' on 'other' and this int if appropriate."
4.38
4.39 if _isinstance(other, int):
4.40 - return op(other.__data__, self.__data__)
4.41 + return op(other, self)
4.42 else:
4.43 return NotImplemented
4.44
4.45 @@ -122,7 +120,7 @@
4.46
4.47 "Return the inversion of this int."
4.48
4.49 - return int_not(self.__data__)
4.50 + return int_not(self)
4.51
4.52 __add__ = __radd__ = __iadd__
4.53 __sub__ = __isub__
4.54 @@ -206,7 +204,7 @@
4.55
4.56 "Apply the unary negation operator."
4.57
4.58 - return int_neg(self.__data__)
4.59 + return int_neg(self)
4.60
4.61 def __pos__(self):
4.62
4.63 @@ -218,7 +216,7 @@
4.64
4.65 "Return a string representation."
4.66
4.67 - return utf8string(int_str(self.__data__))
4.68 + return utf8string(int_str(self))
4.69
4.70 __repr__ = __str__
4.71
4.72 @@ -233,8 +231,7 @@
4.73
4.74 "Return whether this int is non-zero."
4.75
4.76 - zero = 0
4.77 - return int_ne(self.__data__, zero.__data__)
4.78 + return int_ne(self, 0)
4.79
4.80 # Limits.
4.81
5.1 --- a/lib/__builtins__/str.py Fri Mar 24 18:52:59 2017 +0100
5.2 +++ b/lib/__builtins__/str.py Sat Mar 25 14:26:26 2017 +0100
5.3 @@ -22,7 +22,7 @@
5.4 from __builtins__.operator import _negate
5.5 from __builtins__.sequence import hashable, itemaccess
5.6 from __builtins__.types import check_int
5.7 -from native import int_new, str_add, str_lt, str_gt, str_eq, str_ord, \
5.8 +from native import str_add, str_lt, str_gt, str_eq, str_ord, \
5.9 str_substr
5.10
5.11 WHITESPACE = (" ", "\f", "\n", "\r", "\t")
5.12 @@ -53,7 +53,7 @@
5.13 else:
5.14 self.__data__ = None
5.15 self.__key__ = None
5.16 - self.__size__ = None
5.17 + self.__size__ = 0
5.18
5.19 # Internal methods.
5.20
5.21 @@ -157,7 +157,7 @@
5.22
5.23 "Return the number of bytes in this string."
5.24
5.25 - return int_new(self.__size__)
5.26 + return self.__size__
5.27
5.28 # General type methods.
5.29
5.30 @@ -165,7 +165,7 @@
5.31
5.32 "Return whether the string provides any data."
5.33
5.34 - return int_new(self.__size__).__bool__()
5.35 + return self.__size__.__bool__()
5.36
5.37 def __contains__(self, value):
5.38
6.1 --- a/lib/native/__init__.py Fri Mar 24 18:52:59 2017 +0100
6.2 +++ b/lib/native/__init__.py Sat Mar 25 14:26:26 2017 +0100
6.3 @@ -23,10 +23,10 @@
6.4
6.5 from native.identity import is_, is_not
6.6
6.7 -from native.int import int_new, \
6.8 - int_add, int_div, int_mod, int_mul, int_neg, int_pow, \
6.9 - int_sub, int_and, int_not, int_or, int_xor, int_lt, \
6.10 - int_gt, int_eq, int_ne, int_str
6.11 +from native.int import int_add, int_div, int_mod, int_mul, int_neg, int_pow, \
6.12 + int_sub, int_and, int_not, int_or, int_xor, \
6.13 + int_eq, int_ge, int_gt, int_le, int_lt, int_ne, \
6.14 + int_str, is_int
6.15
6.16 from native.introspection import object_getattr, isinstance, issubclass
6.17
7.1 --- a/lib/native/int.py Fri Mar 24 18:52:59 2017 +0100
7.2 +++ b/lib/native/int.py Sat Mar 25 14:26:26 2017 +0100
7.3 @@ -24,7 +24,7 @@
7.4 this program. If not, see <http://www.gnu.org/licenses/>.
7.5 """
7.6
7.7 -def int_new(data): pass
7.8 +def is_int(obj): pass
7.9
7.10 def int_add(self, other): pass
7.11 def int_div(self, other): pass
7.12 @@ -39,9 +39,11 @@
7.13 def int_or(self, other): pass
7.14 def int_xor(self, other): pass
7.15
7.16 -def int_lt(self, other): pass
7.17 +def int_eq(self, other): pass
7.18 +def int_ge(self, other): pass
7.19 def int_gt(self, other): pass
7.20 -def int_eq(self, other): pass
7.21 +def int_le(self, other): pass
7.22 +def int_lt(self, other): pass
7.23 def int_ne(self, other): pass
7.24
7.25 def int_str(self): pass
8.1 --- a/lib/operator/augmented.py Fri Mar 24 18:52:59 2017 +0100
8.2 +++ b/lib/operator/augmented.py Sat Mar 25 14:26:26 2017 +0100
8.3 @@ -3,7 +3,7 @@
8.4 """
8.5 Operator support.
8.6
8.7 -Copyright (C) 2010, 2013, 2015 Paul Boddie <paul@boddie.org.uk>
8.8 +Copyright (C) 2010, 2013, 2015, 2017 Paul Boddie <paul@boddie.org.uk>
8.9
8.10 This program is free software; you can redistribute it and/or modify it under
8.11 the terms of the GNU General Public License as published by the Free Software
8.12 @@ -20,6 +20,9 @@
8.13 """
8.14
8.15 from operator.core import augassign
8.16 +from native import int_add, int_div, int_mod, int_mul, int_pow, int_sub, \
8.17 + int_and, int_or, int_xor, \
8.18 + is_int
8.19
8.20 # These functions defer method lookup by wrapping the attribute access in
8.21 # lambda functions. Thus, the appropriate methods are defined locally, but no
8.22 @@ -31,12 +34,18 @@
8.23 # Augmented assignment functions.
8.24
8.25 def iadd(a, b):
8.26 + if is_int(a) and is_int(b):
8.27 + return int_add(a, b)
8.28 return augassign(a, b, lambda a: a.__iadd__, lambda a: a.__add__, lambda b: b.__radd__)
8.29
8.30 def iand_(a, b):
8.31 + if is_int(a) and is_int(b):
8.32 + return int_and(a, b)
8.33 return augassign(a, b, lambda a: a.__iand__, lambda a: a.__and__, lambda b: b.__rand__)
8.34
8.35 def idiv(a, b):
8.36 + if is_int(a) and is_int(b):
8.37 + return int_div(a, b)
8.38 return augassign(a, b, lambda a: a.__idiv__, lambda a: a.__div__, lambda b: b.__rdiv__)
8.39
8.40 def ifloordiv(a, b):
8.41 @@ -46,24 +55,36 @@
8.42 return augassign(a, b, lambda a: a.__ilshift__, lambda a: a.__lshift__, lambda b: b.__rlshift__)
8.43
8.44 def imod(a, b):
8.45 + if is_int(a) and is_int(b):
8.46 + return int_mod(a, b)
8.47 return augassign(a, b, lambda a: a.__imod__, lambda a: a.__mod__, lambda b: b.__rmod__)
8.48
8.49 def imul(a, b):
8.50 + if is_int(a) and is_int(b):
8.51 + return int_mul(a, b)
8.52 return augassign(a, b, lambda a: a.__imul__, lambda a: a.__mul__, lambda b: b.__rmul__)
8.53
8.54 def ior_(a, b):
8.55 + if is_int(a) and is_int(b):
8.56 + return int_or(a, b)
8.57 return augassign(a, b, lambda a: a.__ior__, lambda a: a.__or__, lambda b: b.__ror__)
8.58
8.59 def ipow(a, b):
8.60 + if is_int(a) and is_int(b):
8.61 + return int_pow(a, b)
8.62 return augassign(a, b, lambda a: a.__ipow__, lambda a: a.__pow__, lambda b: b.__rpow__)
8.63
8.64 def irshift(a, b):
8.65 return augassign(a, b, lambda a: a.__irshift__, lambda a: a.__rshift__, lambda b: b.__rrshift__)
8.66
8.67 def isub(a, b):
8.68 + if is_int(a) and is_int(b):
8.69 + return int_sub(a, b)
8.70 return augassign(a, b, lambda a: a.__isub__, lambda a: a.__sub__, lambda b: b.__rsub__)
8.71
8.72 def ixor(a, b):
8.73 + if is_int(a) and is_int(b):
8.74 + return int_xor(a, b)
8.75 return augassign(a, b, lambda a: a.__ixor__, lambda a: a.__xor__, lambda b: b.__rxor__)
8.76
8.77 # vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/lib/operator/binary.py Fri Mar 24 18:52:59 2017 +0100
9.2 +++ b/lib/operator/binary.py Sat Mar 25 14:26:26 2017 +0100
9.3 @@ -3,7 +3,7 @@
9.4 """
9.5 Operator support.
9.6
9.7 -Copyright (C) 2010, 2013, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
9.8 +Copyright (C) 2010, 2013, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
9.9
9.10 This program is free software; you can redistribute it and/or modify it under
9.11 the terms of the GNU General Public License as published by the Free Software
9.12 @@ -20,6 +20,9 @@
9.13 """
9.14
9.15 from operator.core import binary_op, is_, is_not
9.16 +from native import int_add, int_div, int_mod, int_mul, int_pow, int_sub, \
9.17 + int_and, int_not, int_or, int_xor, \
9.18 + is_int
9.19
9.20 # These functions defer method lookup by wrapping the attribute access in
9.21 # lambda functions. Thus, the appropriate methods are defined locally, but no
9.22 @@ -28,15 +31,21 @@
9.23 # Binary operator functions.
9.24
9.25 def add(a, b):
9.26 + if is_int(a) and is_int(b):
9.27 + return int_add(a, b)
9.28 return binary_op(a, b, lambda a: a.__add__, lambda b: b.__radd__)
9.29
9.30 def and_(a, b):
9.31 + if is_int(a) and is_int(b):
9.32 + return int_and(a, b)
9.33 return binary_op(a, b, lambda a: a.__and__, lambda b: b.__rand__)
9.34
9.35 def contains(a, b):
9.36 return in_(b, a)
9.37
9.38 def div(a, b):
9.39 + if is_int(a) and is_int(b):
9.40 + return int_div(a, b)
9.41 return binary_op(a, b, lambda a: a.__div__, lambda b: b.__rdiv__)
9.42
9.43 def floordiv(a, b):
9.44 @@ -52,24 +61,36 @@
9.45 return binary_op(a, b, lambda a: a.__lshift__, lambda b: b.__rlshift__)
9.46
9.47 def mod(a, b):
9.48 + if is_int(a) and is_int(b):
9.49 + return int_mod(a, b)
9.50 return binary_op(a, b, lambda a: a.__mod__, lambda b: b.__rmod__)
9.51
9.52 def mul(a, b):
9.53 + if is_int(a) and is_int(b):
9.54 + return int_mul(a, b)
9.55 return binary_op(a, b, lambda a: a.__mul__, lambda b: b.__rmul__)
9.56
9.57 def or_(a, b):
9.58 + if is_int(a) and is_int(b):
9.59 + return int_or(a, b)
9.60 return binary_op(a, b, lambda a: a.__or__, lambda b: b.__ror__)
9.61
9.62 def pow(a, b):
9.63 + if is_int(a) and is_int(b):
9.64 + return int_pow(a, b)
9.65 return binary_op(a, b, lambda a: a.__pow__, lambda b: b.__rpow__)
9.66
9.67 def rshift(a, b):
9.68 return binary_op(a, b, lambda a: a.__rshift__, lambda b: b.__rrshift__)
9.69
9.70 def sub(a, b):
9.71 + if is_int(a) and is_int(b):
9.72 + return int_sub(a, b)
9.73 return binary_op(a, b, lambda a: a.__sub__, lambda b: b.__rsub__)
9.74
9.75 def xor(a, b):
9.76 + if is_int(a) and is_int(b):
9.77 + return int_xor(a, b)
9.78 return binary_op(a, b, lambda a: a.__xor__, lambda b: b.__rxor__)
9.79
9.80 # vim: tabstop=4 expandtab shiftwidth=4
10.1 --- a/lib/operator/comparison.py Fri Mar 24 18:52:59 2017 +0100
10.2 +++ b/lib/operator/comparison.py Sat Mar 25 14:26:26 2017 +0100
10.3 @@ -3,7 +3,7 @@
10.4 """
10.5 Operator support.
10.6
10.7 -Copyright (C) 2010, 2013, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
10.8 +Copyright (C) 2010, 2013, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
10.9
10.10 This program is free software; you can redistribute it and/or modify it under
10.11 the terms of the GNU General Public License as published by the Free Software
10.12 @@ -20,6 +20,7 @@
10.13 """
10.14
10.15 from operator.core import binary_op
10.16 +from native import int_eq, int_ge, int_gt, int_le, int_lt, int_ne, is_int
10.17
10.18 # These functions defer method lookup by wrapping the attribute access in
10.19 # lambda functions. Thus, the appropriate methods are defined locally, but no
10.20 @@ -28,21 +29,33 @@
10.21 # Comparison functions.
10.22
10.23 def eq(a, b):
10.24 + if is_int(a) and is_int(b):
10.25 + return int_eq(a, b)
10.26 return binary_op(a, b, lambda a: a.__eq__, lambda b: b.__eq__, False)
10.27
10.28 def ge(a, b):
10.29 + if is_int(a) and is_int(b):
10.30 + return int_ge(a, b)
10.31 return binary_op(a, b, lambda a: a.__ge__, lambda b: b.__le__)
10.32
10.33 def gt(a, b):
10.34 + if is_int(a) and is_int(b):
10.35 + return int_gt(a, b)
10.36 return binary_op(a, b, lambda a: a.__gt__, lambda b: b.__lt__)
10.37
10.38 def le(a, b):
10.39 + if is_int(a) and is_int(b):
10.40 + return int_le(a, b)
10.41 return binary_op(a, b, lambda a: a.__le__, lambda b: b.__ge__)
10.42
10.43 def lt(a, b):
10.44 + if is_int(a) and is_int(b):
10.45 + return int_lt(a, b)
10.46 return binary_op(a, b, lambda a: a.__lt__, lambda b: b.__gt__)
10.47
10.48 def ne(a, b):
10.49 + if is_int(a) and is_int(b):
10.50 + return int_ne(a, b)
10.51 return binary_op(a, b, lambda a: a.__ne__, lambda b: b.__ne__, True)
10.52
10.53 # vim: tabstop=4 expandtab shiftwidth=4
11.1 --- a/lib/operator/unary.py Fri Mar 24 18:52:59 2017 +0100
11.2 +++ b/lib/operator/unary.py Sat Mar 25 14:26:26 2017 +0100
11.3 @@ -3,7 +3,7 @@
11.4 """
11.5 Operator support.
11.6
11.7 -Copyright (C) 2010, 2013, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
11.8 +Copyright (C) 2010, 2013, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
11.9
11.10 This program is free software; you can redistribute it and/or modify it under
11.11 the terms of the GNU General Public License as published by the Free Software
11.12 @@ -20,6 +20,7 @@
11.13 """
11.14
11.15 from operator.core import unary_op
11.16 +from native.int import int_neg, int_not, is_int
11.17
11.18 # These functions defer method lookup by wrapping the attribute access in
11.19 # lambda functions. Thus, the appropriate methods are defined locally, but no
11.20 @@ -31,12 +32,18 @@
11.21 return unary_op(a, lambda a: a.__invert__)
11.22
11.23 def neg(a):
11.24 + if is_int(a):
11.25 + return int_neg(a)
11.26 return unary_op(a, lambda a: a.__neg__)
11.27
11.28 def not_(a):
11.29 + if is_int(a):
11.30 + return int_not(a)
11.31 return not a
11.32
11.33 def pos(a):
11.34 + if is_int(a):
11.35 + return a
11.36 return unary_op(a, lambda a: a.__pos__)
11.37
11.38 # vim: tabstop=4 expandtab shiftwidth=4
12.1 --- a/templates/Makefile Fri Mar 24 18:52:59 2017 +0100
12.2 +++ b/templates/Makefile Sat Mar 25 14:26:26 2017 +0100
12.3 @@ -2,7 +2,7 @@
12.4 include modules.mk
12.5 include options.mk
12.6
12.7 -SRC += exceptions.c main.c ops.c progops.c progtypes.c
12.8 +SRC += calls.c exceptions.c main.c ops.c progops.c progtypes.c
12.9 OBJ = $(SRC:.c=.o)
12.10 CFLAGS += -Wall -I. -finput-charset=UTF-8
12.11 LDFLAGS += -lm -lgc
13.1 --- a/templates/native/buffer.c Fri Mar 24 18:52:59 2017 +0100
13.2 +++ b/templates/native/buffer.c Sat Mar 25 14:26:26 2017 +0100
13.3 @@ -26,18 +26,17 @@
13.4 #include "progtypes.h"
13.5 #include "main.h"
13.6
13.7 -__attr __fn_native_buffer_buffer_str(__attr __args[])
13.8 +__attr __fn_native_buffer_buffer_str(__attr __self, __attr _data)
13.9 {
13.10 - __attr * const _data = &__args[1];
13.11 - /* _data interpreted as buffer */
13.12 - __fragment *data = _data->seqvalue;
13.13 + /* _data interpreted as buffer.__data__ */
13.14 + __fragment *data = _data.seqvalue;
13.15 unsigned int size = 0, i, j, n;
13.16 char *s;
13.17 __attr o;
13.18
13.19 /* Calculate the size of the string. */
13.20 for (i = 0; i < data->size; i++)
13.21 - size += __load_via_object(data->attrs[i].value, __size__).intvalue;
13.22 + size += __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__));
13.23
13.24 /* Reserve space for a new string. */
13.25 s = (char *) __ALLOCATE(size + 1, sizeof(char));
13.26 @@ -45,8 +44,8 @@
13.27 /* Build a single string from the buffer contents. */
13.28 for (i = 0, j = 0; i < data->size; i++)
13.29 {
13.30 - o = __load_via_object(data->attrs[i].value, __data__);
13.31 - n = __load_via_object(data->attrs[i].value, __size__).intvalue;
13.32 + o = __load_via_object(__VALUE(data->attrs[i]), __data__);
13.33 + n = __TOINT(__load_via_object(__VALUE(data->attrs[i]), __size__));
13.34 memcpy(s + j, o.strvalue, n); /* does not null terminate but final byte should be zero */
13.35 j += n;
13.36 }
14.1 --- a/templates/native/buffer.h Fri Mar 24 18:52:59 2017 +0100
14.2 +++ b/templates/native/buffer.h Sat Mar 25 14:26:26 2017 +0100
14.3 @@ -1,6 +1,6 @@
14.4 /* Native functions for buffer operations.
14.5
14.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
14.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
14.8
14.9 This program is free software; you can redistribute it and/or modify it under
14.10 the terms of the GNU General Public License as published by the Free Software
14.11 @@ -23,7 +23,7 @@
14.12
14.13 /* Buffer operations. */
14.14
14.15 -__attr __fn_native_buffer_buffer_str(__attr __args[]);
14.16 +__attr __fn_native_buffer_buffer_str(__attr __self, __attr _data);
14.17
14.18 /* Module initialisation. */
14.19
15.1 --- a/templates/native/common.c Fri Mar 24 18:52:59 2017 +0100
15.2 +++ b/templates/native/common.c Sat Mar 25 14:26:26 2017 +0100
15.3 @@ -26,20 +26,12 @@
15.4
15.5 /* Utility functions. */
15.6
15.7 -__attr __new_int(int i)
15.8 -{
15.9 - /* Create a new integer and mutate the __data__ attribute. */
15.10 - __attr attr = __NEWINSTANCEIM(__builtins___int_int);
15.11 - attr.value->attrs[__ATTRPOS(__data__)].intvalue = i;
15.12 - return attr;
15.13 -}
15.14 -
15.15 __attr __new_str(char *s, int size)
15.16 {
15.17 /* Create a new string and mutate the __data__, __size__ and __key__ attributes. */
15.18 __attr attr = __NEWINSTANCE(__builtins___str_string);
15.19 attr.value->attrs[__ATTRPOS(__data__)].strvalue = s;
15.20 - attr.value->attrs[__ATTRPOS(__size__)].intvalue = size;
15.21 + attr.value->attrs[__ATTRPOS(__size__)] = __INTVALUE(size);
15.22 attr.value->attrs[__ATTRPOS(__key__)] = __NULL;
15.23 return attr;
15.24 }
15.25 @@ -52,7 +44,7 @@
15.26 return attr;
15.27 }
15.28
15.29 -__fragment *__fragment_append(__fragment *data, __attr * const value)
15.30 +__fragment *__fragment_append(__fragment *data, __attr value)
15.31 {
15.32 __fragment *newdata = data;
15.33 unsigned int size = data->size, capacity = data->capacity;
15.34 @@ -68,7 +60,7 @@
15.35 }
15.36
15.37 /* Insert the new element and increment the list size. */
15.38 - newdata->attrs[size] = *value;
15.39 + newdata->attrs[size] = value;
15.40 newdata->size = size + 1;
15.41
15.42 return newdata;
16.1 --- a/templates/native/common.h Fri Mar 24 18:52:59 2017 +0100
16.2 +++ b/templates/native/common.h Sat Mar 25 14:26:26 2017 +0100
16.3 @@ -23,9 +23,9 @@
16.4
16.5 /* Utility functions. */
16.6
16.7 -__attr __new_int(int i);
16.8 +#define __new_int(VALUE) __INTVALUE(VALUE)
16.9 __attr __new_str(char *s, int size);
16.10 __attr __new_list(__fragment *f);
16.11 -__fragment *__fragment_append(__fragment *data, __attr * const value);
16.12 +__fragment *__fragment_append(__fragment *data, __attr value);
16.13
16.14 #endif /* __NATIVE_COMMON_H__ */
17.1 --- a/templates/native/iconv.c Fri Mar 24 18:52:59 2017 +0100
17.2 +++ b/templates/native/iconv.c Sat Mar 25 14:26:26 2017 +0100
17.3 @@ -33,37 +33,31 @@
17.4 static void __raise_incomplete_sequence_error(__attr value, __attr arg)
17.5 {
17.6 #ifdef __HAVE_posix_iconv_IncompleteSequenceError
17.7 - __attr args[3] = {__NULL, value, arg};
17.8 - __attr exc = __new_posix_iconv_IncompleteSequenceError(args);
17.9 - __Raise(exc);
17.10 + __Raise(__new_posix_iconv_IncompleteSequenceError(__NULL, value, arg));
17.11 #endif /* __HAVE_posix_iconv_IncompleteSequenceError */
17.12 }
17.13
17.14 static void __raise_invalid_sequence_error(__attr value, __attr arg)
17.15 {
17.16 #ifdef __HAVE_posix_iconv_InvalidSequenceError
17.17 - __attr args[3] = {__NULL, value, arg};
17.18 - __attr exc = __new_posix_iconv_InvalidSequenceError(args);
17.19 - __Raise(exc);
17.20 + __Raise(__new_posix_iconv_InvalidSequenceError(__NULL, value, arg));
17.21 #endif /* __HAVE_posix_iconv_InvalidSequenceError */
17.22 }
17.23
17.24 /* Character set conversion. */
17.25
17.26 -__attr __fn_native_iconv_iconv(__attr __args[])
17.27 +__attr __fn_native_iconv_iconv(__attr __self, __attr cd, __attr state)
17.28 {
17.29 - __attr * const cd = &__args[1];
17.30 - __attr * const state = &__args[2];
17.31 /* cd interpreted as iconv_t */
17.32 - iconv_t c = (iconv_t) cd->datavalue;
17.33 + iconv_t c = (iconv_t) cd.datavalue;
17.34 /* state.__data__ interpreted as list */
17.35 - __fragment *f = __load_via_object(state->value, __data__).seqvalue;
17.36 + __fragment *f = __load_via_object(__VALUE(state), __data__).seqvalue;
17.37
17.38 /* Obtain the string, start position, and remaining bytes from the state. */
17.39
17.40 - char *inbuf = __load_via_object(f->attrs[0].value, __data__).strvalue;
17.41 - int start = __load_via_object(f->attrs[1].value, __data__).intvalue;
17.42 - int remaining = __load_via_object(f->attrs[2].value, __data__).intvalue;
17.43 + char *inbuf = __load_via_object(__VALUE(f->attrs[0]), __data__).strvalue;
17.44 + int start = __TOINT(f->attrs[1]);
17.45 + int remaining = __TOINT(f->attrs[2]);
17.46
17.47 /* Allocate a string for the output buffer using the remaining input size
17.48 as a guide. */
17.49 @@ -123,11 +117,10 @@
17.50 return __builtins___none_None;
17.51 }
17.52
17.53 -__attr __fn_native_iconv_iconv_close(__attr __args[])
17.54 +__attr __fn_native_iconv_iconv_close(__attr __self, __attr cd)
17.55 {
17.56 - __attr * const cd = &__args[1];
17.57 /* cd interpreted as iconv_t */
17.58 - iconv_t c = (iconv_t) cd->datavalue;
17.59 + iconv_t c = (iconv_t) cd.datavalue;
17.60
17.61 errno = 0;
17.62
17.63 @@ -137,14 +130,12 @@
17.64 return __builtins___none_None;
17.65 }
17.66
17.67 -__attr __fn_native_iconv_iconv_open(__attr __args[])
17.68 +__attr __fn_native_iconv_iconv_open(__attr __self, __attr tocode, __attr fromcode)
17.69 {
17.70 - __attr * const tocode = &__args[1];
17.71 - __attr * const fromcode = &__args[2];
17.72 /* tocode.__data__ interpreted as string */
17.73 - char *t = __load_via_object(tocode->value, __data__).strvalue;
17.74 + char *t = __load_via_object(__VALUE(tocode), __data__).strvalue;
17.75 /* fromcode.__data__ interpreted as string */
17.76 - char *f = __load_via_object(fromcode->value, __data__).strvalue;
17.77 + char *f = __load_via_object(__VALUE(fromcode), __data__).strvalue;
17.78 iconv_t result;
17.79 __attr attr;
17.80
17.81 @@ -160,11 +151,10 @@
17.82 return attr;
17.83 }
17.84
17.85 -__attr __fn_native_iconv_iconv_reset(__attr __args[])
17.86 +__attr __fn_native_iconv_iconv_reset(__attr __self, __attr cd)
17.87 {
17.88 - __attr * const cd = &__args[1];
17.89 /* cd interpreted as iconv_t */
17.90 - iconv_t c = (iconv_t) cd->datavalue;
17.91 + iconv_t c = (iconv_t) cd.datavalue;
17.92
17.93 iconv(c, NULL, NULL, NULL, NULL);
17.94 return __builtins___none_None;
18.1 --- a/templates/native/iconv.h Fri Mar 24 18:52:59 2017 +0100
18.2 +++ b/templates/native/iconv.h Sat Mar 25 14:26:26 2017 +0100
18.3 @@ -1,6 +1,6 @@
18.4 /* Native functions for character set conversion.
18.5
18.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
18.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
18.8
18.9 This program is free software; you can redistribute it and/or modify it under
18.10 the terms of the GNU General Public License as published by the Free Software
18.11 @@ -23,10 +23,10 @@
18.12
18.13 /* Input/output. */
18.14
18.15 -__attr __fn_native_iconv_iconv(__attr __args[]);
18.16 -__attr __fn_native_iconv_iconv_close(__attr __args[]);
18.17 -__attr __fn_native_iconv_iconv_open(__attr __args[]);
18.18 -__attr __fn_native_iconv_iconv_reset(__attr __args[]);
18.19 +__attr __fn_native_iconv_iconv(__attr __self, __attr cd, __attr state);
18.20 +__attr __fn_native_iconv_iconv_close(__attr __self, __attr cd);
18.21 +__attr __fn_native_iconv_iconv_open(__attr __self, __attr tocode, __attr fromcode);
18.22 +__attr __fn_native_iconv_iconv_reset(__attr __self, __attr cd);
18.23
18.24 /* Module initialisation. */
18.25
19.1 --- a/templates/native/identity.c Fri Mar 24 18:52:59 2017 +0100
19.2 +++ b/templates/native/identity.c Sat Mar 25 14:26:26 2017 +0100
19.3 @@ -1,6 +1,6 @@
19.4 /* Native functions for identity operations.
19.5
19.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
19.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
19.8
19.9 This program is free software; you can redistribute it and/or modify it under
19.10 the terms of the GNU General Public License as published by the Free Software
19.11 @@ -26,20 +26,18 @@
19.12
19.13 /* Identity testing. */
19.14
19.15 -__attr __fn_native_identity_is_(__attr __args[])
19.16 +__attr __fn_native_identity_is_(__attr __self, __attr x, __attr y)
19.17 {
19.18 - __attr * const x = &__args[1];
19.19 - __attr * const y = &__args[2];
19.20 + /* NOTE: value member assumed equivalent to intvalue for comparison. */
19.21
19.22 - return x->value == y->value ? __builtins___boolean_True : __builtins___boolean_False;
19.23 + return x.value == y.value ? __builtins___boolean_True : __builtins___boolean_False;
19.24 }
19.25
19.26 -__attr __fn_native_identity_is_not(__attr __args[])
19.27 +__attr __fn_native_identity_is_not(__attr __self, __attr x, __attr y)
19.28 {
19.29 - __attr * const x = &__args[1];
19.30 - __attr * const y = &__args[2];
19.31 + /* NOTE: value member assumed equivalent to intvalue for comparison. */
19.32
19.33 - return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False;
19.34 + return x.value != y.value ? __builtins___boolean_True : __builtins___boolean_False;
19.35 }
19.36
19.37 /* Module initialisation. */
20.1 --- a/templates/native/identity.h Fri Mar 24 18:52:59 2017 +0100
20.2 +++ b/templates/native/identity.h Sat Mar 25 14:26:26 2017 +0100
20.3 @@ -1,6 +1,6 @@
20.4 /* Native functions for identity operations.
20.5
20.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
20.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
20.8
20.9 This program is free software; you can redistribute it and/or modify it under
20.10 the terms of the GNU General Public License as published by the Free Software
20.11 @@ -23,8 +23,8 @@
20.12
20.13 /* Identity testing. */
20.14
20.15 -__attr __fn_native_identity_is_(__attr __args[]);
20.16 -__attr __fn_native_identity_is_not(__attr __args[]);
20.17 +__attr __fn_native_identity_is_(__attr __self, __attr x, __attr y);
20.18 +__attr __fn_native_identity_is_not(__attr __self, __attr x, __attr y);
20.19
20.20 /* Module initialisation. */
20.21
21.1 --- a/templates/native/int.c Fri Mar 24 18:52:59 2017 +0100
21.2 +++ b/templates/native/int.c Sat Mar 25 14:26:26 2017 +0100
21.3 @@ -16,7 +16,6 @@
21.4 this program. If not, see <http://www.gnu.org/licenses/>.
21.5 */
21.6
21.7 -#include <limits.h> /* INT_MAX, INT_MIN */
21.8 #include <math.h> /* ceil, log10, pow */
21.9 #include <stdio.h> /* fdopen, snprintf */
21.10 #include <errno.h> /* errno */
21.11 @@ -32,24 +31,20 @@
21.12
21.13 /* Integer operations. */
21.14
21.15 -__attr __fn_native_int_int_new(__attr __args[])
21.16 +__attr __fn_native_int_is_int(__attr __self, __attr obj)
21.17 {
21.18 - __attr * const _data = &__args[1];
21.19 -
21.20 - return __new_int(_data->intvalue);
21.21 + return __INTEGER(obj) ? __builtins___boolean_True : __builtins___boolean_False;
21.22 }
21.23
21.24 -__attr __fn_native_int_int_add(__attr __args[])
21.25 +__attr __fn_native_int_int_add(__attr __self, __attr self, __attr other)
21.26 {
21.27 - __attr * const _data = &__args[1];
21.28 - __attr * const other = &__args[2];
21.29 - /* _data and other interpreted as int */
21.30 - int i = _data->intvalue;
21.31 - int j = other->intvalue;
21.32 + /* self and other interpreted as int */
21.33 + int i = __TOINT(self);
21.34 + int j = __TOINT(other);
21.35
21.36 /* Test for overflow. */
21.37 - if (((i > 0) && (j > 0) && (i > INT_MAX - j)) ||
21.38 - ((i < 0) && (j < 0) && (i < INT_MIN - j)))
21.39 + if (((i > 0) && (j > 0) && (i > __MAXINT - j)) ||
21.40 + ((i < 0) && (j < 0) && (i < __MININT - j)))
21.41
21.42 __raise_overflow_error();
21.43
21.44 @@ -57,17 +52,15 @@
21.45 return __new_int(i + j);
21.46 }
21.47
21.48 -__attr __fn_native_int_int_sub(__attr __args[])
21.49 +__attr __fn_native_int_int_sub(__attr __self, __attr self, __attr other)
21.50 {
21.51 - __attr * const _data = &__args[1];
21.52 - __attr * const other = &__args[2];
21.53 - /* _data and other interpreted as int */
21.54 - int i = _data->intvalue;
21.55 - int j = other->intvalue;
21.56 + /* self and other interpreted as int */
21.57 + int i = __TOINT(self);
21.58 + int j = __TOINT(other);
21.59
21.60 /* Test for overflow. */
21.61 - if (((i < 0) && (j > 0) && (i < INT_MIN + j)) ||
21.62 - ((i > 0) && (j < 0) && (i > INT_MAX + j)))
21.63 + if (((i < 0) && (j > 0) && (i < __MININT + j)) ||
21.64 + ((i > 0) && (j < 0) && (i > __MAXINT + j)))
21.65
21.66 __raise_overflow_error();
21.67
21.68 @@ -75,19 +68,17 @@
21.69 return __new_int(i - j);
21.70 }
21.71
21.72 -__attr __fn_native_int_int_mul(__attr __args[])
21.73 +__attr __fn_native_int_int_mul(__attr __self, __attr self, __attr other)
21.74 {
21.75 - __attr * const _data = &__args[1];
21.76 - __attr * const other = &__args[2];
21.77 - /* _data and other interpreted as int */
21.78 - int i = _data->intvalue;
21.79 - int j = other->intvalue;
21.80 + /* self and other interpreted as int */
21.81 + int i = __TOINT(self);
21.82 + int j = __TOINT(other);
21.83
21.84 /* Test for overflow. */
21.85 - if (((i > 0) && (j > 0) && (i > INT_MAX / j)) ||
21.86 - ((i < 0) && (j < 0) && (i > INT_MAX / j)) ||
21.87 - ((i < 0) && (j > 0) && (i < INT_MIN / j)) ||
21.88 - ((i > 0) && (j < 0) && (j < INT_MIN / i)))
21.89 + if (((i > 0) && (j > 0) && (i > __MAXINT / j)) ||
21.90 + ((i < 0) && (j < 0) && (i > __MAXINT / j)) ||
21.91 + ((i < 0) && (j > 0) && (i < __MININT / j)) ||
21.92 + ((i > 0) && (j < 0) && (j < __MININT / i)))
21.93
21.94 __raise_overflow_error();
21.95
21.96 @@ -95,63 +86,56 @@
21.97 return __new_int(i * j);
21.98 }
21.99
21.100 -__attr __fn_native_int_int_div(__attr __args[])
21.101 +__attr __fn_native_int_int_div(__attr __self, __attr self, __attr other)
21.102 {
21.103 - __attr * const _data = &__args[1];
21.104 - __attr * const other = &__args[2];
21.105 - /* _data and other interpreted as int */
21.106 - int i = _data->intvalue;
21.107 - int j = other->intvalue;
21.108 + /* self and other interpreted as int */
21.109 + int i = __TOINT(self);
21.110 + int j = __TOINT(other);
21.111
21.112 /* Test for division by zero or overflow. */
21.113 if (j == 0)
21.114 __raise_zero_division_error();
21.115 - else if ((j == -1) && (i == INT_MIN))
21.116 + else if ((j == -1) && (i == __MININT))
21.117 __raise_overflow_error();
21.118
21.119 /* Return the new integer. */
21.120 return __new_int(i / j);
21.121 }
21.122
21.123 -__attr __fn_native_int_int_mod(__attr __args[])
21.124 +__attr __fn_native_int_int_mod(__attr __self, __attr self, __attr other)
21.125 {
21.126 - __attr * const _data = &__args[1];
21.127 - __attr * const other = &__args[2];
21.128 - /* _data and other interpreted as int */
21.129 - int i = _data->intvalue;
21.130 - int j = other->intvalue;
21.131 + /* self and other interpreted as int */
21.132 + int i = __TOINT(self);
21.133 + int j = __TOINT(other);
21.134
21.135 /* Test for division by zero or overflow. */
21.136 if (j == 0)
21.137 __raise_zero_division_error();
21.138 - else if ((j == -1) && (i == INT_MIN))
21.139 + else if ((j == -1) && (i == __MININT))
21.140 __raise_overflow_error();
21.141
21.142 /* Return the new integer. */
21.143 return __new_int(i % j);
21.144 }
21.145
21.146 -__attr __fn_native_int_int_neg(__attr __args[])
21.147 +__attr __fn_native_int_int_neg(__attr __self, __attr self)
21.148 {
21.149 - __attr * const _data = &__args[1];
21.150 - /* _data interpreted as int */
21.151 - int i = _data->intvalue;
21.152 + /* self interpreted as int */
21.153 + int i = __TOINT(self);
21.154
21.155 /* Test for overflow. */
21.156 - if (i == INT_MIN)
21.157 + if (i == __MININT)
21.158 __raise_overflow_error();
21.159
21.160 /* Return the new integer. */
21.161 return __new_int(-i);
21.162 }
21.163
21.164 -__attr __fn_native_int_int_pow(__attr __args[])
21.165 +__attr __fn_native_int_int_pow(__attr __self, __attr self, __attr other)
21.166 {
21.167 - __attr * const _data = &__args[1];
21.168 - __attr * const other = &__args[2];
21.169 - /* _data and other interpreted as int */
21.170 - int i = _data->intvalue;
21.171 - int j = other->intvalue;
21.172 + /* self and other interpreted as int */
21.173 + int i = __TOINT(self);
21.174 + int j = __TOINT(other);
21.175 int k;
21.176
21.177 errno = 0;
21.178 @@ -166,111 +150,116 @@
21.179 return __new_int(k);
21.180 }
21.181
21.182 -__attr __fn_native_int_int_and(__attr __args[])
21.183 +__attr __fn_native_int_int_and(__attr __self, __attr self, __attr other)
21.184 {
21.185 - __attr * const _data = &__args[1];
21.186 - __attr * const other = &__args[2];
21.187 - /* _data and other interpreted as int */
21.188 - int i = _data->intvalue;
21.189 - int j = other->intvalue;
21.190 + /* self and other interpreted as int */
21.191 + int i = __TOINT(self);
21.192 + int j = __TOINT(other);
21.193
21.194 /* Return the new integer. */
21.195 /* NOTE: No overflow test applied. */
21.196 return __new_int(i & j);
21.197 }
21.198
21.199 -__attr __fn_native_int_int_not(__attr __args[])
21.200 +__attr __fn_native_int_int_not(__attr __self, __attr self)
21.201 {
21.202 - __attr * const _data = &__args[1];
21.203 - /* _data interpreted as int */
21.204 - int i = _data->intvalue;
21.205 + /* self interpreted as int */
21.206 + int i = __TOINT(self);
21.207
21.208 /* Return the new integer. */
21.209 return __new_int(~i);
21.210 }
21.211
21.212 -__attr __fn_native_int_int_or(__attr __args[])
21.213 +__attr __fn_native_int_int_or(__attr __self, __attr self, __attr other)
21.214 {
21.215 - __attr * const _data = &__args[1];
21.216 - __attr * const other = &__args[2];
21.217 - /* _data and other interpreted as int */
21.218 - int i = _data->intvalue;
21.219 - int j = other->intvalue;
21.220 + /* self and other interpreted as int */
21.221 + int i = __TOINT(self);
21.222 + int j = __TOINT(other);
21.223
21.224 /* Return the new integer. */
21.225 /* NOTE: No overflow test applied. */
21.226 return __new_int(i | j);
21.227 }
21.228
21.229 -__attr __fn_native_int_int_xor(__attr __args[])
21.230 +__attr __fn_native_int_int_xor(__attr __self, __attr self, __attr other)
21.231 {
21.232 - __attr * const _data = &__args[1];
21.233 - __attr * const other = &__args[2];
21.234 - /* _data and other interpreted as int */
21.235 - int i = _data->intvalue;
21.236 - int j = other->intvalue;
21.237 + /* self and other interpreted as int */
21.238 + int i = __TOINT(self);
21.239 + int j = __TOINT(other);
21.240
21.241 /* Return the new integer. */
21.242 /* NOTE: No overflow test applied. */
21.243 return __new_int(i ^ j);
21.244 }
21.245
21.246 -__attr __fn_native_int_int_lt(__attr __args[])
21.247 +__attr __fn_native_int_int_le(__attr __self, __attr self, __attr other)
21.248 {
21.249 - __attr * const _data = &__args[1];
21.250 - __attr * const other = &__args[2];
21.251 - /* _data and other interpreted as int */
21.252 - int i = _data->intvalue;
21.253 - int j = other->intvalue;
21.254 + /* self and other interpreted as int */
21.255 + int i = __TOINT(self);
21.256 + int j = __TOINT(other);
21.257 +
21.258 + /* Return a boolean result. */
21.259 + return i <= j ? __builtins___boolean_True : __builtins___boolean_False;
21.260 +}
21.261 +
21.262 +__attr __fn_native_int_int_lt(__attr __self, __attr self, __attr other)
21.263 +{
21.264 + /* self and other interpreted as int */
21.265 + int i = __TOINT(self);
21.266 + int j = __TOINT(other);
21.267
21.268 /* Return a boolean result. */
21.269 return i < j ? __builtins___boolean_True : __builtins___boolean_False;
21.270 }
21.271
21.272 -__attr __fn_native_int_int_gt(__attr __args[])
21.273 +__attr __fn_native_int_int_ge(__attr __self, __attr self, __attr other)
21.274 {
21.275 - __attr * const _data = &__args[1];
21.276 - __attr * const other = &__args[2];
21.277 - /* _data and other interpreted as int */
21.278 - int i = _data->intvalue;
21.279 - int j = other->intvalue;
21.280 + /* self and other interpreted as int */
21.281 + int i = __TOINT(self);
21.282 + int j = __TOINT(other);
21.283 +
21.284 + /* Return a boolean result. */
21.285 + return i >= j ? __builtins___boolean_True : __builtins___boolean_False;
21.286 +}
21.287 +
21.288 +__attr __fn_native_int_int_gt(__attr __self, __attr self, __attr other)
21.289 +{
21.290 + /* self and other interpreted as int */
21.291 + int i = __TOINT(self);
21.292 + int j = __TOINT(other);
21.293
21.294 /* Return a boolean result. */
21.295 return i > j ? __builtins___boolean_True : __builtins___boolean_False;
21.296 }
21.297
21.298 -__attr __fn_native_int_int_eq(__attr __args[])
21.299 +__attr __fn_native_int_int_eq(__attr __self, __attr self, __attr other)
21.300 {
21.301 - __attr * const _data = &__args[1];
21.302 - __attr * const other = &__args[2];
21.303 - /* _data and other interpreted as int */
21.304 - int i = _data->intvalue;
21.305 - int j = other->intvalue;
21.306 + /* self and other interpreted as int */
21.307 + int i = __TOINT(self);
21.308 + int j = __TOINT(other);
21.309
21.310 /* Return a boolean result. */
21.311 return i == j ? __builtins___boolean_True : __builtins___boolean_False;
21.312 }
21.313
21.314 -__attr __fn_native_int_int_ne(__attr __args[])
21.315 +__attr __fn_native_int_int_ne(__attr __self, __attr self, __attr other)
21.316 {
21.317 - __attr * const _data = &__args[1];
21.318 - __attr * const other = &__args[2];
21.319 - /* _data and other interpreted as int */
21.320 - int i = _data->intvalue;
21.321 - int j = other->intvalue;
21.322 + /* self and other interpreted as int */
21.323 + int i = __TOINT(self);
21.324 + int j = __TOINT(other);
21.325
21.326 /* Return a boolean result. */
21.327 return i != j ? __builtins___boolean_True : __builtins___boolean_False;
21.328 }
21.329
21.330 -__attr __fn_native_int_int_str(__attr __args[])
21.331 +__attr __fn_native_int_int_str(__attr __self, __attr self)
21.332 {
21.333 - __attr * const _data = &__args[1];
21.334 - /* _data interpreted as int */
21.335 - int i = _data->intvalue;
21.336 + /* self interpreted as int */
21.337 + int i = __TOINT(self);
21.338 +
21.339 /* Employ a buffer big enough to fit the largest integer plus an extra
21.340 character, a minus sign, and the null terminator. */
21.341 - unsigned int n = (int) log10(INT_MAX) + 3;
21.342 + unsigned int n = (int) log10(__MAXINT) + 3;
21.343 char *s = (char *) __ALLOCATE(n, sizeof(char));
21.344
21.345 snprintf(s, n, "%d", i);
22.1 --- a/templates/native/int.h Fri Mar 24 18:52:59 2017 +0100
22.2 +++ b/templates/native/int.h Sat Mar 25 14:26:26 2017 +0100
22.3 @@ -23,32 +23,28 @@
22.4
22.5 /* Integer operations. */
22.6
22.7 -__attr __fn_native_int_int_new(__attr __args[]);
22.8 -
22.9 -__attr __fn_native_int_int_add(__attr __args[]);
22.10 -__attr __fn_native_int_int_div(__attr __args[]);
22.11 -__attr __fn_native_int_int_mod(__attr __args[]);
22.12 -__attr __fn_native_int_int_mul(__attr __args[]);
22.13 -__attr __fn_native_int_int_neg(__attr __args[]);
22.14 -__attr __fn_native_int_int_pow(__attr __args[]);
22.15 -__attr __fn_native_int_int_sub(__attr __args[]);
22.16 +__attr __fn_native_int_is_int(__attr __self, __attr obj);
22.17 +__attr __fn_native_int_int_add(__attr __self, __attr _data, __attr other);
22.18 +__attr __fn_native_int_int_sub(__attr __self, __attr _data, __attr other);
22.19 +__attr __fn_native_int_int_mul(__attr __self, __attr _data, __attr other);
22.20 +__attr __fn_native_int_int_div(__attr __self, __attr _data, __attr other);
22.21 +__attr __fn_native_int_int_mod(__attr __self, __attr _data, __attr other);
22.22 +__attr __fn_native_int_int_neg(__attr __self, __attr _data);
22.23 +__attr __fn_native_int_int_pow(__attr __self, __attr _data, __attr other);
22.24
22.25 -__attr __fn_native_int_int_and(__attr __args[]);
22.26 -__attr __fn_native_int_int_not(__attr __args[]);
22.27 -__attr __fn_native_int_int_or(__attr __args[]);
22.28 -__attr __fn_native_int_int_xor(__attr __args[]);
22.29 +__attr __fn_native_int_int_and(__attr __self, __attr _data, __attr other);
22.30 +__attr __fn_native_int_int_not(__attr __self, __attr _data);
22.31 +__attr __fn_native_int_int_or(__attr __self, __attr _data, __attr other);
22.32 +__attr __fn_native_int_int_xor(__attr __self, __attr _data, __attr other);
22.33
22.34 -__attr __fn_native_int_int_rdiv(__attr __args[]);
22.35 -__attr __fn_native_int_int_rmod(__attr __args[]);
22.36 -__attr __fn_native_int_int_rpow(__attr __args[]);
22.37 -__attr __fn_native_int_int_rsub(__attr __args[]);
22.38 +__attr __fn_native_int_int_eq(__attr __self, __attr _data, __attr other);
22.39 +__attr __fn_native_int_int_ge(__attr __self, __attr _data, __attr other);
22.40 +__attr __fn_native_int_int_gt(__attr __self, __attr _data, __attr other);
22.41 +__attr __fn_native_int_int_le(__attr __self, __attr _data, __attr other);
22.42 +__attr __fn_native_int_int_lt(__attr __self, __attr _data, __attr other);
22.43 +__attr __fn_native_int_int_ne(__attr __self, __attr _data, __attr other);
22.44
22.45 -__attr __fn_native_int_int_lt(__attr __args[]);
22.46 -__attr __fn_native_int_int_gt(__attr __args[]);
22.47 -__attr __fn_native_int_int_eq(__attr __args[]);
22.48 -__attr __fn_native_int_int_ne(__attr __args[]);
22.49 -
22.50 -__attr __fn_native_int_int_str(__attr __args[]);
22.51 +__attr __fn_native_int_int_str(__attr __self, __attr _data);
22.52
22.53 /* Module initialisation. */
22.54
23.1 --- a/templates/native/introspection.c Fri Mar 24 18:52:59 2017 +0100
23.2 +++ b/templates/native/introspection.c Sat Mar 25 14:26:26 2017 +0100
23.3 @@ -26,56 +26,47 @@
23.4
23.5 /* Introspection. */
23.6
23.7 -__attr __fn_native_introspection_object_getattr(__attr __args[])
23.8 +__attr __fn_native_introspection_object_getattr(__attr __self, __attr obj, __attr name, __attr _default)
23.9 {
23.10 - __attr * const obj = &__args[1];
23.11 - __attr * const name = &__args[2];
23.12 - __attr * const _default = &__args[3];
23.13 - /* name.__data__ interpreted as string */
23.14 - __attr key = __load_via_object(name->value, __key__);
23.15 + /* name interpreted as string */
23.16 + __attr key = __load_via_object(__VALUE(name), __key__);
23.17 __attr out;
23.18
23.19 if ((key.code == 0) && (key.pos == 0))
23.20 - return *_default;
23.21 + return _default;
23.22
23.23 /* Attempt to get the attribute from the object. */
23.24
23.25 - out = __check_and_load_via_object_null(obj->value, key.pos, key.code);
23.26 - if (out.value == 0)
23.27 + out = __check_and_load_via_object_null(__VALUE(obj), key.pos, key.code);
23.28 + if (__ISNULL(out))
23.29 {
23.30 /* Inspect the object's class if this failed. */
23.31
23.32 - out = __check_and_load_via_class__(obj->value, key.pos, key.code);
23.33 - if (out.value == 0)
23.34 - return *_default;
23.35 + out = __check_and_load_via_class__(__VALUE(obj), key.pos, key.code);
23.36 + if (__ISNULL(out))
23.37 + return _default;
23.38
23.39 /* Update the context to the object if it is a method. */
23.40
23.41 - return __update_context(*obj, out);
23.42 + return __update_context(obj, out);
23.43 }
23.44
23.45 return out;
23.46 }
23.47
23.48 -__attr __fn_native_introspection_isinstance(__attr __args[])
23.49 +__attr __fn_native_introspection_isinstance(__attr __self, __attr obj, __attr cls)
23.50 {
23.51 - __attr * const obj = &__args[1];
23.52 - __attr * const cls = &__args[2];
23.53 -
23.54 /* cls must be a class. */
23.55 - if (__is_instance_subclass(obj->value, *cls))
23.56 + if (__is_instance_subclass(__VALUE(obj), cls))
23.57 return __builtins___boolean_True;
23.58 else
23.59 return __builtins___boolean_False;
23.60 }
23.61
23.62 -__attr __fn_native_introspection_issubclass(__attr __args[])
23.63 +__attr __fn_native_introspection_issubclass(__attr __self, __attr obj, __attr cls)
23.64 {
23.65 - __attr * const obj = &__args[1];
23.66 - __attr * const cls = &__args[2];
23.67 -
23.68 /* obj and cls must be classes. */
23.69 - if (__is_subclass(obj->value, *cls))
23.70 + if (__is_subclass(__VALUE(obj), cls))
23.71 return __builtins___boolean_True;
23.72 else
23.73 return __builtins___boolean_False;
24.1 --- a/templates/native/introspection.h Fri Mar 24 18:52:59 2017 +0100
24.2 +++ b/templates/native/introspection.h Sat Mar 25 14:26:26 2017 +0100
24.3 @@ -1,6 +1,6 @@
24.4 /* Native functions for introspection.
24.5
24.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
24.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
24.8
24.9 This program is free software; you can redistribute it and/or modify it under
24.10 the terms of the GNU General Public License as published by the Free Software
24.11 @@ -23,9 +23,9 @@
24.12
24.13 /* Introspection. */
24.14
24.15 -__attr __fn_native_introspection_object_getattr(__attr __args[]);
24.16 -__attr __fn_native_introspection_isinstance(__attr __args[]);
24.17 -__attr __fn_native_introspection_issubclass(__attr __args[]);
24.18 +__attr __fn_native_introspection_object_getattr(__attr __self, __attr obj, __attr name, __attr _default);
24.19 +__attr __fn_native_introspection_isinstance(__attr __self, __attr obj, __attr cls);
24.20 +__attr __fn_native_introspection_issubclass(__attr __self, __attr obj, __attr cls);
24.21
24.22 /* Module initialisation. */
24.23
25.1 --- a/templates/native/io.c Fri Mar 24 18:52:59 2017 +0100
25.2 +++ b/templates/native/io.c Sat Mar 25 14:26:26 2017 +0100
25.3 @@ -31,11 +31,10 @@
25.4
25.5 /* Input/output. */
25.6
25.7 -__attr __fn_native_io_fclose(__attr __args[])
25.8 +__attr __fn_native_io_fclose(__attr __self, __attr fp)
25.9 {
25.10 - __attr * const fp = &__args[1];
25.11 /* fp interpreted as FILE reference */
25.12 - FILE *f = (FILE *) fp->datavalue;
25.13 + FILE *f = (FILE *) fp.datavalue;
25.14
25.15 errno = 0;
25.16 if (fclose(f))
25.17 @@ -44,11 +43,10 @@
25.18 return __builtins___none_None;
25.19 }
25.20
25.21 -__attr __fn_native_io_fflush(__attr __args[])
25.22 +__attr __fn_native_io_fflush(__attr __self, __attr fp)
25.23 {
25.24 - __attr * const fp = &__args[1];
25.25 /* fp interpreted as FILE reference */
25.26 - FILE *f = (FILE *) fp->datavalue;
25.27 + FILE *f = (FILE *) fp.datavalue;
25.28
25.29 errno = 0;
25.30 if (fflush(f))
25.31 @@ -57,14 +55,12 @@
25.32 return __builtins___none_None;
25.33 }
25.34
25.35 -__attr __fn_native_io_fopen(__attr __args[])
25.36 +__attr __fn_native_io_fopen(__attr __self, __attr filename, __attr mode)
25.37 {
25.38 - __attr * const filename = &__args[1];
25.39 - __attr * const mode = &__args[2];
25.40 /* filename.__data__ interpreted as string */
25.41 - char *fn = __load_via_object(filename->value, __data__).strvalue;
25.42 + char *fn = __load_via_object(__VALUE(filename), __data__).strvalue;
25.43 /* mode.__data__ interpreted as string */
25.44 - char *s = __load_via_object(mode->value, __data__).strvalue;
25.45 + char *s = __load_via_object(__VALUE(mode), __data__).strvalue;
25.46 FILE *f;
25.47 __attr attr;
25.48
25.49 @@ -89,14 +85,12 @@
25.50 return __builtins___none_None;
25.51 }
25.52
25.53 -__attr __fn_native_io_fdopen(__attr __args[])
25.54 +__attr __fn_native_io_fdopen(__attr __self, __attr fd, __attr mode)
25.55 {
25.56 - __attr * const fd = &__args[1];
25.57 - __attr * const mode = &__args[2];
25.58 - /* fd.__data__ interpreted as int */
25.59 - int i = __load_via_object(fd->value, __data__).intvalue;
25.60 + /* fd interpreted as int */
25.61 + int i = __TOINT(fd);
25.62 /* mode.__data__ interpreted as string */
25.63 - char *s = __load_via_object(mode->value, __data__).strvalue;
25.64 + char *s = __load_via_object(__VALUE(mode), __data__).strvalue;
25.65 FILE *f;
25.66 __attr attr;
25.67
25.68 @@ -121,14 +115,12 @@
25.69 return __builtins___none_None;
25.70 }
25.71
25.72 -__attr __fn_native_io_fread(__attr __args[])
25.73 +__attr __fn_native_io_fread(__attr __self, __attr fp, __attr size)
25.74 {
25.75 - __attr * const fp = &__args[1];
25.76 - __attr * const size = &__args[2];
25.77 /* fp interpreted as FILE reference */
25.78 - FILE *f = (FILE *) fp->datavalue;
25.79 - /* size.__data__ interpreted as int */
25.80 - int to_read = __load_via_object(size->value, __data__).intvalue;
25.81 + FILE *f = (FILE *) fp.datavalue;
25.82 + /* size interpreted as int */
25.83 + int to_read = __TOINT(size);
25.84 char buf[to_read];
25.85 size_t have_read;
25.86 int error;
25.87 @@ -151,16 +143,14 @@
25.88 return __new_str(s, have_read);
25.89 }
25.90
25.91 -__attr __fn_native_io_fwrite(__attr __args[])
25.92 +__attr __fn_native_io_fwrite(__attr __self, __attr fp, __attr str)
25.93 {
25.94 - __attr * const fp = &__args[1];
25.95 - __attr * const str = &__args[2];
25.96 /* fp interpreted as FILE reference */
25.97 - FILE *f = (FILE *) fp->datavalue;
25.98 + FILE *f = (FILE *) fp.datavalue;
25.99 /* str.__data__ interpreted as string */
25.100 - char *s = __load_via_object(str->value, __data__).strvalue;
25.101 + char *s = __load_via_object(__VALUE(str), __data__).strvalue;
25.102 /* str.__size__ interpreted as int */
25.103 - int to_write = __load_via_object(str->value, __size__).intvalue;
25.104 + int to_write = __TOINT(__load_via_object(__VALUE(str), __size__));
25.105 size_t have_written = fwrite(s, sizeof(char), to_write, f);
25.106 int error;
25.107
25.108 @@ -175,11 +165,10 @@
25.109 return __builtins___none_None;
25.110 }
25.111
25.112 -__attr __fn_native_io_close(__attr __args[])
25.113 +__attr __fn_native_io_close(__attr __self, __attr fd)
25.114 {
25.115 - __attr * const fd = &__args[1];
25.116 - /* fd.__data__ interpreted as int */
25.117 - int i = __load_via_object(fd->value, __data__).intvalue;
25.118 + /* fd interpreted as int */
25.119 + int i = __TOINT(fd);
25.120
25.121 errno = 0;
25.122 if (close(i) == -1)
25.123 @@ -188,14 +177,12 @@
25.124 return __builtins___none_None;
25.125 }
25.126
25.127 -__attr __fn_native_io_read(__attr __args[])
25.128 +__attr __fn_native_io_read(__attr __self, __attr fd, __attr n)
25.129 {
25.130 - __attr * const fd = &__args[1];
25.131 - __attr * const n = &__args[2];
25.132 - /* fd.__data__ interpreted as int */
25.133 - int i = __load_via_object(fd->value, __data__).intvalue;
25.134 - /* n.__data__ interpreted as int */
25.135 - int to_read = __load_via_object(n->value, __data__).intvalue;
25.136 + /* fd interpreted as int */
25.137 + int i = __TOINT(fd);
25.138 + /* n interpreted as int */
25.139 + int to_read = __TOINT(n);
25.140 char buf[to_read];
25.141 ssize_t have_read;
25.142 char *s;
25.143 @@ -213,16 +200,14 @@
25.144 return __new_str(s, have_read);
25.145 }
25.146
25.147 -__attr __fn_native_io_write(__attr __args[])
25.148 +__attr __fn_native_io_write(__attr __self, __attr fd, __attr str)
25.149 {
25.150 - __attr * const fd = &__args[1];
25.151 - __attr * const str = &__args[2];
25.152 - /* fd.__data__ interpreted as int */
25.153 - int i = __load_via_object(fd->value, __data__).intvalue;
25.154 + /* fd interpreted as int */
25.155 + int i = __TOINT(fd);
25.156 /* str.__data__ interpreted as string */
25.157 - char *s = __load_via_object(str->value, __data__).strvalue;
25.158 + char *s = __load_via_object(__VALUE(str), __data__).strvalue;
25.159 /* str.__size__ interpreted as int */
25.160 - int size = __load_via_object(str->value, __size__).intvalue;
25.161 + int size = __TOINT(__load_via_object(__VALUE(str), __size__));
25.162 ssize_t have_written;
25.163
25.164 errno = 0;
26.1 --- a/templates/native/io.h Fri Mar 24 18:52:59 2017 +0100
26.2 +++ b/templates/native/io.h Sat Mar 25 14:26:26 2017 +0100
26.3 @@ -1,6 +1,6 @@
26.4 /* Native functions for input/output.
26.5
26.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
26.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
26.8
26.9 This program is free software; you can redistribute it and/or modify it under
26.10 the terms of the GNU General Public License as published by the Free Software
26.11 @@ -23,15 +23,15 @@
26.12
26.13 /* Input/output. */
26.14
26.15 -__attr __fn_native_io_fclose(__attr __args[]);
26.16 -__attr __fn_native_io_fflush(__attr __args[]);
26.17 -__attr __fn_native_io_fopen(__attr __args[]);
26.18 -__attr __fn_native_io_fdopen(__attr __args[]);
26.19 -__attr __fn_native_io_fread(__attr __args[]);
26.20 -__attr __fn_native_io_fwrite(__attr __args[]);
26.21 -__attr __fn_native_io_close(__attr __args[]);
26.22 -__attr __fn_native_io_read(__attr __args[]);
26.23 -__attr __fn_native_io_write(__attr __args[]);
26.24 +__attr __fn_native_io_fclose(__attr __self, __attr fp);
26.25 +__attr __fn_native_io_fflush(__attr __self, __attr fp);
26.26 +__attr __fn_native_io_fopen(__attr __self, __attr filename, __attr mode);
26.27 +__attr __fn_native_io_fdopen(__attr __self, __attr fd, __attr mode);
26.28 +__attr __fn_native_io_fread(__attr __self, __attr fp, __attr size);
26.29 +__attr __fn_native_io_fwrite(__attr __self, __attr fp, __attr str);
26.30 +__attr __fn_native_io_close(__attr __self, __attr fd);
26.31 +__attr __fn_native_io_read(__attr __self, __attr fd, __attr n);
26.32 +__attr __fn_native_io_write(__attr __self, __attr fd, __attr str);
26.33
26.34 /* Module initialisation. */
26.35
27.1 --- a/templates/native/limits.c Fri Mar 24 18:52:59 2017 +0100
27.2 +++ b/templates/native/limits.c Sat Mar 25 14:26:26 2017 +0100
27.3 @@ -1,6 +1,6 @@
27.4 /* Native functions for limit definition.
27.5
27.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
27.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
27.8
27.9 This program is free software; you can redistribute it and/or modify it under
27.10 the terms of the GNU General Public License as published by the Free Software
27.11 @@ -16,7 +16,6 @@
27.12 this program. If not, see <http://www.gnu.org/licenses/>.
27.13 */
27.14
27.15 -#include <limits.h> /* INT_MAX, INT_MIN */
27.16 #include "native/common.h"
27.17 #include "types.h"
27.18 #include "exceptions.h"
27.19 @@ -28,14 +27,14 @@
27.20
27.21 /* Limit definition. */
27.22
27.23 -__attr __fn_native_limits_get_maxint(__attr __args[])
27.24 +__attr __fn_native_limits_get_maxint(__attr __self)
27.25 {
27.26 - return __new_int(INT_MAX);
27.27 + return __new_int(__MAXINT);
27.28 }
27.29
27.30 -__attr __fn_native_limits_get_minint(__attr __args[])
27.31 +__attr __fn_native_limits_get_minint(__attr __self)
27.32 {
27.33 - return __new_int(INT_MIN);
27.34 + return __new_int(__MININT);
27.35 }
27.36
27.37 /* Module initialisation. */
28.1 --- a/templates/native/limits.h Fri Mar 24 18:52:59 2017 +0100
28.2 +++ b/templates/native/limits.h Sat Mar 25 14:26:26 2017 +0100
28.3 @@ -1,6 +1,6 @@
28.4 /* Native functions for limit definition.
28.5
28.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
28.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
28.8
28.9 This program is free software; you can redistribute it and/or modify it under
28.10 the terms of the GNU General Public License as published by the Free Software
28.11 @@ -23,8 +23,8 @@
28.12
28.13 /* Limit definition. */
28.14
28.15 -__attr __fn_native_limits_get_maxint(__attr __args[]);
28.16 -__attr __fn_native_limits_get_minint(__attr __args[]);
28.17 +__attr __fn_native_limits_get_maxint(__attr __self);
28.18 +__attr __fn_native_limits_get_minint(__attr __self);
28.19
28.20 /* Module initialisation. */
28.21
29.1 --- a/templates/native/list.c Fri Mar 24 18:52:59 2017 +0100
29.2 +++ b/templates/native/list.c Sat Mar 25 14:26:26 2017 +0100
29.3 @@ -27,51 +27,44 @@
29.4
29.5 /* List operations. */
29.6
29.7 -__attr __fn_native_list_list_init(__attr __args[])
29.8 +__attr __fn_native_list_list_init(__attr __self, __attr size)
29.9 {
29.10 - __attr * const size = &__args[1];
29.11 - /* size.__data__ interpreted as int */
29.12 - unsigned int n = __load_via_object(size->value, __data__).intvalue;
29.13 + /* size interpreted as int */
29.14 + unsigned int n = __TOINT(size);
29.15 __attr attr = {.seqvalue=__new_fragment(n)};
29.16
29.17 /* Return the __data__ attribute. */
29.18 return attr;
29.19 }
29.20
29.21 -__attr __fn_native_list_list_setsize(__attr __args[])
29.22 +__attr __fn_native_list_list_setsize(__attr __self, __attr _data, __attr size)
29.23 {
29.24 - __attr * const _data = &__args[1];
29.25 - __attr * const size = &__args[2];
29.26 - /* _data interpreted as list */
29.27 - __fragment *data = _data->seqvalue;
29.28 - /* size.__data__ interpreted as int */
29.29 - unsigned int n = __load_via_object(size->value, __data__).intvalue;
29.30 + /* _data interpreted as list.__data__ */
29.31 + __fragment *data = _data.seqvalue;
29.32 + /* size interpreted as int */
29.33 + unsigned int n = __TOINT(size);
29.34
29.35 data->size = n;
29.36 return __builtins___none_None;
29.37 }
29.38
29.39 -__attr __fn_native_list_list_append(__attr __args[])
29.40 +__attr __fn_native_list_list_append(__attr __self, __attr self, __attr value)
29.41 {
29.42 - __attr * const self = &__args[1];
29.43 - __attr * const value = &__args[2];
29.44 /* self.__data__ interpreted as list */
29.45 - __fragment *data = __load_via_object(self->value, __data__).seqvalue;
29.46 + __fragment *data = __load_via_object(__VALUE(self), __data__).seqvalue;
29.47 __fragment *newdata = __fragment_append(data, value);
29.48
29.49 /* Replace the __data__ attribute if appropriate. */
29.50 if (newdata != data)
29.51 - __store_via_object(self->value, __data__, ((__attr) {.seqvalue=newdata}));
29.52 + __store_via_object(__VALUE(self), __data__, ((__attr) {.seqvalue=newdata}));
29.53 return __builtins___none_None;
29.54 }
29.55
29.56 -__attr __fn_native_list_list_concat(__attr __args[])
29.57 +__attr __fn_native_list_list_concat(__attr __self, __attr self, __attr other)
29.58 {
29.59 - __attr * const self = &__args[1];
29.60 - __attr * const other = &__args[2];
29.61 - /* self.__data__, other interpreted as list */
29.62 - __fragment *data = __load_via_object(self->value, __data__).seqvalue;
29.63 - __fragment *other_data = other->seqvalue;
29.64 + /* self, interpreted as list, other interpreted as list.__data__ */
29.65 + __fragment *data = __load_via_object(__VALUE(self), __data__).seqvalue;
29.66 + __fragment *other_data = other.seqvalue;
29.67 __fragment *newdata = data;
29.68 unsigned int size = data->size, capacity = data->capacity;
29.69 unsigned int other_size = other_data->size;
29.70 @@ -91,51 +84,43 @@
29.71
29.72 /* Replace the __data__ attribute if appropriate. */
29.73 if (newdata != data)
29.74 - __store_via_object(self->value, __data__, ((__attr) {.seqvalue=newdata}));
29.75 + __store_via_object(__VALUE(self), __data__, ((__attr) {.seqvalue=newdata}));
29.76 return __builtins___none_None;
29.77 }
29.78
29.79 -__attr __fn_native_list_list_len(__attr __args[])
29.80 +__attr __fn_native_list_list_len(__attr self, __attr _data)
29.81 {
29.82 - __attr * const _data = &__args[1];
29.83 - /* _data interpreted as fragment */
29.84 - unsigned int size = _data->seqvalue->size;
29.85 + /* _data interpreted as list.__data__ */
29.86 + unsigned int size = _data.seqvalue->size;
29.87
29.88 /* Return the new integer. */
29.89 return __new_int(size);
29.90 }
29.91
29.92 -__attr __fn_native_list_list_nonempty(__attr __args[])
29.93 +__attr __fn_native_list_list_nonempty(__attr __self, __attr _data)
29.94 {
29.95 - __attr * const _data = &__args[1];
29.96 -
29.97 - return _data->seqvalue->size ? __builtins___boolean_True : __builtins___boolean_False;
29.98 + return _data.seqvalue->size ? __builtins___boolean_True : __builtins___boolean_False;
29.99 }
29.100
29.101 -__attr __fn_native_list_list_element(__attr __args[])
29.102 +__attr __fn_native_list_list_element(__attr __self, __attr _data, __attr index)
29.103 {
29.104 - __attr * const _data = &__args[1];
29.105 - __attr * const index = &__args[2];
29.106 - /* _data interpreted as fragment */
29.107 - __attr *elements = _data->seqvalue->attrs;
29.108 - /* index.__data__ interpreted as int */
29.109 - int i = __load_via_object(index->value, __data__).intvalue;
29.110 + /* _data interpreted as list.__data__ */
29.111 + __attr *elements = _data.seqvalue->attrs;
29.112 + /* index interpreted as int */
29.113 + int i = __TOINT(index);
29.114
29.115 return elements[i];
29.116 }
29.117
29.118 -__attr __fn_native_list_list_setelement(__attr __args[])
29.119 +__attr __fn_native_list_list_setelement(__attr __self, __attr _data, __attr index, __attr value)
29.120 {
29.121 - __attr * const _data = &__args[1];
29.122 - __attr * const index = &__args[2];
29.123 - __attr * const value = &__args[3];
29.124 - /* _data interpreted as fragment */
29.125 - __attr *elements = _data->seqvalue->attrs;
29.126 - /* index.__data__ interpreted as int */
29.127 - int i = __load_via_object(index->value, __data__).intvalue;
29.128 + /* _data interpreted as list.__data__ */
29.129 + __attr *elements = _data.seqvalue->attrs;
29.130 + /* index interpreted as int */
29.131 + int i = __TOINT(index);
29.132
29.133 /* Set the element. */
29.134 - elements[i] = *value;
29.135 + elements[i] = value;
29.136 return __builtins___none_None;
29.137 }
29.138
30.1 --- a/templates/native/list.h Fri Mar 24 18:52:59 2017 +0100
30.2 +++ b/templates/native/list.h Sat Mar 25 14:26:26 2017 +0100
30.3 @@ -1,6 +1,6 @@
30.4 /* Native functions for list operations.
30.5
30.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
30.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
30.8
30.9 This program is free software; you can redistribute it and/or modify it under
30.10 the terms of the GNU General Public License as published by the Free Software
30.11 @@ -23,14 +23,14 @@
30.12
30.13 /* List operations. */
30.14
30.15 -__attr __fn_native_list_list_init(__attr __args[]);
30.16 -__attr __fn_native_list_list_setsize(__attr __args[]);
30.17 -__attr __fn_native_list_list_append(__attr __args[]);
30.18 -__attr __fn_native_list_list_concat(__attr __args[]);
30.19 -__attr __fn_native_list_list_len(__attr __args[]);
30.20 -__attr __fn_native_list_list_nonempty(__attr __args[]);
30.21 -__attr __fn_native_list_list_element(__attr __args[]);
30.22 -__attr __fn_native_list_list_setelement(__attr __args[]);
30.23 +__attr __fn_native_list_list_init(__attr __self, __attr size);
30.24 +__attr __fn_native_list_list_setsize(__attr __self, __attr _data, __attr size);
30.25 +__attr __fn_native_list_list_append(__attr __self, __attr self, __attr value);
30.26 +__attr __fn_native_list_list_concat(__attr __self, __attr self, __attr other);
30.27 +__attr __fn_native_list_list_len(__attr self, __attr _data);
30.28 +__attr __fn_native_list_list_nonempty(__attr __self, __attr _data);
30.29 +__attr __fn_native_list_list_element(__attr __self, __attr _data, __attr index);
30.30 +__attr __fn_native_list_list_setelement(__attr __self, __attr _data, __attr index, __attr value);
30.31
30.32 /* Module initialisation. */
30.33
31.1 --- a/templates/native/locale.c Fri Mar 24 18:52:59 2017 +0100
31.2 +++ b/templates/native/locale.c Sat Mar 25 14:26:26 2017 +0100
31.3 @@ -29,11 +29,10 @@
31.4
31.5 /* Locales. */
31.6
31.7 -__attr __fn_native_locale_getlocale(__attr __args[])
31.8 +__attr __fn_native_locale_getlocale(__attr __self, __attr category)
31.9 {
31.10 - __attr * const category = &__args[1];
31.11 - /* category.__data__ interpreted as int */
31.12 - int cat = __load_via_object(category->value, __data__).intvalue;
31.13 + /* category interpreted as int */
31.14 + int cat = __TOINT(category);
31.15 char *result, *out;
31.16 size_t length;
31.17
31.18 @@ -49,14 +48,12 @@
31.19 return __new_str(result, length);
31.20 }
31.21
31.22 -__attr __fn_native_locale_setlocale(__attr __args[])
31.23 +__attr __fn_native_locale_setlocale(__attr __self, __attr category, __attr value)
31.24 {
31.25 - __attr * const category = &__args[1];
31.26 - __attr * const value = &__args[2];
31.27 - /* category.__data__ interpreted as int */
31.28 - int cat = __load_via_object(category->value, __data__).intvalue;
31.29 - /* value.__data__ interpreted as string */
31.30 - char *s = __load_via_object(value->value, __data__).strvalue;
31.31 + /* category interpreted as int */
31.32 + int cat = __TOINT(category);
31.33 + /* value interpreted as string */
31.34 + char *s = __load_via_object(__VALUE(value), __data__).strvalue;
31.35 char *result, *out;
31.36 size_t length;
31.37
32.1 --- a/templates/native/locale.h Fri Mar 24 18:52:59 2017 +0100
32.2 +++ b/templates/native/locale.h Sat Mar 25 14:26:26 2017 +0100
32.3 @@ -1,6 +1,6 @@
32.4 /* Native functions for locale handling.
32.5
32.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
32.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
32.8
32.9 This program is free software; you can redistribute it and/or modify it under
32.10 the terms of the GNU General Public License as published by the Free Software
32.11 @@ -23,8 +23,8 @@
32.12
32.13 /* Input/output. */
32.14
32.15 -__attr __fn_native_locale_getlocale(__attr __args[]);
32.16 -__attr __fn_native_locale_setlocale(__attr __args[]);
32.17 +__attr __fn_native_locale_getlocale(__attr __self, __attr category);
32.18 +__attr __fn_native_locale_setlocale(__attr __self, __attr category, __attr value);
32.19
32.20 /* Module initialisation. */
32.21
33.1 --- a/templates/native/program.c Fri Mar 24 18:52:59 2017 +0100
33.2 +++ b/templates/native/program.c Sat Mar 25 14:26:26 2017 +0100
33.3 @@ -26,12 +26,9 @@
33.4
33.5 /* Method binding. */
33.6
33.7 -__attr __fn_native_program_get_using(__attr __args[])
33.8 +__attr __fn_native_program_get_using(__attr __self, __attr callable, __attr instance)
33.9 {
33.10 - __attr * const callable = &__args[1];
33.11 - __attr * const instance = &__args[2];
33.12 -
33.13 - return __test_context(*instance, *callable);
33.14 + return __test_context(instance, callable);
33.15 }
33.16
33.17 /* Module initialisation. */
34.1 --- a/templates/native/program.h Fri Mar 24 18:52:59 2017 +0100
34.2 +++ b/templates/native/program.h Sat Mar 25 14:26:26 2017 +0100
34.3 @@ -1,6 +1,6 @@
34.4 /* Native functions for program operations.
34.5
34.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
34.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
34.8
34.9 This program is free software; you can redistribute it and/or modify it under
34.10 the terms of the GNU General Public License as published by the Free Software
34.11 @@ -21,7 +21,7 @@
34.12
34.13 /* Method binding. */
34.14
34.15 -__attr __fn_native_program_get_using(__attr __args[]);
34.16 +__attr __fn_native_program_get_using(__attr __self, __attr callable, __attr instance);
34.17
34.18 /* Module initialisation. */
34.19
35.1 --- a/templates/native/str.c Fri Mar 24 18:52:59 2017 +0100
35.2 +++ b/templates/native/str.c Sat Mar 25 14:26:26 2017 +0100
35.3 @@ -28,16 +28,13 @@
35.4
35.5 /* String operations. */
35.6
35.7 -__attr __fn_native_str_str_add(__attr __args[])
35.8 +__attr __fn_native_str_str_add(__attr __self, __attr _data, __attr other, __attr _size, __attr othersize)
35.9 {
35.10 - __attr * const _data = &__args[1];
35.11 - __attr * const other = &__args[2];
35.12 - __attr * const _size = &__args[3];
35.13 - __attr * const othersize = &__args[4];
35.14 - /* _data, other interpreted as string */
35.15 - char *s = _data->strvalue;
35.16 - char *o = other->strvalue;
35.17 - int ss = _size->intvalue, os = othersize->intvalue;
35.18 + /* _data, other interpreted as string.__data__ */
35.19 + char *s = _data.strvalue;
35.20 + char *o = other.strvalue;
35.21 + /* _size, othersize interpreted as int */
35.22 + int ss = __TOINT(_size), os = __TOINT(othersize);
35.23 int n = ss + os;
35.24 char *r = (char *) __ALLOCATE(n + 1, sizeof(char));
35.25
35.26 @@ -48,76 +45,64 @@
35.27 return __new_str(r, n);
35.28 }
35.29
35.30 -__attr __fn_native_str_str_chr(__attr __args[])
35.31 +__attr __fn_native_str_str_chr(__attr __self, __attr _data)
35.32 {
35.33 - __attr * const _data = &__args[1];
35.34 - /* _data interpreted as int */
35.35 - int n = _data->intvalue;
35.36 + /* data interpreted as int */
35.37 + int n = __TOINT(_data);
35.38 char *s = (char *) __ALLOCATE(2, sizeof(char));
35.39
35.40 s[0] = (char) n;
35.41 return __new_str(s, 1);
35.42 }
35.43
35.44 -__attr __fn_native_str_str_lt(__attr __args[])
35.45 +__attr __fn_native_str_str_lt(__attr __self, __attr _data, __attr other)
35.46 {
35.47 - __attr * const _data = &__args[1];
35.48 - __attr * const other = &__args[2];
35.49 - /* _data, other interpreted as string */
35.50 - char *s = _data->strvalue;
35.51 - char *o = other->strvalue;
35.52 + /* _data, other interpreted as string.__data__ */
35.53 + char *s = _data.strvalue;
35.54 + char *o = other.strvalue;
35.55
35.56 /* NOTE: Using simple byte-level string operations. */
35.57 return strcmp(s, o) < 0 ? __builtins___boolean_True : __builtins___boolean_False;
35.58 }
35.59
35.60 -__attr __fn_native_str_str_gt(__attr __args[])
35.61 +__attr __fn_native_str_str_gt(__attr __self, __attr _data, __attr other)
35.62 {
35.63 - __attr * const _data = &__args[1];
35.64 - __attr * const other = &__args[2];
35.65 - /* _data, other interpreted as string */
35.66 - char *s = _data->strvalue;
35.67 - char *o = other->strvalue;
35.68 + /* _data, other interpreted as string.__data__ */
35.69 + char *s = _data.strvalue;
35.70 + char *o = other.strvalue;
35.71
35.72 /* NOTE: Using simple byte-level string operations. */
35.73 return strcmp(s, o) > 0 ? __builtins___boolean_True : __builtins___boolean_False;
35.74 }
35.75
35.76 -__attr __fn_native_str_str_eq(__attr __args[])
35.77 +__attr __fn_native_str_str_eq(__attr __self, __attr _data, __attr other)
35.78 {
35.79 - __attr * const _data = &__args[1];
35.80 - __attr * const other = &__args[2];
35.81 - /* _data, other interpreted as string */
35.82 - char *s = _data->strvalue;
35.83 - char *o = other->strvalue;
35.84 + /* _data, other interpreted as string.__data__ */
35.85 + char *s = _data.strvalue;
35.86 + char *o = other.strvalue;
35.87
35.88 /* NOTE: Using simple byte-level string operations. */
35.89 return strcmp(s, o) == 0 ? __builtins___boolean_True : __builtins___boolean_False;
35.90 }
35.91
35.92 -__attr __fn_native_str_str_ord(__attr __args[])
35.93 +__attr __fn_native_str_str_ord(__attr __self, __attr _data)
35.94 {
35.95 - __attr * const _data = &__args[1];
35.96 - /* _data interpreted as string */
35.97 - char *s = _data->strvalue;
35.98 + /* _data interpreted as string.__data__ */
35.99 + char *s = _data.strvalue;
35.100
35.101 return __new_int((unsigned int) s[0]);
35.102 }
35.103
35.104 -__attr __fn_native_str_str_substr(__attr __args[])
35.105 +__attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step)
35.106 {
35.107 - __attr * const _data = &__args[1];
35.108 - __attr * const start = &__args[2];
35.109 - __attr * const end = &__args[3];
35.110 - __attr * const step = &__args[4];
35.111 - /* _data interpreted as string */
35.112 - char *s = _data->strvalue, *sub;
35.113 - /* start.__data__ interpreted as int */
35.114 - int istart = __load_via_object(start->value, __data__).intvalue;
35.115 - /* end.__data__ interpreted as int */
35.116 - int iend = __load_via_object(end->value, __data__).intvalue;
35.117 - /* step.__data__ interpreted as int */
35.118 - int istep = __load_via_object(step->value, __data__).intvalue;
35.119 + /* _data interpreted as string.__data__ */
35.120 + char *s = _data.strvalue, *sub;
35.121 + /* start interpreted as int */
35.122 + int istart = __TOINT(start);
35.123 + /* end interpreted as int */
35.124 + int iend = __TOINT(end);
35.125 + /* step interpreted as int */
35.126 + int istep = __TOINT(step);
35.127
35.128 /* Calculate the size of the substring. */
35.129 size_t resultsize = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
36.1 --- a/templates/native/str.h Fri Mar 24 18:52:59 2017 +0100
36.2 +++ b/templates/native/str.h Sat Mar 25 14:26:26 2017 +0100
36.3 @@ -21,13 +21,13 @@
36.4
36.5 /* String operations. */
36.6
36.7 -__attr __fn_native_str_str_add(__attr __args[]);
36.8 -__attr __fn_native_str_str_chr(__attr __args[]);
36.9 -__attr __fn_native_str_str_lt(__attr __args[]);
36.10 -__attr __fn_native_str_str_gt(__attr __args[]);
36.11 -__attr __fn_native_str_str_eq(__attr __args[]);
36.12 -__attr __fn_native_str_str_ord(__attr __args[]);
36.13 -__attr __fn_native_str_str_substr(__attr __args[]);
36.14 +__attr __fn_native_str_str_add(__attr __self, __attr _data, __attr other, __attr _size, __attr othersize);
36.15 +__attr __fn_native_str_str_chr(__attr __self, __attr _data);
36.16 +__attr __fn_native_str_str_lt(__attr __self, __attr _data, __attr other);
36.17 +__attr __fn_native_str_str_gt(__attr __self, __attr _data, __attr other);
36.18 +__attr __fn_native_str_str_eq(__attr __self, __attr _data, __attr other);
36.19 +__attr __fn_native_str_str_ord(__attr __self, __attr _data);
36.20 +__attr __fn_native_str_str_substr(__attr __self, __attr _data, __attr start, __attr end, __attr step);
36.21
36.22 /* Module initialisation. */
36.23
37.1 --- a/templates/native/system.c Fri Mar 24 18:52:59 2017 +0100
37.2 +++ b/templates/native/system.c Sat Mar 25 14:26:26 2017 +0100
37.3 @@ -27,21 +27,19 @@
37.4
37.5 /* Environment support. */
37.6
37.7 -__attr __fn_native_system_exit(__attr __args[])
37.8 +__attr __fn_native_system_exit(__attr __self, __attr status)
37.9 {
37.10 - __attr * const status = &__args[1];
37.11 -
37.12 - exit(__load_via_object(status->value, __data__).intvalue);
37.13 + exit(__TOINT(status));
37.14 return __builtins___none_None;
37.15 }
37.16
37.17 -__attr __fn_native_system_get_argv(__attr __args[])
37.18 +__attr __fn_native_system_get_argv(__attr __self)
37.19 {
37.20 /* NOTE: To be written. */
37.21 return __builtins___none_None;
37.22 }
37.23
37.24 -__attr __fn_native_system_get_path(__attr __args[])
37.25 +__attr __fn_native_system_get_path(__attr __self)
37.26 {
37.27 /* NOTE: To be written. */
37.28 return __builtins___none_None;
38.1 --- a/templates/native/system.h Fri Mar 24 18:52:59 2017 +0100
38.2 +++ b/templates/native/system.h Sat Mar 25 14:26:26 2017 +0100
38.3 @@ -1,6 +1,6 @@
38.4 /* Native functions for system operations.
38.5
38.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
38.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
38.8
38.9 This program is free software; you can redistribute it and/or modify it under
38.10 the terms of the GNU General Public License as published by the Free Software
38.11 @@ -23,9 +23,9 @@
38.12
38.13 /* Environment support. */
38.14
38.15 -__attr __fn_native_system_exit(__attr __args[]);
38.16 -__attr __fn_native_system_get_argv(__attr __args[]);
38.17 -__attr __fn_native_system_get_path(__attr __args[]);
38.18 +__attr __fn_native_system_exit(__attr __self, __attr status);
38.19 +__attr __fn_native_system_get_argv(__attr __self);
38.20 +__attr __fn_native_system_get_path(__attr __self);
38.21
38.22 /* Module initialisation. */
38.23
39.1 --- a/templates/native/unicode.c Fri Mar 24 18:52:59 2017 +0100
39.2 +++ b/templates/native/unicode.c Sat Mar 25 14:26:26 2017 +0100
39.3 @@ -69,14 +69,12 @@
39.4
39.5 /* Unicode operations. */
39.6
39.7 -__attr __fn_native_unicode_unicode_len(__attr __args[])
39.8 +__attr __fn_native_unicode_unicode_len(__attr __self, __attr _data, __attr _size)
39.9 {
39.10 - __attr * const _data = &__args[1];
39.11 - __attr * const _size = &__args[2];
39.12 - /* _data interpreted as string */
39.13 - char *s = _data->strvalue;
39.14 + /* _data interpreted as string.__data__ */
39.15 + char *s = _data.strvalue;
39.16 /* _size interpreted as int */
39.17 - int size = _size->intvalue;
39.18 + int size = __TOINT(_size);
39.19 unsigned int i, c = 0;
39.20
39.21 for (i = 0; i < size; i++)
39.22 @@ -87,14 +85,12 @@
39.23 return __new_int(c);
39.24 }
39.25
39.26 -__attr __fn_native_unicode_unicode_ord(__attr __args[])
39.27 +__attr __fn_native_unicode_unicode_ord(__attr __self, __attr _data, __attr _size)
39.28 {
39.29 - __attr * const _data = &__args[1];
39.30 - __attr * const _size = &__args[2];
39.31 - /* _data interpreted as string */
39.32 - char *s = _data->strvalue;
39.33 + /* _data interpreted as string.__data__ */
39.34 + char *s = _data.strvalue;
39.35 /* _size interpreted as int */
39.36 - int size = _size->intvalue;
39.37 + int size = __TOINT(_size);
39.38 unsigned int i, c = 0, v;
39.39
39.40 for (i = 0; i < size; i++)
39.41 @@ -123,23 +119,18 @@
39.42 return __new_int(c);
39.43 }
39.44
39.45 -__attr __fn_native_unicode_unicode_substr(__attr __args[])
39.46 +__attr __fn_native_unicode_unicode_substr(__attr __self, __attr _data, __attr _size, __attr start, __attr end, __attr step)
39.47 {
39.48 - __attr * const _data = &__args[1];
39.49 - __attr * const _size = &__args[2];
39.50 - __attr * const start = &__args[3];
39.51 - __attr * const end = &__args[4];
39.52 - __attr * const step = &__args[5];
39.53 - /* _data interpreted as string */
39.54 - char *s = _data->strvalue, *sub;
39.55 + /* _data interpreted as string.__data__ */
39.56 + char *s = _data.strvalue, *sub;
39.57 /* _size interpreted as int */
39.58 - int ss = _size->intvalue;
39.59 - /* start.__data__ interpreted as int */
39.60 - int istart = __load_via_object(start->value, __data__).intvalue;
39.61 - /* end.__data__ interpreted as int */
39.62 - int iend = __load_via_object(end->value, __data__).intvalue;
39.63 - /* step.__data__ interpreted as int */
39.64 - int istep = __load_via_object(step->value, __data__).intvalue;
39.65 + int ss = __TOINT(_size);
39.66 + /* start interpreted as int */
39.67 + int istart = __TOINT(start);
39.68 + /* end interpreted as int */
39.69 + int iend = __TOINT(end);
39.70 + /* step interpreted as int */
39.71 + int istep = __TOINT(step);
39.72
39.73 /* Calculate the number of characters. */
39.74 size_t nchar = ((iend - istart - (istep > 0 ? 1 : -1)) / istep) + 1;
39.75 @@ -202,11 +193,10 @@
39.76 return __new_str(sub, resultsize);
39.77 }
39.78
39.79 -__attr __fn_native_unicode_unicode_unichr(__attr __args[])
39.80 +__attr __fn_native_unicode_unicode_unichr(__attr __self, __attr value)
39.81 {
39.82 - __attr * const value = &__args[1];
39.83 /* value interpreted as int */
39.84 - int i = value->intvalue;
39.85 + int i = __TOINT(value);
39.86 unsigned int resultsize;
39.87 char *s;
39.88
40.1 --- a/templates/native/unicode.h Fri Mar 24 18:52:59 2017 +0100
40.2 +++ b/templates/native/unicode.h Sat Mar 25 14:26:26 2017 +0100
40.3 @@ -21,10 +21,10 @@
40.4
40.5 /* Unicode operations. */
40.6
40.7 -__attr __fn_native_unicode_unicode_len(__attr __args[]);
40.8 -__attr __fn_native_unicode_unicode_ord(__attr __args[]);
40.9 -__attr __fn_native_unicode_unicode_substr(__attr __args[]);
40.10 -__attr __fn_native_unicode_unicode_unichr(__attr __args[]);
40.11 +__attr __fn_native_unicode_unicode_len(__attr __self, __attr _data, __attr _size);
40.12 +__attr __fn_native_unicode_unicode_ord(__attr __self, __attr _data, __attr _size);
40.13 +__attr __fn_native_unicode_unicode_substr(__attr __self, __attr _data, __attr _size, __attr start, __attr end, __attr step);
40.14 +__attr __fn_native_unicode_unicode_unichr(__attr __self, __attr value);
40.15
40.16 /* Module initialisation. */
40.17
41.1 --- a/templates/ops.c Fri Mar 24 18:52:59 2017 +0100
41.2 +++ b/templates/ops.c Sat Mar 25 14:26:26 2017 +0100
41.3 @@ -27,7 +27,10 @@
41.4
41.5 __ref __VALUE(__attr attr)
41.6 {
41.7 - return attr.value;
41.8 + if (!__INTEGER(attr))
41.9 + return attr.value;
41.10 + else
41.11 + return &__common_integer_obj;
41.12 }
41.13
41.14 /* Basic structure tests. */
41.15 @@ -316,17 +319,17 @@
41.16 return __VALUE(value) ? value : callable;
41.17 }
41.18
41.19 -__attr (*__get_function_unchecked(__attr target))(__attr[])
41.20 +__attr (*__get_function_unchecked(__attr target))()
41.21 {
41.22 return __load_via_object(__VALUE(__unwrap_callable(target)), __fn__).fn;
41.23 }
41.24
41.25 -__attr (*__get_function(__attr context, __attr target))(__attr[])
41.26 +__attr (*__get_function(__attr context, __attr target))()
41.27 {
41.28 return __get_function_unwrapped(context, __unwrap_callable(target));
41.29 }
41.30
41.31 -__attr (*__get_function_unwrapped(__attr context, __attr target))(__attr[])
41.32 +__attr (*__get_function_unwrapped(__attr context, __attr target))()
41.33 {
41.34 /* Require null or instance contexts for functions and methods respectively,
41.35 or type instance contexts for type methods. */
41.36 @@ -337,12 +340,12 @@
41.37 return __unbound_method;
41.38 }
41.39
41.40 -__attr (*__check_and_get_function(__attr context, __attr target))(__attr[])
41.41 +__attr (*__check_and_get_function(__attr context, __attr target))()
41.42 {
41.43 return __check_and_get_function_unwrapped(context, __unwrap_callable(target));
41.44 }
41.45
41.46 -__attr (*__check_and_get_function_unwrapped(__attr context, __attr target))(__attr[])
41.47 +__attr (*__check_and_get_function_unwrapped(__attr context, __attr target))()
41.48 {
41.49 /* Require null or instance contexts for functions and methods respectively,
41.50 or type instance contexts for type methods. */
42.1 --- a/templates/ops.h Fri Mar 24 18:52:59 2017 +0100
42.2 +++ b/templates/ops.h Sat Mar 25 14:26:26 2017 +0100
42.3 @@ -112,11 +112,11 @@
42.4 /* Context testing for invocations. */
42.5
42.6 __attr __unwrap_callable(__attr callable);
42.7 -__attr (*__get_function_unchecked(__attr target))(__attr[]);
42.8 -__attr (*__get_function(__attr context, __attr target))(__attr[]);
42.9 -__attr (*__get_function_unwrapped(__attr context, __attr target))(__attr[]);
42.10 -__attr (*__check_and_get_function(__attr context, __attr target))(__attr[]);
42.11 -__attr (*__check_and_get_function_unwrapped(__attr context, __attr target))(__attr[]);
42.12 +__attr (*__get_function_unchecked(__attr target))();
42.13 +__attr (*__get_function(__attr context, __attr target))();
42.14 +__attr (*__get_function_unwrapped(__attr context, __attr target))();
42.15 +__attr (*__check_and_get_function(__attr context, __attr target))();
42.16 +__attr (*__check_and_get_function_unwrapped(__attr context, __attr target))();
42.17
42.18 /* Parameter position operations. */
42.19
43.1 --- a/templates/progops.c Fri Mar 24 18:52:59 2017 +0100
43.2 +++ b/templates/progops.c Sat Mar 25 14:26:26 2017 +0100
43.3 @@ -24,6 +24,7 @@
43.4 #include "progtypes.h"
43.5 #include "main.h"
43.6 #include "exceptions.h"
43.7 +#include "calls.h"
43.8
43.9 /* Generic instantiation operations, defining common members. */
43.10
43.11 @@ -38,7 +39,7 @@
43.12
43.13 __attr __new_wrapper(__attr context, __attr attr)
43.14 {
43.15 - return __new___builtins___core_wrapper((__attr[]) {__NULL, context, attr});
43.16 + return __new___builtins___core_wrapper(__NULL, context, attr);
43.17 }
43.18
43.19 /* Generic internal data allocation. */
43.20 @@ -56,43 +57,38 @@
43.21 return data;
43.22 }
43.23
43.24 -void __newdata_sequence(__attr args[], unsigned int number)
43.25 +__attr __newdata_sequence(__attr self, __attr args[], unsigned int number)
43.26 {
43.27 /* Calculate the size of the fragment. */
43.28
43.29 __fragment *data = __new_fragment(number);
43.30 __attr attr = {.seqvalue=data};
43.31 - unsigned int i, j;
43.32 + unsigned int i;
43.33
43.34 - /* Copy the given number of values, starting from the second element. */
43.35 + /* Copy the given number of values. */
43.36
43.37 - for (i = 1, j = 0; i <= number; i++, j++)
43.38 - data->attrs[j] = args[i];
43.39 + for (i = 0; i <= number; i++)
43.40 + data->attrs[i] = args[i];
43.41
43.42 data->size = number;
43.43
43.44 /* Store a reference to the data in the object's __data__ attribute. */
43.45
43.46 - __store_via_object(args[0].value, __data__, attr);
43.47 + __store_via_object(__VALUE(self), __data__, attr);
43.48 + return self;
43.49 }
43.50
43.51 #ifdef __HAVE___builtins___dict_dict
43.52 -void __newdata_mapping(__attr args[], unsigned int number)
43.53 +__attr __newdata_mapping(__attr self, __attr args[], unsigned int number)
43.54 {
43.55 - __attr dict = args[0];
43.56 - __attr callargs[2];
43.57 -
43.58 /* Create a temporary list using the arguments. */
43.59
43.60 - __newliteral___builtins___list_list(args, number);
43.61 + __attr tmp = __newliteral___builtins___list_list(args, number);
43.62
43.63 /* Call __init__ with the dict object and list argument. */
43.64
43.65 - callargs[0] = dict;
43.66 - callargs[1] = args[0];
43.67 -
43.68 - __fn___builtins___dict_dict___init__(callargs);
43.69 - args[0] = dict;
43.70 + __fn___builtins___dict_dict___init__(self, tmp);
43.71 + return self;
43.72 }
43.73 #endif /* __HAVE___builtins___dict_dict */
43.74
43.75 @@ -101,56 +97,42 @@
43.76 void __raise_eof_error()
43.77 {
43.78 #ifdef __HAVE___builtins___exception_io_EOFError
43.79 - __attr args[1];
43.80 - __attr exc = __new___builtins___exception_io_EOFError(args);
43.81 - __Raise(exc);
43.82 + __Raise(__new___builtins___exception_io_EOFError(__NULL));
43.83 #endif /* __HAVE___builtins___exception_io_EOFError */
43.84 }
43.85
43.86 void __raise_io_error(__attr value)
43.87 {
43.88 #ifdef __HAVE___builtins___exception_io_IOError
43.89 - __attr args[2] = {__NULL, value};
43.90 - __attr exc = __new___builtins___exception_io_IOError(args);
43.91 - __Raise(exc);
43.92 + __Raise(__new___builtins___exception_io_IOError(__NULL, value));
43.93 #endif /* __HAVE___builtins___exception_io_IOError */
43.94 }
43.95
43.96 void __raise_memory_error()
43.97 {
43.98 - __attr args[1];
43.99 - __attr exc = __new___builtins___core_MemoryError(args);
43.100 - __Raise(exc);
43.101 + __Raise(__new___builtins___core_MemoryError(__NULL));
43.102 }
43.103
43.104 void __raise_os_error(__attr value, __attr arg)
43.105 {
43.106 #ifdef __HAVE___builtins___exception_system_OSError
43.107 - __attr args[3] = {__NULL, value, arg};
43.108 - __attr exc = __new___builtins___exception_system_OSError(args);
43.109 - __Raise(exc);
43.110 + __Raise(__new___builtins___exception_system_OSError(__NULL, value, arg));
43.111 #endif /* __HAVE___builtins___exception_system_OSError */
43.112 }
43.113
43.114 void __raise_overflow_error()
43.115 {
43.116 - __attr args[1];
43.117 - __attr exc = __new___builtins___core_OverflowError(args);
43.118 - __Raise(exc);
43.119 + __Raise(__new___builtins___core_OverflowError(__NULL));
43.120 }
43.121
43.122 void __raise_type_error()
43.123 {
43.124 - __attr args[1];
43.125 - __attr exc = __new___builtins___core_TypeError(args);
43.126 - __Raise(exc);
43.127 + __Raise(__new___builtins___core_TypeError(__NULL));
43.128 }
43.129
43.130 void __raise_zero_division_error()
43.131 {
43.132 - __attr args[1];
43.133 - __attr exc = __new___builtins___core_ZeroDivisionError(args);
43.134 - __Raise(exc);
43.135 + __Raise(__new___builtins___core_ZeroDivisionError(__NULL));
43.136 }
43.137
43.138 /* Helper for raising exception instances. */
43.139 @@ -229,7 +211,7 @@
43.140 /* Erase the remaining arguments. */
43.141
43.142 for (pos = nargs; pos < max; pos++)
43.143 - allargs[pos].value = 0;
43.144 + __SETNULL(allargs[pos]);
43.145
43.146 /* Fill keyword arguments. */
43.147
43.148 @@ -254,26 +236,26 @@
43.149
43.150 for (pos = nargs; pos < max; pos++)
43.151 {
43.152 - if (allargs[pos].value == 0)
43.153 + if (__ISNULL(allargs[pos]))
43.154 allargs[pos] = __GETDEFAULT(__VALUE(target), pos - min);
43.155 }
43.156 }
43.157
43.158 - /* Call with the prepared arguments. */
43.159 + /* Call with the prepared arguments via a special adaptor function that
43.160 + converts the array to an argument list. */
43.161
43.162 - return (always_callable ?
43.163 - __get_function_unwrapped(allargs[0], target) :
43.164 - __check_and_get_function_unwrapped(allargs[0], target)
43.165 - )(allargs);
43.166 + return __call_with_args(
43.167 + always_callable ?
43.168 + __get_function_unwrapped(allargs[0], target) :
43.169 + __check_and_get_function_unwrapped(allargs[0], target),
43.170 + allargs, max);
43.171 }
43.172
43.173 /* Error routines. */
43.174
43.175 -__attr __unbound_method(__attr args[])
43.176 +__attr __unbound_method(__attr __self)
43.177 {
43.178 - __attr excargs[1];
43.179 - __attr exc = __new___builtins___core_UnboundMethodInvocation(excargs);
43.180 - __Raise(exc);
43.181 + __Raise(__new___builtins___core_UnboundMethodInvocation(__NULL));
43.182 return __builtins___none_None; /* superfluous */
43.183 }
43.184
43.185 @@ -291,11 +273,10 @@
43.186
43.187 int __BOOL(__attr attr)
43.188 {
43.189 - __attr args[2] = {__NULL, attr};
43.190 __ref truevalue = __VALUE(__builtins___boolean_True);
43.191
43.192 /* Invoke the bool function with the object and test against True. */
43.193
43.194 return (__VALUE(attr) == truevalue) ||
43.195 - (__VALUE(__fn___builtins___boolean_bool(args)) == truevalue);
43.196 + (__VALUE(__fn___builtins___boolean_bool(__NULL, attr)) == truevalue);
43.197 }
44.1 --- a/templates/progops.h Fri Mar 24 18:52:59 2017 +0100
44.2 +++ b/templates/progops.h Sat Mar 25 14:26:26 2017 +0100
44.3 @@ -21,6 +21,7 @@
44.4
44.5 #include <stdlib.h> /* size_t */
44.6 #include "types.h"
44.7 +#include "main.h"
44.8
44.9 /* Generic instantiation operations, defining common members. */
44.10
44.11 @@ -31,10 +32,10 @@
44.12
44.13 __fragment *__new_fragment(unsigned int n);
44.14
44.15 -void __newdata_sequence(__attr args[], unsigned int number);
44.16 +__attr __newdata_sequence(__attr self, __attr args[], unsigned int number);
44.17
44.18 #ifdef __HAVE___builtins___dict_dict
44.19 -void __newdata_mapping(__attr args[], unsigned int number);
44.20 +__attr __newdata_mapping(__attr self, __attr args[], unsigned int number);
44.21 #endif /* __HAVE___builtins___dict_dict */
44.22
44.23 /* Helpers for raising errors within common operations. */
44.24 @@ -60,12 +61,12 @@
44.25 /* Generic invocation operations. */
44.26
44.27 __attr __invoke(__attr callable, int always_callable,
44.28 - unsigned int nkwargs, __param kwcodes[], __attr kwargs[],
44.29 - unsigned int nargs, __attr args[]);
44.30 + unsigned int nkwargs, __param kwcodes[], __attr kwargs[],
44.31 + unsigned int nargs, __attr args[]);
44.32
44.33 /* Error routines. */
44.34
44.35 -__attr __unbound_method(__attr args[]);
44.36 +__attr __unbound_method(__attr __self);
44.37
44.38 /* Generic operations depending on specific program details. */
44.39
44.40 @@ -79,6 +80,6 @@
44.41
44.42 #define __NEWINSTANCE(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS), 0)
44.43 #define __NEWINSTANCEIM(__CLS) __new(&__InstanceTable_##__CLS, &__CLS, sizeof(__obj_##__CLS), 1)
44.44 -#define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance((__attr[]) {__NULL, __ATTR, __TYPE}))
44.45 +#define __ISINSTANCE(__ATTR, __TYPE) __BOOL(__fn_native_introspection_isinstance(__NULL, __ATTR, __TYPE))
44.46
44.47 #endif /* __PROGOPS_H__ */
45.1 --- a/templates/types.h Fri Mar 24 18:52:59 2017 +0100
45.2 +++ b/templates/types.h Sat Mar 25 14:26:26 2017 +0100
45.3 @@ -72,14 +72,19 @@
45.4
45.5 typedef union __attr
45.6 {
45.7 + /* General attribute members. */
45.8 +
45.9 __ref value; /* attribute value */
45.10 + int intvalue; /* integer value data ((integer << 1) | 1) */
45.11 +
45.12 + /* Special case attribute members. */
45.13 +
45.14 const __ptable * ptable; /* parameter table */
45.15 struct {
45.16 __pcode code; /* parameter table code for key */
45.17 __ppos pos; /* parameter table position for key */
45.18 };
45.19 __attr (*fn)(); /* callable details */
45.20 - int intvalue; /* integer value */
45.21 float floatvalue; /* floating point value */
45.22 char * strvalue; /* string value */
45.23 __fragment * seqvalue; /* sequence data */
45.24 @@ -106,10 +111,22 @@
45.25
45.26 #define __FRAGMENT_SIZE(NUMBER) ((NUMBER) * sizeof(__attr) + 2 * sizeof(unsigned int))
45.27
45.28 +/* Attribute interpretation. */
45.29 +
45.30 +#define __INTEGER(ATTR) ((ATTR).intvalue % 2)
45.31 +
45.32 /* Attribute value setting. */
45.33
45.34 #define __ATTRVALUE(VALUE) ((__attr) {.value=VALUE})
45.35 #define __NULL __ATTRVALUE(0)
45.36 +#define __SETNULL(ATTR) ((ATTR).value = 0)
45.37 +
45.38 +/* Attribute as instance setting. */
45.39 +
45.40 +#define __INTVALUE(VALUE) ((__attr) {.intvalue=((VALUE) << 1) | 1})
45.41 +#define __TOINT(ATTR) ((ATTR).intvalue >> 1)
45.42 +#define __MAXINT ((1 << ((sizeof(__attr) * 8) - 2)) - 1)
45.43 +#define __MININT (-(1 << ((sizeof(__attr) * 8) - 2)))
45.44
45.45 /* Argument lists. */
45.46
46.1 --- a/tests/numbers.py Fri Mar 24 18:52:59 2017 +0100
46.2 +++ b/tests/numbers.py Sat Mar 25 14:26:26 2017 +0100
46.3 @@ -10,15 +10,15 @@
46.4 print "# sys.maxint + sys.minint:",
46.5 print sys.maxint + sys.minint
46.6
46.7 -i = 2 ** 30
46.8 -print i # 1073741824
46.9 -print hex(i) # 0x40000000
46.10 -print oct(i) # 010000000000
46.11 +i = 2 ** 29
46.12 +print i # 536870912
46.13 +print hex(i) # 0x20000000
46.14 +print oct(i) # 04000000000
46.15
46.16 -j = -2 ** 30
46.17 -print j # -1073741824
46.18 -print hex(j) # -0x40000000
46.19 -print oct(j) # -010000000000
46.20 +j = -2 ** 29
46.21 +print j # -536870912
46.22 +print hex(j) # -0x20000000
46.23 +print oct(j) # -05000000000
46.24
46.25 print i + j # 0
46.26
46.27 @@ -39,9 +39,9 @@
46.28
46.29 print i - i # 0
46.30 print j - j # 0
46.31 -print ~j # 1073741823
46.32 +print ~j # 536870911
46.33 print i & ~j # 0
46.34 -print i - 1 & ~j # 1073741823
46.35 +print i - 1 & ~j # 536870911
46.36
46.37 print hex(31) # 0x1f
46.38 print oct(31) # 037
47.1 --- a/translator.py Fri Mar 24 18:52:59 2017 +0100
47.2 +++ b/translator.py Sat Mar 25 14:26:26 2017 +0100
47.3 @@ -848,7 +848,12 @@
47.4
47.5 # Produce the body and any additional return statement.
47.6
47.7 - expr = self.process_structure_node(n.code) or PredefinedConstantRef("None")
47.8 + expr = self.process_structure_node(n.code) or \
47.9 + self.in_method() and \
47.10 + function_name.rsplit(".", 1)[-1] == "__init__" and \
47.11 + TrResolvedNameRef("self", self.importer.function_locals[function_name]["self"]) or \
47.12 + PredefinedConstantRef("None")
47.13 +
47.14 if not isinstance(expr, ReturnRef):
47.15 self.writestmt("return %s;" % expr)
47.16
47.17 @@ -882,27 +887,10 @@
47.18 else:
47.19 return
47.20
47.21 - # Produce an appropriate access to an attribute's value.
47.22 -
47.23 - name_as_attr = self.get_name_as_attribute(name)
47.24 -
47.25 # Write a test that raises a TypeError upon failure.
47.26
47.27 self.writestmt("if (!__test_%s_%s(__VALUE(%s), %s)) __raise_type_error();" % (
47.28 - guard, guard_type, name_as_attr, argstr))
47.29 -
47.30 - def get_name_as_attribute(self, name):
47.31 -
47.32 - "Return a generated expression for 'name' yielding an attribute."
47.33 -
47.34 - parameters = self.importer.function_parameters.get(self.get_namespace_path())
47.35 - parameter = name == "self" and self.in_method() or \
47.36 - parameters and name in parameters
47.37 -
47.38 - if parameter:
47.39 - return "*%s" % encode_path(name)
47.40 - else:
47.41 - return "%s" % encode_path(name)
47.42 + guard, guard_type, encode_path(name), argstr))
47.43
47.44 def process_function_node(self, n):
47.45
47.46 @@ -1323,16 +1311,17 @@
47.47
47.48 # Encode the arguments.
47.49
47.50 - argstr = "__ARGS(%s)" % ", ".join(args)
47.51 + # Where literal instantiation is occurring, add an argument indicating
47.52 + # the number of values. The context is excluded.
47.53 +
47.54 + if literal_instantiation:
47.55 + argstr = "__ARGS(%s), %d" % (", ".join(args[1:]), len(args) - 1)
47.56 + else:
47.57 + argstr = ", ".join(args)
47.58 +
47.59 kwargstr = kwargs and ("__ARGS(%s)" % ", ".join(kwargs)) or "0"
47.60 kwcodestr = kwcodes and ("__KWARGS(%s)" % ", ".join(kwcodes)) or "0"
47.61
47.62 - # Where literal instantiation is occurring, add an argument indicating
47.63 - # the number of values.
47.64 -
47.65 - if literal_instantiation:
47.66 - argstr += ", %d" % (len(args) - 1)
47.67 -
47.68 # First, the invocation expression is presented.
47.69
47.70 stages = []
47.71 @@ -1402,7 +1391,7 @@
47.72 target_var,
47.73 self.always_callable(refs) and 1 or 0,
47.74 len(kwargs), kwcodestr, kwargstr,
47.75 - len(args), argstr))
47.76 + len(args), "__ARGS(%s)" % argstr))
47.77 return InvocationResult(stages)
47.78
47.79 def next_target(self):
47.80 @@ -1577,7 +1566,7 @@
47.81 # such names.
47.82
47.83 name_ref = TrResolvedNameRef(n.name, ref, expr=expr, is_global=is_global,
47.84 - parameter=parameter, location=location)
47.85 + location=location)
47.86 return not expr and self.get_aliases(name_ref) or name_ref
47.87
47.88 def get_aliases(self, name_ref):
47.89 @@ -1969,8 +1958,6 @@
47.90
47.91 "Start the function having the given 'name'."
47.92
47.93 - print >>self.out, "__attr %s(__attr __args[])" % encode_function_pointer(name)
47.94 - print >>self.out, "{"
47.95 self.indent += 1
47.96
47.97 self.start_unit()
47.98 @@ -1981,6 +1968,12 @@
47.99
47.100 out = self.end_unit()
47.101
47.102 + # Write the signature at the top indentation level.
47.103 +
47.104 + self.indent -= 1
47.105 + self.write_parameters(name)
47.106 + print >>self.out, "{"
47.107 +
47.108 # Obtain local names from parameters.
47.109
47.110 parameters = self.importer.function_parameters[name]
47.111 @@ -2001,7 +1994,9 @@
47.112 else:
47.113 names.append(encode_path(n))
47.114
47.115 - # Emit required local names.
47.116 + # Emit required local names at the function indentation level.
47.117 +
47.118 + self.indent += 1
47.119
47.120 if names:
47.121 names.sort()
47.122 @@ -2011,14 +2006,38 @@
47.123 volatile_names.sort()
47.124 self.writeline("volatile __attr %s;" % ", ".join(volatile_names))
47.125
47.126 - self.write_parameters(name)
47.127 -
47.128 self.flush_unit(name, out)
47.129
47.130 self.indent -= 1
47.131 print >>self.out, "}"
47.132 print >>self.out
47.133
47.134 + def write_parameters(self, name):
47.135 +
47.136 + """
47.137 + For the function having the given 'name', write definitions of
47.138 + parameters found in the arguments array.
47.139 + """
47.140 +
47.141 + # Generate any self reference.
47.142 +
47.143 + l = []
47.144 +
47.145 + if self.is_method(name):
47.146 + l.append("__attr self")
47.147 + else:
47.148 + l.append("__attr __self")
47.149 +
47.150 + # Generate aliases for the parameters.
47.151 +
47.152 + for parameter in self.importer.function_parameters[name]:
47.153 + l.append("%s__attr %s" % (
47.154 + parameter in self.volatile_locals and "volatile " or "",
47.155 + encode_path(parameter)))
47.156 +
47.157 + self.writeline("__attr %s(%s)" % (
47.158 + encode_function_pointer(name), ", ".join(l)))
47.159 +
47.160 def write_temporaries(self, name):
47.161
47.162 "Write temporary storage employed by 'name'."
47.163 @@ -2048,27 +2067,6 @@
47.164 if name in module.exception_namespaces:
47.165 self.writeline("__exc __tmp_exc;")
47.166
47.167 - def write_parameters(self, name):
47.168 -
47.169 - """
47.170 - For the function having the given 'name', write definitions of
47.171 - parameters found in the arguments array.
47.172 - """
47.173 -
47.174 - parameters = self.importer.function_parameters[name]
47.175 -
47.176 - # Generate any self reference.
47.177 -
47.178 - if self.is_method(name):
47.179 - self.writeline("__attr * const self = &__args[0];")
47.180 -
47.181 - # Generate aliases for the parameters.
47.182 -
47.183 - for i, parameter in enumerate(parameters):
47.184 - self.writeline("%s__attr * const %s = &__args[%d];" % (
47.185 - parameter in self.volatile_locals and "volatile " or "",
47.186 - encode_path(parameter), i+1))
47.187 -
47.188 def start_if(self, first, test_ref):
47.189 statement = "%sif" % (not first and "else " or "")
47.190
48.1 --- a/transresults.py Fri Mar 24 18:52:59 2017 +0100
48.2 +++ b/transresults.py Sat Mar 25 14:26:26 2017 +0100
48.3 @@ -63,9 +63,8 @@
48.4
48.5 "A reference to a name in the translation."
48.6
48.7 - def __init__(self, name, ref, expr=None, is_global=False, parameter=None, location=None):
48.8 + def __init__(self, name, ref, expr=None, is_global=False, location=None):
48.9 ResolvedNameRef.__init__(self, name, ref, expr, is_global)
48.10 - self.parameter = parameter
48.11 self.location = location
48.12
48.13 def access_location(self):
48.14 @@ -115,7 +114,7 @@
48.15 # All other assignments involve the names as they were given.
48.16
48.17 else:
48.18 - return "(%s%s) = %s" % (self.parameter and "*" or "", attrname, self.expr)
48.19 + return "%s = %s" % (attrname, self.expr)
48.20
48.21 # Expressions.
48.22
48.23 @@ -133,14 +132,20 @@
48.24 # All other accesses involve the names as they were given.
48.25
48.26 else:
48.27 - return "(%s%s)" % (self.parameter and "*" or "", attrname)
48.28 + return "(%s)" % attrname
48.29
48.30 class TrConstantValueRef(ConstantValueRef):
48.31
48.32 "A constant value reference in the translation."
48.33
48.34 def __str__(self):
48.35 - return encode_literal_constant(self.number)
48.36 +
48.37 + # NOTE: Should reference a common variable for the type name.
48.38 +
48.39 + if self.ref.get_origin() == "__builtins__.int.int":
48.40 + return "__INTVALUE(%s)" % self.value
48.41 + else:
48.42 + return encode_literal_constant(self.number)
48.43
48.44 class TrLiteralSequenceRef(LiteralSequenceRef):
48.45