mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-04-05 03:37:43 +00:00
New WHEN/IS for hosted compiler
This commit is contained in:
parent
3ee19e86f6
commit
6de120ec89
@ -171,11 +171,20 @@ def emit_daw(tag, offset)#0
|
||||
emit_byte($7E)
|
||||
emit_addr(tag, offset)
|
||||
end
|
||||
def emit_brne(tag)#0
|
||||
def emit_select(tag)#0
|
||||
emit_pending_seq
|
||||
emit_byte($52)
|
||||
emit_reladdr(tag)
|
||||
end
|
||||
def emit_caseblock(cnt, oflist, taglist)#0
|
||||
byte i
|
||||
|
||||
emit_byte(cnt)
|
||||
for i = 0 to cnt-1
|
||||
emit_word(oflist=>[i])
|
||||
emit_reladdr(taglist=>[i])
|
||||
next
|
||||
end
|
||||
def emit_branch(tag)#0
|
||||
emit_pending_seq
|
||||
emit_byte($50)
|
||||
|
@ -1011,7 +1011,6 @@ int parse_stmnt(void)
|
||||
caseval = malloc(sizeof(int)*256);
|
||||
casetag = malloc(sizeof(int)*256);
|
||||
casecnt = 0;
|
||||
//stack_loop++;
|
||||
if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||
parse_error("Bad CASE expression");
|
||||
if (cfnvals > 1)
|
||||
@ -1028,33 +1027,18 @@ int parse_stmnt(void)
|
||||
{
|
||||
constval = 0;
|
||||
parse_constexpr(&constval, &constsize);
|
||||
//if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||
// parse_error("Bad CASE OF expression");
|
||||
//if (cfnvals > 1)
|
||||
//{
|
||||
// parse_warn("Expression value overflow");
|
||||
// while (cfnvals-- > 1) seq = gen_drop(seq);
|
||||
//}
|
||||
//emit_seq(seq);
|
||||
//emit_brne(tag_choice);
|
||||
//tag_choice = tag_new(BRANCH_TYPE);
|
||||
tag_of = tag_new(BRANCH_TYPE);
|
||||
caseval[casecnt] = constval;
|
||||
casetag[casecnt] = tag_of;
|
||||
casecnt++;
|
||||
if (casecnt > 255)
|
||||
if (casecnt > 256)
|
||||
parse_error("CASE clause overflow");
|
||||
emit_codetag(tag_of);
|
||||
while (parse_stmnt()) next_line();
|
||||
//tag_of = tag_new(BRANCH_TYPE);
|
||||
//if (prevstmnt != BREAK_TOKEN) // Fall through to next OF if no break
|
||||
// emit_brnch(tag_of);
|
||||
//emit_codetag(tag_choice);
|
||||
//tag_choice = tag_new(BRANCH_TYPE);
|
||||
}
|
||||
else if (scantoken == DEFAULT_TOKEN)
|
||||
{
|
||||
if (prevstmnt != BREAK_TOKEN) // Fall through to next OF if no break
|
||||
if (prevstmnt != BREAK_TOKEN) // Branch around caseblock if falling through
|
||||
{
|
||||
tag_of = tag_new(BRANCH_TYPE);
|
||||
emit_brnch(tag_of);
|
||||
@ -1084,11 +1068,7 @@ int parse_stmnt(void)
|
||||
}
|
||||
free(caseval);
|
||||
free(casetag);
|
||||
//if (tag_of)
|
||||
// emit_codetag(tag_of);
|
||||
emit_codetag(break_tag);
|
||||
//emit_drop();
|
||||
//stack_loop--;
|
||||
break_tag = tag_prevbrk;
|
||||
infor = prev_for;
|
||||
break;
|
||||
|
@ -590,6 +590,7 @@ def parse_stmnt
|
||||
byte type, elem_type, elem_size, i, cfnvals, prev_for
|
||||
word seq, fromseq, toseq, tag_prevbrk, tag_prevcnt, tag_else, tag_endif, tag_while, tag_wend
|
||||
word tag_repeat, tag_for, tag_choice, tag_of, idptr, addr, stepdir
|
||||
word caseconst, casecnt, caseval, casetag
|
||||
|
||||
if token <> END_TKN and token <> DONE_TKN and token <> OF_TKN and token <> DEFAULT_TKN
|
||||
prevstmnt = token
|
||||
@ -781,11 +782,12 @@ def parse_stmnt
|
||||
is CASE_TKN
|
||||
prev_for = infor
|
||||
infor = FALSE
|
||||
stack_loop++
|
||||
tag_prevbrk = break_tag
|
||||
break_tag = new_tag(RELATIVE_FIXUP)
|
||||
tag_choice = new_tag(RELATIVE_FIXUP)
|
||||
tag_of = new_tag(RELATIVE_FIXUP)
|
||||
caseval = heapalloc(512)
|
||||
casetag = heapalloc(512)
|
||||
casecnt = 0
|
||||
seq, cfnvals = parse_expr(NULL)
|
||||
if !seq; exit_err(ERR_INVAL|ERR_STATE); fin
|
||||
if cfnvals > 1
|
||||
@ -793,32 +795,34 @@ def parse_stmnt
|
||||
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
||||
fin
|
||||
emit_seq(seq)
|
||||
emit_select(tag_choice)
|
||||
nextln
|
||||
while token <> ENDCASE_TKN
|
||||
when token
|
||||
is OF_TKN
|
||||
seq, cfnvals = parse_expr(NULL)
|
||||
if !seq; exit_err(ERR_INVAL|ERR_STATE); fin
|
||||
if cfnvals > 1
|
||||
parse_warn("Expression value overflow")
|
||||
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
||||
fin
|
||||
emit_seq(seq)
|
||||
emit_brne(tag_choice)
|
||||
caseconst, drop, drop = parse_constexpr
|
||||
tag_of = new_tag(RELATIVE_FIXUP)
|
||||
caseval=>[casecnt] = caseconst
|
||||
casetag=>[casecnt] = tag_of
|
||||
casecnt++
|
||||
if casecnt > 256; exit_err(ERR_OVER|ERR_STATE); fin
|
||||
emit_tag(tag_of)
|
||||
while parse_stmnt
|
||||
nextln
|
||||
loop
|
||||
tag_of = new_tag(RELATIVE_FIXUP)
|
||||
if prevstmnt <> BREAK_TKN // Fall through to next OF if no break
|
||||
break
|
||||
is DEFAULT_TKN
|
||||
tag_of = 0
|
||||
if prevstmnt <> BREAK_TKN // Branch around caseblock if falling through
|
||||
tag_of = new_tag(RELATIVE_FIXUP)
|
||||
emit_branch(tag_of)
|
||||
fin
|
||||
emit_tag(tag_choice)
|
||||
tag_choice = new_tag(RELATIVE_FIXUP)
|
||||
break
|
||||
is DEFAULT_TKN
|
||||
emit_tag(tag_of)
|
||||
tag_of = 0
|
||||
emit_caseblock(casecnt, caseval, casetag)
|
||||
tag_choice = 0
|
||||
if tag_of
|
||||
emit_tag(tag_of)
|
||||
fin
|
||||
scan
|
||||
while parse_stmnt
|
||||
nextln
|
||||
@ -832,14 +836,15 @@ def parse_stmnt
|
||||
exit_err(ERR_MISS|ERR_CLOSE|ERR_STATE)
|
||||
wend
|
||||
loop
|
||||
if (tag_of)
|
||||
emit_tag(tag_of)
|
||||
if tag_choice
|
||||
emit_branch(break_tag)
|
||||
emit_tag(tag_choice)
|
||||
emit_caseblock(casecnt, caseval, casetag)
|
||||
fin
|
||||
heaprelease(caseval)
|
||||
emit_tag(break_tag)
|
||||
emit_code(DROP_CODE)
|
||||
break_tag = tag_prevbrk
|
||||
stack_loop--
|
||||
infor = prev_for
|
||||
infor = prev_for
|
||||
break
|
||||
is BREAK_TKN
|
||||
if break_tag
|
||||
|
@ -1328,6 +1328,7 @@ SEL INX
|
||||
STA IPH
|
||||
DEY
|
||||
LDA (IP),Y
|
||||
BEQ ++
|
||||
STA TMPL ; CASE COUNT
|
||||
INC IPL
|
||||
BNE +
|
||||
@ -1358,9 +1359,9 @@ FIXNEXT TYA
|
||||
CLC
|
||||
ADC IPL
|
||||
STA IPL
|
||||
BCC +
|
||||
BCC ++
|
||||
INC IPH
|
||||
+ JMP NEXTOP
|
||||
++ JMP NEXTOP
|
||||
;BREQ INX
|
||||
; LDA ESTKL-1,X
|
||||
; CMP ESTKL,X
|
||||
|
Loading…
x
Reference in New Issue
Block a user