diff --git a/makefile b/makefile index b02b660..48c29ea 100644 --- a/makefile +++ b/makefile @@ -33,10 +33,7 @@ clean: test:nasal @ ./nasal -e test/ascii-art.nas - @ ./nasal -c test/auto_crash.nas - @ ./nasal -a -c test/bf.nas - @ ./nasal -a -c test/bfconvertor.nas - @ ./nasal -d test/bfs.nas + @ ./nasal -t -d test/bfs.nas @ ./nasal -t test/bigloop.nas @ ./nasal -t test/bp.nas @ ./nasal -d test/calc.nas @@ -51,7 +48,6 @@ test:nasal @ ./nasal -t -d test/fib.nas @ ./nasal -e test/filesystem.nas @ ./nasal -d test/hexdump.nas - @ ./nasal -c test/httptest.nas @ ./nasal -e test/json.nas @ ./nasal -e test/leetcode1319.nas @ ./nasal -d test/lexer.nas @@ -63,11 +59,9 @@ test:nasal @ ./nasal -t -d test/md5compare.nas -@ ./nasal -d test/module_test.nas @ ./nasal -e test/nasal_test.nas - @ ./nasal test/occupation.nas 2 + @ ./nasal -t -d test/occupation.nas 2 @ ./nasal -t -d test/pi.nas - @ ./nasal -c test/ppmgen.nas @ ./nasal -t -d test/prime.nas - @ ./nasal -c test/push.nas @ ./nasal -e test/qrcode.nas @ ./nasal -t -d test/quick_sort.nas @ ./nasal -e test/scalar.nas hello world diff --git a/nasal_codegen.h b/nasal_codegen.h index 25d189d..a7aa2e7 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -147,12 +147,11 @@ public: u8 op=ins.code.op; u32 num=ins.code.num; out<>24)&0xff)<<" " <>16)&0xff)<<" " <>8)&0xff)<<" " - < imm; // immediate number + const f64* cnum; // constant numbers + const string* cstr; // constant symbols and strings + std::vector imm; // immediate number table /* garbage collector */ - gc ngc; + gc ngc; + /* main stack */ var stack[STACK_DEPTH]; /* values used for debugger */ - const string* files; - const opcode* bytecode; + const string* files; // file name list + const opcode* bytecode; // bytecode buffer address + /* vm initializing function */ void init( const std::vector&, const std::vector&, const std::vector&, const std::vector&, const std::vector&); + /* debug functions */ bool verbose; void valinfo(var&); @@ -49,8 +53,10 @@ protected: void ustate(); void detail(); void die(const string&); + /* vm calculation functions*/ bool cond(var&); + /* vm operands */ void o_intg(); void o_intl(); @@ -139,12 +145,16 @@ protected: void o_mcallh(); void o_ret(); public: + + /* constructor of vm instance */ vm(): pc(0),localr(nullptr),memr(nullptr),funcr(nil), upvalr(nil),canary(nullptr),top(stack), cnum(nullptr),cstr(nullptr), ngc(pc,localr,memr,funcr,upvalr,canary,top,stack), files(nullptr),bytecode(nullptr),verbose(false) {} + + /* execution entry */ void run( const codegen&, const linker&, @@ -179,39 +189,38 @@ void vm::init( void vm::valinfo(var& val) { const nas_val* p=val.val.gcobj; - std::cout<<"\t"; switch(val.type) { - case vm_none: std::cout<<"| null |";break; - case vm_ret: std::cout<<"| pc | 0x"< "< entry:0x"< ["< ["< {"< obj:0x"<<(u64)val.obj().ptr < coroutine";break; - default: std::cout<<"| err | <0x"< unknown object";break; } - std::cout<<"\n"; + std::clog<<"\n"; } void vm::traceback() { @@ -225,19 +234,19 @@ void vm::traceback() { } } ret.push(pc); // store the position program crashed - std::cout<<"trace back ("<<(ngc.stack==stack?"main":"coroutine")<<")\n"; + std::clog<<"trace back ("<<(ngc.stack==stack?"main":"coroutine")<<")\n"; for(u32 p=0,same=0,prev=0xffffffff;!ret.empty();prev=p,ret.pop()) { if ((p=ret.top())==prev) { ++same; continue; } if (same) { - std::cout - <<" 0x"<, limit "<, limit "<=bottom;++i,--t) { - std::cout<<" 0x"<)\n"<)\n"<)\n"<)\n"< upval["< upval["<","!","@","#","$","%", "^","&","*","(",")","-","=","\\","|","[","]","{","}","`"," ","\t","?" ]; - return func(begin,end){ + return func(begin,end) { var byte=0; var total=end-begin; var timestamp=maketimestamp(); timestamp.stamp(); var bar=process_bar.high_resolution_bar(40); - for(var i=begin;i