mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-08-09 01:25:00 +00:00
Order caseblock values in ascending order
This commit is contained in:
@@ -761,7 +761,7 @@ t_opseq *parse_expr(t_opseq *codeseq, int *stackdepth)
|
|||||||
if (stackdepth1 != *stackdepth)
|
if (stackdepth1 != *stackdepth)
|
||||||
parse_error("Inconsistent AND value counts");
|
parse_error("Inconsistent AND value counts");
|
||||||
codeseq = gen_codetag(codeseq, tag_or);
|
codeseq = gen_codetag(codeseq, tag_or);
|
||||||
}
|
}
|
||||||
else if (scantoken == TERNARY_TOKEN)
|
else if (scantoken == TERNARY_TOKEN)
|
||||||
{
|
{
|
||||||
int tag_else, tag_endtri;
|
int tag_else, tag_endtri;
|
||||||
@@ -1056,14 +1056,23 @@ int parse_stmnt(void)
|
|||||||
{
|
{
|
||||||
if (scantoken == OF_TOKEN)
|
if (scantoken == OF_TOKEN)
|
||||||
{
|
{
|
||||||
|
tag_of = tag_new(BRANCH_TYPE);
|
||||||
constval = 0;
|
constval = 0;
|
||||||
parse_constexpr(&constval, &constsize);
|
parse_constexpr(&constval, &constsize);
|
||||||
for (i = 0; i < casecnt; i++)
|
i = casecnt;
|
||||||
if (caseval[i] == constval)
|
while ((i > 0) && (caseval[i-1] > constval))
|
||||||
parse_error("Duplicate CASE");
|
{
|
||||||
tag_of = tag_new(BRANCH_TYPE);
|
//
|
||||||
caseval[casecnt] = constval;
|
// Move larger case consts up
|
||||||
casetag[casecnt] = tag_of;
|
//
|
||||||
|
caseval[i] = caseval[i-1];
|
||||||
|
casetag[i] = casetag[i-1];
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
if (casecnt && (caseval[i] == constval))
|
||||||
|
parse_error("Duplicate CASE");
|
||||||
|
caseval[i] = constval;
|
||||||
|
casetag[i] = tag_of;
|
||||||
casecnt++;
|
casecnt++;
|
||||||
emit_codetag(tag_of);
|
emit_codetag(tag_of);
|
||||||
while (parse_stmnt()) next_line();
|
while (parse_stmnt()) next_line();
|
||||||
@@ -1124,7 +1133,7 @@ int parse_stmnt(void)
|
|||||||
if (infunc)
|
if (infunc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = stack_loop;
|
i = stack_loop;
|
||||||
while (i >= 2)
|
while (i >= 2)
|
||||||
{
|
{
|
||||||
|
@@ -811,12 +811,19 @@ def parse_stmnt
|
|||||||
is OF_TKN
|
is OF_TKN
|
||||||
if casecnt == CASENUM; exit_err(ERR_OVER|ERR_TABLE); fin
|
if casecnt == CASENUM; exit_err(ERR_OVER|ERR_TABLE); fin
|
||||||
caseconst, drop, drop = parse_constexpr
|
caseconst, drop, drop = parse_constexpr
|
||||||
for i = 0 to casecnt-1
|
|
||||||
if caseval=>[i] == caseconst; exit_err(ERR_DUP|ERR_STATE); fin
|
|
||||||
next
|
|
||||||
tag_of = new_tag(RELATIVE_FIXUP)
|
tag_of = new_tag(RELATIVE_FIXUP)
|
||||||
caseval=>[casecnt] = caseconst
|
i = casecnt
|
||||||
casetag=>[casecnt] = tag_of
|
while i > 0 and caseval=>[i-1] > caseconst
|
||||||
|
//
|
||||||
|
// Move larger case consts up
|
||||||
|
//
|
||||||
|
caseval=>[i] = caseval=>[i-1]
|
||||||
|
casetag=>[i] = casetag=>[i-1]
|
||||||
|
i--
|
||||||
|
loop
|
||||||
|
if casecnt and caseval=>[i] == caseconst; exit_err(ERR_DUP|ERR_STATE); fin
|
||||||
|
caseval=>[i] = caseconst
|
||||||
|
casetag=>[i] = tag_of
|
||||||
casecnt++
|
casecnt++
|
||||||
emit_tag(tag_of)
|
emit_tag(tag_of)
|
||||||
while parse_stmnt
|
while parse_stmnt
|
||||||
|
Reference in New Issue
Block a user