From 816b6d54f45ed3c413be17a826665bbe12253f77 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 16 Mar 2024 17:00:34 +0900 Subject: [PATCH] wip - class_load instruction for out-of-class method definition --- lib/decode.c | 12 ++++++++++++ lib/exec.c | 25 +++++++++++++++++++++++++ lib/hcl-prv.h | 5 ++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/decode.c b/lib/decode.c index eea30d0..a0cd523 100644 --- a/lib/decode.c +++ b/lib/decode.c @@ -373,6 +373,18 @@ 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); + break; + case HCL_CODE_CLASS_ENTER: { hcl_oow_t b3; diff --git a/lib/exec.c b/lib/exec.c index 8aa9a0f..be2e08a 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -3797,6 +3797,31 @@ if (do_throw(hcl, hcl->_nil, fetched_instruction_pointer) <= -1) 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: + { + hcl_oop_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); + /* this literal must be a symbol. find a class with the symbol and push it */ + t = hcl->active_function->literal_frame[b1]; + if (!t || !HCL_IS_SYMBOL(hcl, t)) + { + /* TODO: critical vm error.. */ + } + /* TODO: find class with this name */ + HCL_CLSTACK_PUSH (hcl, t); + break; + } + case HCL_CODE_CLASS_ENTER: { /* push superclass diff --git a/lib/hcl-prv.h b/lib/hcl-prv.h index b793ed8..70aefa9 100644 --- a/lib/hcl-prv.h +++ b/lib/hcl-prv.h @@ -1324,7 +1324,10 @@ enum hcl_bcode_t HCL_CODE_THROW = 0xDB, /* 219 */ HCL_CODE_POP_INTO_CTXTEMPVAR_X = 0xDC, /* 220 ## */ - /* UNUSED - 0xDD - 0xDF */ + HCL_CODE_CLASS_LOAD_X = 0xDD, /* 221 ## */ + HCL_CODE_CLASS_LOAD_X2 = 0xDE, /* 222 ## */ + + /* UNUSED - 0xDF - 0xDF */ HCL_CODE_PUSH_CTXTEMPVAR_X = 0xE0, /* 224 ## */ HCL_CODE_CLASS_ENTER = 0xE1, /* 225 ## */