diff --git a/makefile b/makefile index e7f9d92..3df0450 100644 --- a/makefile +++ b/makefile @@ -30,8 +30,10 @@ test:nasal @ ./nasal -op -t -d test/pi.nas @ ./nasal -op -t -d test/prime.nas @ ./nasal -op -t -d test/props_sim.nas + @ ./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 diff --git a/nasal_codegen.h b/nasal_codegen.h index c5af598..50c6174 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -166,7 +166,7 @@ struct struct opcode { - uint16_t op; // opcode + uint8_t op; // opcode uint16_t fidx;// source code file index uint32_t num; // imm num uint32_t line;// line of source code @@ -200,6 +200,11 @@ private: std::unordered_map global; // local : max 32768 upvalues 65536 values std::list> local; + + // func end stack, reserved for print + std::stack fbstk; + std::stack festk; + void die(std::string,const uint32_t); void regist_number(const double); @@ -613,7 +618,7 @@ void nasal_codegen::multi_def(const nasal_ast& ast) { auto& ids=ast[0].child(); int size=ids.size(); - if(ast[1].type()==ast_multi_scalar) + if(ast[1].type()==ast_multi_scalar) // (var a,b,c)=(c,b,a); { auto& vals=ast[1].child(); for(int i=0;i;\n\n",fbstk.top()); + fbstk.pop(); + festk.pop(); + } + if(c.op==op_newf) + { + printf("\nfunc <0x%x>:\n",index); + for(uint32_t i=index;i>24), + uint8_t((c.num&0x00ff0000)>>16), + uint8_t((c.num&0x0000ff00)>>8), + uint8_t(c.num&0x000000ff), + code_table[c.op].name + ); // print detail info switch(c.op) { @@ -1170,9 +1200,10 @@ void nasal_codegen::print_op(uint32_t index) void nasal_codegen::print() { for(auto& num:num_res) - std::cout<<".number "<32) + cx=cx-int(cx/32)*32; + return bits.bitor(l(num,cx),r(num,32-cx)); + } + var F=func(x,y,z){ + return bits.bitor( + bits.bitand(x,y), + bits.bitand(bits.bitnot(x),z) + ); + } + var G=func(x,y,z){ + return bits.bitor( + bits.bitand(x,z), + bits.bitand(y,bits.bitnot(z)) + ); + } + var H=func(x,y,z){ + return bits.bitxor(bits.bitxor(x,y),z); + } + var I=func(x,y,z){ + return bits.bitor( + bits.bitxor(x,y), + bits.bitnot(z) + ); + } + + var len=size(s); + var res=[]; + var v=[256,128,64,32,16,8,4,2,1]; + for(var i=0;i448){ + append(res,1); + mod+=1; + for(;mod<512+448;mod+=1) + append(res,0); + } + var tmp=[]; + + var A=0x01234567; + var B=0x89abcdef; + var C=0xfedcba98; + var D=0x76543210; + println(res,' ',size(res)); +} + +md5("helloworld"); \ No newline at end of file