From d535c8f7c4cc9c8a960bbf140e626df389b4a802 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Wed, 5 Jun 2024 23:12:38 +0800 Subject: [PATCH] :memo: use the same function table --- src/nasal_dbg.h | 93 ----------------------------------------------- src/nasal_vm.cpp | 95 +----------------------------------------------- src/nasal_vm.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 186 deletions(-) diff --git a/src/nasal_dbg.h b/src/nasal_dbg.h index 132c570..c554941 100644 --- a/src/nasal_dbg.h +++ b/src/nasal_dbg.h @@ -40,99 +40,6 @@ public: }; class dbg: public vm { -private: - typedef void (dbg::*nasal_vm_func)(); - const nasal_vm_func operand_function[op_ret + 1] = { - nullptr, - &dbg::o_repl, - &dbg::o_intl, - &dbg::o_loadg, - &dbg::o_loadl, - &dbg::o_loadu, - &dbg::o_dup, - &dbg::o_pnum, - &dbg::o_pnil, - &dbg::o_pstr, - &dbg::o_newv, - &dbg::o_newh, - &dbg::o_newf, - &dbg::o_happ, - &dbg::o_para, - &dbg::o_deft, - &dbg::o_dyn, - &dbg::o_lnot, - &dbg::o_usub, - &dbg::o_bnot, - &dbg::o_btor, - &dbg::o_btxor, - &dbg::o_btand, - &dbg::o_add, - &dbg::o_sub, - &dbg::o_mul, - &dbg::o_div, - &dbg::o_lnk, - &dbg::o_addc, - &dbg::o_subc, - &dbg::o_mulc, - &dbg::o_divc, - &dbg::o_lnkc, - &dbg::o_addeq, - &dbg::o_subeq, - &dbg::o_muleq, - &dbg::o_diveq, - &dbg::o_lnkeq, - &dbg::o_bandeq, - &dbg::o_boreq, - &dbg::o_bxoreq, - &dbg::o_addeqc, - &dbg::o_subeqc, - &dbg::o_muleqc, - &dbg::o_diveqc, - &dbg::o_lnkeqc, - &dbg::o_addecp, - &dbg::o_subecp, - &dbg::o_mulecp, - &dbg::o_divecp, - &dbg::o_lnkecp, - &dbg::o_meq, - &dbg::o_eq, - &dbg::o_neq, - &dbg::o_less, - &dbg::o_leq, - &dbg::o_grt, - &dbg::o_geq, - &dbg::o_lessc, - &dbg::o_leqc, - &dbg::o_grtc, - &dbg::o_geqc, - &dbg::o_pop, - &dbg::o_jmp, - &dbg::o_jt, - &dbg::o_jf, - &dbg::o_cnt, - &dbg::o_findex, - &dbg::o_feach, - &dbg::o_callg, - &dbg::o_calll, - &dbg::o_upval, - &dbg::o_callv, - &dbg::o_callvi, - &dbg::o_callh, - &dbg::o_callfv, - &dbg::o_callfh, - &dbg::o_callb, - &dbg::o_slcbeg, - &dbg::o_slcend, - &dbg::o_slc, - &dbg::o_slc2, - &dbg::o_mcallg, - &dbg::o_mcalll, - &dbg::o_mupval, - &dbg::o_mcallv, - &dbg::o_mcallh, - &dbg::o_ret - }; - private: enum class cmd_kind { cmd_error, diff --git a/src/nasal_vm.cpp b/src/nasal_vm.cpp index a5e2a46..0f25470 100644 --- a/src/nasal_vm.cpp +++ b/src/nasal_vm.cpp @@ -526,98 +526,7 @@ void vm::run(const codegen& gen, // goto the first operand goto *code[ctx.pc]; #else - typedef void (vm::*nafunc)(); - const nafunc oprs[] = { - nullptr, - &vm::o_repl, - &vm::o_intl, - &vm::o_loadg, - &vm::o_loadl, - &vm::o_loadu, - &vm::o_dup, - &vm::o_pnum, - &vm::o_pnil, - &vm::o_pstr, - &vm::o_newv, - &vm::o_newh, - &vm::o_newf, - &vm::o_happ, - &vm::o_para, - &vm::o_deft, - &vm::o_dyn, - &vm::o_lnot, - &vm::o_usub, - &vm::o_bnot, - &vm::o_btor, - &vm::o_btxor, - &vm::o_btand, - &vm::o_add, - &vm::o_sub, - &vm::o_mul, - &vm::o_div, - &vm::o_lnk, - &vm::o_addc, - &vm::o_subc, - &vm::o_mulc, - &vm::o_divc, - &vm::o_lnkc, - &vm::o_addeq, - &vm::o_subeq, - &vm::o_muleq, - &vm::o_diveq, - &vm::o_lnkeq, - &vm::o_bandeq, - &vm::o_boreq, - &vm::o_bxoreq, - &vm::o_addeqc, - &vm::o_subeqc, - &vm::o_muleqc, - &vm::o_diveqc, - &vm::o_lnkeqc, - &vm::o_addecp, - &vm::o_subecp, - &vm::o_mulecp, - &vm::o_divecp, - &vm::o_lnkecp, - &vm::o_meq, - &vm::o_eq, - &vm::o_neq, - &vm::o_less, - &vm::o_leq, - &vm::o_grt, - &vm::o_geq, - &vm::o_lessc, - &vm::o_leqc, - &vm::o_grtc, - &vm::o_geqc, - &vm::o_pop, - &vm::o_jmp, - &vm::o_jt, - &vm::o_jf, - &vm::o_cnt, - &vm::o_findex, - &vm::o_feach, - &vm::o_callg, - &vm::o_calll, - &vm::o_upval, - &vm::o_callv, - &vm::o_callvi, - &vm::o_callh, - &vm::o_callfv, - &vm::o_callfh, - &vm::o_callb, - &vm::o_slcbeg, - &vm::o_slcend, - &vm::o_slc, - &vm::o_slc2, - &vm::o_mcallg, - &vm::o_mcalll, - &vm::o_mupval, - &vm::o_mcallv, - &vm::o_mcallh, - &vm::o_ret - }; - std::vector code; + std::vector code; for(const auto& i : gen.codes()) { code.push_back(oprs[i.op]); imm.push_back(i.num); @@ -630,7 +539,7 @@ void vm::run(const codegen& gen, ++ctx.pc; } #endif - +// all nasal programs should end here vmexit: if (verbose) { ngc.info(); diff --git a/src/nasal_vm.h b/src/nasal_vm.h index f253075..392dfaa 100644 --- a/src/nasal_vm.h +++ b/src/nasal_vm.h @@ -176,6 +176,100 @@ protected: inline void o_mcallh(); inline void o_ret(); +protected: + // for debugger and MSVC(does not support labels as values) + typedef void (vm::*nasal_vm_func)(); + const nasal_vm_func operand_function[op_ret + 1] = { + nullptr, + &vm::o_repl, + &vm::o_intl, + &vm::o_loadg, + &vm::o_loadl, + &vm::o_loadu, + &vm::o_dup, + &vm::o_pnum, + &vm::o_pnil, + &vm::o_pstr, + &vm::o_newv, + &vm::o_newh, + &vm::o_newf, + &vm::o_happ, + &vm::o_para, + &vm::o_deft, + &vm::o_dyn, + &vm::o_lnot, + &vm::o_usub, + &vm::o_bnot, + &vm::o_btor, + &vm::o_btxor, + &vm::o_btand, + &vm::o_add, + &vm::o_sub, + &vm::o_mul, + &vm::o_div, + &vm::o_lnk, + &vm::o_addc, + &vm::o_subc, + &vm::o_mulc, + &vm::o_divc, + &vm::o_lnkc, + &vm::o_addeq, + &vm::o_subeq, + &vm::o_muleq, + &vm::o_diveq, + &vm::o_lnkeq, + &vm::o_bandeq, + &vm::o_boreq, + &vm::o_bxoreq, + &vm::o_addeqc, + &vm::o_subeqc, + &vm::o_muleqc, + &vm::o_diveqc, + &vm::o_lnkeqc, + &vm::o_addecp, + &vm::o_subecp, + &vm::o_mulecp, + &vm::o_divecp, + &vm::o_lnkecp, + &vm::o_meq, + &vm::o_eq, + &vm::o_neq, + &vm::o_less, + &vm::o_leq, + &vm::o_grt, + &vm::o_geq, + &vm::o_lessc, + &vm::o_leqc, + &vm::o_grtc, + &vm::o_geqc, + &vm::o_pop, + &vm::o_jmp, + &vm::o_jt, + &vm::o_jf, + &vm::o_cnt, + &vm::o_findex, + &vm::o_feach, + &vm::o_callg, + &vm::o_calll, + &vm::o_upval, + &vm::o_callv, + &vm::o_callvi, + &vm::o_callh, + &vm::o_callfv, + &vm::o_callfh, + &vm::o_callb, + &vm::o_slcbeg, + &vm::o_slcend, + &vm::o_slc, + &vm::o_slc2, + &vm::o_mcallg, + &vm::o_mcalll, + &vm::o_mupval, + &vm::o_mcallv, + &vm::o_mcallh, + &vm::o_ret + }; + public: /* constructor of vm instance */