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: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@
.idea/
.python-version
.tox/
/parsetab/parser.out
/parsetab/zxbasmlextab.py
/parsetab/zxbasmtab.py
/parsetab/zxblextab.py
/parsetab/zxbpptab.py
/parsetab/zxbtab.py
MANIFEST
dist/
examples/*.bin
examples/*.tzx
scratch/
.coverage
.coverage/
htmlcov/
build/
18 changes: 9 additions & 9 deletions arch/zx48k/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from . import beep
from .translator import * # noqa

import api.global_
from api.constants import TYPE
import src.api.global_
from src.api.constants import TYPE


__all__ = [
Expand All @@ -17,10 +17,10 @@
# -----------------------------------------
# Arch initialization setup
# -----------------------------------------
api.global_.PARAM_ALIGN = 2 # Z80 param align
api.global_.BOUND_TYPE = TYPE.uinteger
api.global_.SIZE_TYPE = TYPE.ubyte
api.global_.PTR_TYPE = TYPE.uinteger
api.global_.STR_INDEX_TYPE = TYPE.uinteger
api.global_.MIN_STRSLICE_IDX = 0 # Min. string slicing position
api.global_.MAX_STRSLICE_IDX = 65534 # Max. string slicing position
src.api.global_.PARAM_ALIGN = 2 # Z80 param align
src.api.global_.BOUND_TYPE = TYPE.uinteger
src.api.global_.SIZE_TYPE = TYPE.ubyte
src.api.global_.PTR_TYPE = TYPE.uinteger
src.api.global_.STR_INDEX_TYPE = TYPE.uinteger
src.api.global_.MIN_STRSLICE_IDX = 0 # Min. string slicing position
src.api.global_.MAX_STRSLICE_IDX = 65534 # Max. string slicing position
2 changes: 1 addition & 1 deletion arch/zx48k/backend/__float.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# -----------------------------------------------------
# Floating Point operators
# -----------------------------------------------------
from api import fp
from src.api import fp


def _float(op):
Expand Down
6 changes: 3 additions & 3 deletions arch/zx48k/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
# External functions
from ..optimizer.helpers import HI16, LO16
from arch.zx48k.optimizer.asm import Asm
from api.config import OPTIONS
import api.fp
from src.api.config import OPTIONS
import src.api.fp

from arch.zx48k.peephole import engine

Expand Down Expand Up @@ -488,7 +488,7 @@ def _data(ins):
size = "B"
q = ['"%s"' % x.replace('"', '""') for x in q]
elif t == 'f':
dat_ = [api.fp.immediate_float(float(x)) for x in q]
dat_ = [src.api.fp.immediate_float(float(x)) for x in q]
for x in dat_:
output.extend(['DEFB %s' % x[0], 'DEFW %s, %s' % (x[1], x[2])])
return output
Expand Down
2 changes: 1 addition & 1 deletion arch/zx48k/backend/__parray.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This module contains local array (both parameters and
# comparation intermediate-code traductions
# --------------------------------------------------------------
from api import fp
from src.api import fp
from .__common import REQUIRES
from .__float import _fpush
from .__f16 import f16
Expand Down
2 changes: 1 addition & 1 deletion arch/zx48k/backend/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# vim:ts=4:et:sw=4:

from api.errors import Error
from src.api.errors import Error

__all__ = ['GenericError',
'InvalidICError',
Expand Down
6 changes: 3 additions & 3 deletions arch/zx48k/optimizer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from api.utils import flatten_list
from src.api.utils import flatten_list
from arch.zx48k.peephole import engine

from .patterns import RE_PRAGMA, RE_LABEL
Expand All @@ -9,8 +9,8 @@
from .basicblock import DummyBasicBlock
from . import basicblock
from .labelinfo import LabelInfo
from api.config import OPTIONS
from api.debug import __DEBUG__
from src.api.config import OPTIONS
from src.api.debug import __DEBUG__


def init():
Expand Down
16 changes: 8 additions & 8 deletions arch/zx48k/optimizer/basicblock.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

import arch
import api.utils
import api.config
import src.api.utils
import src.api.config

from api.debug import __DEBUG__
from api.identityset import IdentitySet
from src.api.debug import __DEBUG__
from src.api.identityset import IdentitySet
from .memcell import MemCell
from .labelinfo import LabelInfo
from .helpers import ALL_REGS, END_PROGRAM_LABEL
Expand Down Expand Up @@ -389,7 +389,7 @@ def is_used(self, regs, i, top=None):

return True

regs = api.utils.flatten_list([helpers.single_registers(x) for x in regs]) # make a copy
regs = src.api.utils.flatten_list([helpers.single_registers(x) for x in regs]) # make a copy
for ii in range(i, top):
if any(r in regs for r in self.mem[ii].requires):
return True
Expand Down Expand Up @@ -565,7 +565,7 @@ def optimize(self, patterns_list):
'z': str(self.cpu.Z) if self.cpu.Z is not None else helpers.new_tmp_val()
}.get(x.lower(), helpers.new_tmp_val())

if api.config.OPTIONS.optimization > 3:
if src.api.config.OPTIONS.optimization > 3:
regs, mems = self.guesses_initial_state_from_origin_blocks()
else:
regs, mems = {}, {}
Expand All @@ -591,8 +591,8 @@ def optimize(self, patterns_list):
new_code = list(code)
matched = new_code[i: i + len(p.patt)]
new_code[i: i + len(p.patt)] = p.template.filter(match)
api.errmsg.info('pattern applied [{}:{}]'.format("%03i" % p.flag, p.fname))
api.debug.__DEBUG__('matched: \n {}'.format('\n '.join(matched)), level=1)
src.api.errmsg.info('pattern applied [{}:{}]'.format("%03i" % p.flag, p.fname))
src.api.debug.__DEBUG__('matched: \n {}'.format('\n '.join(matched)), level=1)
changed = new_code != code
if changed:
code = new_code
Expand Down
2 changes: 1 addition & 1 deletion arch/zx48k/optimizer/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from api.errors import Error
from src.api.errors import Error


class DuplicatedLabelError(Error):
Expand Down
2 changes: 1 addition & 1 deletion arch/zx48k/optimizer/labelinfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from api.identityset import IdentitySet
from src.api.identityset import IdentitySet
from . import common
from . import errors

Expand Down
2 changes: 1 addition & 1 deletion arch/zx48k/optimizer/memcell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import helpers
from .. import backend
from .asm import Asm
from api.utils import flatten_list
from src.api.utils import flatten_list
from libzxbasm import asmlex


Expand Down
2 changes: 1 addition & 1 deletion arch/zx48k/peephole/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from collections import defaultdict, namedtuple

import api
from src import api

from arch.zx48k.peephole import evaluator
from arch.zx48k.peephole import parser
Expand Down
2 changes: 1 addition & 1 deletion arch/zx48k/peephole/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import re

from api import utils
from src.api import utils
from .template import UnboundVarError
from .pattern import RE_SVAR
from ..optimizer import helpers
Expand Down
45 changes: 22 additions & 23 deletions arch/zx48k/peephole/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import sys
import re
from collections import defaultdict, namedtuple
import api.errmsg
import api.global_
import src.api.global_

from . import evaluator
from . import pattern
Expand Down Expand Up @@ -109,11 +108,11 @@ def parse_ifline(if_line, lineno):
if tok == ')':
paren -= 1
if paren < 0:
api.errmsg.warning(lineno, "Too much closed parenthesis")
src.api.errmsg.warning(lineno, "Too much closed parenthesis")
return

if expr and expr[-1] == evaluator.OP_COMMA:
api.errmsg.warning(lineno, "missing element in list")
src.api.errmsg.warning(lineno, "missing element in list")
return

stack[-1].append(expr)
Expand All @@ -125,7 +124,7 @@ def parse_ifline(if_line, lineno):

if tok == evaluator.OP_COMMA:
if len(expr) < 2 or expr[-2] == tok:
api.errmsg.warning(lineno, "Unexpected {} in list".format(tok))
src.api.errmsg.warning(lineno, "Unexpected {} in list".format(tok))
return

while len(expr) == 2 and isinstance(expr[-2], str):
Expand All @@ -139,15 +138,15 @@ def parse_ifline(if_line, lineno):
if len(expr) == 3 and expr[1] != evaluator.OP_COMMA:
left_, op, right_ = expr
if not isinstance(op, str) or op not in IF_OPERATORS:
api.errmsg.warning(lineno, "Unexpected binary operator '{0}'".format(op))
src.api.errmsg.warning(lineno, "Unexpected binary operator '{0}'".format(op))
return
if isinstance(left_, list) and len(left_) == 3 and IF_OPERATORS[left_[-2]] > IF_OPERATORS[op]:
expr = [[left_[:-2], left_[-2], [left_[-1], op, right_]]] # Rebalance tree
else:
expr = [expr]

if not error_ and paren:
api.errmsg.warning(lineno, "unclosed parenthesis in IF section")
src.api.errmsg.warning(lineno, "unclosed parenthesis in IF section")
return

while stack and not error_:
Expand All @@ -157,16 +156,16 @@ def parse_ifline(if_line, lineno):
if len(expr) == 2:
op = expr[0]
if not isinstance(op, str) or op not in evaluator.UNARY:
api.errmsg.warning(lineno, "unexpected unary operator '{0}'".format(op))
src.api.errmsg.warning(lineno, "unexpected unary operator '{0}'".format(op))
return
elif len(expr) == 3:
op = expr[1]
if not isinstance(op, str) or op not in evaluator.BINARY:
api.errmsg.warning(lineno, "unexpected binary operator '{0}'".format(op))
src.api.errmsg.warning(lineno, "unexpected binary operator '{0}'".format(op))
return

if error_:
api.errmsg.warning(lineno, "syntax error in IF section")
src.api.errmsg.warning(lineno, "syntax error in IF section")
return

return flatten(expr)
Expand All @@ -176,12 +175,12 @@ def parse_define_line(sourceline):
""" Given a line $nnn = <expression>, returns a tuple the parsed
("$var", [expression]) or None, None if error. """
if '=' not in sourceline.line:
api.errmsg.warning(sourceline.lineno, "assignation '=' not found")
src.api.errmsg.warning(sourceline.lineno, "assignation '=' not found")
return None, None

result = [x.strip() for x in sourceline.line.split('=', 1)]
if not pattern.RE_SVAR.match(result[0]): # Define vars
api.errmsg.warning(sourceline.lineno, "'{0}' not a variable name".format(result[0]))
src.api.errmsg.warning(sourceline.lineno, "'{0}' not a variable name".format(result[0]))
return None, None

result[1] = parse_ifline(result[1], sourceline.lineno)
Expand Down Expand Up @@ -210,16 +209,16 @@ def parse_str(spec):
def add_entry(key, val):
key = key.upper()
if key in result:
api.errmsg.warning(line_num, "duplicated definition {0}".format(key))
src.api.errmsg.warning(line_num, "duplicated definition {0}".format(key))
return False

if key not in REGIONS and key not in SCALARS:
api.errmsg.warning(line_num, "unknown definition parameter '{0}'".format(key))
src.api.errmsg.warning(line_num, "unknown definition parameter '{0}'".format(key))
return False

if key in NUMERIC:
if not re_int.match(val):
api.errmsg.warning(line_num, "field '{0} must be integer".format(key))
src.api.errmsg.warning(line_num, "field '{0} must be integer".format(key))
return False
val = int(val)

Expand All @@ -228,7 +227,7 @@ def add_entry(key, val):

def check_entry(key):
if key not in result:
api.errmsg.warning(line_num, "undefined section {0}".format(key))
src.api.errmsg.warning(line_num, "undefined section {0}".format(key))
return False

return True
Expand Down Expand Up @@ -265,7 +264,7 @@ def check_entry(key):
region_name = None
continue

api.errmsg.warning(line_num, "syntax error. Cannot parse file")
src.api.errmsg.warning(line_num, "syntax error. Cannot parse file")
is_ok = False
break

Expand All @@ -277,7 +276,7 @@ def check_entry(key):
is_ok = False
break
if var_ in defined_vars:
api.errmsg.warning(source_line.lineno, "duplicated variable '{0}'".format(var_))
src.api.errmsg.warning(source_line.lineno, "duplicated variable '{0}'".format(var_))
is_ok = False
break
defines.append([var_, DefineLine(expr=evaluator.Evaluator(expr), lineno=source_line.lineno)])
Expand All @@ -297,11 +296,11 @@ def check_entry(key):

if is_ok:
if not result[REG_REPLACE]: # Empty REPLACE region??
api.errmsg.warning(line_num, "empty region {0}".format(REG_REPLACE))
src.api.errmsg.warning(line_num, "empty region {0}".format(REG_REPLACE))
is_ok = False

if not is_ok:
api.errmsg.warning(line_num, "this optimizer template will be ignored due to errors")
src.api.errmsg.warning(line_num, "this optimizer template will be ignored due to errors")
return

return result
Expand All @@ -310,13 +309,13 @@ def check_entry(key):
def parse_file(fname):
""" Opens and parse a file given by filename
"""
tmp = api.global_.FILENAME
api.global_.FILENAME = fname # set filename so it shows up in error/warning msgs
tmp = src.api.global_.FILENAME
src.api.global_.FILENAME = fname # set filename so it shows up in error/warning msgs

with open(fname, 'rt') as f:
result = parse_str(f.read())

api.global_.FILENAME = tmp # restores original filename
src.api.global_.FILENAME = tmp # restores original filename
return result


Expand Down
Loading