Skip to content

Commit db16d9d

Browse files
committed
Add support for floating point data statements.
1 parent c78eee2 commit db16d9d

File tree

5 files changed

+26
-0
lines changed

5 files changed

+26
-0
lines changed

manual.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,14 @@ General Statements
18781878
(abbreviated `W.`). If no type is
18791879
given, a word data is assumed.
18801880

1881+
If the name _arr_ ends with a `%`
1882+
symbol, this defines a floating point
1883+
array, in this case you can't specify
1884+
a type. It is important that at least
1885+
the first element of each line in the
1886+
data has a decimal point to force
1887+
storing the data as floating point.
1888+
18811889
If you end the `DATA` statement with
18821890
a comma, the following line must be
18831891
another `DATA` statement without the

src/compiler/vartype.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ void labelType::set_type(std::string str)
117117
type = 128;
118118
else if(str == "VT_ARRAY_BYTE")
119119
type = 129;
120+
else if(str == "VT_ARRAY_FLOAT")
121+
type = 130;
120122
else
121123
throw std::runtime_error("invalid label type " + str);
122124
}

src/syntax/float.syn

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ FP_FUNCS:
8888
ADR_EXPR:
8989
emit { TOK_VAR_LOAD, VT_ARRAY_FLOAT } E_VAR_SEARCH "%"
9090
emit { TOK_VAR_ADDR, VT_FLOAT } E_VAR_SEARCH "%"
91+
emit { TOK_NUM, VT_ARRAY_FLOAT } E_LABEL "%"
9192

9293
INT_FUNCTIONS:
9394
"Int" FP_T_EXPR emit TOK_FP_INT
@@ -135,6 +136,16 @@ DIM_VAR_TYPE:<
135136
DIM_VAR:
136137
emit { VT_FLOAT } E_VAR_SEARCH "%" E_PUSH_VAR
137138
139+
DATA_FLOATS: data number
140+
"," E_NUMBER_FP DATA_FLOATS
141+
pass
142+
143+
DATA_TYPE:
144+
emit { VT_ARRAY_FLOAT } DATA_EXT_TYPE EQUAL E_LABEL_SET_TYPE E_NUMBER_FP DATA_FLOATS
145+
146+
DATA_VAR:
147+
E_LABEL_CREATE "%()" emit { TOK_JUMP } E_LABEL_DEF DATA_TYPE
148+
138149
# Can create Float variables now
139150
VAR_CREATE_TYPE:
140151
"%" emit VT_FLOAT

testsuite/tests/floatadr.bas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ A%(2) = 0.03125
1616
@SUM &A%, 3
1717
? SUM%
1818

19+
DATA B%() = -0.125, 0.0625, 0.03125
20+
@SUM &B%, 3
21+
? SUM%
22+
1923
X%=1234.5
2024

2125
@SUM &X%, 1

testsuite/tests/floatadr.chk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ Name: Test for using address of floating point vars
22
Test: run-fp
33
Output:
44
0.21875
5+
-0.03125
56
1234.5

0 commit comments

Comments
 (0)