Skip to content
Merged
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
8 changes: 6 additions & 2 deletions arch/zx48k/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,9 @@ def visit_LBOUND(self, node):
if entry.scope == SCOPE.global_:
self.ic_fparam(gl.PTR_TYPE, '#{}'.format(entry.mangled))
elif entry.scope == SCOPE.parameter:
self.ic_fparam(entry.t, entry.offset)
self.ic_pload(gl.PTR_TYPE, entry.t, entry.offset)
t1 = optemps.new_t()
self.ic_fparam(gl.PTR_TYPE, t1)
elif entry.scope == SCOPE.local:
self.ic_paddr(-entry.offset, entry.t)
t1 = optemps.new_t()
Expand All @@ -1320,7 +1322,9 @@ def visit_UBOUND(self, node):
if entry.scope == SCOPE.global_:
self.ic_fparam(gl.PTR_TYPE, '#{}'.format(entry.mangled))
elif entry.scope == SCOPE.parameter:
self.ic_fparam(entry.t, entry.offset)
self.ic_pload(gl.PTR_TYPE, entry.t, entry.offset)
t1 = optemps.new_t()
self.ic_fparam(gl.PTR_TYPE, t1)
elif entry.scope == SCOPE.local:
self.ic_paddr(-entry.offset, entry.t)
t1 = optemps.new_t()
Expand Down
4 changes: 2 additions & 2 deletions arch/zx48k/translatorinstvisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def ic_param(self, type_, t):
def ic_pastore(self, type_, offset, t):
return self.emit('pastore' + self.TSUFFIX(type_), offset, t)

def ic_pload(self, type_, t1, t2):
return self.emit('pload' + self.TSUFFIX(type_), t1, t2)
def ic_pload(self, type_, t1, offset):
return self.emit('pload' + self.TSUFFIX(type_), t1, offset)

def ic_pow(self, type_):
return self.emit('pow' + self.TSUFFIX(type_))
Expand Down
175 changes: 175 additions & 0 deletions tests/functional/lbound7.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
org 32768
__START_PROGRAM:
di
push ix
push iy
exx
push hl
exx
ld hl, 0
add hl, sp
ld (__CALL_BACK__), hl
ei
ld hl, _a
push hl
call _test
ld hl, (_b)
push hl
ld hl, _a
call __LBOUND
ld (_c), hl
ld hl, 0
ld b, h
ld c, l
__END_PROGRAM:
di
ld hl, (__CALL_BACK__)
ld sp, hl
exx
pop hl
exx
pop iy
pop ix
ei
ret
__CALL_BACK__:
DEFW 0
_test:
push ix
ld ix, 0
add ix, sp
ld hl, 0
ld (_b), hl
jp __LABEL0
__LABEL3:
ld hl, (_b)
push hl
ld l, (ix+4)
ld h, (ix+5)
call __LBOUND
ld (_c), hl
__LABEL4:
ld hl, (_b)
inc hl
ld (_b), hl
__LABEL0:
ld hl, 3
ld de, (_b)
or a
sbc hl, de
jp nc, __LABEL3
__LABEL2:
_test__leave:
ld sp, ix
pop ix
exx
pop hl
ex (sp), hl
exx
ret
#line 1 "bound.asm"
; ---------------------------------------------------------
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
; http://www.boriel.com
;
; ZX BASIC Compiler http://www.zxbasic.net
; This code is released under the BSD License
; ---------------------------------------------------------
; Implements both LBOUND(array, N) and UBOUND(array, N) function
; Parameters:
; HL = PTR to array
; [stack - 2] -> N (dimension)
PROC
LOCAL __BOUND
LOCAL __DIM_NOT_EXIST
LOCAL __CONT
__LBOUND:
ld a, 4
jr __BOUND
__UBOUND:
ld a, 6
__BOUND:
ex de, hl ; DE <-- Array ptr
pop hl ; HL <-- Ret address
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
push hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
ld c, (hl)
inc hl
ld b, (hl)
inc bc ; Number of total dimensions of the array
pop hl ; Recovers ARRAY PTR
ex af, af' ; Saves A for later
ld a, d
or e
jr nz, __CONT ; N = 0 => Return number of dimensions
;; Return the number of dimensions of the array
ld h, b
ld l, c
ret
__CONT:
dec de
ex af, af' ; Recovers A (contains PTR offset)
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
or a
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
jr nc, __DIM_NOT_EXIST
add hl, bc ; restores HL = (N - 1)
add hl, hl ; hl *= 2
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
ld b, 0
ld c, a
add hl, bc ; HL = &BOUND_PTR
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
add hl, de ; hl += OFFSET __LBOUND._xxxx
ld e, (hl) ; de = (hl)
inc hl
ld d, (hl)
ex de, hl ; hl = de => returns result in HL
ret
__DIM_NOT_EXIST:
; The dimension requested by the user does not exists. Return 0
ld hl, 0
ret
ENDP
#line 59 "lbound7.bas"
ZXBASIC_USER_DATA:
_b:
DEFB 00, 00
_c:
DEFB 00, 00
_a:
DEFW __LABEL5
_a.__DATA__.__PTR__:
DEFW _a.__DATA__
DEFW _a.__LBOUND__
DEFW 0
_a.__DATA__:
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
__LABEL5:
DEFW 0001h
DEFW 0003h
DEFB 01h
_a.__LBOUND__:
DEFW 0003h
DEFW 0007h
; Defines DATA END --> HEAP size is 0
ZXBASIC_USER_DATA_END:
; Defines USER DATA Length in bytes
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
END
14 changes: 14 additions & 0 deletions tests/functional/lbound7.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

DIM b, c as UInteger

DIM a(3 TO 5, 7 TO 9) As UByte
SUB test(a() as UByte)
FOR b = 0 TO 3
c = LBound(a, b)
NEXT
END SUB

test(a)
c = LBound(a, b) ' This will signal LBound is used on Array a


175 changes: 175 additions & 0 deletions tests/functional/ubound7.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
org 32768
__START_PROGRAM:
di
push ix
push iy
exx
push hl
exx
ld hl, 0
add hl, sp
ld (__CALL_BACK__), hl
ei
ld hl, _a
push hl
call _test
ld hl, (_b)
push hl
ld hl, _a
call __UBOUND
ld (_c), hl
ld hl, 0
ld b, h
ld c, l
__END_PROGRAM:
di
ld hl, (__CALL_BACK__)
ld sp, hl
exx
pop hl
exx
pop iy
pop ix
ei
ret
__CALL_BACK__:
DEFW 0
_test:
push ix
ld ix, 0
add ix, sp
ld hl, 0
ld (_b), hl
jp __LABEL0
__LABEL3:
ld hl, (_b)
push hl
ld l, (ix+4)
ld h, (ix+5)
call __UBOUND
ld (_c), hl
__LABEL4:
ld hl, (_b)
inc hl
ld (_b), hl
__LABEL0:
ld hl, 3
ld de, (_b)
or a
sbc hl, de
jp nc, __LABEL3
__LABEL2:
_test__leave:
ld sp, ix
pop ix
exx
pop hl
ex (sp), hl
exx
ret
#line 1 "bound.asm"
; ---------------------------------------------------------
; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
; http://www.boriel.com
;
; ZX BASIC Compiler http://www.zxbasic.net
; This code is released under the BSD License
; ---------------------------------------------------------
; Implements both LBOUND(array, N) and UBOUND(array, N) function
; Parameters:
; HL = PTR to array
; [stack - 2] -> N (dimension)
PROC
LOCAL __BOUND
LOCAL __DIM_NOT_EXIST
LOCAL __CONT
__LBOUND:
ld a, 4
jr __BOUND
__UBOUND:
ld a, 6
__BOUND:
ex de, hl ; DE <-- Array ptr
pop hl ; HL <-- Ret address
ex (sp), hl ; CALLEE: HL <-- N, (SP) <-- Ret address
ex de, hl ; DE <-- N, HL <-- ARRAY_PTR
push hl
ld c, (hl)
inc hl
ld h, (hl)
ld l, c ; HL = start of dimension table (first position contains number of dimensions - 1)
ld c, (hl)
inc hl
ld b, (hl)
inc bc ; Number of total dimensions of the array
pop hl ; Recovers ARRAY PTR
ex af, af' ; Saves A for later
ld a, d
or e
jr nz, __CONT ; N = 0 => Return number of dimensions
;; Return the number of dimensions of the array
ld h, b
ld l, c
ret
__CONT:
dec de
ex af, af' ; Recovers A (contains PTR offset)
ex de, hl ; HL = N (dimension asked) - 1, DE = Array PTR
or a
sbc hl, bc ; if no Carry => the user asked for a dimension that does not exist. Return 0
jr nc, __DIM_NOT_EXIST
add hl, bc ; restores HL = (N - 1)
add hl, hl ; hl *= 2
ex de, hl ; hl = ARRAY_PTR + 3, DE jsz = (N - 1) * 2
ld b, 0
ld c, a
add hl, bc ; HL = &BOUND_PTR
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; LD HL, (HL) => Origin of L/U Bound table
add hl, de ; hl += OFFSET __LBOUND._xxxx
ld e, (hl) ; de = (hl)
inc hl
ld d, (hl)
ex de, hl ; hl = de => returns result in HL
ret
__DIM_NOT_EXIST:
; The dimension requested by the user does not exists. Return 0
ld hl, 0
ret
ENDP
#line 59 "ubound7.bas"
ZXBASIC_USER_DATA:
_b:
DEFB 00, 00
_c:
DEFB 00, 00
_a:
DEFW __LABEL5
_a.__DATA__.__PTR__:
DEFW _a.__DATA__
DEFW 0
DEFW _a.__UBOUND__
_a.__DATA__:
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
DEFB 00h
__LABEL5:
DEFW 0001h
DEFW 0003h
DEFB 01h
_a.__UBOUND__:
DEFW 0005h
DEFW 0009h
; Defines DATA END --> HEAP size is 0
ZXBASIC_USER_DATA_END:
; Defines USER DATA Length in bytes
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
END
Loading