diff --git a/makefile b/makefile index 884fbc6..dd24ee3 100644 --- a/makefile +++ b/makefile @@ -1,80 +1,80 @@ -.PHONY:test clean - -SRC=\ - main.cpp\ - nasal_ast.h\ - nasal_err.h\ - nasal_builtin.h\ - nasal_opt.h\ - nasal_codegen.h\ - nasal_gc.h\ - nasal_import.h\ - nasal_lexer.h\ - nasal_parse.h\ - nasal_vm.h\ - nasal_dbg.h\ - nasal.h - -STD=c++14 - -nasal:$(SRC) - $(CXX) -std=$(STD) -O3 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall -nasal.exe:$(SRC) - $(CXX) -std=$(STD) -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static - -stable-release:$(SRC) - $(CXX) -std=$(STD) -O2 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall -stable-release-mingw:$(SRC) - $(CXX) -std=$(STD) -O2 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static - -clean: - @ echo "[clean] nasal" && if [ -e nasal ]; then rm nasal; fi - @ echo "[clean] nasal.exe" && if [ -e nasal.exe ]; then rm nasal.exe; fi - -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 test/bigloop.nas - @ ./nasal -t test/bp.nas - @ ./nasal -d test/calc.nas - @ ./nasal -e test/choice.nas - @ ./nasal -e test/class.nas - @ ./nasal -t -d test/console3D.nas 25 - @ ./nasal -e test/coroutine.nas - @ ./nasal -t -d test/datalog.nas - @ ./nasal -e test/diff.nas - @ ./nasal -e test/donuts.nas 100 - -@ ./nasal -d test/exception.nas - @ ./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 - @ ./nasal -d test/life.nas - @ ./nasal -t test/loop.nas - @ ./nasal -t -d test/mandel.nas - @ ./nasal -t test/mandelbrot.nas - @ ./nasal -t test/md5.nas - @ ./nasal -t -d test/md5compare.nas - -@ ./nasal -d test/module_test.nas - @ ./nasal -e test/nasal_test.nas - @ ./nasal test/occupation.nas 5 - @ ./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 - -@ ./nasal -t test/snake.nas --skip - @ ./nasal -e test/trait.nas - -@ ./nasal -t test/tetris.nas --skip - @ ./nasal -t -d test/turingmachine.nas - @ ./nasal -d test/wavecollapse.nas - @ ./nasal test/word_collector.nas test/md5compare.nas +.PHONY:test clean + +SRC=\ + main.cpp\ + nasal_ast.h\ + nasal_err.h\ + nasal_builtin.h\ + nasal_opt.h\ + nasal_codegen.h\ + nasal_gc.h\ + nasal_import.h\ + nasal_lexer.h\ + nasal_parse.h\ + nasal_vm.h\ + nasal_dbg.h\ + nasal.h + +STD=c++14 + +nasal:$(SRC) + $(CXX) -std=$(STD) -O3 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall +nasal.exe:$(SRC) + $(CXX) -std=$(STD) -O3 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static + +stable-release:$(SRC) + $(CXX) -std=$(STD) -O2 main.cpp -o nasal -fno-exceptions -ldl -Wshadow -Wall +stable-release-mingw:$(SRC) + $(CXX) -std=$(STD) -O2 main.cpp -o nasal.exe -fno-exceptions -Wshadow -Wall -static + +clean: + @ echo "[clean] nasal" && if [ -e nasal ]; then rm nasal; fi + @ echo "[clean] nasal.exe" && if [ -e nasal.exe ]; then rm nasal.exe; fi + +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 test/bigloop.nas + @ ./nasal -t test/bp.nas + @ ./nasal -d test/calc.nas + @ ./nasal -e test/choice.nas + @ ./nasal -e test/class.nas + @ ./nasal -t -d test/console3D.nas 25 + @ ./nasal -e test/coroutine.nas + @ ./nasal -t -d test/datalog.nas + @ ./nasal -e test/diff.nas + @ ./nasal -e test/donuts.nas 50 + -@ ./nasal -d test/exception.nas + @ ./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 + @ ./nasal -d test/life.nas + @ ./nasal -t test/loop.nas + @ ./nasal -t -d test/mandel.nas + @ ./nasal -t test/mandelbrot.nas + @ ./nasal -t test/md5.nas + @ ./nasal -t -d test/md5compare.nas + -@ ./nasal -d test/module_test.nas + @ ./nasal -e test/nasal_test.nas + @ ./nasal test/occupation.nas 5 + @ ./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 + -@ ./nasal -t test/snake.nas --skip + @ ./nasal -e test/trait.nas + -@ ./nasal -t test/tetris.nas --skip + @ ./nasal -t -d test/turingmachine.nas + @ ./nasal -d test/wavecollapse.nas + @ ./nasal test/word_collector.nas test/md5compare.nas @ ./nasal -t -d test/ycombinator.nas \ No newline at end of file diff --git a/nasal_ast.h b/nasal_ast.h index e82e16f..fcc8812 100644 --- a/nasal_ast.h +++ b/nasal_ast.h @@ -47,8 +47,8 @@ enum ast_node:u32 { ast_div, // / ast_link, // ~ ast_neg, // unary - - ast_not, // unary ! - ast_negate, // unary ~ + ast_lnot, // unary ! + ast_bnot, // unary ~ ast_trino, // ?: ast_for, // for keyword ast_forindex, // forindex keyword diff --git a/nasal_codegen.h b/nasal_codegen.h index 25413f0..501547e 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -810,7 +810,7 @@ void codegen::for_gen(const ast& node) { case ast_nil:case ast_num:case ast_str:case ast_bool:break; case ast_vec:case ast_hash:case ast_func: case ast_call: - case ast_neg:case ast_not: + case ast_neg:case ast_lnot:case ast_bnot: case ast_add:case ast_sub: case ast_mult:case ast_div: case ast_link: @@ -876,7 +876,7 @@ void codegen::for_gen(const ast& node) { case ast_nil:case ast_num:case ast_str:case ast_bool:break; case ast_vec:case ast_hash:case ast_func: case ast_call: - case ast_neg:case ast_not: + case ast_neg:case ast_lnot:case ast_bnot: case ast_add:case ast_sub:case ast_mult: case ast_div:case ast_link: case ast_cmpeq:case ast_neq:case ast_leq: @@ -1112,11 +1112,11 @@ void codegen::calc_gen(const ast& node) { calc_gen(node[0]); gen(op_usub,0,node.line()); break; - case ast_not: + case ast_lnot: calc_gen(node[0]); gen(op_lnot,0,node.line()); break; - case ast_negate: + case ast_bnot: calc_gen(node[0]); gen(op_bnot,0,node.line()); break; @@ -1189,7 +1189,8 @@ void codegen::block_gen(const ast& node) { case ast_func: case ast_call: case ast_neg: - case ast_not: + case ast_lnot: + case ast_bnot: case ast_add: case ast_sub: case ast_mult: diff --git a/nasal_parse.h b/nasal_parse.h index e3c08c6..4facc96 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -620,8 +620,8 @@ ast parse::unary() { ast node(toks[ptr].tk_end_line,toks[ptr].tk_end_column,ast_null,toks[ptr].file); switch(toks[ptr].type) { case tok::sub: node.set_type(ast_neg);match(tok::sub);break; - case tok::opnot: node.set_type(ast_not);match(tok::opnot);break; - case tok::floater: node.set_type(ast_negate);match(tok::floater);break; + case tok::opnot: node.set_type(ast_lnot);match(tok::opnot);break; + case tok::floater: node.set_type(ast_bnot);match(tok::floater);break; default: break; } node.add((lookahead(tok::sub) || lookahead(tok::opnot) || lookahead(tok::floater))?unary():scalar()); diff --git a/test/coroutine.nas b/test/coroutine.nas index be9b14a..da42821 100644 --- a/test/coroutine.nas +++ b/test/coroutine.nas @@ -94,7 +94,7 @@ for(var t=0;t<10;t+=1){ coroutine.yield(i); } } - var total=1000; # ms + var co=coroutine.create(productor); var tm=maketimestamp(); @@ -104,14 +104,14 @@ for(var t=0;t<10;t+=1){ counter+=1; for(var i=0;i