diff --git a/nasal_codegen.h b/nasal_codegen.h index 40a63ea..1e8a28a 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -12,15 +12,24 @@ enum op_code op_pushstr, op_newvec,op_newhash,op_newfunc, op_vecapp,op_hashapp, - op_newscope,op_delscope, op_para,op_defpara,op_dynpara,op_entry, op_unot,op_usub, op_add,op_sub,op_mul,op_div,op_lnk, op_addeq,op_subeq,op_muleq,op_diveq,op_lnkeq,op_meq, op_eq,op_neq,op_less,op_leq,op_grt,op_geq, op_pop, - op_jmp,op_jmptrue,op_jmpfalse, - op_jp,op_jtp,op_jfp, + op_newscope, + op_delscope, + op_jmp, + op_jmptrue, + op_jmpfalse, + op_jp, + op_jtp, + op_jfp, + op_continue, + op_break, + op_forindex, // index counter on the top of forindex_stack plus 1 + op_foreach, // index counter on the top of forindex_stack plus 1 and get the value in vector op_call, // call identifier op_callv, // call vec[index] op_callvi, // call vec[immediate] (used in multi-assign/multi-define) @@ -55,8 +64,6 @@ struct {op_newfunc, "newf "}, {op_vecapp, "vapp "}, {op_hashapp, "happ "}, - {op_newscope, "nscp "}, - {op_delscope, "dscp "}, {op_para, "para "}, {op_defpara, "deflt "}, {op_dynpara, "dyn "}, @@ -81,12 +88,18 @@ struct {op_grt, "g "}, {op_geq, "geq "}, {op_pop, "pop "}, + {op_newscope, "nscp "}, + {op_delscope, "dscp "}, {op_jmp, "jmp "}, {op_jmptrue, "jt "}, {op_jmpfalse, "jf "}, {op_jp, "jp "}, {op_jtp, "jtp "}, {op_jfp, "jfp "}, + {op_continue, "contn "}, + {op_break, "break "}, + {op_forindex, "findx "}, + {op_foreach, "feach "}, {op_call, "call "}, {op_callv, "callv "}, {op_callvi, "callvi"}, @@ -122,6 +135,8 @@ private: std::vector number_result_table; std::vector string_result_table; std::vector exec_code; + std::vector continue_ptr; + std::vector break_ptr; int error; void regist_number(double); void regist_string(std::string); @@ -147,6 +162,7 @@ private: void multi_assignment_gen(nasal_ast&); void conditional_gen(nasal_ast&); void loop_gen(nasal_ast&); + void load_continue_break(); void while_gen(nasal_ast&); void for_gen(nasal_ast&); void forindex_gen(nasal_ast&); @@ -661,12 +677,23 @@ void nasal_codegen::loop_gen(nasal_ast& ast) return; } +void nasal_codegen::load_continue_break() +{ + for(int i=0;i