💬 change code related to macros 'PRTHEX'

This commit is contained in:
ValKmjolnir 2022-05-08 19:43:27 +08:00
parent 07857d980c
commit c5171c735a
3 changed files with 22 additions and 20 deletions

10
nasal.h
View File

@ -33,12 +33,12 @@
#endif #endif
#ifndef _WIN32 #ifndef _WIN32
#define PRTHEX64 "0x%lx" #define PRTHEX64 "%lx"
#define PRTHEX64_8 "0x%.8lx" #define PRTHEX64_8 "%.8lx"
#define PRTINT64 "%ld" #define PRTINT64 "%ld"
#else #else
#define PRTHEX64 "0x%llx" #define PRTHEX64 "%llx"
#define PRTHEX64_8 "0x%.8llx" #define PRTHEX64_8 "%.8llx"
#define PRTINT64 "%lld" #define PRTINT64 "%lld"
#endif #endif
@ -124,6 +124,7 @@ double str2num(const char* str)
int utf8_hdchk(char head) int utf8_hdchk(char head)
{ {
// RFC-2279 but in fact now we use RFC-3629 so nbytes is less than 4
uint8_t c=(uint8_t)head; uint8_t c=(uint8_t)head;
uint32_t nbytes=0; uint32_t nbytes=0;
if((c>>5)==0x06) // 110x xxxx (10xx xxxx)^1 if((c>>5)==0x06) // 110x xxxx (10xx xxxx)^1
@ -132,6 +133,7 @@ int utf8_hdchk(char head)
nbytes=2; nbytes=2;
if((c>>3)==0x1e) // 1111 0xxx (10xx xxxx)^3 if((c>>3)==0x1e) // 1111 0xxx (10xx xxxx)^3
nbytes=3; nbytes=3;
// these should not be true
if((c>>2)==0x3e) // 1111 10xx (10xx xxxx)^4 if((c>>2)==0x3e) // 1111 10xx (10xx xxxx)^4
nbytes=4; nbytes=4;
if((c>>1)==0x7e) // 1111 110x (10xx xxxx)^5 if((c>>1)==0x7e) // 1111 110x (10xx xxxx)^5

View File

@ -1287,7 +1287,7 @@ void nasal_codegen::print_op(uint32_t index)
case op_calll: case op_mcalll: case op_loadl: case op_calll: case op_mcalll: case op_loadl:
printf("0x%x\n",c.num);break; printf("0x%x\n",c.num);break;
case op_callb: case op_callb:
printf("0x%x <%s@" PRTHEX64 ">\n",c.num,builtin[c.num].name,(uint64_t)builtin[c.num].func);break; printf("0x%x <%s@0x" PRTHEX64 ">\n",c.num,builtin[c.num].name,(uint64_t)builtin[c.num].func);break;
case op_upval:case op_mupval: case op_loadu: case op_upval:case op_mupval: case op_loadu:
printf("0x%x[0x%x]\n",(c.num>>16)&0xffff,c.num&0xffff);break; printf("0x%x[0x%x]\n",(c.num>>16)&0xffff,c.num&0xffff);break;
case op_happ: case op_pstr: case op_happ: case op_pstr:

View File

@ -148,20 +148,20 @@ void nasal_vm::valinfo(nasal_ref& val)
{ {
case vm_none: printf("| null |\n");break; case vm_none: printf("| null |\n");break;
case vm_ret: printf("| pc | 0x%x\n",val.ret());break; case vm_ret: printf("| pc | 0x%x\n",val.ret());break;
case vm_addr: printf("| addr | " PRTHEX64 "\n",(uint64_t)val.addr());break; case vm_addr: printf("| addr | 0x" PRTHEX64 "\n",(uint64_t)val.addr());break;
case vm_cnt: printf("| cnt | " PRTINT64 "\n",val.cnt());break; case vm_cnt: printf("| cnt | " PRTINT64 "\n",val.cnt());break;
case vm_nil: printf("| nil |\n");break; case vm_nil: printf("| nil |\n");break;
case vm_num: printf("| num | ");std::cout<<val.num()<<'\n';break; case vm_num: printf("| num | ");std::cout<<val.num()<<'\n';break;
case vm_str: case vm_str:
{ {
std::string tmp=rawstr(val.str()); std::string tmp=rawstr(val.str());
printf("| str | <" PRTHEX64 "> %.16s%s\n",(uint64_t)p,tmp.c_str(),tmp.length()>16?"...":""); printf("| str | <0x" PRTHEX64 "> %.16s%s\n",(uint64_t)p,tmp.c_str(),tmp.length()>16?"...":"");
}break; }break;
case vm_func: printf("| func | <" PRTHEX64 "> entry:0x%x\n",(uint64_t)p,val.func().entry);break; case vm_func: printf("| func | <0x" PRTHEX64 "> entry:0x%x\n",(uint64_t)p,val.func().entry);break;
case vm_vec: printf("| vec | <" PRTHEX64 "> [%zu val]\n",(uint64_t)p,val.vec().size());break; case vm_vec: printf("| vec | <0x" PRTHEX64 "> [%zu val]\n",(uint64_t)p,val.vec().size());break;
case vm_hash: printf("| hash | <" PRTHEX64 "> {%zu val}\n",(uint64_t)p,val.hash().size());break; case vm_hash: printf("| hash | <0x" PRTHEX64 "> {%zu val}\n",(uint64_t)p,val.hash().size());break;
case vm_obj: printf("| obj | <" PRTHEX64 "> obj:" PRTHEX64 "\n",(uint64_t)p,(uint64_t)val.obj().ptr);break; case vm_obj: printf("| obj | <0x" PRTHEX64 "> obj:0x" PRTHEX64 "\n",(uint64_t)p,(uint64_t)val.obj().ptr);break;
default: printf("| err | <" PRTHEX64 "> unknown object\n",(uint64_t)p);break; default: printf("| err | <0x" PRTHEX64 "> unknown object\n",(uint64_t)p);break;
} }
} }
void nasal_vm::bytecodeinfo(const char* header,const uint32_t p) void nasal_vm::bytecodeinfo(const char* header,const uint32_t p)
@ -202,7 +202,7 @@ void nasal_vm::bytecodeinfo(const char* header,const uint32_t p)
case op_calll: case op_mcalll: case op_loadl: case op_calll: case op_mcalll: case op_loadl:
printf("0x%x",c.num);break; printf("0x%x",c.num);break;
case op_callb: case op_callb:
printf("0x%x <%s@" PRTHEX64 ">",c.num,builtin[c.num].name,(uint64_t)builtin[c.num].func);break; printf("0x%x <%s@0x" PRTHEX64 ">",c.num,builtin[c.num].name,(uint64_t)builtin[c.num].func);break;
case op_upval: case op_mupval: case op_loadu: case op_upval: case op_mupval: case op_loadu:
printf(" (0x%x[0x%x])",(c.num>>16)&0xffff,c.num&0xffff);break; printf(" (0x%x[0x%x])",(c.num>>16)&0xffff,c.num&0xffff);break;
case op_happ: case op_pstr: case op_happ: case op_pstr:
@ -251,7 +251,7 @@ void nasal_vm::stackinfo(const uint32_t limit=10)
uint32_t gsize=bytecode[0].num; uint32_t gsize=bytecode[0].num;
nasal_ref* top=gc.top; nasal_ref* top=gc.top;
nasal_ref* bottom=gc.stack+gsize; nasal_ref* bottom=gc.stack+gsize;
printf("vm stack(" PRTHEX64 "<sp+%u>, limit %d, total ",(uint64_t)bottom,gsize,limit); printf("vm stack(0x" PRTHEX64 "<sp+%u>, limit %d, total ",(uint64_t)bottom,gsize,limit);
if(top<bottom) if(top<bottom)
{ {
printf("0)\n"); printf("0)\n");
@ -260,7 +260,7 @@ void nasal_vm::stackinfo(const uint32_t limit=10)
printf("" PRTINT64 "):\n",top-bottom+1); printf("" PRTINT64 "):\n",top-bottom+1);
for(uint32_t i=0;i<limit && top>=bottom;++i,--top) for(uint32_t i=0;i<limit && top>=bottom;++i,--top)
{ {
printf(" " PRTHEX64_8 "",top-gc.stack); printf(" 0x" PRTHEX64_8 "",top-gc.stack);
valinfo(top[0]); valinfo(top[0]);
} }
} }
@ -268,7 +268,7 @@ void nasal_vm::global_state()
{ {
if(!bytecode[0].num || gc.stack[0].type==vm_none) // bytecode[0].op is op_intg if(!bytecode[0].num || gc.stack[0].type==vm_none) // bytecode[0].op is op_intg
return; return;
printf("global(" PRTHEX64 "<sp+0>):\n",(uint64_t)gc.stack); printf("global(0x" PRTHEX64 "<sp+0>):\n",(uint64_t)gc.stack);
for(uint32_t i=0;i<bytecode[0].num;++i) for(uint32_t i=0;i<bytecode[0].num;++i)
{ {
printf(" 0x%.8x",i); printf(" 0x%.8x",i);
@ -280,7 +280,7 @@ void nasal_vm::local_state()
if(!localr || !gc.funcr.func().lsize) if(!localr || !gc.funcr.func().lsize)
return; return;
uint32_t lsize=gc.funcr.func().lsize; uint32_t lsize=gc.funcr.func().lsize;
printf("local(" PRTHEX64 "<sp+" PRTINT64 ">):\n",(uint64_t)localr,localr-gc.stack); printf("local(0x" PRTHEX64 "<sp+" PRTINT64 ">):\n",(uint64_t)localr,localr-gc.stack);
for(uint32_t i=0;i<lsize;++i) for(uint32_t i=0;i<lsize;++i)
{ {
printf(" 0x%.8x",i); printf(" 0x%.8x",i);
@ -306,12 +306,12 @@ void nasal_vm::upval_state()
} }
void nasal_vm::detail() void nasal_vm::detail()
{ {
printf("maddr:\n (" PRTHEX64 ")\n",(uint64_t)mem_addr); printf("maddr:\n (0x" PRTHEX64 ")\n",(uint64_t)mem_addr);
printf("localr:\n (" PRTHEX64 ")\n",(uint64_t)localr); printf("localr:\n (0x" PRTHEX64 ")\n",(uint64_t)localr);
if(gc.funcr.type==vm_nil) if(gc.funcr.type==vm_nil)
printf("funcr:\n (nil)\n"); printf("funcr:\n (nil)\n");
else else
printf("funcr:\n (<" PRTHEX64 "> entry:0x%x)\n", printf("funcr:\n (<0x" PRTHEX64 "> entry:0x%x)\n",
(uint64_t)gc.funcr.value.gcobj, (uint64_t)gc.funcr.value.gcobj,
gc.funcr.func().entry); gc.funcr.func().entry);
global_state(); global_state();