Skip to content

Commit f41f249

Browse files
authored
Merge pull request #394 from boriel/bugfix/byref_byref
Fix bug when passing parameters
2 parents a897d60 + d12fa2c commit f41f249

7 files changed

Lines changed: 270 additions & 2 deletions

File tree

arch/zx48k/translator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ def visit_ARGUMENT(self, node):
223223
self.ic_load(TYPE.uinteger, t, '#' + node.mangled)
224224
elif scope == SCOPE.parameter: # A function has used a parameter as an argument to another function call
225225
if not node.value.byref: # It's like a local variable
226-
self.ic_paddr(node.value.offset, t)
226+
offset = 1 if node.type_ in (Type.byte_, Type.ubyte) else 0
227+
self.ic_paddr(node.value.offset + offset, t)
227228
else:
228-
self.ic_pload(TYPE.uinteger, t, str(node.value.offset))
229+
self.ic_pload(gl.PTR_TYPE, t, str(node.value.offset))
229230
elif scope == SCOPE.local:
230231
self.ic_paddr(-node.value.offset, t)
231232

tests/functional/byrefbyref.asm

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
jp __MAIN_PROGRAM__
14+
ZXBASIC_USER_DATA:
15+
; Defines USER DATA Length in bytes
16+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
17+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
18+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
19+
_v:
20+
DEFB 00
21+
ZXBASIC_USER_DATA_END:
22+
__MAIN_PROGRAM__:
23+
ld hl, _v
24+
push hl
25+
call _primero
26+
ld hl, 0
27+
ld b, h
28+
ld c, l
29+
__END_PROGRAM:
30+
di
31+
ld hl, (__CALL_BACK__)
32+
ld sp, hl
33+
exx
34+
pop hl
35+
exx
36+
pop iy
37+
pop ix
38+
ei
39+
ret
40+
__CALL_BACK__:
41+
DEFW 0
42+
_primero:
43+
push ix
44+
ld ix, 0
45+
add ix, sp
46+
ld l, (ix+4)
47+
ld h, (ix+5)
48+
push hl
49+
call _segundo
50+
_primero__leave:
51+
ld sp, ix
52+
pop ix
53+
exx
54+
pop hl
55+
ex (sp), hl
56+
exx
57+
ret
58+
_segundo:
59+
push ix
60+
ld ix, 0
61+
add ix, sp
62+
ld h, (ix+5)
63+
ld l, (ix+4)
64+
ld (hl), 2
65+
_segundo__leave:
66+
ld sp, ix
67+
pop ix
68+
exx
69+
pop hl
70+
ex (sp), hl
71+
exx
72+
ret
73+
END

tests/functional/byrefbyref.bas

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
dim v as Ubyte
3+
primero v
4+
5+
sub primero(byref vv as ubyte)
6+
segundo vv
7+
end sub
8+
9+
sub segundo(byref vvv as ubyte)
10+
vvv = 2
11+
end sub
12+
13+

tests/functional/byvalbyref.asm

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
jp __MAIN_PROGRAM__
14+
ZXBASIC_USER_DATA:
15+
; Defines USER DATA Length in bytes
16+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
17+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
18+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
19+
_v:
20+
DEFB 00
21+
ZXBASIC_USER_DATA_END:
22+
__MAIN_PROGRAM__:
23+
ld a, (_v)
24+
push af
25+
call _primero
26+
ld hl, 0
27+
ld b, h
28+
ld c, l
29+
__END_PROGRAM:
30+
di
31+
ld hl, (__CALL_BACK__)
32+
ld sp, hl
33+
exx
34+
pop hl
35+
exx
36+
pop iy
37+
pop ix
38+
ei
39+
ret
40+
__CALL_BACK__:
41+
DEFW 0
42+
_primero:
43+
push ix
44+
ld ix, 0
45+
add ix, sp
46+
push ix
47+
pop hl
48+
ld de, 5
49+
add hl, de
50+
push hl
51+
call _segundo
52+
_primero__leave:
53+
ld sp, ix
54+
pop ix
55+
exx
56+
pop hl
57+
ex (sp), hl
58+
exx
59+
ret
60+
_segundo:
61+
push ix
62+
ld ix, 0
63+
add ix, sp
64+
ld h, (ix+5)
65+
ld l, (ix+4)
66+
ld (hl), 2
67+
_segundo__leave:
68+
ld sp, ix
69+
pop ix
70+
exx
71+
pop hl
72+
ex (sp), hl
73+
exx
74+
ret
75+
END

tests/functional/byvalbyref.bas

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
dim v as Ubyte
3+
primero v
4+
5+
sub primero(vv as ubyte)
6+
segundo vv
7+
end sub
8+
9+
sub segundo(byref vvv as ubyte)
10+
vvv = 2
11+
end sub
12+
13+

tests/functional/localbyref.asm

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
jp __MAIN_PROGRAM__
14+
ZXBASIC_USER_DATA:
15+
; Defines USER DATA Length in bytes
16+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
17+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
18+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
19+
ZXBASIC_USER_DATA_END:
20+
__MAIN_PROGRAM__:
21+
call _primero
22+
ld hl, 0
23+
ld b, h
24+
ld c, l
25+
__END_PROGRAM:
26+
di
27+
ld hl, (__CALL_BACK__)
28+
ld sp, hl
29+
exx
30+
pop hl
31+
exx
32+
pop iy
33+
pop ix
34+
ei
35+
ret
36+
__CALL_BACK__:
37+
DEFW 0
38+
_primero:
39+
push ix
40+
ld ix, 0
41+
add ix, sp
42+
ld hl, 0
43+
push hl
44+
inc sp
45+
push ix
46+
pop hl
47+
ld bc, -1
48+
add hl, bc
49+
ex de, hl
50+
ld hl, __LABEL0
51+
ld bc, 1
52+
ldir
53+
push ix
54+
pop hl
55+
ld de, -1
56+
add hl, de
57+
push hl
58+
call _segundo
59+
_primero__leave:
60+
ld sp, ix
61+
pop ix
62+
ret
63+
_segundo:
64+
push ix
65+
ld ix, 0
66+
add ix, sp
67+
ld h, (ix+5)
68+
ld l, (ix+4)
69+
ld (hl), 2
70+
_segundo__leave:
71+
ld sp, ix
72+
pop ix
73+
exx
74+
pop hl
75+
ex (sp), hl
76+
exx
77+
ret
78+
__LABEL0:
79+
DEFB 01h
80+
END

tests/functional/localbyref.bas

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
primero()
3+
4+
sub primero()
5+
DIM vv as Ubyte = 1
6+
segundo vv
7+
end sub
8+
9+
sub segundo(byref vvv as ubyte)
10+
vvv = 2
11+
end sub
12+
13+

0 commit comments

Comments
 (0)