diff --git a/nasal.h b/nasal.h index 67d436f..63fc038 100644 --- a/nasal.h +++ b/nasal.h @@ -33,12 +33,12 @@ #endif #ifndef _WIN32 -#define PRTHEX64 "0x%lx" -#define PRTHEX64_8 "0x%.8lx" +#define PRTHEX64 "%lx" +#define PRTHEX64_8 "%.8lx" #define PRTINT64 "%ld" #else -#define PRTHEX64 "0x%llx" -#define PRTHEX64_8 "0x%.8llx" +#define PRTHEX64 "%llx" +#define PRTHEX64_8 "%.8llx" #define PRTINT64 "%lld" #endif @@ -124,6 +124,7 @@ double str2num(const char* str) 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; uint32_t nbytes=0; if((c>>5)==0x06) // 110x xxxx (10xx xxxx)^1 @@ -132,6 +133,7 @@ int utf8_hdchk(char head) nbytes=2; if((c>>3)==0x1e) // 1111 0xxx (10xx xxxx)^3 nbytes=3; + // these should not be true if((c>>2)==0x3e) // 1111 10xx (10xx xxxx)^4 nbytes=4; if((c>>1)==0x7e) // 1111 110x (10xx xxxx)^5 diff --git a/nasal_codegen.h b/nasal_codegen.h index f46453c..3240e7b 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -1287,7 +1287,7 @@ void nasal_codegen::print_op(uint32_t index) case op_calll: case op_mcalll: case op_loadl: printf("0x%x\n",c.num);break; 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: printf("0x%x[0x%x]\n",(c.num>>16)&0xffff,c.num&0xffff);break; case op_happ: case op_pstr: diff --git a/nasal_vm.h b/nasal_vm.h index 1fff491..aa14b85 100644 --- a/nasal_vm.h +++ b/nasal_vm.h @@ -148,20 +148,20 @@ void nasal_vm::valinfo(nasal_ref& val) { case vm_none: printf("| null |\n");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_nil: printf("| nil |\n");break; case vm_num: printf("| num | ");std::cout< %.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; - case vm_func: printf("| func | <" 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_hash: printf("| hash | <" 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; - default: printf("| err | <" PRTHEX64 "> unknown object\n",(uint64_t)p);break; + case vm_func: printf("| func | <0x" PRTHEX64 "> entry:0x%x\n",(uint64_t)p,val.func().entry);break; + case vm_vec: printf("| vec | <0x" PRTHEX64 "> [%zu val]\n",(uint64_t)p,val.vec().size());break; + case vm_hash: printf("| hash | <0x" PRTHEX64 "> {%zu val}\n",(uint64_t)p,val.hash().size());break; + case vm_obj: printf("| obj | <0x" PRTHEX64 "> obj:0x" PRTHEX64 "\n",(uint64_t)p,(uint64_t)val.obj().ptr);break; + default: printf("| err | <0x" PRTHEX64 "> unknown object\n",(uint64_t)p);break; } } 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: printf("0x%x",c.num);break; 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: printf(" (0x%x[0x%x])",(c.num>>16)&0xffff,c.num&0xffff);break; 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; nasal_ref* top=gc.top; nasal_ref* bottom=gc.stack+gsize; - printf("vm stack(" PRTHEX64 ", limit %d, total ",(uint64_t)bottom,gsize,limit); + printf("vm stack(0x" PRTHEX64 ", limit %d, total ",(uint64_t)bottom,gsize,limit); if(top=bottom;++i,--top) { - printf(" " PRTHEX64_8 "",top-gc.stack); + printf(" 0x" PRTHEX64_8 "",top-gc.stack); 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 return; - printf("global(" PRTHEX64 "):\n",(uint64_t)gc.stack); + printf("global(0x" PRTHEX64 "):\n",(uint64_t)gc.stack); for(uint32_t i=0;i):\n",(uint64_t)localr,localr-gc.stack); + printf("local(0x" PRTHEX64 "):\n",(uint64_t)localr,localr-gc.stack); for(uint32_t i=0;i entry:0x%x)\n", + printf("funcr:\n (<0x" PRTHEX64 "> entry:0x%x)\n", (uint64_t)gc.funcr.value.gcobj, gc.funcr.func().entry); global_state();