delete operand `op_nop`
This commit is contained in:
parent
5f6051e333
commit
a4738e8c7d
|
@ -3,7 +3,7 @@
|
|||
|
||||
enum op_code
|
||||
{
|
||||
op_nop, // do nothing
|
||||
op_exit, // stop the virtual machine
|
||||
op_intg, // global scope size
|
||||
op_intl, // local scope size
|
||||
op_loadg, // load global value
|
||||
|
@ -77,8 +77,7 @@ enum op_code
|
|||
op_mupval, // get memory space of value in closure
|
||||
op_mcallv, // get memory space of vec[index]
|
||||
op_mcallh, // get memory space of hash.label
|
||||
op_ret, // return
|
||||
op_exit // stop the virtual machine
|
||||
op_ret // return
|
||||
};
|
||||
|
||||
struct
|
||||
|
@ -87,7 +86,7 @@ struct
|
|||
const char* name;
|
||||
}code_table[]=
|
||||
{
|
||||
{op_nop, "nop "},
|
||||
{op_exit, "exit "},
|
||||
{op_intg, "intg "},
|
||||
{op_intl, "intl "},
|
||||
{op_loadg, "loadg "},
|
||||
|
@ -162,7 +161,6 @@ struct
|
|||
{op_mcallv, "mcallv"},
|
||||
{op_mcallh, "mcallh"},
|
||||
{op_ret, "ret "},
|
||||
{op_exit, "exit "},
|
||||
{-1, nullptr },
|
||||
};
|
||||
|
||||
|
@ -172,7 +170,7 @@ struct opcode
|
|||
uint16_t fidx;// source code file index
|
||||
uint32_t num; // imm num
|
||||
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){}
|
||||
opcode& operator=(const opcode& tmp)
|
||||
{
|
||||
|
|
|
@ -105,7 +105,7 @@ void nasal_dbg::interact()
|
|||
<<"[debug] nasal debug mode\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;
|
||||
|
||||
if(
|
||||
|
@ -183,7 +183,7 @@ void nasal_dbg::run(
|
|||
init(gen.get_strs(),gen.get_nums(),gen.get_code(),linker.get_file());
|
||||
const void* opr_table[]=
|
||||
{
|
||||
&&nop, &&intg, &&intl, &&loadg,
|
||||
&&vmexit, &&intg, &&intl, &&loadg,
|
||||
&&loadl, &&loadu, &&pnum, &&pnil,
|
||||
&&pstr, &&newv, &&newh, &&newf,
|
||||
&&happ, &¶, &&defpara,&&dynpara,
|
||||
|
@ -201,7 +201,7 @@ void nasal_dbg::run(
|
|||
&&callvi, &&callh, &&callfv, &&callfh,
|
||||
&&callb, &&slcbegin, &&slcend, &&slc,
|
||||
&&slc2, &&mcallg, &&mcalll, &&mupval,
|
||||
&&mcallv, &&mcallh, &&ret, &&vmexit
|
||||
&&mcallv, &&mcallh, &&ret
|
||||
};
|
||||
std::vector<const void*> code;
|
||||
for(auto& i:gen.get_code())
|
||||
|
@ -221,7 +221,6 @@ vmexit:
|
|||
return;
|
||||
#define dbg(op) {interact();op();if(gc.top<canary)goto *code[++pc];goto vmexit;}
|
||||
|
||||
nop: dbg(opr_nop );
|
||||
intg: dbg(opr_intg );
|
||||
intl: dbg(opr_intl );
|
||||
loadg: dbg(opr_loadg );
|
||||
|
|
10
nasal_gc.h
10
nasal_gc.h
|
@ -87,8 +87,10 @@ struct nasal_ref
|
|||
|
||||
struct nasal_vec
|
||||
{
|
||||
uint32_t depth;
|
||||
std::vector<nasal_ref> elems;
|
||||
|
||||
nasal_vec():depth(0){}
|
||||
void print();
|
||||
nasal_ref get_val(const int);
|
||||
nasal_ref* get_mem(const int);
|
||||
|
@ -96,8 +98,10 @@ struct nasal_vec
|
|||
|
||||
struct nasal_hash
|
||||
{
|
||||
uint32_t depth;
|
||||
std::unordered_map<std::string,nasal_ref> elems;
|
||||
|
||||
nasal_hash():depth(0){}
|
||||
void print();
|
||||
nasal_ref get_val(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()
|
||||
{
|
||||
static int depth=0;
|
||||
if(!elems.size() || depth>8)
|
||||
if(!elems.size() || depth>3)
|
||||
{
|
||||
std::cout<<(elems.size()?"[..]":"[]");
|
||||
return;
|
||||
|
@ -231,8 +234,7 @@ nasal_ref* nasal_hash::get_mem(const std::string& key)
|
|||
}
|
||||
void nasal_hash::print()
|
||||
{
|
||||
static int depth=0;
|
||||
if(!elems.size() || depth>8)
|
||||
if(!elems.size() || depth>3)
|
||||
{
|
||||
std::cout<<(elems.size()?"{..}":"{}");
|
||||
return;
|
||||
|
|
|
@ -41,7 +41,6 @@ protected:
|
|||
/* vm calculation functions*/
|
||||
bool condition(nasal_ref);
|
||||
/* vm operands */
|
||||
void opr_nop();
|
||||
void opr_intg();
|
||||
void opr_intl();
|
||||
void opr_loadg();
|
||||
|
@ -322,7 +321,6 @@ inline bool nasal_vm::condition(nasal_ref val)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
inline void nasal_vm::opr_nop(){}
|
||||
inline void nasal_vm::opr_intg()
|
||||
{
|
||||
// global values store on stack
|
||||
|
@ -883,10 +881,10 @@ void nasal_vm::run(
|
|||
{
|
||||
detail_info=detail;
|
||||
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[]=
|
||||
{
|
||||
&&nop, &&intg, &&intl, &&loadg,
|
||||
&&vmexit, &&intg, &&intl, &&loadg,
|
||||
&&loadl, &&loadu, &&pnum, &&pnil,
|
||||
&&pstr, &&newv, &&newh, &&newf,
|
||||
&&happ, &¶, &&defpara,&&dynpara,
|
||||
|
@ -904,7 +902,7 @@ void nasal_vm::run(
|
|||
&&callvi, &&callh, &&callfv, &&callfh,
|
||||
&&callb, &&slcbegin, &&slcend, &&slc,
|
||||
&&slc2, &&mcallg, &&mcalll, &&mupval,
|
||||
&&mcallv, &&mcallh, &&ret, &&vmexit
|
||||
&&mcallv, &&mcallh, &&ret
|
||||
};
|
||||
std::vector<const void*> code;
|
||||
for(auto& i:gen.get_code())
|
||||
|
@ -930,7 +928,6 @@ vmexit:
|
|||
// do not cause stackoverflow
|
||||
#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)
|
||||
intl: exec_opnodie(opr_intl ,op_intl ); // -0
|
||||
loadg: exec_opnodie(opr_loadg ,op_loadg ); // -1
|
||||
|
|
|
@ -116,6 +116,7 @@ var curve4=func()
|
|||
}
|
||||
trans_ttf("just for test");
|
||||
trans_ttf(" ValKmjolnir ");
|
||||
trans_ttf("just for fun");
|
||||
curve1();
|
||||
curve2();
|
||||
curve3();
|
||||
|
|
Loading…
Reference in New Issue