From 185f72381abc6516459a658650901f5acbe3419a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 11 Aug 2024 02:17:52 +0900 Subject: [PATCH] updatecd basicAt and basicAtPut to cater for fixed fields --- bin/hcl.c | 11 +---------- mod/core.c | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/bin/hcl.c b/bin/hcl.c index 9b08348..fb6156e 100644 --- a/bin/hcl.c +++ b/bin/hcl.c @@ -730,7 +730,6 @@ int main (int argc, char* argv[]) hcl_oow_t heapsize = DEFAULT_HEAPSIZE; int verbose = 0; int show_info = 0; - int nl_terminator = 0; const char* modlibdirs = HCL_NULL; #if defined(HCL_BUILD_DEBUG) @@ -745,7 +744,7 @@ int main (int argc, char* argv[]) print_usage: fprintf (stderr, "Usage: %s [options] script-filename [output-filename]\n", argv[0]); fprintf (stderr, "Options are:\n"); - fprintf (stderr, " -n enable line-break as expression terminator\n"); + fprintf (stderr, " -v show verbose messages\n"); return -1; } @@ -757,10 +756,6 @@ int main (int argc, char* argv[]) logopt = opt.arg; break; - case 'n': - nl_terminator = 1; - break; - case 'v': verbose = 1; break; @@ -831,11 +826,7 @@ int main (int argc, char* argv[]) /*trait |= HCL_TRAIT_NOGC;*/ trait |= HCL_TRAIT_AWAIT_PROCS; - #if 0 - if (nl_terminator) trait |= HCL_TRAIT_LANG_ENABLE_EOL; - #else trait |= HCL_TRAIT_LANG_ENABLE_EOL; - #endif hcl_setoption (hcl, HCL_TRAIT, &trait); } diff --git a/mod/core.c b/mod/core.c index c9ef642..37681ec 100644 --- a/mod/core.c +++ b/mod/core.c @@ -65,7 +65,9 @@ static hcl_pfrc_t pf_core_basic_at (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) { hcl_oop_t obj, val; hcl_oop_t pos; - hcl_ooi_t index; + hcl_oow_t index; + hcl_oop_class_t _class; + hcl_oow_t fixed, flexi; obj = HCL_STACK_GETARG(hcl, nargs, 0); pos = HCL_STACK_GETARG(hcl, nargs, 1); @@ -81,14 +83,19 @@ static hcl_pfrc_t pf_core_basic_at (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs) if (hcl_inttooow_noseterr(hcl, pos, &index) <= 0) { /* negative integer or not integer */ - hcl_seterrbfmt (hcl, HCL_EINVAL, "position not valid- %O", pos); + hcl_seterrbfmt (hcl, HCL_EINVAL, "position not valid - %O", pos); return HCL_PF_FAILURE; } - if (index >= HCL_OBJ_GET_SIZE(obj)) + + _class = (hcl_oop_class_t)HCL_CLASSOF(hcl, obj); + fixed = HCL_CLASS_SPEC_NAMED_INSTVARS(_class->spec); + flexi = HCL_OBJ_GET_SIZE(obj) - fixed; + if (index >= flexi) { hcl_seterrbfmt (hcl, HCL_EINVAL, "position(%zd) out of range - negative or greater than or equal to %zu", index, (hcl_ooi_t)HCL_OBJ_GET_SIZE(obj)); return HCL_PF_FAILURE; } + index += fixed; switch (HCL_OBJ_GET_FLAGS_TYPE(obj)) { @@ -135,7 +142,9 @@ static hcl_pfrc_t pf_core_basic_at_put (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t na { hcl_oop_t obj, val; hcl_oop_t pos; - hcl_ooi_t index; + hcl_oow_t index; + hcl_oop_class_t _class; + hcl_oow_t fixed, flexi; obj = HCL_STACK_GETARG(hcl, nargs, 0); pos = HCL_STACK_GETARG(hcl, nargs, 1); @@ -151,9 +160,19 @@ static hcl_pfrc_t pf_core_basic_at_put (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t na if (hcl_inttooow_noseterr(hcl, pos, &index) <= 0) { /* negative integer or not integer */ - hcl_seterrbfmt (hcl, HCL_EINVAL, "position not valid- %O", pos); + hcl_seterrbfmt (hcl, HCL_EINVAL, "position not valid - %O", pos); return HCL_PF_FAILURE; } + + _class = (hcl_oop_class_t)HCL_CLASSOF(hcl, obj); + fixed = HCL_CLASS_SPEC_NAMED_INSTVARS(_class->spec); + flexi = HCL_OBJ_GET_SIZE(obj) - fixed; + if (index >= flexi) + { + hcl_seterrbfmt (hcl, HCL_EINVAL, "position(%zd) out of range - negative or greater than or equal to %zu", index, (hcl_ooi_t)HCL_OBJ_GET_SIZE(obj)); + return HCL_PF_FAILURE; + } + index += fixed; if (index >= HCL_OBJ_GET_SIZE(obj)) { hcl_seterrbfmt (hcl, HCL_EINVAL, "position(%zd) out of range - negative or greater than or equal to %zu", index, (hcl_ooi_t)HCL_OBJ_GET_SIZE(obj));