This commit is contained in:
ValKmjolnir 2021-07-14 01:24:15 +08:00
parent 590c595522
commit 8b8e72c879
1 changed files with 84 additions and 80 deletions

View File

@ -672,8 +672,11 @@ inline void nasal_vm::opr_callfv()
return; return;
} }
// if args_size>para_size,for 0 to args_size will cause corruption // if args_size>para_size,for 0 to args_size will cause corruption
for(int i=0;i<para_size;++i) int min_size=std::min(para_size,args_size);
ref_closure[i+offset]=(i<args_size)?vec[i]:ref_default[i]; for(int i=0;i<min_size;++i)
ref_closure[i+offset]=vec[i];
for(int i=args_size;i<para_size;++i)
ref_closure[i+offset]=ref_default[i];
// load dynamic argument if args_size>=para_size // load dynamic argument if args_size>=para_size
if(ref_func.dynpara>=0) if(ref_func.dynpara>=0)
{ {
@ -872,7 +875,7 @@ inline void nasal_vm::opr_ret()
} }
void nasal_vm::run(std::vector<opcode>& exec) void nasal_vm::run(std::vector<opcode>& exec)
{ {
// int count[op_ret+1]={0}; uint32_t count[op_ret+1]={0};
void* opr_table[]= void* opr_table[]=
{ {
&&nop, &&intg, &&intl, &&offset, &&nop, &&intg, &&intl, &&offset,
@ -915,7 +918,7 @@ nop:
// for(int i=0;i<15;++i) // for(int i=0;i<15;++i)
// { // {
// int maxnum=0,index=0; // int maxnum=0,index=0;
// for(int j=0;j<62;++j) // for(int j=0;j<op_ret+1;++j)
// if(count[j]>maxnum) // if(count[j]>maxnum)
// { // {
// index=j; // index=j;
@ -925,81 +928,82 @@ nop:
// count[index]=0; // count[index]=0;
// } // }
return; return;
#define exec_operand(op,num) {op();/*++count[num];*/if(!canary[0])goto *code[++pc];goto nop;} //#define exec_operand(op,num) {op();++count[num];if(!canary[0])goto *code[++pc];goto nop;}
intg: exec_operand(opr_intg ,1); #define exec_operand(op,num) {op();if(!canary[0])goto *code[++pc];goto nop;}
intl: exec_operand(opr_intl ,2); intg: exec_operand(opr_intg ,op_intg);
offset: exec_operand(opr_offset ,3); intl: exec_operand(opr_intl ,op_intl);
loadg: exec_operand(opr_loadg ,4); offset: exec_operand(opr_offset ,op_offset);
loadl: exec_operand(opr_loadl ,5); loadg: exec_operand(opr_loadg ,op_loadg);
pnum: exec_operand(opr_pnum ,6); loadl: exec_operand(opr_loadl ,op_loadl);
pone: exec_operand(opr_pone ,7); pnum: exec_operand(opr_pnum ,op_pnum);
pzero: exec_operand(opr_pzero ,8); pone: exec_operand(opr_pone ,op_pone);
pnil: exec_operand(opr_pnil ,9); pzero: exec_operand(opr_pzero ,op_pzero);
pstr: exec_operand(opr_pstr ,10); pnil: exec_operand(opr_pnil ,op_pnil);
newv: exec_operand(opr_newv ,11); pstr: exec_operand(opr_pstr ,op_pstr);
newh: exec_operand(opr_newh ,12); newv: exec_operand(opr_newv ,op_newv);
newf: exec_operand(opr_newf ,13); newh: exec_operand(opr_newh ,op_newh);
happ: exec_operand(opr_happ ,14); newf: exec_operand(opr_newf ,op_newf);
para: exec_operand(opr_para ,15); happ: exec_operand(opr_happ ,op_happ);
defpara: exec_operand(opr_defpara ,16); para: exec_operand(opr_para ,op_para);
dynpara: exec_operand(opr_dynpara ,17); defpara: exec_operand(opr_defpara ,op_defpara);
unot: exec_operand(opr_unot ,18); dynpara: exec_operand(opr_dynpara ,op_dynpara);
usub: exec_operand(opr_usub ,19); unot: exec_operand(opr_unot ,op_unot);
add: exec_operand(opr_add ,20); usub: exec_operand(opr_usub ,op_usub);
sub: exec_operand(opr_sub ,21); add: exec_operand(opr_add ,op_add);
mul: exec_operand(opr_mul ,22); sub: exec_operand(opr_sub ,op_sub);
div: exec_operand(opr_div ,23); mul: exec_operand(opr_mul ,op_mul);
lnk: exec_operand(opr_lnk ,24); div: exec_operand(opr_div ,op_div);
addc: exec_operand(opr_addc ,25); lnk: exec_operand(opr_lnk ,op_lnk);
subc: exec_operand(opr_subc ,26); addc: exec_operand(opr_addc ,op_addc);
mulc: exec_operand(opr_mulc ,27); subc: exec_operand(opr_subc ,op_subc);
divc: exec_operand(opr_divc ,28); mulc: exec_operand(opr_mulc ,op_mulc);
lnkc: exec_operand(opr_lnkc ,29); divc: exec_operand(opr_divc ,op_divc);
addeq: exec_operand(opr_addeq ,30); lnkc: exec_operand(opr_lnkc ,op_lnkc);
subeq: exec_operand(opr_subeq ,31); addeq: exec_operand(opr_addeq ,op_addeq);
muleq: exec_operand(opr_muleq ,32); subeq: exec_operand(opr_subeq ,op_subeq);
diveq: exec_operand(opr_diveq ,33); muleq: exec_operand(opr_muleq ,op_muleq);
lnkeq: exec_operand(opr_lnkeq ,34); diveq: exec_operand(opr_diveq ,op_diveq);
addeqc: exec_operand(opr_addeqc ,35); lnkeq: exec_operand(opr_lnkeq ,op_lnkeq);
subeqc: exec_operand(opr_subeqc ,36); addeqc: exec_operand(opr_addeqc ,op_addeqc);
muleqc: exec_operand(opr_muleqc ,37); subeqc: exec_operand(opr_subeqc ,op_subeqc);
diveqc: exec_operand(opr_diveqc ,38); muleqc: exec_operand(opr_muleqc ,op_muleqc);
lnkeqc: exec_operand(opr_lnkeqc ,39); diveqc: exec_operand(opr_diveqc ,op_diveqc);
meq: exec_operand(opr_meq ,40); lnkeqc: exec_operand(opr_lnkeqc ,op_lnkeqc);
eq: exec_operand(opr_eq ,41); meq: exec_operand(opr_meq ,op_meq);
neq: exec_operand(opr_neq ,42); eq: exec_operand(opr_eq ,op_eq);
less: exec_operand(opr_less ,43); neq: exec_operand(opr_neq ,op_neq);
leq: exec_operand(opr_leq ,44); less: exec_operand(opr_less ,op_less);
grt: exec_operand(opr_grt ,45); leq: exec_operand(opr_leq ,op_leq);
geq: exec_operand(opr_geq ,46); grt: exec_operand(opr_grt ,op_grt);
lessc: exec_operand(opr_lessc ,47); geq: exec_operand(opr_geq ,op_geq);
leqc: exec_operand(opr_leqc ,48); lessc: exec_operand(opr_lessc ,op_lessc);
grtc: exec_operand(opr_grtc ,49); leqc: exec_operand(opr_leqc ,op_leqc);
geqc: exec_operand(opr_geqc ,50); grtc: exec_operand(opr_grtc ,op_grtc);
pop: exec_operand(opr_pop ,51); geqc: exec_operand(opr_geqc ,op_geqc);
jmp: exec_operand(opr_jmp ,52); pop: exec_operand(opr_pop ,op_pop);
jt: exec_operand(opr_jt ,53); jmp: exec_operand(opr_jmp ,op_jmp);
jf: exec_operand(opr_jf ,54); jt: exec_operand(opr_jt ,op_jt);
counter: exec_operand(opr_counter ,55); jf: exec_operand(opr_jf ,op_jf);
cntpop: exec_operand(opr_cntpop ,56); counter: exec_operand(opr_counter ,op_cnt);
findex: exec_operand(opr_findex ,57); cntpop: exec_operand(opr_cntpop ,op_cntpop);
feach: exec_operand(opr_feach ,58); findex: exec_operand(opr_findex ,op_findex);
callg: exec_operand(opr_callg ,59); feach: exec_operand(opr_feach ,op_feach);
calll: exec_operand(opr_calll ,60); callg: exec_operand(opr_callg ,op_callg);
callv: exec_operand(opr_callv ,61); calll: exec_operand(opr_calll ,op_calll);
callvi: exec_operand(opr_callvi ,62); callv: exec_operand(opr_callv ,op_callv);
callh: exec_operand(opr_callh ,63); callvi: exec_operand(opr_callvi ,op_callvi);
callfv: exec_operand(opr_callfv ,64); callh: exec_operand(opr_callh ,op_callh);
callfh: exec_operand(opr_callfh ,65); callfv: exec_operand(opr_callfv ,op_callfv);
callb: exec_operand(opr_callb ,66); callfh: exec_operand(opr_callfh ,op_callfh);
slcbegin:exec_operand(opr_slcbegin,67); callb: exec_operand(opr_callb ,op_callb);
slcend: exec_operand(opr_slcend ,68); slcbegin:exec_operand(opr_slcbegin,op_slcbegin);
slc: exec_operand(opr_slc ,69); slcend: exec_operand(opr_slcend ,op_slcend);
slc2: exec_operand(opr_slc2 ,70); slc: exec_operand(opr_slc ,op_slc);
mcallg: exec_operand(opr_mcallg ,71); slc2: exec_operand(opr_slc2 ,op_slc2);
mcalll: exec_operand(opr_mcalll ,72); mcallg: exec_operand(opr_mcallg ,op_mcallg);
mcallv: exec_operand(opr_mcallv ,73); mcalll: exec_operand(opr_mcalll ,op_mcalll);
mcallh: exec_operand(opr_mcallh ,74); mcallv: exec_operand(opr_mcallv ,op_mcallv);
ret: exec_operand(opr_ret ,75); mcallh: exec_operand(opr_mcallh ,op_mcallh);
ret: exec_operand(opr_ret ,op_ret);
} }
#endif #endif