Oops. sorry, I forgot to attach the sources On Thu, 26 Aug 2010 04:11:42 +0200 pancake <panc...@youterm.com> wrote:
> I have written an initial version of 'nscc' with support for creating > native interfaces by parsing an 'nsi' file. > > [panc...@dazo nscript]$ cat libc.ns > # test program for libc.nsi > dup print "\n" print > "food" > ns_pop > "one" "one" strcmp $x > "one" "two" strcmp $y > "strcmp one-one: " print x print "\n" print > "strcmp one-two: " print y print "\n" print > "ls" system > # "echo 'hello world'" system > { "true\n" print } $t > "false" t ns_pop > # print > exit > > [panc...@dazo nscript]$ cat libc.nsi > i:s:system > i:s-s:strcmp > -:-:ns_pop > > The command to compile the nscript will be: > > [panc...@dazo nscript]$ ./nscc -i libc.nsi libc.ns > > [panc...@dazo nscript]$ ./a.out > strcmp one-one: 0 > strcmp one-two: 1 > Makefile Todo include libc.ns.c libnscript.a ns.c nscc src > ReadMe a.out libc.ns libc.nsi ns ns.o p test > true > > ------- > > I have only added support for string and integer types. > > Feel free to import this code into your repo. > > --pancake >
nscc
Description: Binary data
libc.nsi
Description: Binary data
libc.ns
Description: Binary data
#include <stdio.h> #include <nscript.h> #include <nsstack.h> #include <dynarray.h> #include <nsnamemaps.h> static const char *code = \ "# test program for libc.nsi\n" "dup print \"\n\" print\n" "\"food\"\n" "ns_pop\n" "\"one\" \"one\" strcmp $x\n" "\"one\" \"two\" strcmp $y\n" "\"strcmp one-one: \" print x print \"\n\" print\n" "\"strcmp one-two: \" print y print \"\n\" print\n" "\"ls\" system\n" "# \"echo 'hello world'\" system\n" "{ \"true\n\" print } $t\n" "\"false\" t ns_pop\n" "# print\n" "exit\n" ; static void myns_system() { struct ns_obj obj; struct ns_obj arg_0 = ns_pop(); int ret = system(arg_0.u.s->arr); obj.type = TY_INT; obj.u.i = ret; ns_push(obj); } static void myns_strcmp() { struct ns_obj obj; struct ns_obj arg_0 = ns_pop(); struct ns_obj arg_1 = ns_pop(); int ret = strcmp(arg_0.u.s->arr, arg_1.u.s->arr); obj.type = TY_INT; obj.u.i = ret; ns_push(obj); } static void myns_ns_pop() { ns_pop(); } static struct ns_namemap my_ns_funcmap[] = { { "system", { TY_FUNC, { .f = myns_system } } }, { "strcmp", { TY_FUNC, { .f = myns_strcmp } } }, { "ns_pop", { TY_FUNC, { .f = myns_ns_pop } } }, { 0 } }; static void my_ns_init() { struct ns_namemap *curr = my_ns_funcmap; for(;curr->key;++curr) trie_add(ns_functrie, curr->key, curr->obj); } int main() { ns_init(); my_ns_init(); ns_interpret(code); return 0; }