repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_documentation_string
stringlengths 1
47.2k
| func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|
boriel/zxbasic | asmparse.py | p_jr | def p_jr(p):
""" asm : JR jr_flags COMMA expr
| JR jr_flags COMMA pexpr
"""
p[4] = Expr.makenode(Container('-', p.lineno(3)), p[4], Expr.makenode(Container(MEMORY.org + 2, p.lineno(1))))
p[0] = Asm(p.lineno(1), 'JR %s,N' % p[2], p[4]) | python | def p_jr(p):
""" asm : JR jr_flags COMMA expr
| JR jr_flags COMMA pexpr
"""
p[4] = Expr.makenode(Container('-', p.lineno(3)), p[4], Expr.makenode(Container(MEMORY.org + 2, p.lineno(1))))
p[0] = Asm(p.lineno(1), 'JR %s,N' % p[2], p[4]) | asm : JR jr_flags COMMA expr
| JR jr_flags COMMA pexpr | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1174-L1179 |
boriel/zxbasic | asmparse.py | p_jrjp | def p_jrjp(p):
""" asm : JP expr
| JR expr
| CALL expr
| DJNZ expr
| JP pexpr
| JR pexpr
| CALL pexpr
| DJNZ pexpr
"""
if p[1] in ('JR', 'DJNZ'):
op = 'N'
p[2] = Expr.makenode(Container('-', p.lineno(1)), p[2], Expr.makenode(Container(MEMORY.org + 2, p.lineno(1))))
else:
op = 'NN'
p[0] = Asm(p.lineno(1), p[1] + ' ' + op, p[2]) | python | def p_jrjp(p):
""" asm : JP expr
| JR expr
| CALL expr
| DJNZ expr
| JP pexpr
| JR pexpr
| CALL pexpr
| DJNZ pexpr
"""
if p[1] in ('JR', 'DJNZ'):
op = 'N'
p[2] = Expr.makenode(Container('-', p.lineno(1)), p[2], Expr.makenode(Container(MEMORY.org + 2, p.lineno(1))))
else:
op = 'NN'
p[0] = Asm(p.lineno(1), p[1] + ' ' + op, p[2]) | asm : JP expr
| JR expr
| CALL expr
| DJNZ expr
| JP pexpr
| JR pexpr
| CALL pexpr
| DJNZ pexpr | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1191-L1207 |
boriel/zxbasic | asmparse.py | p_rst | def p_rst(p):
""" asm : RST expr
"""
val = p[2].eval()
if val not in (0, 8, 16, 24, 32, 40, 48, 56):
error(p.lineno(1), 'Invalid RST number %i' % val)
p[0] = None
return
p[0] = Asm(p.lineno(1), 'RST %XH' % val) | python | def p_rst(p):
""" asm : RST expr
"""
val = p[2].eval()
if val not in (0, 8, 16, 24, 32, 40, 48, 56):
error(p.lineno(1), 'Invalid RST number %i' % val)
p[0] = None
return
p[0] = Asm(p.lineno(1), 'RST %XH' % val) | asm : RST expr | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1210-L1220 |
boriel/zxbasic | asmparse.py | p_im | def p_im(p):
""" asm : IM expr
"""
val = p[2].eval()
if val not in (0, 1, 2):
error(p.lineno(1), 'Invalid IM number %i' % val)
p[0] = None
return
p[0] = Asm(p.lineno(1), 'IM %i' % val) | python | def p_im(p):
""" asm : IM expr
"""
val = p[2].eval()
if val not in (0, 1, 2):
error(p.lineno(1), 'Invalid IM number %i' % val)
p[0] = None
return
p[0] = Asm(p.lineno(1), 'IM %i' % val) | asm : IM expr | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1223-L1232 |
boriel/zxbasic | asmparse.py | p_expr_div_expr | def p_expr_div_expr(p):
""" expr : expr BAND expr
| expr BOR expr
| expr BXOR expr
| expr PLUS expr
| expr MINUS expr
| expr MUL expr
| expr DIV expr
| expr MOD expr
| expr POW expr
| expr LSHIFT expr
| expr RSHIFT expr
| pexpr BAND expr
| pexpr BOR expr
| pexpr BXOR expr
| pexpr PLUS expr
| pexpr MINUS expr
| pexpr MUL expr
| pexpr DIV expr
| pexpr MOD expr
| pexpr POW expr
| pexpr LSHIFT expr
| pexpr RSHIFT expr
| expr BAND pexpr
| expr BOR pexpr
| expr BXOR pexpr
| expr PLUS pexpr
| expr MINUS pexpr
| expr MUL pexpr
| expr DIV pexpr
| expr MOD pexpr
| expr POW pexpr
| expr LSHIFT pexpr
| expr RSHIFT pexpr
| pexpr BAND pexpr
| pexpr BOR pexpr
| pexpr BXOR pexpr
| pexpr PLUS pexpr
| pexpr MINUS pexpr
| pexpr MUL pexpr
| pexpr DIV pexpr
| pexpr MOD pexpr
| pexpr POW pexpr
| pexpr LSHIFT pexpr
| pexpr RSHIFT pexpr
"""
p[0] = Expr.makenode(Container(p[2], p.lineno(2)), p[1], p[3]) | python | def p_expr_div_expr(p):
""" expr : expr BAND expr
| expr BOR expr
| expr BXOR expr
| expr PLUS expr
| expr MINUS expr
| expr MUL expr
| expr DIV expr
| expr MOD expr
| expr POW expr
| expr LSHIFT expr
| expr RSHIFT expr
| pexpr BAND expr
| pexpr BOR expr
| pexpr BXOR expr
| pexpr PLUS expr
| pexpr MINUS expr
| pexpr MUL expr
| pexpr DIV expr
| pexpr MOD expr
| pexpr POW expr
| pexpr LSHIFT expr
| pexpr RSHIFT expr
| expr BAND pexpr
| expr BOR pexpr
| expr BXOR pexpr
| expr PLUS pexpr
| expr MINUS pexpr
| expr MUL pexpr
| expr DIV pexpr
| expr MOD pexpr
| expr POW pexpr
| expr LSHIFT pexpr
| expr RSHIFT pexpr
| pexpr BAND pexpr
| pexpr BOR pexpr
| pexpr BXOR pexpr
| pexpr PLUS pexpr
| pexpr MINUS pexpr
| pexpr MUL pexpr
| pexpr DIV pexpr
| pexpr MOD pexpr
| pexpr POW pexpr
| pexpr LSHIFT pexpr
| pexpr RSHIFT pexpr
"""
p[0] = Expr.makenode(Container(p[2], p.lineno(2)), p[1], p[3]) | expr : expr BAND expr
| expr BOR expr
| expr BXOR expr
| expr PLUS expr
| expr MINUS expr
| expr MUL expr
| expr DIV expr
| expr MOD expr
| expr POW expr
| expr LSHIFT expr
| expr RSHIFT expr
| pexpr BAND expr
| pexpr BOR expr
| pexpr BXOR expr
| pexpr PLUS expr
| pexpr MINUS expr
| pexpr MUL expr
| pexpr DIV expr
| pexpr MOD expr
| pexpr POW expr
| pexpr LSHIFT expr
| pexpr RSHIFT expr
| expr BAND pexpr
| expr BOR pexpr
| expr BXOR pexpr
| expr PLUS pexpr
| expr MINUS pexpr
| expr MUL pexpr
| expr DIV pexpr
| expr MOD pexpr
| expr POW pexpr
| expr LSHIFT pexpr
| expr RSHIFT pexpr
| pexpr BAND pexpr
| pexpr BOR pexpr
| pexpr BXOR pexpr
| pexpr PLUS pexpr
| pexpr MINUS pexpr
| pexpr MUL pexpr
| pexpr DIV pexpr
| pexpr MOD pexpr
| pexpr POW pexpr
| pexpr LSHIFT pexpr
| pexpr RSHIFT pexpr | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1301-L1347 |
boriel/zxbasic | asmparse.py | p_expr_int | def p_expr_int(p):
""" expr : INTEGER
"""
p[0] = Expr.makenode(Container(int(p[1]), p.lineno(1))) | python | def p_expr_int(p):
""" expr : INTEGER
"""
p[0] = Expr.makenode(Container(int(p[1]), p.lineno(1))) | expr : INTEGER | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1362-L1365 |
boriel/zxbasic | asmparse.py | p_expr_label | def p_expr_label(p):
""" expr : ID
"""
p[0] = Expr.makenode(Container(MEMORY.get_label(p[1], p.lineno(1)), p.lineno(1))) | python | def p_expr_label(p):
""" expr : ID
"""
p[0] = Expr.makenode(Container(MEMORY.get_label(p[1], p.lineno(1)), p.lineno(1))) | expr : ID | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1368-L1371 |
boriel/zxbasic | asmparse.py | p_expr_addr | def p_expr_addr(p):
""" expr : ADDR
"""
# The current instruction address
p[0] = Expr.makenode(Container(MEMORY.org, p.lineno(1))) | python | def p_expr_addr(p):
""" expr : ADDR
"""
# The current instruction address
p[0] = Expr.makenode(Container(MEMORY.org, p.lineno(1))) | expr : ADDR | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1380-L1384 |
boriel/zxbasic | asmparse.py | p_preprocessor_line_line | def p_preprocessor_line_line(p):
""" preproc_line : _LINE INTEGER
"""
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(2) | python | def p_preprocessor_line_line(p):
""" preproc_line : _LINE INTEGER
"""
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(2) | preproc_line : _LINE INTEGER | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1394-L1397 |
boriel/zxbasic | asmparse.py | p_preprocessor_line_line_file | def p_preprocessor_line_line_file(p):
""" preproc_line : _LINE INTEGER STRING
"""
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(3) - 1
gl.FILENAME = p[3] | python | def p_preprocessor_line_line_file(p):
""" preproc_line : _LINE INTEGER STRING
"""
p.lexer.lineno = int(p[2]) + p.lexer.lineno - p.lineno(3) - 1
gl.FILENAME = p[3] | preproc_line : _LINE INTEGER STRING | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1400-L1404 |
boriel/zxbasic | asmparse.py | assemble | def assemble(input_):
""" Assembles input string, and leave the result in the
MEMORY global object
"""
global MEMORY
if MEMORY is None:
MEMORY = Memory()
parser.parse(input_, lexer=LEXER, debug=OPTIONS.Debug.value > 2)
if len(MEMORY.scopes):
error(MEMORY.scopes[-1], 'Missing ENDP to close this scope')
return gl.has_errors | python | def assemble(input_):
""" Assembles input string, and leave the result in the
MEMORY global object
"""
global MEMORY
if MEMORY is None:
MEMORY = Memory()
parser.parse(input_, lexer=LEXER, debug=OPTIONS.Debug.value > 2)
if len(MEMORY.scopes):
error(MEMORY.scopes[-1], 'Missing ENDP to close this scope')
return gl.has_errors | Assembles input string, and leave the result in the
MEMORY global object | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1426-L1439 |
boriel/zxbasic | asmparse.py | generate_binary | def generate_binary(outputfname, format_, progname='', binary_files=None, headless_binary_files=None):
""" Outputs the memory binary to the
output filename using one of the given
formats: tap, tzx or bin
"""
global AUTORUN_ADDR
org, binary = MEMORY.dump()
if gl.has_errors:
return
if binary_files is None:
binary_files = []
if headless_binary_files is None:
headless_binary_files = []
bin_blocks = []
for fname in binary_files:
with api.utils.open_file(fname) as f:
bin_blocks.append((os.path.basename(fname), f.read()))
headless_bin_blocks = []
for fname in headless_binary_files:
with api.utils.open_file(fname) as f:
headless_bin_blocks.append(f.read())
if AUTORUN_ADDR is None:
AUTORUN_ADDR = org
if not progname:
progname = os.path.basename(outputfname)[:10]
if OPTIONS.use_loader.value:
import basic # Minimalist basic tokenizer
program = basic.Basic()
if org > 16383: # Only for zx48k: CLEAR if below 16383
program.add_line([['CLEAR', org - 1]])
program.add_line([['LOAD', '""', program.token('CODE')]])
if OPTIONS.autorun.value:
program.add_line([['RANDOMIZE', program.token('USR'), AUTORUN_ADDR]])
else:
program.add_line([['REM'], ['RANDOMIZE', program.token('USR'), AUTORUN_ADDR]])
if format_ in ('tap', 'tzx'):
t = {'tap': outfmt.TAP, 'tzx': outfmt.TZX}[format_]()
if OPTIONS.use_loader.value:
t.save_program('loader', program.bytes, line=1) # Put line 0 to protect against MERGE
t.save_code(progname, org, binary)
for name, block in bin_blocks:
t.save_code(name, 0, block)
for block in headless_bin_blocks:
t.standard_block(block)
t.dump(outputfname)
else:
with open(outputfname, 'wb') as f:
f.write(bytearray(binary)) | python | def generate_binary(outputfname, format_, progname='', binary_files=None, headless_binary_files=None):
""" Outputs the memory binary to the
output filename using one of the given
formats: tap, tzx or bin
"""
global AUTORUN_ADDR
org, binary = MEMORY.dump()
if gl.has_errors:
return
if binary_files is None:
binary_files = []
if headless_binary_files is None:
headless_binary_files = []
bin_blocks = []
for fname in binary_files:
with api.utils.open_file(fname) as f:
bin_blocks.append((os.path.basename(fname), f.read()))
headless_bin_blocks = []
for fname in headless_binary_files:
with api.utils.open_file(fname) as f:
headless_bin_blocks.append(f.read())
if AUTORUN_ADDR is None:
AUTORUN_ADDR = org
if not progname:
progname = os.path.basename(outputfname)[:10]
if OPTIONS.use_loader.value:
import basic # Minimalist basic tokenizer
program = basic.Basic()
if org > 16383: # Only for zx48k: CLEAR if below 16383
program.add_line([['CLEAR', org - 1]])
program.add_line([['LOAD', '""', program.token('CODE')]])
if OPTIONS.autorun.value:
program.add_line([['RANDOMIZE', program.token('USR'), AUTORUN_ADDR]])
else:
program.add_line([['REM'], ['RANDOMIZE', program.token('USR'), AUTORUN_ADDR]])
if format_ in ('tap', 'tzx'):
t = {'tap': outfmt.TAP, 'tzx': outfmt.TZX}[format_]()
if OPTIONS.use_loader.value:
t.save_program('loader', program.bytes, line=1) # Put line 0 to protect against MERGE
t.save_code(progname, org, binary)
for name, block in bin_blocks:
t.save_code(name, 0, block)
for block in headless_bin_blocks:
t.standard_block(block)
t.dump(outputfname)
else:
with open(outputfname, 'wb') as f:
f.write(bytearray(binary)) | Outputs the memory binary to the
output filename using one of the given
formats: tap, tzx or bin | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1442-L1504 |
boriel/zxbasic | asmparse.py | main | def main(argv):
""" This is a test and will assemble the file in argv[0]
"""
init()
if OPTIONS.StdErrFileName.value:
OPTIONS.stderr.value = open('wt', OPTIONS.StdErrFileName.value)
asmlex.FILENAME = OPTIONS.inputFileName.value = argv[0]
input_ = open(OPTIONS.inputFileName.value, 'rt').read()
assemble(input_)
generate_binary(OPTIONS.outputFileName.value, OPTIONS.output_file_type) | python | def main(argv):
""" This is a test and will assemble the file in argv[0]
"""
init()
if OPTIONS.StdErrFileName.value:
OPTIONS.stderr.value = open('wt', OPTIONS.StdErrFileName.value)
asmlex.FILENAME = OPTIONS.inputFileName.value = argv[0]
input_ = open(OPTIONS.inputFileName.value, 'rt').read()
assemble(input_)
generate_binary(OPTIONS.outputFileName.value, OPTIONS.output_file_type) | This is a test and will assemble the file in argv[0] | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1507-L1518 |
boriel/zxbasic | asmparse.py | Asm.bytes | def bytes(self):
""" Returns opcodes
"""
if self.asm not in ('DEFB', 'DEFS', 'DEFW'):
if self.pending:
tmp = self.arg # Saves current arg temporarily
self.arg = tuple([0] * self.arg_num)
result = super(Asm, self).bytes()
self.arg = tmp # And recovers it
return result
return super(Asm, self).bytes()
if self.asm == 'DEFB':
if self.pending:
return tuple([0] * self.arg_num)
return tuple([x & 0xFF for x in self.argval()])
if self.asm == 'DEFS':
if self.pending:
N = self.arg[0]
if isinstance(N, Expr):
N = N.eval()
return tuple([0] * N) # ??
args = self.argval()
num = args[1] & 0xFF
return tuple([num] * args[0])
if self.pending: # DEFW
return tuple([0] * 2 * self.arg_num)
result = ()
for i in self.argval():
x = i & 0xFFFF
result += (x & 0xFF, x >> 8)
return result | python | def bytes(self):
""" Returns opcodes
"""
if self.asm not in ('DEFB', 'DEFS', 'DEFW'):
if self.pending:
tmp = self.arg # Saves current arg temporarily
self.arg = tuple([0] * self.arg_num)
result = super(Asm, self).bytes()
self.arg = tmp # And recovers it
return result
return super(Asm, self).bytes()
if self.asm == 'DEFB':
if self.pending:
return tuple([0] * self.arg_num)
return tuple([x & 0xFF for x in self.argval()])
if self.asm == 'DEFS':
if self.pending:
N = self.arg[0]
if isinstance(N, Expr):
N = N.eval()
return tuple([0] * N) # ??
args = self.argval()
num = args[1] & 0xFF
return tuple([num] * args[0])
if self.pending: # DEFW
return tuple([0] * 2 * self.arg_num)
result = ()
for i in self.argval():
x = i & 0xFFFF
result += (x & 0xFF, x >> 8)
return result | Returns opcodes | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L118-L157 |
boriel/zxbasic | asmparse.py | Asm.argval | def argval(self):
""" Solve args values or raise errors if not
defined yet
"""
if gl.has_errors:
return [None]
if self.asm in ('DEFB', 'DEFS', 'DEFW'):
return tuple([x.eval() if isinstance(x, Expr) else x for x in self.arg])
self.arg = tuple([x if not isinstance(x, Expr) else x.eval() for x in self.arg])
if gl.has_errors:
return [None]
if self.asm.split(' ')[0] in ('JR', 'DJNZ'): # A relative jump?
if self.arg[0] < -128 or self.arg[0] > 127:
error(self.lineno, 'Relative jump out of range')
return [None]
return super(Asm, self).argval() | python | def argval(self):
""" Solve args values or raise errors if not
defined yet
"""
if gl.has_errors:
return [None]
if self.asm in ('DEFB', 'DEFS', 'DEFW'):
return tuple([x.eval() if isinstance(x, Expr) else x for x in self.arg])
self.arg = tuple([x if not isinstance(x, Expr) else x.eval() for x in self.arg])
if gl.has_errors:
return [None]
if self.asm.split(' ')[0] in ('JR', 'DJNZ'): # A relative jump?
if self.arg[0] < -128 or self.arg[0] > 127:
error(self.lineno, 'Relative jump out of range')
return [None]
return super(Asm, self).argval() | Solve args values or raise errors if not
defined yet | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L159-L178 |
boriel/zxbasic | asmparse.py | Expr.eval | def eval(self):
""" Recursively evals the node. Exits with an
error if not resolved.
"""
Expr.ignore = False
result = self.try_eval()
Expr.ignore = True
return result | python | def eval(self):
""" Recursively evals the node. Exits with an
error if not resolved.
"""
Expr.ignore = False
result = self.try_eval()
Expr.ignore = True
return result | Recursively evals the node. Exits with an
error if not resolved. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L244-L252 |
boriel/zxbasic | asmparse.py | Expr.try_eval | def try_eval(self):
""" Recursively evals the node. Returns None
if it is still unresolved.
"""
item = self.symbol.item
if isinstance(item, int):
return item
if isinstance(item, Label):
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 None
try:
if isinstance(item, tuple):
return tuple([x.try_eval() for x in item])
if isinstance(item, list):
return [x.try_eval() for x in item]
if item == '-' and len(self.children) == 1:
return -self.left.try_eval()
try:
return self.funct[item](self.left.try_eval(), self.right.try_eval())
except ZeroDivisionError:
error(self.symbol.lineno, 'Division by 0')
except KeyError:
pass
except TypeError:
pass
return None | python | def try_eval(self):
""" Recursively evals the node. Returns None
if it is still unresolved.
"""
item = self.symbol.item
if isinstance(item, int):
return item
if isinstance(item, Label):
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 None
try:
if isinstance(item, tuple):
return tuple([x.try_eval() for x in item])
if isinstance(item, list):
return [x.try_eval() for x in item]
if item == '-' and len(self.children) == 1:
return -self.left.try_eval()
try:
return self.funct[item](self.left.try_eval(), self.right.try_eval())
except ZeroDivisionError:
error(self.symbol.lineno, 'Division by 0')
except KeyError:
pass
except TypeError:
pass
return None | Recursively evals the node. Returns None
if it is still unresolved. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L254-L297 |
boriel/zxbasic | asmparse.py | Label.define | def define(self, value, lineno, namespace=None):
""" Defines label value. It can be anything. Even an AST
"""
if self.defined:
error(lineno, "label '%s' already defined at line %i" % (self.name, self.lineno))
self.value = value
self.lineno = lineno
self.namespace = NAMESPACE if namespace is None else namespace | python | def define(self, value, lineno, namespace=None):
""" Defines label value. It can be anything. Even an AST
"""
if self.defined:
error(lineno, "label '%s' already defined at line %i" % (self.name, self.lineno))
self.value = value
self.lineno = lineno
self.namespace = NAMESPACE if namespace is None else namespace | Defines label value. It can be anything. Even an AST | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L329-L337 |
boriel/zxbasic | asmparse.py | Label.resolve | def resolve(self, lineno):
""" Evaluates label value. Exits with error (unresolved) if value is none
"""
if not self.defined:
error(lineno, "Undeclared label '%s'" % self.name)
if isinstance(self.value, Expr):
return self.value.eval()
return self.value | python | def resolve(self, lineno):
""" Evaluates label value. Exits with error (unresolved) if value is none
"""
if not self.defined:
error(lineno, "Undeclared label '%s'" % self.name)
if isinstance(self.value, Expr):
return self.value.eval()
return self.value | Evaluates label value. Exits with error (unresolved) if value is none | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L339-L348 |
boriel/zxbasic | asmparse.py | Memory.enter_proc | def enter_proc(self, lineno):
""" Enters (pushes) a new context
"""
self.local_labels.append({}) # Add a new context
self.scopes.append(lineno)
__DEBUG__('Entering scope level %i at line %i' % (len(self.scopes), lineno)) | python | def enter_proc(self, lineno):
""" Enters (pushes) a new context
"""
self.local_labels.append({}) # Add a new context
self.scopes.append(lineno)
__DEBUG__('Entering scope level %i at line %i' % (len(self.scopes), lineno)) | Enters (pushes) a new context | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L370-L375 |
boriel/zxbasic | asmparse.py | Memory.set_org | def set_org(self, value, lineno):
""" Sets a new ORG value
"""
if value < 0 or value > MAX_MEM:
error(lineno, "Memory ORG out of range [0 .. 65535]. Current value: %i" % value)
self.index = self.ORG = value | python | def set_org(self, value, lineno):
""" Sets a new ORG value
"""
if value < 0 or value > MAX_MEM:
error(lineno, "Memory ORG out of range [0 .. 65535]. Current value: %i" % value)
self.index = self.ORG = value | Sets a new ORG value | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L377-L383 |
boriel/zxbasic | asmparse.py | Memory.id_name | def id_name(label, namespace=None):
""" Given a name and a namespace, resolves
returns the name as namespace + '.' + name. If namespace
is none, the current NAMESPACE is used
"""
if not label.startswith(DOT):
if namespace is None:
namespace = NAMESPACE
ex_label = namespace + label # The mangled namespace.labelname label
else:
if namespace is None:
namespace = GLOBAL_NAMESPACE # Global namespace
ex_label = label
return ex_label, namespace | python | def id_name(label, namespace=None):
""" Given a name and a namespace, resolves
returns the name as namespace + '.' + name. If namespace
is none, the current NAMESPACE is used
"""
if not label.startswith(DOT):
if namespace is None:
namespace = NAMESPACE
ex_label = namespace + label # The mangled namespace.labelname label
else:
if namespace is None:
namespace = GLOBAL_NAMESPACE # Global namespace
ex_label = label
return ex_label, namespace | Given a name and a namespace, resolves
returns the name as namespace + '.' + name. If namespace
is none, the current NAMESPACE is used | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L386-L400 |
boriel/zxbasic | asmparse.py | Memory.__set_byte | def __set_byte(self, byte, lineno):
""" Sets a byte at the current location,
and increments org in one. Raises an error if org > MAX_MEMORY
"""
if byte < 0 or byte > 255:
error(lineno, 'Invalid byte value %i' % byte)
self.memory_bytes[self.org] = byte
self.index += 1 | python | def __set_byte(self, byte, lineno):
""" Sets a byte at the current location,
and increments org in one. Raises an error if org > MAX_MEMORY
"""
if byte < 0 or byte > 255:
error(lineno, 'Invalid byte value %i' % byte)
self.memory_bytes[self.org] = byte
self.index += 1 | Sets a byte at the current location,
and increments org in one. Raises an error if org > MAX_MEMORY | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L408-L416 |
boriel/zxbasic | asmparse.py | Memory.exit_proc | def exit_proc(self, lineno):
""" Exits current procedure. Local labels are transferred to global
scope unless they have been marked as local ones.
Raises an error if no current local context (stack underflow)
"""
__DEBUG__('Exiting current scope from lineno %i' % lineno)
if len(self.local_labels) <= 1:
error(lineno, 'ENDP in global scope (with no PROC)')
return
for label in self.local_labels[-1].values():
if label.local:
if not label.defined:
error(lineno, "Undefined LOCAL label '%s'" % label.name)
return
continue
name = label.name
_lineno = label.lineno
value = label.value
if name not in self.global_labels.keys():
self.global_labels[name] = label
else:
self.global_labels[name].define(value, _lineno)
self.local_labels.pop() # Removes current context
self.scopes.pop() | python | def exit_proc(self, lineno):
""" Exits current procedure. Local labels are transferred to global
scope unless they have been marked as local ones.
Raises an error if no current local context (stack underflow)
"""
__DEBUG__('Exiting current scope from lineno %i' % lineno)
if len(self.local_labels) <= 1:
error(lineno, 'ENDP in global scope (with no PROC)')
return
for label in self.local_labels[-1].values():
if label.local:
if not label.defined:
error(lineno, "Undefined LOCAL label '%s'" % label.name)
return
continue
name = label.name
_lineno = label.lineno
value = label.value
if name not in self.global_labels.keys():
self.global_labels[name] = label
else:
self.global_labels[name].define(value, _lineno)
self.local_labels.pop() # Removes current context
self.scopes.pop() | Exits current procedure. Local labels are transferred to global
scope unless they have been marked as local ones.
Raises an error if no current local context (stack underflow) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L418-L447 |
boriel/zxbasic | asmparse.py | Memory.add_instruction | def add_instruction(self, instr):
""" This will insert an asm instruction at the current memory position
in a t-uple as (mnemonic, params).
It will also insert the opcodes at the memory_bytes
"""
if gl.has_errors:
return
__DEBUG__('%04Xh [%04Xh] ASM: %s' % (self.org, self.org - self.ORG, instr.asm))
self.set_memory_slot()
self.orgs[self.org] += (instr,)
for byte in instr.bytes():
self.__set_byte(byte, instr.lineno) | python | def add_instruction(self, instr):
""" This will insert an asm instruction at the current memory position
in a t-uple as (mnemonic, params).
It will also insert the opcodes at the memory_bytes
"""
if gl.has_errors:
return
__DEBUG__('%04Xh [%04Xh] ASM: %s' % (self.org, self.org - self.ORG, instr.asm))
self.set_memory_slot()
self.orgs[self.org] += (instr,)
for byte in instr.bytes():
self.__set_byte(byte, instr.lineno) | This will insert an asm instruction at the current memory position
in a t-uple as (mnemonic, params).
It will also insert the opcodes at the memory_bytes | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L454-L468 |
boriel/zxbasic | asmparse.py | Memory.dump | def dump(self):
""" Returns a tuple containing code ORG, and a list of OUTPUT
"""
org = min(self.memory_bytes.keys()) # Org is the lowest one
OUTPUT = []
align = []
for i in range(org, max(self.memory_bytes.keys()) + 1):
if gl.has_errors:
return org, OUTPUT
try:
try:
a = [x for x in self.orgs[i] if isinstance(x, Asm)] # search for asm instructions
if not a:
align.append(0) # Fill with ZEROes not used memory regions
continue
OUTPUT += align
align = []
a = a[0]
if a.pending:
a.arg = a.argval()
a.pending = False
tmp = a.bytes()
for r in range(len(tmp)):
self.memory_bytes[i + r] = tmp[r]
except KeyError:
pass
OUTPUT.append(self.memory_bytes[i])
except KeyError:
OUTPUT.append(0) # Fill with ZEROes not used memory regions
return org, OUTPUT | python | def dump(self):
""" Returns a tuple containing code ORG, and a list of OUTPUT
"""
org = min(self.memory_bytes.keys()) # Org is the lowest one
OUTPUT = []
align = []
for i in range(org, max(self.memory_bytes.keys()) + 1):
if gl.has_errors:
return org, OUTPUT
try:
try:
a = [x for x in self.orgs[i] if isinstance(x, Asm)] # search for asm instructions
if not a:
align.append(0) # Fill with ZEROes not used memory regions
continue
OUTPUT += align
align = []
a = a[0]
if a.pending:
a.arg = a.argval()
a.pending = False
tmp = a.bytes()
for r in range(len(tmp)):
self.memory_bytes[i + r] = tmp[r]
except KeyError:
pass
OUTPUT.append(self.memory_bytes[i])
except KeyError:
OUTPUT.append(0) # Fill with ZEROes not used memory regions
return org, OUTPUT | Returns a tuple containing code ORG, and a list of OUTPUT | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L470-L507 |
boriel/zxbasic | asmparse.py | Memory.declare_label | def declare_label(self, label, lineno, value=None, local=False, namespace=None):
""" Sets a label with the given value or with the current address (org)
if no value is passed.
Exits with error if label already set,
otherwise return the label object
"""
ex_label, namespace = Memory.id_name(label, namespace)
is_address = value is None
if value is None:
value = self.org
if ex_label in self.local_labels[-1].keys():
self.local_labels[-1][ex_label].define(value, lineno)
self.local_labels[-1][ex_label].is_address = is_address
else:
self.local_labels[-1][ex_label] = Label(ex_label, lineno, value, local, namespace, is_address)
self.set_memory_slot()
return self.local_labels[-1][ex_label] | python | def declare_label(self, label, lineno, value=None, local=False, namespace=None):
""" Sets a label with the given value or with the current address (org)
if no value is passed.
Exits with error if label already set,
otherwise return the label object
"""
ex_label, namespace = Memory.id_name(label, namespace)
is_address = value is None
if value is None:
value = self.org
if ex_label in self.local_labels[-1].keys():
self.local_labels[-1][ex_label].define(value, lineno)
self.local_labels[-1][ex_label].is_address = is_address
else:
self.local_labels[-1][ex_label] = Label(ex_label, lineno, value, local, namespace, is_address)
self.set_memory_slot()
return self.local_labels[-1][ex_label] | Sets a label with the given value or with the current address (org)
if no value is passed.
Exits with error if label already set,
otherwise return the label object | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L509-L530 |
boriel/zxbasic | asmparse.py | Memory.get_label | def get_label(self, label, lineno):
""" Returns a label in the current context or in the global one.
If the label does not exists, creates a new one and returns it.
"""
global NAMESPACE
ex_label, namespace = Memory.id_name(label)
for i in range(len(self.local_labels) - 1, -1, -1): # Downstep
result = self.local_labels[i].get(ex_label, None)
if result is not None:
return result
result = Label(ex_label, lineno, namespace=namespace)
self.local_labels[-1][ex_label] = result # HINT: no namespace
return result | python | def get_label(self, label, lineno):
""" Returns a label in the current context or in the global one.
If the label does not exists, creates a new one and returns it.
"""
global NAMESPACE
ex_label, namespace = Memory.id_name(label)
for i in range(len(self.local_labels) - 1, -1, -1): # Downstep
result = self.local_labels[i].get(ex_label, None)
if result is not None:
return result
result = Label(ex_label, lineno, namespace=namespace)
self.local_labels[-1][ex_label] = result # HINT: no namespace
return result | Returns a label in the current context or in the global one.
If the label does not exists, creates a new one and returns it. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L532-L548 |
boriel/zxbasic | asmparse.py | Memory.set_label | def set_label(self, label, lineno, local=False):
""" Sets a label, lineno and local flag in the current scope
(even if it exist in previous scopes). If the label exist in
the current scope, changes it flags.
The resulting label is returned.
"""
ex_label, namespace = Memory.id_name(label)
if ex_label in self.local_labels[-1].keys():
result = self.local_labels[-1][ex_label]
result.lineno = lineno
else:
result = self.local_labels[-1][ex_label] = Label(ex_label, lineno, namespace=NAMESPACE)
if result.local == local:
warning(lineno, "label '%s' already declared as LOCAL" % label)
result.local = local
return result | python | def set_label(self, label, lineno, local=False):
""" Sets a label, lineno and local flag in the current scope
(even if it exist in previous scopes). If the label exist in
the current scope, changes it flags.
The resulting label is returned.
"""
ex_label, namespace = Memory.id_name(label)
if ex_label in self.local_labels[-1].keys():
result = self.local_labels[-1][ex_label]
result.lineno = lineno
else:
result = self.local_labels[-1][ex_label] = Label(ex_label, lineno, namespace=NAMESPACE)
if result.local == local:
warning(lineno, "label '%s' already declared as LOCAL" % label)
result.local = local
return result | Sets a label, lineno and local flag in the current scope
(even if it exist in previous scopes). If the label exist in
the current scope, changes it flags.
The resulting label is returned. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L550-L570 |
boriel/zxbasic | asmparse.py | Memory.memory_map | def memory_map(self):
""" Returns a (very long) string containing a memory map
hex address: label
"""
return '\n'.join(sorted("%04X: %s" % (x.value, x.name) for x in self.global_labels.values() if x.is_address)) | python | def memory_map(self):
""" Returns a (very long) string containing a memory map
hex address: label
"""
return '\n'.join(sorted("%04X: %s" % (x.value, x.name) for x in self.global_labels.values() if x.is_address)) | Returns a (very long) string containing a memory map
hex address: label | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L573-L577 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _addr | def _addr(value):
''' Common subroutine for emitting array address
'''
output = []
try:
indirect = False
if value[0] == '*':
indirect = True
value = value[1:]
value = int(value) & 0xFFFF
if indirect:
output.append('ld hl, (%s)' % str(value))
else:
output.append('ld hl, %s' % str(value))
except ValueError:
if value[0] == '_':
output.append('ld hl, %s' % str(value))
if indirect:
output.append('ld c, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, c')
else:
output.append('pop hl')
if indirect:
output.append('ld c, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, c')
output.append('call __ARRAY')
REQUIRES.add('array.asm')
return output | python | def _addr(value):
''' Common subroutine for emitting array address
'''
output = []
try:
indirect = False
if value[0] == '*':
indirect = True
value = value[1:]
value = int(value) & 0xFFFF
if indirect:
output.append('ld hl, (%s)' % str(value))
else:
output.append('ld hl, %s' % str(value))
except ValueError:
if value[0] == '_':
output.append('ld hl, %s' % str(value))
if indirect:
output.append('ld c, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, c')
else:
output.append('pop hl')
if indirect:
output.append('ld c, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, c')
output.append('call __ARRAY')
REQUIRES.add('array.asm')
return output | Common subroutine for emitting array address | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L20-L56 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _aload8 | def _aload8(ins):
''' Loads an 8 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('ld a, (hl)')
output.append('push af')
return output | python | def _aload8(ins):
''' Loads an 8 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('ld a, (hl)')
output.append('push af')
return output | Loads an 8 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L69-L78 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _aload16 | def _aload16(ins):
''' Loads a 16 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('ld e, (hl)')
output.append('inc hl')
output.append('ld d, (hl)')
output.append('ex de, hl')
output.append('push hl')
return output | python | def _aload16(ins):
''' Loads a 16 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('ld e, (hl)')
output.append('inc hl')
output.append('ld d, (hl)')
output.append('ex de, hl')
output.append('push hl')
return output | Loads a 16 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L81-L94 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _aload32 | def _aload32(ins):
''' Load a 32 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
REQUIRES.add('iload32.asm')
return output | python | def _aload32(ins):
''' Load a 32 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
REQUIRES.add('iload32.asm')
return output | Load a 32 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L97-L110 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _aloadf | def _aloadf(ins):
''' Loads a floating point value from a memory address.
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('call __LOADF')
output.extend(_fpush())
REQUIRES.add('iloadf.asm')
return output | python | def _aloadf(ins):
''' Loads a floating point value from a memory address.
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _addr(ins.quad[2])
output.append('call __LOADF')
output.extend(_fpush())
REQUIRES.add('iloadf.asm')
return output | Loads a floating point value from a memory address.
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L113-L124 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _aloadstr | def _aloadstr(ins):
''' Loads a string value from a memory address.
'''
output = _addr(ins.quad[2])
output.append('call __ILOADSTR')
output.append('push hl')
REQUIRES.add('loadstr.asm')
return output | python | def _aloadstr(ins):
''' Loads a string value from a memory address.
'''
output = _addr(ins.quad[2])
output.append('call __ILOADSTR')
output.append('push hl')
REQUIRES.add('loadstr.asm')
return output | Loads a string value from a memory address. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L127-L136 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _astore8 | def _astore8(ins):
''' Stores 2º operand content into address of 1st operand.
1st operand is an array element. Dimensions are pushed into the
stack.
Use '*' for indirect store on 1st operand (A pointer to an array)
'''
output = _addr(ins.quad[1])
op = ins.quad[2]
indirect = op[0] == '*'
if indirect:
op = op[1:]
immediate = op[0] == '#'
if immediate:
op = op[1:]
if is_int(op):
if indirect:
if immediate:
op = str(int(op) & 0xFFFF) # Truncate to 16bit pointer
output.append('ld a, (%s)' % op)
else:
output.append('ld de, (%s)' % op)
output.append('ld a, (de)')
else:
op = str(int(op) & 0xFF) # Truncate to byte
output.append('ld (hl), %s' % op)
return output
elif op[0] == '_':
if indirect:
if immediate:
output.append('ld a, (%s)' % op) # Redundant: *#_id == _id
else:
output.append('ld de, (%s)' % op) # *_id
output.append('ld a, (de)')
else:
if immediate:
output.append('ld a, %s' % op) # #_id
else:
output.append('ld a, (%s)' % op) # _id
else:
output.append('pop af') # tn
output.append('ld (hl), a')
return output | python | def _astore8(ins):
''' Stores 2º operand content into address of 1st operand.
1st operand is an array element. Dimensions are pushed into the
stack.
Use '*' for indirect store on 1st operand (A pointer to an array)
'''
output = _addr(ins.quad[1])
op = ins.quad[2]
indirect = op[0] == '*'
if indirect:
op = op[1:]
immediate = op[0] == '#'
if immediate:
op = op[1:]
if is_int(op):
if indirect:
if immediate:
op = str(int(op) & 0xFFFF) # Truncate to 16bit pointer
output.append('ld a, (%s)' % op)
else:
output.append('ld de, (%s)' % op)
output.append('ld a, (de)')
else:
op = str(int(op) & 0xFF) # Truncate to byte
output.append('ld (hl), %s' % op)
return output
elif op[0] == '_':
if indirect:
if immediate:
output.append('ld a, (%s)' % op) # Redundant: *#_id == _id
else:
output.append('ld de, (%s)' % op) # *_id
output.append('ld a, (de)')
else:
if immediate:
output.append('ld a, %s' % op) # #_id
else:
output.append('ld a, (%s)' % op) # _id
else:
output.append('pop af') # tn
output.append('ld (hl), a')
return output | Stores 2º operand content into address of 1st operand.
1st operand is an array element. Dimensions are pushed into the
stack.
Use '*' for indirect store on 1st operand (A pointer to an array) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L139-L186 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _astore16 | def _astore16(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand.
'''
output = _addr(ins.quad[1])
op = ins.quad[2]
indirect = op[0] == '*'
if indirect:
op = op[1:]
immediate = op[0] == '#'
if immediate:
op = op[1:]
if is_int(op):
op = str(int(op) & 0xFFFF) # Truncate to 16bit pointer
if indirect:
if immediate:
output.append('ld de, (%s)' % op)
else:
output.append('ld de, (%s)' % op)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
H = int(op) >> 8
L = int(op) & 0xFF
output.append('ld (hl), %i' % L)
output.append('inc hl')
output.append('ld (hl), %i' % H)
return output
elif op[0] == '_':
if indirect:
if immediate:
output.append('ld de, (%s)' % op) # redundant: *#_id == _id
else:
output.append('ld de, (%s)' % op) # *_id
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
if immediate:
output.append('ld de, %s' % op)
else:
output.append('ld de, (%s)' % op)
else:
output.append('pop de')
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
return output | python | def _astore16(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand.
'''
output = _addr(ins.quad[1])
op = ins.quad[2]
indirect = op[0] == '*'
if indirect:
op = op[1:]
immediate = op[0] == '#'
if immediate:
op = op[1:]
if is_int(op):
op = str(int(op) & 0xFFFF) # Truncate to 16bit pointer
if indirect:
if immediate:
output.append('ld de, (%s)' % op)
else:
output.append('ld de, (%s)' % op)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
H = int(op) >> 8
L = int(op) & 0xFF
output.append('ld (hl), %i' % L)
output.append('inc hl')
output.append('ld (hl), %i' % H)
return output
elif op[0] == '_':
if indirect:
if immediate:
output.append('ld de, (%s)' % op) # redundant: *#_id == _id
else:
output.append('ld de, (%s)' % op) # *_id
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
if immediate:
output.append('ld de, %s' % op)
else:
output.append('ld de, (%s)' % op)
else:
output.append('pop de')
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
return output | Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L189-L243 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _astore32 | def _astore32(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
'''
output = _addr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFFFFFF # Immediate?
if indirect:
output.append('push hl')
output.append('ld hl, %i' % (value & 0xFFFF))
output.append('call __ILOAD32')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
output.append('ld de, %i' % (value >> 16))
output.append('ld bc, %i' % (value & 0xFFFF))
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | python | def _astore32(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
'''
output = _addr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFFFFFF # Immediate?
if indirect:
output.append('push hl')
output.append('ld hl, %i' % (value & 0xFFFF))
output.append('call __ILOAD32')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
output.append('ld de, %i' % (value >> 16))
output.append('ld bc, %i' % (value & 0xFFFF))
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L246-L279 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _astoref16 | def _astoref16(ins):
''' Stores 2º operand content into address of 1st operand.
storef16 a, x => *(&a) = x
'''
output = _addr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
if indirect:
output.append('push hl')
output.extend(_f16_oper(ins.quad[2], useBC=True))
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
output.extend(_f16_oper(ins.quad[2], useBC=True))
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | python | def _astoref16(ins):
''' Stores 2º operand content into address of 1st operand.
storef16 a, x => *(&a) = x
'''
output = _addr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
if indirect:
output.append('push hl')
output.extend(_f16_oper(ins.quad[2], useBC=True))
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
output.extend(_f16_oper(ins.quad[2], useBC=True))
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | Stores 2º operand content into address of 1st operand.
storef16 a, x => *(&a) = x | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L282-L306 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _astoref | def _astoref(ins):
''' Stores a floating point value into a memory address.
'''
output = _addr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
if indirect:
output.append('push hl')
output.extend(_float_oper(ins.quad[2]))
output.append('pop hl')
else:
output.extend(_float_oper(ins.quad[2]))
output.append('call __STOREF')
REQUIRES.add('storef.asm')
return output | python | def _astoref(ins):
''' Stores a floating point value into a memory address.
'''
output = _addr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
if indirect:
output.append('push hl')
output.extend(_float_oper(ins.quad[2]))
output.append('pop hl')
else:
output.extend(_float_oper(ins.quad[2]))
output.append('call __STOREF')
REQUIRES.add('storef.asm')
return output | Stores a floating point value into a memory address. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L309-L331 |
boriel/zxbasic | arch/zx48k/backend/__array.py | _astorestr | def _astorestr(ins):
''' Stores a string value into a memory address.
It copies content of 2nd operand (string), into 1st, reallocating
dynamic memory for the 1st str. These instruction DOES ALLOW
immediate strings for the 2nd parameter, starting with '#'.
'''
output = _addr(ins.quad[1])
op = ins.quad[2]
indirect = op[0] == '*'
if indirect:
op = op[1:]
immediate = op[0] == '#'
if immediate:
op = op[1:]
temporal = op[0] != '$'
if not temporal:
op = op[1:]
if is_int(op):
op = str(int(op) & 0xFFFF)
if indirect:
if immediate: # *#<addr> = ld hl, (number)
output.append('ld de, (%s)' % op)
else:
output.append('ld de, (%s)' % op)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
# Integer does not make sense here (unless it's a ptr)
raise InvalidICError(str(ins))
output.append('ld de, (%s)' % op)
elif op[0] == '_': # an identifier
temporal = False # Global var is not a temporary string
if indirect:
if immediate: # *#_id = _id
output.append('ld de, (%s)' % op)
else: # *_id
output.append('ld de, (%s)' % op)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
if immediate:
output.append('ld de, %s' % op)
else:
output.append('ld de, (%s)' % op)
else: # tn
output.append('pop de')
if indirect:
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
if not temporal:
output.append('call __STORE_STR')
REQUIRES.add('storestr.asm')
else: # A value already on dynamic memory
output.append('call __STORE_STR2')
REQUIRES.add('storestr2.asm')
return output | python | def _astorestr(ins):
''' Stores a string value into a memory address.
It copies content of 2nd operand (string), into 1st, reallocating
dynamic memory for the 1st str. These instruction DOES ALLOW
immediate strings for the 2nd parameter, starting with '#'.
'''
output = _addr(ins.quad[1])
op = ins.quad[2]
indirect = op[0] == '*'
if indirect:
op = op[1:]
immediate = op[0] == '#'
if immediate:
op = op[1:]
temporal = op[0] != '$'
if not temporal:
op = op[1:]
if is_int(op):
op = str(int(op) & 0xFFFF)
if indirect:
if immediate: # *#<addr> = ld hl, (number)
output.append('ld de, (%s)' % op)
else:
output.append('ld de, (%s)' % op)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
# Integer does not make sense here (unless it's a ptr)
raise InvalidICError(str(ins))
output.append('ld de, (%s)' % op)
elif op[0] == '_': # an identifier
temporal = False # Global var is not a temporary string
if indirect:
if immediate: # *#_id = _id
output.append('ld de, (%s)' % op)
else: # *_id
output.append('ld de, (%s)' % op)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
if immediate:
output.append('ld de, %s' % op)
else:
output.append('ld de, (%s)' % op)
else: # tn
output.append('pop de')
if indirect:
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
if not temporal:
output.append('call __STORE_STR')
REQUIRES.add('storestr.asm')
else: # A value already on dynamic memory
output.append('call __STORE_STR2')
REQUIRES.add('storestr2.asm')
return output | Stores a string value into a memory address.
It copies content of 2nd operand (string), into 1st, reallocating
dynamic memory for the 1st str. These instruction DOES ALLOW
immediate strings for the 2nd parameter, starting with '#'. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__array.py#L334-L398 |
boriel/zxbasic | symbols/arglist.py | SymbolARGLIST.make_node | def make_node(cls, node, *args):
""" This will return a node with an argument_list.
"""
if node is None:
node = cls()
assert isinstance(node, SymbolARGUMENT) or isinstance(node, cls)
if not isinstance(node, cls):
return cls.make_node(None, node, *args)
for arg in args:
assert isinstance(arg, SymbolARGUMENT)
node.appendChild(arg)
return node | python | def make_node(cls, node, *args):
""" This will return a node with an argument_list.
"""
if node is None:
node = cls()
assert isinstance(node, SymbolARGUMENT) or isinstance(node, cls)
if not isinstance(node, cls):
return cls.make_node(None, node, *args)
for arg in args:
assert isinstance(arg, SymbolARGUMENT)
node.appendChild(arg)
return node | This will return a node with an argument_list. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/arglist.py#L50-L65 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _32bit_oper | def _32bit_oper(op1, op2=None, reversed=False, preserveHL=False):
""" Returns pop sequence for 32 bits operands
1st operand in HLDE, 2nd operand remains in the stack
Now it does support operands inversion calling __SWAP32.
However, if 1st operand is integer (immediate) or indirect, the stack
will be rearranged, so it contains a 32 bit pushed parameter value for the
subroutine to be called.
If preserveHL is True, then BC will be used instead of HL for lower part
for the 1st operand.
"""
output = []
if op1 is not None:
op1 = str(op1)
if op2 is not None:
op2 = str(op2)
op = op2 if op2 is not None else op1
int1 = False # whether op1 (2nd operand) is integer
indirect = (op[0] == '*')
if indirect:
op = op[1:]
immediate = (op[0] == '#')
if immediate:
op = op[1:]
hl = 'hl' if not preserveHL and not indirect else 'bc'
if is_int(op):
int1 = True
op = int(op)
if indirect:
if immediate:
output.append('ld hl, %i' % op)
else:
output.append('ld hl, (%i)' % op)
output.append('call __ILOAD32')
REQUIRES.add('iload32.asm')
if preserveHL:
output.append('ld b, h')
output.append('ld c, l')
else:
DE, HL = int32(op)
output.append('ld de, %i' % DE)
output.append('ld %s, %i' % (hl, HL))
else:
if op[0] == '_':
if immediate:
output.append('ld %s, %s' % (hl, op))
else:
output.append('ld %s, (%s)' % (hl, op))
else:
if immediate:
output.append('ld %s, (%s) & 0xFFFF' % (hl, op))
else:
output.append('pop %s' % hl)
if indirect:
output.append('call __ILOAD32')
REQUIRES.add('iload32.asm')
if preserveHL:
output.append('ld b, h')
output.append('ld c, l')
else:
if op[0] == '_':
output.append('ld de, (%s + 2)' % op)
else:
if immediate:
output.append('ld de, (%s) >> 16' % op)
else:
output.append('pop de')
if op2 is not None:
op = op1
indirect = (op[0] == '*')
if indirect:
op = op[1:]
immediate = (op[0] == '#')
if immediate:
op = op[1:]
if is_int(op):
op = int(op)
if indirect:
output.append('exx')
if immediate:
output.append('ld hl, %i' % (op & 0xFFFF))
else:
output.append('ld hl, (%i)' % (op & 0xFFFF))
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
output.append('exx')
REQUIRES.add('iload32.asm')
else:
DE, HL = int32(op)
output.append('ld bc, %i' % DE)
output.append('push bc')
output.append('ld bc, %i' % HL)
output.append('push bc')
else:
if indirect:
output.append('exx') # uses alternate set to put it on the stack
if op[0] == '_':
if immediate:
output.append('ld hl, %s' % op)
else:
output.append('ld hl, (%s)' % op)
else:
output.append('pop hl') # Pointers are only 16 bits ***
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
output.append('exx')
REQUIRES.add('iload32.asm')
elif immediate:
output.append('ld bc, (%s) >> 16' % op)
output.append('push bc')
output.append('ld bc, (%s) & 0xFFFF' % op)
output.append('push bc')
elif op[0] == '_': # an address
if int1 or op1[0] == '_': # If previous op was integer, we can use hl in advance
tmp = output
output = []
output.append('ld hl, (%s + 2)' % op)
output.append('push hl')
output.append('ld hl, (%s)' % op)
output.append('push hl')
output.extend(tmp)
else:
output.append('ld bc, (%s + 2)' % op)
output.append('push bc')
output.append('ld bc, (%s)' % op)
output.append('push bc')
else:
pass # 2nd operand remains in the stack
if op2 is not None and reversed:
output.append('call __SWAP32')
REQUIRES.add('swap32.asm')
return output | python | def _32bit_oper(op1, op2=None, reversed=False, preserveHL=False):
""" Returns pop sequence for 32 bits operands
1st operand in HLDE, 2nd operand remains in the stack
Now it does support operands inversion calling __SWAP32.
However, if 1st operand is integer (immediate) or indirect, the stack
will be rearranged, so it contains a 32 bit pushed parameter value for the
subroutine to be called.
If preserveHL is True, then BC will be used instead of HL for lower part
for the 1st operand.
"""
output = []
if op1 is not None:
op1 = str(op1)
if op2 is not None:
op2 = str(op2)
op = op2 if op2 is not None else op1
int1 = False # whether op1 (2nd operand) is integer
indirect = (op[0] == '*')
if indirect:
op = op[1:]
immediate = (op[0] == '#')
if immediate:
op = op[1:]
hl = 'hl' if not preserveHL and not indirect else 'bc'
if is_int(op):
int1 = True
op = int(op)
if indirect:
if immediate:
output.append('ld hl, %i' % op)
else:
output.append('ld hl, (%i)' % op)
output.append('call __ILOAD32')
REQUIRES.add('iload32.asm')
if preserveHL:
output.append('ld b, h')
output.append('ld c, l')
else:
DE, HL = int32(op)
output.append('ld de, %i' % DE)
output.append('ld %s, %i' % (hl, HL))
else:
if op[0] == '_':
if immediate:
output.append('ld %s, %s' % (hl, op))
else:
output.append('ld %s, (%s)' % (hl, op))
else:
if immediate:
output.append('ld %s, (%s) & 0xFFFF' % (hl, op))
else:
output.append('pop %s' % hl)
if indirect:
output.append('call __ILOAD32')
REQUIRES.add('iload32.asm')
if preserveHL:
output.append('ld b, h')
output.append('ld c, l')
else:
if op[0] == '_':
output.append('ld de, (%s + 2)' % op)
else:
if immediate:
output.append('ld de, (%s) >> 16' % op)
else:
output.append('pop de')
if op2 is not None:
op = op1
indirect = (op[0] == '*')
if indirect:
op = op[1:]
immediate = (op[0] == '#')
if immediate:
op = op[1:]
if is_int(op):
op = int(op)
if indirect:
output.append('exx')
if immediate:
output.append('ld hl, %i' % (op & 0xFFFF))
else:
output.append('ld hl, (%i)' % (op & 0xFFFF))
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
output.append('exx')
REQUIRES.add('iload32.asm')
else:
DE, HL = int32(op)
output.append('ld bc, %i' % DE)
output.append('push bc')
output.append('ld bc, %i' % HL)
output.append('push bc')
else:
if indirect:
output.append('exx') # uses alternate set to put it on the stack
if op[0] == '_':
if immediate:
output.append('ld hl, %s' % op)
else:
output.append('ld hl, (%s)' % op)
else:
output.append('pop hl') # Pointers are only 16 bits ***
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
output.append('exx')
REQUIRES.add('iload32.asm')
elif immediate:
output.append('ld bc, (%s) >> 16' % op)
output.append('push bc')
output.append('ld bc, (%s) & 0xFFFF' % op)
output.append('push bc')
elif op[0] == '_': # an address
if int1 or op1[0] == '_': # If previous op was integer, we can use hl in advance
tmp = output
output = []
output.append('ld hl, (%s + 2)' % op)
output.append('push hl')
output.append('ld hl, (%s)' % op)
output.append('push hl')
output.extend(tmp)
else:
output.append('ld bc, (%s + 2)' % op)
output.append('push bc')
output.append('ld bc, (%s)' % op)
output.append('push bc')
else:
pass # 2nd operand remains in the stack
if op2 is not None and reversed:
output.append('call __SWAP32')
REQUIRES.add('swap32.asm')
return output | Returns pop sequence for 32 bits operands
1st operand in HLDE, 2nd operand remains in the stack
Now it does support operands inversion calling __SWAP32.
However, if 1st operand is integer (immediate) or indirect, the stack
will be rearranged, so it contains a 32 bit pushed parameter value for the
subroutine to be called.
If preserveHL is True, then BC will be used instead of HL for lower part
for the 1st operand. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L32-L189 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _add32 | def _add32(ins):
""" Pops last 2 bytes from the stack and adds them.
Then push the result onto the stack.
Optimizations:
* If any of the operands is ZERO,
then do NOTHING: A + 0 = 0 + A = A
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
o1, o2 = _int_ops(op1, op2)
if int(o2) == 0: # A + 0 = 0 + A = A => Do Nothing
output = _32bit_oper(o1)
output.append('push de')
output.append('push hl')
return output
if op1[0] == '_' and op2[0] != '_':
op1, op2 = op2, op1 # swap them
if op2[0] == '_':
output = _32bit_oper(op1)
output.append('ld bc, (%s)' % op2)
output.append('add hl, bc')
output.append('ex de, hl')
output.append('ld bc, (%s + 2)' % op2)
output.append('adc hl, bc')
output.append('push hl')
output.append('push de')
return output
output = _32bit_oper(op1, op2)
output.append('pop bc')
output.append('add hl, bc')
output.append('ex de, hl')
output.append('pop bc')
output.append('adc hl, bc')
output.append('push hl') # High and low parts are reversed
output.append('push de')
return output | python | def _add32(ins):
""" Pops last 2 bytes from the stack and adds them.
Then push the result onto the stack.
Optimizations:
* If any of the operands is ZERO,
then do NOTHING: A + 0 = 0 + A = A
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
o1, o2 = _int_ops(op1, op2)
if int(o2) == 0: # A + 0 = 0 + A = A => Do Nothing
output = _32bit_oper(o1)
output.append('push de')
output.append('push hl')
return output
if op1[0] == '_' and op2[0] != '_':
op1, op2 = op2, op1 # swap them
if op2[0] == '_':
output = _32bit_oper(op1)
output.append('ld bc, (%s)' % op2)
output.append('add hl, bc')
output.append('ex de, hl')
output.append('ld bc, (%s + 2)' % op2)
output.append('adc hl, bc')
output.append('push hl')
output.append('push de')
return output
output = _32bit_oper(op1, op2)
output.append('pop bc')
output.append('add hl, bc')
output.append('ex de, hl')
output.append('pop bc')
output.append('adc hl, bc')
output.append('push hl') # High and low parts are reversed
output.append('push de')
return output | Pops last 2 bytes from the stack and adds them.
Then push the result onto the stack.
Optimizations:
* If any of the operands is ZERO,
then do NOTHING: A + 0 = 0 + A = A | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L196-L238 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _sub32 | def _sub32(ins):
""" Pops last 2 dwords from the stack and subtract them.
Then push the result onto the stack.
NOTE: The operation is TOP[0] = TOP[-1] - TOP[0]
If TOP[0] is 0, nothing is done
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
if int(op2) == 0: # A - 0 = A => Do Nothing
output = _32bit_oper(op1)
output.append('push de')
output.append('push hl')
return output
rev = op1[0] != 't' and not is_int(op1) and op2[0] == 't'
output = _32bit_oper(op1, op2, rev)
output.append('call __SUB32')
output.append('push de')
output.append('push hl')
REQUIRES.add('sub32.asm')
return output | python | def _sub32(ins):
""" Pops last 2 dwords from the stack and subtract them.
Then push the result onto the stack.
NOTE: The operation is TOP[0] = TOP[-1] - TOP[0]
If TOP[0] is 0, nothing is done
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
if int(op2) == 0: # A - 0 = A => Do Nothing
output = _32bit_oper(op1)
output.append('push de')
output.append('push hl')
return output
rev = op1[0] != 't' and not is_int(op1) and op2[0] == 't'
output = _32bit_oper(op1, op2, rev)
output.append('call __SUB32')
output.append('push de')
output.append('push hl')
REQUIRES.add('sub32.asm')
return output | Pops last 2 dwords from the stack and subtract them.
Then push the result onto the stack.
NOTE: The operation is TOP[0] = TOP[-1] - TOP[0]
If TOP[0] is 0, nothing is done | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L241-L264 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _mul32 | def _mul32(ins):
""" Multiplies two last 32bit values on top of the stack and
and returns the value on top of the stack
Optimizations done:
* If any operand is 1, do nothing
* If any operand is 0, push 0
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2):
op1, op2 = _int_ops(op1, op2)
output = _32bit_oper(op1)
if op2 == 1:
output.append('push de')
output.append('push hl')
return output # A * 1 = Nothing
if op2 == 0:
output.append('ld hl, 0')
output.append('push hl')
output.append('push hl')
return output
output = _32bit_oper(op1, op2)
output.append('call __MUL32') # Inmmediate
output.append('push de')
output.append('push hl')
REQUIRES.add('mul32.asm')
return output | python | def _mul32(ins):
""" Multiplies two last 32bit values on top of the stack and
and returns the value on top of the stack
Optimizations done:
* If any operand is 1, do nothing
* If any operand is 0, push 0
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2):
op1, op2 = _int_ops(op1, op2)
output = _32bit_oper(op1)
if op2 == 1:
output.append('push de')
output.append('push hl')
return output # A * 1 = Nothing
if op2 == 0:
output.append('ld hl, 0')
output.append('push hl')
output.append('push hl')
return output
output = _32bit_oper(op1, op2)
output.append('call __MUL32') # Inmmediate
output.append('push de')
output.append('push hl')
REQUIRES.add('mul32.asm')
return output | Multiplies two last 32bit values on top of the stack and
and returns the value on top of the stack
Optimizations done:
* If any operand is 1, do nothing
* If any operand is 0, push 0 | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L267-L297 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _ltu32 | def _ltu32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit unsigned version
"""
op1, op2 = tuple(ins.quad[2:])
rev = op1[0] != 't' and not is_int(op1) and op2[0] == 't'
output = _32bit_oper(op1, op2, rev)
output.append('call __SUB32')
output.append('sbc a, a')
output.append('push af')
REQUIRES.add('sub32.asm')
return output | python | def _ltu32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit unsigned version
"""
op1, op2 = tuple(ins.quad[2:])
rev = op1[0] != 't' and not is_int(op1) and op2[0] == 't'
output = _32bit_oper(op1, op2, rev)
output.append('call __SUB32')
output.append('sbc a, a')
output.append('push af')
REQUIRES.add('sub32.asm')
return output | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit unsigned version | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L406-L420 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _gtu32 | def _gtu32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand > 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit unsigned version
"""
op1, op2 = tuple(ins.quad[2:])
rev = op1[0] != 't' and not is_int(op1) and op2[0] == 't'
output = _32bit_oper(op1, op2, rev)
output.append('pop bc')
output.append('or a')
output.append('sbc hl, bc')
output.append('ex de, hl')
output.append('pop de')
output.append('sbc hl, de')
output.append('sbc a, a')
output.append('push af')
return output | python | def _gtu32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand > 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit unsigned version
"""
op1, op2 = tuple(ins.quad[2:])
rev = op1[0] != 't' and not is_int(op1) and op2[0] == 't'
output = _32bit_oper(op1, op2, rev)
output.append('pop bc')
output.append('or a')
output.append('sbc hl, bc')
output.append('ex de, hl')
output.append('pop de')
output.append('sbc hl, de')
output.append('sbc a, a')
output.append('push af')
return output | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand > 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit unsigned version | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L439-L457 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _eq32 | def _eq32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand == 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
output = _32bit_oper(op1, op2)
output.append('call __EQ32')
output.append('push af')
REQUIRES.add('eq32.asm')
return output | python | def _eq32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand == 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
output = _32bit_oper(op1, op2)
output.append('call __EQ32')
output.append('push af')
REQUIRES.add('eq32.asm')
return output | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand == 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit un/signed version | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L552-L564 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _and32 | def _and32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand AND (Logical) 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2):
op1, op2 = _int_ops(op1, op2)
if op2 == 0: # X and False = False
if str(op1)[0] == 't': # a temporary term (stack)
output = _32bit_oper(op1) # Remove op1 from the stack
else:
output = []
output.append('xor a')
output.append('push af')
return output
# For X and TRUE = X we do nothing as we have to convert it to boolean
# which is a rather expensive instruction
output = _32bit_oper(op1, op2)
output.append('call __AND32')
output.append('push af')
REQUIRES.add('and32.asm')
return output | python | def _and32(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand AND (Logical) 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2):
op1, op2 = _int_ops(op1, op2)
if op2 == 0: # X and False = False
if str(op1)[0] == 't': # a temporary term (stack)
output = _32bit_oper(op1) # Remove op1 from the stack
else:
output = []
output.append('xor a')
output.append('push af')
return output
# For X and TRUE = X we do nothing as we have to convert it to boolean
# which is a rather expensive instruction
output = _32bit_oper(op1, op2)
output.append('call __AND32')
output.append('push af')
REQUIRES.add('and32.asm')
return output | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand AND (Logical) 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
32 bit un/signed version | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L646-L674 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _not32 | def _not32(ins):
""" Negates top (Logical NOT) of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __NOT32')
output.append('push af')
REQUIRES.add('not32.asm')
return output | python | def _not32(ins):
""" Negates top (Logical NOT) of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __NOT32')
output.append('push af')
REQUIRES.add('not32.asm')
return output | Negates top (Logical NOT) of the stack (32 bits in DEHL) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L693-L700 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _bnot32 | def _bnot32(ins):
""" Negates top (Bitwise NOT) of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __BNOT32')
output.append('push de')
output.append('push hl')
REQUIRES.add('bnot32.asm')
return output | python | def _bnot32(ins):
""" Negates top (Bitwise NOT) of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __BNOT32')
output.append('push de')
output.append('push hl')
REQUIRES.add('bnot32.asm')
return output | Negates top (Bitwise NOT) of the stack (32 bits in DEHL) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L703-L711 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _neg32 | def _neg32(ins):
""" Negates top of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __NEG32')
output.append('push de')
output.append('push hl')
REQUIRES.add('neg32.asm')
return output | python | def _neg32(ins):
""" Negates top of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __NEG32')
output.append('push de')
output.append('push hl')
REQUIRES.add('neg32.asm')
return output | Negates top of the stack (32 bits in DEHL) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L714-L722 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _abs32 | def _abs32(ins):
""" Absolute value of top of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __ABS32')
output.append('push de')
output.append('push hl')
REQUIRES.add('abs32.asm')
return output | python | def _abs32(ins):
""" Absolute value of top of the stack (32 bits in DEHL)
"""
output = _32bit_oper(ins.quad[2])
output.append('call __ABS32')
output.append('push de')
output.append('push hl')
REQUIRES.add('abs32.asm')
return output | Absolute value of top of the stack (32 bits in DEHL) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L725-L733 |
boriel/zxbasic | arch/zx48k/backend/__32bit.py | _shl32 | def _shl32(ins):
""" Logical Left shift 32bit unsigned integers.
The result is pushed onto the stack.
Optimizations:
* If 2nd operand is 0, do nothing
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
output = _32bit_oper(op1)
if int(op2) == 0:
output.append('push de')
output.append('push hl')
return output
if int(op2) > 1:
label = tmp_label()
output.append('ld b, %s' % op2)
output.append('%s:' % label)
output.append('call __SHL32')
output.append('djnz %s' % label)
else:
output.append('call __SHL32')
output.append('push de')
output.append('push hl')
REQUIRES.add('shl32.asm')
return output
output = _8bit_oper(op2)
output.append('ld b, a')
output.extend(_32bit_oper(op1))
label = tmp_label()
output.append('%s:' % label)
output.append('call __SHL32')
output.append('djnz %s' % label)
output.append('push de')
output.append('push hl')
REQUIRES.add('shl32.asm')
return output | python | def _shl32(ins):
""" Logical Left shift 32bit unsigned integers.
The result is pushed onto the stack.
Optimizations:
* If 2nd operand is 0, do nothing
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
output = _32bit_oper(op1)
if int(op2) == 0:
output.append('push de')
output.append('push hl')
return output
if int(op2) > 1:
label = tmp_label()
output.append('ld b, %s' % op2)
output.append('%s:' % label)
output.append('call __SHL32')
output.append('djnz %s' % label)
else:
output.append('call __SHL32')
output.append('push de')
output.append('push hl')
REQUIRES.add('shl32.asm')
return output
output = _8bit_oper(op2)
output.append('ld b, a')
output.extend(_32bit_oper(op1))
label = tmp_label()
output.append('%s:' % label)
output.append('call __SHL32')
output.append('djnz %s' % label)
output.append('push de')
output.append('push hl')
REQUIRES.add('shl32.asm')
return output | Logical Left shift 32bit unsigned integers.
The result is pushed onto the stack.
Optimizations:
* If 2nd operand is 0, do nothing | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__32bit.py#L826-L868 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _float_oper | def _float_oper(op1, op2=None):
''' Returns pop sequence for floating point operands
1st operand in A DE BC, 2nd operand remains in the stack
Unlike 8bit and 16bit version, this does not supports
operands inversion. Since many of the instructions are implemented
as functions, they must support this.
However, if 1st operand is a number (immediate) or indirect, the stack
will be rearranged, so it contains a 48 bit pushed parameter value for the
subroutine to be called.
'''
output = []
op = op2 if op2 is not None else op1
indirect = (op[0] == '*')
if indirect:
op = op[1:]
if is_float(op):
op = float(op)
if indirect:
op = int(op) & 0xFFFF
output.append('ld hl, (%i)' % op)
output.append('call __ILOADF')
REQUIRES.add('iloadf.asm')
else:
A, DE, BC = _float(op)
output.append('ld a, %s' % A)
output.append('ld de, %s' % DE)
output.append('ld bc, %s' % BC)
else:
if indirect:
if op[0] == '_':
output.append('ld hl, (%s)' % op)
else:
output.append('pop hl')
output.append('call __ILOADF')
REQUIRES.add('iloadf.asm')
else:
if op[0] == '_':
output.append('ld a, (%s)' % op)
output.append('ld de, (%s + 1)' % op)
output.append('ld bc, (%s + 3)' % op)
else:
output.extend(_fpop())
if op2 is not None:
op = op1
if is_float(op): # An float must be in the stack. Let's pushit
A, DE, BC = _float(op)
output.append('ld hl, %s' % BC)
output.append('push hl')
output.append('ld hl, %s' % DE)
output.append('push hl')
output.append('ld h, %s' % A)
output.append('push hl')
elif op[0] == '*': # Indirect
op = op[1:]
output.append('exx') # uses alternate set to put it on the stack
output.append("ex af, af'")
if is_int(op): # noqa TODO: it will fail
op = int(op)
output.append('ld hl, %i' % op)
elif op[0] == '_':
output.append('ld hl, (%s)' % op)
else:
output.append('pop hl')
output.append('call __ILOADF')
output.extend(_fpush())
output.append("ex af, af'")
output.append('exx')
REQUIRES.add('iloadf.asm')
elif op[0] == '_':
if is_float(op2):
tmp = output
output = []
output.append('ld hl, %s + 4' % op)
'''
output.append('ld hl, (%s + 3)' % op)
output.append('push hl')
output.append('ld hl, (%s + 1)' % op)
output.append('push hl')
output.append('ld a, (%s)' % op)
output.append('push af')
'''
output.append('call __FP_PUSH_REV')
output.extend(tmp)
REQUIRES.add('pushf.asm')
else:
'''
output.append('ld hl, (%s + 3)' % op)
output.append('push hl')
output.append('ld hl, (%s + 1)' % op)
output.append('push hl')
output.append('ld hl, (%s - 1)' % op)
output.append('push hl')
'''
output.append('ld hl, %s + 4' % op)
output.append('call __FP_PUSH_REV')
REQUIRES.add('pushf.asm')
else:
pass # Else do nothing, and leave the op onto the stack
return output | python | def _float_oper(op1, op2=None):
''' Returns pop sequence for floating point operands
1st operand in A DE BC, 2nd operand remains in the stack
Unlike 8bit and 16bit version, this does not supports
operands inversion. Since many of the instructions are implemented
as functions, they must support this.
However, if 1st operand is a number (immediate) or indirect, the stack
will be rearranged, so it contains a 48 bit pushed parameter value for the
subroutine to be called.
'''
output = []
op = op2 if op2 is not None else op1
indirect = (op[0] == '*')
if indirect:
op = op[1:]
if is_float(op):
op = float(op)
if indirect:
op = int(op) & 0xFFFF
output.append('ld hl, (%i)' % op)
output.append('call __ILOADF')
REQUIRES.add('iloadf.asm')
else:
A, DE, BC = _float(op)
output.append('ld a, %s' % A)
output.append('ld de, %s' % DE)
output.append('ld bc, %s' % BC)
else:
if indirect:
if op[0] == '_':
output.append('ld hl, (%s)' % op)
else:
output.append('pop hl')
output.append('call __ILOADF')
REQUIRES.add('iloadf.asm')
else:
if op[0] == '_':
output.append('ld a, (%s)' % op)
output.append('ld de, (%s + 1)' % op)
output.append('ld bc, (%s + 3)' % op)
else:
output.extend(_fpop())
if op2 is not None:
op = op1
if is_float(op): # An float must be in the stack. Let's pushit
A, DE, BC = _float(op)
output.append('ld hl, %s' % BC)
output.append('push hl')
output.append('ld hl, %s' % DE)
output.append('push hl')
output.append('ld h, %s' % A)
output.append('push hl')
elif op[0] == '*': # Indirect
op = op[1:]
output.append('exx') # uses alternate set to put it on the stack
output.append("ex af, af'")
if is_int(op): # noqa TODO: it will fail
op = int(op)
output.append('ld hl, %i' % op)
elif op[0] == '_':
output.append('ld hl, (%s)' % op)
else:
output.append('pop hl')
output.append('call __ILOADF')
output.extend(_fpush())
output.append("ex af, af'")
output.append('exx')
REQUIRES.add('iloadf.asm')
elif op[0] == '_':
if is_float(op2):
tmp = output
output = []
output.append('ld hl, %s + 4' % op)
'''
output.append('ld hl, (%s + 3)' % op)
output.append('push hl')
output.append('ld hl, (%s + 1)' % op)
output.append('push hl')
output.append('ld a, (%s)' % op)
output.append('push af')
'''
output.append('call __FP_PUSH_REV')
output.extend(tmp)
REQUIRES.add('pushf.asm')
else:
'''
output.append('ld hl, (%s + 3)' % op)
output.append('push hl')
output.append('ld hl, (%s + 1)' % op)
output.append('push hl')
output.append('ld hl, (%s - 1)' % op)
output.append('push hl')
'''
output.append('ld hl, %s + 4' % op)
output.append('call __FP_PUSH_REV')
REQUIRES.add('pushf.asm')
else:
pass # Else do nothing, and leave the op onto the stack
return output | Returns pop sequence for floating point operands
1st operand in A DE BC, 2nd operand remains in the stack
Unlike 8bit and 16bit version, this does not supports
operands inversion. Since many of the instructions are implemented
as functions, they must support this.
However, if 1st operand is a number (immediate) or indirect, the stack
will be rearranged, so it contains a 48 bit pushed parameter value for the
subroutine to be called. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L50-L157 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _addf | def _addf(ins):
''' Adds 2 float values. The result is pushed onto the stack.
'''
op1, op2 = tuple(ins.quad[2:])
if _f_ops(op1, op2) is not None:
opa, opb = _f_ops(op1, op2)
if opb == 0: # A + 0 => A
output = _float_oper(opa)
output.extend(_fpush())
return output
output = _float_oper(op1, op2)
output.append('call __ADDF')
output.extend(_fpush())
REQUIRES.add('addf.asm')
return output | python | def _addf(ins):
''' Adds 2 float values. The result is pushed onto the stack.
'''
op1, op2 = tuple(ins.quad[2:])
if _f_ops(op1, op2) is not None:
opa, opb = _f_ops(op1, op2)
if opb == 0: # A + 0 => A
output = _float_oper(opa)
output.extend(_fpush())
return output
output = _float_oper(op1, op2)
output.append('call __ADDF')
output.extend(_fpush())
REQUIRES.add('addf.asm')
return output | Adds 2 float values. The result is pushed onto the stack. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L164-L180 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _divf | def _divf(ins):
''' Divides 2 float values. The result is pushed onto the stack.
'''
op1, op2 = tuple(ins.quad[2:])
if is_float(op2) and float(op2) == 1: # Nothing to do. A / 1 = A
output = _float_oper(op1)
output.extend(_fpush())
return output
output = _float_oper(op1, op2)
output.append('call __DIVF')
output.extend(_fpush())
REQUIRES.add('divf.asm')
return output | python | def _divf(ins):
''' Divides 2 float values. The result is pushed onto the stack.
'''
op1, op2 = tuple(ins.quad[2:])
if is_float(op2) and float(op2) == 1: # Nothing to do. A / 1 = A
output = _float_oper(op1)
output.extend(_fpush())
return output
output = _float_oper(op1, op2)
output.append('call __DIVF')
output.extend(_fpush())
REQUIRES.add('divf.asm')
return output | Divides 2 float values. The result is pushed onto the stack. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L219-L233 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _modf | def _modf(ins):
''' Reminder of div. 2 float values. The result is pushed onto the stack.
'''
op1, op2 = tuple(ins.quad[2:])
output = _float_oper(op1, op2)
output.append('call __MODF')
output.extend(_fpush())
REQUIRES.add('modf.asm')
return output | python | def _modf(ins):
''' Reminder of div. 2 float values. The result is pushed onto the stack.
'''
op1, op2 = tuple(ins.quad[2:])
output = _float_oper(op1, op2)
output.append('call __MODF')
output.extend(_fpush())
REQUIRES.add('modf.asm')
return output | Reminder of div. 2 float values. The result is pushed onto the stack. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L236-L244 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _ltf | def _ltf(ins):
''' Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
Floating Point version
'''
op1, op2 = tuple(ins.quad[2:])
output = _float_oper(op1, op2)
output.append('call __LTF')
output.append('push af')
REQUIRES.add('ltf.asm')
return output | python | def _ltf(ins):
''' Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
Floating Point version
'''
op1, op2 = tuple(ins.quad[2:])
output = _float_oper(op1, op2)
output.append('call __LTF')
output.append('push af')
REQUIRES.add('ltf.asm')
return output | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
Floating Point version | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L264-L276 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _notf | def _notf(ins):
''' Negates top of the stack (48 bits)
'''
output = _float_oper(ins.quad[2])
output.append('call __NOTF')
output.append('push af')
REQUIRES.add('notf.asm')
return output | python | def _notf(ins):
''' Negates top of the stack (48 bits)
'''
output = _float_oper(ins.quad[2])
output.append('call __NOTF')
output.append('push af')
REQUIRES.add('notf.asm')
return output | Negates top of the stack (48 bits) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L399-L406 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _negf | def _negf(ins):
''' Changes sign of top of the stack (48 bits)
'''
output = _float_oper(ins.quad[2])
output.append('call __NEGF')
output.extend(_fpush())
REQUIRES.add('negf.asm')
return output | python | def _negf(ins):
''' Changes sign of top of the stack (48 bits)
'''
output = _float_oper(ins.quad[2])
output.append('call __NEGF')
output.extend(_fpush())
REQUIRES.add('negf.asm')
return output | Changes sign of top of the stack (48 bits) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L409-L416 |
boriel/zxbasic | arch/zx48k/backend/__float.py | _absf | def _absf(ins):
''' Absolute value of top of the stack (48 bits)
'''
output = _float_oper(ins.quad[2])
output.append('res 7, e') # Just resets the sign bit!
output.extend(_fpush())
return output | python | def _absf(ins):
''' Absolute value of top of the stack (48 bits)
'''
output = _float_oper(ins.quad[2])
output.append('res 7, e') # Just resets the sign bit!
output.extend(_fpush())
return output | Absolute value of top of the stack (48 bits) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__float.py#L419-L425 |
boriel/zxbasic | asmlex.py | get_uniques | def get_uniques(l):
""" Returns a list with no repeated elements.
"""
result = []
for i in l:
if i not in result:
result.append(i)
return result | python | def get_uniques(l):
""" Returns a list with no repeated elements.
"""
result = []
for i in l:
if i not in result:
result.append(i)
return result | Returns a list with no repeated elements. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L161-L170 |
boriel/zxbasic | asmlex.py | Lexer.t_CHAR | def t_CHAR(self, t):
r"'.'" # A single char
t.value = ord(t.value[1])
t.type = 'INTEGER'
return t | python | def t_CHAR(self, t):
r"'.'" # A single char
t.value = ord(t.value[1])
t.type = 'INTEGER'
return t | r"'. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L205-L210 |
boriel/zxbasic | asmlex.py | Lexer.t_BIN | def t_BIN(self, t):
r'(%[01]+)|([01]+[bB])' # A Binary integer
# Note 00B is a 0 binary, but
# 00Bh is a 12 in hex. So this pattern must come
# after HEXA
if t.value[0] == '%':
t.value = t.value[1:] # Remove initial %
else:
t.value = t.value[:-1] # Remove last 'b'
t.value = int(t.value, 2) # Convert to decimal
t.type = 'INTEGER'
return t | python | def t_BIN(self, t):
r'(%[01]+)|([01]+[bB])' # A Binary integer
# Note 00B is a 0 binary, but
# 00Bh is a 12 in hex. So this pattern must come
# after HEXA
if t.value[0] == '%':
t.value = t.value[1:] # Remove initial %
else:
t.value = t.value[:-1] # Remove last 'b'
t.value = int(t.value, 2) # Convert to decimal
t.type = 'INTEGER'
return t | r'(%[01]+)|([01]+[bB]) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L226-L239 |
boriel/zxbasic | asmlex.py | Lexer.t_INITIAL_ID | def t_INITIAL_ID(self, t):
r'[._a-zA-Z][._a-zA-Z0-9]*([ \t]*[:])?' # Any identifier
tmp = t.value # Saves original value
if tmp[-1] == ':':
t.type = 'LABEL'
t.value = tmp[:-1].strip()
return t
t.value = tmp.upper() # Convert it to uppercase, since our internal tables uses uppercase
id_ = tmp.lower()
t.type = reserved_instructions.get(id_)
if t.type is not None:
return t
t.type = pseudo.get(id_)
if t.type is not None:
return t
t.type = regs8.get(id_)
if t.type is not None:
return t
t.type = flags.get(id_)
if t.type is not None:
return t
t.type = regs16.get(id_, 'ID')
if t.type == 'ID':
t.value = tmp # Restores original value
return t | python | def t_INITIAL_ID(self, t):
r'[._a-zA-Z][._a-zA-Z0-9]*([ \t]*[:])?' # Any identifier
tmp = t.value # Saves original value
if tmp[-1] == ':':
t.type = 'LABEL'
t.value = tmp[:-1].strip()
return t
t.value = tmp.upper() # Convert it to uppercase, since our internal tables uses uppercase
id_ = tmp.lower()
t.type = reserved_instructions.get(id_)
if t.type is not None:
return t
t.type = pseudo.get(id_)
if t.type is not None:
return t
t.type = regs8.get(id_)
if t.type is not None:
return t
t.type = flags.get(id_)
if t.type is not None:
return t
t.type = regs16.get(id_, 'ID')
if t.type == 'ID':
t.value = tmp # Restores original value
return t | r'[._a-zA-Z][._a-zA-Z0-9]*([ \t]*[:])? | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L246-L278 |
boriel/zxbasic | asmlex.py | Lexer.t_preproc_ID | def t_preproc_ID(self, t):
r'[_a-zA-Z][_a-zA-Z0-9]*' # preprocessor directives
t.type = preprocessor.get(t.value.lower(), 'ID')
return t | python | def t_preproc_ID(self, t):
r'[_a-zA-Z][_a-zA-Z0-9]*' # preprocessor directives
t.type = preprocessor.get(t.value.lower(), 'ID')
return t | r'[_a-zA-Z][_a-zA-Z0-9]* | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L280-L283 |
boriel/zxbasic | asmlex.py | Lexer.t_LP | def t_LP(self, t):
r'[[(]'
if t.value != '[' and OPTIONS.bracket.value:
t.type = 'LPP'
return t | python | def t_LP(self, t):
r'[[(]'
if t.value != '[' and OPTIONS.bracket.value:
t.type = 'LPP'
return t | r'[[(] | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L293-L297 |
boriel/zxbasic | asmlex.py | Lexer.t_RP | def t_RP(self, t):
r'[])]'
if t.value != ']' and OPTIONS.bracket.value:
t.type = 'RPP'
return t | python | def t_RP(self, t):
r'[])]'
if t.value != ']' and OPTIONS.bracket.value:
t.type = 'RPP'
return t | r'[])] | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L299-L303 |
boriel/zxbasic | asmlex.py | Lexer.t_INITIAL_preproc_NEWLINE | def t_INITIAL_preproc_NEWLINE(self, t):
r'\r?\n'
t.lexer.lineno += 1
t.lexer.begin('INITIAL')
return t | python | def t_INITIAL_preproc_NEWLINE(self, t):
r'\r?\n'
t.lexer.lineno += 1
t.lexer.begin('INITIAL')
return t | r'\r?\n | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L371-L375 |
boriel/zxbasic | asmlex.py | Lexer.t_INITIAL_SHARP | def t_INITIAL_SHARP(self, t):
r'\#'
if self.find_column(t) == 1:
t.lexer.begin('preproc')
else:
self.t_INITIAL_preproc_error(t) | python | def t_INITIAL_SHARP(self, t):
r'\#'
if self.find_column(t) == 1:
t.lexer.begin('preproc')
else:
self.t_INITIAL_preproc_error(t) | r'\# | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L377-L383 |
boriel/zxbasic | asmlex.py | Lexer.input | def input(self, str):
""" Defines input string, removing current lexer.
"""
self.input_data = str
self.lex = lex.lex(object=self)
self.lex.input(self.input_data) | python | def input(self, str):
""" Defines input string, removing current lexer.
"""
self.input_data = str
self.lex = lex.lex(object=self)
self.lex.input(self.input_data) | Defines input string, removing current lexer. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmlex.py#L402-L407 |
boriel/zxbasic | symbols/argument.py | SymbolARGUMENT.typecast | def typecast(self, type_):
""" Test type casting to the argument expression.
On success changes the node value to the new typecast, and returns
True. On failure, returns False, and the node value is set to None.
"""
self.value = SymbolTYPECAST.make_node(type_, self.value, self.lineno)
return self.value is not None | python | def typecast(self, type_):
""" Test type casting to the argument expression.
On success changes the node value to the new typecast, and returns
True. On failure, returns False, and the node value is set to None.
"""
self.value = SymbolTYPECAST.make_node(type_, self.value, self.lineno)
return self.value is not None | Test type casting to the argument expression.
On success changes the node value to the new typecast, and returns
True. On failure, returns False, and the node value is set to None. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/argument.py#L88-L94 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _paddr | def _paddr(offset):
''' Generic array address parameter loading.
Emmits output code for setting IX at the right location.
bytes = Number of bytes to load:
1 => 8 bit value
2 => 16 bit value / string
4 => 32 bit value / f16 value
5 => 40 bit value
'''
output = []
indirect = offset[0] == '*'
if indirect:
offset = offset[1:]
I = int(offset)
if I >= 0:
I += 4 # Return Address + "push IX"
output.append('push ix')
output.append('pop hl')
output.append('ld de, %i' % I)
output.append('add hl, de')
if indirect:
output.append('ld c, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, c')
output.append('call __ARRAY')
REQUIRES.add('array.asm')
return output | python | def _paddr(offset):
''' Generic array address parameter loading.
Emmits output code for setting IX at the right location.
bytes = Number of bytes to load:
1 => 8 bit value
2 => 16 bit value / string
4 => 32 bit value / f16 value
5 => 40 bit value
'''
output = []
indirect = offset[0] == '*'
if indirect:
offset = offset[1:]
I = int(offset)
if I >= 0:
I += 4 # Return Address + "push IX"
output.append('push ix')
output.append('pop hl')
output.append('ld de, %i' % I)
output.append('add hl, de')
if indirect:
output.append('ld c, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, c')
output.append('call __ARRAY')
REQUIRES.add('array.asm')
return output | Generic array address parameter loading.
Emmits output code for setting IX at the right location.
bytes = Number of bytes to load:
1 => 8 bit value
2 => 16 bit value / string
4 => 32 bit value / f16 value
5 => 40 bit value | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L18-L50 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _paload8 | def _paload8(ins):
''' Loads an 8 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('ld a, (hl)')
output.append('push af')
return output | python | def _paload8(ins):
''' Loads an 8 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('ld a, (hl)')
output.append('push af')
return output | Loads an 8 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L62-L71 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _paload16 | def _paload16(ins):
''' Loads a 16 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('ld e, (hl)')
output.append('inc hl')
output.append('ld d, (hl)')
output.append('ex de, hl')
output.append('push hl')
return output | python | def _paload16(ins):
''' Loads a 16 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('ld e, (hl)')
output.append('inc hl')
output.append('ld d, (hl)')
output.append('ex de, hl')
output.append('push hl')
return output | Loads a 16 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L74-L87 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _paload32 | def _paload32(ins):
''' Load a 32 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
REQUIRES.add('iload32.asm')
return output | python | def _paload32(ins):
''' Load a 32 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('call __ILOAD32')
output.append('push de')
output.append('push hl')
REQUIRES.add('iload32.asm')
return output | Load a 32 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L90-L103 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _paloadf | def _paloadf(ins):
''' Loads a floating point value from a memory address.
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('call __ILOADF')
output.extend(_fpush())
REQUIRES.add('iloadf.asm')
return output | python | def _paloadf(ins):
''' Loads a floating point value from a memory address.
If 2nd arg. start with '*', it is always treated as
an indirect value.
'''
output = _paddr(ins.quad[2])
output.append('call __ILOADF')
output.extend(_fpush())
REQUIRES.add('iloadf.asm')
return output | Loads a floating point value from a memory address.
If 2nd arg. start with '*', it is always treated as
an indirect value. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L106-L117 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _paloadstr | def _paloadstr(ins):
''' Loads a string value from a memory address.
'''
output = _paddr(ins.quad[2])
output.append('call __ILOADSTR')
output.append('push hl')
REQUIRES.add('loadstr.asm')
return output | python | def _paloadstr(ins):
''' Loads a string value from a memory address.
'''
output = _paddr(ins.quad[2])
output.append('call __ILOADSTR')
output.append('push hl')
REQUIRES.add('loadstr.asm')
return output | Loads a string value from a memory address. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L120-L129 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _pastore8 | def _pastore8(ins):
''' Stores 2º operand content into address of 1st operand.
1st operand is an array element. Dimensions are pushed into the
stack.
Use '*' for indirect store on 1st operand (A pointer to an array)
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFF
if indirect:
output.append('ld a, (%i)' % value)
output.append('ld (hl), a')
else:
value &= 0xFF
output.append('ld (hl), %i' % value)
except ValueError:
output.append('pop af')
output.append('ld (hl), a')
return output | python | def _pastore8(ins):
''' Stores 2º operand content into address of 1st operand.
1st operand is an array element. Dimensions are pushed into the
stack.
Use '*' for indirect store on 1st operand (A pointer to an array)
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFF
if indirect:
output.append('ld a, (%i)' % value)
output.append('ld (hl), a')
else:
value &= 0xFF
output.append('ld (hl), %i' % value)
except ValueError:
output.append('pop af')
output.append('ld (hl), a')
return output | Stores 2º operand content into address of 1st operand.
1st operand is an array element. Dimensions are pushed into the
stack.
Use '*' for indirect store on 1st operand (A pointer to an array) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L132-L159 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _pastore16 | def _pastore16(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand.
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFF
output.append('ld de, %i' % value)
if indirect:
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
except ValueError:
output.append('pop de')
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
return output | python | def _pastore16(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand.
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFF
output.append('ld de, %i' % value)
if indirect:
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
except ValueError:
output.append('pop de')
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
return output | Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L162-L190 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _pastore32 | def _pastore32(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFFFFFF # Immediate?
if indirect:
output.append('push hl')
output.append('ld hl, %i' % (value & 0xFFFF))
output.append('call __ILOAD32')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
output.append('ld de, %i' % (value >> 16))
output.append('ld bc, %i' % (value & 0xFFFF))
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | python | def _pastore32(ins):
''' Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
value = int(ins.quad[2]) & 0xFFFFFFFF # Immediate?
if indirect:
output.append('push hl')
output.append('ld hl, %i' % (value & 0xFFFF))
output.append('call __ILOAD32')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
output.append('ld de, %i' % (value >> 16))
output.append('ld bc, %i' % (value & 0xFFFF))
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L193-L226 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _pastoref16 | def _pastoref16(ins):
''' Stores 2º operand content into address of 1st operand.
storef16 a, x => *(&a) = x
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
if indirect:
value = int(ins.quad[2])
output.append('push hl')
output.append('ld hl, %i' % (value & 0xFFFF))
output.append('call __ILOAD32')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
de, hl = f16(value)
output.append('ld de, %i' % de)
output.append('ld bc, %i' % hl)
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | python | def _pastoref16(ins):
''' Stores 2º operand content into address of 1st operand.
storef16 a, x => *(&a) = x
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
if indirect:
value = int(ins.quad[2])
output.append('push hl')
output.append('ld hl, %i' % (value & 0xFFFF))
output.append('call __ILOAD32')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits
output.append('pop hl')
REQUIRES.add('iload32.asm')
else:
de, hl = f16(value)
output.append('ld de, %i' % de)
output.append('ld bc, %i' % hl)
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | Stores 2º operand content into address of 1st operand.
storef16 a, x => *(&a) = x | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L229-L263 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _pastoref | def _pastoref(ins):
''' Stores a floating point value into a memory address.
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
if indirect:
value = int(value) & 0xFFFF # Inmediate?
output.append('push hl')
output.append('ld hl, %i' % value)
output.append('call __ILOADF')
output.append('ld a, c')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits, A = Exp
output.append('pop hl') # Recovers pointer
REQUIRES.add('iloadf.asm')
else:
value = float(value) # Inmediate?
C, DE, HL = fp.immediate_float(value) # noqa TODO: it will fail
output.append('ld a, %s' % C)
output.append('ld de, %s' % DE)
output.append('ld bc, %s' % HL)
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('ex (sp), hl') # Preserve HL for STOREF
output.append('ld a, l')
output.append('pop hl')
output.append('call __STOREF')
REQUIRES.add('storef.asm')
return output | python | def _pastoref(ins):
''' Stores a floating point value into a memory address.
'''
output = _paddr(ins.quad[1])
value = ins.quad[2]
if value[0] == '*':
value = value[1:]
indirect = True
else:
indirect = False
try:
if indirect:
value = int(value) & 0xFFFF # Inmediate?
output.append('push hl')
output.append('ld hl, %i' % value)
output.append('call __ILOADF')
output.append('ld a, c')
output.append('ld b, h')
output.append('ld c, l') # BC = Lower 16 bits, A = Exp
output.append('pop hl') # Recovers pointer
REQUIRES.add('iloadf.asm')
else:
value = float(value) # Inmediate?
C, DE, HL = fp.immediate_float(value) # noqa TODO: it will fail
output.append('ld a, %s' % C)
output.append('ld de, %s' % DE)
output.append('ld bc, %s' % HL)
except ValueError:
output.append('pop bc')
output.append('pop de')
output.append('ex (sp), hl') # Preserve HL for STOREF
output.append('ld a, l')
output.append('pop hl')
output.append('call __STOREF')
REQUIRES.add('storef.asm')
return output | Stores a floating point value into a memory address. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L266-L305 |
boriel/zxbasic | arch/zx48k/backend/__parray.py | _pastorestr | def _pastorestr(ins):
''' Stores a string value into a memory address.
It copies content of 2nd operand (string), into 1st, reallocating
dynamic memory for the 1st str. These instruction DOES ALLOW
inmediate strings for the 2nd parameter, starting with '#'.
'''
output = _paddr(ins.quad[1])
temporal = False
value = ins.quad[2]
indirect = value[0] == '*'
if indirect:
value = value[1:]
immediate = value[0]
if immediate:
value = value[1:]
if value[0] == '_':
if indirect:
if immediate:
output.append('ld de, (%s)' % value)
else:
output.append('ld de, (%s)' % value)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
if immediate:
output.append('ld de, %s' % value)
else:
output.append('ld de, (%s)' % value)
else:
output.append('pop de')
temporal = True
if indirect:
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
if not temporal:
output.append('call __STORE_STR')
REQUIRES.add('storestr.asm')
else: # A value already on dynamic memory
output.append('call __STORE_STR2')
REQUIRES.add('storestr2.asm')
return output | python | def _pastorestr(ins):
''' Stores a string value into a memory address.
It copies content of 2nd operand (string), into 1st, reallocating
dynamic memory for the 1st str. These instruction DOES ALLOW
inmediate strings for the 2nd parameter, starting with '#'.
'''
output = _paddr(ins.quad[1])
temporal = False
value = ins.quad[2]
indirect = value[0] == '*'
if indirect:
value = value[1:]
immediate = value[0]
if immediate:
value = value[1:]
if value[0] == '_':
if indirect:
if immediate:
output.append('ld de, (%s)' % value)
else:
output.append('ld de, (%s)' % value)
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
else:
if immediate:
output.append('ld de, %s' % value)
else:
output.append('ld de, (%s)' % value)
else:
output.append('pop de')
temporal = True
if indirect:
output.append('call __LOAD_DE_DE')
REQUIRES.add('lddede.asm')
if not temporal:
output.append('call __STORE_STR')
REQUIRES.add('storestr.asm')
else: # A value already on dynamic memory
output.append('call __STORE_STR2')
REQUIRES.add('storestr2.asm')
return output | Stores a string value into a memory address.
It copies content of 2nd operand (string), into 1st, reallocating
dynamic memory for the 1st str. These instruction DOES ALLOW
inmediate strings for the 2nd parameter, starting with '#'. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__parray.py#L308-L354 |
boriel/zxbasic | asm.py | num2bytes | def num2bytes(x, bytes):
""" Returns x converted to a little-endian t-uple of bytes.
E.g. num2bytes(255, 4) = (255, 0, 0, 0)
"""
if not isinstance(x, int): # If it is another "thing", just return ZEROs
return tuple([0] * bytes)
x = x & ((2 << (bytes * 8)) - 1) # mask the initial value
result = ()
for i in range(bytes):
result += (x & 0xFF,)
x >>= 8
return result | python | def num2bytes(x, bytes):
""" Returns x converted to a little-endian t-uple of bytes.
E.g. num2bytes(255, 4) = (255, 0, 0, 0)
"""
if not isinstance(x, int): # If it is another "thing", just return ZEROs
return tuple([0] * bytes)
x = x & ((2 << (bytes * 8)) - 1) # mask the initial value
result = ()
for i in range(bytes):
result += (x & 0xFF,)
x >>= 8
return result | Returns x converted to a little-endian t-uple of bytes.
E.g. num2bytes(255, 4) = (255, 0, 0, 0) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asm.py#L23-L37 |
boriel/zxbasic | asm.py | AsmInstruction.argval | def argval(self):
""" Returns the value of the arg (if any) or None.
If the arg. is not an integer, an error be triggered.
"""
if self.arg is None or any(x is None for x in self.arg):
return None
for x in self.arg:
if not isinstance(x, int):
raise InvalidArgError(self.arg)
return self.arg | python | def argval(self):
""" Returns the value of the arg (if any) or None.
If the arg. is not an integer, an error be triggered.
"""
if self.arg is None or any(x is None for x in self.arg):
return None
for x in self.arg:
if not isinstance(x, int):
raise InvalidArgError(self.arg)
return self.arg | Returns the value of the arg (if any) or None.
If the arg. is not an integer, an error be triggered. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asm.py#L115-L126 |
boriel/zxbasic | asm.py | AsmInstruction.bytes | def bytes(self):
""" Returns a t-uple with instruction bytes (integers)
"""
result = []
op = self.opcode.split(' ')
argi = 0
while op:
q = op.pop(0)
if q == 'XX':
for k in range(self.argbytes[argi] - 1):
op.pop(0)
result.extend(num2bytes(self.argval()[argi], self.argbytes[argi]))
argi += 1
else:
result.append(int(q, 16)) # Add opcode
if len(result) != self.size:
raise InternalMismatchSizeError(len(result), self)
return result | python | def bytes(self):
""" Returns a t-uple with instruction bytes (integers)
"""
result = []
op = self.opcode.split(' ')
argi = 0
while op:
q = op.pop(0)
if q == 'XX':
for k in range(self.argbytes[argi] - 1):
op.pop(0)
result.extend(num2bytes(self.argval()[argi], self.argbytes[argi]))
argi += 1
else:
result.append(int(q, 16)) # Add opcode
if len(result) != self.size:
raise InternalMismatchSizeError(len(result), self)
return result | Returns a t-uple with instruction bytes (integers) | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asm.py#L128-L150 |
boriel/zxbasic | api/errmsg.py | syntax_error | def syntax_error(lineno, msg):
""" Generic syntax error routine
"""
if global_.has_errors > OPTIONS.max_syntax_errors.value:
msg = 'Too many errors. Giving up!'
msg = "%s:%i: %s" % (global_.FILENAME, lineno, msg)
msg_output(msg)
if global_.has_errors > OPTIONS.max_syntax_errors.value:
sys.exit(1)
global_.has_errors += 1 | python | def syntax_error(lineno, msg):
""" Generic syntax error routine
"""
if global_.has_errors > OPTIONS.max_syntax_errors.value:
msg = 'Too many errors. Giving up!'
msg = "%s:%i: %s" % (global_.FILENAME, lineno, msg)
msg_output(msg)
if global_.has_errors > OPTIONS.max_syntax_errors.value:
sys.exit(1)
global_.has_errors += 1 | Generic syntax error routine | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/api/errmsg.py#L28-L40 |
boriel/zxbasic | api/errmsg.py | warning | def warning(lineno, msg):
""" Generic warning error routine
"""
msg = "%s:%i: warning: %s" % (global_.FILENAME, lineno, msg)
msg_output(msg)
global_.has_warnings += 1 | python | def warning(lineno, msg):
""" Generic warning error routine
"""
msg = "%s:%i: warning: %s" % (global_.FILENAME, lineno, msg)
msg_output(msg)
global_.has_warnings += 1 | Generic warning error routine | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/api/errmsg.py#L43-L48 |
boriel/zxbasic | api/errmsg.py | warning_implicit_type | def warning_implicit_type(lineno, id_, type_=None):
""" Warning: Using default implicit type 'x'
"""
if OPTIONS.strict.value:
syntax_error_undeclared_type(lineno, id_)
return
if type_ is None:
type_ = global_.DEFAULT_TYPE
warning(lineno, "Using default implicit type '%s' for '%s'" % (type_, id_)) | python | def warning_implicit_type(lineno, id_, type_=None):
""" Warning: Using default implicit type 'x'
"""
if OPTIONS.strict.value:
syntax_error_undeclared_type(lineno, id_)
return
if type_ is None:
type_ = global_.DEFAULT_TYPE
warning(lineno, "Using default implicit type '%s' for '%s'" % (type_, id_)) | Warning: Using default implicit type 'x' | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/api/errmsg.py#L51-L61 |
boriel/zxbasic | arch/zx48k/optimizer.py | oper | def oper(inst):
""" Returns operands of an ASM instruction.
Even "indirect" operands, like SP if RET or CALL is used.
"""
i = inst.strip(' \t\n').split(' ')
I = i[0].lower() # Instruction
i = ''.join(i[1:])
op = i.split(',')
if I in {'call', 'jp', 'jr'} and len(op) > 1:
op = op[1:] + ['f']
elif I == 'djnz':
op.append('b')
elif I in {'push', 'pop', 'call'}:
op.append('sp') # Sp is also affected by push, pop and call
elif I in {'or', 'and', 'xor', 'neg', 'cpl', 'rrca', 'rlca'}:
op.append('a')
elif I in {'rra', 'rla'}:
op.extend(['a', 'f'])
elif I in ('rr', 'rl'):
op.append('f')
elif I in {'adc', 'sbc'}:
if len(op) == 1:
op = ['a', 'f'] + op
elif I in {'add', 'sub'}:
if len(op) == 1:
op = ['a'] + op
elif I in {'ldd', 'ldi', 'lddr', 'ldir'}:
op = ['hl', 'de', 'bc']
elif I in {'cpd', 'cpi', 'cpdr', 'cpir'}:
op = ['a', 'hl', 'bc']
elif I == 'exx':
op = ['*', 'bc', 'de', 'hl', 'b', 'c', 'd', 'e', 'h', 'l']
elif I in {'ret', 'reti', 'retn'}:
op += ['sp']
elif I == 'out':
if len(op) and RE_OUTC.match(op[0]):
op[0] = 'c'
else:
op.pop(0)
elif I == 'in':
if len(op) > 1 and RE_OUTC.match(op[1]):
op[1] = 'c'
else:
op.pop(1)
for i in range(len(op)):
tmp = RE_INDIR16.match(op[i])
if tmp is not None:
op[i] = '(' + op[i].strip()[1:-1].strip().lower() + ')' # ' ( dE ) ' => '(de)'
return op | python | def oper(inst):
""" Returns operands of an ASM instruction.
Even "indirect" operands, like SP if RET or CALL is used.
"""
i = inst.strip(' \t\n').split(' ')
I = i[0].lower() # Instruction
i = ''.join(i[1:])
op = i.split(',')
if I in {'call', 'jp', 'jr'} and len(op) > 1:
op = op[1:] + ['f']
elif I == 'djnz':
op.append('b')
elif I in {'push', 'pop', 'call'}:
op.append('sp') # Sp is also affected by push, pop and call
elif I in {'or', 'and', 'xor', 'neg', 'cpl', 'rrca', 'rlca'}:
op.append('a')
elif I in {'rra', 'rla'}:
op.extend(['a', 'f'])
elif I in ('rr', 'rl'):
op.append('f')
elif I in {'adc', 'sbc'}:
if len(op) == 1:
op = ['a', 'f'] + op
elif I in {'add', 'sub'}:
if len(op) == 1:
op = ['a'] + op
elif I in {'ldd', 'ldi', 'lddr', 'ldir'}:
op = ['hl', 'de', 'bc']
elif I in {'cpd', 'cpi', 'cpdr', 'cpir'}:
op = ['a', 'hl', 'bc']
elif I == 'exx':
op = ['*', 'bc', 'de', 'hl', 'b', 'c', 'd', 'e', 'h', 'l']
elif I in {'ret', 'reti', 'retn'}:
op += ['sp']
elif I == 'out':
if len(op) and RE_OUTC.match(op[0]):
op[0] = 'c'
else:
op.pop(0)
elif I == 'in':
if len(op) > 1 and RE_OUTC.match(op[1]):
op[1] = 'c'
else:
op.pop(1)
for i in range(len(op)):
tmp = RE_INDIR16.match(op[i])
if tmp is not None:
op[i] = '(' + op[i].strip()[1:-1].strip().lower() + ')' # ' ( dE ) ' => '(de)'
return op | Returns operands of an ASM instruction.
Even "indirect" operands, like SP if RET or CALL is used. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L190-L254 |
boriel/zxbasic | arch/zx48k/optimizer.py | condition | def condition(i):
""" Returns the flag this instruction uses
or None. E.g. 'c' for Carry, 'nz' for not-zero, etc.
That is the condition required for this instruction
to execute. For example: ADC A, 0 does NOT have a
condition flag (it always execute) whilst RETC does.
"""
I = inst(i)
if I not in {'call', 'jp', 'jr', 'ret'}:
return None # This instruction always execute
if I == 'ret':
i = [x.lower() for x in i.split(' ') if x != '']
return i[1] if len(i) > 1 else None
i = [x.strip() for x in i.split(',')]
i = [x.lower() for x in i[0].split(' ') if x != '']
if len(i) > 1 and i[1] in {'c', 'nc', 'z', 'nz', 'po', 'pe', 'p', 'm'}:
return i[1]
return None | python | def condition(i):
""" Returns the flag this instruction uses
or None. E.g. 'c' for Carry, 'nz' for not-zero, etc.
That is the condition required for this instruction
to execute. For example: ADC A, 0 does NOT have a
condition flag (it always execute) whilst RETC does.
"""
I = inst(i)
if I not in {'call', 'jp', 'jr', 'ret'}:
return None # This instruction always execute
if I == 'ret':
i = [x.lower() for x in i.split(' ') if x != '']
return i[1] if len(i) > 1 else None
i = [x.strip() for x in i.split(',')]
i = [x.lower() for x in i[0].split(' ') if x != '']
if len(i) > 1 and i[1] in {'c', 'nc', 'z', 'nz', 'po', 'pe', 'p', 'm'}:
return i[1]
return None | Returns the flag this instruction uses
or None. E.g. 'c' for Carry, 'nz' for not-zero, etc.
That is the condition required for this instruction
to execute. For example: ADC A, 0 does NOT have a
condition flag (it always execute) whilst RETC does. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L262-L283 |
boriel/zxbasic | arch/zx48k/optimizer.py | single_registers | def single_registers(op):
""" Given a list of registers like ['a', 'bc', 'h', 'hl'] returns
a set of single registers: ['a', 'b', 'c', 'h', 'l'].
Non register parameters, like numbers will be ignored.
"""
result = set()
if isinstance(op, str):
op = [op]
for x in op:
if is_8bit_register(x):
result = result.union([x])
elif x == 'sp':
result.add(x)
elif x == 'af':
result = result.union(['a', 'f'])
elif x == "af'":
result = result.union(["a'", "f'"])
elif is_16bit_register(x): # Must be a 16bit reg or we have an internal error!
result = result.union([LO16(x), HI16(x)])
return list(result) | python | def single_registers(op):
""" Given a list of registers like ['a', 'bc', 'h', 'hl'] returns
a set of single registers: ['a', 'b', 'c', 'h', 'l'].
Non register parameters, like numbers will be ignored.
"""
result = set()
if isinstance(op, str):
op = [op]
for x in op:
if is_8bit_register(x):
result = result.union([x])
elif x == 'sp':
result.add(x)
elif x == 'af':
result = result.union(['a', 'f'])
elif x == "af'":
result = result.union(["a'", "f'"])
elif is_16bit_register(x): # Must be a 16bit reg or we have an internal error!
result = result.union([LO16(x), HI16(x)])
return list(result) | Given a list of registers like ['a', 'bc', 'h', 'hl'] returns
a set of single registers: ['a', 'b', 'c', 'h', 'l'].
Non register parameters, like numbers will be ignored. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L286-L307 |
boriel/zxbasic | arch/zx48k/optimizer.py | result | def result(i):
""" Returns which 8-bit registers are used by an asm
instruction to return a result.
"""
ins = inst(i)
op = oper(i)
if ins in ('or', 'and') and op == ['a']:
return ['f']
if ins in {'xor', 'or', 'and', 'neg', 'cpl', 'daa', 'rld', 'rrd', 'rra', 'rla', 'rrca', 'rlca'}:
return ['a', 'f']
if ins in {'bit', 'cp', 'scf', 'ccf'}:
return ['f']
if ins in {'sub', 'add', 'sbc', 'adc'}:
if len(op) == 1:
return ['a', 'f']
else:
return single_registers(op[0]) + ['f']
if ins == 'djnz':
return ['b', 'f']
if ins in {'ldir', 'ldi', 'lddr', 'ldd'}:
return ['f', 'b', 'c', 'd', 'e', 'h', 'l']
if ins in {'cpi', 'cpir', 'cpd', 'cpdr'}:
return ['f', 'b', 'c', 'h', 'l']
if ins in ('pop', 'ld'):
return single_registers(op[0])
if ins in {'inc', 'dec', 'sbc', 'rr', 'rl', 'rrc', 'rlc'}:
return ['f'] + single_registers(op[0])
if ins in ('set', 'res'):
return single_registers(op[1])
return [] | python | def result(i):
""" Returns which 8-bit registers are used by an asm
instruction to return a result.
"""
ins = inst(i)
op = oper(i)
if ins in ('or', 'and') and op == ['a']:
return ['f']
if ins in {'xor', 'or', 'and', 'neg', 'cpl', 'daa', 'rld', 'rrd', 'rra', 'rla', 'rrca', 'rlca'}:
return ['a', 'f']
if ins in {'bit', 'cp', 'scf', 'ccf'}:
return ['f']
if ins in {'sub', 'add', 'sbc', 'adc'}:
if len(op) == 1:
return ['a', 'f']
else:
return single_registers(op[0]) + ['f']
if ins == 'djnz':
return ['b', 'f']
if ins in {'ldir', 'ldi', 'lddr', 'ldd'}:
return ['f', 'b', 'c', 'd', 'e', 'h', 'l']
if ins in {'cpi', 'cpir', 'cpd', 'cpdr'}:
return ['f', 'b', 'c', 'h', 'l']
if ins in ('pop', 'ld'):
return single_registers(op[0])
if ins in {'inc', 'dec', 'sbc', 'rr', 'rl', 'rrc', 'rlc'}:
return ['f'] + single_registers(op[0])
if ins in ('set', 'res'):
return single_registers(op[1])
return [] | Returns which 8-bit registers are used by an asm
instruction to return a result. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L310-L350 |
boriel/zxbasic | arch/zx48k/optimizer.py | block_partition | def block_partition(block, i):
""" Returns two blocks, as a result of partitioning the given one at
i-th instruction.
"""
i += 1
new_block = BasicBlock(block.asm[i:])
block.mem = block.mem[:i]
block.asm = block.asm[:i]
block.update_labels()
new_block.update_labels()
new_block.goes_to = block.goes_to
block.goes_to = IdentitySet()
new_block.label_goes = block.label_goes
block.label_goes = []
new_block.next = new_block.original_next = block.original_next
new_block.prev = block
new_block.add_comes_from(block)
if new_block.next is not None:
new_block.next.prev = new_block
new_block.next.add_comes_from(new_block)
new_block.next.delete_from(block)
block.next = block.original_next = new_block
block.update_next_block()
block.add_goes_to(new_block)
return block, new_block | python | def block_partition(block, i):
""" Returns two blocks, as a result of partitioning the given one at
i-th instruction.
"""
i += 1
new_block = BasicBlock(block.asm[i:])
block.mem = block.mem[:i]
block.asm = block.asm[:i]
block.update_labels()
new_block.update_labels()
new_block.goes_to = block.goes_to
block.goes_to = IdentitySet()
new_block.label_goes = block.label_goes
block.label_goes = []
new_block.next = new_block.original_next = block.original_next
new_block.prev = block
new_block.add_comes_from(block)
if new_block.next is not None:
new_block.next.prev = new_block
new_block.next.add_comes_from(new_block)
new_block.next.delete_from(block)
block.next = block.original_next = new_block
block.update_next_block()
block.add_goes_to(new_block)
return block, new_block | Returns two blocks, as a result of partitioning the given one at
i-th instruction. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L2060-L2090 |
boriel/zxbasic | arch/zx48k/optimizer.py | partition_block | def partition_block(block):
""" If a block is not partitionable, returns a list with the same block.
Otherwise, returns a list with the resulting blocks, recursively.
"""
result = [block]
if not block.is_partitionable:
return result
EDP = END_PROGRAM_LABEL + ':'
for i in range(len(block) - 1):
if i and block.asm[i] == EDP: # END_PROGRAM label always starts a basic block
block, new_block = block_partition(block, i - 1)
LABELS[END_PROGRAM_LABEL].basic_block = new_block
result.extend(partition_block(new_block))
return result
if block.mem[i].is_ender:
block, new_block = block_partition(block, i)
result.extend(partition_block(new_block))
op = block.mem[i].opers
for l in op:
if l in LABELS.keys():
JUMP_LABELS.add(l)
block.label_goes += [l]
return result
if block.asm[i] in arch.zx48k.backend.ASMS:
if i > 0:
block, new_block = block_partition(block, i - 1)
result.extend(partition_block(new_block))
return result
block, new_block = block_partition(block, i)
result.extend(partition_block(new_block))
return result
for label in JUMP_LABELS:
must_partition = False
if LABELS[label].basic_block is block:
for i in range(len(block)):
cell = block.mem[i]
if cell.inst == label:
break
if cell.is_label:
continue
if cell.is_ender:
continue
must_partition = True
if must_partition:
block, new_block = block_partition(block, i - 1)
LABELS[label].basic_block = new_block
result.extend(partition_block(new_block))
return result
return result | python | def partition_block(block):
""" If a block is not partitionable, returns a list with the same block.
Otherwise, returns a list with the resulting blocks, recursively.
"""
result = [block]
if not block.is_partitionable:
return result
EDP = END_PROGRAM_LABEL + ':'
for i in range(len(block) - 1):
if i and block.asm[i] == EDP: # END_PROGRAM label always starts a basic block
block, new_block = block_partition(block, i - 1)
LABELS[END_PROGRAM_LABEL].basic_block = new_block
result.extend(partition_block(new_block))
return result
if block.mem[i].is_ender:
block, new_block = block_partition(block, i)
result.extend(partition_block(new_block))
op = block.mem[i].opers
for l in op:
if l in LABELS.keys():
JUMP_LABELS.add(l)
block.label_goes += [l]
return result
if block.asm[i] in arch.zx48k.backend.ASMS:
if i > 0:
block, new_block = block_partition(block, i - 1)
result.extend(partition_block(new_block))
return result
block, new_block = block_partition(block, i)
result.extend(partition_block(new_block))
return result
for label in JUMP_LABELS:
must_partition = False
if LABELS[label].basic_block is block:
for i in range(len(block)):
cell = block.mem[i]
if cell.inst == label:
break
if cell.is_label:
continue
if cell.is_ender:
continue
must_partition = True
if must_partition:
block, new_block = block_partition(block, i - 1)
LABELS[label].basic_block = new_block
result.extend(partition_block(new_block))
return result
return result | If a block is not partitionable, returns a list with the same block.
Otherwise, returns a list with the resulting blocks, recursively. | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L2093-L2154 |
boriel/zxbasic | arch/zx48k/optimizer.py | get_labels | def get_labels(MEMORY, basic_block):
""" Traverses memory, to annotate all the labels in the global
LABELS table
"""
for cell in MEMORY:
if cell.is_label:
label = cell.inst
LABELS[label] = LabelInfo(label, cell.addr, basic_block) | python | def get_labels(MEMORY, basic_block):
""" Traverses memory, to annotate all the labels in the global
LABELS table
"""
for cell in MEMORY:
if cell.is_label:
label = cell.inst
LABELS[label] = LabelInfo(label, cell.addr, basic_block) | Traverses memory, to annotate all the labels in the global
LABELS table | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L2172-L2179 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.