# HG changeset patch # User Paul Boddie # Date 1479233532 -3600 # Node ID 27ac1971cb382b785f8e21dc14fa9af397c343a5 # Parent 67edffe846e38547f763f5c39924a5af12c61bf2 Added initial support for integers and environment initialisation. diff -r 67edffe846e3 -r 27ac1971cb38 lib/__builtins__/int.py --- a/lib/__builtins__/int.py Sat Nov 12 23:27:04 2016 +0100 +++ b/lib/__builtins__/int.py Tue Nov 15 19:12:12 2016 +0100 @@ -23,9 +23,18 @@ import native class int(object): + + "An integer abstraction." + def __init__(self, number_or_string=None): - # Note member. - self.__data__ = 0 + + "Initialise the integer with the given 'number_or_string'." + + if isinstance(number_or_string, int): + self.__data__ = number_or_string.__data__ + else: + # NOTE: To be implemented. + self.__data__ = None def __iadd__(self, other): "Return a new int for the operation." diff -r 67edffe846e3 -r 27ac1971cb38 lib/native.py --- a/lib/native.py Sat Nov 12 23:27:04 2016 +0100 +++ b/lib/native.py Tue Nov 15 19:12:12 2016 +0100 @@ -20,25 +20,28 @@ """ def _exit(status): pass +def _get_argv(): pass +def _get_path(): pass def _is(x, y): pass def _is_not(x, y): pass def _int_add(self, other): pass -def _int_sub(self, other): pass -def _int_mul(self, other): pass def _int_div(self, other): pass def _int_mod(self, other): pass +def _int_mul(self, other): pass def _int_pow(self, other): pass +def _int_sub(self, other): pass + +def _int_rdiv(self, other): pass +def _int_rmod(self, other): pass +def _int_rpow(self, other): pass +def _int_rsub(self, other): pass + def _int_and(self, other): pass def _int_or(self, other): pass def _int_xor(self, other): pass -def _int_rsub(self, other): pass -def _int_rdiv(self, other): pass -def _int_rmod(self, other): pass -def _int_rpow(self, other): pass - def _int_lt(self, other): pass def _int_gt(self, other): pass def _int_eq(self, other): pass diff -r 67edffe846e3 -r 27ac1971cb38 lib/sys.py --- a/lib/sys.py Sat Nov 12 23:27:04 2016 +0100 +++ b/lib/sys.py Tue Nov 15 19:12:12 2016 +0100 @@ -19,7 +19,7 @@ this program. If not, see . """ -from native import _exit +from native import _exit, _get_argv, _get_path # Standard streams. @@ -29,8 +29,8 @@ # NOTE: Environment details to be implemented. -argv = [] -path = [] +argv = _get_argv() +path = _get_path() # Functions to be implemented natively. diff -r 67edffe846e3 -r 27ac1971cb38 templates/native.c --- a/templates/native.c Sat Nov 12 23:27:04 2016 +0100 +++ b/templates/native.c Tue Nov 15 19:12:12 2016 +0100 @@ -19,6 +19,24 @@ #undef status } +__attr __fn_native__get_argv(__attr __args[]) +{ + #define status (__args[1]) + + /* NOTE: To be written. */ + return __builtins___none_None; + #undef status +} + +__attr __fn_native__get_path(__attr __args[]) +{ + #define status (__args[1]) + + /* NOTE: To be written. */ + return __builtins___none_None; + #undef status +} + __attr __fn_native__is(__attr __args[]) { #define x (__args[1]) @@ -291,9 +309,15 @@ __attr __fn_native__list_len(__attr __args[]) { #define self (__args[1]) + /* self.__data__ interpreted as fragment */ + unsigned int size = __load_via_object(self.value, __pos___data__).data->size; - /* NOTE: To be written. */ - return __builtins___none_None; + /* Create a new integer and mutate the __data__ attribute. */ + __attr length = __new(&__InstanceTable___builtins___int_int, &__builtins___int_int, sizeof(__obj___builtins___int_int)); + length.value->attrs[__pos___data__].intvalue = size; + + /* Return the new integer. */ + return length; #undef self } @@ -361,7 +385,7 @@ #define obj (__args[1]) #define cls (__args[2]) - if (__HASATTR(obj.value, __TYPEPOS(cls.value), __TYPECODE(cls.value))) + if (__is_instance(obj.value) && __HASATTR(__get_class(obj.value), __TYPEPOS(cls.value), __TYPECODE(cls.value))) return obj; else return __builtins___none_None; diff -r 67edffe846e3 -r 27ac1971cb38 templates/native.h --- a/templates/native.h Sat Nov 12 23:27:04 2016 +0100 +++ b/templates/native.h Tue Nov 15 19:12:12 2016 +0100 @@ -4,39 +4,51 @@ /* Native functions. */ __attr __fn_native__exit(__attr __args[]); +__attr __fn_native__get_argv(__attr __args[]); +__attr __fn_native__get_path(__attr __args[]); + __attr __fn_native__is(__attr __args[]); __attr __fn_native__is_not(__attr __args[]); + __attr __fn_native__int_add(__attr __args[]); -__attr __fn_native__int_sub(__attr __args[]); -__attr __fn_native__int_mul(__attr __args[]); __attr __fn_native__int_div(__attr __args[]); __attr __fn_native__int_mod(__attr __args[]); +__attr __fn_native__int_mul(__attr __args[]); __attr __fn_native__int_pow(__attr __args[]); +__attr __fn_native__int_sub(__attr __args[]); + __attr __fn_native__int_and(__attr __args[]); __attr __fn_native__int_or(__attr __args[]); __attr __fn_native__int_xor(__attr __args[]); -__attr __fn_native__int_rsub(__attr __args[]); + __attr __fn_native__int_rdiv(__attr __args[]); __attr __fn_native__int_rmod(__attr __args[]); __attr __fn_native__int_rpow(__attr __args[]); +__attr __fn_native__int_rsub(__attr __args[]); + __attr __fn_native__int_lt(__attr __args[]); __attr __fn_native__int_gt(__attr __args[]); __attr __fn_native__int_eq(__attr __args[]); + __attr __fn_native__str_add(__attr __args[]); __attr __fn_native__str_lt(__attr __args[]); __attr __fn_native__str_gt(__attr __args[]); __attr __fn_native__str_eq(__attr __args[]); __attr __fn_native__str_len(__attr __args[]); __attr __fn_native__str_nonempty(__attr __args[]); + __attr __fn_native__list_init(__attr __args[]); __attr __fn_native__list_len(__attr __args[]); __attr __fn_native__list_nonempty(__attr __args[]); __attr __fn_native__list_element(__attr __args[]); __attr __fn_native__list_to_tuple(__attr __args[]); + __attr __fn_native__tuple_init(__attr __args[]); __attr __fn_native__tuple_len(__attr __args[]); __attr __fn_native__tuple_element(__attr __args[]); + __attr __fn_native__isinstance(__attr __args[]); + __attr __fn_native__read(__attr __args[]); __attr __fn_native__write(__attr __args[]);