1.1 --- a/lib/__builtins__/int.py Sat Nov 12 23:27:04 2016 +0100
1.2 +++ b/lib/__builtins__/int.py Tue Nov 15 19:12:12 2016 +0100
1.3 @@ -23,9 +23,18 @@
1.4 import native
1.5
1.6 class int(object):
1.7 +
1.8 + "An integer abstraction."
1.9 +
1.10 def __init__(self, number_or_string=None):
1.11 - # Note member.
1.12 - self.__data__ = 0
1.13 +
1.14 + "Initialise the integer with the given 'number_or_string'."
1.15 +
1.16 + if isinstance(number_or_string, int):
1.17 + self.__data__ = number_or_string.__data__
1.18 + else:
1.19 + # NOTE: To be implemented.
1.20 + self.__data__ = None
1.21
1.22 def __iadd__(self, other):
1.23 "Return a new int for the operation."
2.1 --- a/lib/native.py Sat Nov 12 23:27:04 2016 +0100
2.2 +++ b/lib/native.py Tue Nov 15 19:12:12 2016 +0100
2.3 @@ -20,25 +20,28 @@
2.4 """
2.5
2.6 def _exit(status): pass
2.7 +def _get_argv(): pass
2.8 +def _get_path(): pass
2.9
2.10 def _is(x, y): pass
2.11 def _is_not(x, y): pass
2.12
2.13 def _int_add(self, other): pass
2.14 -def _int_sub(self, other): pass
2.15 -def _int_mul(self, other): pass
2.16 def _int_div(self, other): pass
2.17 def _int_mod(self, other): pass
2.18 +def _int_mul(self, other): pass
2.19 def _int_pow(self, other): pass
2.20 +def _int_sub(self, other): pass
2.21 +
2.22 +def _int_rdiv(self, other): pass
2.23 +def _int_rmod(self, other): pass
2.24 +def _int_rpow(self, other): pass
2.25 +def _int_rsub(self, other): pass
2.26 +
2.27 def _int_and(self, other): pass
2.28 def _int_or(self, other): pass
2.29 def _int_xor(self, other): pass
2.30
2.31 -def _int_rsub(self, other): pass
2.32 -def _int_rdiv(self, other): pass
2.33 -def _int_rmod(self, other): pass
2.34 -def _int_rpow(self, other): pass
2.35 -
2.36 def _int_lt(self, other): pass
2.37 def _int_gt(self, other): pass
2.38 def _int_eq(self, other): pass
3.1 --- a/lib/sys.py Sat Nov 12 23:27:04 2016 +0100
3.2 +++ b/lib/sys.py Tue Nov 15 19:12:12 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 _exit
3.8 +from native import _exit, _get_argv, _get_path
3.9
3.10 # Standard streams.
3.11
3.12 @@ -29,8 +29,8 @@
3.13
3.14 # NOTE: Environment details to be implemented.
3.15
3.16 -argv = []
3.17 -path = []
3.18 +argv = _get_argv()
3.19 +path = _get_path()
3.20
3.21 # Functions to be implemented natively.
3.22
4.1 --- a/templates/native.c Sat Nov 12 23:27:04 2016 +0100
4.2 +++ b/templates/native.c Tue Nov 15 19:12:12 2016 +0100
4.3 @@ -19,6 +19,24 @@
4.4 #undef status
4.5 }
4.6
4.7 +__attr __fn_native__get_argv(__attr __args[])
4.8 +{
4.9 + #define status (__args[1])
4.10 +
4.11 + /* NOTE: To be written. */
4.12 + return __builtins___none_None;
4.13 + #undef status
4.14 +}
4.15 +
4.16 +__attr __fn_native__get_path(__attr __args[])
4.17 +{
4.18 + #define status (__args[1])
4.19 +
4.20 + /* NOTE: To be written. */
4.21 + return __builtins___none_None;
4.22 + #undef status
4.23 +}
4.24 +
4.25 __attr __fn_native__is(__attr __args[])
4.26 {
4.27 #define x (__args[1])
4.28 @@ -291,9 +309,15 @@
4.29 __attr __fn_native__list_len(__attr __args[])
4.30 {
4.31 #define self (__args[1])
4.32 + /* self.__data__ interpreted as fragment */
4.33 + unsigned int size = __load_via_object(self.value, __pos___data__).data->size;
4.34
4.35 - /* NOTE: To be written. */
4.36 - return __builtins___none_None;
4.37 + /* Create a new integer and mutate the __data__ attribute. */
4.38 + __attr length = __new(&__InstanceTable___builtins___int_int, &__builtins___int_int, sizeof(__obj___builtins___int_int));
4.39 + length.value->attrs[__pos___data__].intvalue = size;
4.40 +
4.41 + /* Return the new integer. */
4.42 + return length;
4.43 #undef self
4.44 }
4.45
4.46 @@ -361,7 +385,7 @@
4.47 #define obj (__args[1])
4.48 #define cls (__args[2])
4.49
4.50 - if (__HASATTR(obj.value, __TYPEPOS(cls.value), __TYPECODE(cls.value)))
4.51 + if (__is_instance(obj.value) && __HASATTR(__get_class(obj.value), __TYPEPOS(cls.value), __TYPECODE(cls.value)))
4.52 return obj;
4.53 else
4.54 return __builtins___none_None;
5.1 --- a/templates/native.h Sat Nov 12 23:27:04 2016 +0100
5.2 +++ b/templates/native.h Tue Nov 15 19:12:12 2016 +0100
5.3 @@ -4,39 +4,51 @@
5.4 /* Native functions. */
5.5
5.6 __attr __fn_native__exit(__attr __args[]);
5.7 +__attr __fn_native__get_argv(__attr __args[]);
5.8 +__attr __fn_native__get_path(__attr __args[]);
5.9 +
5.10 __attr __fn_native__is(__attr __args[]);
5.11 __attr __fn_native__is_not(__attr __args[]);
5.12 +
5.13 __attr __fn_native__int_add(__attr __args[]);
5.14 -__attr __fn_native__int_sub(__attr __args[]);
5.15 -__attr __fn_native__int_mul(__attr __args[]);
5.16 __attr __fn_native__int_div(__attr __args[]);
5.17 __attr __fn_native__int_mod(__attr __args[]);
5.18 +__attr __fn_native__int_mul(__attr __args[]);
5.19 __attr __fn_native__int_pow(__attr __args[]);
5.20 +__attr __fn_native__int_sub(__attr __args[]);
5.21 +
5.22 __attr __fn_native__int_and(__attr __args[]);
5.23 __attr __fn_native__int_or(__attr __args[]);
5.24 __attr __fn_native__int_xor(__attr __args[]);
5.25 -__attr __fn_native__int_rsub(__attr __args[]);
5.26 +
5.27 __attr __fn_native__int_rdiv(__attr __args[]);
5.28 __attr __fn_native__int_rmod(__attr __args[]);
5.29 __attr __fn_native__int_rpow(__attr __args[]);
5.30 +__attr __fn_native__int_rsub(__attr __args[]);
5.31 +
5.32 __attr __fn_native__int_lt(__attr __args[]);
5.33 __attr __fn_native__int_gt(__attr __args[]);
5.34 __attr __fn_native__int_eq(__attr __args[]);
5.35 +
5.36 __attr __fn_native__str_add(__attr __args[]);
5.37 __attr __fn_native__str_lt(__attr __args[]);
5.38 __attr __fn_native__str_gt(__attr __args[]);
5.39 __attr __fn_native__str_eq(__attr __args[]);
5.40 __attr __fn_native__str_len(__attr __args[]);
5.41 __attr __fn_native__str_nonempty(__attr __args[]);
5.42 +
5.43 __attr __fn_native__list_init(__attr __args[]);
5.44 __attr __fn_native__list_len(__attr __args[]);
5.45 __attr __fn_native__list_nonempty(__attr __args[]);
5.46 __attr __fn_native__list_element(__attr __args[]);
5.47 __attr __fn_native__list_to_tuple(__attr __args[]);
5.48 +
5.49 __attr __fn_native__tuple_init(__attr __args[]);
5.50 __attr __fn_native__tuple_len(__attr __args[]);
5.51 __attr __fn_native__tuple_element(__attr __args[]);
5.52 +
5.53 __attr __fn_native__isinstance(__attr __args[]);
5.54 +
5.55 __attr __fn_native__read(__attr __args[]);
5.56 __attr __fn_native__write(__attr __args[]);
5.57