adding some experimental code

This commit is contained in:
hyung-hwan 2020-09-19 11:55:58 +00:00
parent e8ac460f59
commit e6be071a54
2 changed files with 36 additions and 16 deletions

View File

@ -164,7 +164,7 @@ static int emit_byte_instruction (hcl_t* hcl, hcl_oob_t bc)
/* the context object has the ip field. it should be representable /* the context object has the ip field. it should be representable
* in a small integer. for simplicity, limit the total byte code length * in a small integer. for simplicity, limit the total byte code length
* to fit in a small integer. because 'ip' points to the next instruction * to fit in a small integer. because 'ip' points to the next instruction
* to execute, he upper bound should be (max - 1) so that i stays * to execute, the upper bound should be (max - 1) so that 'ip' stays
* at the max when incremented */ * at the max when incremented */
if (hcl->code.bc.len == HCL_SMOOI_MAX - 1) if (hcl->code.bc.len == HCL_SMOOI_MAX - 1)
{ {
@ -179,7 +179,7 @@ static int emit_byte_instruction (hcl_t* hcl, hcl_oob_t bc)
hcl_oow_t newcapa; hcl_oow_t newcapa;
newcapa = HCL_ALIGN(capa + 1, HCL_BC_BUFFER_ALIGN); newcapa = HCL_ALIGN(capa + 1, HCL_BC_BUFFER_ALIGN);
tmp = hcl_remakengcbytearray (hcl, (hcl_oop_t)hcl->code.bc.arr, newcapa); tmp = hcl_remakengcbytearray(hcl, (hcl_oop_t)hcl->code.bc.arr, newcapa);
if (!tmp) return -1; if (!tmp) return -1;
hcl->code.bc.arr = (hcl_oop_byte_t)tmp; hcl->code.bc.arr = (hcl_oop_byte_t)tmp;
@ -414,16 +414,16 @@ static int emit_push_literal (hcl_t* hcl, hcl_oop_t obj)
switch (i) switch (i)
{ {
case -1: case -1:
return emit_byte_instruction (hcl, HCL_CODE_PUSH_NEGONE); return emit_byte_instruction(hcl, HCL_CODE_PUSH_NEGONE);
case 0: case 0:
return emit_byte_instruction (hcl, HCL_CODE_PUSH_ZERO); return emit_byte_instruction(hcl, HCL_CODE_PUSH_ZERO);
case 1: case 1:
return emit_byte_instruction (hcl, HCL_CODE_PUSH_ONE); return emit_byte_instruction(hcl, HCL_CODE_PUSH_ONE);
case 2: case 2:
return emit_byte_instruction (hcl, HCL_CODE_PUSH_TWO); return emit_byte_instruction(hcl, HCL_CODE_PUSH_TWO);
} }
if (i >= 0 && i <= MAX_CODE_PARAM) if (i >= 0 && i <= MAX_CODE_PARAM)
@ -993,7 +993,7 @@ static int compile_lambda (hcl_t* hcl, hcl_oop_t src, int defun)
return -1; return -1;
} }
if (add_temporary_variable (hcl, ((hcl_oop_oop_t)dcl)->slot[i], tv_dup_start) <= -1) if (add_temporary_variable(hcl, ((hcl_oop_oop_t)dcl)->slot[i], tv_dup_start) <= -1)
{ {
if (hcl->errnum == HCL_EEXIST) if (hcl->errnum == HCL_EEXIST)
{ {
@ -1026,19 +1026,19 @@ static int compile_lambda (hcl_t* hcl, hcl_oop_t src, int defun)
return -1; return -1;
} }
hcl->c->blk.depth++; hcl->c->blk.depth++;
if (store_temporary_variable_count_for_block (hcl, hcl->c->tv.size) <= -1) return -1; if (store_temporary_variable_count_for_block(hcl, hcl->c->tv.size) <= -1) return -1;
/* use the accumulated number of temporaries so far when generating /* use the accumulated number of temporaries so far when generating
* the make_block instruction. at context activation time, the actual * the make_block instruction. at context activation time, the actual
* count of temporaries for this block is derived by subtracting the * count of temporaries for this block is derived by subtracting the
* count of temporaries in the home context */ * count of temporaries in the home context */
if (emit_double_param_instruction (hcl, HCL_CODE_MAKE_BLOCK, nargs, hcl->c->tv.size/*ntmprs*/) <= -1) return -1; if (emit_double_param_instruction(hcl, HCL_CODE_MAKE_BLOCK, nargs, hcl->c->tv.size/*ntmprs*/) <= -1) return -1;
HCL_ASSERT (hcl, hcl->code.bc.len < HCL_SMOOI_MAX); /* guaranteed in emit_byte_instruction() */ HCL_ASSERT (hcl, hcl->code.bc.len < HCL_SMOOI_MAX); /* guaranteed in emit_byte_instruction() */
jump_inst_pos = hcl->code.bc.len; jump_inst_pos = hcl->code.bc.len;
/* specifying MAX_CODE_JUMP causes emit_single_param_instruction() to /* specifying MAX_CODE_JUMP causes emit_single_param_instruction() to
* produce the long jump instruction (BCODE_JUMP_FORWARD_X) */ * produce the long jump instruction (BCODE_JUMP_FORWARD_X) */
if (emit_single_param_instruction (hcl, HCL_CODE_JUMP_FORWARD_0, MAX_CODE_JUMP) <= -1) return -1; if (emit_single_param_instruction(hcl, HCL_CODE_JUMP_FORWARD_0, MAX_CODE_JUMP) <= -1) return -1;
SWITCH_TOP_CFRAME (hcl, COP_COMPILE_OBJECT_LIST, obj); SWITCH_TOP_CFRAME (hcl, COP_COMPILE_OBJECT_LIST, obj);
@ -1264,7 +1264,7 @@ static int compile_while (hcl_t* hcl, hcl_oop_t src, int next_cop)
static int compile_cons_array_expression (hcl_t* hcl, hcl_oop_t obj) static int compile_cons_array_expression (hcl_t* hcl, hcl_oop_t obj)
{ {
/* #[ ] */ /* [ ] */
hcl_ooi_t nargs; hcl_ooi_t nargs;
hcl_cframe_t* cf; hcl_cframe_t* cf;
@ -1295,7 +1295,7 @@ static int compile_cons_array_expression (hcl_t* hcl, hcl_oop_t obj)
static int compile_cons_bytearray_expression (hcl_t* hcl, hcl_oop_t obj) static int compile_cons_bytearray_expression (hcl_t* hcl, hcl_oop_t obj)
{ {
/* #[ ] */ /* #[ ] - e.g. #[1, 2, 3] or #[ 1 2 3 ] */
hcl_ooi_t nargs; hcl_ooi_t nargs;
hcl_cframe_t* cf; hcl_cframe_t* cf;
@ -1326,7 +1326,7 @@ static int compile_cons_bytearray_expression (hcl_t* hcl, hcl_oop_t obj)
static int compile_cons_dic_expression (hcl_t* hcl, hcl_oop_t obj) static int compile_cons_dic_expression (hcl_t* hcl, hcl_oop_t obj)
{ {
/* #{ } */ /* { } - e.g. {1:2, 3:4,"abc":def, "hwaddr":"00:00:00:01"} or { 1 2 3 4 } */
hcl_ooi_t nargs; hcl_ooi_t nargs;
hcl_cframe_t* cf; hcl_cframe_t* cf;
@ -1629,7 +1629,7 @@ static int compile_object (hcl_t* hcl)
break; break;
case HCL_CONCODE_BYTEARRAY: case HCL_CONCODE_BYTEARRAY:
if (compile_cons_bytearray_expression (hcl, cf->operand) <= -1) return -1; if (compile_cons_bytearray_expression(hcl, cf->operand) <= -1) return -1;
break; break;
case HCL_CONCODE_DIC: case HCL_CONCODE_DIC:
@ -1638,7 +1638,7 @@ static int compile_object (hcl_t* hcl)
/* TODO: QLIST? */ /* TODO: QLIST? */
default: default:
if (compile_cons_xlist_expression (hcl, cf->operand) <= -1) return -1; if (compile_cons_xlist_expression(hcl, cf->operand) <= -1) return -1;
break; break;
} }
break; break;

View File

@ -2277,6 +2277,26 @@ static int execute (hcl_t* hcl)
HCL_ASSERT (hcl, b1 >= 0); HCL_ASSERT (hcl, b1 >= 0);
HCL_ASSERT (hcl, b2 >= b1); HCL_ASSERT (hcl, b2 >= b1);
#if 0
/* the MAKE_BLOCK instruction is followed by the long JUMP_FORWARD_X instruction.
* i can decode the instruction and get the size of instructions
* of the block context */
{
hcl_oow_t joff;
HCL_ASSERT (hcl, hcl->code.bc.arr->slot[hcl->ip] == HCL_CODE_JUMP_FORWARD_X);
joff = hcl->code.bc.arr->slot[hcl->ip + 1];
#if (HCL_BCODE_LONG_PARAM_SIZE == 2)
joff = (joff << 8) | hcl->code.bc.arr->slot[hcl->ip + 2];
#endif
HCL_DEBUG1(hcl, "**** MAKE BLOCK joff = %zu\n", joff);
}
#endif
/* the block context object created here is used as a base /* the block context object created here is used as a base
* object for block context activation. activate_context() * object for block context activation. activate_context()
* clones a block context and activates the cloned context. * clones a block context and activates the cloned context.