diff --git a/nasal_codegen.h b/nasal_codegen.h index c00571c..1683888 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -1272,7 +1272,10 @@ void nasal_codegen::print_op(uint32_t index) std::cout<>31)<<"\n"; break; case op_lnkeqc: - printf("0x%x (\"%s\") sp-%u\n",c.num&0x7fffffff,rawstr(str_res[c.num&0x7fffffff]).c_str(),c.num>>31);break; + { + std::string tmp=rawstr(str_res[c.num&0x7fffffff]); + printf("0x%x (\"%.16s%s\") sp-%u\n",c.num&0x7fffffff,tmp.c_str(),tmp.length()>16?"...":"",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: @@ -1291,7 +1294,10 @@ void nasal_codegen::print_op(uint32_t index) case op_lnkc: 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; + { + std::string tmp=rawstr(str_res[c.num]); + printf("0x%x (\"%.16s%s\")\n",c.num,tmp.c_str(),tmp.length()>16?"...":""); + }break; default:printf("\n");break; } } diff --git a/nasal_gc.h b/nasal_gc.h index 97f0c90..4196e9e 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -22,7 +22,7 @@ enum nasal_type // change parameters here to make your own efficient gc // better set bigger number on vm_vec -const uint32_t increment[vm_type_size]= +const uint32_t initialize[vm_type_size]= { /* none-gc object */ 0, // vm_none, error type @@ -39,6 +39,23 @@ const uint32_t increment[vm_type_size]= 512, // vm_upval 16 // vm_obj }; +const uint32_t increment[vm_type_size]= +{ + /* none-gc object */ + 0, // vm_none, error type + 0, // vm_count, used in foreach/forindex + 0, // vm_addr, used to store local address pointers + 0, // vm_ret, used to store call-return address + 0, // vm_nil + 0, // vm_num + /* gc object */ + 1024,// vm_str + 512, // vm_func + 8192,// vm_vec + 1024,// vm_hash + 128, // vm_upval + 256 // vm_obj +}; struct nasal_vec; // vector struct nasal_hash; // hashmap(dict) @@ -468,7 +485,7 @@ void nasal_gc::init(const std::vector& s) for(uint8_t i=0;i %s\n",(uint64_t)p,rawstr(val.str()).c_str());break; + case vm_str: + { + std::string tmp=rawstr(val.str()); + printf("| str | <0x%lx> %.16s%s\n",(uint64_t)p,tmp.c_str(),tmp.length()>16?"...":""); + }break; case vm_func: printf("| func | <0x%lx> entry:0x%x\n",(uint64_t)p,val.func().entry);break; case vm_vec: printf("| vec | <0x%lx> [%lu val]\n",(uint64_t)p,val.vec().size());break; case vm_hash: printf("| hash | <0x%lx> {%lu val}\n",(uint64_t)p,val.hash().size());break; @@ -183,7 +187,10 @@ void nasal_vm::bytecodeinfo(const char* header,const uint32_t p) std::cout<>31); break; case op_lnkeqc: - printf("0x%x (\"%s\") sp-%u",c.num&0x7fffffff,rawstr(str_table[c.num&0x7fffffff]).c_str(),c.num>>31);break; + { + std::string tmp=rawstr(str_table[c.num&0x7fffffff]); + printf("0x%x (\"%.16s%s\") sp-%u",c.num&0x7fffffff,tmp.c_str(),tmp.length()>16?"...":"",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: @@ -202,7 +209,10 @@ void nasal_vm::bytecodeinfo(const char* header,const uint32_t p) case op_lnkc: case op_callh: case op_mcallh: case op_para: case op_defpara:case op_dynpara: - printf("0x%x (\"%s\")",c.num,rawstr(str_table[c.num]).c_str());break; + { + std::string tmp=rawstr(str_table[c.num]); + printf("0x%x (\"%.16s%s\")",c.num,tmp.c_str(),tmp.length()>16?"...":""); + }break; default:printf("0x%x",c.num);break; } printf(" (%s:%d)\n",files[c.fidx].c_str(),c.line); diff --git a/test/diff.nas b/test/diff.nas index f13ae3f..64f3c3a 100644 --- a/test/diff.nas +++ b/test/diff.nas @@ -5,27 +5,19 @@ var myers=func(src,dst,show_table=0){ var (src_len,dst_len)=(size(src),size(dst)); var mat=[]; - setsize(mat,dst_len); + setsize(mat,dst_len*src_len); forindex(var i;mat){ - var tmp=[]; - setsize(tmp,src_len); - mat[i]=tmp; - forindex(var j;tmp) - tmp[j]=0; + mat[i]=0; } var visited=[]; - setsize(visited,dst_len); + setsize(visited,dst_len*src_len); forindex(var i;visited){ - var tmp=[]; - setsize(tmp,src_len); - visited[i]=tmp; - forindex(var j;tmp) - tmp[j]=0; + visited[i]=0; } forindex(var y;dst) forindex(var x;src) - mat[y][x]=(src[x]==dst[y]); + mat[y*src_len+x]=(src[x]==dst[y]); if(show_table){ var curve=[ @@ -39,7 +31,7 @@ var myers=func(src,dst,show_table=0){ forindex(var y;dst){ forindex(var t;curve[0]){ forindex(var x;src){ - s~=curve[mat[y][x]][t]; + s~=curve[mat[y*src_len+x]][t]; } s~=["+","|"][t]~"\n"; } @@ -52,7 +44,7 @@ var myers=func(src,dst,show_table=0){ var total=[]; var path=[]; var vec=[[0,0,-1]]; - visited[0][0]=1; + visited[0]=1; while(size(vec)){ append(total,vec); var tmp=[]; @@ -96,20 +88,20 @@ var myers=func(src,dst,show_table=0){ } # do bfs - if(mat[y][x]==1){ - if(x+1