🐛 fix codegen for binary not on some ast nodes

This commit is contained in:
ValKmjolnir 2023-02-12 15:33:38 +08:00
parent 368b057a91
commit 068184f451
5 changed files with 93 additions and 92 deletions

158
makefile
View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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());

View File

@ -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<t+1;i+=1)
coroutine.resume(co);
if(counter-int(counter/1000)*1000==0){
var rate=counter/4e5;
if(counter-int(counter/5000)*5000==0){
var rate=counter/2e5;
print(" ",bar.bar(rate)," ",leftpad(str(int(rate*100)),3),"% | ",str(1e3*int(counter/tm.elapsedMSec()))," tasks/s \r");
}
}
tm.stamp();
for(var i=0;i<4e5;i+=1)
for(var i=0;i<2e5;i+=1)
consumer();
println(" ",bar.bar(1)," 100% | ",str(int(1e3*counter/tm.elapsedMSec()))," tasks/s ");
}