From 374748f2718b5e0b88df75ff7ab6d178336aac44 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 15 Feb 2018 01:39:00 +0000 Subject: [PATCH] added reader & compiler check to filter out special symbols when processing argument and variable names in more contexts --- lib/comp.c | 13 +++++++------ lib/prim.c | 11 ++++++++++- lib/read.c | 12 ++++++++++-- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/comp.c b/lib/comp.c index 2a501f9..1b03b23 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -797,7 +797,7 @@ static int compile_lambda (hcl_t* hcl, hcl_oop_t src, int defun) return -1; } - if (HCL_OBJ_GET_FLAGS_SYNCODE(defun_name)) + if (HCL_OBJ_GET_FLAGS_SYNCODE(defun_name) || HCL_OBJ_GET_FLAGS_KERNEL(defun_name)) { hcl_setsynerrbfmt (hcl, HCL_SYNERR_BANNEDVARNAME, HCL_NULL, HCL_NULL, "special symbol not to be used as a defun name - %O", defun_name); /* TOOD: error location */ @@ -854,10 +854,10 @@ static int compile_lambda (hcl_t* hcl, hcl_oop_t src, int defun) return -1; } - if (HCL_OBJ_GET_FLAGS_SYNCODE(arg)) + if (HCL_OBJ_GET_FLAGS_SYNCODE(arg) || HCL_OBJ_GET_FLAGS_KERNEL(arg)) { hcl_setsynerrbfmt (hcl, HCL_SYNERR_BANNEDARGNAME, HCL_NULL, HCL_NULL, - "special symbol not to be declared as an argument name - %O", arg); /* TOOD: error location */ + "special symbol not to be declared as an argument - %O", arg); /* TOOD: error location */ return -1; } @@ -914,10 +914,11 @@ static int compile_lambda (hcl_t* hcl, hcl_oop_t src, int defun) sz = HCL_OBJ_GET_SIZE(dcl); for (i = 0; i < sz; i++) { - if (HCL_OBJ_GET_FLAGS_SYNCODE(((hcl_oop_oop_t)dcl)->slot[i])) + if (HCL_OBJ_GET_FLAGS_SYNCODE(((hcl_oop_oop_t)dcl)->slot[i]) || + HCL_OBJ_GET_FLAGS_KERNEL(((hcl_oop_oop_t)dcl)->slot[i])) { hcl_setsynerrbfmt (hcl, HCL_SYNERR_BANNEDVARNAME, HCL_NULL, HCL_NULL, - "special symbol not to be declared as a variable name - %O", obj); /* TOOD: error location */ + "special symbol not to be declared as a variable - %O", obj); /* TOOD: error location */ return -1; } @@ -1063,7 +1064,7 @@ static int compile_set (hcl_t* hcl, hcl_oop_t src) return -1; } - if (HCL_OBJ_GET_FLAGS_SYNCODE(var)) + if (HCL_OBJ_GET_FLAGS_SYNCODE(var) || HCL_OBJ_GET_FLAGS_KERNEL(var)) { hcl_setsynerrbfmt (hcl, HCL_SYNERR_BANNEDVARNAME, HCL_NULL, HCL_NULL, "special symbol not to be used as a variable name - %O", var); /* TOOD: error location */ return -1; diff --git a/lib/prim.c b/lib/prim.c index 40261c8..aac2343 100644 --- a/lib/prim.c +++ b/lib/prim.c @@ -395,6 +395,7 @@ int hcl_addbuiltinprims (hcl_t* hcl) { hcl_oow_t i; hcl_oop_t prim, name; + hcl_oop_cons_t cons; for (i = 0; i < HCL_COUNTOF(builtin_prims); i++) { @@ -406,7 +407,15 @@ int hcl_addbuiltinprims (hcl_t* hcl) hcl_poptmp (hcl); if (!name) return -1; - if (!hcl_putatsysdic(hcl, name, prim)) return -1; + hcl_pushtmp (hcl, &name); + cons = hcl_putatsysdic(hcl, name, prim); + hcl_poptmp (hcl); + if (!cons) return -1; + + /* turn on the kernel bit in the symbol associated with a primitive + * function. 'set' prevents this symbol from being used as a variable + * name */ + HCL_OBJ_SET_FLAGS_KERNEL (name, 1); } return 0; diff --git a/lib/read.c b/lib/read.c index 862774f..7d23517 100644 --- a/lib/read.c +++ b/lib/read.c @@ -1646,11 +1646,18 @@ static int get_symbol_array_literal (hcl_t* hcl, hcl_oop_t* xlit) HCL_ASSERT (hcl, TOKEN_TYPE(hcl) == HCL_IOTOK_VBAR); GET_TOKEN(hcl); /* skip #[ */ - while (TOKEN_TYPE(hcl) == HCL_IOTOK_IDENT) + while (TOKEN_TYPE(hcl) == HCL_IOTOK_IDENT /* || TOKEN_TYPE(hcl) == HCL_IOTOK_IDENT_DOTTED */) { - sym = hcl_makesymbol (hcl, TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl)); + sym = hcl_makesymbol(hcl, TOKEN_NAME_PTR(hcl), TOKEN_NAME_LEN(hcl)); if (!sym) return -1; + if (HCL_OBJ_GET_FLAGS_SYNCODE(sym) || HCL_OBJ_GET_FLAGS_KERNEL(sym)) + { + hcl_setsynerrbfmt (hcl, HCL_SYNERR_BANNEDVARNAME, HCL_NULL, HCL_NULL, + "special symbol not to be declared as a variable - %O", sym); /* TOOD: error location */ + return -1; + } + if (add_to_symbol_array_literal_buffer(hcl, sym) <= -1) return -1; GET_TOKEN (hcl); } @@ -1934,6 +1941,7 @@ static int read_object (hcl_t* hcl) hcl_poptmp (hcl); + HCL_OBJ_SET_FLAGS_KERNEL (obj, 1); } break; }