delete operand `op_nop`

This commit is contained in:
ValKmjolnir 2022-02-16 23:27:22 +08:00
parent 5f6051e333
commit a4738e8c7d
5 changed files with 17 additions and 20 deletions

View File

@ -3,7 +3,7 @@
enum op_code enum op_code
{ {
op_nop, // do nothing op_exit, // stop the virtual machine
op_intg, // global scope size op_intg, // global scope size
op_intl, // local scope size op_intl, // local scope size
op_loadg, // load global value op_loadg, // load global value
@ -77,8 +77,7 @@ enum op_code
op_mupval, // get memory space of value in closure op_mupval, // get memory space of value in closure
op_mcallv, // get memory space of vec[index] op_mcallv, // get memory space of vec[index]
op_mcallh, // get memory space of hash.label op_mcallh, // get memory space of hash.label
op_ret, // return op_ret // return
op_exit // stop the virtual machine
}; };
struct struct
@ -87,7 +86,7 @@ struct
const char* name; const char* name;
}code_table[]= }code_table[]=
{ {
{op_nop, "nop "}, {op_exit, "exit "},
{op_intg, "intg "}, {op_intg, "intg "},
{op_intl, "intl "}, {op_intl, "intl "},
{op_loadg, "loadg "}, {op_loadg, "loadg "},
@ -162,7 +161,6 @@ struct
{op_mcallv, "mcallv"}, {op_mcallv, "mcallv"},
{op_mcallh, "mcallh"}, {op_mcallh, "mcallh"},
{op_ret, "ret "}, {op_ret, "ret "},
{op_exit, "exit "},
{-1, nullptr }, {-1, nullptr },
}; };
@ -172,7 +170,7 @@ struct opcode
uint16_t fidx;// source code file index uint16_t fidx;// source code file index
uint32_t num; // imm num uint32_t num; // imm num
uint32_t line;// line of source code uint32_t line;// line of source code
opcode(uint8_t o=op_nop,uint16_t f=0,uint32_t n=0,uint32_t l=0): opcode(uint8_t o=op_exit,uint16_t f=0,uint32_t n=0,uint32_t l=0):
op(o),fidx(f),num(n),line(l){} op(o),fidx(f),num(n),line(l){}
opcode& operator=(const opcode& tmp) opcode& operator=(const opcode& tmp)
{ {

View File

@ -105,7 +105,7 @@ void nasal_dbg::interact()
<<"[debug] nasal debug mode\n" <<"[debug] nasal debug mode\n"
<<"input \'h\' to get help\n"; <<"input \'h\' to get help\n";
} }
else if(bytecode[pc].op==op_nop || bytecode[pc].op==op_exit) else if(bytecode[pc].op==op_exit)
return; return;
if( if(
@ -183,7 +183,7 @@ void nasal_dbg::run(
init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file()); init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file());
const void* opr_table[]= const void* opr_table[]=
{ {
&&nop, &&intg, &&intl, &&loadg, &&vmexit, &&intg, &&intl, &&loadg,
&&loadl, &&loadu, &&pnum, &&pnil, &&loadl, &&loadu, &&pnum, &&pnil,
&&pstr, &&newv, &&newh, &&newf, &&pstr, &&newv, &&newh, &&newf,
&&happ, &&para, &&defpara,&&dynpara, &&happ, &&para, &&defpara,&&dynpara,
@ -201,7 +201,7 @@ void nasal_dbg::run(
&&callvi, &&callh, &&callfv, &&callfh, &&callvi, &&callh, &&callfv, &&callfh,
&&callb, &&slcbegin, &&slcend, &&slc, &&callb, &&slcbegin, &&slcend, &&slc,
&&slc2, &&mcallg, &&mcalll, &&mupval, &&slc2, &&mcallg, &&mcalll, &&mupval,
&&mcallv, &&mcallh, &&ret, &&vmexit &&mcallv, &&mcallh, &&ret
}; };
std::vector<const void*> code; std::vector<const void*> code;
for(auto& i:gen.get_code()) for(auto& i:gen.get_code())
@ -221,7 +221,6 @@ vmexit:
return; return;
#define dbg(op) {interact();op();if(gc.top<canary)goto *code[++pc];goto vmexit;} #define dbg(op) {interact();op();if(gc.top<canary)goto *code[++pc];goto vmexit;}
nop: dbg(opr_nop );
intg: dbg(opr_intg ); intg: dbg(opr_intg );
intl: dbg(opr_intl ); intl: dbg(opr_intl );
loadg: dbg(opr_loadg ); loadg: dbg(opr_loadg );

View File

@ -87,8 +87,10 @@ struct nasal_ref
struct nasal_vec struct nasal_vec
{ {
uint32_t depth;
std::vector<nasal_ref> elems; std::vector<nasal_ref> elems;
nasal_vec():depth(0){}
void print(); void print();
nasal_ref get_val(const int); nasal_ref get_val(const int);
nasal_ref* get_mem(const int); nasal_ref* get_mem(const int);
@ -96,8 +98,10 @@ struct nasal_vec
struct nasal_hash struct nasal_hash
{ {
uint32_t depth;
std::unordered_map<std::string,nasal_ref> elems; std::unordered_map<std::string,nasal_ref> elems;
nasal_hash():depth(0){}
void print(); void print();
nasal_ref get_val(const std::string&); nasal_ref get_val(const std::string&);
nasal_ref* get_mem(const std::string&); nasal_ref* get_mem(const std::string&);
@ -174,8 +178,7 @@ nasal_ref* nasal_vec::get_mem(const int index)
} }
void nasal_vec::print() void nasal_vec::print()
{ {
static int depth=0; if(!elems.size() || depth>3)
if(!elems.size() || depth>8)
{ {
std::cout<<(elems.size()?"[..]":"[]"); std::cout<<(elems.size()?"[..]":"[]");
return; return;
@ -231,8 +234,7 @@ nasal_ref* nasal_hash::get_mem(const std::string& key)
} }
void nasal_hash::print() void nasal_hash::print()
{ {
static int depth=0; if(!elems.size() || depth>3)
if(!elems.size() || depth>8)
{ {
std::cout<<(elems.size()?"{..}":"{}"); std::cout<<(elems.size()?"{..}":"{}");
return; return;

View File

@ -41,7 +41,6 @@ protected:
/* vm calculation functions*/ /* vm calculation functions*/
bool condition(nasal_ref); bool condition(nasal_ref);
/* vm operands */ /* vm operands */
void opr_nop();
void opr_intg(); void opr_intg();
void opr_intl(); void opr_intl();
void opr_loadg(); void opr_loadg();
@ -322,7 +321,6 @@ inline bool nasal_vm::condition(nasal_ref val)
} }
return false; return false;
} }
inline void nasal_vm::opr_nop(){}
inline void nasal_vm::opr_intg() inline void nasal_vm::opr_intg()
{ {
// global values store on stack // global values store on stack
@ -883,10 +881,10 @@ void nasal_vm::run(
{ {
detail_info=detail; detail_info=detail;
init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file()); init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file());
uint64_t count[op_exit+1]={0}; uint64_t count[op_ret+1]={0};
const void* opr_table[]= const void* opr_table[]=
{ {
&&nop, &&intg, &&intl, &&loadg, &&vmexit, &&intg, &&intl, &&loadg,
&&loadl, &&loadu, &&pnum, &&pnil, &&loadl, &&loadu, &&pnum, &&pnil,
&&pstr, &&newv, &&newh, &&newf, &&pstr, &&newv, &&newh, &&newf,
&&happ, &&para, &&defpara,&&dynpara, &&happ, &&para, &&defpara,&&dynpara,
@ -904,7 +902,7 @@ void nasal_vm::run(
&&callvi, &&callh, &&callfv, &&callfh, &&callvi, &&callh, &&callfv, &&callfh,
&&callb, &&slcbegin, &&slcend, &&slc, &&callb, &&slcbegin, &&slcend, &&slc,
&&slc2, &&mcallg, &&mcalll, &&mupval, &&slc2, &&mcallg, &&mcalll, &&mupval,
&&mcallv, &&mcallh, &&ret, &&vmexit &&mcallv, &&mcallh, &&ret
}; };
std::vector<const void*> code; std::vector<const void*> code;
for(auto& i:gen.get_code()) for(auto& i:gen.get_code())
@ -930,7 +928,6 @@ vmexit:
// do not cause stackoverflow // do not cause stackoverflow
#define exec_opnodie(op,num) {op();++count[num];goto *code[++pc];} #define exec_opnodie(op,num) {op();++count[num];goto *code[++pc];}
nop: exec_opnodie(opr_nop ,op_nop ); // 0
intg: exec_opnodie(opr_intg ,op_intg ); // +imm[pc] (detected at codegen) intg: exec_opnodie(opr_intg ,op_intg ); // +imm[pc] (detected at codegen)
intl: exec_opnodie(opr_intl ,op_intl ); // -0 intl: exec_opnodie(opr_intl ,op_intl ); // -0
loadg: exec_opnodie(opr_loadg ,op_loadg ); // -1 loadg: exec_opnodie(opr_loadg ,op_loadg ); // -1

View File

@ -116,6 +116,7 @@ var curve4=func()
} }
trans_ttf("just for test"); trans_ttf("just for test");
trans_ttf(" ValKmjolnir "); trans_ttf(" ValKmjolnir ");
trans_ttf("just for fun");
curve1(); curve1();
curve2(); curve2();
curve3(); curve3();