# HG changeset patch # User Paul Boddie # Date 1481219465 -3600 # Node ID 5f24a4b9d16a4bcba59c3aa65b3c928ef75b9152 # Parent e0879c83a43902b73cedef28f20d7553e13f0a3e Added comments and copyright and licensing information. diff -r e0879c83a439 -r 5f24a4b9d16a templates/native.c --- a/templates/native.c Wed Dec 07 17:37:00 2016 +0100 +++ b/templates/native.c Thu Dec 08 18:51:05 2016 +0100 @@ -1,3 +1,21 @@ +/* Native functions. + +Copyright (C) 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +*/ + #include /* abs, exit */ #include /* read, write */ #include /* INT_MAX, INT_MIN */ @@ -61,7 +79,7 @@ return newdata; } -/* Native functions. */ +/* Environment support. */ __attr __fn_native__exit(__attr __args[]) { @@ -87,6 +105,8 @@ return __builtins___none_None; } +/* Identity testing. */ + __attr __fn_native__is(__attr __args[]) { __attr * const x = &__args[1]; @@ -103,6 +123,8 @@ return x->value != y->value ? __builtins___boolean_True : __builtins___boolean_False; } +/* Limit definition. */ + __attr __fn_native__get_maxint(__attr __args[]) { __attr * const status = &__args[1]; @@ -117,6 +139,8 @@ return __new_int(INT_MIN); } +/* Integer operations. */ + __attr __fn_native__int_add(__attr __args[]) { __attr * const _data = &__args[1]; @@ -357,6 +381,8 @@ return __new_str(s); } +/* String operations. */ + __attr __fn_native__str_add(__attr __args[]) { __attr * const _data = &__args[1]; @@ -456,6 +482,8 @@ return __new_str(sub); } +/* List operations. */ + __attr __fn_native__list_init(__attr __args[]) { __attr * const size = &__args[1]; @@ -569,6 +597,8 @@ return __builtins___none_None; } +/* Buffer operations. */ + __attr __fn_native__buffer_str(__attr __args[]) { __attr * const _data = &__args[1]; @@ -597,6 +627,8 @@ return __new_str(s); } +/* Method binding. */ + __attr __fn_native__get_using(__attr __args[]) { __attr * const callable = &__args[1]; @@ -605,6 +637,8 @@ return __replace_context(instance->value, *callable); } +/* Introspection. */ + __attr __fn_native__object_getattr(__attr __args[]) { __attr * const obj = &__args[1]; diff -r e0879c83a439 -r 5f24a4b9d16a templates/native.h --- a/templates/native.h Wed Dec 07 17:37:00 2016 +0100 +++ b/templates/native.h Thu Dec 08 18:51:05 2016 +0100 @@ -1,18 +1,42 @@ +/* Native functions. + +Copyright (C) 2016 Paul Boddie + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +*/ + #ifndef __NATIVE_H__ #define __NATIVE_H__ -/* Native functions. */ +/* Environment support. */ __attr __fn_native__exit(__attr __args[]); __attr __fn_native__get_argv(__attr __args[]); __attr __fn_native__get_path(__attr __args[]); +/* Identity testing. */ + __attr __fn_native__is(__attr __args[]); __attr __fn_native__is_not(__attr __args[]); +/* Limit definition. */ + __attr __fn_native__get_maxint(__attr __args[]); __attr __fn_native__get_minint(__attr __args[]); +/* Integer operations. */ + __attr __fn_native__int_add(__attr __args[]); __attr __fn_native__int_div(__attr __args[]); __attr __fn_native__int_mod(__attr __args[]); @@ -38,6 +62,8 @@ __attr __fn_native__int_str(__attr __args[]); +/* String operations. */ + __attr __fn_native__str_add(__attr __args[]); __attr __fn_native__str_lt(__attr __args[]); __attr __fn_native__str_gt(__attr __args[]); @@ -47,6 +73,8 @@ __attr __fn_native__str_ord(__attr __args[]); __attr __fn_native__str_substr(__attr __args[]); +/* List operations. */ + __attr __fn_native__list_init(__attr __args[]); __attr __fn_native__list_setsize(__attr __args[]); __attr __fn_native__list_append(__attr __args[]); @@ -56,15 +84,22 @@ __attr __fn_native__list_element(__attr __args[]); __attr __fn_native__list_setelement(__attr __args[]); +/* Buffer operations. */ + __attr __fn_native__buffer_str(__attr __args[]); +/* Method binding. */ + __attr __fn_native__get_using(__attr __args[]); +/* Introspection. */ + __attr __fn_native__object_getattr(__attr __args[]); - __attr __fn_native__isinstance(__attr __args[]); __attr __fn_native__issubclass(__attr __args[]); +/* Input/output. */ + __attr __fn_native__fdopen(__attr __args[]); __attr __fn_native__fread(__attr __args[]); __attr __fn_native__fwrite(__attr __args[]);