wrote more compiler mode to handle input in the cli mode
This commit is contained in:
45
lib/comp.c
45
lib/comp.c
@ -651,7 +651,8 @@ enum
|
||||
COP_POST_WHILE_BODY,
|
||||
COP_POST_WHILE_COND,
|
||||
|
||||
COP_UPDATE_BREAK
|
||||
COP_UPDATE_BREAK,
|
||||
COP_DO_NOTHING
|
||||
};
|
||||
|
||||
/* ========================================================================= */
|
||||
@ -1364,7 +1365,8 @@ static int compile_cons_xlist_expression (hcl_t* hcl, hcl_oop_t obj)
|
||||
* if the name is another function call, i can't know if the
|
||||
* function name will be valid at the compile time.
|
||||
*/
|
||||
HCL_ASSERT (hcl, HCL_IS_CONS_XLIST(hcl, obj));
|
||||
HCL_ASSERT (hcl, HCL_IS_CONS_CONCODED(hcl, obj, HCL_CONCODE_XLIST) ||
|
||||
HCL_IS_CONS_CONCODED(hcl, obj, HCL_CONCODE_EXPLIST));
|
||||
|
||||
car = HCL_CONS_CAR(obj);
|
||||
if (HCL_IS_SYMBOL(hcl,car) && (syncode = HCL_OBJ_GET_FLAGS_SYNCODE(car)))
|
||||
@ -1435,7 +1437,8 @@ static int compile_cons_xlist_expression (hcl_t* hcl, hcl_oop_t obj)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (HCL_IS_SYMBOL(hcl,car) || HCL_IS_CONS_XLIST(hcl,car) || ((hcl->option.trait & HCL_CLI_MODE) && HCL_IS_STRING(hcl, car)))
|
||||
else if (HCL_IS_SYMBOL(hcl,car) || HCL_IS_CONS_CONCODED(hcl,car,HCL_CONCODE_XLIST) ||
|
||||
((hcl->option.trait & HCL_CLI_MODE) && HCL_IS_STRING(hcl, car)))
|
||||
{
|
||||
/* normal function call
|
||||
* (<operator> <operand1> ...) */
|
||||
@ -1454,7 +1457,14 @@ static int compile_cons_xlist_expression (hcl_t* hcl, hcl_oop_t obj)
|
||||
oldtop = GET_TOP_CFRAME_INDEX(hcl);
|
||||
HCL_ASSERT (hcl, oldtop >= 0);
|
||||
|
||||
SWITCH_TOP_CFRAME (hcl, COP_EMIT_CALL, HCL_SMOOI_TO_OOP(0));
|
||||
if (HCL_IS_CONS_CONCODED(hcl,obj,HCL_CONCODE_EXPLIST))
|
||||
{
|
||||
SWITCH_TOP_CFRAME (hcl, COP_DO_NOTHING, hcl->_nil);
|
||||
}
|
||||
else
|
||||
{
|
||||
SWITCH_TOP_CFRAME (hcl, COP_EMIT_CALL, HCL_SMOOI_TO_OOP(0));
|
||||
}
|
||||
|
||||
/* compile <operator> */
|
||||
PUSH_CFRAME (hcl, COP_COMPILE_OBJECT, car);
|
||||
@ -1505,10 +1515,16 @@ static int compile_cons_xlist_expression (hcl_t* hcl, hcl_oop_t obj)
|
||||
/* redundant cdr check is performed inside compile_object_list() */
|
||||
PUSH_SUBCFRAME (hcl, COP_COMPILE_ARGUMENT_LIST, cdr);
|
||||
|
||||
/* patch the argument count in the operand field of the COP_EMIT_CALL frame */
|
||||
cf = GET_CFRAME(hcl, oldtop);
|
||||
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_CALL);
|
||||
cf->operand = HCL_SMOOI_TO_OOP(nargs);
|
||||
if (HCL_IS_CONS_CONCODED(hcl,obj,HCL_CONCODE_EXPLIST))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
/* patch the argument count in the operand field of the COP_EMIT_CALL frame */
|
||||
cf = GET_CFRAME(hcl, oldtop);
|
||||
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_CALL);
|
||||
cf->operand = HCL_SMOOI_TO_OOP(nargs);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1664,6 +1680,10 @@ static int compile_object (hcl_t* hcl)
|
||||
if (compile_cons_dic_expression(hcl, cf->operand) <= -1) return -1;
|
||||
break;
|
||||
|
||||
case HCL_CONCODE_EXPLIST:
|
||||
if (compile_cons_xlist_expression (hcl, cf->operand) <= -1) return -1;
|
||||
break;
|
||||
|
||||
/* TODO: QLIST? */
|
||||
default:
|
||||
if (compile_cons_xlist_expression (hcl, cf->operand) <= -1) return -1;
|
||||
@ -2531,7 +2551,7 @@ static HCL_INLINE int emit_pop_stacktop (hcl_t* hcl)
|
||||
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_POP_STACKTOP);
|
||||
HCL_ASSERT (hcl, HCL_IS_NIL(hcl, cf->operand));
|
||||
|
||||
n = emit_byte_instruction (hcl, HCL_CODE_POP_STACKTOP);
|
||||
n = emit_byte_instruction(hcl, HCL_CODE_POP_STACKTOP);
|
||||
|
||||
POP_CFRAME (hcl);
|
||||
return n;
|
||||
@ -2546,7 +2566,7 @@ static HCL_INLINE int emit_return (hcl_t* hcl)
|
||||
HCL_ASSERT (hcl, cf->opcode == COP_EMIT_RETURN);
|
||||
HCL_ASSERT (hcl, HCL_IS_NIL(hcl, cf->operand));
|
||||
|
||||
n = emit_byte_instruction (hcl, HCL_CODE_RETURN_FROM_BLOCK);
|
||||
n = emit_byte_instruction(hcl, HCL_CODE_RETURN_FROM_BLOCK);
|
||||
|
||||
POP_CFRAME (hcl);
|
||||
return n;
|
||||
@ -2739,6 +2759,11 @@ int hcl_compile (hcl_t* hcl, hcl_oop_t obj)
|
||||
if (update_break(hcl) <= -1) goto oops;
|
||||
break;
|
||||
|
||||
case COP_DO_NOTHING:
|
||||
/* do nothing but popping the current cframe */
|
||||
POP_CFRAME (hcl);
|
||||
break;
|
||||
|
||||
default:
|
||||
HCL_DEBUG1 (hcl, "Internal error - invalid compiler opcode %d\n", cf->opcode);
|
||||
hcl_seterrbfmt (hcl, HCL_EINTERN, "invalid compiler opcode %d", cf->opcode);
|
||||
|
Reference in New Issue
Block a user