added hcl_executefromip()

This commit is contained in:
hyung-hwan 2018-02-08 10:33:59 +00:00
parent 08d6f4b4ad
commit 49363231a1
3 changed files with 21 additions and 5 deletions

View File

@ -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);
}

View File

@ -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.

View File

@ -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));
}