1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-18 22:24:28 +00:00

Better WHILE/LOOP

This commit is contained in:
David Schmenk 2018-03-04 15:00:40 -08:00
parent 18301b6ce9
commit e1090c012c
2 changed files with 10 additions and 8 deletions

View File

@ -861,9 +861,10 @@ int parse_stmnt(void)
tag_while = tag_new(BRANCH_TYPE);
tag_wend = tag_new(BRANCH_TYPE);
tag_prevcnt = cont_tag;
cont_tag = tag_while;
cont_tag = tag_new(BRANCH_TYPE);
tag_prevbrk = break_tag;
break_tag = tag_wend;
emit_brnch(cont_tag);
emit_codetag(tag_while);
if (!(seq = parse_expr(NULL, &cfnvals)))
parse_error("Bad expression");
@ -872,12 +873,12 @@ int parse_stmnt(void)
parse_warn("Expression value overflow");
while (cfnvals-- > 1) seq = gen_drop(seq);
}
seq = gen_brfls(seq, tag_wend);
emit_seq(seq);
seq = gen_brtru(seq, tag_while);
while (parse_stmnt()) next_line();
if (scantoken != LOOP_TOKEN)
parse_error("Missing WHILE/END");
emit_brnch(tag_while);
emit_codetag(cont_tag);
emit_seq(seq);
emit_codetag(tag_wend);
break_tag = tag_prevbrk;
cont_tag = tag_prevcnt;

View File

@ -645,9 +645,10 @@ def parse_stmnt
tag_while = new_tag(RELATIVE_FIXUP)
tag_wend = new_tag(RELATIVE_FIXUP)
tag_prevcnt = cont_tag
cont_tag = tag_while
cont_tag = new_tag(RELATIVE_FIXUP)
tag_prevbrk = break_tag
break_tag = tag_wend
emit_branch(cont_tag)
emit_tag(tag_while)
seq, cfnvals = parse_expr(NULL)
if !seq; exit_err(ERR_INVAL|ERR_STATE); fin
@ -655,13 +656,13 @@ def parse_stmnt
parse_warn("Expression value overflow")
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
fin
seq = gen_oprel(seq, BRFALSE_CODE, tag_wend)
emit_seq(seq)
seq = gen_oprel(seq, BRTRUE_CODE, tag_while)
while parse_stmnt
nextln
loop
if token <> LOOP_TKN; exit_err(ERR_MISS|ERR_CLOSE|ERR_STATE); fin
emit_branch(tag_while)
emit_tag(cont_tag)
emit_seq(seq)
emit_tag(tag_wend)
break_tag = tag_prevbrk
cont_tag = tag_prevcnt