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
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ select = [
"I",
"PLR",
"PLW",
"RET",
"RUF",
"UP",
]
Expand All @@ -131,6 +132,12 @@ ignore = [
"PLW0603",
"PLW2901",
"PLW0602",
"RET501",
"RET502",
"RET503",
"RET504",
"RET506",
"RET507",
"RUF005",
"RUF012",
"RUF013",
Expand Down
4 changes: 2 additions & 2 deletions src/api/symboltable/symboltable.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ def access_call(self, id_: str, lineno: int, scope=None, type_=None):
if entry.type_ != self.basic_types[TYPE.string]:
syntax_error_not_array_nor_func(lineno, id_)
return None
else: # Ok, it is a string slice if it has 0 or 1 parameters
return entry
# Ok, it is a string slice if it has 0 or 1 parameters
return entry

if entry.callable is None and entry.type_ == self.basic_types[TYPE.string]:
# Ok, it is a string slice if it has 0 or 1 parameters
Expand Down
9 changes: 3 additions & 6 deletions src/arch/z80/backend/_16bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,7 @@ def jzero16(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) == 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, h")
Expand Down Expand Up @@ -1106,8 +1105,7 @@ def jgezeroi16(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) >= 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("add hl, hl") # Puts sign into carry
Expand Down Expand Up @@ -1145,8 +1143,7 @@ def jnzero16(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) != 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, h")
Expand Down
9 changes: 3 additions & 6 deletions src/arch/z80/backend/_32bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,7 @@ def jzero32(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) == 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, h")
Expand Down Expand Up @@ -954,8 +953,7 @@ def jgezeroi32(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) >= 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, d")
Expand Down Expand Up @@ -995,8 +993,7 @@ def jnzero32(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) != 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, h")
Expand Down
12 changes: 4 additions & 8 deletions src/arch/z80/backend/_8bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,7 @@ def store8(cls, ins: Quad) -> list[str]:
else:
output.append("ld (%s), a" % op)
return output
else:
output.append("pop hl")
output.append("pop hl")

if indirect:
output.append("ld e, (hl)")
Expand All @@ -1112,8 +1111,7 @@ def jzero8(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) == 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("or a")
Expand All @@ -1127,8 +1125,7 @@ def jnzero8(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) != 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("or a")
Expand All @@ -1155,8 +1152,7 @@ def jgezeroi8(cls, ins: Quad) -> list[str]:
if is_int(value):
if int(value) >= 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("add a, a") # Puts sign into carry
Expand Down
6 changes: 2 additions & 4 deletions src/arch/z80/backend/_f16.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ def jzerof16(cls, ins: Quad) -> list[str]:
if is_float(value):
if float(value) == 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, h")
Expand All @@ -471,8 +470,7 @@ def jnzerof16(cls, ins: Quad) -> list[str]:
if is_float(value):
if float(value) != 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, h")
Expand Down
6 changes: 2 additions & 4 deletions src/arch/z80/backend/_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,7 @@ def jzerof(cls, ins: Quad) -> list[str]:
if is_float(value):
if float(value) == 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, c")
Expand All @@ -414,8 +413,7 @@ def jnzerof(cls, ins: Quad) -> list[str]:
if is_float(value):
if float(value) != 0:
return ["jp %s" % str(ins[2])] # Always true
else:
return []
return []

output = cls.get_oper(value)
output.append("ld a, c")
Expand Down
9 changes: 4 additions & 5 deletions src/arch/z80/backend/_pload.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,10 @@ def _pstore16(ins: Quad) -> list[str]:
output.append("inc hl")
output.append("ld (hl), %i" % (v >> 8))
return output
else:
output.append("ld (hl), e")
output.append("inc hl")
output.append("ld (hl), d")
return output
output.append("ld (hl), e")
output.append("inc hl")
output.append("ld (hl), d")
return output

if is_int(value):
v = Bits16.int16(value)
Expand Down
3 changes: 1 addition & 2 deletions src/arch/z80/optimizer/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ def result(asm: str) -> tuple[str, ...]:
if ins in {"sub", "add", "sbc", "adc"}:
if len(op) == 1:
return "a", "f"
else:
return tuple(single_registers(op[0]) + ["f"])
return tuple(single_registers(op[0]) + ["f"])

if ins == "djnz":
return "b", "f"
Expand Down
6 changes: 2 additions & 4 deletions src/arch/z80/visitor/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,14 +991,12 @@ def default_value(cls, type_: symbols.TYPE, expr) -> list[str]: # TODO: This fu
if type_.size == 1: # U/byte
if expr.type_.size != 1:
return [f"#({val}) & 0xFF"]
else:
return [f"#{val}"]
return [f"#{val}"]

if type_.size == 2: # U/integer
if expr.type_.size != 2:
return [f"##({val}) & 0xFFFF"]
else:
return [f"##{val}"]
return [f"##{val}"]

if type_ == cls.TYPE(TYPE.fixed):
return ["0000", f"##({val}) & 0xFFFF"]
Expand Down
5 changes: 2 additions & 3 deletions src/ply/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ def token(self):
if tok.type:
self.lexpos = m.end()
return tok
else:
lexpos = m.end()
break
lexpos = m.end()
break

lexpos = m.end()

Expand Down
8 changes: 3 additions & 5 deletions src/ply/yacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def format_stack_entry(r):
repr_str = repr(repr_str)
if len(repr_str) < 16:
return repr_str
else:
return "<%s @ 0x%x>" % (type(r).__name__, id(r))
return "<%s @ 0x%x>" % (type(r).__name__, id(r))


# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -188,10 +187,9 @@ def __init__(self, s, stack=None):
def __getitem__(self, n):
if isinstance(n, slice):
return [s.value for s in self.slice[n]]
elif n >= 0:
if n >= 0:
return self.slice[n].value
else:
return self.stack[n].value
return self.stack[n].value

def __setitem__(self, n, v):
self.slice[n].value = v
Expand Down
3 changes: 1 addition & 2 deletions src/symbols/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def t(self):
if self.value.token == "VAR":
if self.value.scope == SCOPE.global_:
return self.value.t
else:
return self.value.t[1:] # Removed '$' prefix
return self.value.t[1:] # Removed '$' prefix

return self.value.t

Expand Down
2 changes: 1 addition & 1 deletion src/symbols/unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def make_node(cls, lineno, operator, operand, func=None, type_=None):
if func is not None: # Try constant-folding
if check.is_number(operand): # e.g. ABS(-5)
return SymbolNUMBER(func(operand.value), lineno=lineno)
elif check.is_string(operand): # e.g. LEN("a")
if check.is_string(operand): # e.g. LEN("a")
return SymbolSTRING(func(operand.text), lineno=lineno)

if type_ is None:
Expand Down
14 changes: 6 additions & 8 deletions src/zxbasm/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,14 @@ def try_eval(self):
if item.defined:
if isinstance(item.value, Expr):
return item.value.try_eval()
else:
return item.value
else:
if Expr.ignore:
return None

# Try to resolve into the global namespace
error(self.symbol.lineno, "Undefined label '%s'" % item.name)
return item.value
if Expr.ignore:
return None

# Try to resolve into the global namespace
error(self.symbol.lineno, "Undefined label '%s'" % item.name)
return None

try:
if isinstance(item, tuple):
return tuple([x.try_eval() for x in item])
Expand Down
28 changes: 12 additions & 16 deletions src/zxbc/zxbparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@ def p_var_decl_ini(p):
if not is_static_str(value):
errmsg.syntax_error_not_constant(p.lineno(4))
return
else:
defval = value
defval = value

SYMBOL_TABLE.declare_const(idlist[0].name, idlist[0].lineno, typedef, default_value=defval)

Expand Down Expand Up @@ -776,8 +775,7 @@ def p_arr_decl_attr(p):
if expr.operand.token not in ("ID", "VAR", "LABEL"):
error(p.lineno(3), "Only addresses of identifiers are allowed")
return
else:
expr.operand.has_address = True
expr.operand.has_address = True

elif not is_static(expr):
errmsg.syntax_error_address_must_be_constant(p.lineno(3))
Expand Down Expand Up @@ -2234,11 +2232,10 @@ def p_save_code(p):
if p[3].upper() not in ("SCREEN", "SCREEN$"):
error(p.lineno(3), 'Unexpected "%s" ID. Expected "SCREEN$" instead' % p[3])
return None
else:
# ZX Spectrum screen start + length
# This should be stored in a architecture-dependant file
start = make_number(16384, lineno=p.lineno(1))
length = make_number(6912, lineno=p.lineno(1))
# ZX Spectrum screen start + length
# This should be stored in a architecture-dependant file
start = make_number(16384, lineno=p.lineno(1))
length = make_number(6912, lineno=p.lineno(1))
else:
start = make_typecast(TYPE.uinteger, p[4], p.lineno(4))
length = make_typecast(TYPE.uinteger, p[6], p.lineno(6))
Expand Down Expand Up @@ -2298,13 +2295,12 @@ def p_load_code(p):
if p[3].upper() not in ("SCREEN", "SCREEN$", "CODE"):
error(p.lineno(3), 'Unexpected "%s" ID. Expected "SCREEN$" instead' % p[3])
return None
else:
if p[3].upper() == "CODE": # LOAD "..." CODE
start = make_number(0, lineno=p.lineno(3))
length = make_number(0, lineno=p.lineno(3))
else: # SCREEN$
start = make_number(16384, lineno=p.lineno(3))
length = make_number(6912, lineno=p.lineno(3))
if p[3].upper() == "CODE": # LOAD "..." CODE
start = make_number(0, lineno=p.lineno(3))
length = make_number(0, lineno=p.lineno(3))
else: # SCREEN$
start = make_number(16384, lineno=p.lineno(3))
length = make_number(6912, lineno=p.lineno(3))
else:
start = make_typecast(TYPE.uinteger, p[4], p.lineno(3))

Expand Down