fixing types of some fields in hcl_context_t and hcl_function_t for clarity and consistency
This commit is contained in:
parent
1b07957718
commit
a28553b195
31
lib/exec.c
31
lib/exec.c
@ -174,7 +174,7 @@ static HCL_INLINE hcl_oop_t make_function (hcl_t* hcl, hcl_oow_t lfsize, const h
|
||||
return hcl_allocoopobjwithtrailer(hcl, HCL_BRAND_FUNCTION, HCL_FUNCTION_NAMED_INSTVARS + lfsize, bptr, blen);
|
||||
}
|
||||
|
||||
static HCL_INLINE void fill_function_data (hcl_t* hcl, hcl_oop_function_t func, hcl_ooi_t nargs, hcl_ooi_t ntmprs, hcl_oop_t homectx, const hcl_oop_t* lfptr, hcl_oow_t lfsize)
|
||||
static HCL_INLINE void fill_function_data (hcl_t* hcl, hcl_oop_function_t func, hcl_ooi_t nargs, hcl_ooi_t ntmprs, hcl_oop_context_t homectx, const hcl_oop_t* lfptr, hcl_oow_t lfsize)
|
||||
{
|
||||
/* Although this function could be integrated into make_function(),
|
||||
* this function has been separated from make_function() to make GC handling simpler */
|
||||
@ -976,7 +976,7 @@ static int __activate_context (hcl_t* hcl, hcl_oop_context_t rcv_blkctx, hcl_ooi
|
||||
|
||||
HCL_STACK_POPS (hcl, nargs + 1); /* pop arguments and receiver */
|
||||
|
||||
HCL_ASSERT (hcl, (rcv_blkctx == hcl->initial_context && blkctx->home == hcl->_nil) || blkctx->home != hcl->_nil);
|
||||
HCL_ASSERT (hcl, (rcv_blkctx == hcl->initial_context && (hcl_oop_t)blkctx->home == hcl->_nil) || (hcl_oop_t)blkctx->home != hcl->_nil);
|
||||
blkctx->sp = HCL_SMOOI_TO_OOP(-1); /* not important at all */
|
||||
blkctx->sender = hcl->active_context;
|
||||
|
||||
@ -1054,7 +1054,7 @@ static int __activate_function (hcl_t* hcl, hcl_oop_function_t rcv_func, hcl_ooi
|
||||
|
||||
HCL_STACK_POPS (hcl, nargs + 1); /* pop arguments and receiver */
|
||||
|
||||
HCL_ASSERT (hcl, blkctx->home != hcl->_nil);
|
||||
HCL_ASSERT (hcl, (hcl_oop_t)blkctx->home != hcl->_nil);
|
||||
blkctx->sp = HCL_SMOOI_TO_OOP(-1); /* not important at all */
|
||||
blkctx->sender = hcl->active_context;
|
||||
|
||||
@ -1065,9 +1065,10 @@ static int __activate_function (hcl_t* hcl, hcl_oop_function_t rcv_func, hcl_ooi
|
||||
static HCL_INLINE int activate_function (hcl_t* hcl, hcl_ooi_t nargs)
|
||||
{
|
||||
int x;
|
||||
hcl_oop_context_t rcv, blkctx;
|
||||
hcl_oop_function_t rcv;
|
||||
hcl_oop_context_t blkctx;
|
||||
|
||||
rcv = (hcl_oop_context_t)HCL_STACK_GETRCV(hcl, nargs);
|
||||
rcv = (hcl_oop_function_t)HCL_STACK_GETRCV(hcl, nargs);
|
||||
HCL_ASSERT (hcl, HCL_IS_FUNCTION(hcl, rcv));
|
||||
|
||||
x = __activate_function(hcl, rcv, nargs, &blkctx);
|
||||
@ -1307,28 +1308,25 @@ 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;
|
||||
|
||||
/* create a fake initial context over the initial function */
|
||||
/* create the initial context over the initial function */
|
||||
ctx = (hcl_oop_context_t)make_context(hcl, 0); /* no temporary variables */
|
||||
if (!ctx) return -1;
|
||||
|
||||
/* the initial context starts the life of the entire VM
|
||||
* 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 = initial_ip;
|
||||
hcl->sp = -1;
|
||||
|
||||
ctx->ip = HCL_SMOOI_TO_OOP(initial_ip);
|
||||
ctx->sp = HCL_SMOOI_TO_OOP(-1); /* pointer to -1 below the bottom */
|
||||
/*ctx->nargs = (hcl_oop_t)mth;*/ /* fake. help SWITCH_ACTIVE_CONTEXT() not fail. */
|
||||
ctx->nargs = HCL_SMOOI_TO_OOP(0);
|
||||
ctx->ntmprs = HCL_SMOOI_TO_OOP(0);
|
||||
ctx->origin = hcl->initial_function;
|
||||
ctx->home = hcl->initial_function->home; /* this should be nil */
|
||||
HCL_ASSERT (hcl, ctx->home == hcl->_nil);
|
||||
ctx->sender = (hcl_oop_context_t)hcl->_nil;
|
||||
ctx->receiver_or_base = hcl->initial_function;
|
||||
HCL_ASSERT (hcl, (hcl_oop_t)ctx->home == hcl->_nil);
|
||||
|
||||
/* [NOTE]
|
||||
* the receiver field and the sender field of ctx are nils.
|
||||
* the sender field of the initial context is nil.
|
||||
* especially, the fact that the sender field is nil is used by
|
||||
* the main execution loop for breaking out of the loop */
|
||||
|
||||
@ -1355,8 +1353,9 @@ static int start_initial_process_and_context (hcl_t* hcl, hcl_ooi_t initial_ip)
|
||||
|
||||
HCL_ASSERT (hcl, proc == hcl->processor->active);
|
||||
hcl->initial_context = proc->initial_context;
|
||||
HCL_ASSERT (hcl, hcl->initial_context == hcl->active_context);
|
||||
|
||||
return activate_context(hcl, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -1879,7 +1878,7 @@ static int execute (hcl_t* hcl)
|
||||
ctx = (hcl_oop_context_t)ctx->home;
|
||||
/* the initial context has nil in the home field.
|
||||
* the loop must not reach beyond the initial context */
|
||||
HCL_ASSERT (hcl, ctx != hcl->_nil);
|
||||
HCL_ASSERT (hcl, (hcl_oop_t)ctx != hcl->_nil);
|
||||
}
|
||||
|
||||
if ((bcode >> 3) & 1)
|
||||
@ -2499,7 +2498,7 @@ hcl_oop_t hcl_execute (hcl_t* hcl)
|
||||
if (HCL_UNLIKELY(!func)) return HCL_NULL;
|
||||
|
||||
/* pass nil for the home context of the initial function */
|
||||
fill_function_data (hcl, func, 0, 0, hcl->_nil, hcl->code.lit.arr->slot, hcl->code.lit.len);
|
||||
fill_function_data (hcl, func, 0, 0, (hcl_oop_context_t)hcl->_nil, hcl->code.lit.arr->slot, hcl->code.lit.len);
|
||||
|
||||
hcl->initial_function = func;
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
41
lib/hcl.h
41
lib/hcl.h
@ -512,23 +512,6 @@ struct hcl_fpdec_t
|
||||
hcl_oop_t scale; /* smooi, positive */
|
||||
};
|
||||
|
||||
#define HCL_FUNCTION_NAMED_INSTVARS 3 /* this excludes literal frames and byte codes */
|
||||
typedef struct hcl_function_t hcl_function_t;
|
||||
typedef struct hcl_function_t* hcl_oop_function_t;
|
||||
struct hcl_function_t
|
||||
{
|
||||
HCL_OBJ_HEADER;
|
||||
|
||||
hcl_oop_t ntmprs; /* smooi */
|
||||
hcl_oop_t nargs; /* smooi */
|
||||
hcl_oop_t home; /* home function. nil for the initial function */
|
||||
|
||||
/* == variable indexed part == */
|
||||
hcl_oop_t literal_frame[1]; /* it stores literals. it may not exist */
|
||||
|
||||
/* after the literal frame comes the actual byte code */
|
||||
};
|
||||
|
||||
/* the first byte after the main payload is the trailer size
|
||||
* the code bytes are placed after the trailer size.
|
||||
*
|
||||
@ -538,9 +521,28 @@ struct hcl_function_t
|
||||
#define HCL_FUNCTION_GET_CODE_BYTE(m) HCL_OBJ_GET_TRAILER_BYTE(m)
|
||||
#define HCL_FUNCTION_GET_CODE_SIZE(m) HCL_OBJ_GET_TRAILER_SIZE(m)
|
||||
|
||||
#define HCL_FUNCTION_NAMED_INSTVARS 3 /* this excludes literal frames and byte codes */
|
||||
typedef struct hcl_function_t hcl_function_t;
|
||||
typedef struct hcl_function_t* hcl_oop_function_t;
|
||||
|
||||
#define HCL_CONTEXT_NAMED_INSTVARS 8
|
||||
typedef struct hcl_context_t hcl_context_t;
|
||||
typedef struct hcl_context_t* hcl_oop_context_t;
|
||||
|
||||
struct hcl_function_t
|
||||
{
|
||||
HCL_OBJ_HEADER;
|
||||
|
||||
hcl_oop_t ntmprs; /* smooi */
|
||||
hcl_oop_t nargs; /* smooi */
|
||||
hcl_oop_context_t home; /* home context. nil for the initial function */
|
||||
|
||||
/* == variable indexed part == */
|
||||
hcl_oop_t literal_frame[1]; /* it stores literals. it may not exist */
|
||||
|
||||
/* after the literal frame comes the actual byte code */
|
||||
};
|
||||
|
||||
struct hcl_context_t
|
||||
{
|
||||
HCL_OBJ_HEADER;
|
||||
@ -550,7 +552,7 @@ struct hcl_context_t
|
||||
* is activated as a result of normal message sending and a block
|
||||
* context is activated when it is sent 'value'. it's set to
|
||||
* nil if a block context created hasn't received 'value'. */
|
||||
hcl_oop_context_t sender;
|
||||
hcl_oop_context_t sender; /* context or nil */
|
||||
|
||||
/* SmallInteger, instruction pointer */
|
||||
hcl_oop_t ip;
|
||||
@ -577,7 +579,7 @@ struct hcl_context_t
|
||||
* moment the block context was created. that is, it points to
|
||||
* a method context where the base block has been defined.
|
||||
* an activated block context copies this field from the base block context. */
|
||||
hcl_oop_t home;
|
||||
hcl_oop_context_t home; /* context or nil */
|
||||
|
||||
/* it points to the method context created of the method defining the code
|
||||
* of this context. a method context points to itself. a block context
|
||||
@ -598,7 +600,6 @@ struct hcl_context_t
|
||||
hcl_oop_t slot[1]; /* stack */
|
||||
};
|
||||
|
||||
|
||||
#define HCL_PROCESS_NAMED_INSTVARS 8 /* TODO: RENAME THIS TO SOMETHING ELSE */
|
||||
typedef struct hcl_process_t hcl_process_t;
|
||||
typedef struct hcl_process_t* hcl_oop_process_t;
|
||||
|
Loading…
Reference in New Issue
Block a user