code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
result = True # Check for functions defined after calls (parametres, etc) for id_, params, lineno in global_.FUNCTION_CALLS: result = result and check_call_arguments(lineno, id_, params) return result
def check_pending_calls()
Calls the above function for each pending call of the current scope level
19.839251
16.863346
1.176472
result = True visited = set() pending = [ast] while pending: node = pending.pop() if node is None or node in visited: # Avoid recursive infinite-loop continue visited.add(node) for x in node.children: pending.append(x) if node.tok...
def check_pending_labels(ast)
Iteratively traverses the node looking for ID with no class set, marks them as labels, and check they've been declared. This way we avoid stack overflow for high line-numbered listings.
4.580366
4.489927
1.020143
if isinstance(lbl, float): if lbl == int(lbl): id_ = str(int(lbl)) else: syntax_error(lineno, 'Line numbers must be integers.') return None else: id_ = lbl return global_.SYMBOL_TABLE.access_label(id_, lineno)
def check_and_make_label(lbl, lineno)
Checks if the given label (or line number) is valid and, if so, returns a label object. :param lbl: Line number of label (string) :param lineno: Line number in the basic source code for error reporting :return: Label object or None if error.
5.699485
5.519907
1.032533
from symbols.symbol_ import Symbol for sym in symbols: if sym is None: continue if not isinstance(sym, Symbol): return False if sym.token == 'NOP': continue if sym.token == 'BLOCK': if not is_null(*sym.children): ...
def is_null(*symbols)
True if no nodes or all the given nodes are either None, NOP or empty blocks. For blocks this applies recursively
4.033003
3.518943
1.146084
from symbols.symbol_ import Symbol assert all(isinstance(x, Symbol) for x in symbols) for sym in symbols: if sym.token != token: return False return True
def is_SYMBOL(token, *symbols)
Returns True if ALL of the given argument are AST nodes of the given token (e.g. 'BINARY')
5.439189
5.22491
1.041011
return is_SYMBOL('VAR', *p) and all(x.class_ == CLASS.const for x in p)
def is_const(*p)
A constant in the program, like CONST a = 5
18.349892
14.884018
1.232859
return all(is_CONST(x) or is_number(x) or is_const(x) for x in p)
def is_static(*p)
A static value (does not change at runtime) which is known at compile time
6.313923
7.493677
0.842567
try: for i in p: if i.token != 'NUMBER' and (i.token != 'ID' or i.class_ != CLASS.const): return False return True except: pass return False
def is_number(*p)
Returns True if ALL of the arguments are AST nodes containing NUMBER or numeric CONSTANTS
5.598751
4.876421
1.148127
from symbols.type_ import Type try: for i in p: if not i.type_.is_basic or not Type.is_unsigned(i.type_): return False return True except: pass return False
def is_unsigned(*p)
Returns false unless all types in p are unsigned
5.478511
5.368435
1.020504
try: for i in p: if i.type_ != type_: return False return True except: pass return False
def is_type(type_, *p)
True if all args have the same type
4.586682
4.084093
1.12306
for i in p: if i.scope == SCOPE.global_ and i.is_basic and \ i.type_ != Type.string: return False return True except: pass return False
def is_dynamic(*p): # TODO: Explain this better from symbols.type_ import Type try
True if all args are dynamic (e.g. Strings, dynamic arrays, etc) The use a ptr (ref) and it might change during runtime.
8.289321
7.917642
1.046943
import symbols return all(isinstance(x, symbols.FUNCTION) for x in p)
def is_callable(*p)
True if all the args are functions and / or subroutines
11.754319
10.059525
1.168477
if is_LABEL(block) and block.accessed: return True for child in block.children: if not is_callable(child) and is_block_accessed(child): return True return False
def is_block_accessed(block)
Returns True if a block is "accessed". A block of code is accessed if it has a LABEL and it is used in a GOTO, GO SUB or @address access :param block: A block of code (AST node) :return: True / False depending if it has labels accessed or not
4.327068
5.217452
0.829345
from symbols.type_ import SymbolBASICTYPE as BASICTYPE from symbols.type_ import Type as TYPE from symbols.type_ import SymbolTYPE if a is None or b is None: return None if not isinstance(a, SymbolTYPE): a = a.type_ if not isinstance(b, SymbolTYPE): b = b.type_ ...
def common_type(a, b)
Returns a type which is common for both a and b types. Returns None if no common types allowed.
4.223965
4.116961
1.025991
for m in memory: m = m.rstrip('\r\n\t ') # Ensures no trailing newlines (might with upon includes) if m and m[0] == '#': # Preprocessor directive? if ofile is None: print(m) else: ofile.write('%s\n' % m) continue # P...
def output(memory, ofile=None)
Filters the output removing useless preprocessor #directives and writes it to the given file or to the screen if no file is passed
4.536332
4.210233
1.077454
''' Returns pop sequence for 16 bits operands 1st operand in HL, 2nd operand in DE For subtraction, division, etc. you can swap operators extraction order by setting reversed to True ''' output = [] if op1 is not None: op1 = str(op1) # always to str if op2 is not None: ...
def _16bit_oper(op1, op2=None, reversed=False)
Returns pop sequence for 16 bits operands 1st operand in HL, 2nd operand in DE For subtraction, division, etc. you can swap operators extraction order by setting reversed to True
2.761564
2.208149
1.250624
''' 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 * If any of the operands is < 4, then INC is used * If any of the operands is > (65531) (-4), the...
def _add16(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 * If any of the operands is < 4, then INC is used * If any of the operands is > (65531) (-4), then ...
4.563395
2.851871
1.600141
''' Pops last 2 words from the stack and subtract them. Then push the result onto the stack. Top of the stack is subtracted Top -1 Optimizations: * If 2nd op is ZERO, then do NOTHING: A - 0 = A * If any of the operands is < 4, then DEC is used * If any of the operand...
def _sub16(ins)
Pops last 2 words from the stack and subtract them. Then push the result onto the stack. Top of the stack is subtracted Top -1 Optimizations: * If 2nd op is ZERO, then do NOTHING: A - 0 = A * If any of the operands is < 4, then DEC is used * If any of the operands is > 6...
5.297718
2.761054
1.91873
''' Multiplies tow last 16bit values on top of the stack and and returns the value on top of the stack Optimizations: * If any of the ops is ZERO, then do A = 0 ==> XOR A, cause A * 0 = 0 * A = 0 * If any ot the ops is ONE, do NOTHING A * 1 = 1 * A = A * If B is 2^n and ...
def _mul16(ins)
Multiplies tow last 16bit values on top of the stack and and returns the value on top of the stack Optimizations: * If any of the ops is ZERO, then do A = 0 ==> XOR A, cause A * 0 = 0 * A = 0 * If any ot the ops is ONE, do NOTHING A * 1 = 1 * A = A * If B is 2^n and B < 16 =...
6.256519
3.718404
1.682582
''' Divides 2 16bit unsigned integers. The result is pushed onto the stack. Optimizations: * If 2nd op is 1 then do nothing * If 2nd op is 2 then Shift Right Logical ''' op1, op2 = tuple(ins.quad[2:]) if is_int(op1) and int(op1) == 0: # 0 / A = 0 if op2[0] in (...
def _divu16(ins)
Divides 2 16bit unsigned integers. The result is pushed onto the stack. Optimizations: * If 2nd op is 1 then do nothing * If 2nd op is 2 then Shift Right Logical
4.778126
3.8581
1.238466
''' Reminder of div. 2 16bit unsigned integers. The result is pushed onto the stack. Optimizations: * If 2nd operand is 1 => Return 0 * If 2nd operand = 2^n => do AND (2^n - 1) ''' op1, op2 = tuple(ins.quad[2:]) if is_int(op2): op2 = int16(op2) output = _16bit...
def _modu16(ins)
Reminder of div. 2 16bit unsigned integers. The result is pushed onto the stack. Optimizations: * If 2nd operand is 1 => Return 0 * If 2nd operand = 2^n => do AND (2^n - 1)
6.02221
4.138873
1.455036
''' 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. 16 bit unsigned version ''' output = _16bit_oper(ins.quad[2], ins.quad[3]) output.append('or a') output.append('sbc hl, de') ...
def _ltu16(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. 16 bit unsigned version
10.252542
3.990804
2.569042
''' 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. 16 bit signed version ''' output = _16bit_oper(ins.quad[2], ins.quad[3]) output.append('call __LTI16') output.append('push af') ...
def _lti16(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. 16 bit signed version
12.528338
4.794461
2.613086
''' 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. 16 bit unsigned version ''' output = _16bit_oper(ins.quad[2], ins.quad[3], reversed=True) output.append('or a') output.append('s...
def _gtu16(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. 16 bit unsigned version
10.488056
4.194559
2.500396
''' 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. 16 bit signed version ''' output = _16bit_oper(ins.quad[2], ins.quad[3], reversed=True) output.append('call __LTI16') output.app...
def _gti16(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. 16 bit signed version
14.571978
5.407968
2.694538
''' 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. 16 bit unsigned version ''' output = _16bit_oper(ins.quad[2], ins.quad[3], reversed=True) output.append('or a') output.append('...
def _leu16(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. 16 bit unsigned version
11.124269
5.155908
2.157577
''' 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. 16 bit signed version ''' output = _16bit_oper(ins.quad[2], ins.quad[3]) output.append('call __LEI16') output.append('push af')...
def _lei16(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. 16 bit signed version
13.400765
4.78688
2.799478
''' 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. 16 bit unsigned version ''' output = _16bit_oper(ins.quad[2], ins.quad[3]) output.append('or a') output.append('sbc hl, de') ...
def _geu16(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. 16 bit unsigned version
10.259347
4.141948
2.476938
''' 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. 16 bit un/signed version ''' output = _16bit_oper(ins.quad[2], ins.quad[3]) output.append('call __EQ16') output.append('push af...
def _eq16(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. 16 bit un/signed version
14.734719
5.086755
2.896684
''' 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. 16 bit un/signed version ''' output = _16bit_oper(ins.quad[2], ins.quad[3]) output.append('or a') # Resets carry flag output.a...
def _ne16(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. 16 bit un/signed version
11.726015
4.585811
2.557021
''' Compares & pops top 2 operands out of the stack, and checks if the 1st operand OR (logical) 2nd operand (top of the stack), pushes 0 if False, 1 if True. 16 bit un/signed version Optimizations: If any of the operators are constants: Returns either 0 or the othe...
def _or16(ins)
Compares & pops top 2 operands out of the stack, and checks if the 1st operand OR (logical) 2nd operand (top of the stack), pushes 0 if False, 1 if True. 16 bit un/signed version Optimizations: If any of the operators are constants: Returns either 0 or the other operan...
6.112658
3.026862
2.01947
''' Pops top 2 operands out of the stack, and performs 1st operand OR (bitwise) 2nd operand (top of the stack), pushes result (16 bit in HL). 16 bit un/signed version Optimizations: If any of the operators are constants: Returns either 0 or the other operand ''...
def _bor16(ins)
Pops top 2 operands out of the stack, and performs 1st operand OR (bitwise) 2nd operand (top of the stack), pushes result (16 bit in HL). 16 bit un/signed version Optimizations: If any of the operators are constants: Returns either 0 or the other operand
7.608874
3.317036
2.293877
''' Negates top (Logical NOT) of the stack (16 bits in HL) ''' output = _16bit_oper(ins.quad[2]) output.append('ld a, h') output.append('or l') output.append('sub 1') output.append('sbc a, a') output.append('push af') return output
def _not16(ins)
Negates top (Logical NOT) of the stack (16 bits in HL)
12.486103
7.087039
1.761822
''' Negates top (Bitwise NOT) of the stack (16 bits in HL) ''' output = _16bit_oper(ins.quad[2]) output.append('call __BNOT16') output.append('push hl') REQUIRES.add('bnot16.asm') return output
def _bnot16(ins)
Negates top (Bitwise NOT) of the stack (16 bits in HL)
19.587534
11.048168
1.772921
''' Negates top of the stack (16 bits in HL) ''' output = _16bit_oper(ins.quad[2]) output.append('call __NEGHL') output.append('push hl') REQUIRES.add('neg16.asm') return output
def _neg16(ins)
Negates top of the stack (16 bits in HL)
21.85759
16.092123
1.358279
''' Absolute value of top of the stack (16 bits in HL) ''' output = _16bit_oper(ins.quad[2]) output.append('call __ABS16') output.append('push hl') REQUIRES.add('abs16.asm') return output
def _abs16(ins)
Absolute value of top of the stack (16 bits in HL)
17.730482
13.62318
1.301494
''' Logical right shift 16bit unsigned integer. The result is pushed onto the stack. Optimizations: * If 2nd op is 0 then do nothing * If 2nd op is 1 Shift Right Arithmetic ''' op1, op2 = tuple(ins.quad[2:]) if is_int(op2): op = int16(op2) if op == 0...
def _shru16(ins)
Logical right shift 16bit unsigned integer. The result is pushed onto the stack. Optimizations: * If 2nd op is 0 then do nothing * If 2nd op is 1 Shift Right Arithmetic
5.457038
3.649913
1.495115
self.out(self.LH(len(bytes_) + 1)) # + 1 for CHECKSUM byte checksum = 0 for i in bytes_: checksum ^= (int(i) & 0xFF) self.out(i) self.out(checksum)
def standard_block(self, bytes_)
Adds a standard block of bytes. For TAP files, it's just the Low + Hi byte plus the content (here, the bytes plus the checksum)
5.773748
4.907112
1.176608
encodings = ['utf-8-sig', 'cp1252'] with open(fname, 'rb') as f: content = bytes(f.read()) for i in encodings: try: result = content.decode(i) if six.PY2: result = result.encode('utf-8') return result except UnicodeDecodeError...
def read_txt_file(fname)
Reads a txt file, regardless of its encoding
3.990541
3.88797
1.026382
if six.PY2 or 't' not in mode: kwargs = {} else: kwargs = {'encoding': encoding} return open(fname, mode, **kwargs)
def open_file(fname, mode='rb', encoding='utf-8')
An open() wrapper for PY2 and PY3 which allows encoding :param fname: file name (string) :param mode: file mode (string) optional :param encoding: optional encoding (string). Ignored in python2 or if not in text mode :return: an open file handle
3.886946
3.98787
0.974692
str_num = (str_num or "").strip().upper() if not str_num: return None base = 10 if str_num.startswith('0X'): base = 16 str_num = str_num[2:] if str_num.endswith('H'): base = 16 str_num = str_num[:-1] if str_num.startswith('$'): base = 16 ...
def parse_int(str_num)
Given an integer number, return its value, or None if it could not be parsed. Allowed formats: DECIMAL, HEXA (0xnnn, $nnnn or nnnnh) :param str_num: (string) the number to be parsed :return: an integer number or None if it could not be parsedd
1.901065
1.791363
1.06124
if not isinstance(l, list): l = [l] self.output.extend([int(i) & 0xFF for i in l])
def out(self, l)
Adds a list of bytes to the output string
4.491113
3.85352
1.165457
self.out(self.BLOCK_STANDARD) # Standard block ID self.out(self.LH(1000)) # 1000 ms standard pause self.out(self.LH(len(_bytes) + 1)) # + 1 for CHECKSUM byte checksum = 0 for i in _bytes: checksum ^= (int(i) & 0xFF) self.out(i) self.o...
def standard_block(self, _bytes)
Adds a standard block of bytes
5.259664
5.235721
1.004573
with open(fname, 'wb') as f: f.write(self.output)
def dump(self, fname)
Saves TZX file to fname
3.91641
3.989751
0.981618
title = (title + 10 * ' ')[:10] # Padd it with spaces title_bytes = [ord(i) for i in title] # Convert it to bytes _bytes = [self.BLOCK_TYPE_HEADER, _type] + title_bytes + self.LH(length) + self.LH(param1) + self.LH(param2) self.standard_block(_bytes)
def save_header(self, _type, title, length, param1, param2)
Saves a generic standard header: type: 00 -- Program 01 -- Number Array 02 -- Char Array 03 -- Code title: Name title. Will be truncated to 10 chars and padded with...
5.532807
5.355974
1.033016
self.save_header(self.HEADER_TYPE_CODE, title, length, param1=addr, param2=32768)
def standard_bytes_header(self, title, addr, length)
Generates a standard header block of CODE type
10.355989
8.404181
1.232242
self.save_header(self.HEADER_TYPE_BASIC, title, length, param1=line, param2=length)
def standard_program_header(self, title, length, line=32768)
Generates a standard header block of PROGRAM type
10.514177
10.463333
1.004859
self.standard_bytes_header(title, addr, len(_bytes)) _bytes = [self.BLOCK_TYPE_DATA] + [(int(x) & 0xFF) for x in _bytes] # & 0xFF truncates to bytes self.standard_block(_bytes)
def save_code(self, title, addr, _bytes)
Saves the given bytes as code. If bytes are strings, its chars will be converted to bytes
7.062387
7.554525
0.934855
self.standard_program_header(title, len(bytes), line) bytes = [self.BLOCK_TYPE_DATA] + [(int(x) & 0xFF) for x in bytes] # & 0xFF truncates to bytes self.standard_block(bytes)
def save_program(self, title, bytes, line=32768)
Saves the given bytes as a BASIC program.
6.755334
6.656813
1.0148
if lower is None or upper is None or s is None: return None if not check_type(lineno, Type.string, s): return None lo = up = None base = NUMBER(api.config.OPTIONS.string_base.value, lineno=lineno) lower = TYPECAST.make_node(gl.SYMBOL_TABLE.basic...
def make_node(cls, lineno, s, lower, upper)
Creates a node for a string slice. S is the string expression Tree. Lower and upper are the bounds, if lower & upper are constants, and s is also constant, then a string constant is returned. If lower > upper, an empty string is returned.
4.77586
4.532634
1.053661
global ASMS global ASMCOUNT global AT_END global FLAG_end_emitted global FLAG_use_function_exit __common.init() ASMS = {} ASMCOUNT = 0 AT_END = [] FLAG_use_function_exit = False FLAG_end_emitted = False # Default code ORG OPTIONS.add_option('org', int, 32768) ...
def init()
Initializes this module
6.431042
6.445052
0.997826
output = [] if stype in ('i8', 'u8'): return [] if is_int_type(stype): output.append('ld a, l') elif stype == 'f16': output.append('ld a, e') elif stype == 'f': # Converts C ED LH to byte output.append('call __FTOU32REG') output.append('ld a, l') ...
def to_byte(stype)
Returns the instruction sequence for converting from the given type to byte.
8.598422
8.393352
1.024432
output = [] # List of instructions if stype == 'u8': # Byte to word output.append('ld l, a') output.append('ld h, 0') elif stype == 'i8': # Signed byte to word output.append('ld l, a') output.append('add a, a') output.append('sbc a, a') output.append...
def to_word(stype)
Returns the instruction sequence for converting the given type stored in DE,HL to word (unsigned) HL.
5.721276
5.414023
1.056751
output = [] # List of instructions if is_int_type(stype): output = to_word(stype) output.append('ex de, hl') output.append('ld hl, 0') # 'Truncate' the fixed point elif stype == 'f': output.append('call __FTOF16REG') REQUIRES.add('ftof16reg.asm') return o...
def to_fixed(stype)
Returns the instruction sequence for converting the given type stored in DE,HL to fixed DE,HL.
14.043277
12.624643
1.11237
output = [] # List of instructions if stype == 'f': return [] # Nothing to do if stype == 'f16': output.append('call __F16TOFREG') REQUIRES.add('f16tofreg.asm') return output # If we reach this point, it's an integer type if stype == 'u8': output.app...
def to_float(stype)
Returns the instruction sequence for converting the given type stored in DE,HL to fixed DE,HL.
3.283669
3.180398
1.032471
global FLAG_end_emitted output = _16bit_oper(ins.quad[1]) output.append('ld b, h') output.append('ld c, l') if FLAG_end_emitted: return output + ['jp %s' % END_LABEL] FLAG_end_emitted = True output.append('%s:' % END_LABEL) if OPTIONS.headerless.value: return outp...
def _end(ins)
Outputs the ending sequence
5.605093
5.609806
0.99916
output = [] t = ins.quad[1] q = eval(ins.quad[2]) if t in ('i8', 'u8'): size = 'B' elif t in ('i16', 'u16'): size = 'W' elif t in ('i32', 'u32'): size = 'W' z = list() for expr in ins.quad[2]: z.extend(['(%s) & 0xFFFF' % expr, '(%s) >> 16...
def _data(ins)
Defines a data item (binary). It's just a constant expression to be converted do binary data "as is" 1st parameter is the type-size (u8 or i8 for byte, u16 or i16 for word, etc) 2nd parameter is the list of expressions. All of them will be converted to the type required.
3.939739
3.647851
1.080017
output = [] output.append('%s:' % ins.quad[1]) output.append('DEFB %s' % ((int(ins.quad[2]) - 1) * '00, ' + '00')) return output
def _var(ins)
Defines a memory variable.
10.081974
9.333661
1.080174
output = [] output.append('%s:' % ins.quad[1]) q = eval(ins.quad[3]) if ins.quad[2] in ('i8', 'u8'): size = 'B' elif ins.quad[2] in ('i16', 'u16'): size = 'W' elif ins.quad[2] in ('i32', 'u32'): size = 'W' z = list() for expr in q: z.exte...
def _varx(ins)
Defines a memory space with a default CONSTANT expression 1st parameter is the var name 2nd parameter is the type-size (u8 or i8 for byte, u16 or i16 for word, etc) 3rd parameter is the list of expressions. All of them will be converted to the type required.
3.77379
3.436172
1.098254
output = [] output.append('%s:' % ins.quad[1]) q = eval(ins.quad[2]) for x in q: if x[0] == '#': # literal? size_t = 'W' if x[1] == '#' else 'B' output.append('DEF{0} {1}'.format(size_t, x.lstrip('#'))) continue # must be an hex number ...
def _vard(ins)
Defines a memory space with a default set of bytes/words in hexadecimal (starting with a number) or literals (starting with #). Numeric values with more than 2 digits represents a WORD (2 bytes) value. E.g. '01' => 0, '001' => 1, 0 bytes Literal values starts with # (1 byte) or ## (2 bytes) E.g. '#l...
4.577711
4.337409
1.055402
output = [] l = eval(ins.quad[3]) # List of bytes to push label = tmp_label() offset = int(ins.quad[1]) tmp = list(ins.quad) tmp[1] = label ins.quad = tmp AT_END.extend(_varx(ins)) output.append('push ix') output.append('pop hl') output.append('ld bc, %i' % -offset) ...
def _lvarx(ins)
Defines a local variable. 1st param is offset of the local variable. 2nd param is the type a list of bytes in hexadecimal.
7.28308
7.09257
1.02686
output = [] l = eval(ins.quad[2]) # List of bytes to push label = tmp_label() offset = int(ins.quad[1]) tmp = list(ins.quad) tmp[1] = label ins.quad = tmp AT_END.extend(_vard(ins)) output.append('push ix') output.append('pop hl') output.append('ld bc, %i' % -offset) ...
def _lvard(ins)
Defines a local variable. 1st param is offset of the local variable. 2nd param is a list of bytes in hexadecimal.
7.122221
6.711096
1.06126
output = _8bit_oper(ins.quad[2]) output.extend(_16bit_oper(ins.quad[1])) output.append('ld b, h') output.append('ld c, l') output.append('out (c), a') return output
def _out(ins)
Translates OUT to asm.
8.366859
6.895968
1.213297
output = _16bit_oper(ins.quad[1]) output.append('ld b, h') output.append('ld c, l') output.append('in a, (c)') output.append('push af') return output
def _in(ins)
Translates IN to asm.
10.704836
8.793096
1.217414
output = _32bit_oper(ins.quad[2]) output.append('push de') output.append('push hl') return output
def _load32(ins)
Load a 32 bit value from a memory address If 2nd arg. start with '*', it is always treated as an indirect value.
16.693865
17.734568
0.941318
output = _f16_oper(ins.quad[2]) output.append('push de') output.append('push hl') return output
def _loadf16(ins)
Load a 32 bit (16.16) fixed point value from a memory address If 2nd arg. start with '*', it is always treated as an indirect value.
14.887515
17.413553
0.854938
output = _float_oper(ins.quad[2]) output.extend(_fpush()) return output
def _loadf(ins)
Loads a floating point value from a memory address. If 2nd arg. start with '*', it is always treated as an indirect value.
40.171993
38.578815
1.041297
temporal, output = _str_oper(ins.quad[2], no_exaf=True) if not temporal: output.append('call __LOADSTR') REQUIRES.add('loadstr.asm') output.append('push hl') return output
def _loadstr(ins)
Loads a string value from a memory address.
29.247684
30.087662
0.972082
output = _8bit_oper(ins.quad[2]) op = ins.quad[1] indirect = op[0] == '*' if indirect: op = op[1:] immediate = op[0] == '#' if immediate: op = op[1:] if is_int(op) or op[0] == '_': if is_int(op): op = str(int(op) & 0xFFFF) if immediate: ...
def _store8(ins)
Stores 2nd operand content into address of 1st operand. store8 a, x => a = x Use '*' for indirect store on 1st operand.
3.121815
3.163098
0.986949
output = [] output = _16bit_oper(ins.quad[2]) try: value = ins.quad[1] indirect = False if value[0] == '*': indirect = True value = value[1:] value = int(value) & 0xFFFF if indirect: output.append('ex de, hl') out...
def _store16(ins)
Stores 2nd operand content into address of 1st operand. store16 a, x => *(&a) = x Use '*' for indirect store on 1st operand.
2.101378
2.117977
0.992163
op = ins.quad[1] indirect = op[0] == '*' if indirect: op = op[1:] immediate = op[0] == '#' # Might make no sense here? if immediate: op = op[1:] if is_int(op) or op[0] == '_' or immediate: output = _32bit_oper(ins.quad[2], preserveHL=indirect) if is_int(...
def _store32(ins)
Stores 2nd operand content into address of 1st operand. store16 a, x => *(&a) = x
4.144335
4.261772
0.972444
value = ins.quad[2] if is_float(value): val = float(ins.quad[2]) # Immediate? (de, hl) = f16(val) q = list(ins.quad) q[2] = (de << 16) | hl ins.quad = tuple(q) return _store32(ins)
def _storef16(ins)
Stores 2º operand content into address of 1st operand. store16 a, x => *(&a) = x
6.250197
6.54734
0.954616
output = _float_oper(ins.quad[2]) op = ins.quad[1] indirect = op[0] == '*' if indirect: op = op[1:] immediate = op[0] == '#' # Might make no sense here? if immediate: op = op[1:] if is_int(op) or op[0] == '_': if is_int(op): op = str(int(op) & 0x...
def _storef(ins)
Stores a floating point value into a memory address.
5.192875
5.100468
1.018117
op1 = ins.quad[1] indirect = op1[0] == '*' if indirect: op1 = op1[1:] immediate = op1[0] == '#' if immediate and not indirect: raise InvalidIC('storestr does not allow immediate destination', ins.quad) if not indirect: op1 = '#' + op1 tmp1, tmp2, output = _str...
def _storestr(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 '#'. Must prepend '#' (immediate sigil) to 1st operand, as we need the &...
6.883989
7.047946
0.976737
# Signed and unsigned types are the same in the Z80 tA = ins.quad[2] # From TypeA tB = ins.quad[3] # To TypeB YY_TYPES[tA] # Type sizes xsB = sB = YY_TYPES[tB] # Type sizes output = [] if tA in ('u8', 'i8'): output.extend(_8bit_oper(ins.quad[4])) elif tA in ('u16', 'i1...
def _cast(ins)
Convert data from typeA to typeB (only numeric data types)
3.125281
3.032242
1.030683
value = ins.quad[1] if is_float(value): if float(value) == 0: return ['jp %s' % str(ins.quad[2])] # Always true else: return [] output = _float_oper(value) output.append('ld a, c') output.append('or l') output.append('or h') output.append('or e'...
def _jzerof(ins)
Jumps if top of the stack (40bit, float) is 0 to arg(1)
4.881588
4.7147
1.035397
output = [] disposable = False # True if string must be freed from memory if ins.quad[1][0] == '_': # Variable? output.append('ld hl, (%s)' % ins.quad[1][0]) else: output.append('pop hl') output.append('push hl') # Saves it for later disposable = True output...
def _jzerostr(ins)
Jumps if top of the stack contains a NULL pointer or its len is Zero
6.859957
6.89873
0.99438
value = ins.quad[1] if is_int(value): if int(value) != 0: return ['jp %s' % str(ins.quad[2])] # Always true else: return [] output = _16bit_oper(value) output.append('ld a, h') output.append('or l') output.append('jp nz, %s' % str(ins.quad[2])) ...
def _jnzero16(ins)
Jumps if top of the stack (16bit) is != 0 to arg(1)
5.76593
5.491062
1.050057
value = ins.quad[1] if is_int(value): if int(value) != 0: return ['jp %s' % str(ins.quad[2])] # Always true else: return [] output = _32bit_oper(value) output.append('ld a, h') output.append('or l') output.append('or e') output.append('or d') ...
def _jnzero32(ins)
Jumps if top of the stack (32bit) is !=0 to arg(1)
5.285254
5.099523
1.036421
value = ins.quad[1] if is_float(value): if float(value) != 0: return ['jp %s' % str(ins.quad[2])] # Always true else: return [] output = _f16_oper(value) output.append('ld a, h') output.append('or l') output.append('or e') output.append('or d') ...
def _jnzerof16(ins)
Jumps if top of the stack (32bit) is !=0 to arg(1) Fixed Point (16.16 bit) values.
5.31701
5.483327
0.969669
output = [] value = ins.quad[1] if not is_int(value): output = _8bit_oper(value) output.append('jp %s' % str(ins.quad[2])) return output
def _jgezerou8(ins)
Jumps if top of the stack (8bit) is >= 0 to arg(1) Always TRUE for unsigned
9.334437
10.6086
0.879893
value = ins.quad[1] if is_int(value): if int(value) >= 0: return ['jp %s' % str(ins.quad[2])] # Always true else: return [] output = _8bit_oper(value) output.append('add a, a') # Puts sign into carry output.append('jp nc, %s' % str(ins.quad[2])) re...
def _jgezeroi8(ins)
Jumps if top of the stack (8bit) is >= 0 to arg(1)
6.999773
6.767516
1.034319
output = [] value = ins.quad[1] if not is_int(value): output = _16bit_oper(value) output.append('jp %s' % str(ins.quad[2])) return output
def _jgezerou16(ins)
Jumps if top of the stack (16bit) is >= 0 to arg(1) Always TRUE for unsigned
8.610281
9.883459
0.871181
output = [] value = ins.quad[1] if not is_int(value): output = _32bit_oper(value) output.append('jp %s' % str(ins.quad[2])) return output
def _jgezerou32(ins)
Jumps if top of the stack (23bit) is >= 0 to arg(1) Always TRUE for unsigned
8.746615
10.224223
0.85548
output = _8bit_oper(ins.quad[1]) output.append('#pragma opt require a') output.append('jp %s' % str(ins.quad[2])) return output
def _ret8(ins)
Returns from a procedure / function an 8bits value
19.594597
17.855316
1.09741
output = _16bit_oper(ins.quad[1]) output.append('#pragma opt require hl') output.append('jp %s' % str(ins.quad[2])) return output
def _ret16(ins)
Returns from a procedure / function a 16bits value
21.248531
19.914801
1.066972
output = _32bit_oper(ins.quad[1]) output.append('#pragma opt require hl,de') output.append('jp %s' % str(ins.quad[2])) return output
def _ret32(ins)
Returns from a procedure / function a 32bits value (even Fixed point)
23.498899
21.702038
1.082797
output = _f16_oper(ins.quad[1]) output.append('#pragma opt require hl,de') output.append('jp %s' % str(ins.quad[2])) return output
def _retf16(ins)
Returns from a procedure / function a Fixed Point (32bits) value
21.236443
21.060305
1.008364
output = _float_oper(ins.quad[1]) output.append('#pragma opt require a,bc,de') output.append('jp %s' % str(ins.quad[2])) return output
def _retf(ins)
Returns from a procedure / function a Floating Point (40bits) value
21.307287
20.985949
1.015312
tmp, output = _str_oper(ins.quad[1], no_exaf=True) if not tmp: output.append('call __LOADSTR') REQUIRES.add('loadstr.asm') output.append('#pragma opt require hl') output.append('jp %s' % str(ins.quad[2])) return output
def _retstr(ins)
Returns from a procedure / function a string pointer (16bits) value
22.386545
23.910389
0.936269
output = [] output.append('call %s' % str(ins.quad[1])) try: val = int(ins.quad[2]) if val == 1: output.append('push af') # Byte else: if val > 4: output.extend(_fpush()) else: if val > 2: ...
def _call(ins)
Calls a function XXXX (or address XXXX) 2nd parameter contains size of the returning result if any, and will be pushed onto the stack.
4.978584
5.128573
0.970754
global FLAG_use_function_exit output = [] if ins.quad[1] == '__fastcall__': output.append('ret') return output nbytes = int(ins.quad[1]) # Number of bytes to pop (params size) if nbytes == 0: output.append('ld sp, ix') output.append('pop ix') output....
def _leave(ins)
Return from a function popping N bytes from the stack Use '__fastcall__' as 1st parameter, to just return
3.947549
3.766023
1.048201
output = [] if ins.quad[1] == '__fastcall__': return output output.append('push ix') output.append('ld ix, 0') output.append('add ix, sp') size_bytes = int(ins.quad[1]) if size_bytes != 0: if size_bytes < 7: output.append('ld hl, 0') output.ex...
def _enter(ins)
Enter function sequence for doing a function start ins.quad[1] contains size (in bytes) of local variables Use '__fastcall__' as 1st parameter to prepare a fastcall function (no local variables).
4.817005
4.311672
1.117201
output = _32bit_oper(ins.quad[1]) output.append('push de') output.append('push hl') return output
def _param32(ins)
Pushes 32bit param into the stack
17.639076
15.304951
1.152508
output = _f16_oper(ins.quad[1]) output.append('push de') output.append('push hl') return output
def _paramf16(ins)
Pushes 32bit fixed point param into the stack
16.323719
16.068632
1.015875
output = _float_oper(ins.quad[1]) output.extend(_fpush()) return output
def _paramf(ins)
Pushes 40bit (float) param into the stack
40.376278
28.93227
1.395545
(tmp, output) = _str_oper(ins.quad[1]) output.pop() # Remove a register flag (useless here) tmp = ins.quad[1][0] in ('#', '_') # Determine if the string must be duplicated if tmp: output.append('call __LOADSTR') # Must be duplicated REQUIRES.add('loadstr.asm') output.append...
def _paramstr(ins)
Pushes an 16 bit unsigned value, which points to a string. For indirect values, it will push the pointer to the pointer :-)
19.083111
18.729595
1.018875
output = _16bit_oper(ins.quad[3]) output.append('ld b, h') output.append('ld c, l') output.extend(_16bit_oper(ins.quad[1], ins.quad[2], reversed=True)) output.append('ldir') # *** return output
def _memcopy(ins)
Copies a block of memory from param 2 addr to param 1 addr.
9.427575
10.74511
0.877383
tmp = [x.strip(' \t\r\n') for x in ins.quad[1].split('\n')] # Split lines i = 0 while i < len(tmp): if not tmp[i] or tmp[i][0] == ';': # a comment or empty string? tmp.pop(i) continue if tmp[i][0] == '#': # A preprocessor directive i += 1 ...
def _inline(ins)
Inline code
3.861979
3.815592
1.012157
if not OPTIONS.strictBool.value: return [] REQUIRES.add('strictbool.asm') result = [] result.append('pop af') result.append('call __NORMALIZE_BOOLEAN') result.append('push af') return result
def convertToBool()
Convert a byte value to boolean (0 or 1) if the global flag strictBool is True
17.274921
16.754572
1.031057