diff --git a/nasal_codegen.h b/nasal_codegen.h index a9de36d..ee6f52b 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -205,7 +205,6 @@ private: std::stack fbstk; std::stack festk; - void die(std::string,const uint32_t); void regist_number(const double); void regist_string(const std::string&); @@ -1265,7 +1264,8 @@ void nasal_codegen::print_op(uint32_t index) // print detail info switch(c.op) { - case op_addeq: case op_subeq: case op_muleq: case op_diveq: case op_lnkeq: + case op_addeq: case op_subeq: case op_muleq: case op_diveq: + case op_lnkeq: case op_meq: printf("0x%x sp-%u\n",c.num,c.num);break; case op_addeqc:case op_subeqc: case op_muleqc:case op_diveqc: printf("0x%x (",c.num&0x7fffffff); @@ -1280,12 +1280,11 @@ void nasal_codegen::print_op(uint32_t index) case op_callvi:case op_newv: case op_callfv: case op_intg: case op_intl: case op_newf: case op_jmp: case op_jt: case op_jf: - printf("0x%x\n",c.num);break; - case op_callb: - printf("0x%x <%s@0x%lx>\n",c.num,builtin[c.num].name,(uint64_t)builtin[c.num].func);break; case op_callg: case op_mcallg: case op_loadg: case op_calll: case op_mcalll: case op_loadl: printf("0x%x\n",c.num);break; + case op_callb: + printf("0x%x <%s@0x%lx>\n",c.num,builtin[c.num].name,(uint64_t)builtin[c.num].func);break; case op_upval:case op_mupval: case op_loadu: printf("0x%x[0x%x]\n",(c.num>>16)&0xffff,c.num&0xffff);break; case op_happ: case op_pstr: @@ -1293,8 +1292,6 @@ void nasal_codegen::print_op(uint32_t index) case op_callh: case op_mcallh: case op_para: case op_defpara:case op_dynpara: printf("0x%x (\"%s\")\n",c.num,rawstr(str_res[c.num]).c_str());break; - case op_meq: - printf("0x%x sp-%u\n",c.num,c.num);break; default:printf("\n");break; } } diff --git a/nasal_vm.h b/nasal_vm.h index 7755dda..affc46c 100644 --- a/nasal_vm.h +++ b/nasal_vm.h @@ -163,29 +163,47 @@ void nasal_vm::valinfo(nasal_ref& val) void nasal_vm::bytecodeinfo(const char* header,const uint32_t p) { const opcode& c=bytecode[p]; - printf("%s0x%.8x: %s 0x%x",header,p,code_table[c.op].name,c.num); + printf("%s0x%.8x: %.2x %.2x %.2x %.2x %.2x %s ", + header, + p, + c.op, + uint8_t((c.num>>24)&0xff), + uint8_t((c.num>>16)&0xff), + uint8_t((c.num>>8)&0xff), + uint8_t(c.num&0xff), + code_table[c.op].name + ); switch(c.op) { - case op_addeq: case op_subeq: case op_muleq: case op_diveq: case op_lnkeq: - printf(" sp-%u",c.num);break; + case op_addeq: case op_subeq: case op_muleq: case op_diveq: + case op_lnkeq: case op_meq: + printf("0x%x sp-%u",c.num,c.num);break; case op_addeqc:case op_subeqc: case op_muleqc:case op_diveqc: - std::cout<<" ("<>31);break; + printf("0x%x (",c.num&0x7fffffff); + std::cout<>31); + break; case op_lnkeqc: - printf(" (\"%s\") sp-%u",rawstr(str_table[c.num&0x7fffffff]).c_str(),c.num>>31);break; + printf("0x%x (\"%s\") sp-%u",c.num&0x7fffffff,rawstr(str_table[c.num&0x7fffffff]).c_str(),c.num>>31);break; case op_addc: case op_subc: case op_mulc: case op_divc: case op_lessc: case op_leqc: case op_grtc: case op_geqc: case op_pnum: - std::cout<<" ("<",builtin[c.num].name,(uint64_t)builtin[c.num].func);break; + printf("0x%x <%s@0x%lx>",c.num,builtin[c.num].name,(uint64_t)builtin[c.num].func);break; case op_happ: case op_pstr: case op_lnkc: case op_callh: case op_mcallh: case op_para: case op_defpara:case op_dynpara: - printf(" (\"%s\")",rawstr(str_table[c.num]).c_str());break; + printf("0x%x (\"%s\")",c.num,rawstr(str_table[c.num]).c_str());break; case op_upval: case op_mupval: case op_loadu: printf(" (0x%x[0x%x])",(c.num>>16)&0xffff,c.num&0xffff);break; - default:break; + default:printf("0x%x",c.num);break; } printf(" (%s:%d)\n",files[c.fidx].c_str(),c.line); } diff --git a/test/bigloop.nas b/test/bigloop.nas index 453598a..0747cff 100644 --- a/test/bigloop.nas +++ b/test/bigloop.nas @@ -1 +1 @@ -for(var i=0;i<4e6;i+=1); \ No newline at end of file +for(var i=0;i<4e6;i+=1); diff --git a/test/md5compare.nas b/test/md5compare.nas index 626d1a0..b1d4208 100644 --- a/test/md5compare.nas +++ b/test/md5compare.nas @@ -1,4 +1,3 @@ -import("lib.nas"); import("test/md5.nas"); rand(time(0)); diff --git a/test/pi.nas b/test/pi.nas index 672cec8..9cbc750 100644 --- a/test/pi.nas +++ b/test/pi.nas @@ -1,5 +1,3 @@ -import("lib.nas"); - var (t,res)=(1,0); for(var m=1;m<4e6;m+=2) { diff --git a/test/qrcode.nas b/test/qrcode.nas index 868abf8..ec6e023 100644 --- a/test/qrcode.nas +++ b/test/qrcode.nas @@ -1,5 +1,3 @@ -import("lib.nas"); - var code=[ [1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1], [1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1], diff --git a/test/quick_sort.nas b/test/quick_sort.nas index 1c7d1f2..107ce7c 100644 --- a/test/quick_sort.nas +++ b/test/quick_sort.nas @@ -1,4 +1,3 @@ -import("lib.nas"); var sort=func(vec,left,right) { if(left>=right) return; diff --git a/test/scalar.nas b/test/scalar.nas index fcb19f2..1c16f5b 100644 --- a/test/scalar.nas +++ b/test/scalar.nas @@ -1,5 +1,4 @@ # basic type -import("lib.nas"); nil; 2147483647; 0x7fffffff; diff --git a/test/trait.nas b/test/trait.nas index 0f00688..5bda73d 100644 --- a/test/trait.nas +++ b/test/trait.nas @@ -1,4 +1,3 @@ -import("lib.nas"); var trait={ get:func{return me.val;}, diff --git a/test/turingmachine.nas b/test/turingmachine.nas index 5c65025..95dea5d 100644 --- a/test/turingmachine.nas +++ b/test/turingmachine.nas @@ -1,4 +1,3 @@ -import("lib.nas"); var table=[ ['q0','0','1','R','q1'], diff --git a/test/wavecollapse.nas b/test/wavecollapse.nas index fbb4f97..28fc14c 100644 --- a/test/wavecollapse.nas +++ b/test/wavecollapse.nas @@ -1,7 +1,5 @@ # wave collapse function 2022/4/10 # by ValKmjolnir -import("lib.nas"); - srand(); var interval=1/60; var table=[ diff --git a/test/ycombinator.nas b/test/ycombinator.nas index 8a08436..0efe447 100644 --- a/test/ycombinator.nas +++ b/test/ycombinator.nas @@ -1,7 +1,4 @@ # Y combinator by ValKmjolnir - -import("lib.nas"); - var fib=func(f){ return f(f); }(