mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-01-07 15:31:49 +00:00
Clean up statement sequence output and PLASM constant evaluation
This commit is contained in:
parent
72463cb690
commit
0fe0782137
@ -119,10 +119,10 @@ export def main(range)#0
|
|||||||
putc('?')
|
putc('?')
|
||||||
wend
|
wend
|
||||||
putln
|
putln
|
||||||
printfunc(1, 2, &(a,b) a+b)
|
//printfunc(1, 2, &(a,b) a+b)
|
||||||
printfunc(1, 2, &(a,b) (a-b))
|
//printfunc(1, 2, &(a,b) (a-b))
|
||||||
lambda = &(x,y) x * y
|
//lambda = &(x,y) x * y
|
||||||
puti(lambda(2,3));putln
|
//puti(lambda(2,3));putln
|
||||||
a = vals123
|
a = vals123
|
||||||
drop, b, drop = vals123
|
drop, b, drop = vals123
|
||||||
drop, drop, c = vals123
|
drop, drop, c = vals123
|
||||||
|
@ -221,7 +221,7 @@ def emit_enter(cparms)#0
|
|||||||
fin
|
fin
|
||||||
end
|
end
|
||||||
def emit_tag(tag)#0
|
def emit_tag(tag)#0
|
||||||
word fixups, updtptr, nextptr
|
word fixups, updtptr, nextptr, codeofst
|
||||||
|
|
||||||
emit_pending_seq
|
emit_pending_seq
|
||||||
if tag_type->[tag] & RESOLVED_FIXUP; puts("Tag already resolved"); exit_err(0); fin // DEBUG
|
if tag_type->[tag] & RESOLVED_FIXUP; puts("Tag already resolved"); exit_err(0); fin // DEBUG
|
||||||
@ -235,15 +235,18 @@ def emit_tag(tag)#0
|
|||||||
*updtptr = codeptr - updtptr
|
*updtptr = codeptr - updtptr
|
||||||
updtptr = nextptr
|
updtptr = nextptr
|
||||||
loop
|
loop
|
||||||
|
updtptr = codeptr
|
||||||
else
|
else
|
||||||
|
codeofst = codeptr - codebuff
|
||||||
for fixups = fixup_cnt-1 downto 0
|
for fixups = fixup_cnt-1 downto 0
|
||||||
if fixup_tag=>[fixups] == tag
|
if fixup_tag=>[fixups] == tag
|
||||||
updtptr = fixup_addr=>[fixups]
|
updtptr = fixup_addr=>[fixups]
|
||||||
*updtptr = *updtptr + codeptr - codebuff
|
*updtptr = *updtptr + codeofst
|
||||||
fin
|
fin
|
||||||
next
|
next
|
||||||
|
updtptr = codeptr - codebuff
|
||||||
fin
|
fin
|
||||||
tag_addr=>[tag] = codeptr
|
tag_addr=>[tag] = updtptr
|
||||||
tag_type->[tag] = tag_type->[tag] | RESOLVED_FIXUP
|
tag_type->[tag] = tag_type->[tag] | RESOLVED_FIXUP
|
||||||
end
|
end
|
||||||
//
|
//
|
||||||
@ -429,8 +432,10 @@ def add_iddata(namestr, len, type, size)#0
|
|||||||
else
|
else
|
||||||
lastglobal=>idval = new_tag(WORD_FIXUP)//datasize
|
lastglobal=>idval = new_tag(WORD_FIXUP)//datasize
|
||||||
emit_tag(lastglobal=>idval)
|
emit_tag(lastglobal=>idval)
|
||||||
emit_fill(size)
|
if size
|
||||||
datasize = datasize + size
|
emit_fill(size)
|
||||||
|
datasize = datasize + size
|
||||||
|
fin
|
||||||
fin
|
fin
|
||||||
globals++
|
globals++
|
||||||
lastglobal = lastglobal + t_id + len
|
lastglobal = lastglobal + t_id + len
|
||||||
@ -801,7 +806,7 @@ def writeheader(refnum)
|
|||||||
header:8 = def_cnt // DEFinition count
|
header:8 = def_cnt // DEFinition count
|
||||||
header:10 = entrypoint + modfix // Init entrypoint
|
header:10 = entrypoint + modfix // Init entrypoint
|
||||||
fileio:write(refnum, @header, len + 2)
|
fileio:write(refnum, @header, len + 2)
|
||||||
return modfix
|
return len
|
||||||
end
|
end
|
||||||
//
|
//
|
||||||
// Write DeFinition Directory
|
// Write DeFinition Directory
|
||||||
@ -896,12 +901,13 @@ end
|
|||||||
// Write Extended REL file
|
// Write Extended REL file
|
||||||
//
|
//
|
||||||
def writemodule(refnum)#0
|
def writemodule(refnum)#0
|
||||||
word esd, esdlen, modfix, modofst, fixups, updtptr
|
word hdrlen, esd, esdlen, modfix, modadj, modofst, fixups, updtptr
|
||||||
//
|
//
|
||||||
// Write module header
|
// Write module header
|
||||||
//
|
//
|
||||||
modfix = writeheader(refnum)
|
hdrlen = writeheader(refnum)
|
||||||
modofst = modfix - MODADDR
|
modfix = hdrlen + MODADDR
|
||||||
|
modofst = hdrlen - codebuff
|
||||||
//
|
//
|
||||||
// Adjust internal fixups for header size
|
// Adjust internal fixups for header size
|
||||||
//
|
//
|
||||||
|
@ -896,13 +896,14 @@ int parse_stmnt(void)
|
|||||||
addr = id_tag(tokenstr, tokenlen);
|
addr = id_tag(tokenstr, tokenlen);
|
||||||
if (scan() != SET_TOKEN)
|
if (scan() != SET_TOKEN)
|
||||||
parse_error("Missing FOR =");
|
parse_error("Missing FOR =");
|
||||||
if (!emit_seq(parse_expr(NULL, &cfnvals)))
|
if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||||
parse_error("Bad FOR expression");
|
parse_error("Bad FOR expression");
|
||||||
if (cfnvals > 1)
|
if (cfnvals > 1)
|
||||||
{
|
{
|
||||||
parse_warn("Expression value overflow");
|
parse_warn("Expression value overflow");
|
||||||
while (cfnvals-- > 1) seq = gen_drop(seq);
|
while (cfnvals-- > 1) seq = gen_drop(seq);
|
||||||
}
|
}
|
||||||
|
emit_seq(seq);
|
||||||
emit_codetag(tag_for);
|
emit_codetag(tag_for);
|
||||||
if (type & LOCAL_TYPE)
|
if (type & LOCAL_TYPE)
|
||||||
type & BYTE_TYPE ? emit_dlb(addr) : emit_dlw(addr);
|
type & BYTE_TYPE ? emit_dlb(addr) : emit_dlw(addr);
|
||||||
@ -914,23 +915,25 @@ int parse_stmnt(void)
|
|||||||
step = -1;
|
step = -1;
|
||||||
else
|
else
|
||||||
parse_error("Missing FOR TO");
|
parse_error("Missing FOR TO");
|
||||||
if (!emit_seq(parse_expr(NULL, &cfnvals)))
|
if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||||
parse_error("Bad FOR TO expression");
|
parse_error("Bad FOR TO expression");
|
||||||
if (cfnvals > 1)
|
if (cfnvals > 1)
|
||||||
{
|
{
|
||||||
parse_warn("Expression value overflow");
|
parse_warn("Expression value overflow");
|
||||||
while (cfnvals-- > 1) seq = gen_drop(seq);
|
while (cfnvals-- > 1) seq = gen_drop(seq);
|
||||||
}
|
}
|
||||||
|
emit_seq(seq);
|
||||||
step > 0 ? emit_brgt(break_tag) : emit_brlt(break_tag);
|
step > 0 ? emit_brgt(break_tag) : emit_brlt(break_tag);
|
||||||
if (scantoken == STEP_TOKEN)
|
if (scantoken == STEP_TOKEN)
|
||||||
{
|
{
|
||||||
if (!emit_seq(parse_expr(NULL, &cfnvals)))
|
if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||||
parse_error("Bad FOR STEP expression");
|
parse_error("Bad FOR STEP expression");
|
||||||
if (cfnvals > 1)
|
if (cfnvals > 1)
|
||||||
{
|
{
|
||||||
parse_warn("Expression value overflow");
|
parse_warn("Expression value overflow");
|
||||||
while (cfnvals-- > 1) seq = gen_drop(seq);
|
while (cfnvals-- > 1) seq = gen_drop(seq);
|
||||||
}
|
}
|
||||||
|
emit_seq(seq);
|
||||||
emit_op(step > 0 ? ADD_TOKEN : SUB_TOKEN);
|
emit_op(step > 0 ? ADD_TOKEN : SUB_TOKEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -951,25 +954,27 @@ int parse_stmnt(void)
|
|||||||
break_tag = tag_new(BRANCH_TYPE);
|
break_tag = tag_new(BRANCH_TYPE);
|
||||||
tag_choice = tag_new(BRANCH_TYPE);
|
tag_choice = tag_new(BRANCH_TYPE);
|
||||||
tag_of = tag_new(BRANCH_TYPE);
|
tag_of = tag_new(BRANCH_TYPE);
|
||||||
if (!emit_seq(parse_expr(NULL, &cfnvals)))
|
if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||||
parse_error("Bad CASE expression");
|
parse_error("Bad CASE expression");
|
||||||
if (cfnvals > 1)
|
if (cfnvals > 1)
|
||||||
{
|
{
|
||||||
parse_warn("Expression value overflow");
|
parse_warn("Expression value overflow");
|
||||||
while (cfnvals-- > 1) seq = gen_drop(seq);
|
while (cfnvals-- > 1) seq = gen_drop(seq);
|
||||||
}
|
}
|
||||||
|
emit_seq(seq);
|
||||||
next_line();
|
next_line();
|
||||||
while (scantoken != ENDCASE_TOKEN)
|
while (scantoken != ENDCASE_TOKEN)
|
||||||
{
|
{
|
||||||
if (scantoken == OF_TOKEN)
|
if (scantoken == OF_TOKEN)
|
||||||
{
|
{
|
||||||
if (!emit_seq(parse_expr(NULL, &cfnvals)))
|
if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||||
parse_error("Bad CASE OF expression");
|
parse_error("Bad CASE OF expression");
|
||||||
if (cfnvals > 1)
|
if (cfnvals > 1)
|
||||||
{
|
{
|
||||||
parse_warn("Expression value overflow");
|
parse_warn("Expression value overflow");
|
||||||
while (cfnvals-- > 1) seq = gen_drop(seq);
|
while (cfnvals-- > 1) seq = gen_drop(seq);
|
||||||
}
|
}
|
||||||
|
emit_seq(seq);
|
||||||
emit_brne(tag_choice);
|
emit_brne(tag_choice);
|
||||||
emit_codetag(tag_of);
|
emit_codetag(tag_of);
|
||||||
while (parse_stmnt()) next_line();
|
while (parse_stmnt()) next_line();
|
||||||
@ -1032,12 +1037,13 @@ int parse_stmnt(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!emit_seq(parse_expr(NULL, &cfnvals)))
|
if (!(seq = parse_expr(NULL, &cfnvals)))
|
||||||
emit_const(0);
|
emit_const(0);
|
||||||
else if (cfnvals > 1)
|
else if (cfnvals > 1)
|
||||||
{
|
{
|
||||||
parse_warn("Expression value overflow");
|
parse_warn("Expression value overflow");
|
||||||
while (cfnvals-- > 1) seq = gen_drop(seq);
|
while (cfnvals-- > 1) seq = gen_drop(seq);
|
||||||
|
emit_seq(seq);
|
||||||
}
|
}
|
||||||
emit_ret();
|
emit_ret();
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ def tos_op_prec(tos)
|
|||||||
return opsp <= tos ?? 100 :: precstack[opsp-1]
|
return opsp <= tos ?? 100 :: precstack[opsp-1]
|
||||||
end
|
end
|
||||||
def push_val(value, size, type)#0
|
def push_val(value, size, type)#0
|
||||||
|
byte i
|
||||||
if valsp == 16; exit_err(ERR_OVER|ERR_CODE|ERR_FRAME); fin
|
if valsp == 16; exit_err(ERR_OVER|ERR_CODE|ERR_FRAME); fin
|
||||||
valstack[valsp] = value
|
valstack[valsp] = value
|
||||||
sizestack[valsp] = size
|
sizestack[valsp] = size
|
||||||
@ -26,6 +27,7 @@ def push_val(value, size, type)#0
|
|||||||
valsp++
|
valsp++
|
||||||
end
|
end
|
||||||
def pop_val#3
|
def pop_val#3
|
||||||
|
byte i
|
||||||
valsp--
|
valsp--
|
||||||
if valsp < 0; exit_err(ERR_INVAL|ERR_CODE|ERR_FRAME); fin
|
if valsp < 0; exit_err(ERR_INVAL|ERR_CODE|ERR_FRAME); fin
|
||||||
return valstack[valsp], sizestack[valsp], typestack[valsp]
|
return valstack[valsp], sizestack[valsp], typestack[valsp]
|
||||||
@ -78,9 +80,12 @@ def calc_binaryop(op)#0
|
|||||||
push_val(val1, size1, type1)
|
push_val(val1, size1, type1)
|
||||||
end
|
end
|
||||||
def parse_constterm
|
def parse_constterm
|
||||||
|
word val
|
||||||
|
byte size, type
|
||||||
|
|
||||||
when scan
|
when scan
|
||||||
is OPEN_PAREN_TKN
|
is OPEN_PAREN_TKN
|
||||||
parse_constexpr
|
push_val(parse_constexpr)
|
||||||
if token <> CLOSE_PAREN_TKN; exit_err(ERR_MISS|ERR_CLOSE|ERR_SYNTAX); fin
|
if token <> CLOSE_PAREN_TKN; exit_err(ERR_MISS|ERR_CLOSE|ERR_SYNTAX); fin
|
||||||
return TRUE
|
return TRUE
|
||||||
is ID_TKN
|
is ID_TKN
|
||||||
@ -114,6 +119,7 @@ def parse_constval
|
|||||||
loop
|
loop
|
||||||
when token
|
when token
|
||||||
is CLOSE_PAREN_TKN
|
is CLOSE_PAREN_TKN
|
||||||
|
value, size, type = pop_val
|
||||||
break
|
break
|
||||||
is STR_TKN
|
is STR_TKN
|
||||||
size = tknlen - 1
|
size = tknlen - 1
|
||||||
@ -686,11 +692,11 @@ def parse_stmnt
|
|||||||
if scan <> SET_TKN; exit_err(ERR_INVAL|ERR_STATE); fin
|
if scan <> SET_TKN; exit_err(ERR_INVAL|ERR_STATE); fin
|
||||||
seq, cfnvals = parse_expr(NULL)
|
seq, cfnvals = parse_expr(NULL)
|
||||||
if !seq; exit_err(ERR_INVAL|ERR_STATE); fin
|
if !seq; exit_err(ERR_INVAL|ERR_STATE); fin
|
||||||
emit_seq(seq)
|
|
||||||
if cfnvals > 1
|
if cfnvals > 1
|
||||||
parse_warn("Expression value overflow")
|
parse_warn("Expression value overflow")
|
||||||
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
||||||
fin
|
fin
|
||||||
|
emit_seq(seq)
|
||||||
emit_tag(tag_for)
|
emit_tag(tag_for)
|
||||||
if type & LOCAL_TYPE
|
if type & LOCAL_TYPE
|
||||||
if type & BYTE_TYPE; emit_dlb(addr); else; emit_dlw(addr); fin
|
if type & BYTE_TYPE; emit_dlb(addr); else; emit_dlw(addr); fin
|
||||||
@ -719,6 +725,7 @@ def parse_stmnt
|
|||||||
parse_warn("Expression value overflow")
|
parse_warn("Expression value overflow")
|
||||||
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
||||||
fin
|
fin
|
||||||
|
emit_seq(seq)
|
||||||
emit_byte(stepdir > 0 ?? ADD_CODE :: SUB_CODE)
|
emit_byte(stepdir > 0 ?? ADD_CODE :: SUB_CODE)
|
||||||
else
|
else
|
||||||
emit_byte(stepdir > 0 ?? INC_CODE :: DEC_CODE)
|
emit_byte(stepdir > 0 ?? INC_CODE :: DEC_CODE)
|
||||||
@ -746,6 +753,7 @@ def parse_stmnt
|
|||||||
parse_warn("Expression value overflow")
|
parse_warn("Expression value overflow")
|
||||||
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
||||||
fin
|
fin
|
||||||
|
emit_seq(seq)
|
||||||
nextln
|
nextln
|
||||||
while token <> ENDCASE_TKN
|
while token <> ENDCASE_TKN
|
||||||
when token
|
when token
|
||||||
@ -756,6 +764,7 @@ def parse_stmnt
|
|||||||
parse_warn("Expression value overflow")
|
parse_warn("Expression value overflow")
|
||||||
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
||||||
fin
|
fin
|
||||||
|
emit_seq(seq)
|
||||||
emit_brne(tag_choice)
|
emit_brne(tag_choice)
|
||||||
emit_tag(tag_of)
|
emit_tag(tag_of)
|
||||||
while parse_stmnt
|
while parse_stmnt
|
||||||
@ -825,11 +834,12 @@ def parse_stmnt
|
|||||||
emit_leave
|
emit_leave
|
||||||
else
|
else
|
||||||
seq, cfnvals = parse_expr(NULL)
|
seq, cfnvals = parse_expr(NULL)
|
||||||
if !seq
|
if not seq
|
||||||
emit_const(0)
|
emit_const(0)
|
||||||
elsif cfnvals > 1
|
elsif cfnvals > 1
|
||||||
exit_err(ERR_OVER|ERR_CLOSE|ERR_STATE)
|
exit_err(ERR_OVER|ERR_CLOSE|ERR_STATE)
|
||||||
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
while cfnvals > 1;cfnvals--; seq = gen_op(seq, DROP_CODE); loop
|
||||||
|
emit_seq(seq)
|
||||||
fin
|
fin
|
||||||
emit_byte(RET_CODE)
|
emit_byte(RET_CODE)
|
||||||
fin
|
fin
|
||||||
|
Loading…
Reference in New Issue
Block a user