Skip to content

Commit ddb0927

Browse files
authored
Merge pull request #133 from Joe7M/master
Fix bug #132 Function Exprseq doesn't work
2 parents c2dd1f5 + 0bf0739 commit ddb0927

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

samples/distro-examples/tests/all.bas

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ n=1234
1212
a=[1,1;2,-1,-2;1,-2,2,1;1,-3,1,3;3,-1,-2]
1313
b=[44,3,4,5,6]
1414
inva=[1,-1,1;2,-1,2;3,2,-1]
15+
def expression(x) = x * 0.1
16+
DATA 1,"a"
1517

1618
print "ACCESS:" +IFF(ACCESS ("/etc/hostname") != 0, "<> 0", "0")
1719
print "APPEND:"; : APPEND c, "1", "2", "3", "4": PRINT c
@@ -21,7 +23,7 @@ print "BEEP:" ':BEEP
2123
print "BLOAD:" ':BLOAD "/etc/hostname"
2224
print "BPUTC#:" ':BPUTC# fileN; byte
2325
print "BSAVE:" ':BSAVE filename, address, length
24-
print "CALL:" ':CALL (fp)
26+
print "CALL:" :aa=@expression: aa=CALL(aa,5):if(aa != 0.5) then throw "CALL failed"
2527
print "CHART:" ':CHART LINECHART|BARCHART, array() [, style [, x1, y1, x2, y2]]
2628
print "CHDIR:" ':CHDIR dir
2729
print "CHMOD:" ':CHMOD file, mode
@@ -30,7 +32,7 @@ print "CLOSE:" ':CLOSE #fileN
3032
print "CLS:" :CLS
3133
print "COLOR:" :COLOR 1,2
3234
print "COPY:" ':COPY "file", "newfile"
33-
print "DATEDMY:"': DATEDMY(100000,d,m,y); PRINT d,m,u
35+
print "DATEDMY:";: DATEDMY(2459590,jd,jm,jy): print jd;jm;jy
3436
print "DELAY:" ':DELAY ms
3537
print "DELETE:" :DELETE a, 1
3638
print "DERIV:" ':DERIV x, maxtries, maxerr, BYREF result, BYREF errcode USE expr
@@ -40,22 +42,22 @@ print "DRAW:" :DRAW ""
4042
print "DRAWPOLY:" ':DRAWPOLY array [,x-origin,y-origin [, scalef [, color]]] [COLOR color] [FILLED]
4143
print "EMPTY:" ':EMPTY (x)
4244
print "ENV:" :ENV("foo=bar"): if (env("foo") != "bar") then throw "env failed"
43-
print "EXPRSEQ:" ':EXPRSEQ BYREF array, xmin, xmax, count USE expression
45+
print "EXPRSEQ:" : EXPRSEQ aa, -30, 70, 5 USE expression(x): if aa != [-3,-0.5,2,4.5,7] then throw "EXPRSEQ failed"
4446
print "FORM(map):" ':FORM(map)
4547
print "IMAGE:" ':IMAGE [#handle | fileName | http://path-to-file.png | image-var | array of pixmap data]
4648
print "INPUT:" ':INPUT #fileN; var1 [,delim] [, var2 [,delim]] ...
4749
print "INPUT:" ':INPUT [prompt,|;] var[, var [, ...]]
48-
print "INSERT:" :INSERT a, 2, "this", "that", "the", "other"
50+
print "INSERT:" :InsIn=[1,2,3]:INSERT InsIn,2,"this","that","the","other":if(InsIn != [1,2,"other","the","that","this",3]) then throw "INSERT failed"
4951
print "INTERSECT:" ':INTERSECT Ax, Ay, Bx, By, Cx, Cy, Dx, Dy, BYREF type, BYREF Rx, BYREF Ry
50-
print "JOIN:" ':JOIN a, ",.", "ss": PRINT words
52+
print "JOIN:" :JoinIn=["a","b","c"]:JOIN JoinIn(),"-",JoinOut:if(JoinOut != "a-b-c") then throw("JOIN failed")
5153
print "KILL:" ':KILL "file"
5254
print "LINE:" ':LINE [STEP] x,y [,|STEP x2,y2] [, color| COLOR color]
5355
print "LINEINPUT:" ':LINEINPUT [#fileN] var
5456
print "LINPUT:" ':LINPUT [#fileN] var
5557
print "LOCATE:" ':LOCATE y, x
5658
print "LOCK:" ':LOCK
5759
print "LOGPRINT:" ':LOGPRINT ...
58-
print "M3APPLY:" ': M3APPLY m3x3, poly
60+
print "M3APPLY:" ': M3APPLY m3x3, polyko
5961
print "M3IDENT:" ':M3IDENT m3x3
6062
print "M3ROTATE:" ':M3ROTATE m3x3, angle
6163
print "M3SCALE:" ':M3SCALE m3x3, x, y, Sx, Sy
@@ -72,7 +74,7 @@ print "POLYEXT:" :POLYEXT poly, xmin, ymin, xmax, ymax
7274
print "PRINT:" ':PRINT [USING [format];] [expr|str [,|; [expr|str]] ...
7375
print "PSET:" ':PSET [STEP] x,y [, color| COLOR color]
7476
print "RANDOMIZE:" :RANDOMIZE 111
75-
print "READ:" ':READ var[, var ...]
77+
print "READ:" :READ VarRead1, VarRead2: if(VarRead1 != 1 OR VarRead2 != "a") then throw "READ failed"
7678
print "RECT:" ':RECT [STEP] x,y [,|STEP x2,y2] [, color| COLOR color] [FILLED]
7779
print "REDIM:" ':REDIM x
7880
print "RENAME:" ':RENAME "file", "newname"

samples/distro-examples/tests/output/all.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CLOSE:
1515
CLS:
1616
COLOR:
1717
COPY:
18-
DATEDMY:
18+
DATEDMY:1012022
1919
DELAY:
2020
DELETE:
2121
DERIV:
@@ -77,7 +77,7 @@ THROW:
7777
TIMEHMS:
7878
TLOAD:
7979
TRON:
80-
<95>TROFF:
80+
<97>TROFF:
8181
TSAVE:
8282
VIEW:
8383
WINDOW:
@@ -171,7 +171,7 @@ POINT:0
171171
POLYAREA:0
172172
POLYCENT:
173173
POW:12.3
174-
PROGLINE:189
174+
PROGLINE:191
175175
PTDISTLN:0
176176
PTDISTSEG:0
177177
PTSIGN:0
@@ -222,7 +222,7 @@ TRANSLATE:source
222222
TRIM(s):s with spaces
223223
TXTH:1
224224
TXTW:11
225-
UBOUND:22
225+
UBOUND:18
226226
UCASE:CATSANDDOGS
227227
UPPER:CATSANDDOGS
228228
VAL:0

src/common/blib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,7 +2670,7 @@ void cmd_swap(void) {
26702670
void cmd_exprseq(void) {
26712671
var_t *var_p;
26722672
bcip_t use_ip, exit_ip = INVALID_ADDR;
2673-
var_num_t xmin, xmax, dx;
2673+
var_num_t xmin, xmax, x, dx;
26742674
var_int_t count;
26752675

26762676
par_massget("PFFI", &var_p, &xmin, &xmax, &count);
@@ -2689,9 +2689,9 @@ void cmd_exprseq(void) {
26892689
if (count > 1) {
26902690
v_toarray1(var_p, count);
26912691
dx = (xmax - xmin) / (count - 1);
2692-
2692+
x = xmin;
26932693
// add the entries
2694-
for (int i = 0, x = xmin; i < count; i++, x += dx) {
2694+
for (int i = 0; i < count; i++, x += dx) {
26952695
var_t *elem_p = v_elem(var_p, i);
26962696
v_setreal(elem_p, x);
26972697
exec_usefunc(elem_p, use_ip);

0 commit comments

Comments
 (0)