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