Skip to content

Commit a31a94c

Browse files
committed
fix: allow ../ in #include paths
1 parent 1654aba commit a31a94c

File tree

5 files changed

+189
-6
lines changed

5 files changed

+189
-6
lines changed

src/zxbpp/zxbpp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def search_filename(fname: str, lineno: int, local_first: bool) -> str:
179179
return fname
180180
else:
181181
for dir_ in i_path:
182-
path = utils.sanitize_filename(os.path.join(dir_, fname))
182+
path = utils.get_absolute_filename_path(utils.sanitize_filename(os.path.join(dir_, fname)))
183183
if os.path.exists(path):
184184
return path
185185

@@ -198,8 +198,9 @@ def include_file(filename: str, lineno: int, local_first: bool) -> str:
198198
"""
199199
global CURRENT_DIR
200200

201-
filename = search_filename(filename, lineno, local_first)
202-
abs_filename = utils.get_absolute_filename_path(filename)
201+
abs_filename = search_filename(filename, lineno, local_first)
202+
filename = utils.get_relative_filename_path(abs_filename)
203+
203204
if abs_filename not in INCLUDED:
204205
INCLUDED[abs_filename] = IncludedFileInfo(once=False, parents=[])
205206
elif INCLUDED[abs_filename].once:
@@ -221,14 +222,14 @@ def include_once(filename: str, lineno: int, local_first: bool) -> str:
221222
at line <lineno>.
222223
223224
The file is ignored if it was previously included (a warning will
224-
be emitted though).
225+
be emitted, though).
225226
226227
If local_first is True, then it will first search the file in the
227228
local path before looking for it in the include path chain.
228229
This is used when doing a #include "filename".
229230
"""
230-
filename = search_filename(filename, lineno, local_first)
231-
abs_filename = utils.get_absolute_filename_path(filename)
231+
abs_filename = search_filename(filename, lineno, local_first)
232+
232233
if abs_filename not in INCLUDED: # If not already included
233234
return include_file(filename, lineno, local_first) # include it and return
234235

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
org 32768
2+
.core.__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld (.core.__CALL_BACK__), sp
10+
ei
11+
jp .core.__MAIN_PROGRAM__
12+
.core.__CALL_BACK__:
13+
DEFW 0
14+
.core.ZXBASIC_USER_DATA:
15+
; Defines USER DATA Length in bytes
16+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
17+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
18+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
19+
_a:
20+
DEFB 00
21+
.core.ZXBASIC_USER_DATA_END:
22+
.core.__MAIN_PROGRAM__:
23+
ld a, 1
24+
ld (_a), a
25+
ld a, 1
26+
ld (_a), a
27+
ld hl, 0
28+
ld b, h
29+
ld c, l
30+
.core.__END_PROGRAM:
31+
di
32+
ld hl, (.core.__CALL_BACK__)
33+
ld sp, hl
34+
exx
35+
pop hl
36+
exx
37+
pop iy
38+
pop ix
39+
ei
40+
ret
41+
;; --- end of user code ---
42+
END
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include once "../zx48k/rel_include.bas"
2+
3+
LET a = 1

tests/functional/zxbpp/prepro85.bi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REM relative import
2+
3+
#include "../zxbpp/prepro00.bi"
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#line 1 "prepro85.bi"
2+
3+
4+
#line 1 "../zxbpp/prepro00.bi"
5+
#line 1 "/zxbasic/src/lib/arch/zx48k/stdlib/attr.bas"
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
#line 13 "/zxbasic/src/lib/arch/zx48k/stdlib/attr.bas"
18+
19+
#pragma push(case_insensitive)
20+
#pragma case_insensitive = TRUE
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
function attr(byval row as ubyte, byval col as ubyte) as ubyte
33+
asm
34+
push namespace core
35+
36+
PROC
37+
LOCAL __ATTR_END
38+
39+
ld e, (ix+7)
40+
ld d, (ix+5)
41+
42+
43+
call __IN_SCREEN
44+
jr nc, __ATTR_END
45+
46+
call __ATTR_ADDR
47+
ld a, (hl)
48+
49+
__ATTR_END:
50+
ENDP
51+
52+
pop namespace
53+
end asm
54+
55+
end function
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
sub setattr(byval row as ubyte, byval col as ubyte, byval value as ubyte)
71+
asm
72+
push namespace core
73+
74+
PROC
75+
LOCAL __ATTR_END
76+
77+
ld e, (ix+7)
78+
ld d, (ix+5)
79+
80+
81+
call __IN_SCREEN
82+
jr nc, __ATTR_END
83+
84+
call __ATTR_ADDR
85+
ld a, (ix+9)
86+
ld (hl), a
87+
88+
__ATTR_END:
89+
ENDP
90+
91+
pop namespace
92+
end asm
93+
94+
end sub
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
function fastcall attraddr(byval row as ubyte, byval col as ubyte) as uinteger
107+
asm
108+
push namespace core
109+
110+
pop hl
111+
ex (sp), hl
112+
ld d, a
113+
ld e, h
114+
jp __ATTR_ADDR
115+
pop namespace
116+
end asm
117+
end function
118+
119+
120+
121+
#pragma pop(case_insensitive)
122+
123+
124+
#require "attr.asm"
125+
126+
127+
#require "in_screen.asm"
128+
129+
#line 125 "/zxbasic/src/lib/arch/zx48k/stdlib/attr.bas"
130+
#line 2 "../zxbpp/prepro00.bi"
131+
PRINT "HELLO"
132+
#line 4 "prepro85.bi"
133+
134+

0 commit comments

Comments
 (0)