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
2 changes: 1 addition & 1 deletion api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def init():
OPTIONS.add_option('arrayCheck', bool, False)
OPTIONS.add_option('enableBreak', bool, False)
OPTIONS.add_option('emitBackend', bool, False)
OPTIONS.add_option('arch', str, 'zx48k')
OPTIONS.add_option('__DEFINES', dict, {})
OPTIONS.add_option('explicit', bool, False)
OPTIONS.add_option('Sinclair', bool, False)
OPTIONS.add_option('strict', bool, False) # True to force type checking
OPTIONS.add_option('zxnext', bool, False) # True to enable ZX Next ASM opcodes
OPTIONS.add_option('architecture', str, None) # Architecture


init()
4 changes: 3 additions & 1 deletion arch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:ts=4:et:sw=4:

Expand All @@ -8,3 +8,5 @@
__all__ = [
'zx48k',
]

AVAILABLE_ARCHITECTURES = __all__
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ast_/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def children(self):

@children.setter
def children(self, value):
assert isinstance(value, collections.Iterable)
assert isinstance(value, collections.abc.Iterable)
while len(self.children):
self.children.pop()

Expand Down
8 changes: 8 additions & 0 deletions libzxbc/zxb.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ def main(args=None, emitter=None):
help='Appends binary to tape file (only works with -t or -T)')
parser.add_argument('-N', '--zxnext', action='store_true',
help='Enables ZX Next asm extended opcodes')
parser.add_argument('--arch', type=str, default=arch.AVAILABLE_ARCHITECTURES[0],
help=f"Target architecture (defaults is'{arch.AVAILABLE_ARCHITECTURES[0]}'). "
f"Available architectures: {','.join(arch.AVAILABLE_ARCHITECTURES)}")

options = parser.parse_args(args=args)

Expand All @@ -177,6 +180,11 @@ def main(args=None, emitter=None):
OPTIONS.headerless.value = options.headerless
OPTIONS.zxnext.value = options.zxnext

if options.arch not in arch.AVAILABLE_ARCHITECTURES:
parser.error(f"Invalid architecture '{options.arch}'")
return 2
OPTIONS.architecture.value = options.arch

OPTIONS.org.value = api.utils.parse_int(options.org)
if OPTIONS.org.value is None:
parser.error("Invalid --org option '{}'".format(options.org))
Expand Down
2 changes: 1 addition & 1 deletion libzxbc/zxbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def make_builtin(lineno, fname, operands, func=None, type_=None):
assert isinstance(operands, Symbol) or isinstance(operands, tuple) or isinstance(operands, list)
# TODO: In the future, builtin functions will be implemented in an external library, like POINT or ATTR
__DEBUG__('Creating BUILTIN "{}"'.format(fname), 1)
if not isinstance(operands, collections.Iterable):
if not isinstance(operands, collections.abc.Iterable):
operands = [operands]
return symbols.BUILTIN.make_node(lineno, fname, func, type_, *operands)

Expand Down
31 changes: 25 additions & 6 deletions libzxbpp/zxbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from .prepro import DefinesTable, ID, MacroCall, Arg, ArgList
from .prepro.exceptions import PreprocError

import arch


OUTPUT = ''
INCLUDED = {} # Already included files (with lines)
Expand All @@ -43,7 +45,7 @@
CURRENT_DIR = None

# Default include path
INCLUDEPATH = ('library', 'library-asm')
INCLUDEPATH = ['library', 'library-asm']

# Enabled to FALSE if IFDEF failed
ENABLED: bool = True
Expand Down Expand Up @@ -72,7 +74,6 @@ def init():
global INCLUDED
global CURRENT_DIR
global ENABLED
global INCLUDEPATH
global IFDEFS
global ID_TABLE
global CURRENT_FILE
Expand All @@ -82,8 +83,6 @@ def init():
OUTPUT = ''
INCLUDED = {}
CURRENT_DIR = ''
pwd = get_include_path()
INCLUDEPATH = [os.path.join(pwd, 'library'), os.path.join(pwd, 'library-asm')]
ENABLED = True
IFDEFS = []
global_.has_errors = 0
Expand All @@ -96,7 +95,18 @@ def init():
def get_include_path():
""" Default include path using a tricky sys calls.
"""
return os.path.realpath(os.path.join(os.path.dirname(__file__), os.path.pardir))
return os.path.realpath(os.path.join(
os.path.dirname(__file__),
os.path.pardir,
'arch',
OPTIONS.architecture.value or '')
)


def set_include_path():
global INCLUDEPATH
pwd = get_include_path()
INCLUDEPATH = [os.path.join(pwd, 'library'), os.path.join(pwd, 'library-asm')]


def setMode(mode):
Expand Down Expand Up @@ -160,7 +170,7 @@ def include_once(filename, lineno, local_first):
Writes down that "filename" was included at the current file,
at line <lineno>.

The file is ignored if it was previuosly included (a warning will
The file is ignored if it was previously included (a warning will
be emitted though).

If local_first is True, then it will first search the file in the
Expand Down Expand Up @@ -760,6 +770,7 @@ def main(argv):

ENABLED = True
OUTPUT = ''
set_include_path()

if argv:
CURRENT_FILE.append(argv[0])
Expand Down Expand Up @@ -816,11 +827,19 @@ def entry_point(args=None):
help='Error messages file. Standard error console by default (STDERR)')
parser.add_argument('input_file', type=str, default=None, nargs='?',
help="File to parse. If not specified, console input will be used (STDIN)")
parser.add_argument('--arch', type=str, default=arch.AVAILABLE_ARCHITECTURES[0],
help=f"Target architecture (defaults is'{arch.AVAILABLE_ARCHITECTURES[0]}'). "
f"Available architectures: {','.join(arch.AVAILABLE_ARCHITECTURES)}")

options = parser.parse_args(args=args)
OPTIONS.Debug.value = options.debug
OPTIONS.debug_zxbpp.value = OPTIONS.Debug.value > 0

if options.arch not in arch.AVAILABLE_ARCHITECTURES:
parser.error(f"Invalid architecture '{options.arch}'")
return 2
OPTIONS.architecture.value = options.arch

if options.stderr:
OPTIONS.StdErrFileName.value = options.stderr
OPTIONS.stderr.value = api.utils.open_file(OPTIONS.StdErrFileName.value, 'wt', 'utf-8')
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_init(self):
self.assertEqual(config.OPTIONS.arrayCheck.value, False)
self.assertEqual(config.OPTIONS.enableBreak.value, False)
self.assertEqual(config.OPTIONS.emitBackend.value, False)
self.assertEqual(config.OPTIONS.arch.value, 'zx48k')
self.assertEqual(config.OPTIONS.architecture.value, None)
# private options that cannot be accessed with #pragma
self.assertEqual(config.OPTIONS.option('__DEFINES').value, {})
self.assertEqual(config.OPTIONS.explicit.value, False)
Expand All @@ -49,7 +49,7 @@ def test_initted_values(self):
'Sinclair',
'StdErrFileName',
'__DEFINES',
'arch',
'architecture',
'arrayCheck',
'array_base',
'autorun',
Expand Down
5 changes: 0 additions & 5 deletions tests/functional/emook0.out
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#line 1 "emook0.bi"


ASM

LD A,A
LD BC,254
#line 6

end Asm

80 changes: 2 additions & 78 deletions tests/functional/prepro00.out
Original file line number Diff line number Diff line change
@@ -1,124 +1,48 @@
#line 1 "prepro00.bi"
#line 1 "/zxbasic/library/attr.bas"













#line 1 "/zxbasic/arch/zx48k/library/attr.bas"
#pragma push(case_insensitive)
#pragma case_insensitive = TRUE











function attr(byval row as ubyte, byval col as ubyte) as ubyte
asm

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

end asm

end function














sub setattr(byval row as ubyte, byval col as ubyte, byval value as ubyte)
asm

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

end asm

end sub











function fastcall attraddr(byval row as ubyte, byval col as ubyte) as uinteger
asm

pop hl
ex (sp), hl
ld d, a
ld e, h
jp __ATTR_ADDR
end asm
end function



#pragma pop(case_insensitive)


#require "attr.asm"


#require "in_screen.asm"

#line 119 "/zxbasic/library/attr.bas"

#line 119 "/zxbasic/arch/zx48k/library/attr.bas"
#line 2 "prepro00.bi"
PRINT "HELLO"

Loading