diff --git a/lib/gc.c b/lib/gc.c index c66139c..4bef8fe 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -39,18 +39,19 @@ static struct hcl_oow_t offset; } syminfo[] = { - { 3, { 'a','n','d' }, HCL_SYNCODE_AND, HCL_OFFSETOF(hcl_t,_and) }, + { 3, { 'a','n','d' }, HCL_SYNCODE_AND, HCL_OFFSETOF(hcl_t,_and) }, { 5, { 'b','r','e','a','k' }, HCL_SYNCODE_BREAK, HCL_OFFSETOF(hcl_t,_break) }, { 5, { 'c','a','t','c','h' }, HCL_SYNCODE_CATCH, HCL_OFFSETOF(hcl_t,_catch) }, - { 8, { 'c','o','n','t','i','n','u','e' }, HCL_SYNCODE_CONTINUE, HCL_OFFSETOF(hcl_t,_continue) }, - { 8, { 'd','e','f','c','l','a','s','s' }, HCL_SYNCODE_DEFCLASS, HCL_OFFSETOF(hcl_t,_defclass) }, + { 8, { 'c','o','n','t','i','n','u','e' }, HCL_SYNCODE_CONTINUE, HCL_OFFSETOF(hcl_t,_continue) }, + { 8, { 'd','e','f','c','l','a','s','s' }, HCL_SYNCODE_DEFCLASS, HCL_OFFSETOF(hcl_t,_defclass) }, { 5, { 'd','e','f','u','n' }, HCL_SYNCODE_DEFUN, HCL_OFFSETOF(hcl_t,_defun) }, - { 2, { 'd','o' }, HCL_SYNCODE_DO, HCL_OFFSETOF(hcl_t,_do) }, + { 2, { 'd','o' }, HCL_SYNCODE_DO, HCL_OFFSETOF(hcl_t,_do) }, { 4, { 'e','l','i','f' }, HCL_SYNCODE_ELIF, HCL_OFFSETOF(hcl_t,_elif) }, { 4, { 'e','l','s','e' }, HCL_SYNCODE_ELSE, HCL_OFFSETOF(hcl_t,_else) }, + { 3, { 'f','u','n' }, HCL_SYNCODE_LAMBDA, HCL_OFFSETOF(hcl_t,_fun) }, /* same syncode as lambda */ { 2, { 'i','f' }, HCL_SYNCODE_IF, HCL_OFFSETOF(hcl_t,_if) }, { 6, { 'l','a','m','b','d','a' }, HCL_SYNCODE_LAMBDA, HCL_OFFSETOF(hcl_t,_lambda) }, - { 2, { 'o','r' }, HCL_SYNCODE_OR, HCL_OFFSETOF(hcl_t,_or) }, + { 2, { 'o','r' }, HCL_SYNCODE_OR, HCL_OFFSETOF(hcl_t,_or) }, { 4, { 'p','l','u','s' }, HCL_SYNCODE_PLUS, HCL_OFFSETOF(hcl_t,_plus) }, { 6, { 'r','e','t','u','r','n'}, HCL_SYNCODE_RETURN, HCL_OFFSETOF(hcl_t,_return) }, { 16, { 'r','e','t','u','r','n','-','f','r','o','m','-','h','o','m','e'}, diff --git a/lib/hcl.h b/lib/hcl.h index d292df1..805e05c 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1581,10 +1581,11 @@ struct hcl_t hcl_oop_t _do; /* symbol */ hcl_oop_t _elif; /* symbol */ hcl_oop_t _else; /* symbol */ + hcl_oop_t _fun; /* symbol */ hcl_oop_t _if; /* symbol */ hcl_oop_t _lambda; /* symbol */ hcl_oop_t _or; /* symbol */ - hcl_oop_t _plus; /* symbol */ + hcl_oop_t _plus; /* symbol */ hcl_oop_t _return; /* symbol */ hcl_oop_t _return_from_home; /* symbol */ hcl_oop_t _set; /* symbol */ diff --git a/t/fun-01.hcl b/t/fun-01.hcl index 7beba71..41fd024 100644 --- a/t/fun-01.hcl +++ b/t/fun-01.hcl @@ -6,12 +6,18 @@ defun aaa(a b) { set k (aaa 10 20); -if (= k 30) { - printf "OK\n"; -} -else { - printf "ERROR\n"; +if (= k 30) { printf "OK\n"; } +else { printf "ERROR\n"; }; + +## -------------------------------------- + +defun mkfun(t) { + return (fun(c) { + return (+ t c); + }); }; - - +set f (mkfun 20); +set k (f 50); +if (= k 50) { printf "OK\n"; } +else { printf "ERROR\n"; };