From f8f063a68ca62054adf628ca467cb206fa9702d5 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 18 Sep 2025 01:09:04 +0900 Subject: [PATCH] updated the class-superclass compatibility check --- bin/hak.c | 10 ++-------- lib/bigint.c | 3 +-- lib/comp.c | 2 +- lib/exec.c | 8 +++++--- lib/fmt.c | 4 ++-- lib/read.c | 2 +- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/bin/hak.c b/bin/hak.c index ec566dd..c62fa9b 100644 --- a/bin/hak.c +++ b/bin/hak.c @@ -980,16 +980,10 @@ int main (int argc, char* argv[]) /*hakcb.vm_checkbc = vm_checkbc;*/ hak_regcb (hak, &hakcb); - if (logopt) - { - if (handle_logopt(hak, logopt) <= -1) goto oops; - } + if (logopt && handle_logopt(hak, logopt) <= -1) goto oops; #if defined(HAK_BUILD_DEBUG) - if (dbgopt) - { - if (handle_dbgopt(hak, dbgopt) <= -1) goto oops; - } + if (dbgopt && handle_dbgopt(hak, dbgopt) <= -1) goto oops; #endif if (show_info) diff --git a/lib/bigint.c b/lib/bigint.c index 591bbf1..d49cab9 100644 --- a/lib/bigint.c +++ b/lib/bigint.c @@ -693,7 +693,6 @@ static HAK_INLINE hak_oop_t make_bigint_with_ooi (hak_t* hak, hak_ooi_t i) } else { - w = -i; w = (i == HAK_TYPE_MIN(hak_ooi_t))? ((hak_oow_t)HAK_TYPE_MAX(hak_ooi_t) + 1): -i; hw[0] = w /*& HAK_LBMASK(hak_oow_t,HAK_LIW_BITS)*/; hw[1] = w >> HAK_LIW_BITS; @@ -4528,7 +4527,7 @@ hak_oop_t hak_strtoint (hak_t* hak, const hak_ooch_t* str, hak_oow_t len, int ra if (outlen > HAK_COUNTOF(hw)) { hwp = (hak_liw_t*)hak_allocmem(hak, outlen * HAK_SIZEOF(hak_liw_t)); - if (!hwp) return HAK_NULL; + if (HAK_UNLIKELY(!hwp)) return HAK_NULL; } else { diff --git a/lib/comp.c b/lib/comp.c index 0a2e2af..640ae31 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -4997,7 +4997,7 @@ done: return 0; } -static int compile_cons_mlist_expression (hak_t* hak, hak_cnode_t* obj, int nrets) +static int compile_cons_mlist_expression (hak_t* hak, hak_cnode_t* obj, hak_ooi_t nrets) { hak_cnode_t* car, * cdr, * rcv; hak_ooi_t nargs; diff --git a/lib/exec.c b/lib/exec.c index 5d0602f..5e1a016 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -2394,7 +2394,7 @@ static HAK_INLINE int do_throw (hak_t* hak, hak_oop_t val, hak_ooi_t ip) while (!HAK_CLSTACK_IS_EMPTY(hak)) HAK_CLSTACK_POP(hak); f = hak->active_function; - if (f->dbgi != hak->_nil) + if (f->dbgi != hak->_nil && ip >= 0) { hak_dbgi_t* dbgi; hak_loc_t loc; @@ -2416,7 +2416,7 @@ static HAK_INLINE int do_throw (hak_t* hak, hak_oop_t val, hak_ooi_t ip) /* output backtrace */ HAK_LOG0(hak, HAK_LOG_IC | HAK_LOG_INFO, "[BACKTRACE]\n"); c = hak->active_context; - if ((hak_oop_t)c != hak->_nil) + if ((hak_oop_t)c != hak->_nil && ip >= 0) { hak_ooi_t cip; @@ -3437,6 +3437,8 @@ static int execute (hak_t* hak) HAK_INIT_NTIME (&hak->gci.stat.mark, 0, 0); HAK_INIT_NTIME (&hak->gci.stat.sweep, 0, 0); + fetched_instruction_pointer = -1; + while (1) { /* stop requested or no more runnable process */ @@ -4135,7 +4137,7 @@ static int execute (hak_t* hak) super_spec = HAK_OOP_TO_SMOOI(((hak_oop_class_t)superclass)->spec); super_indexed_type = HAK_CLASS_SPEC_INDEXED_TYPE(super_spec); - if (super_indexed_type != b5) + if (HAK_CLASS_SPEC_NAMED_INSTVARS(super_spec) > 0 && super_indexed_type != b5) { /* TODO: include the class indexed type in the message .. */ hak_seterrbfmt(hak, HAK_ECALL, "incompatible %hs superclass %O with %hs class", diff --git a/lib/fmt.c b/lib/fmt.c index 403e3fc..bb80d83 100644 --- a/lib/fmt.c +++ b/lib/fmt.c @@ -1211,13 +1211,13 @@ static int fmt_outv (hak_t* hak, hak_fmtout_t* fmtout, va_list ap) if (fb.out.ptr == fb.out.sbuf) { fb.out.ptr = (hak_bch_t*)HAK_MMGR_ALLOC(fmtout->mmgr, HAK_SIZEOF(hak_bch_t) * (newcapa + 1)); - if (!fb.out.ptr) goto oops; + if (HAK_UNLIKELY(!fb.out.ptr)) goto oops; } else { hak_bch_t* tmpptr; tmpptr = (hak_bch_t*)HAK_MMGR_REALLOC(fmtout->mmgr, fb.out.ptr, HAK_SIZEOF(hak_bch_t) * (newcapa + 1)); - if (!tmpptr) goto oops; + if (HAK_UNLIKELY(!tmpptr)) goto oops; fb.out.ptr = tmpptr; } fb.out.capa = newcapa; diff --git a/lib/read.c b/lib/read.c index fec93e5..7ad63d9 100644 --- a/lib/read.c +++ b/lib/read.c @@ -2458,7 +2458,7 @@ static int flx_comment (hak_t* hak, hak_ooci_t c) * LANG_ENABLE_EOL mode. * TODO: Consider removing this check because not consuming it * in another mode doesn't cause a problem. */ - if ((hak->option.trait & HAK_TRAIT_LANG_ENABLE_EOL)) return 0; /* not consumed */ + if (hak->option.trait & HAK_TRAIT_LANG_ENABLE_EOL) return 0; /* not consumed */ } return 1; /* consumed */ }