From 49363231a1dcab611582dff59dda81006e24a609 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 8 Feb 2018 10:33:59 +0000 Subject: [PATCH] added hcl_executefromip() --- lib/exec.c | 13 +++++++++---- lib/hcl.h | 5 +++++ lib/main.c | 8 +++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/exec.c b/lib/exec.c index c68b4c4..759d0e1 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -1148,7 +1148,7 @@ static hcl_oop_process_t start_initial_process (hcl_t* hcl, hcl_oop_context_t ct return proc; } -static int start_initial_process_and_context (hcl_t* hcl) +static int start_initial_process_and_context (hcl_t* hcl, hcl_ooi_t initial_ip) { hcl_oop_context_t ctx; hcl_oop_process_t proc; @@ -1161,7 +1161,7 @@ static int start_initial_process_and_context (hcl_t* hcl) * and is not really worked on except that it is used to call the * initial method. so it doesn't really require any extra stack space. */ /* TODO: verify this theory of mine. */ - hcl->ip = 0; + hcl->ip = initial_ip; hcl->sp = -1; ctx->ip = HCL_SMOOI_TO_OOP(0); /* point to the beginning */ @@ -2416,14 +2416,14 @@ oops: return -1; } -int hcl_execute (hcl_t* hcl) +int hcl_executefromip (hcl_t* hcl, hcl_ooi_t initial_ip) { int n; HCL_ASSERT (hcl, hcl->initial_context == HCL_NULL); HCL_ASSERT (hcl, hcl->active_context == HCL_NULL); - if (start_initial_process_and_context (hcl) <= -1) return -1; + if (start_initial_process_and_context(hcl, initial_ip) <= -1) return -1; hcl->initial_context = hcl->processor->active->initial_context; n = execute (hcl); @@ -2434,3 +2434,8 @@ int hcl_execute (hcl_t* hcl) return n; } + +int hcl_execute (hcl_t* hcl) +{ + return hcl_executefromip (hcl, 0); +} diff --git a/lib/hcl.h b/lib/hcl.h index a1c2b6b..9de2bce 100644 --- a/lib/hcl.h +++ b/lib/hcl.h @@ -1557,6 +1557,11 @@ HCL_EXPORT int hcl_execute ( hcl_t* hcl ); +HCL_EXPORT int hcl_executefromip ( + hcl_t* hcl, + hcl_ooi_t initial_ip +); + /** * The hcl_invoke() function sends a message named \a mthname to an object * named \a objname. diff --git a/lib/main.c b/lib/main.c index 889faa1..9cd409b 100644 --- a/lib/main.c +++ b/lib/main.c @@ -1029,6 +1029,10 @@ int main (int argc, char* argv[]) } else { + hcl_oow_t code_offset; + + code_offset = hcl->code.bc.len; + hcl_proutbfmt (hcl, 0, "\n"); if (hcl_compile(hcl, obj) <= -1) { @@ -1041,6 +1045,8 @@ int main (int argc, char* argv[]) hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: cannot compile object - [%d] %js\n", hcl_geterrnum(hcl), hcl_geterrmsg(hcl)); } /* carry on? */ + + hcl->code.bc.len = code_offset; /* just in case */ } else { @@ -1048,7 +1054,7 @@ int main (int argc, char* argv[]) HCL_LOG0 (hcl, HCL_LOG_MNEMONIC, "------------------------------------------\n"); g_hcl = hcl; //setup_tick (); - if (hcl_execute(hcl) <= -1) + if (hcl_executefromip(hcl, code_offset) <= -1) { hcl_logbfmt (hcl, HCL_LOG_STDERR, "ERROR: cannot execute - [%d] %js\n", hcl_geterrnum(hcl), hcl_geterrmsg(hcl)); }