Skip to content

Commit

Permalink
make all uses of forward labels count as non-static
Browse files Browse the repository at this point in the history
  • Loading branch information
randomdude999 committed Jan 27, 2024
1 parent 2b14b95 commit 6619e38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/asar/asar_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ static double eval(int depth);
//userfunction

bool foundlabel;
// WARNING: this flag is only correctly set in pass 0, as forward labels are
// always non-static but we don't know when we hit forward-labels past pass 0
bool foundlabel_static;
// only set in pass 0
bool forwardlabel;

struct cachedfile {
Expand Down Expand Up @@ -821,7 +824,10 @@ static double getnumcore()
}

str=start;
if (i==-1) forwardlabel=true;
if (i==-1) {
foundlabel_static = false;
forwardlabel=true;
}
return (int)i&0xFFFFFF;
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/asar/assembleblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ void assembleblock(const char * block, int& single_line_for_tracker)
if(!is("for"))
{
cond = getnum(word[1]);
if (foundlabel && !foundlabel_static && !is("assert")) asar_throw_error(1, error_type_block, error_id_label_in_conditional, word[0]);
if (foundlabel && !foundlabel_static && !is("assert")) asar_throw_error(0, error_type_block, error_id_label_in_conditional, word[0]);
}

if (is("for"))
Expand Down Expand Up @@ -1582,6 +1582,10 @@ void assembleblock(const char * block, int& single_line_for_tracker)
base = getnum(word[2]);

if (foundlabel && !foundlabel_static) static_struct = false;
if (pass > 0) {
// foundlabel_static isn't accurate anymore
static_struct &= structs.find(word[1]).is_static;
}
}

bool old_in_struct = in_struct;
Expand Down
10 changes: 5 additions & 5 deletions tests/labels_static_fail.asm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
;`errElabel_in_conditional
;`errElabel_in_conditional
;`errElabel_in_conditional
;`errElabel_in_conditional
;`errElabel_in_conditional
;`errEno_labels_here
;`errEno_labels_here
;`errElabel_cross_assignment
;`errEno_labels_here
;`errEno_labels_here
;`errEno_labels_here
;`errEdefine_label_math
;`errElabel_in_conditional
;`errElabel_in_conditional
;`errElabel_in_conditional
;`errElabel_in_conditional
;`errElabel_in_conditional
org $008000
ANonStaticLabel:

Expand Down

0 comments on commit 6619e38

Please sign in to comment.