Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static bool parse_line(std::string line, int ln, parse &s, bool show_text,
{
if(!short_line.size())
short_line = txt;
else if(short_line.size() + 1 + txt.size() < short_text)
else if(short_line.size() + 1 + txt.size() <= short_text)
{
short_line += ':';
short_line += txt;
Expand Down
19 changes: 11 additions & 8 deletions src/compiler/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class parse
std::set<saved_error> saved_errors;
int linenum;
std::map<std::string, std::vector<codew>> procs;
std::vector<std::string> proc_order; // procs in order of creation
std::vector<std::string> proc_stack;
std::map<std::string, int> vars;
std::map<std::string, labelType> labels;
Expand Down Expand Up @@ -374,7 +375,7 @@ class parse
if(pos < str.length())
{
char p = str[pos];
if(p >= 'a' && p >= 'z')
if(p >= 'a' && p <= 'z')
p = p - ('a' - 'A');
if(c >= 'a' && c <= 'z')
c = c - ('a' - 'A');
Expand Down Expand Up @@ -478,7 +479,7 @@ class parse
{
if(c == '"')
expand.stext += "\"\"";
else if((unsigned) c == 155)
else if((unsigned char)c == 155)
{
in = false;
expand.stext += std::string("\"$") + hexd(c >> 4) + hexd(c);
Expand All @@ -488,7 +489,7 @@ class parse
}
else
{
if((unsigned) c == 155 || c == '"')
if((unsigned char)c == 155 || c == '"')
expand.stext += std::string("$") + hexd(c >> 4) + hexd(c);
else
{
Expand Down Expand Up @@ -584,6 +585,8 @@ class parse
void push_proc(std::string l)
{
proc_stack.push_back(l);
if(!procs.count(l))
proc_order.push_back(l);
code = &procs[l];
}
void pop_proc(std::string l)
Expand All @@ -609,11 +612,11 @@ class parse
p.push_back(codew::ctok("TOK_END", 0));
// To emit procs sorted by line number, copy to a vector
std::vector<std::vector<codew> *> sprocs;
for(auto &c : procs)
if(!c.first.empty() && c.second.size())
sprocs.push_back(&c.second);
// Sort by line number
std::sort(std::begin(sprocs), std::end(sprocs),
for(auto &l : proc_order)
if(procs[l].size())
sprocs.push_back(&procs[l]);
// Sort by line number, keeping the source order of blocks in one line
std::stable_sort(std::begin(sprocs), std::end(sprocs),
[](const std::vector<codew> *a, const std::vector<codew> *b)
{ return (*a)[0].linenum() < (*b)[0].linenum(); });
// Emit into code
Expand Down
13 changes: 13 additions & 0 deletions src/compiler/peephole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,19 @@ class peephole
i--;
continue;
}
// VAR = VAR + 1 (or 1 + VAR), after the rules above ==> INC VAR
// TOK_NUM / 1 / TOK_ADD_VAR / x / TOK_VAR_STORE / x -> TOK_INCVAR / x
if(mtok(0, "TOK_NUM") && mword(1) && val(1) == 1 &&
mtok(2, "TOK_ADD_VAR") && mtok(4, "TOK_VAR_STORE") && varn(3) == varn(5))
{
set_tok(2, "TOK_INCVAR");
del(5);
del(4);
del(1);
del(0);
i--;
continue;
}
// VAR = VAR + 1 ==> INC VAR
// TOK_VAR / x / TOK_PUSH / TOK_NUM / 1 / TOK_ADD / TOK_VAR_STORE / x
// -> TOK_INCVAR / x
Expand Down
2 changes: 2 additions & 0 deletions src/parse.asm
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ loop_redo:
sta (bptr), y
cmp #$9B
beq ucase_end ; End upper-casing, C=1
cpy #$FF
beq too_long ; Line longer than 255 characters

cmp #'"'
bne skip_str ; Skip string constants
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/basic.syn
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ INPUT_VAR_MORE:
pass

INPUT_VAR:
VAR_WORD_LVALUE_SADDR emit { TOK_INPUT_STR, TOK_VAL, TOK_DPOKE }
ARRAY_BYTE_ADDR emit { TOK_SADDR, TOK_INPUT_STR, TOK_VAL, TOK_POKE }
VAR_WORD_LVALUE_SADDR emit { TOK_INPUT_STR, TOK_VAL, TOK_DPOKE }
VAR_STR_LVALUE_SADDR emit { TOK_INPUT_STR, TOK_COPY_STR }

# Optional WORD array type
Expand Down
6 changes: 6 additions & 0 deletions src/syntax/float.syn
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ PRINT_ONE:
INPUT_VAR:
VAR_FP_LVALUE_SADDR emit { TOK_INPUT_STR, TOK_FP_VAL, TOK_FP_STORE }

# Floating point DATA, added at start of the table (<): VAR_WORD_LVALUE_SADDR
# would create a variable with the same name, and accept it
INPUT_VAR:<
emit { TOK_NUM, VT_ARRAY_FLOAT } E_LABEL "%" emit TOK_PUSH PAR_EXPR \
emit { TOK_MUL6, TOK_ADD, TOK_SADDR, TOK_INPUT_STR, TOK_FP_VAL, TOK_FP_STORE }

# Arrays
ARRAY_FLOAT_ADDR:
emit { TOK_VAR_ADDR, VT_FLOAT } E_VAR_SEARCH "%"
Expand Down
8 changes: 5 additions & 3 deletions testsuite/src/fbtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@

#ifdef _WIN32
# define PATH_SEP "\\"
// Implement missing "strndup"
static char *strndup(const char *s, size_t n)
// Implement "strndup", missing in older MinGW versions. Use another name, as
// newer MinGW versions declare it in <string.h>.
static char *fbtest_strndup(const char *s, size_t n)
{
char *ret = malloc(n + 1);
strncpy(ret, s, n);
ret[n] = 0;
return ret;
};
}
# define strndup fbtest_strndup
#else
# define PATH_SEP "/"
#endif
Expand Down
10 changes: 10 additions & 0 deletions testsuite/tests/data-order.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
' Test that DATA arrays in one line are in source order in memory
FOR I=1 TO 2:NEXT I
FOR I=1 TO 2:NEXT I
FOR I=1 TO 2:NEXT I
FOR I=1 TO 2:NEXT I
DATA A() BYTE = 1 : DATA B() BYTE = 2
? ADR(B) > ADR(A)
DA.C()B.=0:DA.D()B.=1:DA.E()B.=2:DA.F()B.=3:DA.G()B.=4:DA.H()B.=5:DA.I()B.=6:DA.J()B.=7:DA.K()B.=8:DA.L()B.=9:DA.M()B.=10:DA.N()B.=11:DA.O()B.=12:DA.P()B.=13:DA.Q()B.=14:DA.R()B.=15:DA.S()B.=16
? (ADR(D)>ADR(C))+(ADR(E)>ADR(D))+(ADR(F)>ADR(E))+(ADR(G)>ADR(F))+(ADR(H)>ADR(G))+(ADR(I)>ADR(H))+(ADR(J)>ADR(I))+(ADR(K)>ADR(J))
? (ADR(L)>ADR(K))+(ADR(M)>ADR(L))+(ADR(N)>ADR(M))+(ADR(O)>ADR(N))+(ADR(P)>ADR(O))+(ADR(Q)>ADR(P))+(ADR(R)>ADR(Q))+(ADR(S)>ADR(R))
6 changes: 6 additions & 0 deletions testsuite/tests/data-order.chk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Name: Test order of DATA arrays in one line
Test: run
Output:
1
8
8
3 changes: 3 additions & 0 deletions testsuite/tests/err-line-long.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
' Lines longer than 255 characters are an error in the native compiler
? 1
A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1:A=1 :?A
3 changes: 3 additions & 0 deletions testsuite/tests/err-line-long.chk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name: Check detection of lines too long for the native compiler
Test: compile-error-native
Error: too long at line 3 column 0
5 changes: 5 additions & 0 deletions testsuite/tests/fp-input-data.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
' Test for statement "INPUT" into floating point DATA arrays
DATA F%() = 1.5, 2.5
? "Start"
input F%(1)
? err(), F%(0), F%(1)
8 changes: 8 additions & 0 deletions testsuite/tests/fp-input-data.chk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Name: Test statement "INPUT" into floating point DATA arrays
Test: run-fp
Input:
0.25
.
Output:
Start
?1 1.5 0.25
11 changes: 11 additions & 0 deletions testsuite/tests/input-data.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
' Test for statement "INPUT" into DATA arrays
DATA B() BYTE = 1, 2, 3
DATA W() = 1000, 2000
DIM D(2) BYTE
? "Start"
input B(1)
? err(), B(0); B(1); B(2)
input "Word:", W(1)
? err(), W(0), W(1)
input D(1)
? err(), D(1)
12 changes: 12 additions & 0 deletions testsuite/tests/input-data.chk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Name: Test statement "INPUT" into DATA arrays
Test: run
Input:
7
2345
9
.
Output:
Start
?1 173
Word: 1 1000 2345
?1 9
Loading