🐛 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

View File

@ -46,7 +46,7 @@ test:nasal
@ ./nasal -e test/coroutine.nas
@ ./nasal -t -d test/datalog.nas
@ ./nasal -e test/diff.nas
@ ./nasal -e test/donuts.nas 100
@ ./nasal -e test/donuts.nas 50
-@ ./nasal -d test/exception.nas
@ ./nasal -t -d test/fib.nas
@ ./nasal -e test/filesystem.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 ");
}