Skip to content

Commit 4f8c630

Browse files
committed
Update grammar to allow array name clash
When using an array as parameter, ARRAY_ID instead of ID might be returned if the param name matches one of an array name
1 parent 8244bd1 commit 4f8c630

6 files changed

Lines changed: 236 additions & 8 deletions

File tree

parsetab/tabs.dbm.bak

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'zxbppparse', (0, 69185)
2-
'asmparse', (69632, 250690)
3-
'zxnext_asmparse', (320512, 281648)
4-
'zxbparser', (602624, 707985)
1+
'zxbppparse', (0, 69164)
2+
'asmparse', (69632, 250673)
3+
'zxnext_asmparse', (320512, 281631)
4+
'zxbparser', (602624, 708961)

parsetab/tabs.dbm.dat

976 Bytes
Binary file not shown.

parsetab/tabs.dbm.dir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'zxbppparse', (0, 69185)
2-
'asmparse', (69632, 250690)
3-
'zxnext_asmparse', (320512, 281648)
4-
'zxbparser', (602624, 707985)
1+
'zxbppparse', (0, 69164)
2+
'asmparse', (69632, 250673)
3+
'zxnext_asmparse', (320512, 281631)
4+
'zxbparser', (602624, 708961)

tests/functional/pararray9.asm

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
ld hl, _q
14+
push hl
15+
call _test
16+
ld hl, 0
17+
ld b, h
18+
ld c, l
19+
__END_PROGRAM:
20+
di
21+
ld hl, (__CALL_BACK__)
22+
ld sp, hl
23+
exx
24+
pop hl
25+
exx
26+
pop iy
27+
pop ix
28+
ei
29+
ret
30+
__CALL_BACK__:
31+
DEFW 0
32+
_test:
33+
push ix
34+
ld ix, 0
35+
add ix, sp
36+
ld hl, 3
37+
push hl
38+
push ix
39+
pop hl
40+
ld de, 4
41+
add hl, de
42+
call __ARRAY_PTR
43+
ld de, 7
44+
ld (hl), e
45+
inc hl
46+
ld (hl), d
47+
_test__leave:
48+
ld sp, ix
49+
pop ix
50+
exx
51+
pop hl
52+
ex (sp), hl
53+
exx
54+
ret
55+
#line 1 "array.asm"
56+
; vim: ts=4:et:sw=4:
57+
; Copyleft (K) by Jose M. Rodriguez de la Rosa
58+
; (a.k.a. Boriel)
59+
; http://www.boriel.com
60+
; -------------------------------------------------------------------
61+
; Simple array Index routine
62+
; Number of total indexes dimensions - 1 at beginning of memory
63+
; HL = Start of array memory (First two bytes contains N-1 dimensions)
64+
; Dimension values on the stack, (top of the stack, highest dimension)
65+
; E.g. A(2, 4) -> PUSH <4>; PUSH <2>
66+
; For any array of N dimension A(aN-1, ..., a1, a0)
67+
; and dimensions D[bN-1, ..., b1, b0], the offset is calculated as
68+
; O = [a0 + b0 * (a1 + b1 * (a2 + ... bN-2(aN-1)))]
69+
; What I will do here is to calculate the following sequence:
70+
; ((aN-1 * bN-2) + aN-2) * bN-3 + ...
71+
#line 1 "mul16.asm"
72+
__MUL16: ; Mutiplies HL with the last value stored into de stack
73+
; Works for both signed and unsigned
74+
PROC
75+
LOCAL __MUL16LOOP
76+
LOCAL __MUL16NOADD
77+
ex de, hl
78+
pop hl ; Return address
79+
ex (sp), hl ; CALLEE caller convention
80+
__MUL16_FAST:
81+
ld b, 16
82+
ld a, h
83+
ld c, l
84+
ld hl, 0
85+
__MUL16LOOP:
86+
add hl, hl ; hl << 1
87+
sla c
88+
rla ; a,c << 1
89+
jp nc, __MUL16NOADD
90+
add hl, de
91+
__MUL16NOADD:
92+
djnz __MUL16LOOP
93+
ret ; Result in hl (16 lower bits)
94+
ENDP
95+
#line 20 "array.asm"
96+
#line 24 "/zxbasic/library-asm/array.asm"
97+
__ARRAY_PTR: ;; computes an array offset from a pointer
98+
ld c, (hl)
99+
inc hl
100+
ld h, (hl)
101+
ld l, c
102+
__ARRAY:
103+
PROC
104+
LOCAL LOOP
105+
LOCAL ARRAY_END
106+
LOCAL RET_ADDRESS ; Stores return address
107+
LOCAL TMP_ARR_PTR ; Stores pointer temporarily
108+
ld e, (hl)
109+
inc hl
110+
ld d, (hl)
111+
inc hl
112+
ld (TMP_ARR_PTR), hl
113+
ex de, hl
114+
ex (sp), hl ; Return address in HL, array address in the stack
115+
ld (RET_ADDRESS + 1), hl ; Stores it for later
116+
exx
117+
pop hl ; Will use H'L' as the pointer
118+
ld c, (hl) ; Loads Number of dimensions from (hl)
119+
inc hl
120+
ld b, (hl)
121+
inc hl ; Ready
122+
exx
123+
ld hl, 0 ; HL = Offset "accumulator"
124+
LOOP:
125+
#line 62 "/zxbasic/library-asm/array.asm"
126+
pop bc ; Get next index (Ai) from the stack
127+
#line 72 "/zxbasic/library-asm/array.asm"
128+
add hl, bc ; Adds current index
129+
exx ; Checks if B'C' = 0
130+
ld a, b ; Which means we must exit (last element is not multiplied by anything)
131+
or c
132+
jr z, ARRAY_END ; if B'Ci == 0 we are done
133+
ld e, (hl) ; Loads next dimension into D'E'
134+
inc hl
135+
ld d, (hl)
136+
inc hl
137+
push de
138+
dec bc ; Decrements loop counter
139+
exx
140+
pop de ; DE = Max bound Number (i-th dimension)
141+
call __FNMUL
142+
jp LOOP
143+
ARRAY_END:
144+
ld a, (hl)
145+
exx
146+
#line 101 "/zxbasic/library-asm/array.asm"
147+
LOCAL ARRAY_SIZE_LOOP
148+
ex de, hl
149+
ld hl, 0
150+
ld b, a
151+
ARRAY_SIZE_LOOP:
152+
add hl, de
153+
djnz ARRAY_SIZE_LOOP
154+
#line 111 "/zxbasic/library-asm/array.asm"
155+
ex de, hl
156+
ld hl, (TMP_ARR_PTR)
157+
ld a, (hl)
158+
inc hl
159+
ld h, (hl)
160+
ld l, a
161+
add hl, de ; Adds element start
162+
RET_ADDRESS:
163+
jp 0
164+
;; Performs a faster multiply for little 16bit numbs
165+
LOCAL __FNMUL, __FNMUL2
166+
__FNMUL:
167+
xor a
168+
or h
169+
jp nz, __MUL16_FAST
170+
or l
171+
ret z
172+
cp 33
173+
jp nc, __MUL16_FAST
174+
ld b, l
175+
ld l, h ; HL = 0
176+
__FNMUL2:
177+
add hl, de
178+
djnz __FNMUL2
179+
ret
180+
TMP_ARR_PTR:
181+
DW 0 ; temporary storage for pointer to tables
182+
ENDP
183+
#line 44 "pararray9.bas"
184+
ZXBASIC_USER_DATA:
185+
_q:
186+
DEFW __LABEL0
187+
_q.__DATA__.__PTR__:
188+
DEFW _q.__DATA__
189+
_q.__DATA__:
190+
DEFB 00h
191+
DEFB 00h
192+
DEFB 00h
193+
DEFB 00h
194+
DEFB 00h
195+
DEFB 00h
196+
DEFB 00h
197+
DEFB 00h
198+
DEFB 00h
199+
DEFB 00h
200+
DEFB 00h
201+
DEFB 00h
202+
DEFB 00h
203+
DEFB 00h
204+
DEFB 00h
205+
DEFB 00h
206+
DEFB 00h
207+
DEFB 00h
208+
DEFB 00h
209+
DEFB 00h
210+
DEFB 00h
211+
DEFB 00h
212+
__LABEL0:
213+
DEFW 0000h
214+
DEFB 02h
215+
; Defines DATA END --> HEAP size is 0
216+
ZXBASIC_USER_DATA_END:
217+
; Defines USER DATA Length in bytes
218+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
219+
END

tests/functional/pararray9.bas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
DIM q(10) as UInteger
3+
FUNCTION test(q() as UInteger) as Byte
4+
q(3) = 7
5+
END FUNCTION
6+
7+
test(q)
8+

zxb/zxbparser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,6 +3031,7 @@ def p_param_definition(p):
30313031

30323032
def p_param_def_array(p):
30333033
""" param_def : ID LP RP typedef
3034+
| ARRAY_ID LP RP typedef
30343035
"""
30353036
typeref = p[4]
30363037
if typeref is None:

0 commit comments

Comments
 (0)