1.1 --- a/templates/native.c Wed Dec 07 17:37:00 2016 +0100
1.2 +++ b/templates/native.c Thu Dec 08 18:51:05 2016 +0100
1.3 @@ -1,3 +1,21 @@
1.4 +/* Native functions.
1.5 +
1.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
1.7 +
1.8 +This program is free software; you can redistribute it and/or modify it under
1.9 +the terms of the GNU General Public License as published by the Free Software
1.10 +Foundation; either version 3 of the License, or (at your option) any later
1.11 +version.
1.12 +
1.13 +This program is distributed in the hope that it will be useful, but WITHOUT
1.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.16 +details.
1.17 +
1.18 +You should have received a copy of the GNU General Public License along with
1.19 +this program. If not, see <http://www.gnu.org/licenses/>.
1.20 +*/
1.21 +
1.22 #include <stdlib.h> /* abs, exit */
1.23 #include <unistd.h> /* read, write */
1.24 #include <limits.h> /* INT_MAX, INT_MIN */
1.25 @@ -61,7 +79,7 @@
1.26 return newdata;
1.27 }
1.28
1.29 -/* Native functions. */
1.30 +/* Environment support. */
1.31
1.32 __attr __fn_native__exit(__attr __args[])
1.33 {
1.34 @@ -87,6 +105,8 @@
1.35 return __builtins___none_None;
1.36 }
1.37
1.38 +/* Identity testing. */
1.39 +
1.40 __attr __fn_native__is(__attr __args[])
1.41 {
1.42 __attr * const x = &__args[1];
1.43 @@ -103,6 +123,8 @@
1.44 return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False;
1.45 }
1.46
1.47 +/* Limit definition. */
1.48 +
1.49 __attr __fn_native__get_maxint(__attr __args[])
1.50 {
1.51 __attr * const status = &__args[1];
1.52 @@ -117,6 +139,8 @@
1.53 return __new_int(INT_MIN);
1.54 }
1.55
1.56 +/* Integer operations. */
1.57 +
1.58 __attr __fn_native__int_add(__attr __args[])
1.59 {
1.60 __attr * const _data = &__args[1];
1.61 @@ -357,6 +381,8 @@
1.62 return __new_str(s);
1.63 }
1.64
1.65 +/* String operations. */
1.66 +
1.67 __attr __fn_native__str_add(__attr __args[])
1.68 {
1.69 __attr * const _data = &__args[1];
1.70 @@ -456,6 +482,8 @@
1.71 return __new_str(sub);
1.72 }
1.73
1.74 +/* List operations. */
1.75 +
1.76 __attr __fn_native__list_init(__attr __args[])
1.77 {
1.78 __attr * const size = &__args[1];
1.79 @@ -569,6 +597,8 @@
1.80 return __builtins___none_None;
1.81 }
1.82
1.83 +/* Buffer operations. */
1.84 +
1.85 __attr __fn_native__buffer_str(__attr __args[])
1.86 {
1.87 __attr * const _data = &__args[1];
1.88 @@ -597,6 +627,8 @@
1.89 return __new_str(s);
1.90 }
1.91
1.92 +/* Method binding. */
1.93 +
1.94 __attr __fn_native__get_using(__attr __args[])
1.95 {
1.96 __attr * const callable = &__args[1];
1.97 @@ -605,6 +637,8 @@
1.98 return __replace_context(instance->value, *callable);
1.99 }
1.100
1.101 +/* Introspection. */
1.102 +
1.103 __attr __fn_native__object_getattr(__attr __args[])
1.104 {
1.105 __attr * const obj = &__args[1];
2.1 --- a/templates/native.h Wed Dec 07 17:37:00 2016 +0100
2.2 +++ b/templates/native.h Thu Dec 08 18:51:05 2016 +0100
2.3 @@ -1,18 +1,42 @@
2.4 +/* Native functions.
2.5 +
2.6 +Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
2.7 +
2.8 +This program is free software; you can redistribute it and/or modify it under
2.9 +the terms of the GNU General Public License as published by the Free Software
2.10 +Foundation; either version 3 of the License, or (at your option) any later
2.11 +version.
2.12 +
2.13 +This program is distributed in the hope that it will be useful, but WITHOUT
2.14 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
2.15 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
2.16 +details.
2.17 +
2.18 +You should have received a copy of the GNU General Public License along with
2.19 +this program. If not, see <http://www.gnu.org/licenses/>.
2.20 +*/
2.21 +
2.22 #ifndef __NATIVE_H__
2.23 #define __NATIVE_H__
2.24
2.25 -/* Native functions. */
2.26 +/* Environment support. */
2.27
2.28 __attr __fn_native__exit(__attr __args[]);
2.29 __attr __fn_native__get_argv(__attr __args[]);
2.30 __attr __fn_native__get_path(__attr __args[]);
2.31
2.32 +/* Identity testing. */
2.33 +
2.34 __attr __fn_native__is(__attr __args[]);
2.35 __attr __fn_native__is_not(__attr __args[]);
2.36
2.37 +/* Limit definition. */
2.38 +
2.39 __attr __fn_native__get_maxint(__attr __args[]);
2.40 __attr __fn_native__get_minint(__attr __args[]);
2.41
2.42 +/* Integer operations. */
2.43 +
2.44 __attr __fn_native__int_add(__attr __args[]);
2.45 __attr __fn_native__int_div(__attr __args[]);
2.46 __attr __fn_native__int_mod(__attr __args[]);
2.47 @@ -38,6 +62,8 @@
2.48
2.49 __attr __fn_native__int_str(__attr __args[]);
2.50
2.51 +/* String operations. */
2.52 +
2.53 __attr __fn_native__str_add(__attr __args[]);
2.54 __attr __fn_native__str_lt(__attr __args[]);
2.55 __attr __fn_native__str_gt(__attr __args[]);
2.56 @@ -47,6 +73,8 @@
2.57 __attr __fn_native__str_ord(__attr __args[]);
2.58 __attr __fn_native__str_substr(__attr __args[]);
2.59
2.60 +/* List operations. */
2.61 +
2.62 __attr __fn_native__list_init(__attr __args[]);
2.63 __attr __fn_native__list_setsize(__attr __args[]);
2.64 __attr __fn_native__list_append(__attr __args[]);
2.65 @@ -56,15 +84,22 @@
2.66 __attr __fn_native__list_element(__attr __args[]);
2.67 __attr __fn_native__list_setelement(__attr __args[]);
2.68
2.69 +/* Buffer operations. */
2.70 +
2.71 __attr __fn_native__buffer_str(__attr __args[]);
2.72
2.73 +/* Method binding. */
2.74 +
2.75 __attr __fn_native__get_using(__attr __args[]);
2.76
2.77 +/* Introspection. */
2.78 +
2.79 __attr __fn_native__object_getattr(__attr __args[]);
2.80 -
2.81 __attr __fn_native__isinstance(__attr __args[]);
2.82 __attr __fn_native__issubclass(__attr __args[]);
2.83
2.84 +/* Input/output. */
2.85 +
2.86 __attr __fn_native__fdopen(__attr __args[]);
2.87 __attr __fn_native__fread(__attr __args[]);
2.88 __attr __fn_native__fwrite(__attr __args[]);