1.1 --- a/generator.py Fri Dec 09 00:09:01 2016 +0100 1.2 +++ b/generator.py Fri Dec 09 16:22:37 2016 +0100 1.3 @@ -31,7 +31,7 @@ 1.4 encode_symbol, encode_tablename, \ 1.5 encode_type_attribute, decode_type_attribute, \ 1.6 is_type_attribute 1.7 -from os import listdir 1.8 +from os import listdir, mkdir 1.9 from os.path import exists, isdir, join, split 1.10 from referencing import Reference 1.11 1.12 @@ -111,7 +111,23 @@ 1.13 if debug and exists(join(templates, "%s-debug" % filename)): 1.14 continue 1.15 1.16 - copy(join(templates, filename), target) 1.17 + pathname = join(templates, filename) 1.18 + 1.19 + # Copy files into the target directory. 1.20 + 1.21 + if not isdir(pathname): 1.22 + copy(pathname, target) 1.23 + 1.24 + # Copy directories (such as the native code directory). 1.25 + 1.26 + else: 1.27 + target = join(self.output, filename) 1.28 + 1.29 + if not exists(target): 1.30 + mkdir(target) 1.31 + 1.32 + for filename in listdir(pathname): 1.33 + copy(join(pathname, filename), target) 1.34 1.35 def write_structures(self): 1.36 1.37 @@ -964,9 +980,11 @@ 1.38 function_name = "__main_%s" % encode_path(name) 1.39 print >>f_signatures, "void %s();" % function_name 1.40 1.41 - # Omit the native module. 1.42 + # Omit the native modules. 1.43 1.44 - if name != "native": 1.45 + parts = name.split(".") 1.46 + 1.47 + if parts[0] != "native": 1.48 print >>f_code, """\ 1.49 %s();""" % function_name 1.50
2.1 --- a/lib/__builtins__/attribute.py Fri Dec 09 00:09:01 2016 +0100 2.2 +++ b/lib/__builtins__/attribute.py Fri Dec 09 16:22:37 2016 +0100 2.3 @@ -19,7 +19,7 @@ 2.4 this program. If not, see <http://www.gnu.org/licenses/>. 2.5 """ 2.6 2.7 -from native import _object_getattr 2.8 +from native import object_getattr 2.9 2.10 _default=object() # a unique placeholder for a missing value 2.11 2.12 @@ -30,7 +30,7 @@ 2.13 'default' if the attribute is not defined for 'obj'. 2.14 """ 2.15 2.16 - return _object_getattr(obj, name, default) 2.17 + return object_getattr(obj, name, default) 2.18 2.19 def getattr(obj, name, default=_default): 2.20
3.1 --- a/lib/__builtins__/buffer.py Fri Dec 09 00:09:01 2016 +0100 3.2 +++ b/lib/__builtins__/buffer.py Fri Dec 09 16:22:37 2016 +0100 3.3 @@ -19,7 +19,7 @@ 3.4 this program. If not, see <http://www.gnu.org/licenses/>. 3.5 """ 3.6 3.7 -from native import _list_init, _list_append, _list_concat, _buffer_str 3.8 +from native import list_init, list_append, list_concat, buffer_str 3.9 3.10 class buffer: 3.11 3.12 @@ -36,7 +36,7 @@ 3.13 else: 3.14 raise TypeError(size) 3.15 3.16 - self.__data__ = _list_init(n) 3.17 + self.__data__ = list_init(n) 3.18 3.19 # Append all arguments to the buffer. 3.20 3.21 @@ -52,17 +52,17 @@ 3.22 """ 3.23 3.24 if isinstance(s, buffer): 3.25 - _list_concat(self, s.__data__) 3.26 + list_concat(self, s.__data__) 3.27 elif isinstance(s, string): 3.28 - _list_append(self, s) 3.29 + list_append(self, s) 3.30 else: 3.31 - _list_append(self, str(s)) 3.32 + list_append(self, str(s)) 3.33 3.34 def __str__(self): 3.35 3.36 "Return a string representation." 3.37 3.38 - return _buffer_str(self.__data__) 3.39 + return buffer_str(self.__data__) 3.40 3.41 def __repr__(self): 3.42
4.1 --- a/lib/__builtins__/character.py Fri Dec 09 00:09:01 2016 +0100 4.2 +++ b/lib/__builtins__/character.py Fri Dec 09 16:22:37 2016 +0100 4.3 @@ -19,7 +19,7 @@ 4.4 this program. If not, see <http://www.gnu.org/licenses/>. 4.5 """ 4.6 4.7 -from native import _str_ord 4.8 +from native import str_ord 4.9 4.10 def chr(i): pass 4.11 def hex(number): pass 4.12 @@ -30,7 +30,7 @@ 4.13 "Return the value of the given character 'c'." 4.14 4.15 if isinstance(c, string) and len(c) == 1: 4.16 - return _str_ord(c.__data__) 4.17 + return str_ord(c.__data__) 4.18 else: 4.19 raise ValueError(c) 4.20
5.1 --- a/lib/__builtins__/core.py Fri Dec 09 00:09:01 2016 +0100 5.2 +++ b/lib/__builtins__/core.py Fri Dec 09 16:22:37 2016 +0100 5.3 @@ -19,7 +19,7 @@ 5.4 this program. If not, see <http://www.gnu.org/licenses/>. 5.5 """ 5.6 5.7 -from native import _get_using 5.8 +from native import get_using 5.9 5.10 class object: 5.11 5.12 @@ -127,10 +127,4 @@ 5.13 class Warning: pass 5.14 class ZeroDivisionError(Exception): pass 5.15 5.16 -def get_using(callable, instance): 5.17 - 5.18 - "Return 'callable' bound to 'instance'." 5.19 - 5.20 - return _get_using(callable, instance) 5.21 - 5.22 # vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/lib/__builtins__/dict.py Fri Dec 09 00:09:01 2016 +0100 6.2 +++ b/lib/__builtins__/dict.py Fri Dec 09 16:22:37 2016 +0100 6.3 @@ -86,7 +86,7 @@ 6.4 6.5 index = key.__hash__() 6.6 6.7 - if not native._isinstance(index, int): 6.8 + if not native.isinstance(index, int): 6.9 raise TypeError 6.10 6.11 return index % len(self.buckets)
7.1 --- a/lib/__builtins__/file.py Fri Dec 09 00:09:01 2016 +0100 7.2 +++ b/lib/__builtins__/file.py Fri Dec 09 16:22:37 2016 +0100 7.3 @@ -42,7 +42,7 @@ 7.4 # Read any indicated number of bytes. 7.5 7.6 if n > 0: 7.7 - return native._fread(self.__data__, n) 7.8 + return native.fread(self.__data__, n) 7.9 7.10 # Read all remaining bytes. 7.11 7.12 @@ -53,7 +53,7 @@ 7.13 7.14 try: 7.15 while True: 7.16 - l.append(native._fread(self.__data__, self.bufsize)) 7.17 + l.append(native.fread(self.__data__, self.bufsize)) 7.18 7.19 # Handle end-of-file reads. 7.20 7.21 @@ -67,13 +67,13 @@ 7.22 "Write string 's' to the stream." 7.23 7.24 check_string(s) 7.25 - native._fwrite(self.__data__, s) 7.26 + native.fwrite(self.__data__, s) 7.27 7.28 def close(self): 7.29 7.30 "Close the stream." 7.31 7.32 - native._fclose(self.__data__) 7.33 + native.fclose(self.__data__) 7.34 7.35 class file(filestream): 7.36 7.37 @@ -84,7 +84,7 @@ 7.38 "Open the file with the given 'filename' using the given access 'mode'." 7.39 7.40 get_using(filestream.__init__, self)(bufsize) 7.41 - self.__data__ = native._fopen(filename, mode) 7.42 + self.__data__ = native.fopen(filename, mode) 7.43 7.44 def readline(self, size=None): pass 7.45 def readlines(self, size=None): pass
8.1 --- a/lib/__builtins__/identity.py Fri Dec 09 00:09:01 2016 +0100 8.2 +++ b/lib/__builtins__/identity.py Fri Dec 09 16:22:37 2016 +0100 8.3 @@ -19,7 +19,7 @@ 8.4 this program. If not, see <http://www.gnu.org/licenses/>. 8.5 """ 8.6 8.7 -from native import _isinstance, _issubclass 8.8 +import native 8.9 8.10 def callable(obj): 8.11 8.12 @@ -56,13 +56,13 @@ 8.13 either a class or a sequence of classes. 8.14 """ 8.15 8.16 - if _isinstance(cls_or_tuple, tuple): 8.17 + if native.isinstance(cls_or_tuple, tuple): 8.18 for cls in cls_or_tuple: 8.19 - if obj.__class__ is cls or isclass(cls) and _isinstance(obj, cls): 8.20 + if obj.__class__ is cls or isclass(cls) and native.isinstance(obj, cls): 8.21 return True 8.22 return False 8.23 else: 8.24 - return obj.__class__ is cls_or_tuple or isclass(cls_or_tuple) and _isinstance(obj, cls_or_tuple) 8.25 + return obj.__class__ is cls_or_tuple or isclass(cls_or_tuple) and native.isinstance(obj, cls_or_tuple) 8.26 8.27 def issubclass(obj, cls_or_tuple): 8.28 8.29 @@ -74,13 +74,13 @@ 8.30 8.31 if not isclass(obj): 8.32 return False 8.33 - elif _isinstance(cls_or_tuple, tuple): 8.34 + elif native.isinstance(cls_or_tuple, tuple): 8.35 for cls in cls_or_tuple: 8.36 - if obj is cls or isclass(cls) and _issubclass(obj, cls): 8.37 + if obj is cls or isclass(cls) and native.issubclass(obj, cls): 8.38 return True 8.39 return False 8.40 else: 8.41 - return obj is cls_or_tuple or isclass(cls_or_tuple) and _issubclass(obj, cls_or_tuple) 8.42 + return obj is cls_or_tuple or isclass(cls_or_tuple) and native.issubclass(obj, cls_or_tuple) 8.43 8.44 def repr(obj): 8.45
9.1 --- a/lib/__builtins__/int.py Fri Dec 09 00:09:01 2016 +0100 9.2 +++ b/lib/__builtins__/int.py Fri Dec 09 16:22:37 2016 +0100 9.3 @@ -30,7 +30,7 @@ 9.4 9.5 "Initialise the integer with the given 'number_or_string'." 9.6 9.7 - if native._isinstance(number_or_string, int): 9.8 + if native.isinstance(number_or_string, int): 9.9 self.__data__ = number_or_string.__data__ 9.10 else: 9.11 # NOTE: To be implemented. 9.12 @@ -46,7 +46,7 @@ 9.13 9.14 "Perform 'op' on this int and 'other' if appropriate." 9.15 9.16 - if native._isinstance(other, int): 9.17 + if native.isinstance(other, int): 9.18 return op(self.__data__, other.__data__) 9.19 else: 9.20 return NotImplemented 9.21 @@ -55,7 +55,7 @@ 9.22 9.23 "Perform 'op' on 'other' and this int if appropriate." 9.24 9.25 - if native._isinstance(other, int): 9.26 + if native.isinstance(other, int): 9.27 return op(other.__data__, self.__data__) 9.28 else: 9.29 return NotImplemented 9.30 @@ -64,61 +64,61 @@ 9.31 9.32 "Return a new int for the addition of this int and 'other'." 9.33 9.34 - return self._binary_op(native._int_add, other) 9.35 + return self._binary_op(native.int_add, other) 9.36 9.37 def __isub__(self, other): 9.38 9.39 "Return a new int for the subtraction of this int and 'other'." 9.40 9.41 - return self._binary_op(native._int_sub, other) 9.42 + return self._binary_op(native.int_sub, other) 9.43 9.44 def __imul__(self, other): 9.45 9.46 "Return a new int for the multiplication of this int and 'other'." 9.47 9.48 - return self._binary_op(native._int_mul, other) 9.49 + return self._binary_op(native.int_mul, other) 9.50 9.51 def __idiv__(self, other): 9.52 9.53 "Return a new int for the division of this int and 'other'." 9.54 9.55 - return self._binary_op(native._int_div, other) 9.56 + return self._binary_op(native.int_div, other) 9.57 9.58 def __imod__(self, other): 9.59 9.60 "Return a new int for the modulo of this int by 'other'." 9.61 9.62 - return self._binary_op(native._int_mod, other) 9.63 + return self._binary_op(native.int_mod, other) 9.64 9.65 def __ipow__(self, other): 9.66 9.67 "Return a new int for the exponentiation of this int by 'other'." 9.68 9.69 - return self._binary_op(native._int_pow, other) 9.70 + return self._binary_op(native.int_pow, other) 9.71 9.72 def __iand__(self, other): 9.73 9.74 "Return a new int for the binary-and of this int and 'other'." 9.75 9.76 - return self._binary_op(native._int_and, other) 9.77 + return self._binary_op(native.int_and, other) 9.78 9.79 def __ior__(self, other): 9.80 9.81 "Return a new int for the binary-or of this int and 'other'." 9.82 9.83 - return self._binary_op(native._int_or, other) 9.84 + return self._binary_op(native.int_or, other) 9.85 9.86 def __ixor__(self, other): 9.87 9.88 "Return a new int for the exclusive-or of this int and 'other'." 9.89 9.90 - return self._binary_op(native._int_xor, other) 9.91 + return self._binary_op(native.int_xor, other) 9.92 9.93 def __invert__(self): 9.94 9.95 "Return the inversion of this int." 9.96 9.97 - return native._int_not(self.__data__) 9.98 + return native.int_not(self.__data__) 9.99 9.100 __add__ = __radd__ = __iadd__ 9.101 __sub__ = __isub__ 9.102 @@ -127,7 +127,7 @@ 9.103 9.104 "Return a new int for the subtraction of this int from 'other'." 9.105 9.106 - return self._binary_op_rev(native._int_sub, other) 9.107 + return self._binary_op_rev(native.int_sub, other) 9.108 9.109 __mul__ = __rmul__ = __imul__ 9.110 __div__ = __idiv__ 9.111 @@ -136,7 +136,7 @@ 9.112 9.113 "Return a new int for the division of this int into 'other'." 9.114 9.115 - return self._binary_op_rev(native._int_div, other) 9.116 + return self._binary_op_rev(native.int_div, other) 9.117 9.118 def __floordiv__(self, other): pass 9.119 def __rfloordiv__(self, other): pass 9.120 @@ -148,7 +148,7 @@ 9.121 9.122 "Return a new int for the modulo of 'other' by this int." 9.123 9.124 - return self._binary_op_rev(native._int_mod, other) 9.125 + return self._binary_op_rev(native.int_mod, other) 9.126 9.127 __pow__ = __ipow__ 9.128 9.129 @@ -156,7 +156,7 @@ 9.130 9.131 "Return a new int for the exponentiation of 'other' by this int." 9.132 9.133 - return self._binary_op_rev(native._int_pow, other) 9.134 + return self._binary_op_rev(native.int_pow, other) 9.135 9.136 __and__ = __rand__ = __iand__ 9.137 __or__ = __ror__ = __ior__ 9.138 @@ -166,13 +166,13 @@ 9.139 9.140 "Return whether this int is less than 'other'." 9.141 9.142 - return self._binary_op(native._int_lt, other) 9.143 + return self._binary_op(native.int_lt, other) 9.144 9.145 def __gt__(self, other): 9.146 9.147 "Return whether this int is greater than 'other'." 9.148 9.149 - return self._binary_op(native._int_gt, other) 9.150 + return self._binary_op(native.int_gt, other) 9.151 9.152 def __le__(self, other): 9.153 9.154 @@ -190,7 +190,7 @@ 9.155 9.156 "Return whether this int is equal to 'other'." 9.157 9.158 - return self._binary_op(native._int_eq, other) 9.159 + return self._binary_op(native.int_eq, other) 9.160 9.161 def __ne__(self, other): 9.162 9.163 @@ -202,7 +202,7 @@ 9.164 9.165 "Apply the unary negation operator." 9.166 9.167 - return native._int_neg(self.__data__) 9.168 + return native.int_neg(self.__data__) 9.169 9.170 def __pos__(self): 9.171 9.172 @@ -214,7 +214,7 @@ 9.173 9.174 "Return a string representation." 9.175 9.176 - return native._int_str(self.__data__) 9.177 + return native.int_str(self.__data__) 9.178 9.179 __repr__ = __str__ 9.180 9.181 @@ -230,11 +230,11 @@ 9.182 "Return whether this int is non-zero." 9.183 9.184 zero = 0 9.185 - return native._int_ne(self.__data__, zero.__data__) 9.186 + return native.int_ne(self.__data__, zero.__data__) 9.187 9.188 # Limits. 9.189 9.190 -maxint = native._get_maxint() 9.191 -minint = native._get_minint() 9.192 +maxint = native.get_maxint() 9.193 +minint = native.get_minint() 9.194 9.195 # vim: tabstop=4 expandtab shiftwidth=4
10.1 --- a/lib/__builtins__/list.py Fri Dec 09 00:09:01 2016 +0100 10.2 +++ b/lib/__builtins__/list.py Fri Dec 09 16:22:37 2016 +0100 10.3 @@ -34,7 +34,7 @@ 10.4 # Reserve an attribute for a fragment reference along with some space 10.5 # for elements. 10.6 10.7 - self.__data__ = native._list_init(args is not None and len(args) or 0) 10.8 + self.__data__ = native.list_init(args is not None and len(args) or 0) 10.9 10.10 if args is not None: 10.11 self.extend(args) 10.12 @@ -47,7 +47,7 @@ 10.13 10.14 "Append 'value' to the list." 10.15 10.16 - native._list_append(self, value) 10.17 + native.list_append(self, value) 10.18 10.19 def insert(self, i, value): pass 10.20 10.21 @@ -66,7 +66,7 @@ 10.22 10.23 "Return the length of the list." 10.24 10.25 - return native._list_len(self.__data__) 10.26 + return native.list_len(self.__data__) 10.27 10.28 def __add__(self, other): pass 10.29 10.30 @@ -75,7 +75,7 @@ 10.31 "Concatenate 'other' to the list." 10.32 10.33 if isinstance(other, list): 10.34 - native._list_concat(self, other.__data__) 10.35 + native.list_concat(self, other.__data__) 10.36 else: 10.37 self.extend(other) 10.38 return self 10.39 @@ -92,7 +92,7 @@ 10.40 10.41 "Lists are true if non-empty." 10.42 10.43 - return native._list_nonempty(self.__data__) 10.44 + return native.list_nonempty(self.__data__) 10.45 10.46 def __iter__(self): 10.47 10.48 @@ -107,13 +107,13 @@ 10.49 "Return the item at the normalised (positive) 'index'." 10.50 10.51 self._check_index(index) 10.52 - return native._list_element(self.__data__, index) 10.53 + return native.list_element(self.__data__, index) 10.54 10.55 def __set_single_item__(self, index, value): 10.56 10.57 "Set at the normalised (positive) 'index' the given 'value'." 10.58 10.59 self._check_index(index) 10.60 - return native._list_setelement(self.__data__, index, value) 10.61 + return native.list_setelement(self.__data__, index, value) 10.62 10.63 # vim: tabstop=4 expandtab shiftwidth=4
11.1 --- a/lib/__builtins__/sequence.py Fri Dec 09 00:09:01 2016 +0100 11.2 +++ b/lib/__builtins__/sequence.py Fri Dec 09 16:22:37 2016 +0100 11.3 @@ -19,7 +19,7 @@ 11.4 this program. If not, see <http://www.gnu.org/licenses/>. 11.5 """ 11.6 11.7 -from native import _isinstance 11.8 +import native 11.9 11.10 class itemaccess: 11.11 11.12 @@ -42,13 +42,13 @@ 11.13 # Normalise any integer indexes, converting negative indexes to positive 11.14 # ones. 11.15 11.16 - if _isinstance(index, int): 11.17 + if native.isinstance(index, int): 11.18 index = _get_absolute_index(index, self.__len__()) 11.19 return self.__get_single_item__(index) 11.20 11.21 # Handle slices separately. 11.22 11.23 - elif _isinstance(index, slice): 11.24 + elif native.isinstance(index, slice): 11.25 return self.__getslice__(index.start, index.end, index.step) 11.26 11.27 # No other kinds of objects are supported as indexes. 11.28 @@ -63,13 +63,13 @@ 11.29 # Normalise any integer indexes, converting negative indexes to positive 11.30 # ones. 11.31 11.32 - if _isinstance(index, int): 11.33 + if native.isinstance(index, int): 11.34 index = _get_absolute_index(index, self.__len__()) 11.35 return self.__set_single_item__(index, value) 11.36 11.37 # Handle slices separately. 11.38 11.39 - elif _isinstance(index, slice): 11.40 + elif native.isinstance(index, slice): 11.41 return self.__setslice__(index.start, index.end, value) 11.42 11.43 # No other kinds of objects are supported as indexes.
12.1 --- a/lib/__builtins__/str.py Fri Dec 09 00:09:01 2016 +0100 12.2 +++ b/lib/__builtins__/str.py Fri Dec 09 16:22:37 2016 +0100 12.3 @@ -68,7 +68,7 @@ 12.4 12.5 "Return a string combining this string with 'other'." 12.6 12.7 - return self._binary_op(native._str_add, other) 12.8 + return self._binary_op(native.str_add, other) 12.9 12.10 __add__ = __radd__ = __iadd__ 12.11 12.12 @@ -81,13 +81,13 @@ 12.13 12.14 "Return whether this string is less than 'other'." 12.15 12.16 - return self._binary_op(native._str_lt, other) 12.17 + return self._binary_op(native.str_lt, other) 12.18 12.19 def __gt__(self, other): 12.20 12.21 "Return whether this string is greater than 'other'." 12.22 12.23 - return self._binary_op(native._str_gt, other) 12.24 + return self._binary_op(native.str_gt, other) 12.25 12.26 def __le__(self, other): 12.27 12.28 @@ -105,7 +105,7 @@ 12.29 12.30 "Return whether this string is equal to 'other'." 12.31 12.32 - return self._binary_op(native._str_eq, other) 12.33 + return self._binary_op(native.str_eq, other) 12.34 12.35 def __ne__(self, other): 12.36 12.37 @@ -117,7 +117,7 @@ 12.38 12.39 "Return the length of this string." 12.40 12.41 - return native._str_len(self.__data__) 12.42 + return native.str_len(self.__data__) 12.43 12.44 def __str__(self): 12.45 12.46 @@ -134,7 +134,7 @@ 12.47 return str(b) 12.48 12.49 def __bool__(self): 12.50 - return native._str_nonempty(self.__data__) 12.51 + return native.str_nonempty(self.__data__) 12.52 12.53 def endswith(self, s): pass 12.54 def find(self, sub, start=None, end=None): pass 12.55 @@ -182,7 +182,7 @@ 12.56 "Return the item at the normalised (positive) 'index'." 12.57 12.58 self._check_index(index) 12.59 - return native._str_substr(self.__data__, index, 1) 12.60 + return native.str_substr(self.__data__, index, 1) 12.61 12.62 class string(basestring): 12.63 pass
13.1 --- a/lib/__builtins__/tuple.py Fri Dec 09 00:09:01 2016 +0100 13.2 +++ b/lib/__builtins__/tuple.py Fri Dec 09 16:22:37 2016 +0100 13.3 @@ -35,15 +35,15 @@ 13.4 # for elements. 13.5 13.6 size = args is not None and len(args) or 0 13.7 - self.__data__ = native._list_init(size) 13.8 - native._list_setsize(self.__data__, size) 13.9 + self.__data__ = native.list_init(size) 13.10 + native.list_setsize(self.__data__, size) 13.11 13.12 # Populate the tuple. 13.13 13.14 if args is not None: 13.15 i = 0 13.16 for arg in args: 13.17 - native._list_setelement(self.__data__, i, arg) 13.18 + native.list_setelement(self.__data__, i, arg) 13.19 i += 1 13.20 13.21 def __getslice__(self, start, end=None): 13.22 @@ -56,7 +56,7 @@ 13.23 13.24 "Return the length of the tuple." 13.25 13.26 - return native._list_len(self.__data__) 13.27 + return native.list_len(self.__data__) 13.28 13.29 def __add__(self, other): pass 13.30 13.31 @@ -87,7 +87,7 @@ 13.32 "Return the item at the normalised (positive) 'index'." 13.33 13.34 self._check_index(index) 13.35 - return native._list_element(self.__data__, index) 13.36 + return native.list_element(self.__data__, index) 13.37 13.38 def __set_single_item__(self, index, value): 13.39
14.1 --- a/lib/__builtins__/types.py Fri Dec 09 00:09:01 2016 +0100 14.2 +++ b/lib/__builtins__/types.py Fri Dec 09 16:22:37 2016 +0100 14.3 @@ -25,14 +25,14 @@ 14.4 14.5 "Check the given int 'i'." 14.6 14.7 - if not native._isinstance(i, int): 14.8 + if not native.isinstance(i, int): 14.9 raise ValueError(i) 14.10 14.11 def check_string(s): 14.12 14.13 "Check the given string 's'." 14.14 14.15 - if not native._isinstance(s, string): 14.16 + if not native.isinstance(s, string): 14.17 raise ValueError(s) 14.18 14.19 # vim: tabstop=4 expandtab shiftwidth=4
15.1 --- a/lib/native.py Fri Dec 09 00:09:01 2016 +0100 15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 15.3 @@ -1,118 +0,0 @@ 15.4 -#!/usr/bin/env python 15.5 - 15.6 -""" 15.7 -Native library functions. 15.8 - 15.9 -None of these are actually defined here. Instead, native implementations are 15.10 -substituted when each program is built. It is, however, important to declare 15.11 -non-core exceptions used by the native functions because they need to be 15.12 -identified as being needed by the program. 15.13 - 15.14 -Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 15.15 - 15.16 -This program is free software; you can redistribute it and/or modify it under 15.17 -the terms of the GNU General Public License as published by the Free Software 15.18 -Foundation; either version 3 of the License, or (at your option) any later 15.19 -version. 15.20 - 15.21 -This program is distributed in the hope that it will be useful, but WITHOUT 15.22 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15.23 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15.24 -details. 15.25 - 15.26 -You should have received a copy of the GNU General Public License along with 15.27 -this program. If not, see <http://www.gnu.org/licenses/>. 15.28 -""" 15.29 - 15.30 -# Environment support. 15.31 - 15.32 -def _exit(status): pass 15.33 -def _get_argv(): pass 15.34 -def _get_path(): pass 15.35 - 15.36 -# Identity testing. 15.37 - 15.38 -def _is(x, y): pass 15.39 -def _is_not(x, y): pass 15.40 - 15.41 -# Limit definition. 15.42 - 15.43 -def _get_maxint(): pass 15.44 -def _get_minint(): pass 15.45 - 15.46 -# Integer operations. 15.47 - 15.48 -def _int_add(self, other): pass 15.49 -def _int_div(self, other): pass 15.50 -def _int_mod(self, other): pass 15.51 -def _int_mul(self, other): pass 15.52 -def _int_neg(self): pass 15.53 -def _int_pow(self, other): pass 15.54 -def _int_sub(self, other): pass 15.55 - 15.56 -def _int_and(self, other): pass 15.57 -def _int_not(self): pass 15.58 -def _int_or(self, other): pass 15.59 -def _int_xor(self, other): pass 15.60 - 15.61 -def _int_lt(self, other): pass 15.62 -def _int_gt(self, other): pass 15.63 -def _int_eq(self, other): pass 15.64 -def _int_ne(self, other): pass 15.65 - 15.66 -def _int_str(self): pass 15.67 - 15.68 -# String operations. 15.69 - 15.70 -def _str_add(self, other): pass 15.71 -def _str_eq(self, other): pass 15.72 -def _str_gt(self, other): pass 15.73 -def _str_lt(self, other): pass 15.74 -def _str_len(self): pass 15.75 -def _str_nonempty(self): pass 15.76 -def _str_ord(self): pass 15.77 -def _str_substr(self, start, size): pass 15.78 - 15.79 -# List operations. 15.80 - 15.81 -def _list_init(size): pass 15.82 -def _list_setsize(self, size): pass 15.83 -def _list_append(self, value): pass 15.84 -def _list_concat(self, other): pass 15.85 -def _list_len(self): pass 15.86 -def _list_nonempty(self): pass 15.87 -def _list_element(self, index): pass 15.88 -def _list_setelement(self, index, value): pass 15.89 - 15.90 -# Buffer operations. 15.91 - 15.92 -def _buffer_str(self): pass 15.93 - 15.94 -# Method binding. 15.95 - 15.96 -def _get_using(callable, instance): pass 15.97 - 15.98 -# Introspection. 15.99 - 15.100 -def _object_getattr(obj, name, default): pass 15.101 -def _isinstance(obj, cls): pass 15.102 -def _issubclass(obj, cls): pass 15.103 - 15.104 -# Input/output. 15.105 - 15.106 -def _fclose(fp): IOError 15.107 -def _fopen(filename, mode): IOError 15.108 -def _fdopen(fd, mode): IOError 15.109 -def _close(fd): IOError 15.110 -def _read(fd, n): IOError 15.111 -def _write(fd, str): IOError 15.112 - 15.113 -def _fread(fp, n): 15.114 - IOError 15.115 - EOFError 15.116 - 15.117 -def _fwrite(fp, str): 15.118 - IOError 15.119 - EOFError 15.120 - 15.121 -# vim: tabstop=4 expandtab shiftwidth=4
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/lib/native/__init__.py Fri Dec 09 16:22:37 2016 +0100 16.3 @@ -0,0 +1,46 @@ 16.4 +#!/usr/bin/env python 16.5 + 16.6 +""" 16.7 +Native library functions. 16.8 + 16.9 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 16.10 + 16.11 +This program is free software; you can redistribute it and/or modify it under 16.12 +the terms of the GNU General Public License as published by the Free Software 16.13 +Foundation; either version 3 of the License, or (at your option) any later 16.14 +version. 16.15 + 16.16 +This program is distributed in the hope that it will be useful, but WITHOUT 16.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16.19 +details. 16.20 + 16.21 +You should have received a copy of the GNU General Public License along with 16.22 +this program. If not, see <http://www.gnu.org/licenses/>. 16.23 +""" 16.24 + 16.25 +from native.buffer import buffer_str 16.26 + 16.27 +from native.identity import is_, is_not 16.28 + 16.29 +from native.int import int_add, int_div, int_mod, int_mul, int_neg, int_pow, \ 16.30 + int_sub, int_and, int_not, int_or, int_xor, int_lt, \ 16.31 + int_gt, int_eq, int_ne, int_str 16.32 + 16.33 +from native.introspection import object_getattr, isinstance, issubclass 16.34 + 16.35 +from native.io import fclose, fopen, fdopen, close, read, write, fread, fwrite 16.36 + 16.37 +from native.limits import get_maxint, get_minint 16.38 + 16.39 +from native.list import list_init, list_setsize, list_append, list_concat, \ 16.40 + list_len, list_nonempty, list_element, list_setelement 16.41 + 16.42 +from native.program import get_using 16.43 + 16.44 +from native.str import str_add, str_eq, str_gt, str_lt, str_len, str_nonempty, \ 16.45 + str_ord, str_substr 16.46 + 16.47 +from native.system import exit, get_argv, get_path 16.48 + 16.49 +# vim: tabstop=4 expandtab shiftwidth=4
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/lib/native/buffer.py Fri Dec 09 16:22:37 2016 +0100 17.3 @@ -0,0 +1,29 @@ 17.4 +#!/usr/bin/env python 17.5 + 17.6 +""" 17.7 +Native library functions for buffers. 17.8 + 17.9 +None of these are actually defined here. Instead, native implementations are 17.10 +substituted when each program is built. It is, however, important to declare 17.11 +non-core exceptions used by the native functions because they need to be 17.12 +identified as being needed by the program. 17.13 + 17.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 17.15 + 17.16 +This program is free software; you can redistribute it and/or modify it under 17.17 +the terms of the GNU General Public License as published by the Free Software 17.18 +Foundation; either version 3 of the License, or (at your option) any later 17.19 +version. 17.20 + 17.21 +This program is distributed in the hope that it will be useful, but WITHOUT 17.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17.24 +details. 17.25 + 17.26 +You should have received a copy of the GNU General Public License along with 17.27 +this program. If not, see <http://www.gnu.org/licenses/>. 17.28 +""" 17.29 + 17.30 +def buffer_str(self): pass 17.31 + 17.32 +# vim: tabstop=4 expandtab shiftwidth=4
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/lib/native/identity.py Fri Dec 09 16:22:37 2016 +0100 18.3 @@ -0,0 +1,30 @@ 18.4 +#!/usr/bin/env python 18.5 + 18.6 +""" 18.7 +Native library functions for identity testing. 18.8 + 18.9 +None of these are actually defined here. Instead, native implementations are 18.10 +substituted when each program is built. It is, however, important to declare 18.11 +non-core exceptions used by the native functions because they need to be 18.12 +identified as being needed by the program. 18.13 + 18.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 18.15 + 18.16 +This program is free software; you can redistribute it and/or modify it under 18.17 +the terms of the GNU General Public License as published by the Free Software 18.18 +Foundation; either version 3 of the License, or (at your option) any later 18.19 +version. 18.20 + 18.21 +This program is distributed in the hope that it will be useful, but WITHOUT 18.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 18.24 +details. 18.25 + 18.26 +You should have received a copy of the GNU General Public License along with 18.27 +this program. If not, see <http://www.gnu.org/licenses/>. 18.28 +""" 18.29 + 18.30 +def is_(x, y): pass 18.31 +def is_not(x, y): pass 18.32 + 18.33 +# vim: tabstop=4 expandtab shiftwidth=4
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/lib/native/int.py Fri Dec 09 16:22:37 2016 +0100 19.3 @@ -0,0 +1,47 @@ 19.4 +#!/usr/bin/env python 19.5 + 19.6 +""" 19.7 +Native library functions for integers. 19.8 + 19.9 +None of these are actually defined here. Instead, native implementations are 19.10 +substituted when each program is built. It is, however, important to declare 19.11 +non-core exceptions used by the native functions because they need to be 19.12 +identified as being needed by the program. 19.13 + 19.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 19.15 + 19.16 +This program is free software; you can redistribute it and/or modify it under 19.17 +the terms of the GNU General Public License as published by the Free Software 19.18 +Foundation; either version 3 of the License, or (at your option) any later 19.19 +version. 19.20 + 19.21 +This program is distributed in the hope that it will be useful, but WITHOUT 19.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 19.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 19.24 +details. 19.25 + 19.26 +You should have received a copy of the GNU General Public License along with 19.27 +this program. If not, see <http://www.gnu.org/licenses/>. 19.28 +""" 19.29 + 19.30 +def int_add(self, other): pass 19.31 +def int_div(self, other): pass 19.32 +def int_mod(self, other): pass 19.33 +def int_mul(self, other): pass 19.34 +def int_neg(self): pass 19.35 +def int_pow(self, other): pass 19.36 +def int_sub(self, other): pass 19.37 + 19.38 +def int_and(self, other): pass 19.39 +def int_not(self): pass 19.40 +def int_or(self, other): pass 19.41 +def int_xor(self, other): pass 19.42 + 19.43 +def int_lt(self, other): pass 19.44 +def int_gt(self, other): pass 19.45 +def int_eq(self, other): pass 19.46 +def int_ne(self, other): pass 19.47 + 19.48 +def int_str(self): pass 19.49 + 19.50 +# vim: tabstop=4 expandtab shiftwidth=4
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/lib/native/introspection.py Fri Dec 09 16:22:37 2016 +0100 20.3 @@ -0,0 +1,31 @@ 20.4 +#!/usr/bin/env python 20.5 + 20.6 +""" 20.7 +Native library functions for introspection. 20.8 + 20.9 +None of these are actually defined here. Instead, native implementations are 20.10 +substituted when each program is built. It is, however, important to declare 20.11 +non-core exceptions used by the native functions because they need to be 20.12 +identified as being needed by the program. 20.13 + 20.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 20.15 + 20.16 +This program is free software; you can redistribute it and/or modify it under 20.17 +the terms of the GNU General Public License as published by the Free Software 20.18 +Foundation; either version 3 of the License, or (at your option) any later 20.19 +version. 20.20 + 20.21 +This program is distributed in the hope that it will be useful, but WITHOUT 20.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 20.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 20.24 +details. 20.25 + 20.26 +You should have received a copy of the GNU General Public License along with 20.27 +this program. If not, see <http://www.gnu.org/licenses/>. 20.28 +""" 20.29 + 20.30 +def object_getattr(obj, name, default): pass 20.31 +def isinstance(obj, cls): pass 20.32 +def issubclass(obj, cls): pass 20.33 + 20.34 +# vim: tabstop=4 expandtab shiftwidth=4
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/lib/native/io.py Fri Dec 09 16:22:37 2016 +0100 21.3 @@ -0,0 +1,42 @@ 21.4 +#!/usr/bin/env python 21.5 + 21.6 +""" 21.7 +Native library functions for input/output. 21.8 + 21.9 +None of these are actually defined here. Instead, native implementations are 21.10 +substituted when each program is built. It is, however, important to declare 21.11 +non-core exceptions used by the native functions because they need to be 21.12 +identified as being needed by the program. 21.13 + 21.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 21.15 + 21.16 +This program is free software; you can redistribute it and/or modify it under 21.17 +the terms of the GNU General Public License as published by the Free Software 21.18 +Foundation; either version 3 of the License, or (at your option) any later 21.19 +version. 21.20 + 21.21 +This program is distributed in the hope that it will be useful, but WITHOUT 21.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 21.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 21.24 +details. 21.25 + 21.26 +You should have received a copy of the GNU General Public License along with 21.27 +this program. If not, see <http://www.gnu.org/licenses/>. 21.28 +""" 21.29 + 21.30 +def fclose(fp): IOError 21.31 +def fopen(filename, mode): IOError 21.32 +def fdopen(fd, mode): IOError 21.33 +def close(fd): IOError 21.34 +def read(fd, n): IOError 21.35 +def write(fd, str): IOError 21.36 + 21.37 +def fread(fp, n): 21.38 + IOError 21.39 + EOFError 21.40 + 21.41 +def fwrite(fp, str): 21.42 + IOError 21.43 + EOFError 21.44 + 21.45 +# vim: tabstop=4 expandtab shiftwidth=4
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/lib/native/limits.py Fri Dec 09 16:22:37 2016 +0100 22.3 @@ -0,0 +1,30 @@ 22.4 +#!/usr/bin/env python 22.5 + 22.6 +""" 22.7 +Native library functions for value limits. 22.8 + 22.9 +None of these are actually defined here. Instead, native implementations are 22.10 +substituted when each program is built. It is, however, important to declare 22.11 +non-core exceptions used by the native functions because they need to be 22.12 +identified as being needed by the program. 22.13 + 22.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 22.15 + 22.16 +This program is free software; you can redistribute it and/or modify it under 22.17 +the terms of the GNU General Public License as published by the Free Software 22.18 +Foundation; either version 3 of the License, or (at your option) any later 22.19 +version. 22.20 + 22.21 +This program is distributed in the hope that it will be useful, but WITHOUT 22.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 22.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 22.24 +details. 22.25 + 22.26 +You should have received a copy of the GNU General Public License along with 22.27 +this program. If not, see <http://www.gnu.org/licenses/>. 22.28 +""" 22.29 + 22.30 +def get_maxint(): pass 22.31 +def get_minint(): pass 22.32 + 22.33 +# vim: tabstop=4 expandtab shiftwidth=4
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/lib/native/list.py Fri Dec 09 16:22:37 2016 +0100 23.3 @@ -0,0 +1,36 @@ 23.4 +#!/usr/bin/env python 23.5 + 23.6 +""" 23.7 +Native library functions for lists. 23.8 + 23.9 +None of these are actually defined here. Instead, native implementations are 23.10 +substituted when each program is built. It is, however, important to declare 23.11 +non-core exceptions used by the native functions because they need to be 23.12 +identified as being needed by the program. 23.13 + 23.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 23.15 + 23.16 +This program is free software; you can redistribute it and/or modify it under 23.17 +the terms of the GNU General Public License as published by the Free Software 23.18 +Foundation; either version 3 of the License, or (at your option) any later 23.19 +version. 23.20 + 23.21 +This program is distributed in the hope that it will be useful, but WITHOUT 23.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 23.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 23.24 +details. 23.25 + 23.26 +You should have received a copy of the GNU General Public License along with 23.27 +this program. If not, see <http://www.gnu.org/licenses/>. 23.28 +""" 23.29 + 23.30 +def list_init(size): pass 23.31 +def list_setsize(self, size): pass 23.32 +def list_append(self, value): pass 23.33 +def list_concat(self, other): pass 23.34 +def list_len(self): pass 23.35 +def list_nonempty(self): pass 23.36 +def list_element(self, index): pass 23.37 +def list_setelement(self, index, value): pass 23.38 + 23.39 +# vim: tabstop=4 expandtab shiftwidth=4
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/lib/native/program.py Fri Dec 09 16:22:37 2016 +0100 24.3 @@ -0,0 +1,31 @@ 24.4 +#!/usr/bin/env python 24.5 + 24.6 +""" 24.7 +Native library functions for program operations. 24.8 + 24.9 +None of these are actually defined here. Instead, native implementations are 24.10 +substituted when each program is built. It is, however, important to declare 24.11 +non-core exceptions used by the native functions because they need to be 24.12 +identified as being needed by the program. 24.13 + 24.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 24.15 + 24.16 +This program is free software; you can redistribute it and/or modify it under 24.17 +the terms of the GNU General Public License as published by the Free Software 24.18 +Foundation; either version 3 of the License, or (at your option) any later 24.19 +version. 24.20 + 24.21 +This program is distributed in the hope that it will be useful, but WITHOUT 24.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 24.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 24.24 +details. 24.25 + 24.26 +You should have received a copy of the GNU General Public License along with 24.27 +this program. If not, see <http://www.gnu.org/licenses/>. 24.28 +""" 24.29 + 24.30 +# Method binding. 24.31 + 24.32 +def get_using(callable, instance): pass 24.33 + 24.34 +# vim: tabstop=4 expandtab shiftwidth=4
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/lib/native/str.py Fri Dec 09 16:22:37 2016 +0100 25.3 @@ -0,0 +1,38 @@ 25.4 +#!/usr/bin/env python 25.5 + 25.6 +""" 25.7 +Native library functions for strings. 25.8 + 25.9 +None of these are actually defined here. Instead, native implementations are 25.10 +substituted when each program is built. It is, however, important to declare 25.11 +non-core exceptions used by the native functions because they need to be 25.12 +identified as being needed by the program. 25.13 + 25.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 25.15 + 25.16 +This program is free software; you can redistribute it and/or modify it under 25.17 +the terms of the GNU General Public License as published by the Free Software 25.18 +Foundation; either version 3 of the License, or (at your option) any later 25.19 +version. 25.20 + 25.21 +This program is distributed in the hope that it will be useful, but WITHOUT 25.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 25.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 25.24 +details. 25.25 + 25.26 +You should have received a copy of the GNU General Public License along with 25.27 +this program. If not, see <http://www.gnu.org/licenses/>. 25.28 +""" 25.29 + 25.30 +# String operations. 25.31 + 25.32 +def str_add(self, other): pass 25.33 +def str_eq(self, other): pass 25.34 +def str_gt(self, other): pass 25.35 +def str_lt(self, other): pass 25.36 +def str_len(self): pass 25.37 +def str_nonempty(self): pass 25.38 +def str_ord(self): pass 25.39 +def str_substr(self, start, size): pass 25.40 + 25.41 +# vim: tabstop=4 expandtab shiftwidth=4
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/lib/native/system.py Fri Dec 09 16:22:37 2016 +0100 26.3 @@ -0,0 +1,31 @@ 26.4 +#!/usr/bin/env python 26.5 + 26.6 +""" 26.7 +Native library functions for system operations. 26.8 + 26.9 +None of these are actually defined here. Instead, native implementations are 26.10 +substituted when each program is built. It is, however, important to declare 26.11 +non-core exceptions used by the native functions because they need to be 26.12 +identified as being needed by the program. 26.13 + 26.14 +Copyright (C) 2011, 2015, 2016 Paul Boddie <paul@boddie.org.uk> 26.15 + 26.16 +This program is free software; you can redistribute it and/or modify it under 26.17 +the terms of the GNU General Public License as published by the Free Software 26.18 +Foundation; either version 3 of the License, or (at your option) any later 26.19 +version. 26.20 + 26.21 +This program is distributed in the hope that it will be useful, but WITHOUT 26.22 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 26.23 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 26.24 +details. 26.25 + 26.26 +You should have received a copy of the GNU General Public License along with 26.27 +this program. If not, see <http://www.gnu.org/licenses/>. 26.28 +""" 26.29 + 26.30 +def exit(status): pass 26.31 +def get_argv(): pass 26.32 +def get_path(): pass 26.33 + 26.34 +# vim: tabstop=4 expandtab shiftwidth=4
27.1 --- a/lib/operator/core.py Fri Dec 09 00:09:01 2016 +0100 27.2 +++ b/lib/operator/core.py Fri Dec 09 16:22:37 2016 +0100 27.3 @@ -22,7 +22,7 @@ 27.4 # Define "is" and "is not" in terms of native operations. They are imported by 27.5 # the operator.binary module. 27.6 27.7 -from native import _is as is_, _is_not as is_not 27.8 +from native import is_, is_not 27.9 27.10 def binary_op(a, b, left_accessor, right_accessor, default=None): 27.11
28.1 --- a/lib/posix/io.py Fri Dec 09 00:09:01 2016 +0100 28.2 +++ b/lib/posix/io.py Fri Dec 09 16:22:37 2016 +0100 28.3 @@ -78,7 +78,7 @@ 28.4 28.5 "Close the file descriptor 'fd'." 28.6 28.7 - native._close(fd) 28.8 + native.close(fd) 28.9 28.10 def closerange(fd_low, fd_high): pass 28.11 def dup(fd): pass 28.12 @@ -97,7 +97,7 @@ 28.13 28.14 check_int(fd) 28.15 check_string(mode) 28.16 - return native._fdopen(fd, mode) 28.17 + return native.fdopen(fd, mode) 28.18 28.19 def fpathconf(fd, name): pass 28.20 def fstat(fd): pass 28.21 @@ -124,7 +124,7 @@ 28.22 28.23 check_int(fd) 28.24 check_int(n) 28.25 - return native._read(fd, n) 28.26 + return native.read(fd, n) 28.27 28.28 def times(): pass 28.29 def ttyname(fd): pass 28.30 @@ -138,7 +138,7 @@ 28.31 28.32 check_int(fd) 28.33 check_string(s) 28.34 - return native._write(fd, s) 28.35 + return native.write(fd, s) 28.36 28.37 # Constants. 28.38
29.1 --- a/lib/sys.py Fri Dec 09 00:09:01 2016 +0100 29.2 +++ b/lib/sys.py Fri Dec 09 16:22:37 2016 +0100 29.3 @@ -25,12 +25,12 @@ 29.4 29.5 # NOTE: Environment details to be implemented. 29.6 29.7 -argv = native._get_argv() 29.8 -path = native._get_path() 29.9 +argv = native.get_argv() 29.10 +path = native.get_path() 29.11 29.12 # Functions to be implemented natively. 29.13 29.14 def exit(status=0): 29.15 - native._exit(int(status)) 29.16 + native.exit(int(status)) 29.17 29.18 # vim: tabstop=4 expandtab shiftwidth=4
30.1 --- a/templates/Makefile Fri Dec 09 00:09:01 2016 +0100 30.2 +++ b/templates/Makefile Fri Dec 09 16:22:37 2016 +0100 30.3 @@ -1,4 +1,4 @@ 30.4 -SRC = exceptions.c main.c native.c ops.c progops.c progtypes.c $(wildcard src/*.c) 30.5 +SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c) 30.6 OBJ = $(SRC:.c=.o) 30.7 CFLAGS = -I. 30.8 LDFLAGS = -lm
31.1 --- a/templates/Makefile-debug Fri Dec 09 00:09:01 2016 +0100 31.2 +++ b/templates/Makefile-debug Fri Dec 09 16:22:37 2016 +0100 31.3 @@ -1,4 +1,4 @@ 31.4 -SRC = exceptions.c main.c native.c ops.c progops.c progtypes.c $(wildcard src/*.c) 31.5 +SRC = exceptions.c main.c $(wildcard native/*.c) ops.c progops.c progtypes.c $(wildcard src/*.c) 31.6 OBJ = $(SRC:.c=.o) 31.7 CFLAGS = -I. -g 31.8 LDFLAGS = -lm
32.1 --- a/templates/native.c Fri Dec 09 00:09:01 2016 +0100 32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 32.3 @@ -1,868 +0,0 @@ 32.4 -/* Native functions. 32.5 - 32.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 32.7 - 32.8 -This program is free software; you can redistribute it and/or modify it under 32.9 -the terms of the GNU General Public License as published by the Free Software 32.10 -Foundation; either version 3 of the License, or (at your option) any later 32.11 -version. 32.12 - 32.13 -This program is distributed in the hope that it will be useful, but WITHOUT 32.14 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 32.15 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 32.16 -details. 32.17 - 32.18 -You should have received a copy of the GNU General Public License along with 32.19 -this program. If not, see <http://www.gnu.org/licenses/>. 32.20 -*/ 32.21 - 32.22 -#include <stdlib.h> /* abs, exit */ 32.23 -#include <unistd.h> /* read, write */ 32.24 -#include <limits.h> /* INT_MAX, INT_MIN */ 32.25 -#include <math.h> /* ceil, log10, pow */ 32.26 -#include <string.h> /* strcmp, strncpy, strlen */ 32.27 -#include <stdio.h> /* fdopen, snprintf */ 32.28 -#include <errno.h> /* errno */ 32.29 -#include "types.h" 32.30 -#include "exceptions.h" 32.31 -#include "ops.h" 32.32 -#include "progconsts.h" 32.33 -#include "progops.h" 32.34 -#include "progtypes.h" 32.35 -#include "main.h" 32.36 - 32.37 -/* Utility functions. */ 32.38 - 32.39 -static __attr __new_int(int i) 32.40 -{ 32.41 - /* Create a new integer and mutate the __data__ attribute. */ 32.42 - __attr attr = __new(&__InstanceTable___builtins___int_int, &__builtins___int_int, sizeof(__obj___builtins___int_int)); 32.43 - attr.value->attrs[__pos___data__].intvalue = i; 32.44 - return attr; 32.45 -} 32.46 - 32.47 -static __attr __new_str(char *s) 32.48 -{ 32.49 - /* Create a new string and mutate the __data__ attribute. */ 32.50 - __attr attr = __new(&__InstanceTable___builtins___str_string, &__builtins___str_string, sizeof(__obj___builtins___str_string)); 32.51 - attr.value->attrs[__pos___data__].strvalue = s; 32.52 - return attr; 32.53 -} 32.54 - 32.55 -static __attr __new_list(__fragment *f) 32.56 -{ 32.57 - /* Create a new list and mutate the __data__ attribute. */ 32.58 - __attr attr = __new(&__InstanceTable___builtins___list_list, &__builtins___list_list, sizeof(__obj___builtins___list_list)); 32.59 - attr.value->attrs[__pos___data__].seqvalue = f; 32.60 - return attr; 32.61 -} 32.62 - 32.63 -static __fragment *__fragment_append(__fragment *data, __attr * const value) 32.64 -{ 32.65 - __fragment *newdata = data; 32.66 - unsigned int size = data->size, capacity = data->capacity; 32.67 - unsigned int n; 32.68 - 32.69 - /* Re-allocate the fragment if the capacity has been reached. */ 32.70 - if (size >= capacity) 32.71 - { 32.72 - /* NOTE: Consider various restrictions on capacity increases. */ 32.73 - n = capacity ? capacity * 2 : 1; 32.74 - newdata = (__fragment *) __REALLOCATE(data, __FRAGMENT_SIZE(n)); 32.75 - newdata->capacity = n; 32.76 - } 32.77 - 32.78 - /* Insert the new element and increment the list size. */ 32.79 - newdata->attrs[size] = *value; 32.80 - newdata->size = size + 1; 32.81 - 32.82 - return newdata; 32.83 -} 32.84 - 32.85 -/* Environment support. */ 32.86 - 32.87 -__attr __fn_native__exit(__attr __args[]) 32.88 -{ 32.89 - __attr * const status = &__args[1]; 32.90 - 32.91 - exit(__load_via_object(status->value, __pos___data__).intvalue); 32.92 - return __builtins___none_None; 32.93 -} 32.94 - 32.95 -__attr __fn_native__get_argv(__attr __args[]) 32.96 -{ 32.97 - __attr * const status = &__args[1]; 32.98 - 32.99 - /* NOTE: To be written. */ 32.100 - return __builtins___none_None; 32.101 -} 32.102 - 32.103 -__attr __fn_native__get_path(__attr __args[]) 32.104 -{ 32.105 - __attr * const status = &__args[1]; 32.106 - 32.107 - /* NOTE: To be written. */ 32.108 - return __builtins___none_None; 32.109 -} 32.110 - 32.111 -/* Identity testing. */ 32.112 - 32.113 -__attr __fn_native__is(__attr __args[]) 32.114 -{ 32.115 - __attr * const x = &__args[1]; 32.116 - __attr * const y = &__args[2]; 32.117 - 32.118 - return x->value == y->value ? __builtins___boolean_True : __builtins___boolean_False; 32.119 -} 32.120 - 32.121 -__attr __fn_native__is_not(__attr __args[]) 32.122 -{ 32.123 - __attr * const x = &__args[1]; 32.124 - __attr * const y = &__args[2]; 32.125 - 32.126 - return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False; 32.127 -} 32.128 - 32.129 -/* Limit definition. */ 32.130 - 32.131 -__attr __fn_native__get_maxint(__attr __args[]) 32.132 -{ 32.133 - __attr * const status = &__args[1]; 32.134 - 32.135 - return __new_int(INT_MAX); 32.136 -} 32.137 - 32.138 -__attr __fn_native__get_minint(__attr __args[]) 32.139 -{ 32.140 - __attr * const status = &__args[1]; 32.141 - 32.142 - return __new_int(INT_MIN); 32.143 -} 32.144 - 32.145 -/* Integer operations. */ 32.146 - 32.147 -__attr __fn_native__int_add(__attr __args[]) 32.148 -{ 32.149 - __attr * const _data = &__args[1]; 32.150 - __attr * const other = &__args[2]; 32.151 - /* _data and other interpreted as int */ 32.152 - int i = _data->intvalue; 32.153 - int j = other->intvalue; 32.154 - 32.155 - /* Test for overflow. */ 32.156 - if (((i > 0) && (j > 0) && (i > INT_MAX - j)) || 32.157 - ((i < 0) && (j < 0) && (i < INT_MIN - j))) 32.158 - 32.159 - __raise_overflow_error(); 32.160 - 32.161 - /* Return the new integer. */ 32.162 - return __new_int(i + j); 32.163 -} 32.164 - 32.165 -__attr __fn_native__int_sub(__attr __args[]) 32.166 -{ 32.167 - __attr * const _data = &__args[1]; 32.168 - __attr * const other = &__args[2]; 32.169 - /* _data and other interpreted as int */ 32.170 - int i = _data->intvalue; 32.171 - int j = other->intvalue; 32.172 - 32.173 - /* Test for overflow. */ 32.174 - if (((i < 0) && (j > 0) && (i < INT_MIN + j)) || 32.175 - ((i > 0) && (j < 0) && (i > INT_MAX + j))) 32.176 - 32.177 - __raise_overflow_error(); 32.178 - 32.179 - /* Return the new integer. */ 32.180 - return __new_int(i - j); 32.181 -} 32.182 - 32.183 -__attr __fn_native__int_mul(__attr __args[]) 32.184 -{ 32.185 - __attr * const _data = &__args[1]; 32.186 - __attr * const other = &__args[2]; 32.187 - /* _data and other interpreted as int */ 32.188 - int i = _data->intvalue; 32.189 - int j = other->intvalue; 32.190 - 32.191 - /* Test for overflow. */ 32.192 - if (((i > 0) && (j > 0) && (i > INT_MAX / j)) || 32.193 - ((i < 0) && (j < 0) && (i > INT_MAX / j)) || 32.194 - ((i < 0) && (j > 0) && (i < INT_MIN / j)) || 32.195 - ((i > 0) && (j < 0) && (j < INT_MIN / i))) 32.196 - 32.197 - __raise_overflow_error(); 32.198 - 32.199 - /* Return the new integer. */ 32.200 - return __new_int(i * j); 32.201 -} 32.202 - 32.203 -__attr __fn_native__int_div(__attr __args[]) 32.204 -{ 32.205 - __attr * const _data = &__args[1]; 32.206 - __attr * const other = &__args[2]; 32.207 - /* _data and other interpreted as int */ 32.208 - int i = _data->intvalue; 32.209 - int j = other->intvalue; 32.210 - 32.211 - /* Test for division by zero or overflow. */ 32.212 - if (j == 0) 32.213 - __raise_zero_division_error(); 32.214 - else if ((j == -1) && (i == INT_MIN)) 32.215 - __raise_overflow_error(); 32.216 - 32.217 - /* Return the new integer. */ 32.218 - return __new_int(i / j); 32.219 -} 32.220 - 32.221 -__attr __fn_native__int_mod(__attr __args[]) 32.222 -{ 32.223 - __attr * const _data = &__args[1]; 32.224 - __attr * const other = &__args[2]; 32.225 - /* _data and other interpreted as int */ 32.226 - int i = _data->intvalue; 32.227 - int j = other->intvalue; 32.228 - 32.229 - /* Test for division by zero or overflow. */ 32.230 - if (j == 0) 32.231 - __raise_zero_division_error(); 32.232 - else if ((j == -1) && (i == INT_MIN)) 32.233 - __raise_overflow_error(); 32.234 - 32.235 - /* Return the new integer. */ 32.236 - return __new_int(i % j); 32.237 -} 32.238 - 32.239 -__attr __fn_native__int_neg(__attr __args[]) 32.240 -{ 32.241 - __attr * const _data = &__args[1]; 32.242 - /* _data interpreted as int */ 32.243 - int i = _data->intvalue; 32.244 - 32.245 - /* Test for overflow. */ 32.246 - if (i == INT_MIN) 32.247 - __raise_overflow_error(); 32.248 - 32.249 - /* Return the new integer. */ 32.250 - return __new_int(-i); 32.251 -} 32.252 - 32.253 -__attr __fn_native__int_pow(__attr __args[]) 32.254 -{ 32.255 - __attr * const _data = &__args[1]; 32.256 - __attr * const other = &__args[2]; 32.257 - /* _data and other interpreted as int */ 32.258 - int i = _data->intvalue; 32.259 - int j = other->intvalue; 32.260 - int k; 32.261 - 32.262 - errno = 0; 32.263 - k = (int) pow(i, j); 32.264 - 32.265 - /* Test for overflow. */ 32.266 - 32.267 - if (errno == ERANGE) 32.268 - __raise_overflow_error(); 32.269 - 32.270 - /* Return the new integer. */ 32.271 - return __new_int(k); 32.272 -} 32.273 - 32.274 -__attr __fn_native__int_and(__attr __args[]) 32.275 -{ 32.276 - __attr * const _data = &__args[1]; 32.277 - __attr * const other = &__args[2]; 32.278 - /* _data and other interpreted as int */ 32.279 - int i = _data->intvalue; 32.280 - int j = other->intvalue; 32.281 - 32.282 - /* Return the new integer. */ 32.283 - /* NOTE: No overflow test applied. */ 32.284 - return __new_int(i & j); 32.285 -} 32.286 - 32.287 -__attr __fn_native__int_not(__attr __args[]) 32.288 -{ 32.289 - __attr * const _data = &__args[1]; 32.290 - /* _data interpreted as int */ 32.291 - int i = _data->intvalue; 32.292 - 32.293 - /* Return the new integer. */ 32.294 - return __new_int(~i); 32.295 -} 32.296 - 32.297 -__attr __fn_native__int_or(__attr __args[]) 32.298 -{ 32.299 - __attr * const _data = &__args[1]; 32.300 - __attr * const other = &__args[2]; 32.301 - /* _data and other interpreted as int */ 32.302 - int i = _data->intvalue; 32.303 - int j = other->intvalue; 32.304 - 32.305 - /* Return the new integer. */ 32.306 - /* NOTE: No overflow test applied. */ 32.307 - return __new_int(i | j); 32.308 -} 32.309 - 32.310 -__attr __fn_native__int_xor(__attr __args[]) 32.311 -{ 32.312 - __attr * const _data = &__args[1]; 32.313 - __attr * const other = &__args[2]; 32.314 - /* _data and other interpreted as int */ 32.315 - int i = _data->intvalue; 32.316 - int j = other->intvalue; 32.317 - 32.318 - /* Return the new integer. */ 32.319 - /* NOTE: No overflow test applied. */ 32.320 - return __new_int(i ^ j); 32.321 -} 32.322 - 32.323 -__attr __fn_native__int_lt(__attr __args[]) 32.324 -{ 32.325 - __attr * const _data = &__args[1]; 32.326 - __attr * const other = &__args[2]; 32.327 - /* _data and other interpreted as int */ 32.328 - int i = _data->intvalue; 32.329 - int j = other->intvalue; 32.330 - 32.331 - /* Return a boolean result. */ 32.332 - return i < j ? __builtins___boolean_True : __builtins___boolean_False; 32.333 -} 32.334 - 32.335 -__attr __fn_native__int_gt(__attr __args[]) 32.336 -{ 32.337 - __attr * const _data = &__args[1]; 32.338 - __attr * const other = &__args[2]; 32.339 - /* _data and other interpreted as int */ 32.340 - int i = _data->intvalue; 32.341 - int j = other->intvalue; 32.342 - 32.343 - /* Return a boolean result. */ 32.344 - return i > j ? __builtins___boolean_True : __builtins___boolean_False; 32.345 -} 32.346 - 32.347 -__attr __fn_native__int_eq(__attr __args[]) 32.348 -{ 32.349 - __attr * const _data = &__args[1]; 32.350 - __attr * const other = &__args[2]; 32.351 - /* _data and other interpreted as int */ 32.352 - int i = _data->intvalue; 32.353 - int j = other->intvalue; 32.354 - 32.355 - /* Return a boolean result. */ 32.356 - return i == j ? __builtins___boolean_True : __builtins___boolean_False; 32.357 -} 32.358 - 32.359 -__attr __fn_native__int_ne(__attr __args[]) 32.360 -{ 32.361 - __attr * const _data = &__args[1]; 32.362 - __attr * const other = &__args[2]; 32.363 - /* _data and other interpreted as int */ 32.364 - int i = _data->intvalue; 32.365 - int j = other->intvalue; 32.366 - 32.367 - /* Return a boolean result. */ 32.368 - return i != j ? __builtins___boolean_True : __builtins___boolean_False; 32.369 -} 32.370 - 32.371 -__attr __fn_native__int_str(__attr __args[]) 32.372 -{ 32.373 - __attr * const _data = &__args[1]; 32.374 - /* _data interpreted as int */ 32.375 - int i = _data->intvalue; 32.376 - /* Employ a buffer big enough to fit the largest integer plus an extra 32.377 - character, a minus sign, and the null terminator. */ 32.378 - unsigned int n = (int) log10(INT_MAX) + 3; 32.379 - char *s = (char *) __ALLOCATE(n, sizeof(char)); 32.380 - 32.381 - snprintf(s, n, "%d", i); 32.382 - 32.383 - /* Return a new string. */ 32.384 - return __new_str(s); 32.385 -} 32.386 - 32.387 -/* String operations. */ 32.388 - 32.389 -__attr __fn_native__str_add(__attr __args[]) 32.390 -{ 32.391 - __attr * const _data = &__args[1]; 32.392 - __attr * const other = &__args[2]; 32.393 - /* _data, other interpreted as string */ 32.394 - char *s = _data->strvalue; 32.395 - char *o = other->strvalue; 32.396 - int n = strlen(s) + strlen(o) + 1; 32.397 - char *r = (char *) __ALLOCATE(n, sizeof(char)); 32.398 - 32.399 - strncpy(r, s, n); 32.400 - strncpy(r + strlen(s), o, n - strlen(s)); /* should null terminate */ 32.401 - 32.402 - /* Return a new string. */ 32.403 - return __new_str(r); 32.404 -} 32.405 - 32.406 -__attr __fn_native__str_lt(__attr __args[]) 32.407 -{ 32.408 - __attr * const _data = &__args[1]; 32.409 - __attr * const other = &__args[2]; 32.410 - /* _data, other interpreted as string */ 32.411 - char *s = _data->strvalue; 32.412 - char *o = other->strvalue; 32.413 - 32.414 - /* NOTE: Using simple byte-level string operations. */ 32.415 - return strcmp(s, o) < 0 ? __builtins___boolean_True : __builtins___boolean_False; 32.416 -} 32.417 - 32.418 -__attr __fn_native__str_gt(__attr __args[]) 32.419 -{ 32.420 - __attr * const _data = &__args[1]; 32.421 - __attr * const other = &__args[2]; 32.422 - /* _data, other interpreted as string */ 32.423 - char *s = _data->strvalue; 32.424 - char *o = other->strvalue; 32.425 - 32.426 - /* NOTE: Using simple byte-level string operations. */ 32.427 - return strcmp(s, o) > 0 ? __builtins___boolean_True : __builtins___boolean_False; 32.428 -} 32.429 - 32.430 -__attr __fn_native__str_eq(__attr __args[]) 32.431 -{ 32.432 - __attr * const _data = &__args[1]; 32.433 - __attr * const other = &__args[2]; 32.434 - /* _data, other interpreted as string */ 32.435 - char *s = _data->strvalue; 32.436 - char *o = other->strvalue; 32.437 - 32.438 - /* NOTE: Using simple byte-level string operations. */ 32.439 - return strcmp(s, o) == 0 ? __builtins___boolean_True : __builtins___boolean_False; 32.440 -} 32.441 - 32.442 -__attr __fn_native__str_len(__attr __args[]) 32.443 -{ 32.444 - __attr * const _data = &__args[1]; 32.445 - /* _data interpreted as string */ 32.446 - char *s = _data->strvalue; 32.447 - 32.448 - /* Return the new integer. */ 32.449 - return __new_int(strlen(s)); 32.450 -} 32.451 - 32.452 -__attr __fn_native__str_nonempty(__attr __args[]) 32.453 -{ 32.454 - __attr * const _data = &__args[1]; 32.455 - /* _data interpreted as string */ 32.456 - char *s = _data->strvalue; 32.457 - 32.458 - return strlen(s) ? __builtins___boolean_True : __builtins___boolean_False; 32.459 -} 32.460 - 32.461 -__attr __fn_native__str_ord(__attr __args[]) 32.462 -{ 32.463 - __attr * const _data = &__args[1]; 32.464 - /* _data interpreted as string */ 32.465 - char *s = _data->strvalue; 32.466 - 32.467 - return __new_int((unsigned int) s[0]); 32.468 -} 32.469 - 32.470 -__attr __fn_native__str_substr(__attr __args[]) 32.471 -{ 32.472 - __attr * const _data = &__args[1]; 32.473 - __attr * const start = &__args[2]; 32.474 - __attr * const size = &__args[3]; 32.475 - /* _data interpreted as string */ 32.476 - char *s = _data->strvalue, *sub; 32.477 - /* start.__data__ interpreted as int */ 32.478 - int i = __load_via_object(start->value, __pos___data__).intvalue; 32.479 - /* size.__data__ interpreted as int */ 32.480 - int l = __load_via_object(size->value, __pos___data__).intvalue; 32.481 - 32.482 - /* Reserve space for a new string. */ 32.483 - sub = (char *) __ALLOCATE(l + 1, sizeof(char)); 32.484 - strncpy(sub, s + i, l); /* does not null terminate but final byte should be zero */ 32.485 - return __new_str(sub); 32.486 -} 32.487 - 32.488 -/* List operations. */ 32.489 - 32.490 -__attr __fn_native__list_init(__attr __args[]) 32.491 -{ 32.492 - __attr * const size = &__args[1]; 32.493 - /* size.__data__ interpreted as int */ 32.494 - unsigned int n = __load_via_object(size->value, __pos___data__).intvalue; 32.495 - __attr attr = {0, .seqvalue=__new_fragment(n)}; 32.496 - 32.497 - /* Return the __data__ attribute. */ 32.498 - return attr; 32.499 -} 32.500 - 32.501 -__attr __fn_native__list_setsize(__attr __args[]) 32.502 -{ 32.503 - __attr * const _data = &__args[1]; 32.504 - __attr * const size = &__args[2]; 32.505 - /* _data interpreted as list */ 32.506 - __fragment *data = _data->seqvalue; 32.507 - /* size.__data__ interpreted as int */ 32.508 - unsigned int n = __load_via_object(size->value, __pos___data__).intvalue; 32.509 - 32.510 - data->size = n; 32.511 - return __builtins___none_None; 32.512 -} 32.513 - 32.514 -__attr __fn_native__list_append(__attr __args[]) 32.515 -{ 32.516 - __attr * const self = &__args[1]; 32.517 - __attr * const value = &__args[2]; 32.518 - /* self.__data__ interpreted as list */ 32.519 - __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; 32.520 - __fragment *newdata = __fragment_append(data, value); 32.521 - 32.522 - /* Replace the __data__ attribute if appropriate. */ 32.523 - if (newdata != data) 32.524 - __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); 32.525 - return __builtins___none_None; 32.526 -} 32.527 - 32.528 -__attr __fn_native__list_concat(__attr __args[]) 32.529 -{ 32.530 - __attr * const self = &__args[1]; 32.531 - __attr * const other = &__args[2]; 32.532 - /* self.__data__, other interpreted as list */ 32.533 - __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; 32.534 - __fragment *other_data = other->seqvalue; 32.535 - __fragment *newdata = data; 32.536 - unsigned int size = data->size, capacity = data->capacity; 32.537 - unsigned int other_size = other_data->size; 32.538 - unsigned int i, j, n; 32.539 - 32.540 - /* Re-allocate the fragment if the capacity has been reached. */ 32.541 - if (size + other_size >= capacity) 32.542 - { 32.543 - n = size + other_size; 32.544 - newdata = (__fragment *) __REALLOCATE(data, __FRAGMENT_SIZE(n)); 32.545 - newdata->capacity = n; 32.546 - } 32.547 - 32.548 - /* Copy the elements from the other list and increment the list size. */ 32.549 - for (i = size, j = 0; j < other_size; i++, j++) 32.550 - newdata->attrs[i] = other_data->attrs[j]; 32.551 - newdata->size = n; 32.552 - 32.553 - /* Replace the __data__ attribute if appropriate. */ 32.554 - if (newdata != data) 32.555 - __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); 32.556 - return __builtins___none_None; 32.557 -} 32.558 - 32.559 -__attr __fn_native__list_len(__attr __args[]) 32.560 -{ 32.561 - __attr * const _data = &__args[1]; 32.562 - /* _data interpreted as fragment */ 32.563 - unsigned int size = _data->seqvalue->size; 32.564 - 32.565 - /* Return the new integer. */ 32.566 - return __new_int(size); 32.567 -} 32.568 - 32.569 -__attr __fn_native__list_nonempty(__attr __args[]) 32.570 -{ 32.571 - __attr * const _data = &__args[1]; 32.572 - 32.573 - return _data->seqvalue->size ? __builtins___boolean_True : __builtins___boolean_False; 32.574 -} 32.575 - 32.576 -__attr __fn_native__list_element(__attr __args[]) 32.577 -{ 32.578 - __attr * const _data = &__args[1]; 32.579 - __attr * const index = &__args[2]; 32.580 - /* _data interpreted as fragment */ 32.581 - __attr *elements = _data->seqvalue->attrs; 32.582 - /* index.__data__ interpreted as int */ 32.583 - int i = __load_via_object(index->value, __pos___data__).intvalue; 32.584 - 32.585 - return elements[i]; 32.586 -} 32.587 - 32.588 -__attr __fn_native__list_setelement(__attr __args[]) 32.589 -{ 32.590 - __attr * const _data = &__args[1]; 32.591 - __attr * const index = &__args[2]; 32.592 - __attr * const value = &__args[3]; 32.593 - /* _data interpreted as fragment */ 32.594 - __attr *elements = _data->seqvalue->attrs; 32.595 - /* index.__data__ interpreted as int */ 32.596 - int i = __load_via_object(index->value, __pos___data__).intvalue; 32.597 - 32.598 - /* Set the element. */ 32.599 - elements[i] = *value; 32.600 - return __builtins___none_None; 32.601 -} 32.602 - 32.603 -/* Buffer operations. */ 32.604 - 32.605 -__attr __fn_native__buffer_str(__attr __args[]) 32.606 -{ 32.607 - __attr * const _data = &__args[1]; 32.608 - /* _data interpreted as buffer */ 32.609 - __fragment *data = _data->seqvalue; 32.610 - unsigned int size = 0, i, j, n; 32.611 - char *s, *o; 32.612 - 32.613 - /* Calculate the size of the string. */ 32.614 - for (i = 0; i < data->size; i++) 32.615 - size += strlen(__load_via_object(data->attrs[i].value, __pos___data__).strvalue); 32.616 - 32.617 - /* Reserve space for a new string. */ 32.618 - s = (char *) __ALLOCATE(size + 1, sizeof(char)); 32.619 - 32.620 - /* Build a single string from the buffer contents. */ 32.621 - for (i = 0, j = 0; i < data->size; i++) 32.622 - { 32.623 - o = __load_via_object(data->attrs[i].value, __pos___data__).strvalue; 32.624 - n = strlen(o); 32.625 - strncpy(s + j, o, n); /* does not null terminate but final byte should be zero */ 32.626 - j += n; 32.627 - } 32.628 - 32.629 - /* Return a new string. */ 32.630 - return __new_str(s); 32.631 -} 32.632 - 32.633 -/* Method binding. */ 32.634 - 32.635 -__attr __fn_native__get_using(__attr __args[]) 32.636 -{ 32.637 - __attr * const callable = &__args[1]; 32.638 - __attr * const instance = &__args[2]; 32.639 - 32.640 - return __replace_context(instance->value, *callable); 32.641 -} 32.642 - 32.643 -/* Introspection. */ 32.644 - 32.645 -__attr __fn_native__object_getattr(__attr __args[]) 32.646 -{ 32.647 - __attr * const obj = &__args[1]; 32.648 - __attr * const name = &__args[2]; 32.649 - __attr * const _default = &__args[3]; 32.650 - 32.651 - /* NOTE: To be written. */ 32.652 - return __builtins___none_None; 32.653 -} 32.654 - 32.655 -static int __issubclass(__ref obj, __attr cls) 32.656 -{ 32.657 - return (__HASATTR(obj, __TYPEPOS(cls.value), __TYPECODE(cls.value))); 32.658 -} 32.659 - 32.660 -__attr __fn_native__isinstance(__attr __args[]) 32.661 -{ 32.662 - __attr * const obj = &__args[1]; 32.663 - __attr * const cls = &__args[2]; 32.664 - 32.665 - /* cls must be a class. */ 32.666 - if (__is_instance(obj->value) && __issubclass(__get_class(obj->value), *cls)) 32.667 - return __builtins___boolean_True; 32.668 - else 32.669 - return __builtins___boolean_False; 32.670 -} 32.671 - 32.672 -__attr __fn_native__issubclass(__attr __args[]) 32.673 -{ 32.674 - __attr * const obj = &__args[1]; 32.675 - __attr * const cls = &__args[2]; 32.676 - 32.677 - /* obj and cls must be classes. */ 32.678 - if (__issubclass(obj->value, *cls)) 32.679 - return __builtins___boolean_True; 32.680 - else 32.681 - return __builtins___boolean_False; 32.682 -} 32.683 - 32.684 -/* Input/output. */ 32.685 - 32.686 -__attr __fn_native__fclose(__attr __args[]) 32.687 -{ 32.688 - __attr * const fp = &__args[1]; 32.689 - /* fp interpreted as FILE reference */ 32.690 - FILE *f = (FILE *) fp->datavalue; 32.691 - 32.692 - errno = 0; 32.693 - if (fclose(f)) 32.694 - __raise_io_error(__new_int(errno)); 32.695 - 32.696 - return __builtins___none_None; 32.697 -} 32.698 - 32.699 -__attr __fn_native__fopen(__attr __args[]) 32.700 -{ 32.701 - __attr * const filename = &__args[1]; 32.702 - __attr * const mode = &__args[2]; 32.703 - /* filename.__data__ interpreted as string */ 32.704 - char *fn = __load_via_object(filename->value, __pos___data__).strvalue; 32.705 - /* mode.__data__ interpreted as string */ 32.706 - char *s = __load_via_object(mode->value, __pos___data__).strvalue; 32.707 - FILE *f; 32.708 - __attr attr; 32.709 - 32.710 - errno = 0; 32.711 - f = fopen(fn, s); 32.712 - 32.713 - /* Produce an exception if the operation failed. */ 32.714 - 32.715 - if (f == NULL) 32.716 - __raise_io_error(__new_int(errno)); 32.717 - 32.718 - /* Return the __data__ attribute. */ 32.719 - 32.720 - else 32.721 - { 32.722 - attr.context = 0; 32.723 - attr.datavalue = (void *) f; 32.724 - return attr; 32.725 - } 32.726 -} 32.727 - 32.728 -__attr __fn_native__fdopen(__attr __args[]) 32.729 -{ 32.730 - __attr * const fd = &__args[1]; 32.731 - __attr * const mode = &__args[2]; 32.732 - /* fd.__data__ interpreted as int */ 32.733 - int i = __load_via_object(fd->value, __pos___data__).intvalue; 32.734 - /* mode.__data__ interpreted as string */ 32.735 - char *s = __load_via_object(mode->value, __pos___data__).strvalue; 32.736 - FILE *f; 32.737 - __attr attr; 32.738 - 32.739 - errno = 0; 32.740 - f = fdopen(i, s); 32.741 - 32.742 - /* Produce an exception if the operation failed. */ 32.743 - 32.744 - if (f == NULL) 32.745 - __raise_io_error(__new_int(errno)); 32.746 - 32.747 - /* Return the __data__ attribute. */ 32.748 - 32.749 - else 32.750 - { 32.751 - attr.context = 0; 32.752 - attr.datavalue = (void *) f; 32.753 - return attr; 32.754 - } 32.755 -} 32.756 - 32.757 -__attr __fn_native__fread(__attr __args[]) 32.758 -{ 32.759 - __attr * const fp = &__args[1]; 32.760 - __attr * const size = &__args[2]; 32.761 - /* fp interpreted as FILE reference */ 32.762 - FILE *f = (FILE *) fp->datavalue; 32.763 - /* size.__data__ interpreted as int */ 32.764 - int to_read = __load_via_object(size->value, __pos___data__).intvalue; 32.765 - char buf[to_read]; 32.766 - size_t have_read; 32.767 - int error; 32.768 - char *s; 32.769 - 32.770 - have_read = fread(buf, sizeof(char), to_read, f); 32.771 - 32.772 - if (have_read != to_read) 32.773 - { 32.774 - if (feof(f) && (have_read == 0)) 32.775 - __raise_eof_error(); 32.776 - else if (error = ferror(f)) 32.777 - __raise_io_error(__new_int(error)); 32.778 - } 32.779 - 32.780 - /* Reserve space for a new string. */ 32.781 - 32.782 - s = __ALLOCATE(have_read + 1, sizeof(char)); 32.783 - strncpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */ 32.784 - return __new_str(s); 32.785 -} 32.786 - 32.787 -__attr __fn_native__fwrite(__attr __args[]) 32.788 -{ 32.789 - __attr * const fp = &__args[1]; 32.790 - __attr * const str = &__args[2]; 32.791 - /* fp interpreted as FILE reference */ 32.792 - FILE *f = (FILE *) fp->datavalue; 32.793 - /* str.__data__ interpreted as string */ 32.794 - char *s = __load_via_object(str->value, __pos___data__).strvalue; 32.795 - size_t to_write = strlen(s); 32.796 - size_t have_written = fwrite(s, sizeof(char), to_write, f); 32.797 - int error; 32.798 - 32.799 - if (have_written != to_write) 32.800 - { 32.801 - if (feof(f)) 32.802 - __raise_eof_error(); 32.803 - else if (error = ferror(f)) 32.804 - __raise_io_error(__new_int(error)); 32.805 - } 32.806 - 32.807 - return __builtins___none_None; 32.808 -} 32.809 - 32.810 -__attr __fn_native__close(__attr __args[]) 32.811 -{ 32.812 - __attr * const fd = &__args[1]; 32.813 - /* fd.__data__ interpreted as int */ 32.814 - int i = __load_via_object(fd->value, __pos___data__).intvalue; 32.815 - 32.816 - errno = 0; 32.817 - if (close(i) == -1) 32.818 - __raise_io_error(__new_int(errno)); 32.819 - 32.820 - return __builtins___none_None; 32.821 -} 32.822 - 32.823 -__attr __fn_native__read(__attr __args[]) 32.824 -{ 32.825 - __attr * const fd = &__args[1]; 32.826 - __attr * const n = &__args[2]; 32.827 - /* fd.__data__ interpreted as int */ 32.828 - int i = __load_via_object(fd->value, __pos___data__).intvalue; 32.829 - /* n.__data__ interpreted as int */ 32.830 - int to_read = __load_via_object(n->value, __pos___data__).intvalue; 32.831 - char buf[to_read]; 32.832 - ssize_t have_read; 32.833 - char *s; 32.834 - 32.835 - errno = 0; 32.836 - have_read = read(i, buf, to_read * sizeof(char)); 32.837 - 32.838 - if (have_read == -1) 32.839 - __raise_io_error(__new_int(errno)); 32.840 - 32.841 - /* Reserve space for a new string. */ 32.842 - 32.843 - s = __ALLOCATE(have_read + 1, 1); 32.844 - strncpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */ 32.845 - return __new_str(s); 32.846 -} 32.847 - 32.848 -__attr __fn_native__write(__attr __args[]) 32.849 -{ 32.850 - __attr * const fd = &__args[1]; 32.851 - __attr * const str = &__args[2]; 32.852 - /* fd.__data__ interpreted as int */ 32.853 - int i = __load_via_object(fd->value, __pos___data__).intvalue; 32.854 - /* str.__data__ interpreted as string */ 32.855 - char *s = __load_via_object(str->value, __pos___data__).strvalue; 32.856 - ssize_t have_written; 32.857 - 32.858 - errno = 0; 32.859 - have_written = write(i, s, sizeof(char) * strlen(s)); 32.860 - 32.861 - if (have_written == -1) 32.862 - __raise_io_error(__new_int(errno)); 32.863 - 32.864 - return __new_int(have_written); 32.865 -} 32.866 - 32.867 -/* Module initialisation. */ 32.868 - 32.869 -void __main_native() 32.870 -{ 32.871 -}
33.1 --- a/templates/native.h Fri Dec 09 00:09:01 2016 +0100 33.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 33.3 @@ -1,116 +0,0 @@ 33.4 -/* Native functions. 33.5 - 33.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 33.7 - 33.8 -This program is free software; you can redistribute it and/or modify it under 33.9 -the terms of the GNU General Public License as published by the Free Software 33.10 -Foundation; either version 3 of the License, or (at your option) any later 33.11 -version. 33.12 - 33.13 -This program is distributed in the hope that it will be useful, but WITHOUT 33.14 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 33.15 -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 33.16 -details. 33.17 - 33.18 -You should have received a copy of the GNU General Public License along with 33.19 -this program. If not, see <http://www.gnu.org/licenses/>. 33.20 -*/ 33.21 - 33.22 -#ifndef __NATIVE_H__ 33.23 -#define __NATIVE_H__ 33.24 - 33.25 -/* Environment support. */ 33.26 - 33.27 -__attr __fn_native__exit(__attr __args[]); 33.28 -__attr __fn_native__get_argv(__attr __args[]); 33.29 -__attr __fn_native__get_path(__attr __args[]); 33.30 - 33.31 -/* Identity testing. */ 33.32 - 33.33 -__attr __fn_native__is(__attr __args[]); 33.34 -__attr __fn_native__is_not(__attr __args[]); 33.35 - 33.36 -/* Limit definition. */ 33.37 - 33.38 -__attr __fn_native__get_maxint(__attr __args[]); 33.39 -__attr __fn_native__get_minint(__attr __args[]); 33.40 - 33.41 -/* Integer operations. */ 33.42 - 33.43 -__attr __fn_native__int_add(__attr __args[]); 33.44 -__attr __fn_native__int_div(__attr __args[]); 33.45 -__attr __fn_native__int_mod(__attr __args[]); 33.46 -__attr __fn_native__int_mul(__attr __args[]); 33.47 -__attr __fn_native__int_neg(__attr __args[]); 33.48 -__attr __fn_native__int_pow(__attr __args[]); 33.49 -__attr __fn_native__int_sub(__attr __args[]); 33.50 - 33.51 -__attr __fn_native__int_and(__attr __args[]); 33.52 -__attr __fn_native__int_not(__attr __args[]); 33.53 -__attr __fn_native__int_or(__attr __args[]); 33.54 -__attr __fn_native__int_xor(__attr __args[]); 33.55 - 33.56 -__attr __fn_native__int_rdiv(__attr __args[]); 33.57 -__attr __fn_native__int_rmod(__attr __args[]); 33.58 -__attr __fn_native__int_rpow(__attr __args[]); 33.59 -__attr __fn_native__int_rsub(__attr __args[]); 33.60 - 33.61 -__attr __fn_native__int_lt(__attr __args[]); 33.62 -__attr __fn_native__int_gt(__attr __args[]); 33.63 -__attr __fn_native__int_eq(__attr __args[]); 33.64 -__attr __fn_native__int_ne(__attr __args[]); 33.65 - 33.66 -__attr __fn_native__int_str(__attr __args[]); 33.67 - 33.68 -/* String operations. */ 33.69 - 33.70 -__attr __fn_native__str_add(__attr __args[]); 33.71 -__attr __fn_native__str_lt(__attr __args[]); 33.72 -__attr __fn_native__str_gt(__attr __args[]); 33.73 -__attr __fn_native__str_eq(__attr __args[]); 33.74 -__attr __fn_native__str_len(__attr __args[]); 33.75 -__attr __fn_native__str_nonempty(__attr __args[]); 33.76 -__attr __fn_native__str_ord(__attr __args[]); 33.77 -__attr __fn_native__str_substr(__attr __args[]); 33.78 - 33.79 -/* List operations. */ 33.80 - 33.81 -__attr __fn_native__list_init(__attr __args[]); 33.82 -__attr __fn_native__list_setsize(__attr __args[]); 33.83 -__attr __fn_native__list_append(__attr __args[]); 33.84 -__attr __fn_native__list_concat(__attr __args[]); 33.85 -__attr __fn_native__list_len(__attr __args[]); 33.86 -__attr __fn_native__list_nonempty(__attr __args[]); 33.87 -__attr __fn_native__list_element(__attr __args[]); 33.88 -__attr __fn_native__list_setelement(__attr __args[]); 33.89 - 33.90 -/* Buffer operations. */ 33.91 - 33.92 -__attr __fn_native__buffer_str(__attr __args[]); 33.93 - 33.94 -/* Method binding. */ 33.95 - 33.96 -__attr __fn_native__get_using(__attr __args[]); 33.97 - 33.98 -/* Introspection. */ 33.99 - 33.100 -__attr __fn_native__object_getattr(__attr __args[]); 33.101 -__attr __fn_native__isinstance(__attr __args[]); 33.102 -__attr __fn_native__issubclass(__attr __args[]); 33.103 - 33.104 -/* Input/output. */ 33.105 - 33.106 -__attr __fn_native__fclose(__attr __args[]); 33.107 -__attr __fn_native__fopen(__attr __args[]); 33.108 -__attr __fn_native__fdopen(__attr __args[]); 33.109 -__attr __fn_native__fread(__attr __args[]); 33.110 -__attr __fn_native__fwrite(__attr __args[]); 33.111 -__attr __fn_native__close(__attr __args[]); 33.112 -__attr __fn_native__read(__attr __args[]); 33.113 -__attr __fn_native__write(__attr __args[]); 33.114 - 33.115 -/* Module initialisation. */ 33.116 - 33.117 -void __main_native(); 33.118 - 33.119 -#endif /* __NATIVE_H__ */
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/templates/native/buffer.c Fri Dec 09 16:22:37 2016 +0100 34.3 @@ -0,0 +1,61 @@ 34.4 +/* Native functions for buffer operations. 34.5 + 34.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 34.7 + 34.8 +This program is free software; you can redistribute it and/or modify it under 34.9 +the terms of the GNU General Public License as published by the Free Software 34.10 +Foundation; either version 3 of the License, or (at your option) any later 34.11 +version. 34.12 + 34.13 +This program is distributed in the hope that it will be useful, but WITHOUT 34.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 34.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 34.16 +details. 34.17 + 34.18 +You should have received a copy of the GNU General Public License along with 34.19 +this program. If not, see <http://www.gnu.org/licenses/>. 34.20 +*/ 34.21 + 34.22 +#include <string.h> /* strcmp, strncpy, strlen */ 34.23 +#include "native/common.h" 34.24 +#include "types.h" 34.25 +#include "exceptions.h" 34.26 +#include "ops.h" 34.27 +#include "progconsts.h" 34.28 +#include "progops.h" 34.29 +#include "progtypes.h" 34.30 +#include "main.h" 34.31 + 34.32 +__attr __fn_native_buffer_buffer_str(__attr __args[]) 34.33 +{ 34.34 + __attr * const _data = &__args[1]; 34.35 + /* _data interpreted as buffer */ 34.36 + __fragment *data = _data->seqvalue; 34.37 + unsigned int size = 0, i, j, n; 34.38 + char *s, *o; 34.39 + 34.40 + /* Calculate the size of the string. */ 34.41 + for (i = 0; i < data->size; i++) 34.42 + size += strlen(__load_via_object(data->attrs[i].value, __pos___data__).strvalue); 34.43 + 34.44 + /* Reserve space for a new string. */ 34.45 + s = (char *) __ALLOCATE(size + 1, sizeof(char)); 34.46 + 34.47 + /* Build a single string from the buffer contents. */ 34.48 + for (i = 0, j = 0; i < data->size; i++) 34.49 + { 34.50 + o = __load_via_object(data->attrs[i].value, __pos___data__).strvalue; 34.51 + n = strlen(o); 34.52 + strncpy(s + j, o, n); /* does not null terminate but final byte should be zero */ 34.53 + j += n; 34.54 + } 34.55 + 34.56 + /* Return a new string. */ 34.57 + return __new_str(s); 34.58 +} 34.59 + 34.60 +/* Module initialisation. */ 34.61 + 34.62 +void __main_native_buffer() 34.63 +{ 34.64 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/templates/native/buffer.h Fri Dec 09 16:22:37 2016 +0100 35.3 @@ -0,0 +1,32 @@ 35.4 +/* Native functions for buffer operations. 35.5 + 35.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 35.7 + 35.8 +This program is free software; you can redistribute it and/or modify it under 35.9 +the terms of the GNU General Public License as published by the Free Software 35.10 +Foundation; either version 3 of the License, or (at your option) any later 35.11 +version. 35.12 + 35.13 +This program is distributed in the hope that it will be useful, but WITHOUT 35.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 35.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 35.16 +details. 35.17 + 35.18 +You should have received a copy of the GNU General Public License along with 35.19 +this program. If not, see <http://www.gnu.org/licenses/>. 35.20 +*/ 35.21 + 35.22 +#ifndef __NATIVE_BUFFER_H__ 35.23 +#define __NATIVE_BUFFER_H__ 35.24 + 35.25 +#include "types.h" 35.26 + 35.27 +/* Buffer operations. */ 35.28 + 35.29 +__attr __fn_native_buffer_buffer_str(__attr __args[]); 35.30 + 35.31 +/* Module initialisation. */ 35.32 + 35.33 +void __main_native_buffer(); 35.34 + 35.35 +#endif /* __NATIVE_BUFFER_H__ */
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/templates/native/common.c Fri Dec 09 16:22:37 2016 +0100 36.3 @@ -0,0 +1,73 @@ 36.4 +/* Common operations for native functions. 36.5 + 36.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 36.7 + 36.8 +This program is free software; you can redistribute it and/or modify it under 36.9 +the terms of the GNU General Public License as published by the Free Software 36.10 +Foundation; either version 3 of the License, or (at your option) any later 36.11 +version. 36.12 + 36.13 +This program is distributed in the hope that it will be useful, but WITHOUT 36.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 36.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 36.16 +details. 36.17 + 36.18 +You should have received a copy of the GNU General Public License along with 36.19 +this program. If not, see <http://www.gnu.org/licenses/>. 36.20 +*/ 36.21 + 36.22 +#include "types.h" 36.23 +#include "exceptions.h" 36.24 +#include "ops.h" 36.25 +#include "progconsts.h" 36.26 +#include "progops.h" 36.27 +#include "progtypes.h" 36.28 +#include "main.h" 36.29 + 36.30 +/* Utility functions. */ 36.31 + 36.32 +__attr __new_int(int i) 36.33 +{ 36.34 + /* Create a new integer and mutate the __data__ attribute. */ 36.35 + __attr attr = __new(&__InstanceTable___builtins___int_int, &__builtins___int_int, sizeof(__obj___builtins___int_int)); 36.36 + attr.value->attrs[__pos___data__].intvalue = i; 36.37 + return attr; 36.38 +} 36.39 + 36.40 +__attr __new_str(char *s) 36.41 +{ 36.42 + /* Create a new string and mutate the __data__ attribute. */ 36.43 + __attr attr = __new(&__InstanceTable___builtins___str_string, &__builtins___str_string, sizeof(__obj___builtins___str_string)); 36.44 + attr.value->attrs[__pos___data__].strvalue = s; 36.45 + return attr; 36.46 +} 36.47 + 36.48 +__attr __new_list(__fragment *f) 36.49 +{ 36.50 + /* Create a new list and mutate the __data__ attribute. */ 36.51 + __attr attr = __new(&__InstanceTable___builtins___list_list, &__builtins___list_list, sizeof(__obj___builtins___list_list)); 36.52 + attr.value->attrs[__pos___data__].seqvalue = f; 36.53 + return attr; 36.54 +} 36.55 + 36.56 +__fragment *__fragment_append(__fragment *data, __attr * const value) 36.57 +{ 36.58 + __fragment *newdata = data; 36.59 + unsigned int size = data->size, capacity = data->capacity; 36.60 + unsigned int n; 36.61 + 36.62 + /* Re-allocate the fragment if the capacity has been reached. */ 36.63 + if (size >= capacity) 36.64 + { 36.65 + /* NOTE: Consider various restrictions on capacity increases. */ 36.66 + n = capacity ? capacity * 2 : 1; 36.67 + newdata = (__fragment *) __REALLOCATE(data, __FRAGMENT_SIZE(n)); 36.68 + newdata->capacity = n; 36.69 + } 36.70 + 36.71 + /* Insert the new element and increment the list size. */ 36.72 + newdata->attrs[size] = *value; 36.73 + newdata->size = size + 1; 36.74 + 36.75 + return newdata; 36.76 +}
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/templates/native/common.h Fri Dec 09 16:22:37 2016 +0100 37.3 @@ -0,0 +1,31 @@ 37.4 +/* Common operations for native functions. 37.5 + 37.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 37.7 + 37.8 +This program is free software; you can redistribute it and/or modify it under 37.9 +the terms of the GNU General Public License as published by the Free Software 37.10 +Foundation; either version 3 of the License, or (at your option) any later 37.11 +version. 37.12 + 37.13 +This program is distributed in the hope that it will be useful, but WITHOUT 37.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 37.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 37.16 +details. 37.17 + 37.18 +You should have received a copy of the GNU General Public License along with 37.19 +this program. If not, see <http://www.gnu.org/licenses/>. 37.20 +*/ 37.21 + 37.22 +#ifndef __NATIVE_COMMON_H__ 37.23 +#define __NATIVE_COMMON_H__ 37.24 + 37.25 +#include "types.h" 37.26 + 37.27 +/* Utility functions. */ 37.28 + 37.29 +__attr __new_int(int i); 37.30 +__attr __new_str(char *s); 37.31 +__attr __new_list(__fragment *f); 37.32 +__fragment *__fragment_append(__fragment *data, __attr * const value); 37.33 + 37.34 +#endif /* __NATIVE_COMMON_H__ */
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/templates/native/identity.c Fri Dec 09 16:22:37 2016 +0100 38.3 @@ -0,0 +1,49 @@ 38.4 +/* Native functions for identity operations. 38.5 + 38.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 38.7 + 38.8 +This program is free software; you can redistribute it and/or modify it under 38.9 +the terms of the GNU General Public License as published by the Free Software 38.10 +Foundation; either version 3 of the License, or (at your option) any later 38.11 +version. 38.12 + 38.13 +This program is distributed in the hope that it will be useful, but WITHOUT 38.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 38.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 38.16 +details. 38.17 + 38.18 +You should have received a copy of the GNU General Public License along with 38.19 +this program. If not, see <http://www.gnu.org/licenses/>. 38.20 +*/ 38.21 + 38.22 +#include "types.h" 38.23 +#include "exceptions.h" 38.24 +#include "ops.h" 38.25 +#include "progconsts.h" 38.26 +#include "progops.h" 38.27 +#include "progtypes.h" 38.28 +#include "main.h" 38.29 + 38.30 +/* Identity testing. */ 38.31 + 38.32 +__attr __fn_native_identity_is_(__attr __args[]) 38.33 +{ 38.34 + __attr * const x = &__args[1]; 38.35 + __attr * const y = &__args[2]; 38.36 + 38.37 + return x->value == y->value ? __builtins___boolean_True : __builtins___boolean_False; 38.38 +} 38.39 + 38.40 +__attr __fn_native_identity_is_not(__attr __args[]) 38.41 +{ 38.42 + __attr * const x = &__args[1]; 38.43 + __attr * const y = &__args[2]; 38.44 + 38.45 + return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False; 38.46 +} 38.47 + 38.48 +/* Module initialisation. */ 38.49 + 38.50 +void __main_native_identity() 38.51 +{ 38.52 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/templates/native/identity.h Fri Dec 09 16:22:37 2016 +0100 39.3 @@ -0,0 +1,33 @@ 39.4 +/* Native functions for identity operations. 39.5 + 39.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 39.7 + 39.8 +This program is free software; you can redistribute it and/or modify it under 39.9 +the terms of the GNU General Public License as published by the Free Software 39.10 +Foundation; either version 3 of the License, or (at your option) any later 39.11 +version. 39.12 + 39.13 +This program is distributed in the hope that it will be useful, but WITHOUT 39.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 39.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 39.16 +details. 39.17 + 39.18 +You should have received a copy of the GNU General Public License along with 39.19 +this program. If not, see <http://www.gnu.org/licenses/>. 39.20 +*/ 39.21 + 39.22 +#ifndef __NATIVE_IDENTITY_H__ 39.23 +#define __NATIVE_IDENTITY_H__ 39.24 + 39.25 +#include "types.h" 39.26 + 39.27 +/* Identity testing. */ 39.28 + 39.29 +__attr __fn_native_identity_is_(__attr __args[]); 39.30 +__attr __fn_native_identity_is_not(__attr __args[]); 39.31 + 39.32 +/* Module initialisation. */ 39.33 + 39.34 +void __main_native_identity(); 39.35 + 39.36 +#endif /* __NATIVE_IDENTITY_H__ */
40.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 40.2 +++ b/templates/native/int.c Fri Dec 09 16:22:37 2016 +0100 40.3 @@ -0,0 +1,278 @@ 40.4 +/* Native functions for integer operations. 40.5 + 40.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 40.7 + 40.8 +This program is free software; you can redistribute it and/or modify it under 40.9 +the terms of the GNU General Public License as published by the Free Software 40.10 +Foundation; either version 3 of the License, or (at your option) any later 40.11 +version. 40.12 + 40.13 +This program is distributed in the hope that it will be useful, but WITHOUT 40.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 40.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 40.16 +details. 40.17 + 40.18 +You should have received a copy of the GNU General Public License along with 40.19 +this program. If not, see <http://www.gnu.org/licenses/>. 40.20 +*/ 40.21 + 40.22 +#include <limits.h> /* INT_MAX, INT_MIN */ 40.23 +#include <math.h> /* ceil, log10, pow */ 40.24 +#include <stdio.h> /* fdopen, snprintf */ 40.25 +#include <errno.h> /* errno */ 40.26 +#include "native/common.h" 40.27 +#include "types.h" 40.28 +#include "exceptions.h" 40.29 +#include "ops.h" 40.30 +#include "progconsts.h" 40.31 +#include "progops.h" 40.32 +#include "progtypes.h" 40.33 +#include "main.h" 40.34 + 40.35 +/* Integer operations. */ 40.36 + 40.37 +__attr __fn_native_int_int_add(__attr __args[]) 40.38 +{ 40.39 + __attr * const _data = &__args[1]; 40.40 + __attr * const other = &__args[2]; 40.41 + /* _data and other interpreted as int */ 40.42 + int i = _data->intvalue; 40.43 + int j = other->intvalue; 40.44 + 40.45 + /* Test for overflow. */ 40.46 + if (((i > 0) && (j > 0) && (i > INT_MAX - j)) || 40.47 + ((i < 0) && (j < 0) && (i < INT_MIN - j))) 40.48 + 40.49 + __raise_overflow_error(); 40.50 + 40.51 + /* Return the new integer. */ 40.52 + return __new_int(i + j); 40.53 +} 40.54 + 40.55 +__attr __fn_native_int_int_sub(__attr __args[]) 40.56 +{ 40.57 + __attr * const _data = &__args[1]; 40.58 + __attr * const other = &__args[2]; 40.59 + /* _data and other interpreted as int */ 40.60 + int i = _data->intvalue; 40.61 + int j = other->intvalue; 40.62 + 40.63 + /* Test for overflow. */ 40.64 + if (((i < 0) && (j > 0) && (i < INT_MIN + j)) || 40.65 + ((i > 0) && (j < 0) && (i > INT_MAX + j))) 40.66 + 40.67 + __raise_overflow_error(); 40.68 + 40.69 + /* Return the new integer. */ 40.70 + return __new_int(i - j); 40.71 +} 40.72 + 40.73 +__attr __fn_native_int_int_mul(__attr __args[]) 40.74 +{ 40.75 + __attr * const _data = &__args[1]; 40.76 + __attr * const other = &__args[2]; 40.77 + /* _data and other interpreted as int */ 40.78 + int i = _data->intvalue; 40.79 + int j = other->intvalue; 40.80 + 40.81 + /* Test for overflow. */ 40.82 + if (((i > 0) && (j > 0) && (i > INT_MAX / j)) || 40.83 + ((i < 0) && (j < 0) && (i > INT_MAX / j)) || 40.84 + ((i < 0) && (j > 0) && (i < INT_MIN / j)) || 40.85 + ((i > 0) && (j < 0) && (j < INT_MIN / i))) 40.86 + 40.87 + __raise_overflow_error(); 40.88 + 40.89 + /* Return the new integer. */ 40.90 + return __new_int(i * j); 40.91 +} 40.92 + 40.93 +__attr __fn_native_int_int_div(__attr __args[]) 40.94 +{ 40.95 + __attr * const _data = &__args[1]; 40.96 + __attr * const other = &__args[2]; 40.97 + /* _data and other interpreted as int */ 40.98 + int i = _data->intvalue; 40.99 + int j = other->intvalue; 40.100 + 40.101 + /* Test for division by zero or overflow. */ 40.102 + if (j == 0) 40.103 + __raise_zero_division_error(); 40.104 + else if ((j == -1) && (i == INT_MIN)) 40.105 + __raise_overflow_error(); 40.106 + 40.107 + /* Return the new integer. */ 40.108 + return __new_int(i / j); 40.109 +} 40.110 + 40.111 +__attr __fn_native_int_int_mod(__attr __args[]) 40.112 +{ 40.113 + __attr * const _data = &__args[1]; 40.114 + __attr * const other = &__args[2]; 40.115 + /* _data and other interpreted as int */ 40.116 + int i = _data->intvalue; 40.117 + int j = other->intvalue; 40.118 + 40.119 + /* Test for division by zero or overflow. */ 40.120 + if (j == 0) 40.121 + __raise_zero_division_error(); 40.122 + else if ((j == -1) && (i == INT_MIN)) 40.123 + __raise_overflow_error(); 40.124 + 40.125 + /* Return the new integer. */ 40.126 + return __new_int(i % j); 40.127 +} 40.128 + 40.129 +__attr __fn_native_int_int_neg(__attr __args[]) 40.130 +{ 40.131 + __attr * const _data = &__args[1]; 40.132 + /* _data interpreted as int */ 40.133 + int i = _data->intvalue; 40.134 + 40.135 + /* Test for overflow. */ 40.136 + if (i == INT_MIN) 40.137 + __raise_overflow_error(); 40.138 + 40.139 + /* Return the new integer. */ 40.140 + return __new_int(-i); 40.141 +} 40.142 + 40.143 +__attr __fn_native_int_int_pow(__attr __args[]) 40.144 +{ 40.145 + __attr * const _data = &__args[1]; 40.146 + __attr * const other = &__args[2]; 40.147 + /* _data and other interpreted as int */ 40.148 + int i = _data->intvalue; 40.149 + int j = other->intvalue; 40.150 + int k; 40.151 + 40.152 + errno = 0; 40.153 + k = (int) pow(i, j); 40.154 + 40.155 + /* Test for overflow. */ 40.156 + 40.157 + if (errno == ERANGE) 40.158 + __raise_overflow_error(); 40.159 + 40.160 + /* Return the new integer. */ 40.161 + return __new_int(k); 40.162 +} 40.163 + 40.164 +__attr __fn_native_int_int_and(__attr __args[]) 40.165 +{ 40.166 + __attr * const _data = &__args[1]; 40.167 + __attr * const other = &__args[2]; 40.168 + /* _data and other interpreted as int */ 40.169 + int i = _data->intvalue; 40.170 + int j = other->intvalue; 40.171 + 40.172 + /* Return the new integer. */ 40.173 + /* NOTE: No overflow test applied. */ 40.174 + return __new_int(i & j); 40.175 +} 40.176 + 40.177 +__attr __fn_native_int_int_not(__attr __args[]) 40.178 +{ 40.179 + __attr * const _data = &__args[1]; 40.180 + /* _data interpreted as int */ 40.181 + int i = _data->intvalue; 40.182 + 40.183 + /* Return the new integer. */ 40.184 + return __new_int(~i); 40.185 +} 40.186 + 40.187 +__attr __fn_native_int_int_or(__attr __args[]) 40.188 +{ 40.189 + __attr * const _data = &__args[1]; 40.190 + __attr * const other = &__args[2]; 40.191 + /* _data and other interpreted as int */ 40.192 + int i = _data->intvalue; 40.193 + int j = other->intvalue; 40.194 + 40.195 + /* Return the new integer. */ 40.196 + /* NOTE: No overflow test applied. */ 40.197 + return __new_int(i | j); 40.198 +} 40.199 + 40.200 +__attr __fn_native_int_int_xor(__attr __args[]) 40.201 +{ 40.202 + __attr * const _data = &__args[1]; 40.203 + __attr * const other = &__args[2]; 40.204 + /* _data and other interpreted as int */ 40.205 + int i = _data->intvalue; 40.206 + int j = other->intvalue; 40.207 + 40.208 + /* Return the new integer. */ 40.209 + /* NOTE: No overflow test applied. */ 40.210 + return __new_int(i ^ j); 40.211 +} 40.212 + 40.213 +__attr __fn_native_int_int_lt(__attr __args[]) 40.214 +{ 40.215 + __attr * const _data = &__args[1]; 40.216 + __attr * const other = &__args[2]; 40.217 + /* _data and other interpreted as int */ 40.218 + int i = _data->intvalue; 40.219 + int j = other->intvalue; 40.220 + 40.221 + /* Return a boolean result. */ 40.222 + return i < j ? __builtins___boolean_True : __builtins___boolean_False; 40.223 +} 40.224 + 40.225 +__attr __fn_native_int_int_gt(__attr __args[]) 40.226 +{ 40.227 + __attr * const _data = &__args[1]; 40.228 + __attr * const other = &__args[2]; 40.229 + /* _data and other interpreted as int */ 40.230 + int i = _data->intvalue; 40.231 + int j = other->intvalue; 40.232 + 40.233 + /* Return a boolean result. */ 40.234 + return i > j ? __builtins___boolean_True : __builtins___boolean_False; 40.235 +} 40.236 + 40.237 +__attr __fn_native_int_int_eq(__attr __args[]) 40.238 +{ 40.239 + __attr * const _data = &__args[1]; 40.240 + __attr * const other = &__args[2]; 40.241 + /* _data and other interpreted as int */ 40.242 + int i = _data->intvalue; 40.243 + int j = other->intvalue; 40.244 + 40.245 + /* Return a boolean result. */ 40.246 + return i == j ? __builtins___boolean_True : __builtins___boolean_False; 40.247 +} 40.248 + 40.249 +__attr __fn_native_int_int_ne(__attr __args[]) 40.250 +{ 40.251 + __attr * const _data = &__args[1]; 40.252 + __attr * const other = &__args[2]; 40.253 + /* _data and other interpreted as int */ 40.254 + int i = _data->intvalue; 40.255 + int j = other->intvalue; 40.256 + 40.257 + /* Return a boolean result. */ 40.258 + return i != j ? __builtins___boolean_True : __builtins___boolean_False; 40.259 +} 40.260 + 40.261 +__attr __fn_native_int_int_str(__attr __args[]) 40.262 +{ 40.263 + __attr * const _data = &__args[1]; 40.264 + /* _data interpreted as int */ 40.265 + int i = _data->intvalue; 40.266 + /* Employ a buffer big enough to fit the largest integer plus an extra 40.267 + character, a minus sign, and the null terminator. */ 40.268 + unsigned int n = (int) log10(INT_MAX) + 3; 40.269 + char *s = (char *) __ALLOCATE(n, sizeof(char)); 40.270 + 40.271 + snprintf(s, n, "%d", i); 40.272 + 40.273 + /* Return a new string. */ 40.274 + return __new_str(s); 40.275 +} 40.276 + 40.277 +/* Module initialisation. */ 40.278 + 40.279 +void __main_native_int() 40.280 +{ 40.281 +}
41.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 41.2 +++ b/templates/native/int.h Fri Dec 09 16:22:37 2016 +0100 41.3 @@ -0,0 +1,55 @@ 41.4 +/* Native functions for integer operations. 41.5 + 41.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 41.7 + 41.8 +This program is free software; you can redistribute it and/or modify it under 41.9 +the terms of the GNU General Public License as published by the Free Software 41.10 +Foundation; either version 3 of the License, or (at your option) any later 41.11 +version. 41.12 + 41.13 +This program is distributed in the hope that it will be useful, but WITHOUT 41.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 41.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 41.16 +details. 41.17 + 41.18 +You should have received a copy of the GNU General Public License along with 41.19 +this program. If not, see <http://www.gnu.org/licenses/>. 41.20 +*/ 41.21 + 41.22 +#ifndef __NATIVE_INT_H__ 41.23 +#define __NATIVE_INT_H__ 41.24 + 41.25 +#include "types.h" 41.26 + 41.27 +/* Integer operations. */ 41.28 + 41.29 +__attr __fn_native_int_int_add(__attr __args[]); 41.30 +__attr __fn_native_int_int_div(__attr __args[]); 41.31 +__attr __fn_native_int_int_mod(__attr __args[]); 41.32 +__attr __fn_native_int_int_mul(__attr __args[]); 41.33 +__attr __fn_native_int_int_neg(__attr __args[]); 41.34 +__attr __fn_native_int_int_pow(__attr __args[]); 41.35 +__attr __fn_native_int_int_sub(__attr __args[]); 41.36 + 41.37 +__attr __fn_native_int_int_and(__attr __args[]); 41.38 +__attr __fn_native_int_int_not(__attr __args[]); 41.39 +__attr __fn_native_int_int_or(__attr __args[]); 41.40 +__attr __fn_native_int_int_xor(__attr __args[]); 41.41 + 41.42 +__attr __fn_native_int_int_rdiv(__attr __args[]); 41.43 +__attr __fn_native_int_int_rmod(__attr __args[]); 41.44 +__attr __fn_native_int_int_rpow(__attr __args[]); 41.45 +__attr __fn_native_int_int_rsub(__attr __args[]); 41.46 + 41.47 +__attr __fn_native_int_int_lt(__attr __args[]); 41.48 +__attr __fn_native_int_int_gt(__attr __args[]); 41.49 +__attr __fn_native_int_int_eq(__attr __args[]); 41.50 +__attr __fn_native_int_int_ne(__attr __args[]); 41.51 + 41.52 +__attr __fn_native_int_int_str(__attr __args[]); 41.53 + 41.54 +/* Module initialisation. */ 41.55 + 41.56 +void __main_native_int(); 41.57 + 41.58 +#endif /* __NATIVE_INT_H__ */
42.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 42.2 +++ b/templates/native/introspection.c Fri Dec 09 16:22:37 2016 +0100 42.3 @@ -0,0 +1,72 @@ 42.4 +/* Native functions for introspection operations. 42.5 + 42.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 42.7 + 42.8 +This program is free software; you can redistribute it and/or modify it under 42.9 +the terms of the GNU General Public License as published by the Free Software 42.10 +Foundation; either version 3 of the License, or (at your option) any later 42.11 +version. 42.12 + 42.13 +This program is distributed in the hope that it will be useful, but WITHOUT 42.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 42.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 42.16 +details. 42.17 + 42.18 +You should have received a copy of the GNU General Public License along with 42.19 +this program. If not, see <http://www.gnu.org/licenses/>. 42.20 +*/ 42.21 + 42.22 +#include "types.h" 42.23 +#include "exceptions.h" 42.24 +#include "ops.h" 42.25 +#include "progconsts.h" 42.26 +#include "progops.h" 42.27 +#include "progtypes.h" 42.28 +#include "main.h" 42.29 + 42.30 +/* Introspection. */ 42.31 + 42.32 +__attr __fn_native_introspection_object_getattr(__attr __args[]) 42.33 +{ 42.34 + __attr * const obj = &__args[1]; 42.35 + __attr * const name = &__args[2]; 42.36 + __attr * const _default = &__args[3]; 42.37 + 42.38 + /* NOTE: To be written. */ 42.39 + return __builtins___none_None; 42.40 +} 42.41 + 42.42 +static int __issubclass(__ref obj, __attr cls) 42.43 +{ 42.44 + return (__HASATTR(obj, __TYPEPOS(cls.value), __TYPECODE(cls.value))); 42.45 +} 42.46 + 42.47 +__attr __fn_native_introspection_isinstance(__attr __args[]) 42.48 +{ 42.49 + __attr * const obj = &__args[1]; 42.50 + __attr * const cls = &__args[2]; 42.51 + 42.52 + /* cls must be a class. */ 42.53 + if (__is_instance(obj->value) && __issubclass(__get_class(obj->value), *cls)) 42.54 + return __builtins___boolean_True; 42.55 + else 42.56 + return __builtins___boolean_False; 42.57 +} 42.58 + 42.59 +__attr __fn_native_introspection_issubclass(__attr __args[]) 42.60 +{ 42.61 + __attr * const obj = &__args[1]; 42.62 + __attr * const cls = &__args[2]; 42.63 + 42.64 + /* obj and cls must be classes. */ 42.65 + if (__issubclass(obj->value, *cls)) 42.66 + return __builtins___boolean_True; 42.67 + else 42.68 + return __builtins___boolean_False; 42.69 +} 42.70 + 42.71 +/* Module initialisation. */ 42.72 + 42.73 +void __main_native_introspection() 42.74 +{ 42.75 +}
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 43.2 +++ b/templates/native/introspection.h Fri Dec 09 16:22:37 2016 +0100 43.3 @@ -0,0 +1,34 @@ 43.4 +/* Native functions for introspection. 43.5 + 43.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 43.7 + 43.8 +This program is free software; you can redistribute it and/or modify it under 43.9 +the terms of the GNU General Public License as published by the Free Software 43.10 +Foundation; either version 3 of the License, or (at your option) any later 43.11 +version. 43.12 + 43.13 +This program is distributed in the hope that it will be useful, but WITHOUT 43.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 43.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 43.16 +details. 43.17 + 43.18 +You should have received a copy of the GNU General Public License along with 43.19 +this program. If not, see <http://www.gnu.org/licenses/>. 43.20 +*/ 43.21 + 43.22 +#ifndef __NATIVE_INTROSPECTION_H__ 43.23 +#define __NATIVE_INTROSPECTION_H__ 43.24 + 43.25 +#include "types.h" 43.26 + 43.27 +/* Introspection. */ 43.28 + 43.29 +__attr __fn_native_introspection_object_getattr(__attr __args[]); 43.30 +__attr __fn_native_introspection_isinstance(__attr __args[]); 43.31 +__attr __fn_native_introspection_issubclass(__attr __args[]); 43.32 + 43.33 +/* Module initialisation. */ 43.34 + 43.35 +void __main_native_introspection(); 43.36 + 43.37 +#endif /* __NATIVE_INTROSPECTION_H__ */
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 44.2 +++ b/templates/native/io.c Fri Dec 09 16:22:37 2016 +0100 44.3 @@ -0,0 +1,219 @@ 44.4 +/* Native functions for input/output. 44.5 + 44.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 44.7 + 44.8 +This program is free software; you can redistribute it and/or modify it under 44.9 +the terms of the GNU General Public License as published by the Free Software 44.10 +Foundation; either version 3 of the License, or (at your option) any later 44.11 +version. 44.12 + 44.13 +This program is distributed in the hope that it will be useful, but WITHOUT 44.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 44.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 44.16 +details. 44.17 + 44.18 +You should have received a copy of the GNU General Public License along with 44.19 +this program. If not, see <http://www.gnu.org/licenses/>. 44.20 +*/ 44.21 + 44.22 +#include <unistd.h> /* read, write */ 44.23 +#include <string.h> /* strcmp, strncpy, strlen */ 44.24 +#include <stdio.h> /* fdopen, snprintf */ 44.25 +#include <errno.h> /* errno */ 44.26 +#include "native/common.h" 44.27 +#include "types.h" 44.28 +#include "exceptions.h" 44.29 +#include "ops.h" 44.30 +#include "progconsts.h" 44.31 +#include "progops.h" 44.32 +#include "progtypes.h" 44.33 +#include "main.h" 44.34 + 44.35 +/* Input/output. */ 44.36 + 44.37 +__attr __fn_native_io_fclose(__attr __args[]) 44.38 +{ 44.39 + __attr * const fp = &__args[1]; 44.40 + /* fp interpreted as FILE reference */ 44.41 + FILE *f = (FILE *) fp->datavalue; 44.42 + 44.43 + errno = 0; 44.44 + if (fclose(f)) 44.45 + __raise_io_error(__new_int(errno)); 44.46 + 44.47 + return __builtins___none_None; 44.48 +} 44.49 + 44.50 +__attr __fn_native_io_fopen(__attr __args[]) 44.51 +{ 44.52 + __attr * const filename = &__args[1]; 44.53 + __attr * const mode = &__args[2]; 44.54 + /* filename.__data__ interpreted as string */ 44.55 + char *fn = __load_via_object(filename->value, __pos___data__).strvalue; 44.56 + /* mode.__data__ interpreted as string */ 44.57 + char *s = __load_via_object(mode->value, __pos___data__).strvalue; 44.58 + FILE *f; 44.59 + __attr attr; 44.60 + 44.61 + errno = 0; 44.62 + f = fopen(fn, s); 44.63 + 44.64 + /* Produce an exception if the operation failed. */ 44.65 + 44.66 + if (f == NULL) 44.67 + __raise_io_error(__new_int(errno)); 44.68 + 44.69 + /* Return the __data__ attribute. */ 44.70 + 44.71 + else 44.72 + { 44.73 + attr.context = 0; 44.74 + attr.datavalue = (void *) f; 44.75 + return attr; 44.76 + } 44.77 +} 44.78 + 44.79 +__attr __fn_native_io_fdopen(__attr __args[]) 44.80 +{ 44.81 + __attr * const fd = &__args[1]; 44.82 + __attr * const mode = &__args[2]; 44.83 + /* fd.__data__ interpreted as int */ 44.84 + int i = __load_via_object(fd->value, __pos___data__).intvalue; 44.85 + /* mode.__data__ interpreted as string */ 44.86 + char *s = __load_via_object(mode->value, __pos___data__).strvalue; 44.87 + FILE *f; 44.88 + __attr attr; 44.89 + 44.90 + errno = 0; 44.91 + f = fdopen(i, s); 44.92 + 44.93 + /* Produce an exception if the operation failed. */ 44.94 + 44.95 + if (f == NULL) 44.96 + __raise_io_error(__new_int(errno)); 44.97 + 44.98 + /* Return the __data__ attribute. */ 44.99 + 44.100 + else 44.101 + { 44.102 + attr.context = 0; 44.103 + attr.datavalue = (void *) f; 44.104 + return attr; 44.105 + } 44.106 +} 44.107 + 44.108 +__attr __fn_native_io_fread(__attr __args[]) 44.109 +{ 44.110 + __attr * const fp = &__args[1]; 44.111 + __attr * const size = &__args[2]; 44.112 + /* fp interpreted as FILE reference */ 44.113 + FILE *f = (FILE *) fp->datavalue; 44.114 + /* size.__data__ interpreted as int */ 44.115 + int to_read = __load_via_object(size->value, __pos___data__).intvalue; 44.116 + char buf[to_read]; 44.117 + size_t have_read; 44.118 + int error; 44.119 + char *s; 44.120 + 44.121 + have_read = fread(buf, sizeof(char), to_read, f); 44.122 + 44.123 + if (have_read != to_read) 44.124 + { 44.125 + if (feof(f) && (have_read == 0)) 44.126 + __raise_eof_error(); 44.127 + else if (error = ferror(f)) 44.128 + __raise_io_error(__new_int(error)); 44.129 + } 44.130 + 44.131 + /* Reserve space for a new string. */ 44.132 + 44.133 + s = __ALLOCATE(have_read + 1, sizeof(char)); 44.134 + strncpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */ 44.135 + return __new_str(s); 44.136 +} 44.137 + 44.138 +__attr __fn_native_io_fwrite(__attr __args[]) 44.139 +{ 44.140 + __attr * const fp = &__args[1]; 44.141 + __attr * const str = &__args[2]; 44.142 + /* fp interpreted as FILE reference */ 44.143 + FILE *f = (FILE *) fp->datavalue; 44.144 + /* str.__data__ interpreted as string */ 44.145 + char *s = __load_via_object(str->value, __pos___data__).strvalue; 44.146 + size_t to_write = strlen(s); 44.147 + size_t have_written = fwrite(s, sizeof(char), to_write, f); 44.148 + int error; 44.149 + 44.150 + if (have_written != to_write) 44.151 + { 44.152 + if (feof(f)) 44.153 + __raise_eof_error(); 44.154 + else if (error = ferror(f)) 44.155 + __raise_io_error(__new_int(error)); 44.156 + } 44.157 + 44.158 + return __builtins___none_None; 44.159 +} 44.160 + 44.161 +__attr __fn_native_io_close(__attr __args[]) 44.162 +{ 44.163 + __attr * const fd = &__args[1]; 44.164 + /* fd.__data__ interpreted as int */ 44.165 + int i = __load_via_object(fd->value, __pos___data__).intvalue; 44.166 + 44.167 + errno = 0; 44.168 + if (close(i) == -1) 44.169 + __raise_io_error(__new_int(errno)); 44.170 + 44.171 + return __builtins___none_None; 44.172 +} 44.173 + 44.174 +__attr __fn_native_io_read(__attr __args[]) 44.175 +{ 44.176 + __attr * const fd = &__args[1]; 44.177 + __attr * const n = &__args[2]; 44.178 + /* fd.__data__ interpreted as int */ 44.179 + int i = __load_via_object(fd->value, __pos___data__).intvalue; 44.180 + /* n.__data__ interpreted as int */ 44.181 + int to_read = __load_via_object(n->value, __pos___data__).intvalue; 44.182 + char buf[to_read]; 44.183 + ssize_t have_read; 44.184 + char *s; 44.185 + 44.186 + errno = 0; 44.187 + have_read = read(i, buf, to_read * sizeof(char)); 44.188 + 44.189 + if (have_read == -1) 44.190 + __raise_io_error(__new_int(errno)); 44.191 + 44.192 + /* Reserve space for a new string. */ 44.193 + 44.194 + s = __ALLOCATE(have_read + 1, 1); 44.195 + strncpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */ 44.196 + return __new_str(s); 44.197 +} 44.198 + 44.199 +__attr __fn_native_io_write(__attr __args[]) 44.200 +{ 44.201 + __attr * const fd = &__args[1]; 44.202 + __attr * const str = &__args[2]; 44.203 + /* fd.__data__ interpreted as int */ 44.204 + int i = __load_via_object(fd->value, __pos___data__).intvalue; 44.205 + /* str.__data__ interpreted as string */ 44.206 + char *s = __load_via_object(str->value, __pos___data__).strvalue; 44.207 + ssize_t have_written; 44.208 + 44.209 + errno = 0; 44.210 + have_written = write(i, s, sizeof(char) * strlen(s)); 44.211 + 44.212 + if (have_written == -1) 44.213 + __raise_io_error(__new_int(errno)); 44.214 + 44.215 + return __new_int(have_written); 44.216 +} 44.217 + 44.218 +/* Module initialisation. */ 44.219 + 44.220 +void __main_native_io() 44.221 +{ 44.222 +}
45.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 45.2 +++ b/templates/native/io.h Fri Dec 09 16:22:37 2016 +0100 45.3 @@ -0,0 +1,39 @@ 45.4 +/* Native functions for input/output. 45.5 + 45.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 45.7 + 45.8 +This program is free software; you can redistribute it and/or modify it under 45.9 +the terms of the GNU General Public License as published by the Free Software 45.10 +Foundation; either version 3 of the License, or (at your option) any later 45.11 +version. 45.12 + 45.13 +This program is distributed in the hope that it will be useful, but WITHOUT 45.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 45.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 45.16 +details. 45.17 + 45.18 +You should have received a copy of the GNU General Public License along with 45.19 +this program. If not, see <http://www.gnu.org/licenses/>. 45.20 +*/ 45.21 + 45.22 +#ifndef __NATIVE_IO_H__ 45.23 +#define __NATIVE_IO_H__ 45.24 + 45.25 +#include "types.h" 45.26 + 45.27 +/* Input/output. */ 45.28 + 45.29 +__attr __fn_native_io_fclose(__attr __args[]); 45.30 +__attr __fn_native_io_fopen(__attr __args[]); 45.31 +__attr __fn_native_io_fdopen(__attr __args[]); 45.32 +__attr __fn_native_io_fread(__attr __args[]); 45.33 +__attr __fn_native_io_fwrite(__attr __args[]); 45.34 +__attr __fn_native_io_close(__attr __args[]); 45.35 +__attr __fn_native_io_read(__attr __args[]); 45.36 +__attr __fn_native_io_write(__attr __args[]); 45.37 + 45.38 +/* Module initialisation. */ 45.39 + 45.40 +void __main_native_io(); 45.41 + 45.42 +#endif /* __NATIVE_IO_H__ */
46.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 46.2 +++ b/templates/native/limits.c Fri Dec 09 16:22:37 2016 +0100 46.3 @@ -0,0 +1,49 @@ 46.4 +/* Native functions for limit definition. 46.5 + 46.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 46.7 + 46.8 +This program is free software; you can redistribute it and/or modify it under 46.9 +the terms of the GNU General Public License as published by the Free Software 46.10 +Foundation; either version 3 of the License, or (at your option) any later 46.11 +version. 46.12 + 46.13 +This program is distributed in the hope that it will be useful, but WITHOUT 46.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 46.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 46.16 +details. 46.17 + 46.18 +You should have received a copy of the GNU General Public License along with 46.19 +this program. If not, see <http://www.gnu.org/licenses/>. 46.20 +*/ 46.21 + 46.22 +#include <limits.h> /* INT_MAX, INT_MIN */ 46.23 +#include "native/common.h" 46.24 +#include "types.h" 46.25 +#include "exceptions.h" 46.26 +#include "ops.h" 46.27 +#include "progconsts.h" 46.28 +#include "progops.h" 46.29 +#include "progtypes.h" 46.30 +#include "main.h" 46.31 + 46.32 +/* Limit definition. */ 46.33 + 46.34 +__attr __fn_native_limits_get_maxint(__attr __args[]) 46.35 +{ 46.36 + __attr * const status = &__args[1]; 46.37 + 46.38 + return __new_int(INT_MAX); 46.39 +} 46.40 + 46.41 +__attr __fn_native_limits_get_minint(__attr __args[]) 46.42 +{ 46.43 + __attr * const status = &__args[1]; 46.44 + 46.45 + return __new_int(INT_MIN); 46.46 +} 46.47 + 46.48 +/* Module initialisation. */ 46.49 + 46.50 +void __main_native_limits() 46.51 +{ 46.52 +}
47.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 47.2 +++ b/templates/native/limits.h Fri Dec 09 16:22:37 2016 +0100 47.3 @@ -0,0 +1,33 @@ 47.4 +/* Native functions for limit definition. 47.5 + 47.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 47.7 + 47.8 +This program is free software; you can redistribute it and/or modify it under 47.9 +the terms of the GNU General Public License as published by the Free Software 47.10 +Foundation; either version 3 of the License, or (at your option) any later 47.11 +version. 47.12 + 47.13 +This program is distributed in the hope that it will be useful, but WITHOUT 47.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 47.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 47.16 +details. 47.17 + 47.18 +You should have received a copy of the GNU General Public License along with 47.19 +this program. If not, see <http://www.gnu.org/licenses/>. 47.20 +*/ 47.21 + 47.22 +#ifndef __NATIVE_LIMITS_H__ 47.23 +#define __NATIVE_LIMITS_H__ 47.24 + 47.25 +#include "types.h" 47.26 + 47.27 +/* Limit definition. */ 47.28 + 47.29 +__attr __fn_native_limits_get_maxint(__attr __args[]); 47.30 +__attr __fn_native_limits_get_minint(__attr __args[]); 47.31 + 47.32 +/* Module initialisation. */ 47.33 + 47.34 +void __main_native_limits(); 47.35 + 47.36 +#endif /* __NATIVE_LIMITS_H__ */
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/templates/native/list.c Fri Dec 09 16:22:37 2016 +0100 48.3 @@ -0,0 +1,147 @@ 48.4 +/* Native functions for list operations. 48.5 + 48.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 48.7 + 48.8 +This program is free software; you can redistribute it and/or modify it under 48.9 +the terms of the GNU General Public License as published by the Free Software 48.10 +Foundation; either version 3 of the License, or (at your option) any later 48.11 +version. 48.12 + 48.13 +This program is distributed in the hope that it will be useful, but WITHOUT 48.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 48.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 48.16 +details. 48.17 + 48.18 +You should have received a copy of the GNU General Public License along with 48.19 +this program. If not, see <http://www.gnu.org/licenses/>. 48.20 +*/ 48.21 + 48.22 +#include "native/common.h" 48.23 +#include "types.h" 48.24 +#include "exceptions.h" 48.25 +#include "ops.h" 48.26 +#include "progconsts.h" 48.27 +#include "progops.h" 48.28 +#include "progtypes.h" 48.29 +#include "main.h" 48.30 + 48.31 +/* List operations. */ 48.32 + 48.33 +__attr __fn_native_list_list_init(__attr __args[]) 48.34 +{ 48.35 + __attr * const size = &__args[1]; 48.36 + /* size.__data__ interpreted as int */ 48.37 + unsigned int n = __load_via_object(size->value, __pos___data__).intvalue; 48.38 + __attr attr = {0, .seqvalue=__new_fragment(n)}; 48.39 + 48.40 + /* Return the __data__ attribute. */ 48.41 + return attr; 48.42 +} 48.43 + 48.44 +__attr __fn_native_list_list_setsize(__attr __args[]) 48.45 +{ 48.46 + __attr * const _data = &__args[1]; 48.47 + __attr * const size = &__args[2]; 48.48 + /* _data interpreted as list */ 48.49 + __fragment *data = _data->seqvalue; 48.50 + /* size.__data__ interpreted as int */ 48.51 + unsigned int n = __load_via_object(size->value, __pos___data__).intvalue; 48.52 + 48.53 + data->size = n; 48.54 + return __builtins___none_None; 48.55 +} 48.56 + 48.57 +__attr __fn_native_list_list_append(__attr __args[]) 48.58 +{ 48.59 + __attr * const self = &__args[1]; 48.60 + __attr * const value = &__args[2]; 48.61 + /* self.__data__ interpreted as list */ 48.62 + __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; 48.63 + __fragment *newdata = __fragment_append(data, value); 48.64 + 48.65 + /* Replace the __data__ attribute if appropriate. */ 48.66 + if (newdata != data) 48.67 + __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); 48.68 + return __builtins___none_None; 48.69 +} 48.70 + 48.71 +__attr __fn_native_list_list_concat(__attr __args[]) 48.72 +{ 48.73 + __attr * const self = &__args[1]; 48.74 + __attr * const other = &__args[2]; 48.75 + /* self.__data__, other interpreted as list */ 48.76 + __fragment *data = __load_via_object(self->value, __pos___data__).seqvalue; 48.77 + __fragment *other_data = other->seqvalue; 48.78 + __fragment *newdata = data; 48.79 + unsigned int size = data->size, capacity = data->capacity; 48.80 + unsigned int other_size = other_data->size; 48.81 + unsigned int i, j, n; 48.82 + 48.83 + /* Re-allocate the fragment if the capacity has been reached. */ 48.84 + if (size + other_size >= capacity) 48.85 + { 48.86 + n = size + other_size; 48.87 + newdata = (__fragment *) __REALLOCATE(data, __FRAGMENT_SIZE(n)); 48.88 + newdata->capacity = n; 48.89 + } 48.90 + 48.91 + /* Copy the elements from the other list and increment the list size. */ 48.92 + for (i = size, j = 0; j < other_size; i++, j++) 48.93 + newdata->attrs[i] = other_data->attrs[j]; 48.94 + newdata->size = n; 48.95 + 48.96 + /* Replace the __data__ attribute if appropriate. */ 48.97 + if (newdata != data) 48.98 + __store_via_object(self->value, __pos___data__, ((__attr) {0, .seqvalue=newdata})); 48.99 + return __builtins___none_None; 48.100 +} 48.101 + 48.102 +__attr __fn_native_list_list_len(__attr __args[]) 48.103 +{ 48.104 + __attr * const _data = &__args[1]; 48.105 + /* _data interpreted as fragment */ 48.106 + unsigned int size = _data->seqvalue->size; 48.107 + 48.108 + /* Return the new integer. */ 48.109 + return __new_int(size); 48.110 +} 48.111 + 48.112 +__attr __fn_native_list_list_nonempty(__attr __args[]) 48.113 +{ 48.114 + __attr * const _data = &__args[1]; 48.115 + 48.116 + return _data->seqvalue->size ? __builtins___boolean_True : __builtins___boolean_False; 48.117 +} 48.118 + 48.119 +__attr __fn_native_list_list_element(__attr __args[]) 48.120 +{ 48.121 + __attr * const _data = &__args[1]; 48.122 + __attr * const index = &__args[2]; 48.123 + /* _data interpreted as fragment */ 48.124 + __attr *elements = _data->seqvalue->attrs; 48.125 + /* index.__data__ interpreted as int */ 48.126 + int i = __load_via_object(index->value, __pos___data__).intvalue; 48.127 + 48.128 + return elements[i]; 48.129 +} 48.130 + 48.131 +__attr __fn_native_list_list_setelement(__attr __args[]) 48.132 +{ 48.133 + __attr * const _data = &__args[1]; 48.134 + __attr * const index = &__args[2]; 48.135 + __attr * const value = &__args[3]; 48.136 + /* _data interpreted as fragment */ 48.137 + __attr *elements = _data->seqvalue->attrs; 48.138 + /* index.__data__ interpreted as int */ 48.139 + int i = __load_via_object(index->value, __pos___data__).intvalue; 48.140 + 48.141 + /* Set the element. */ 48.142 + elements[i] = *value; 48.143 + return __builtins___none_None; 48.144 +} 48.145 + 48.146 +/* Module initialisation. */ 48.147 + 48.148 +void __main_native_list() 48.149 +{ 48.150 +}
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/templates/native/list.h Fri Dec 09 16:22:37 2016 +0100 49.3 @@ -0,0 +1,39 @@ 49.4 +/* Native functions for list operations. 49.5 + 49.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 49.7 + 49.8 +This program is free software; you can redistribute it and/or modify it under 49.9 +the terms of the GNU General Public License as published by the Free Software 49.10 +Foundation; either version 3 of the License, or (at your option) any later 49.11 +version. 49.12 + 49.13 +This program is distributed in the hope that it will be useful, but WITHOUT 49.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 49.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 49.16 +details. 49.17 + 49.18 +You should have received a copy of the GNU General Public License along with 49.19 +this program. If not, see <http://www.gnu.org/licenses/>. 49.20 +*/ 49.21 + 49.22 +#ifndef __NATIVE_LIST_H__ 49.23 +#define __NATIVE_LIST_H__ 49.24 + 49.25 +#include "types.h" 49.26 + 49.27 +/* List operations. */ 49.28 + 49.29 +__attr __fn_native_list_list_init(__attr __args[]); 49.30 +__attr __fn_native_list_list_setsize(__attr __args[]); 49.31 +__attr __fn_native_list_list_append(__attr __args[]); 49.32 +__attr __fn_native_list_list_concat(__attr __args[]); 49.33 +__attr __fn_native_list_list_len(__attr __args[]); 49.34 +__attr __fn_native_list_list_nonempty(__attr __args[]); 49.35 +__attr __fn_native_list_list_element(__attr __args[]); 49.36 +__attr __fn_native_list_list_setelement(__attr __args[]); 49.37 + 49.38 +/* Module initialisation. */ 49.39 + 49.40 +void __main_native_list(); 49.41 + 49.42 +#endif /* __NATIVE_LIST_H__ */
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/templates/native/program.c Fri Dec 09 16:22:37 2016 +0100 50.3 @@ -0,0 +1,41 @@ 50.4 +/* Native functions for program operations. 50.5 + 50.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 50.7 + 50.8 +This program is free software; you can redistribute it and/or modify it under 50.9 +the terms of the GNU General Public License as published by the Free Software 50.10 +Foundation; either version 3 of the License, or (at your option) any later 50.11 +version. 50.12 + 50.13 +This program is distributed in the hope that it will be useful, but WITHOUT 50.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 50.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 50.16 +details. 50.17 + 50.18 +You should have received a copy of the GNU General Public License along with 50.19 +this program. If not, see <http://www.gnu.org/licenses/>. 50.20 +*/ 50.21 + 50.22 +#include "types.h" 50.23 +#include "exceptions.h" 50.24 +#include "ops.h" 50.25 +#include "progconsts.h" 50.26 +#include "progops.h" 50.27 +#include "progtypes.h" 50.28 +#include "main.h" 50.29 + 50.30 +/* Method binding. */ 50.31 + 50.32 +__attr __fn_native_program_get_using(__attr __args[]) 50.33 +{ 50.34 + __attr * const callable = &__args[1]; 50.35 + __attr * const instance = &__args[2]; 50.36 + 50.37 + return __replace_context(instance->value, *callable); 50.38 +} 50.39 + 50.40 +/* Module initialisation. */ 50.41 + 50.42 +void __main_native_program() 50.43 +{ 50.44 +}
51.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 51.2 +++ b/templates/native/program.h Fri Dec 09 16:22:37 2016 +0100 51.3 @@ -0,0 +1,30 @@ 51.4 +/* Native functions for program operations. 51.5 + 51.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 51.7 + 51.8 +This program is free software; you can redistribute it and/or modify it under 51.9 +the terms of the GNU General Public License as published by the Free Software 51.10 +Foundation; either version 3 of the License, or (at your option) any later 51.11 +version. 51.12 + 51.13 +This program is distributed in the hope that it will be useful, but WITHOUT 51.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 51.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 51.16 +details. 51.17 + 51.18 +You should have received a copy of the GNU General Public License along with 51.19 +this program. If not, see <http://www.gnu.org/licenses/>. 51.20 +*/ 51.21 + 51.22 +#ifndef __NATIVE_PROGRAM_H__ 51.23 +#define __NATIVE_PROGRAM_H__ 51.24 + 51.25 +/* Method binding. */ 51.26 + 51.27 +__attr __fn_native_program_get_using(__attr __args[]); 51.28 + 51.29 +/* Module initialisation. */ 51.30 + 51.31 +void __main_native_program(); 51.32 + 51.33 +#endif /* __NATIVE_PROGRAM_H__ */
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 52.2 +++ b/templates/native/str.c Fri Dec 09 16:22:37 2016 +0100 52.3 @@ -0,0 +1,134 @@ 52.4 +/* Native functions for string operations. 52.5 + 52.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 52.7 + 52.8 +This program is free software; you can redistribute it and/or modify it under 52.9 +the terms of the GNU General Public License as published by the Free Software 52.10 +Foundation; either version 3 of the License, or (at your option) any later 52.11 +version. 52.12 + 52.13 +This program is distributed in the hope that it will be useful, but WITHOUT 52.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 52.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 52.16 +details. 52.17 + 52.18 +You should have received a copy of the GNU General Public License along with 52.19 +this program. If not, see <http://www.gnu.org/licenses/>. 52.20 +*/ 52.21 + 52.22 +#include <string.h> /* strcmp, strncpy, strlen */ 52.23 +#include "native/common.h" 52.24 +#include "types.h" 52.25 +#include "exceptions.h" 52.26 +#include "ops.h" 52.27 +#include "progconsts.h" 52.28 +#include "progops.h" 52.29 +#include "progtypes.h" 52.30 +#include "main.h" 52.31 + 52.32 +/* String operations. */ 52.33 + 52.34 +__attr __fn_native_str_str_add(__attr __args[]) 52.35 +{ 52.36 + __attr * const _data = &__args[1]; 52.37 + __attr * const other = &__args[2]; 52.38 + /* _data, other interpreted as string */ 52.39 + char *s = _data->strvalue; 52.40 + char *o = other->strvalue; 52.41 + int n = strlen(s) + strlen(o) + 1; 52.42 + char *r = (char *) __ALLOCATE(n, sizeof(char)); 52.43 + 52.44 + strncpy(r, s, n); 52.45 + strncpy(r + strlen(s), o, n - strlen(s)); /* should null terminate */ 52.46 + 52.47 + /* Return a new string. */ 52.48 + return __new_str(r); 52.49 +} 52.50 + 52.51 +__attr __fn_native_str_str_lt(__attr __args[]) 52.52 +{ 52.53 + __attr * const _data = &__args[1]; 52.54 + __attr * const other = &__args[2]; 52.55 + /* _data, other interpreted as string */ 52.56 + char *s = _data->strvalue; 52.57 + char *o = other->strvalue; 52.58 + 52.59 + /* NOTE: Using simple byte-level string operations. */ 52.60 + return strcmp(s, o) < 0 ? __builtins___boolean_True : __builtins___boolean_False; 52.61 +} 52.62 + 52.63 +__attr __fn_native_str_str_gt(__attr __args[]) 52.64 +{ 52.65 + __attr * const _data = &__args[1]; 52.66 + __attr * const other = &__args[2]; 52.67 + /* _data, other interpreted as string */ 52.68 + char *s = _data->strvalue; 52.69 + char *o = other->strvalue; 52.70 + 52.71 + /* NOTE: Using simple byte-level string operations. */ 52.72 + return strcmp(s, o) > 0 ? __builtins___boolean_True : __builtins___boolean_False; 52.73 +} 52.74 + 52.75 +__attr __fn_native_str_str_eq(__attr __args[]) 52.76 +{ 52.77 + __attr * const _data = &__args[1]; 52.78 + __attr * const other = &__args[2]; 52.79 + /* _data, other interpreted as string */ 52.80 + char *s = _data->strvalue; 52.81 + char *o = other->strvalue; 52.82 + 52.83 + /* NOTE: Using simple byte-level string operations. */ 52.84 + return strcmp(s, o) == 0 ? __builtins___boolean_True : __builtins___boolean_False; 52.85 +} 52.86 + 52.87 +__attr __fn_native_str_str_len(__attr __args[]) 52.88 +{ 52.89 + __attr * const _data = &__args[1]; 52.90 + /* _data interpreted as string */ 52.91 + char *s = _data->strvalue; 52.92 + 52.93 + /* Return the new integer. */ 52.94 + return __new_int(strlen(s)); 52.95 +} 52.96 + 52.97 +__attr __fn_native_str_str_nonempty(__attr __args[]) 52.98 +{ 52.99 + __attr * const _data = &__args[1]; 52.100 + /* _data interpreted as string */ 52.101 + char *s = _data->strvalue; 52.102 + 52.103 + return strlen(s) ? __builtins___boolean_True : __builtins___boolean_False; 52.104 +} 52.105 + 52.106 +__attr __fn_native_str_str_ord(__attr __args[]) 52.107 +{ 52.108 + __attr * const _data = &__args[1]; 52.109 + /* _data interpreted as string */ 52.110 + char *s = _data->strvalue; 52.111 + 52.112 + return __new_int((unsigned int) s[0]); 52.113 +} 52.114 + 52.115 +__attr __fn_native_str_str_substr(__attr __args[]) 52.116 +{ 52.117 + __attr * const _data = &__args[1]; 52.118 + __attr * const start = &__args[2]; 52.119 + __attr * const size = &__args[3]; 52.120 + /* _data interpreted as string */ 52.121 + char *s = _data->strvalue, *sub; 52.122 + /* start.__data__ interpreted as int */ 52.123 + int i = __load_via_object(start->value, __pos___data__).intvalue; 52.124 + /* size.__data__ interpreted as int */ 52.125 + int l = __load_via_object(size->value, __pos___data__).intvalue; 52.126 + 52.127 + /* Reserve space for a new string. */ 52.128 + sub = (char *) __ALLOCATE(l + 1, sizeof(char)); 52.129 + strncpy(sub, s + i, l); /* does not null terminate but final byte should be zero */ 52.130 + return __new_str(sub); 52.131 +} 52.132 + 52.133 +/* Module initialisation. */ 52.134 + 52.135 +void __main_native_str() 52.136 +{ 52.137 +}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/templates/native/str.h Fri Dec 09 16:22:37 2016 +0100 53.3 @@ -0,0 +1,37 @@ 53.4 +/* Native functions for string operations. 53.5 + 53.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 53.7 + 53.8 +This program is free software; you can redistribute it and/or modify it under 53.9 +the terms of the GNU General Public License as published by the Free Software 53.10 +Foundation; either version 3 of the License, or (at your option) any later 53.11 +version. 53.12 + 53.13 +This program is distributed in the hope that it will be useful, but WITHOUT 53.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 53.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 53.16 +details. 53.17 + 53.18 +You should have received a copy of the GNU General Public License along with 53.19 +this program. If not, see <http://www.gnu.org/licenses/>. 53.20 +*/ 53.21 + 53.22 +#ifndef __NATIVE_STR_H__ 53.23 +#define __NATIVE_STR_H__ 53.24 + 53.25 +/* String operations. */ 53.26 + 53.27 +__attr __fn_native_str_str_add(__attr __args[]); 53.28 +__attr __fn_native_str_str_lt(__attr __args[]); 53.29 +__attr __fn_native_str_str_gt(__attr __args[]); 53.30 +__attr __fn_native_str_str_eq(__attr __args[]); 53.31 +__attr __fn_native_str_str_len(__attr __args[]); 53.32 +__attr __fn_native_str_str_nonempty(__attr __args[]); 53.33 +__attr __fn_native_str_str_ord(__attr __args[]); 53.34 +__attr __fn_native_str_str_substr(__attr __args[]); 53.35 + 53.36 +/* Module initialisation. */ 53.37 + 53.38 +void __main_native_str(); 53.39 + 53.40 +#endif /* __NATIVE_STR_H__ */
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/templates/native/system.c Fri Dec 09 16:22:37 2016 +0100 54.3 @@ -0,0 +1,58 @@ 54.4 +/* Native functions for system operations. 54.5 + 54.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 54.7 + 54.8 +This program is free software; you can redistribute it and/or modify it under 54.9 +the terms of the GNU General Public License as published by the Free Software 54.10 +Foundation; either version 3 of the License, or (at your option) any later 54.11 +version. 54.12 + 54.13 +This program is distributed in the hope that it will be useful, but WITHOUT 54.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 54.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 54.16 +details. 54.17 + 54.18 +You should have received a copy of the GNU General Public License along with 54.19 +this program. If not, see <http://www.gnu.org/licenses/>. 54.20 +*/ 54.21 + 54.22 +#include <stdlib.h> /* abs, exit */ 54.23 +#include "types.h" 54.24 +#include "exceptions.h" 54.25 +#include "ops.h" 54.26 +#include "progconsts.h" 54.27 +#include "progops.h" 54.28 +#include "progtypes.h" 54.29 +#include "main.h" 54.30 + 54.31 +/* Environment support. */ 54.32 + 54.33 +__attr __fn_native_system_exit(__attr __args[]) 54.34 +{ 54.35 + __attr * const status = &__args[1]; 54.36 + 54.37 + exit(__load_via_object(status->value, __pos___data__).intvalue); 54.38 + return __builtins___none_None; 54.39 +} 54.40 + 54.41 +__attr __fn_native_system_get_argv(__attr __args[]) 54.42 +{ 54.43 + __attr * const status = &__args[1]; 54.44 + 54.45 + /* NOTE: To be written. */ 54.46 + return __builtins___none_None; 54.47 +} 54.48 + 54.49 +__attr __fn_native_system_get_path(__attr __args[]) 54.50 +{ 54.51 + __attr * const status = &__args[1]; 54.52 + 54.53 + /* NOTE: To be written. */ 54.54 + return __builtins___none_None; 54.55 +} 54.56 + 54.57 +/* Module initialisation. */ 54.58 + 54.59 +void __main_native_system() 54.60 +{ 54.61 +}
55.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 55.2 +++ b/templates/native/system.h Fri Dec 09 16:22:37 2016 +0100 55.3 @@ -0,0 +1,34 @@ 55.4 +/* Native functions for system operations. 55.5 + 55.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> 55.7 + 55.8 +This program is free software; you can redistribute it and/or modify it under 55.9 +the terms of the GNU General Public License as published by the Free Software 55.10 +Foundation; either version 3 of the License, or (at your option) any later 55.11 +version. 55.12 + 55.13 +This program is distributed in the hope that it will be useful, but WITHOUT 55.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 55.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 55.16 +details. 55.17 + 55.18 +You should have received a copy of the GNU General Public License along with 55.19 +this program. If not, see <http://www.gnu.org/licenses/>. 55.20 +*/ 55.21 + 55.22 +#ifndef __NATIVE_SYSTEM_H__ 55.23 +#define __NATIVE_SYSTEM_H__ 55.24 + 55.25 +#include "types.h" 55.26 + 55.27 +/* Environment support. */ 55.28 + 55.29 +__attr __fn_native_system_exit(__attr __args[]); 55.30 +__attr __fn_native_system_get_argv(__attr __args[]); 55.31 +__attr __fn_native_system_get_path(__attr __args[]); 55.32 + 55.33 +/* Module initialisation. */ 55.34 + 55.35 +void __main_native_system(); 55.36 + 55.37 +#endif /* __NATIVE_SYSTEM_H__ */
56.1 --- a/translator.py Fri Dec 09 00:09:01 2016 +0100 56.2 +++ b/translator.py Fri Dec 09 16:22:37 2016 +0100 56.3 @@ -46,7 +46,8 @@ 56.4 self.check_output() 56.5 56.6 for module in self.importer.modules.values(): 56.7 - if module.name != "native": 56.8 + parts = module.name.split(".") 56.9 + if parts[0] != "native": 56.10 tm = TranslatedModule(module.name, self.importer, self.deducer, self.optimiser) 56.11 tm.translate(module.filename, join(output, "%s.c" % module.name)) 56.12 56.13 @@ -1479,7 +1480,7 @@ 56.14 56.15 if name is not None: 56.16 name_ref = self.process_structure_node(name) 56.17 - self.writeline("else if (__BOOL(__fn_native__isinstance((__attr[]) {{0, 0}, __tmp_exc.arg, %s})))" % name_ref) 56.18 + self.writeline("else if (__BOOL(__fn_native_introspection_isinstance((__attr[]) {{0, 0}, __tmp_exc.arg, %s})))" % name_ref) 56.19 else: 56.20 self.writeline("else if (1)") 56.21