From c387772803c68c3d215906ba9fda62219f233907 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 3 Mar 2018 03:28:10 +0000 Subject: [PATCH] added a new special word and and or. compiler yet to be enhanced --- lib/comp.c | 19 +++++++++++++++++++ lib/gc.c | 3 ++- lib/hcl.h | 8 ++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/comp.c b/lib/comp.c index 544515d..29ad6d1 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -650,6 +650,17 @@ enum }; /* ========================================================================= */ +static int compile_and (hcl_t* hcl, hcl_oop_t src) +{ + hcl_seterrbfmt (hcl, HCL_ENOIMPL, "and not implemented"); + return -1; +} + +static int compile_or (hcl_t* hcl, hcl_oop_t src) +{ + hcl_seterrbfmt (hcl, HCL_ENOIMPL, "or not implemented"); + return -1; +} static int compile_break (hcl_t* hcl, hcl_oop_t src) { @@ -1301,6 +1312,10 @@ static int compile_cons_xlist_expression (hcl_t* hcl, hcl_oop_t obj) { switch (syncode) { + case HCL_SYNCODE_AND: + if (compile_and(hcl, obj) <= -1) return -1; + break; + case HCL_SYNCODE_BREAK: /* break */ if (compile_break(hcl, obj) <= -1) return -1; @@ -1331,6 +1346,10 @@ static int compile_cons_xlist_expression (hcl_t* hcl, hcl_oop_t obj) if (compile_lambda(hcl, obj, 0) <= -1) return -1; break; + case HCL_SYNCODE_OR: + if (compile_or(hcl, obj) <= -1) return -1; + break; + case HCL_SYNCODE_SET: /* (set x 10) * (set x (lambda (x y) (+ x y)) */ diff --git a/lib/gc.c b/lib/gc.c index 40854d7..e019d34 100644 --- a/lib/gc.c +++ b/lib/gc.c @@ -34,7 +34,7 @@ static struct hcl_oow_t offset; } syminfo[] = { - + { 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, { 'd','e','f','u','n' }, HCL_SYNCODE_DEFUN, HCL_OFFSETOF(hcl_t,_defun) }, { 2, { 'd','o' }, HCL_SYNCODE_DO, HCL_OFFSETOF(hcl_t,_do) }, @@ -42,6 +42,7 @@ static struct { 4, { 'e','l','s','e' }, HCL_SYNCODE_ELSE, HCL_OFFSETOF(hcl_t,_else) }, { 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) }, { 6, { 'r','e','t','u','r','n'}, HCL_SYNCODE_RETURN, HCL_OFFSETOF(hcl_t,_return) }, { 3, { 's','e','t' }, HCL_SYNCODE_SET, HCL_OFFSETOF(hcl_t,_set) }, { 5, { 'u','n','t','i','l' }, HCL_SYNCODE_UNTIL, HCL_OFFSETOF(hcl_t,_until) }, diff --git a/lib/hcl.h b/lib/hcl.h index ff6c7ea..5de3098 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1004,13 +1004,15 @@ struct hcl_t hcl_oop_t _true; hcl_oop_t _false; + hcl_oop_t _and; /* symbol */ hcl_oop_t _break; /* symbol */ hcl_oop_t _defun; /* symbol */ - hcl_oop_t _do; /* symbol */ + hcl_oop_t _do; /* symbol */ hcl_oop_t _elif; /* symbol */ hcl_oop_t _else; /* symbol */ hcl_oop_t _if; /* symbol */ hcl_oop_t _lambda; /* symbol */ + hcl_oop_t _or; /* symbol */ hcl_oop_t _return; /* symbol */ hcl_oop_t _set; /* symbol */ hcl_oop_t _until; /* symbol */ @@ -1269,13 +1271,15 @@ typedef enum hcl_brand_t hcl_brand_t; enum hcl_syncode_t { /* SYNCODE 0 means it's not a syncode object. so it begins with 1 */ - HCL_SYNCODE_BREAK = 1, + HCL_SYNCODE_AND = 1, + HCL_SYNCODE_BREAK, HCL_SYNCODE_DEFUN, HCL_SYNCODE_DO, HCL_SYNCODE_ELIF, HCL_SYNCODE_ELSE, HCL_SYNCODE_IF, HCL_SYNCODE_LAMBDA, + HCL_SYNCODE_OR, HCL_SYNCODE_RETURN, HCL_SYNCODE_SET, HCL_SYNCODE_UNTIL,