diff --git a/src/zxbpp/zxbpp.py b/src/zxbpp/zxbpp.py index c1d4d004f..8ed7ca76a 100755 --- a/src/zxbpp/zxbpp.py +++ b/src/zxbpp/zxbpp.py @@ -179,7 +179,7 @@ def search_filename(fname: str, lineno: int, local_first: bool) -> str: return fname else: for dir_ in i_path: - path = utils.sanitize_filename(os.path.join(dir_, fname)) + path = utils.get_absolute_filename_path(utils.sanitize_filename(os.path.join(dir_, fname))) if os.path.exists(path): return path @@ -198,8 +198,9 @@ def include_file(filename: str, lineno: int, local_first: bool) -> str: """ global CURRENT_DIR - filename = search_filename(filename, lineno, local_first) - abs_filename = utils.get_absolute_filename_path(filename) + abs_filename = search_filename(filename, lineno, local_first) + filename = utils.get_relative_filename_path(abs_filename) + if abs_filename not in INCLUDED: INCLUDED[abs_filename] = IncludedFileInfo(once=False, parents=[]) elif INCLUDED[abs_filename].once: @@ -221,14 +222,14 @@ def include_once(filename: str, lineno: int, local_first: bool) -> str: at line . The file is ignored if it was previously included (a warning will - be emitted though). + be emitted, though). If local_first is True, then it will first search the file in the local path before looking for it in the include path chain. This is used when doing a #include "filename". """ - filename = search_filename(filename, lineno, local_first) - abs_filename = utils.get_absolute_filename_path(filename) + abs_filename = search_filename(filename, lineno, local_first) + if abs_filename not in INCLUDED: # If not already included return include_file(filename, lineno, local_first) # include it and return diff --git a/tests/functional/arch/zx48k/rel_include.asm b/tests/functional/arch/zx48k/rel_include.asm new file mode 100644 index 000000000..cf14001cb --- /dev/null +++ b/tests/functional/arch/zx48k/rel_include.asm @@ -0,0 +1,42 @@ + org 32768 +.core.__START_PROGRAM: + di + push ix + push iy + exx + push hl + exx + ld (.core.__CALL_BACK__), sp + ei + jp .core.__MAIN_PROGRAM__ +.core.__CALL_BACK__: + DEFW 0 +.core.ZXBASIC_USER_DATA: + ; Defines USER DATA Length in bytes +.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA + .core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN + .core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA +_a: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld a, 1 + ld (_a), a + ld a, 1 + ld (_a), a + ld hl, 0 + ld b, h + ld c, l +.core.__END_PROGRAM: + di + ld hl, (.core.__CALL_BACK__) + ld sp, hl + exx + pop hl + exx + pop iy + pop ix + ei + ret + ;; --- end of user code --- + END diff --git a/tests/functional/arch/zx48k/rel_include.bas b/tests/functional/arch/zx48k/rel_include.bas new file mode 100644 index 000000000..d069e5074 --- /dev/null +++ b/tests/functional/arch/zx48k/rel_include.bas @@ -0,0 +1,3 @@ +#include once "../zx48k/rel_include.bas" + +LET a = 1 diff --git a/tests/functional/asm/rel_include.asm b/tests/functional/asm/rel_include.asm new file mode 100644 index 000000000..ce250e7ce --- /dev/null +++ b/tests/functional/asm/rel_include.asm @@ -0,0 +1,3 @@ +#include once "../asm/rel_include.asm" + +NOP diff --git a/tests/functional/asm/rel_include.bin b/tests/functional/asm/rel_include.bin new file mode 100644 index 000000000..09f370e38 Binary files /dev/null and b/tests/functional/asm/rel_include.bin differ diff --git a/tests/functional/zxbpp/prepro70.out b/tests/functional/zxbpp/prepro70.out index 599230c43..47bdb70b4 100644 --- a/tests/functional/zxbpp/prepro70.out +++ b/tests/functional/zxbpp/prepro70.out @@ -3,9 +3,9 @@ DIM b -#line 1 "./prepro70.bi" +#line 1 "prepro70.bi" DIM b -#line 10 "./prepro70.bi" +#line 10 "prepro70.bi" #line 6 "prepro70.bi" DIM a diff --git a/tests/functional/zxbpp/prepro72.out b/tests/functional/zxbpp/prepro72.out index 3ba0b5f2a..b21476152 100644 --- a/tests/functional/zxbpp/prepro72.out +++ b/tests/functional/zxbpp/prepro72.out @@ -3,9 +3,9 @@ DIM b -#line 1 "./prepro70.bi" +#line 1 "prepro70.bi" DIM b -#line 10 "./prepro70.bi" +#line 10 "prepro70.bi" #line 6 "prepro72.bi" DIM a diff --git a/tests/functional/zxbpp/prepro85.bi b/tests/functional/zxbpp/prepro85.bi new file mode 100644 index 000000000..7094a3468 --- /dev/null +++ b/tests/functional/zxbpp/prepro85.bi @@ -0,0 +1,3 @@ +REM relative import + +#include "../zxbpp/prepro00.bi" diff --git a/tests/functional/zxbpp/prepro85.out b/tests/functional/zxbpp/prepro85.out new file mode 100644 index 000000000..2847d5075 --- /dev/null +++ b/tests/functional/zxbpp/prepro85.out @@ -0,0 +1,132 @@ +#line 1 "prepro85.bi" + + +#line 1 "prepro00.bi" +#line 1 "/zxbasic/src/lib/arch/zx48k/stdlib/attr.bas" + + + + + + + + + + + +#line 13 "/zxbasic/src/lib/arch/zx48k/stdlib/attr.bas" + +#pragma push(case_insensitive) +#pragma case_insensitive = TRUE + + + + + + + + + + + +function attr(byval row as ubyte, byval col as ubyte) as ubyte + asm + push namespace core + + PROC + LOCAL __ATTR_END + + ld e, (ix+7) + ld d, (ix+5) + + + call __IN_SCREEN + jr nc, __ATTR_END + + call __ATTR_ADDR + ld a, (hl) + +__ATTR_END: + ENDP + + pop namespace + end asm + +end function + + + + + + + + + + + + + + +sub setattr(byval row as ubyte, byval col as ubyte, byval value as ubyte) + asm + push namespace core + + PROC + LOCAL __ATTR_END + + ld e, (ix+7) + ld d, (ix+5) + + + call __IN_SCREEN + jr nc, __ATTR_END + + call __ATTR_ADDR + ld a, (ix+9) + ld (hl), a + +__ATTR_END: + ENDP + + pop namespace + end asm + +end sub + + + + + + + + + + + +function fastcall attraddr(byval row as ubyte, byval col as ubyte) as uinteger + asm + push namespace core + + pop hl + ex (sp), hl + ld d, a + ld e, h + jp __ATTR_ADDR + pop namespace + end asm +end function + + + +#pragma pop(case_insensitive) + + +#require "attr.asm" + + +#require "in_screen.asm" + +#line 125 "/zxbasic/src/lib/arch/zx48k/stdlib/attr.bas" +#line 2 "prepro00.bi" +PRINT "HELLO" +#line 4 "prepro85.bi"