# HG changeset patch # User Paul Boddie # Date 1481300850 -3600 # Node ID 8327049267bf13f2bed74b4d4b660adb4e99ab56 # Parent 56863815fe7bdd54b4df8ab556247d4a51b359b8 Changed imports to directly access names via the native package. diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/dict.py --- a/lib/__builtins__/dict.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/dict.py Fri Dec 09 17:27:30 2016 +0100 @@ -21,7 +21,7 @@ from __builtins__.iterator import itemiterator from __builtins__.sequence import _max -import native +from native import isinstance as _isinstance class dict: @@ -86,7 +86,7 @@ index = key.__hash__() - if not native.isinstance(index, int): + if not _isinstance(index, int): raise TypeError return index % len(self.buckets) diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/file.py --- a/lib/__builtins__/file.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/file.py Fri Dec 09 17:27:30 2016 +0100 @@ -20,7 +20,7 @@ """ from __builtins__.types import check_int, check_string -import native +from native import fclose, fopen, fread, fwrite class filestream: @@ -42,7 +42,7 @@ # Read any indicated number of bytes. if n > 0: - return native.fread(self.__data__, n) + return fread(self.__data__, n) # Read all remaining bytes. @@ -53,7 +53,7 @@ try: while True: - l.append(native.fread(self.__data__, self.bufsize)) + l.append(fread(self.__data__, self.bufsize)) # Handle end-of-file reads. @@ -67,13 +67,13 @@ "Write string 's' to the stream." check_string(s) - native.fwrite(self.__data__, s) + fwrite(self.__data__, s) def close(self): "Close the stream." - native.fclose(self.__data__) + fclose(self.__data__) class file(filestream): @@ -84,7 +84,7 @@ "Open the file with the given 'filename' using the given access 'mode'." get_using(filestream.__init__, self)(bufsize) - self.__data__ = native.fopen(filename, mode) + self.__data__ = fopen(filename, mode) def readline(self, size=None): pass def readlines(self, size=None): pass diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/identity.py --- a/lib/__builtins__/identity.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/identity.py Fri Dec 09 17:27:30 2016 +0100 @@ -19,7 +19,7 @@ this program. If not, see . """ -import native +from native import isinstance as _isinstance, issubclass as _issubclass def callable(obj): @@ -50,13 +50,13 @@ either a class or a sequence of classes. """ - if native.isinstance(cls_or_tuple, tuple): + if _isinstance(cls_or_tuple, tuple): for cls in cls_or_tuple: - if obj.__class__ is cls or isclass(cls) and native.isinstance(obj, cls): + if obj.__class__ is cls or isclass(cls) and _isinstance(obj, cls): return True return False else: - return obj.__class__ is cls_or_tuple or isclass(cls_or_tuple) and native.isinstance(obj, cls_or_tuple) + return obj.__class__ is cls_or_tuple or isclass(cls_or_tuple) and _isinstance(obj, cls_or_tuple) def issubclass(obj, cls_or_tuple): @@ -68,13 +68,13 @@ if not isclass(obj): return False - elif native.isinstance(cls_or_tuple, tuple): + elif _isinstance(cls_or_tuple, tuple): for cls in cls_or_tuple: - if obj is cls or isclass(cls) and native.issubclass(obj, cls): + if obj is cls or isclass(cls) and _issubclass(obj, cls): return True return False else: - return obj is cls_or_tuple or isclass(cls_or_tuple) and native.issubclass(obj, cls_or_tuple) + return obj is cls_or_tuple or isclass(cls_or_tuple) and _issubclass(obj, cls_or_tuple) def repr(obj): diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/int.py --- a/lib/__builtins__/int.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/int.py Fri Dec 09 17:27:30 2016 +0100 @@ -20,7 +20,10 @@ """ from __builtins__.operator import _negate -import native +from native import isinstance as _isinstance, get_maxint, get_minint, \ + int_add, int_and, int_div, int_eq, int_gt, int_lt, int_mod, \ + int_mul, int_ne, int_neg, int_not, int_or, int_pow, \ + int_str, int_sub, int_xor class int: @@ -30,7 +33,7 @@ "Initialise the integer with the given 'number_or_string'." - if native.isinstance(number_or_string, int): + if _isinstance(number_or_string, int): self.__data__ = number_or_string.__data__ else: # NOTE: To be implemented. @@ -46,7 +49,7 @@ "Perform 'op' on this int and 'other' if appropriate." - if native.isinstance(other, int): + if _isinstance(other, int): return op(self.__data__, other.__data__) else: return NotImplemented @@ -55,7 +58,7 @@ "Perform 'op' on 'other' and this int if appropriate." - if native.isinstance(other, int): + if _isinstance(other, int): return op(other.__data__, self.__data__) else: return NotImplemented @@ -64,61 +67,61 @@ "Return a new int for the addition of this int and 'other'." - return self._binary_op(native.int_add, other) + return self._binary_op(int_add, other) def __isub__(self, other): "Return a new int for the subtraction of this int and 'other'." - return self._binary_op(native.int_sub, other) + return self._binary_op(int_sub, other) def __imul__(self, other): "Return a new int for the multiplication of this int and 'other'." - return self._binary_op(native.int_mul, other) + return self._binary_op(int_mul, other) def __idiv__(self, other): "Return a new int for the division of this int and 'other'." - return self._binary_op(native.int_div, other) + return self._binary_op(int_div, other) def __imod__(self, other): "Return a new int for the modulo of this int by 'other'." - return self._binary_op(native.int_mod, other) + return self._binary_op(int_mod, other) def __ipow__(self, other): "Return a new int for the exponentiation of this int by 'other'." - return self._binary_op(native.int_pow, other) + return self._binary_op(int_pow, other) def __iand__(self, other): "Return a new int for the binary-and of this int and 'other'." - return self._binary_op(native.int_and, other) + return self._binary_op(int_and, other) def __ior__(self, other): "Return a new int for the binary-or of this int and 'other'." - return self._binary_op(native.int_or, other) + return self._binary_op(int_or, other) def __ixor__(self, other): "Return a new int for the exclusive-or of this int and 'other'." - return self._binary_op(native.int_xor, other) + return self._binary_op(int_xor, other) def __invert__(self): "Return the inversion of this int." - return native.int_not(self.__data__) + return int_not(self.__data__) __add__ = __radd__ = __iadd__ __sub__ = __isub__ @@ -127,7 +130,7 @@ "Return a new int for the subtraction of this int from 'other'." - return self._binary_op_rev(native.int_sub, other) + return self._binary_op_rev(int_sub, other) __mul__ = __rmul__ = __imul__ __div__ = __idiv__ @@ -136,7 +139,7 @@ "Return a new int for the division of this int into 'other'." - return self._binary_op_rev(native.int_div, other) + return self._binary_op_rev(int_div, other) def __floordiv__(self, other): pass def __rfloordiv__(self, other): pass @@ -148,7 +151,7 @@ "Return a new int for the modulo of 'other' by this int." - return self._binary_op_rev(native.int_mod, other) + return self._binary_op_rev(int_mod, other) __pow__ = __ipow__ @@ -156,7 +159,7 @@ "Return a new int for the exponentiation of 'other' by this int." - return self._binary_op_rev(native.int_pow, other) + return self._binary_op_rev(int_pow, other) __and__ = __rand__ = __iand__ __or__ = __ror__ = __ior__ @@ -166,13 +169,13 @@ "Return whether this int is less than 'other'." - return self._binary_op(native.int_lt, other) + return self._binary_op(int_lt, other) def __gt__(self, other): "Return whether this int is greater than 'other'." - return self._binary_op(native.int_gt, other) + return self._binary_op(int_gt, other) def __le__(self, other): @@ -190,7 +193,7 @@ "Return whether this int is equal to 'other'." - return self._binary_op(native.int_eq, other) + return self._binary_op(int_eq, other) def __ne__(self, other): @@ -202,7 +205,7 @@ "Apply the unary negation operator." - return native.int_neg(self.__data__) + return int_neg(self.__data__) def __pos__(self): @@ -214,7 +217,7 @@ "Return a string representation." - return native.int_str(self.__data__) + return int_str(self.__data__) __repr__ = __str__ @@ -230,11 +233,11 @@ "Return whether this int is non-zero." zero = 0 - return native.int_ne(self.__data__, zero.__data__) + return int_ne(self.__data__, zero.__data__) # Limits. -maxint = native.get_maxint() -minint = native.get_minint() +maxint = get_maxint() +minint = get_minint() # vim: tabstop=4 expandtab shiftwidth=4 diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/list.py --- a/lib/__builtins__/list.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/list.py Fri Dec 09 17:27:30 2016 +0100 @@ -21,7 +21,8 @@ from __builtins__.iterator import itemiterator from __builtins__.sequence import sequence -import native +from native import list_append, list_concat, list_element, list_init, \ + list_len, list_nonempty, list_setelement class list(sequence): @@ -34,7 +35,7 @@ # Reserve an attribute for a fragment reference along with some space # for elements. - self.__data__ = native.list_init(args is not None and len(args) or 0) + self.__data__ = list_init(args is not None and len(args) or 0) if args is not None: self.extend(args) @@ -47,7 +48,7 @@ "Append 'value' to the list." - native.list_append(self, value) + list_append(self, value) def insert(self, i, value): pass @@ -66,7 +67,7 @@ "Return the length of the list." - return native.list_len(self.__data__) + return list_len(self.__data__) def __add__(self, other): pass @@ -75,7 +76,7 @@ "Concatenate 'other' to the list." if isinstance(other, list): - native.list_concat(self, other.__data__) + list_concat(self, other.__data__) else: self.extend(other) return self @@ -92,7 +93,7 @@ "Lists are true if non-empty." - return native.list_nonempty(self.__data__) + return list_nonempty(self.__data__) def __iter__(self): @@ -107,13 +108,13 @@ "Return the item at the normalised (positive) 'index'." self._check_index(index) - return native.list_element(self.__data__, index) + return list_element(self.__data__, index) def __set_single_item__(self, index, value): "Set at the normalised (positive) 'index' the given 'value'." self._check_index(index) - return native.list_setelement(self.__data__, index, value) + return list_setelement(self.__data__, index, value) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/sequence.py --- a/lib/__builtins__/sequence.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/sequence.py Fri Dec 09 17:27:30 2016 +0100 @@ -19,7 +19,7 @@ this program. If not, see . """ -import native +from native import isinstance as _isinstance class itemaccess: @@ -42,13 +42,13 @@ # Normalise any integer indexes, converting negative indexes to positive # ones. - if native.isinstance(index, int): + if _isinstance(index, int): index = _get_absolute_index(index, self.__len__()) return self.__get_single_item__(index) # Handle slices separately. - elif native.isinstance(index, slice): + elif _isinstance(index, slice): return self.__getslice__(index.start, index.end, index.step) # No other kinds of objects are supported as indexes. @@ -63,13 +63,13 @@ # Normalise any integer indexes, converting negative indexes to positive # ones. - if native.isinstance(index, int): + if _isinstance(index, int): index = _get_absolute_index(index, self.__len__()) return self.__set_single_item__(index, value) # Handle slices separately. - elif native.isinstance(index, slice): + elif _isinstance(index, slice): return self.__setslice__(index.start, index.end, value) # No other kinds of objects are supported as indexes. diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/str.py --- a/lib/__builtins__/str.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/str.py Fri Dec 09 17:27:30 2016 +0100 @@ -22,7 +22,8 @@ from __builtins__.int import maxint, minint from __builtins__.operator import _negate from __builtins__.sequence import itemaccess -import native +from native import str_add, str_lt, str_gt, str_eq, str_len, str_nonempty, \ + str_substr class basestring(itemaccess): @@ -68,7 +69,7 @@ "Return a string combining this string with 'other'." - return self._binary_op(native.str_add, other) + return self._binary_op(str_add, other) __add__ = __radd__ = __iadd__ @@ -81,13 +82,13 @@ "Return whether this string is less than 'other'." - return self._binary_op(native.str_lt, other) + return self._binary_op(str_lt, other) def __gt__(self, other): "Return whether this string is greater than 'other'." - return self._binary_op(native.str_gt, other) + return self._binary_op(str_gt, other) def __le__(self, other): @@ -105,7 +106,7 @@ "Return whether this string is equal to 'other'." - return self._binary_op(native.str_eq, other) + return self._binary_op(str_eq, other) def __ne__(self, other): @@ -117,7 +118,7 @@ "Return the length of this string." - return native.str_len(self.__data__) + return str_len(self.__data__) def __str__(self): @@ -134,7 +135,7 @@ return str(b) def __bool__(self): - return native.str_nonempty(self.__data__) + return str_nonempty(self.__data__) def endswith(self, s): pass def find(self, sub, start=None, end=None): pass @@ -182,7 +183,7 @@ "Return the item at the normalised (positive) 'index'." self._check_index(index) - return native.str_substr(self.__data__, index, 1) + return str_substr(self.__data__, index, 1) class string(basestring): pass diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/tuple.py --- a/lib/__builtins__/tuple.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/tuple.py Fri Dec 09 17:27:30 2016 +0100 @@ -21,7 +21,8 @@ from __builtins__.iterator import itemiterator from __builtins__.sequence import sequence -import native +from native import list_element, list_init, list_len, list_setsize, \ + list_setelement class tuple(sequence): @@ -35,15 +36,15 @@ # for elements. size = args is not None and len(args) or 0 - self.__data__ = native.list_init(size) - native.list_setsize(self.__data__, size) + self.__data__ = list_init(size) + list_setsize(self.__data__, size) # Populate the tuple. if args is not None: i = 0 for arg in args: - native.list_setelement(self.__data__, i, arg) + list_setelement(self.__data__, i, arg) i += 1 def __getslice__(self, start, end=None): @@ -56,7 +57,7 @@ "Return the length of the tuple." - return native.list_len(self.__data__) + return list_len(self.__data__) def __add__(self, other): pass @@ -87,7 +88,7 @@ "Return the item at the normalised (positive) 'index'." self._check_index(index) - return native.list_element(self.__data__, index) + return list_element(self.__data__, index) def __set_single_item__(self, index, value): diff -r 56863815fe7b -r 8327049267bf lib/__builtins__/types.py --- a/lib/__builtins__/types.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/__builtins__/types.py Fri Dec 09 17:27:30 2016 +0100 @@ -19,20 +19,20 @@ this program. If not, see . """ -import native +from native import isinstance as _isinstance def check_int(i): "Check the given int 'i'." - if not native.isinstance(i, int): + if not _isinstance(i, int): raise ValueError(i) def check_string(s): "Check the given string 's'." - if not native.isinstance(s, string): + if not _isinstance(s, string): raise ValueError(s) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 56863815fe7b -r 8327049267bf lib/posix/io.py --- a/lib/posix/io.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/posix/io.py Fri Dec 09 17:27:30 2016 +0100 @@ -21,7 +21,12 @@ from __builtins__.file import filestream from __builtins__.types import check_int, check_string -import native +from native import ( + close as _close, + fdopen as _fdopen, + read as _read, + write as _write + ) # Abstractions for system-level files and streams. @@ -78,7 +83,7 @@ "Close the file descriptor 'fd'." - native.close(fd) + _close(fd) def closerange(fd_low, fd_high): pass def dup(fd): pass @@ -97,7 +102,7 @@ check_int(fd) check_string(mode) - return native.fdopen(fd, mode) + return _fdopen(fd, mode) def fpathconf(fd, name): pass def fstat(fd): pass @@ -124,7 +129,7 @@ check_int(fd) check_int(n) - return native.read(fd, n) + return _read(fd, n) def times(): pass def ttyname(fd): pass @@ -138,7 +143,7 @@ check_int(fd) check_string(s) - return native.write(fd, s) + return _write(fd, s) # Constants. diff -r 56863815fe7b -r 8327049267bf lib/sys.py --- a/lib/sys.py Fri Dec 09 16:26:50 2016 +0100 +++ b/lib/sys.py Fri Dec 09 17:27:30 2016 +0100 @@ -21,16 +21,20 @@ from __builtins__.int import maxint, minint from posix.io import stdin, stdout, stderr -import native +from native import ( + exit as _exit, + get_argv as _get_argv, + get_path as _get_path + ) # NOTE: Environment details to be implemented. -argv = native.get_argv() -path = native.get_path() +argv = _get_argv() +path = _get_path() # Functions to be implemented natively. def exit(status=0): - native.exit(int(status)) + _exit(int(status)) # vim: tabstop=4 expandtab shiftwidth=4