diff --git a/lib/exec.c b/lib/exec.c index e3f92b1..b60f0fb 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -2203,7 +2203,7 @@ oops: return -1; } -int hcl_executefromip (hcl_t* hcl, hcl_ooi_t initial_ip) +hcl_oop_t hcl_executefromip (hcl_t* hcl, hcl_ooi_t initial_ip) { int n, log_default_type_mask; @@ -2215,7 +2215,7 @@ int hcl_executefromip (hcl_t* hcl, hcl_ooi_t initial_ip) hcl->last_retv = hcl->_nil; - if (start_initial_process_and_context(hcl, initial_ip) <= -1) return -1; + if (start_initial_process_and_context(hcl, initial_ip) <= -1) return HCL_NULL; hcl->initial_context = hcl->processor->active->initial_context; n = execute (hcl); @@ -2227,11 +2227,10 @@ int hcl_executefromip (hcl_t* hcl, hcl_ooi_t initial_ip) hcl->active_context = HCL_NULL; hcl->log.default_type_mask = log_default_type_mask; - return n; + return (n <= -1)? HCL_NULL: hcl->last_retv; } - -int hcl_execute (hcl_t* hcl) +hcl_oop_t hcl_execute (hcl_t* hcl) { return hcl_executefromip (hcl, 0); } diff --git a/lib/hcl.h b/lib/hcl.h index 4a2b6a9..608948a 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1450,21 +1450,15 @@ HCL_EXPORT int hcl_ignite ( /** * The hcl_execute() function executes an activated context. */ -HCL_EXPORT int hcl_execute ( +HCL_EXPORT hcl_oop_t hcl_execute ( hcl_t* hcl ); -HCL_EXPORT int hcl_executefromip ( +HCL_EXPORT hcl_oop_t hcl_executefromip ( hcl_t* hcl, hcl_ooi_t initial_ip ); -#if defined(HCL_HAVE_INLINE) - static HCL_INLINE hcl_oop_t hcl_getlastretv (hcl_t* hcl) { return hcl->last_retv; } -#else -# define hcl_getlastretv(hcl) ((hcl)->last_retv) -#endif - HCL_EXPORT int hcl_attachio ( hcl_t* hcl, hcl_ioimpl_t reader, diff --git a/lib/main.c b/lib/main.c index 21e6528..68cce04 100644 --- a/lib/main.c +++ b/lib/main.c @@ -1655,17 +1655,21 @@ int main (int argc, char* argv[]) } else if (xtn->reader_istty) { + hcl_oop_t retv; + hcl_decode (hcl, code_offset, hcl->code.bc.len); HCL_LOG0 (hcl, HCL_LOG_MNEMONIC, "------------------------------------------\n"); g_hcl = hcl; //setup_tick (); - if (hcl_executefromip(hcl, code_offset) <= -1) + + retv = hcl_executefromip(hcl, code_offset); + if (!retv) { hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: cannot execute - [%d] %js\n", hcl_geterrnum(hcl), hcl_geterrmsg(hcl)); } else { - hcl_logbfmt (hcl, HCL_LOG_STDERR, "OK: EXITED WITH %O\n", hcl_getlastretv(hcl)); + hcl_logbfmt (hcl, HCL_LOG_STDERR, "OK: EXITED WITH %O\n", retv); } //cancel_tick(); g_hcl = HCL_NULL; @@ -1675,19 +1679,24 @@ int main (int argc, char* argv[]) if (!xtn->reader_istty) { + hcl_oop_t retv; + hcl_decode (hcl, 0, hcl->code.bc.len); HCL_LOG2 (hcl, HCL_LOG_MNEMONIC, "BYTECODES hcl->code.bc.len = > %lu hcl->code.lit.len => %lu\n", (unsigned long int)hcl->code.bc.len, (unsigned long int)hcl->code.lit.len); g_hcl = hcl; //setup_tick (); - if (hcl_execute(hcl) <= -1) + + retv = hcl_execute(hcl); + if (!retv) { hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: cannot execute - [%d] %js\n", hcl_geterrnum(hcl), hcl_geterrmsg(hcl)); } else { - hcl_logbfmt (hcl, HCL_LOG_STDERR, "EXECUTION OK - EXITED WITH %O\n", hcl_getlastretv(hcl)); + hcl_logbfmt (hcl, HCL_LOG_STDERR, "EXECUTION OK - EXITED WITH %O\n", retv); } + //cancel_tick(); g_hcl = HCL_NULL; /*hcl_dumpsymtab (hcl);*/