2 bugs fixed:
empty string will be true in conditional expressions,but now it is false(and string that is not empty and is not numerable will be true) foreach(var i;func(){return []}()); will cause sigsegv because codegen generates error op_pop and op_cntpop,now the counter in_foreach and in_forindex change after generating foreach/forindex expression before block generation.
This commit is contained in:
parent
cd08b2d1bb
commit
6a35c58df4
|
@ -749,10 +749,10 @@ void nasal_codegen::loop_gen(const nasal_ast& ast)
|
|||
break_ptr.push_front(std::vector<int>());
|
||||
switch(ast.type())
|
||||
{
|
||||
case ast_while: while_gen(ast); break;
|
||||
case ast_for: for_gen(ast); break;
|
||||
case ast_forindex: ++in_forindex;forindex_gen(ast);--in_forindex; break;
|
||||
case ast_foreach: ++in_foreach; foreach_gen(ast); --in_foreach; break;
|
||||
case ast_while: while_gen(ast); break;
|
||||
case ast_for: for_gen(ast); break;
|
||||
case ast_forindex:forindex_gen(ast);break;
|
||||
case ast_foreach: foreach_gen(ast); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -872,8 +872,9 @@ void nasal_codegen::forindex_gen(const nasal_ast& ast)
|
|||
gen(op_meq,0,ast[0].line());
|
||||
gen(op_pop,0,0);
|
||||
}
|
||||
|
||||
++in_forindex;
|
||||
block_gen(ast[2]);
|
||||
--in_forindex;
|
||||
gen(op_jmp,ptr,0);
|
||||
code[ptr].num=code.size();
|
||||
load_continue_break(code.size()-1,code.size());
|
||||
|
@ -899,8 +900,9 @@ void nasal_codegen::foreach_gen(const nasal_ast& ast)
|
|||
gen(op_meq,0,ast[0].line());
|
||||
gen(op_pop,0,0);
|
||||
}
|
||||
|
||||
++in_foreach;
|
||||
block_gen(ast[2]);
|
||||
--in_foreach;
|
||||
gen(op_jmp,ptr,0);
|
||||
code[ptr].num=code.size();
|
||||
load_continue_break(code.size()-1,code.size());
|
||||
|
|
|
@ -284,7 +284,7 @@ inline bool nasal_vm::condition(nasal_ref val)
|
|||
{
|
||||
double num=str2num(val.str()->c_str());
|
||||
if(std::isnan(num))
|
||||
return val.str()->empty();
|
||||
return !val.str()->empty();
|
||||
return num;
|
||||
}
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue