diff --git a/bin/main.c b/bin/main.c index 1de5734..f07712a 100644 --- a/bin/main.c +++ b/bin/main.c @@ -205,9 +205,9 @@ static HCL_INLINE int open_input (hcl_t* hcl, hcl_ioinarg_t* arg) } #if defined(__DOS__) || defined(_WIN32) || defined(__OS2__) - bb->fp = fopen (bb->fn, "rb"); + bb->fp = fopen(bb->fn, "rb"); #else - bb->fp = fopen (bb->fn, "r"); + bb->fp = fopen(bb->fn, "r"); #endif if (!bb->fp) { @@ -223,6 +223,18 @@ static HCL_INLINE int open_input (hcl_t* hcl, hcl_ioinarg_t* arg) } arg->handle = bb; + +/* HACK */ + if (!arg->includer) + { + HCL_ASSERT (hcl, arg->name == HCL_NULL); + arg->name = hcl_dupbtooocstr(hcl, xtn->read_path, HCL_NULL); + /* ignore duplication failure */ +/* TODO: change the type of arg->name from const hcl_ooch_t* to hcl_ooch_t*. + * change its specification from [IN] only to [INOUT] in hcl_ioinarg_t. */ + } +/* END HACK */ + return 0; oops: @@ -242,6 +254,14 @@ static HCL_INLINE int close_input (hcl_t* hcl, hcl_ioinarg_t* arg) bb = (bb_t*)arg->handle; HCL_ASSERT (hcl, bb != HCL_NULL && bb->fp != HCL_NULL); +/* HACK */ + if (!arg->includer && arg->name) + { + hcl_freemem (hcl, arg->name); + arg->name = HCL_NULL; + } +/* END HACK */ + fclose (bb->fp); hcl_freemem (hcl, bb); diff --git a/lib/exec.c b/lib/exec.c index 86d8cf7..4bb4c9f 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -3387,37 +3387,6 @@ else HCL_STACK_PUSH (hcl, t); } -#if 0 - if (b1 == 1 || b1 == 3) - { - if (t3 == hcl->_nil) - { - ((hcl_oop_oop_t)t2)->slot[0] = t1; - if (b1 == 1) HCL_STACK_PUSH (hcl, t2); /* push self again */ - } - else - { - hcl_oop_t t; - - t = hcl_makecons(hcl, t1, hcl->_nil); - if (HCL_UNLIKELY(!t)) goto oops; - - ((hcl_oop_oop_t)t3)->slot[1] = t; - if (b1 == 1) HCL_STACK_PUSH (hcl, t); - } - } - else if (b1 == 2) - { - if (t3 == hcl->_nil) - { - ((hcl_oop_oop_t)t2)->slot[1] = t1; - } - else - { - ((hcl_oop_oop_t)t3)->slot[1] = t1; - } - } -#endif break; } diff --git a/lib/hcl.h b/lib/hcl.h index b0d22e6..e3124d9 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1167,7 +1167,7 @@ struct hcl_ioinarg_t /** * [OUT] place data here for #HCL_IO_READ */ - hcl_ooch_t buf[2048]; + hcl_ooch_t buf[2048]; /* TODO: resize this if necessary */ /** * [OUT] place the number of characters read here for #HCL_IO_READ diff --git a/lib/read.c b/lib/read.c index c579e0e..769c421 100644 --- a/lib/read.c +++ b/lib/read.c @@ -2066,6 +2066,26 @@ hcl_cnode_t* hcl_read (hcl_t* hcl) return read_object(hcl); } +/* ------------------------------------------------------------------------ */ + +hcl_iolxc_t* hcl_readchar (hcl_t* hcl) +{ + int n = get_char(hcl); + if (n <= -1) return HCL_NULL; + return &hcl->c->lxc; +} + +int hcl_unreadchar (hcl_t* hcl, const hcl_iolxc_t* c) +{ + if (hcl->c->nungots >= HCL_COUNTOF(hcl->c->ungot)) + { + hcl_seterrbfmt (hcl, HCL_EBUFFULL, "character unread buffer full"); + return -1; + } + + unget_char (hcl, c); + return 0; +} /* TODO: hcl_cnodetoobj (hcl_t* hcl, hcl_cnode_t* x) @@ -2073,8 +2093,9 @@ hcl_cnodetoobj (hcl_t* hcl, hcl_cnode_t* x) * drop location information and compose object ?? * is it doable? can convert a dotted symbol to a proper value? } -*/ - +*/ + +/* ------------------------------------------------------------------------ */ /* TODO: rename compiler to something else that can include reader, printer, and compiler * move compiler intialization/finalization here to more common place */ @@ -2297,21 +2318,3 @@ void hcl_detachio (hcl_t* hcl) } } -hcl_iolxc_t* hcl_readchar (hcl_t* hcl) -{ - int n = get_char(hcl); - if (n <= -1) return HCL_NULL; - return &hcl->c->lxc; -} - -int hcl_unreadchar (hcl_t* hcl, const hcl_iolxc_t* c) -{ - if (hcl->c->nungots >= HCL_COUNTOF(hcl->c->ungot)) - { - hcl_seterrbfmt (hcl, HCL_EBUFFULL, "character unread buffer full"); - return -1; - } - - unget_char (hcl, c); - return 0; -}