diff --git a/lib.nas b/lib.nas index f59ad6b..44c82b0 100644 --- a/lib.nas +++ b/lib.nas @@ -260,6 +260,7 @@ var math= pi: 3.14159265358979323846264338327950288, inf: 1/0, nan: 0/0, + pow: func(x,y){return __builtin_pow(x,y); }, sin: func(x) {return __builtin_sin(x); }, cos: func(x) {return __builtin_cos(x); }, tan: func(x) {return __builtin_tan(x); }, diff --git a/main.cpp b/main.cpp index e62f2bb..244ba54 100644 --- a/main.cpp +++ b/main.cpp @@ -138,7 +138,7 @@ int main(int argc,const char* argv[]) {"--code",VM_CODEINFO},{"-c",VM_CODEINFO}, {"--exec",VM_EXEC},{"-e",VM_EXEC}, {"--opcnt",VM_OPCALLNUM|VM_EXEC},{"-o",VM_OPCALLNUM|VM_EXEC}, - {"--time",VM_EXECTIME},{"-t",VM_EXECTIME}, + {"--time",VM_EXECTIME|VM_EXEC},{"-t",VM_EXECTIME|VM_EXEC}, {"--detail",VM_DBGINFO|VM_EXEC},{"-d",VM_DBGINFO|VM_EXEC}, {"--optimize",VM_OPTIMIZE},{"-op",VM_OPTIMIZE}, {"--debug",VM_DEBUG},{"-dbg",VM_DEBUG} diff --git a/makefile b/makefile index 3df0450..451d2f2 100644 --- a/makefile +++ b/makefile @@ -5,9 +5,9 @@ nasal.exe:main.cpp nasal_ast.h nasal_err.h nasal_builtin.h nasal_opt.h nasal_cod g++ -std=c++11 -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static test:nasal @ ./nasal -op -e test/ascii-art.nas - @ ./nasal -op -c test/bf.nas - @ ./nasal -op -c test/bfcolored.nas - @ ./nasal -op -c test/bfconvertor.nas + @ ./nasal -op -a -c test/bf.nas + @ ./nasal -op -a -c test/bfcolored.nas + @ ./nasal -op -a -c test/bfconvertor.nas @ ./nasal -op -e -d test/bfs.nas @ ./nasal -op -t test/bigloop.nas @ ./nasal -op -e test/bp.nas @@ -33,9 +33,9 @@ test:nasal @ ./nasal -op -e test/qrcode.nas @ ./nasal -op -t -d test/quick_sort.nas @ ./nasal -op -e test/scalar.nas - -@ ./nasal -op -t test/snake.nas - @ ./nasal -op -e test/trait.nas - -@ ./nasal -op -t test/tetris.nas - @ ./nasal -op -t -d test/turingmachine.nas - @ ./nasal -op -t -d -o test/ycombinator.nas + -@ ./nasal -op -c -t test/snake.nas + @ ./nasal -op -c -e test/trait.nas + -@ ./nasal -op -c -t test/tetris.nas + @ ./nasal -op -c -t -d test/turingmachine.nas + @ ./nasal -op -c -t -d -o test/ycombinator.nas \ No newline at end of file diff --git a/nasal_builtin.h b/nasal_builtin.h index 3aba324..24fd4c9 100644 --- a/nasal_builtin.h +++ b/nasal_builtin.h @@ -29,6 +29,7 @@ nas_native(builtin_and); nas_native(builtin_or); nas_native(builtin_nand); nas_native(builtin_not); +nas_native(builtin_pow); nas_native(builtin_sin); nas_native(builtin_cos); nas_native(builtin_tan); @@ -116,6 +117,7 @@ struct {"__builtin_or", builtin_or }, {"__builtin_nand", builtin_nand }, {"__builtin_not", builtin_not }, + {"__builtin_pow", builtin_pow }, {"__builtin_sin", builtin_sin }, {"__builtin_cos", builtin_cos }, {"__builtin_tan", builtin_tan }, @@ -468,6 +470,14 @@ nasal_ref builtin_not(nasal_ref* local,nasal_gc& gc) int number=(int)a.num(); return {vm_num,(double)(~number)}; } +nasal_ref builtin_pow(nasal_ref* local,nasal_gc& gc) +{ + nasal_ref x=local[1]; + nasal_ref y=local[2]; + if(x.type!=vm_num || y.type!=vm_num) + return builtin_err("pow","\"x\" or \"y\" must be number"); + return {vm_num,std::pow(x.num(),y.num())}; +} nasal_ref builtin_sin(nasal_ref* local,nasal_gc& gc) { nasal_ref val=local[1]; diff --git a/nasal_codegen.h b/nasal_codegen.h index 3a9257b..6a5b8a7 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -1165,10 +1165,10 @@ void nasal_codegen::print_op(uint32_t index) printf(" 0x%.8x: %.2x %.2x %.2x %.2x %.2x %s ", index, c.op, - uint8_t((c.num&0xff000000)>>24), - uint8_t((c.num&0x00ff0000)>>16), - uint8_t((c.num&0x0000ff00)>>8), - uint8_t(c.num&0x000000ff), + uint8_t((c.num>>24)&0xff), + uint8_t((c.num>>16)&0xff), + uint8_t((c.num>>8)&0xff), + uint8_t(c.num&0xff), code_table[c.op].name ); // print detail info diff --git a/nasal_gc.h b/nasal_gc.h index 980b9b2..9181ab0 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -505,10 +505,10 @@ void nasal_gc::info() }; std::cout<<"\ngarbage collector info:\n"; for(uint8_t i=vm_str;ib.second;} ); + std::cout<<"\noperands call info:"; uint64_t total=0; for(auto& i:opcall) { if(!i.second) break; total+=i.second; - std::cout<<'\n'<=len) print("read eof when generating string.\n"); ptr+=1; - append(token,str); + gen(str); }, num_gen:func() { @@ -79,7 +93,7 @@ var lexer=func(file) number~=chr(s[ptr]); ptr+=1; } - append(token,num(number)); + gen(num(number)); return; } elsif(ptr0) - append(token,c); + gen(c); ptr+=1; return; }, compile:func() { + line=1; while(ptr