1.1 --- a/lib/native.py Sat Dec 03 17:16:15 2016 +0100
1.2 +++ b/lib/native.py Sat Dec 03 17:34:44 2016 +0100
1.3 @@ -31,6 +31,11 @@
1.4 def _is(x, y): pass
1.5 def _is_not(x, y): pass
1.6
1.7 +# Limit definition.
1.8 +
1.9 +def _get_maxint(): pass
1.10 +def _get_minint(): pass
1.11 +
1.12 # Integer operations.
1.13
1.14 def _int_add(self, other): pass
2.1 --- a/lib/sys.py Sat Dec 03 17:16:15 2016 +0100
2.2 +++ b/lib/sys.py Sat Dec 03 17:34:44 2016 +0100
2.3 @@ -19,7 +19,12 @@
2.4 this program. If not, see <http://www.gnu.org/licenses/>.
2.5 """
2.6
2.7 -from native import _exit, _get_argv, _get_path
2.8 +import native
2.9 +
2.10 +# Limits.
2.11 +
2.12 +maxint = native._get_maxint()
2.13 +minint = native._get_minint()
2.14
2.15 # Standard streams.
2.16
2.17 @@ -29,12 +34,12 @@
2.18
2.19 # NOTE: Environment details to be implemented.
2.20
2.21 -argv = _get_argv()
2.22 -path = _get_path()
2.23 +argv = native._get_argv()
2.24 +path = native._get_path()
2.25
2.26 # Functions to be implemented natively.
2.27
2.28 def exit(status=0):
2.29 - _exit(int(status))
2.30 + native._exit(int(status))
2.31
2.32 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/templates/native.c Sat Dec 03 17:16:15 2016 +0100
3.2 +++ b/templates/native.c Sat Dec 03 17:34:44 2016 +0100
3.3 @@ -103,6 +103,20 @@
3.4 return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False;
3.5 }
3.6
3.7 +__attr __fn_native__get_maxint(__attr __args[])
3.8 +{
3.9 + __attr * const status = &__args[1];
3.10 +
3.11 + return __new_int(INT_MAX);
3.12 +}
3.13 +
3.14 +__attr __fn_native__get_minint(__attr __args[])
3.15 +{
3.16 + __attr * const status = &__args[1];
3.17 +
3.18 + return __new_int(INT_MIN);
3.19 +}
3.20 +
3.21 __attr __fn_native__int_add(__attr __args[])
3.22 {
3.23 __attr * const _data = &__args[1];
3.24 @@ -332,10 +346,11 @@
3.25 __attr * const _data = &__args[1];
3.26 /* _data interpreted as int */
3.27 int i = _data->intvalue;
3.28 - int n = i != 0 ? (int) ceil(log10(abs(i)+1)) + 1 : 2;
3.29 + /* Employ a buffer big enough to fit the largest integer plus an extra
3.30 + character, a minus sign, and the null terminator. */
3.31 + unsigned int n = (int) log10(INT_MAX) + 3;
3.32 char *s = (char *) __ALLOCATE(n, sizeof(char));
3.33
3.34 - if (i < 0) n++;
3.35 snprintf(s, n, "%d", i);
3.36
3.37 /* Return a new string. */
4.1 --- a/templates/native.h Sat Dec 03 17:16:15 2016 +0100
4.2 +++ b/templates/native.h Sat Dec 03 17:34:44 2016 +0100
4.3 @@ -10,6 +10,9 @@
4.4 __attr __fn_native__is(__attr __args[]);
4.5 __attr __fn_native__is_not(__attr __args[]);
4.6
4.7 +__attr __fn_native__get_maxint(__attr __args[]);
4.8 +__attr __fn_native__get_minint(__attr __args[]);
4.9 +
4.10 __attr __fn_native__int_add(__attr __args[]);
4.11 __attr __fn_native__int_div(__attr __args[]);
4.12 __attr __fn_native__int_mod(__attr __args[]);
5.1 --- a/tests/numbers.py Sat Dec 03 17:16:15 2016 +0100
5.2 +++ b/tests/numbers.py Sat Dec 03 17:34:44 2016 +0100
5.3 @@ -1,3 +1,10 @@
5.4 +import sys
5.5 +
5.6 +print sys.maxint
5.7 +print sys.minint
5.8 +
5.9 +print sys.maxint + sys.minint
5.10 +
5.11 i = 2 ** 30
5.12 print i # 1073741824
5.13