bytecode info print and debugger will show the front 16 characters of strings whose length is greater than 16

This commit is contained in:
ValKmjolnir 2022-05-02 16:56:03 +08:00
parent 9c7f5f1a6e
commit fd8a148d0c
4 changed files with 55 additions and 30 deletions

View File

@ -1272,7 +1272,10 @@ void nasal_codegen::print_op(uint32_t index)
std::cout<<num_res[c.num&0x7fffffff]<<") sp-"<<(c.num>>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;
}
}

View File

@ -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<std::string>& s)
for(uint8_t i=0;i<vm_type_size;++i)
size[i]=count[i]=0;
for(uint8_t i=vm_str;i<vm_type_size;++i)
for(uint32_t j=0;j<increment[i];++j)
for(uint32_t j=0;j<initialize[i];++j)
{
nasal_val* tmp=new nasal_val(i);
memory.push_back(tmp);
@ -510,7 +527,7 @@ void nasal_gc::info()
std::cout<<" "<<name[i]<<" | "<<count[i]<<"\n";
std::cout<<"\nmemory allocator info(max size):\n";
for(uint8_t i=vm_str;i<vm_type_size;++i)
std::cout<<" "<<name[i]<<" | "<<(size[i]+1)*increment[i]<<"(+"<<size[i]<<")\n";
std::cout<<" "<<name[i]<<" | "<<initialize[i]+size[i]*increment[i]<<"(+"<<size[i]<<")\n";
}
nasal_ref nasal_gc::alloc(uint8_t type)
{

View File

@ -152,7 +152,11 @@ void nasal_vm::valinfo(nasal_ref& val)
case vm_cnt: printf("| cnt | %ld\n",val.cnt());break;
case vm_nil: printf("| nil |\n");break;
case vm_num: printf("| num | ");std::cout<<val.num()<<'\n';break;
case vm_str: printf("| str | <0x%lx> %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<<num_table[c.num&0x7fffffff]<<") sp-"<<(c.num>>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);

View File

@ -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<src_len and y+1<dst_len and visited[y+1][x+1]==0){
if(mat[y*src_len+x]==1){
if(x+1<src_len and y+1<dst_len and visited[(y+1)*src_len+x+1]==0){
append(tmp,[y+1,x+1,i]);
visited[y+1][x+1]=1;
visited[(y+1)*src_len+x+1]=1;
}
}
else{
if(x+1<src_len and visited[y][x+1]==0){
if(x+1<src_len and visited[y*src_len+x+1]==0){
append(tmp,[y,x+1,i]);
visited[y][x+1]=1;
visited[y*src_len+x+1]=1;
}
if(y+1<dst_len and visited[y+1][x]==0){
if(y+1<dst_len and visited[(y+1)*src_len+x]==0){
append(tmp,[y+1,x,i]);
visited[y+1][x]=1;
visited[(y+1)*src_len+x]=1;
}
}
}