simplified the CLASS_LOAD instruction by chaining it with a PUSH instruction. now the class name part of the out-of-class method defintion refers to a normal variable
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
7001476e6d
commit
897042f7f7
38
lib/comp.c
38
lib/comp.c
@ -679,7 +679,6 @@ static int emit_single_param_instruction (hcl_t* hcl, int cmd, hcl_oow_t param_1
|
||||
case HCL_CODE_STORE_INTO_CVAR_M_X:
|
||||
case HCL_CODE_POP_INTO_CVAR_M_X:
|
||||
|
||||
case HCL_CODE_CLASS_LOAD_X:
|
||||
case HCL_CODE_CLASS_CMSTORE:
|
||||
case HCL_CODE_CLASS_CIMSTORE:
|
||||
case HCL_CODE_CLASS_IMSTORE:
|
||||
@ -5674,40 +5673,13 @@ static HCL_INLINE int post_lambda (hcl_t* hcl)
|
||||
hcl_oow_t index;
|
||||
hcl_oop_t lit, cons;
|
||||
|
||||
/* TODO: CLASS_LOAD_X must be emited before the defun method code instruction is emitted ? */
|
||||
/* treat this like a global variable for now */
|
||||
lit = hcl_makesymbol(hcl, HCL_CNODE_GET_TOKPTR(class_name), HCL_CNODE_GET_TOKLEN(class_name));
|
||||
if (HCL_UNLIKELY(!lit)) return -1;
|
||||
cons = (hcl_oop_t)hcl_getatsysdic(hcl, lit);
|
||||
if (!cons)
|
||||
{
|
||||
cons = (hcl_oop_t)hcl_putatsysdic(hcl, lit, hcl->_undef);
|
||||
if (HCL_UNLIKELY(!cons)) return -1;
|
||||
}
|
||||
/*
|
||||
2024-04-01 23:39:21 +0900 0000000041 make_lambda 0 0 0 0 0
|
||||
2024-04-01 23:39:21 +0900 0000000046 jump_forward 6
|
||||
2024-04-01 23:39:21 +0900 0000000055 store_into_object @4
|
||||
2024-04-01 23:39:21 +0900 0000000058 return_from_block
|
||||
/* treat the class name part as a normal variable.
|
||||
* it can be a global variable like 'String' or a local variable declared */
|
||||
if (compile_symbol(hcl, class_name) <= -1) return -1;
|
||||
|
||||
if (emit_byte_instruction(hcl, HCL_CODE_CLASS_LOAD, HCL_CNODE_GET_LOC(class_name)) <= -1) return -1;
|
||||
|
||||
2024-04-01 23:40:11 +0900 0000000041 make_lambda 0 0 0 0 0
|
||||
2024-04-01 23:40:11 +0900 0000000046 jump_forward 6
|
||||
2024-04-01 23:40:11 +0900 0000000055 class_load @2
|
||||
2024-04-01 23:40:11 +0900 0000000058 class_imstore 4
|
||||
2024-04-01 23:40:11 +0900 0000000061 class_exit
|
||||
2024-04-01 23:40:11 +0900 0000000062 return_from_block
|
||||
*/
|
||||
|
||||
if (add_literal(hcl, cons, &index) <= -1) return -1;
|
||||
if (emit_single_param_instruction(hcl, HCL_CODE_PUSH_OBJECT_0, index, HCL_CNODE_GET_LOC(class_name)) <= -1) return -1;
|
||||
|
||||
/* TODO: for class_name part is a local variable or something...
|
||||
if emit_variable_access(hcl, VAR_ACCESS_PUSH, &vi, HCL_CNODE_GET_LOC(obj)) <= -1) return -1;
|
||||
*/
|
||||
|
||||
if (emit_single_param_instruction(hcl, HCL_CODE_CLASS_LOAD_X, index, HCL_CNODE_GET_LOC(class_name)) <= -1) return -1;
|
||||
|
||||
/* the function name is always named */
|
||||
lit = hcl_makesymbol(hcl, HCL_CNODE_GET_TOKPTR(defun_name), HCL_CNODE_GET_TOKLEN(defun_name));
|
||||
if (HCL_UNLIKELY(!lit)) return -1;
|
||||
if (add_literal(hcl, lit, &index) <= -1) return -1;
|
||||
|
12
lib/decode.c
12
lib/decode.c
@ -373,16 +373,8 @@ int hcl_decode (hcl_t* hcl, const hcl_code_t* code, hcl_oow_t start, hcl_oow_t e
|
||||
LOG_INST_0 (hcl, "throw");
|
||||
break;
|
||||
/* -------------------------------------------------------- */
|
||||
case HCL_CODE_CLASS_LOAD_X2:
|
||||
FETCH_PARAM_CODE_TO (hcl, b1);
|
||||
FETCH_PARAM_CODE_TO (hcl, b2);
|
||||
b1 = (b1 << (8 * HCL_CODE_LONG_PARAM_SIZE)) | b2;
|
||||
goto class_load;
|
||||
|
||||
case HCL_CODE_CLASS_LOAD_X:
|
||||
FETCH_PARAM_CODE_TO (hcl, b1);
|
||||
class_load:
|
||||
LOG_INST_1 (hcl, "class_load @%zu", b1);
|
||||
case HCL_CODE_CLASS_LOAD:
|
||||
LOG_INST_0 (hcl, "class_load");
|
||||
break;
|
||||
|
||||
case HCL_CODE_CLASS_ENTER:
|
||||
|
45
lib/exec.c
45
lib/exec.c
@ -3542,7 +3542,7 @@ static int execute (hcl_t* hcl)
|
||||
LOG_INST_1 (hcl, "push_object @%zu", b1);
|
||||
if (HCL_IS_UNDEF(hcl, ass->cdr))
|
||||
{
|
||||
hcl_seterrbfmt (hcl, HCL_EUNDEFVAR, "%.*js accessed without initization", HCL_OBJ_GET_SIZE(ass->car), HCL_OBJ_GET_CHAR_SLOT(ass->car));
|
||||
hcl_seterrbfmt (hcl, HCL_EUNDEFVAR, "%.*js accessed without initialization", HCL_OBJ_GET_SIZE(ass->car), HCL_OBJ_GET_CHAR_SLOT(ass->car));
|
||||
if (do_throw_with_internal_errmsg(hcl, fetched_instruction_pointer) >= 0) break;
|
||||
goto oops_with_errmsg_supplement;
|
||||
}
|
||||
@ -3805,49 +3805,22 @@ static int execute (hcl_t* hcl)
|
||||
break;
|
||||
/* -------------------------------------------------------- */
|
||||
|
||||
case HCL_CODE_CLASS_LOAD_X2:
|
||||
FETCH_PARAM_CODE_TO (hcl, b1);
|
||||
FETCH_PARAM_CODE_TO (hcl, b2);
|
||||
b1 = (b1 << (8 * HCL_CODE_LONG_PARAM_SIZE)) | b2;
|
||||
goto class_load;
|
||||
|
||||
case HCL_CODE_CLASS_LOAD_X:
|
||||
case HCL_CODE_CLASS_LOAD:
|
||||
{
|
||||
hcl_oop_cons_t t;
|
||||
FETCH_PARAM_CODE_TO (hcl, b1);
|
||||
class_load:
|
||||
/* push the class indiciated by the literal at the given literal frame index
|
||||
* to the class stack */
|
||||
LOG_INST_1 (hcl, "class_load @%zu", b1);
|
||||
hcl_oop_t t;
|
||||
|
||||
#if 0
|
||||
t = (hcl_oop_cons_t)hcl->active_function->literal_frame[b1];
|
||||
if (!HCL_IS_CONS(hcl,t))
|
||||
{
|
||||
/* this is an uncatchable internal error that must not happen - is the bytecode compromised? */
|
||||
hcl_seterrbfmt(hcl, HCL_EINTERN, "internal error - invalid operand to CLASS_LOAD");
|
||||
goto oops_with_errmsg_supplement;
|
||||
}
|
||||
/* push the class off the stack top on the class stack */
|
||||
LOG_INST_0 (hcl, "class_load");
|
||||
|
||||
if (!HCL_IS_CLASS(hcl, t->cdr))
|
||||
HCL_STACK_POP_TO (hcl, t);
|
||||
if (!HCL_IS_CLASS(hcl, t))
|
||||
{
|
||||
hcl_seterrbfmt(hcl, HCL_EUNDEFVAR, "%.*js is not class", HCL_OBJ_GET_SIZE(t->car), HCL_OBJ_GET_CHAR_SLOT(t->car));
|
||||
if (do_throw_with_internal_errmsg(hcl, fetched_instruction_pointer) >= 0) break;
|
||||
goto oops_with_errmsg_supplement;
|
||||
}
|
||||
HCL_CLSTACK_PUSH (hcl, t->cdr);
|
||||
#else
|
||||
hcl_oop_t c;
|
||||
HCL_STACK_POP_TO (hcl, c);
|
||||
if (!HCL_IS_CLASS(hcl, c))
|
||||
{
|
||||
//hcl_seterrbfmt(hcl, HCL_EUNDEFVAR, "%.*js is not class", HCL_OBJ_GET_SIZE(t->car), HCL_OBJ_GET_CHAR_SLOT(t->car));
|
||||
/*hcl_seterrbfmt(hcl, HCL_EUNDEFVAR, "%.*js is not class", HCL_OBJ_GET_SIZE(t->car), HCL_OBJ_GET_CHAR_SLOT(t->car));*/
|
||||
hcl_seterrbfmt(hcl, HCL_EUNDEFVAR, "not class"); /* TODO: change error code */
|
||||
if (do_throw_with_internal_errmsg(hcl, fetched_instruction_pointer) >= 0) break;
|
||||
goto oops_with_errmsg_supplement;
|
||||
}
|
||||
HCL_CLSTACK_PUSH (hcl, c);
|
||||
#endif
|
||||
HCL_CLSTACK_PUSH (hcl, t);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1325,10 +1325,9 @@ enum hcl_bcode_t
|
||||
HCL_CODE_THROW = 0xDB, /* 219 */
|
||||
|
||||
HCL_CODE_POP_INTO_CTXTEMPVAR_X = 0xDC, /* 220 ## */
|
||||
HCL_CODE_CLASS_LOAD_X = 0xDD, /* 221 ## */
|
||||
HCL_CODE_CLASS_LOAD_X2 = 0xDE, /* 222 ## */
|
||||
HCL_CODE_CLASS_LOAD = 0xDD, /* 221 ## */
|
||||
|
||||
/* UNUSED - 0xDF - 0xDF */
|
||||
/* UNUSED - 0xDE - 0xDF */
|
||||
|
||||
HCL_CODE_PUSH_CTXTEMPVAR_X = 0xE0, /* 224 ## */
|
||||
HCL_CODE_CLASS_ENTER = 0xE1, /* 225 ## */
|
||||
|
@ -66,3 +66,21 @@ try { throw "1111"; } catch (e) ##ERROR: syntax error - block expression expecte
|
||||
try { throw "1111"; } catch (e) {
|
||||
printf "EXCEPTION - %s\n" e
|
||||
} 20 ##ERROR: syntax error - redundant expression prohibited after
|
||||
|
||||
---
|
||||
|
||||
{
|
||||
| a |
|
||||
|
||||
a := 30
|
||||
fun a:get_999() { ##ERROR: exception not handled - "not class"
|
||||
return 999;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
---
|
||||
|
||||
fun a:get_999() { ##ERROR: exception not handled - "a accessed without initialization"
|
||||
return 999;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user