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_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
boriel/zxbasic | arch/zx48k/backend/__init__.py | _varx | 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.
"""
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.extend(['(%s) & 0xFFFF' % expr, '(%s) >> 16' % expr])
q = z
else:
raise InvalidIC(ins.quad, 'Unimplemented vard size: %s' % ins.quad[2])
for x in q:
output.append('DEF%s %s' % (size, x))
return output | python | 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.
"""
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.extend(['(%s) & 0xFFFF' % expr, '(%s) >> 16' % expr])
q = z
else:
raise InvalidIC(ins.quad, 'Unimplemented vard size: %s' % ins.quad[2])
for x in q:
output.append('DEF%s %s' % (size, x))
return output | [
"def",
"_varx",
"(",
"ins",
")",
":",
"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",
".",
"extend",
"(",
"[",
"'(%s) & 0xFFFF'",
"%",
"expr",
",",
"'(%s) >> 16'",
"%",
"expr",
"]",
")",
"q",
"=",
"z",
"else",
":",
"raise",
"InvalidIC",
"(",
"ins",
".",
"quad",
",",
"'Unimplemented vard size: %s'",
"%",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"for",
"x",
"in",
"q",
":",
"output",
".",
"append",
"(",
"'DEF%s %s'",
"%",
"(",
"size",
",",
"x",
")",
")",
"return",
"output"
] | 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. | [
"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",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L497-L524 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _vard | 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. '#label + 1' => (label + 1) & 0xFF
'##(label + 1)' => (label + 1) & 0xFFFF
"""
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
x = x.upper()
assert RE_HEXA.match(x), 'expected an hex number, got "%s"' % x
size_t = 'B' if len(x) <= 2 else 'W'
if x[0] > '9': # Not a number?
x = '0' + x
output.append('DEF{0} {1}h'.format(size_t, x))
return output | python | 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. '#label + 1' => (label + 1) & 0xFF
'##(label + 1)' => (label + 1) & 0xFFFF
"""
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
x = x.upper()
assert RE_HEXA.match(x), 'expected an hex number, got "%s"' % x
size_t = 'B' if len(x) <= 2 else 'W'
if x[0] > '9': # Not a number?
x = '0' + x
output.append('DEF{0} {1}h'.format(size_t, x))
return output | [
"def",
"_vard",
"(",
"ins",
")",
":",
"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",
"x",
"=",
"x",
".",
"upper",
"(",
")",
"assert",
"RE_HEXA",
".",
"match",
"(",
"x",
")",
",",
"'expected an hex number, got \"%s\"'",
"%",
"x",
"size_t",
"=",
"'B'",
"if",
"len",
"(",
"x",
")",
"<=",
"2",
"else",
"'W'",
"if",
"x",
"[",
"0",
"]",
">",
"'9'",
":",
"# Not a number?",
"x",
"=",
"'0'",
"+",
"x",
"output",
".",
"append",
"(",
"'DEF{0} {1}h'",
".",
"format",
"(",
"size_t",
",",
"x",
")",
")",
"return",
"output"
] | 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. '#label + 1' => (label + 1) & 0xFF
'##(label + 1)' => (label + 1) & 0xFFFF | [
"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",
".",
"#label",
"+",
"1",
"=",
">",
"(",
"label",
"+",
"1",
")",
"&",
"0xFF",
"##",
"(",
"label",
"+",
"1",
")",
"=",
">",
"(",
"label",
"+",
"1",
")",
"&",
"0xFFFF"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L527-L555 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _lvarx | 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.
"""
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)
output.append('add hl, bc')
output.append('ex de, hl')
output.append('ld hl, %s' % label)
output.append('ld bc, %i' % (len(l) * YY_TYPES[ins.quad[2]]))
output.append('ldir')
return output | python | 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.
"""
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)
output.append('add hl, bc')
output.append('ex de, hl')
output.append('ld hl, %s' % label)
output.append('ld bc, %i' % (len(l) * YY_TYPES[ins.quad[2]]))
output.append('ldir')
return output | [
"def",
"_lvarx",
"(",
"ins",
")",
":",
"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",
")",
"output",
".",
"append",
"(",
"'add hl, bc'",
")",
"output",
".",
"append",
"(",
"'ex de, hl'",
")",
"output",
".",
"append",
"(",
"'ld hl, %s'",
"%",
"label",
")",
"output",
".",
"append",
"(",
"'ld bc, %i'",
"%",
"(",
"len",
"(",
"l",
")",
"*",
"YY_TYPES",
"[",
"ins",
".",
"quad",
"[",
"2",
"]",
"]",
")",
")",
"output",
".",
"append",
"(",
"'ldir'",
")",
"return",
"output"
] | Defines a local variable. 1st param is offset of the local variable.
2nd param is the type a list of bytes in hexadecimal. | [
"Defines",
"a",
"local",
"variable",
".",
"1st",
"param",
"is",
"offset",
"of",
"the",
"local",
"variable",
".",
"2nd",
"param",
"is",
"the",
"type",
"a",
"list",
"of",
"bytes",
"in",
"hexadecimal",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L558-L581 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _lvard | def _lvard(ins):
""" Defines a local variable. 1st param is offset of the local variable.
2nd param is a list of bytes in hexadecimal.
"""
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)
output.append('add hl, bc')
output.append('ex de, hl')
output.append('ld hl, %s' % label)
output.append('ld bc, %i' % len(l))
output.append('ldir')
return output | python | def _lvard(ins):
""" Defines a local variable. 1st param is offset of the local variable.
2nd param is a list of bytes in hexadecimal.
"""
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)
output.append('add hl, bc')
output.append('ex de, hl')
output.append('ld hl, %s' % label)
output.append('ld bc, %i' % len(l))
output.append('ldir')
return output | [
"def",
"_lvard",
"(",
"ins",
")",
":",
"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",
")",
"output",
".",
"append",
"(",
"'add hl, bc'",
")",
"output",
".",
"append",
"(",
"'ex de, hl'",
")",
"output",
".",
"append",
"(",
"'ld hl, %s'",
"%",
"label",
")",
"output",
".",
"append",
"(",
"'ld bc, %i'",
"%",
"len",
"(",
"l",
")",
")",
"output",
".",
"append",
"(",
"'ldir'",
")",
"return",
"output"
] | Defines a local variable. 1st param is offset of the local variable.
2nd param is a list of bytes in hexadecimal. | [
"Defines",
"a",
"local",
"variable",
".",
"1st",
"param",
"is",
"offset",
"of",
"the",
"local",
"variable",
".",
"2nd",
"param",
"is",
"a",
"list",
"of",
"bytes",
"in",
"hexadecimal",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L584-L607 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _out | def _out(ins):
""" Translates OUT to asm.
"""
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 | python | def _out(ins):
""" Translates OUT to asm.
"""
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",
")",
":",
"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"
] | Translates OUT to asm. | [
"Translates",
"OUT",
"to",
"asm",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L610-L619 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _in | def _in(ins):
""" Translates IN to asm.
"""
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 | python | def _in(ins):
""" Translates IN to asm.
"""
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",
")",
":",
"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"
] | Translates IN to asm. | [
"Translates",
"IN",
"to",
"asm",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L622-L631 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _load32 | 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.
"""
output = _32bit_oper(ins.quad[2])
output.append('push de')
output.append('push hl')
return output | python | 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.
"""
output = _32bit_oper(ins.quad[2])
output.append('push de')
output.append('push hl')
return output | [
"def",
"_load32",
"(",
"ins",
")",
":",
"output",
"=",
"_32bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"append",
"(",
"'push de'",
")",
"output",
".",
"append",
"(",
"'push hl'",
")",
"return",
"output"
] | Load a 32 bit value from a memory address
If 2nd arg. start with '*', it is always treated as
an indirect value. | [
"Load",
"a",
"32",
"bit",
"value",
"from",
"a",
"memory",
"address",
"If",
"2nd",
"arg",
".",
"start",
"with",
"*",
"it",
"is",
"always",
"treated",
"as",
"an",
"indirect",
"value",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L654-L662 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _loadf16 | 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.
"""
output = _f16_oper(ins.quad[2])
output.append('push de')
output.append('push hl')
return output | python | 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.
"""
output = _f16_oper(ins.quad[2])
output.append('push de')
output.append('push hl')
return output | [
"def",
"_loadf16",
"(",
"ins",
")",
":",
"output",
"=",
"_f16_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"append",
"(",
"'push de'",
")",
"output",
".",
"append",
"(",
"'push hl'",
")",
"return",
"output"
] | 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. | [
"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",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L665-L673 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _loadf | 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.
"""
output = _float_oper(ins.quad[2])
output.extend(_fpush())
return output | python | 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.
"""
output = _float_oper(ins.quad[2])
output.extend(_fpush())
return output | [
"def",
"_loadf",
"(",
"ins",
")",
":",
"output",
"=",
"_float_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"extend",
"(",
"_fpush",
"(",
")",
")",
"return",
"output"
] | Loads a floating point value from a memory address.
If 2nd arg. start with '*', it is always treated as
an indirect value. | [
"Loads",
"a",
"floating",
"point",
"value",
"from",
"a",
"memory",
"address",
".",
"If",
"2nd",
"arg",
".",
"start",
"with",
"*",
"it",
"is",
"always",
"treated",
"as",
"an",
"indirect",
"value",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L676-L683 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _loadstr | def _loadstr(ins):
""" Loads a string value from a memory address.
"""
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 | python | def _loadstr(ins):
""" Loads a string value from a memory address.
"""
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",
")",
":",
"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"
] | Loads a string value from a memory address. | [
"Loads",
"a",
"string",
"value",
"from",
"a",
"memory",
"address",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L686-L696 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _store8 | def _store8(ins):
""" Stores 2nd operand content into address of 1st operand.
store8 a, x => a = x
Use '*' for indirect store on 1st operand.
"""
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:
if indirect:
output.append('ld (%s), a' % op)
else: # ???
output.append('ld (%s), a' % op)
elif indirect:
output.append('ld hl, (%s)' % op)
output.append('ld (hl), a')
else:
output.append('ld (%s), a' % op)
else:
if immediate:
if indirect: # A label not starting with _
output.append('ld hl, (%s)' % op)
output.append('ld (hl), a')
else:
output.append('ld (%s), a' % op)
return output
else:
output.append('pop hl')
if indirect:
output.append('ld e, (hl)')
output.append('inc hl')
output.append('ld d, (hl)')
output.append('ld (de), a')
else:
output.append('ld (hl), a')
return output | python | def _store8(ins):
""" Stores 2nd operand content into address of 1st operand.
store8 a, x => a = x
Use '*' for indirect store on 1st operand.
"""
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:
if indirect:
output.append('ld (%s), a' % op)
else: # ???
output.append('ld (%s), a' % op)
elif indirect:
output.append('ld hl, (%s)' % op)
output.append('ld (hl), a')
else:
output.append('ld (%s), a' % op)
else:
if immediate:
if indirect: # A label not starting with _
output.append('ld hl, (%s)' % op)
output.append('ld (hl), a')
else:
output.append('ld (%s), a' % op)
return output
else:
output.append('pop hl')
if indirect:
output.append('ld e, (hl)')
output.append('inc hl')
output.append('ld d, (hl)')
output.append('ld (de), a')
else:
output.append('ld (hl), a')
return output | [
"def",
"_store8",
"(",
"ins",
")",
":",
"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",
":",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'ld (%s), a'",
"%",
"op",
")",
"else",
":",
"# ???",
"output",
".",
"append",
"(",
"'ld (%s), a'",
"%",
"op",
")",
"elif",
"indirect",
":",
"output",
".",
"append",
"(",
"'ld hl, (%s)'",
"%",
"op",
")",
"output",
".",
"append",
"(",
"'ld (hl), a'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld (%s), a'",
"%",
"op",
")",
"else",
":",
"if",
"immediate",
":",
"if",
"indirect",
":",
"# A label not starting with _",
"output",
".",
"append",
"(",
"'ld hl, (%s)'",
"%",
"op",
")",
"output",
".",
"append",
"(",
"'ld (hl), a'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld (%s), a'",
"%",
"op",
")",
"return",
"output",
"else",
":",
"output",
".",
"append",
"(",
"'pop hl'",
")",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'ld e, (hl)'",
")",
"output",
".",
"append",
"(",
"'inc hl'",
")",
"output",
".",
"append",
"(",
"'ld d, (hl)'",
")",
"output",
".",
"append",
"(",
"'ld (de), a'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld (hl), a'",
")",
"return",
"output"
] | Stores 2nd operand content into address of 1st operand.
store8 a, x => a = x
Use '*' for indirect store on 1st operand. | [
"Stores",
"2nd",
"operand",
"content",
"into",
"address",
"of",
"1st",
"operand",
".",
"store8",
"a",
"x",
"=",
">",
"a",
"=",
"x",
"Use",
"*",
"for",
"indirect",
"store",
"on",
"1st",
"operand",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L699-L749 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _store16 | def _store16(ins):
""" Stores 2nd operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand.
"""
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')
output.append('ld hl, (%s)' % str(value))
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
else:
output.append('ld (%s), hl' % str(value))
except ValueError:
if value[0] == '_':
if indirect:
output.append('ex de, hl')
output.append('ld hl, (%s)' % str(value))
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
else:
output.append('ld (%s), hl' % str(value))
elif value[0] == '#':
value = value[1:]
if indirect:
output.append('ex de, hl')
output.append('ld hl, (%s)' % str(value))
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
else:
output.append('ld (%s), hl' % str(value))
else:
output.append('ex de, hl')
if indirect:
output.append('pop hl')
output.append('ld a, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, a')
else:
output.append('pop hl')
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
return output | python | def _store16(ins):
""" Stores 2nd operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand.
"""
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')
output.append('ld hl, (%s)' % str(value))
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
else:
output.append('ld (%s), hl' % str(value))
except ValueError:
if value[0] == '_':
if indirect:
output.append('ex de, hl')
output.append('ld hl, (%s)' % str(value))
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
else:
output.append('ld (%s), hl' % str(value))
elif value[0] == '#':
value = value[1:]
if indirect:
output.append('ex de, hl')
output.append('ld hl, (%s)' % str(value))
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
else:
output.append('ld (%s), hl' % str(value))
else:
output.append('ex de, hl')
if indirect:
output.append('pop hl')
output.append('ld a, (hl)')
output.append('inc hl')
output.append('ld h, (hl)')
output.append('ld l, a')
else:
output.append('pop hl')
output.append('ld (hl), e')
output.append('inc hl')
output.append('ld (hl), d')
return output | [
"def",
"_store16",
"(",
"ins",
")",
":",
"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'",
")",
"output",
".",
"append",
"(",
"'ld hl, (%s)'",
"%",
"str",
"(",
"value",
")",
")",
"output",
".",
"append",
"(",
"'ld (hl), e'",
")",
"output",
".",
"append",
"(",
"'inc hl'",
")",
"output",
".",
"append",
"(",
"'ld (hl), d'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld (%s), hl'",
"%",
"str",
"(",
"value",
")",
")",
"except",
"ValueError",
":",
"if",
"value",
"[",
"0",
"]",
"==",
"'_'",
":",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'ex de, hl'",
")",
"output",
".",
"append",
"(",
"'ld hl, (%s)'",
"%",
"str",
"(",
"value",
")",
")",
"output",
".",
"append",
"(",
"'ld (hl), e'",
")",
"output",
".",
"append",
"(",
"'inc hl'",
")",
"output",
".",
"append",
"(",
"'ld (hl), d'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld (%s), hl'",
"%",
"str",
"(",
"value",
")",
")",
"elif",
"value",
"[",
"0",
"]",
"==",
"'#'",
":",
"value",
"=",
"value",
"[",
"1",
":",
"]",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'ex de, hl'",
")",
"output",
".",
"append",
"(",
"'ld hl, (%s)'",
"%",
"str",
"(",
"value",
")",
")",
"output",
".",
"append",
"(",
"'ld (hl), e'",
")",
"output",
".",
"append",
"(",
"'inc hl'",
")",
"output",
".",
"append",
"(",
"'ld (hl), d'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld (%s), hl'",
"%",
"str",
"(",
"value",
")",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ex de, hl'",
")",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'pop hl'",
")",
"output",
".",
"append",
"(",
"'ld a, (hl)'",
")",
"output",
".",
"append",
"(",
"'inc hl'",
")",
"output",
".",
"append",
"(",
"'ld h, (hl)'",
")",
"output",
".",
"append",
"(",
"'ld l, a'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'pop hl'",
")",
"output",
".",
"append",
"(",
"'ld (hl), e'",
")",
"output",
".",
"append",
"(",
"'inc hl'",
")",
"output",
".",
"append",
"(",
"'ld (hl), d'",
")",
"return",
"output"
] | Stores 2nd operand content into address of 1st operand.
store16 a, x => *(&a) = x
Use '*' for indirect store on 1st operand. | [
"Stores",
"2nd",
"operand",
"content",
"into",
"address",
"of",
"1st",
"operand",
".",
"store16",
"a",
"x",
"=",
">",
"*",
"(",
"&a",
")",
"=",
"x",
"Use",
"*",
"for",
"indirect",
"store",
"on",
"1st",
"operand",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L752-L811 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _store32 | def _store32(ins):
""" Stores 2nd operand content into address of 1st operand.
store16 a, x => *(&a) = x
"""
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(op):
op = str(int(op) & 0xFFFF)
if indirect:
output.append('ld hl, (%s)' % op)
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output
output.append('ld (%s), hl' % op)
output.append('ld (%s + 2), de' % op)
return output
output = _32bit_oper(ins.quad[2], preserveHL=True)
output.append('pop hl')
if indirect:
output.append('call __ISTORE32')
REQUIRES.add('store32.asm')
return output
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | python | def _store32(ins):
""" Stores 2nd operand content into address of 1st operand.
store16 a, x => *(&a) = x
"""
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(op):
op = str(int(op) & 0xFFFF)
if indirect:
output.append('ld hl, (%s)' % op)
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output
output.append('ld (%s), hl' % op)
output.append('ld (%s + 2), de' % op)
return output
output = _32bit_oper(ins.quad[2], preserveHL=True)
output.append('pop hl')
if indirect:
output.append('call __ISTORE32')
REQUIRES.add('store32.asm')
return output
output.append('call __STORE32')
REQUIRES.add('store32.asm')
return output | [
"def",
"_store32",
"(",
"ins",
")",
":",
"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",
"(",
"op",
")",
":",
"op",
"=",
"str",
"(",
"int",
"(",
"op",
")",
"&",
"0xFFFF",
")",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'ld hl, (%s)'",
"%",
"op",
")",
"output",
".",
"append",
"(",
"'call __STORE32'",
")",
"REQUIRES",
".",
"add",
"(",
"'store32.asm'",
")",
"return",
"output",
"output",
".",
"append",
"(",
"'ld (%s), hl'",
"%",
"op",
")",
"output",
".",
"append",
"(",
"'ld (%s + 2), de'",
"%",
"op",
")",
"return",
"output",
"output",
"=",
"_32bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"preserveHL",
"=",
"True",
")",
"output",
".",
"append",
"(",
"'pop hl'",
")",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'call __ISTORE32'",
")",
"REQUIRES",
".",
"add",
"(",
"'store32.asm'",
")",
"return",
"output",
"output",
".",
"append",
"(",
"'call __STORE32'",
")",
"REQUIRES",
".",
"add",
"(",
"'store32.asm'",
")",
"return",
"output"
] | Stores 2nd operand content into address of 1st operand.
store16 a, x => *(&a) = x | [
"Stores",
"2nd",
"operand",
"content",
"into",
"address",
"of",
"1st",
"operand",
".",
"store16",
"a",
"x",
"=",
">",
"*",
"(",
"&a",
")",
"=",
"x"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L814-L858 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _storef16 | def _storef16(ins):
""" Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
"""
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) | python | def _storef16(ins):
""" Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x
"""
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",
")",
":",
"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",
")"
] | Stores 2º operand content into address of 1st operand.
store16 a, x => *(&a) = x | [
"Stores",
"2º",
"operand",
"content",
"into",
"address",
"of",
"1st",
"operand",
".",
"store16",
"a",
"x",
"=",
">",
"*",
"(",
"&a",
")",
"=",
"x"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L861-L873 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _storef | def _storef(ins):
""" Stores a floating point value into a memory address.
"""
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) & 0xFFFF)
if indirect:
output.append('ld hl, (%s)' % op)
else:
output.append('ld hl, %s' % op)
else:
output.append('pop hl')
if indirect:
output.append('call __ISTOREF')
REQUIRES.add('storef.asm')
return output
output.append('call __STOREF')
REQUIRES.add('storef.asm')
return output | python | def _storef(ins):
""" Stores a floating point value into a memory address.
"""
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) & 0xFFFF)
if indirect:
output.append('ld hl, (%s)' % op)
else:
output.append('ld hl, %s' % op)
else:
output.append('pop hl')
if indirect:
output.append('call __ISTOREF')
REQUIRES.add('storef.asm')
return output
output.append('call __STOREF')
REQUIRES.add('storef.asm')
return output | [
"def",
"_storef",
"(",
"ins",
")",
":",
"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",
")",
"&",
"0xFFFF",
")",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'ld hl, (%s)'",
"%",
"op",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld hl, %s'",
"%",
"op",
")",
"else",
":",
"output",
".",
"append",
"(",
"'pop hl'",
")",
"if",
"indirect",
":",
"output",
".",
"append",
"(",
"'call __ISTOREF'",
")",
"REQUIRES",
".",
"add",
"(",
"'storef.asm'",
")",
"return",
"output",
"output",
".",
"append",
"(",
"'call __STOREF'",
")",
"REQUIRES",
".",
"add",
"(",
"'storef.asm'",
")",
"return",
"output"
] | Stores a floating point value into a memory address. | [
"Stores",
"a",
"floating",
"point",
"value",
"into",
"a",
"memory",
"address",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L876-L910 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _storestr | 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 & address of the destination.
"""
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_oper(op1, ins.quad[2], no_exaf=True)
if not tmp2:
output.append('call __STORE_STR')
REQUIRES.add('storestr.asm')
else:
output.append('call __STORE_STR2')
REQUIRES.add('storestr2.asm')
return output | python | 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 & address of the destination.
"""
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_oper(op1, ins.quad[2], no_exaf=True)
if not tmp2:
output.append('call __STORE_STR')
REQUIRES.add('storestr.asm')
else:
output.append('call __STORE_STR2')
REQUIRES.add('storestr2.asm')
return output | [
"def",
"_storestr",
"(",
"ins",
")",
":",
"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_oper",
"(",
"op1",
",",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"no_exaf",
"=",
"True",
")",
"if",
"not",
"tmp2",
":",
"output",
".",
"append",
"(",
"'call __STORE_STR'",
")",
"REQUIRES",
".",
"add",
"(",
"'storestr.asm'",
")",
"else",
":",
"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 '#'.
Must prepend '#' (immediate sigil) to 1st operand, as we need
the & address of the destination. | [
"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",
"#",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L913-L943 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _cast | def _cast(ins):
""" Convert data from typeA to typeB (only numeric data types)
"""
# 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', 'i16'):
output.extend(_16bit_oper(ins.quad[4]))
elif tA in ('u32', 'i32'):
output.extend(_32bit_oper(ins.quad[4]))
elif tA == 'f16':
output.extend(_f16_oper(ins.quad[4]))
elif tA == 'f':
output.extend(_float_oper(ins.quad[4]))
else:
raise errors.GenericError(
'Internal error: invalid typecast from %s to %s' % (tA, tB))
if tB in ('u8', 'i8'): # It was a byte
output.extend(to_byte(tA))
elif tB in ('u16', 'i16'):
output.extend(to_word(tA))
elif tB in ('u32', 'i32'):
output.extend(to_long(tA))
elif tB == 'f16':
output.extend(to_fixed(tA))
elif tB == 'f':
output.extend(to_float(tA))
xsB += sB % 2 # make it even (round up)
if xsB > 4:
output.extend(_fpush())
else:
if xsB > 2:
output.append('push de') # Fixed or 32 bit Integer
if sB > 1:
output.append('push hl') # 16 bit Integer
else:
output.append('push af') # 8 bit Integer
return output | python | def _cast(ins):
""" Convert data from typeA to typeB (only numeric data types)
"""
# 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', 'i16'):
output.extend(_16bit_oper(ins.quad[4]))
elif tA in ('u32', 'i32'):
output.extend(_32bit_oper(ins.quad[4]))
elif tA == 'f16':
output.extend(_f16_oper(ins.quad[4]))
elif tA == 'f':
output.extend(_float_oper(ins.quad[4]))
else:
raise errors.GenericError(
'Internal error: invalid typecast from %s to %s' % (tA, tB))
if tB in ('u8', 'i8'): # It was a byte
output.extend(to_byte(tA))
elif tB in ('u16', 'i16'):
output.extend(to_word(tA))
elif tB in ('u32', 'i32'):
output.extend(to_long(tA))
elif tB == 'f16':
output.extend(to_fixed(tA))
elif tB == 'f':
output.extend(to_float(tA))
xsB += sB % 2 # make it even (round up)
if xsB > 4:
output.extend(_fpush())
else:
if xsB > 2:
output.append('push de') # Fixed or 32 bit Integer
if sB > 1:
output.append('push hl') # 16 bit Integer
else:
output.append('push af') # 8 bit Integer
return output | [
"def",
"_cast",
"(",
"ins",
")",
":",
"# 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'",
",",
"'i16'",
")",
":",
"output",
".",
"extend",
"(",
"_16bit_oper",
"(",
"ins",
".",
"quad",
"[",
"4",
"]",
")",
")",
"elif",
"tA",
"in",
"(",
"'u32'",
",",
"'i32'",
")",
":",
"output",
".",
"extend",
"(",
"_32bit_oper",
"(",
"ins",
".",
"quad",
"[",
"4",
"]",
")",
")",
"elif",
"tA",
"==",
"'f16'",
":",
"output",
".",
"extend",
"(",
"_f16_oper",
"(",
"ins",
".",
"quad",
"[",
"4",
"]",
")",
")",
"elif",
"tA",
"==",
"'f'",
":",
"output",
".",
"extend",
"(",
"_float_oper",
"(",
"ins",
".",
"quad",
"[",
"4",
"]",
")",
")",
"else",
":",
"raise",
"errors",
".",
"GenericError",
"(",
"'Internal error: invalid typecast from %s to %s'",
"%",
"(",
"tA",
",",
"tB",
")",
")",
"if",
"tB",
"in",
"(",
"'u8'",
",",
"'i8'",
")",
":",
"# It was a byte",
"output",
".",
"extend",
"(",
"to_byte",
"(",
"tA",
")",
")",
"elif",
"tB",
"in",
"(",
"'u16'",
",",
"'i16'",
")",
":",
"output",
".",
"extend",
"(",
"to_word",
"(",
"tA",
")",
")",
"elif",
"tB",
"in",
"(",
"'u32'",
",",
"'i32'",
")",
":",
"output",
".",
"extend",
"(",
"to_long",
"(",
"tA",
")",
")",
"elif",
"tB",
"==",
"'f16'",
":",
"output",
".",
"extend",
"(",
"to_fixed",
"(",
"tA",
")",
")",
"elif",
"tB",
"==",
"'f'",
":",
"output",
".",
"extend",
"(",
"to_float",
"(",
"tA",
")",
")",
"xsB",
"+=",
"sB",
"%",
"2",
"# make it even (round up)",
"if",
"xsB",
">",
"4",
":",
"output",
".",
"extend",
"(",
"_fpush",
"(",
")",
")",
"else",
":",
"if",
"xsB",
">",
"2",
":",
"output",
".",
"append",
"(",
"'push de'",
")",
"# Fixed or 32 bit Integer",
"if",
"sB",
">",
"1",
":",
"output",
".",
"append",
"(",
"'push hl'",
")",
"# 16 bit Integer",
"else",
":",
"output",
".",
"append",
"(",
"'push af'",
")",
"# 8 bit Integer",
"return",
"output"
] | Convert data from typeA to typeB (only numeric data types) | [
"Convert",
"data",
"from",
"typeA",
"to",
"typeB",
"(",
"only",
"numeric",
"data",
"types",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L946-L995 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jzerof | def _jzerof(ins):
""" Jumps if top of the stack (40bit, float) is 0 to arg(1)
"""
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')
output.append('or d')
output.append('jp z, %s' % str(ins.quad[2]))
return output | python | def _jzerof(ins):
""" Jumps if top of the stack (40bit, float) is 0 to arg(1)
"""
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')
output.append('or d')
output.append('jp z, %s' % str(ins.quad[2]))
return output | [
"def",
"_jzerof",
"(",
"ins",
")",
":",
"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'",
")",
"output",
".",
"append",
"(",
"'or d'",
")",
"output",
".",
"append",
"(",
"'jp z, %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (40bit, float) is 0 to arg(1) | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"40bit",
"float",
")",
"is",
"0",
"to",
"arg",
"(",
"1",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1078-L1095 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jzerostr | def _jzerostr(ins):
""" Jumps if top of the stack contains a NULL pointer
or its len is Zero
"""
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.append('call __STRLEN')
if disposable:
output.append('ex (sp), hl')
output.append('call __MEM_FREE')
output.append('pop hl')
REQUIRES.add('alloc.asm')
output.append('ld a, h')
output.append('or l')
output.append('jp z, %s' % str(ins.quad[2]))
REQUIRES.add('strlen.asm')
return output | python | def _jzerostr(ins):
""" Jumps if top of the stack contains a NULL pointer
or its len is Zero
"""
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.append('call __STRLEN')
if disposable:
output.append('ex (sp), hl')
output.append('call __MEM_FREE')
output.append('pop hl')
REQUIRES.add('alloc.asm')
output.append('ld a, h')
output.append('or l')
output.append('jp z, %s' % str(ins.quad[2]))
REQUIRES.add('strlen.asm')
return output | [
"def",
"_jzerostr",
"(",
"ins",
")",
":",
"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",
".",
"append",
"(",
"'call __STRLEN'",
")",
"if",
"disposable",
":",
"output",
".",
"append",
"(",
"'ex (sp), hl'",
")",
"output",
".",
"append",
"(",
"'call __MEM_FREE'",
")",
"output",
".",
"append",
"(",
"'pop hl'",
")",
"REQUIRES",
".",
"add",
"(",
"'alloc.asm'",
")",
"output",
".",
"append",
"(",
"'ld a, h'",
")",
"output",
".",
"append",
"(",
"'or l'",
")",
"output",
".",
"append",
"(",
"'jp z, %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"REQUIRES",
".",
"add",
"(",
"'strlen.asm'",
")",
"return",
"output"
] | Jumps if top of the stack contains a NULL pointer
or its len is Zero | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"contains",
"a",
"NULL",
"pointer",
"or",
"its",
"len",
"is",
"Zero"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1098-L1124 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jnzero16 | def _jnzero16(ins):
""" Jumps if top of the stack (16bit) is != 0 to arg(1)
"""
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]))
return output | python | def _jnzero16(ins):
""" Jumps if top of the stack (16bit) is != 0 to arg(1)
"""
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]))
return output | [
"def",
"_jnzero16",
"(",
"ins",
")",
":",
"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",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (16bit) is != 0 to arg(1) | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"16bit",
")",
"is",
"!",
"=",
"0",
"to",
"arg",
"(",
"1",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1143-L1157 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jnzero32 | def _jnzero32(ins):
""" Jumps if top of the stack (32bit) is !=0 to arg(1)
"""
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')
output.append('jp nz, %s' % str(ins.quad[2]))
return output | python | def _jnzero32(ins):
""" Jumps if top of the stack (32bit) is !=0 to arg(1)
"""
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')
output.append('jp nz, %s' % str(ins.quad[2]))
return output | [
"def",
"_jnzero32",
"(",
"ins",
")",
":",
"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'",
")",
"output",
".",
"append",
"(",
"'jp nz, %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (32bit) is !=0 to arg(1) | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"32bit",
")",
"is",
"!",
"=",
"0",
"to",
"arg",
"(",
"1",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1160-L1176 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jnzerof16 | def _jnzerof16(ins):
""" Jumps if top of the stack (32bit) is !=0 to arg(1)
Fixed Point (16.16 bit) values.
"""
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')
output.append('jp nz, %s' % str(ins.quad[2]))
return output | python | def _jnzerof16(ins):
""" Jumps if top of the stack (32bit) is !=0 to arg(1)
Fixed Point (16.16 bit) values.
"""
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')
output.append('jp nz, %s' % str(ins.quad[2]))
return output | [
"def",
"_jnzerof16",
"(",
"ins",
")",
":",
"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'",
")",
"output",
".",
"append",
"(",
"'jp nz, %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (32bit) is !=0 to arg(1)
Fixed Point (16.16 bit) values. | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"32bit",
")",
"is",
"!",
"=",
"0",
"to",
"arg",
"(",
"1",
")",
"Fixed",
"Point",
"(",
"16",
".",
"16",
"bit",
")",
"values",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1179-L1196 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jgezerou8 | def _jgezerou8(ins):
""" Jumps if top of the stack (8bit) is >= 0 to arg(1)
Always TRUE for unsigned
"""
output = []
value = ins.quad[1]
if not is_int(value):
output = _8bit_oper(value)
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _jgezerou8(ins):
""" Jumps if top of the stack (8bit) is >= 0 to arg(1)
Always TRUE for unsigned
"""
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",
")",
":",
"output",
"=",
"[",
"]",
"value",
"=",
"ins",
".",
"quad",
"[",
"1",
"]",
"if",
"not",
"is_int",
"(",
"value",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"value",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (8bit) is >= 0 to arg(1)
Always TRUE for unsigned | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"8bit",
")",
"is",
">",
"=",
"0",
"to",
"arg",
"(",
"1",
")",
"Always",
"TRUE",
"for",
"unsigned"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1250-L1260 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jgezeroi8 | def _jgezeroi8(ins):
""" Jumps if top of the stack (8bit) is >= 0 to arg(1)
"""
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]))
return output | python | def _jgezeroi8(ins):
""" Jumps if top of the stack (8bit) is >= 0 to arg(1)
"""
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]))
return output | [
"def",
"_jgezeroi8",
"(",
"ins",
")",
":",
"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",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (8bit) is >= 0 to arg(1) | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"8bit",
")",
"is",
">",
"=",
"0",
"to",
"arg",
"(",
"1",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1263-L1276 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jgezerou16 | def _jgezerou16(ins):
""" Jumps if top of the stack (16bit) is >= 0 to arg(1)
Always TRUE for unsigned
"""
output = []
value = ins.quad[1]
if not is_int(value):
output = _16bit_oper(value)
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _jgezerou16(ins):
""" Jumps if top of the stack (16bit) is >= 0 to arg(1)
Always TRUE for unsigned
"""
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",
")",
":",
"output",
"=",
"[",
"]",
"value",
"=",
"ins",
".",
"quad",
"[",
"1",
"]",
"if",
"not",
"is_int",
"(",
"value",
")",
":",
"output",
"=",
"_16bit_oper",
"(",
"value",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (16bit) is >= 0 to arg(1)
Always TRUE for unsigned | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"16bit",
")",
"is",
">",
"=",
"0",
"to",
"arg",
"(",
"1",
")",
"Always",
"TRUE",
"for",
"unsigned"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1279-L1289 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _jgezerou32 | def _jgezerou32(ins):
""" Jumps if top of the stack (23bit) is >= 0 to arg(1)
Always TRUE for unsigned
"""
output = []
value = ins.quad[1]
if not is_int(value):
output = _32bit_oper(value)
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _jgezerou32(ins):
""" Jumps if top of the stack (23bit) is >= 0 to arg(1)
Always TRUE for unsigned
"""
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",
")",
":",
"output",
"=",
"[",
"]",
"value",
"=",
"ins",
".",
"quad",
"[",
"1",
"]",
"if",
"not",
"is_int",
"(",
"value",
")",
":",
"output",
"=",
"_32bit_oper",
"(",
"value",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Jumps if top of the stack (23bit) is >= 0 to arg(1)
Always TRUE for unsigned | [
"Jumps",
"if",
"top",
"of",
"the",
"stack",
"(",
"23bit",
")",
"is",
">",
"=",
"0",
"to",
"arg",
"(",
"1",
")",
"Always",
"TRUE",
"for",
"unsigned"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1308-L1318 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _ret8 | def _ret8(ins):
""" Returns from a procedure / function an 8bits value
"""
output = _8bit_oper(ins.quad[1])
output.append('#pragma opt require a')
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _ret8(ins):
""" Returns from a procedure / function an 8bits value
"""
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",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"append",
"(",
"'#pragma opt require a'",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Returns from a procedure / function an 8bits value | [
"Returns",
"from",
"a",
"procedure",
"/",
"function",
"an",
"8bits",
"value"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1374-L1380 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _ret16 | def _ret16(ins):
""" Returns from a procedure / function a 16bits value
"""
output = _16bit_oper(ins.quad[1])
output.append('#pragma opt require hl')
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _ret16(ins):
""" Returns from a procedure / function a 16bits value
"""
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",
")",
":",
"output",
"=",
"_16bit_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"append",
"(",
"'#pragma opt require hl'",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Returns from a procedure / function a 16bits value | [
"Returns",
"from",
"a",
"procedure",
"/",
"function",
"a",
"16bits",
"value"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1383-L1389 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _ret32 | def _ret32(ins):
""" Returns from a procedure / function a 32bits value (even Fixed point)
"""
output = _32bit_oper(ins.quad[1])
output.append('#pragma opt require hl,de')
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _ret32(ins):
""" Returns from a procedure / function a 32bits value (even Fixed point)
"""
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",
")",
":",
"output",
"=",
"_32bit_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"append",
"(",
"'#pragma opt require hl,de'",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Returns from a procedure / function a 32bits value (even Fixed point) | [
"Returns",
"from",
"a",
"procedure",
"/",
"function",
"a",
"32bits",
"value",
"(",
"even",
"Fixed",
"point",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1392-L1398 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _retf16 | def _retf16(ins):
""" Returns from a procedure / function a Fixed Point (32bits) value
"""
output = _f16_oper(ins.quad[1])
output.append('#pragma opt require hl,de')
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _retf16(ins):
""" Returns from a procedure / function a Fixed Point (32bits) value
"""
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",
")",
":",
"output",
"=",
"_f16_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"append",
"(",
"'#pragma opt require hl,de'",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Returns from a procedure / function a Fixed Point (32bits) value | [
"Returns",
"from",
"a",
"procedure",
"/",
"function",
"a",
"Fixed",
"Point",
"(",
"32bits",
")",
"value"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1401-L1407 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _retf | def _retf(ins):
""" Returns from a procedure / function a Floating Point (40bits) value
"""
output = _float_oper(ins.quad[1])
output.append('#pragma opt require a,bc,de')
output.append('jp %s' % str(ins.quad[2]))
return output | python | def _retf(ins):
""" Returns from a procedure / function a Floating Point (40bits) value
"""
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",
")",
":",
"output",
"=",
"_float_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"append",
"(",
"'#pragma opt require a,bc,de'",
")",
"output",
".",
"append",
"(",
"'jp %s'",
"%",
"str",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
")",
"return",
"output"
] | Returns from a procedure / function a Floating Point (40bits) value | [
"Returns",
"from",
"a",
"procedure",
"/",
"function",
"a",
"Floating",
"Point",
"(",
"40bits",
")",
"value"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1410-L1416 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _retstr | def _retstr(ins):
""" Returns from a procedure / function a string pointer (16bits) value
"""
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 | python | def _retstr(ins):
""" Returns from a procedure / function a string pointer (16bits) value
"""
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",
")",
":",
"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"
] | Returns from a procedure / function a string pointer (16bits) value | [
"Returns",
"from",
"a",
"procedure",
"/",
"function",
"a",
"string",
"pointer",
"(",
"16bits",
")",
"value"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1419-L1430 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _call | 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.
"""
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:
output.append('push de')
if val > 1:
output.append('push hl')
except ValueError:
pass
return output | python | 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.
"""
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:
output.append('push de')
if val > 1:
output.append('push hl')
except ValueError:
pass
return output | [
"def",
"_call",
"(",
"ins",
")",
":",
"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",
":",
"output",
".",
"append",
"(",
"'push de'",
")",
"if",
"val",
">",
"1",
":",
"output",
".",
"append",
"(",
"'push hl'",
")",
"except",
"ValueError",
":",
"pass",
"return",
"output"
] | Calls a function XXXX (or address XXXX)
2nd parameter contains size of the returning result if any, and will be
pushed onto the stack. | [
"Calls",
"a",
"function",
"XXXX",
"(",
"or",
"address",
"XXXX",
")",
"2nd",
"parameter",
"contains",
"size",
"of",
"the",
"returning",
"result",
"if",
"any",
"and",
"will",
"be",
"pushed",
"onto",
"the",
"stack",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1433-L1457 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _leave | def _leave(ins):
""" Return from a function popping N bytes from the stack
Use '__fastcall__' as 1st parameter, to just return
"""
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.append('ret')
return output
if nbytes == 1:
output.append('ld sp, ix')
output.append('pop ix')
output.append('inc sp') # "Pops" 1 byte
output.append('ret')
return output
if nbytes <= 11: # Number of bytes it worth the hassle to "pop" off the stack
output.append('ld sp, ix')
output.append('pop ix')
output.append('exx')
output.append('pop hl')
for i in range((nbytes >> 1) - 1):
output.append('pop bc') # Removes (n * 2 - 2) bytes form the stack
if nbytes & 1: # Odd?
output.append('inc sp') # "Pops" 1 byte (This should never happens, since params are always even-sized)
output.append('ex (sp), hl') # Place back return address
output.append('exx')
output.append('ret')
return output
if not FLAG_use_function_exit:
FLAG_use_function_exit = True # Use standard exit
output.append('exx')
output.append('ld hl, %i' % nbytes)
output.append('__EXIT_FUNCTION:')
output.append('ld sp, ix')
output.append('pop ix')
output.append('pop de')
output.append('add hl, sp')
output.append('ld sp, hl')
output.append('push de')
output.append('exx')
output.append('ret')
else:
output.append('exx')
output.append('ld hl, %i' % nbytes)
output.append('jp __EXIT_FUNCTION')
return output | python | def _leave(ins):
""" Return from a function popping N bytes from the stack
Use '__fastcall__' as 1st parameter, to just return
"""
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.append('ret')
return output
if nbytes == 1:
output.append('ld sp, ix')
output.append('pop ix')
output.append('inc sp') # "Pops" 1 byte
output.append('ret')
return output
if nbytes <= 11: # Number of bytes it worth the hassle to "pop" off the stack
output.append('ld sp, ix')
output.append('pop ix')
output.append('exx')
output.append('pop hl')
for i in range((nbytes >> 1) - 1):
output.append('pop bc') # Removes (n * 2 - 2) bytes form the stack
if nbytes & 1: # Odd?
output.append('inc sp') # "Pops" 1 byte (This should never happens, since params are always even-sized)
output.append('ex (sp), hl') # Place back return address
output.append('exx')
output.append('ret')
return output
if not FLAG_use_function_exit:
FLAG_use_function_exit = True # Use standard exit
output.append('exx')
output.append('ld hl, %i' % nbytes)
output.append('__EXIT_FUNCTION:')
output.append('ld sp, ix')
output.append('pop ix')
output.append('pop de')
output.append('add hl, sp')
output.append('ld sp, hl')
output.append('push de')
output.append('exx')
output.append('ret')
else:
output.append('exx')
output.append('ld hl, %i' % nbytes)
output.append('jp __EXIT_FUNCTION')
return output | [
"def",
"_leave",
"(",
"ins",
")",
":",
"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",
".",
"append",
"(",
"'ret'",
")",
"return",
"output",
"if",
"nbytes",
"==",
"1",
":",
"output",
".",
"append",
"(",
"'ld sp, ix'",
")",
"output",
".",
"append",
"(",
"'pop ix'",
")",
"output",
".",
"append",
"(",
"'inc sp'",
")",
"# \"Pops\" 1 byte",
"output",
".",
"append",
"(",
"'ret'",
")",
"return",
"output",
"if",
"nbytes",
"<=",
"11",
":",
"# Number of bytes it worth the hassle to \"pop\" off the stack",
"output",
".",
"append",
"(",
"'ld sp, ix'",
")",
"output",
".",
"append",
"(",
"'pop ix'",
")",
"output",
".",
"append",
"(",
"'exx'",
")",
"output",
".",
"append",
"(",
"'pop hl'",
")",
"for",
"i",
"in",
"range",
"(",
"(",
"nbytes",
">>",
"1",
")",
"-",
"1",
")",
":",
"output",
".",
"append",
"(",
"'pop bc'",
")",
"# Removes (n * 2 - 2) bytes form the stack",
"if",
"nbytes",
"&",
"1",
":",
"# Odd?",
"output",
".",
"append",
"(",
"'inc sp'",
")",
"# \"Pops\" 1 byte (This should never happens, since params are always even-sized)",
"output",
".",
"append",
"(",
"'ex (sp), hl'",
")",
"# Place back return address",
"output",
".",
"append",
"(",
"'exx'",
")",
"output",
".",
"append",
"(",
"'ret'",
")",
"return",
"output",
"if",
"not",
"FLAG_use_function_exit",
":",
"FLAG_use_function_exit",
"=",
"True",
"# Use standard exit",
"output",
".",
"append",
"(",
"'exx'",
")",
"output",
".",
"append",
"(",
"'ld hl, %i'",
"%",
"nbytes",
")",
"output",
".",
"append",
"(",
"'__EXIT_FUNCTION:'",
")",
"output",
".",
"append",
"(",
"'ld sp, ix'",
")",
"output",
".",
"append",
"(",
"'pop ix'",
")",
"output",
".",
"append",
"(",
"'pop de'",
")",
"output",
".",
"append",
"(",
"'add hl, sp'",
")",
"output",
".",
"append",
"(",
"'ld sp, hl'",
")",
"output",
".",
"append",
"(",
"'push de'",
")",
"output",
".",
"append",
"(",
"'exx'",
")",
"output",
".",
"append",
"(",
"'ret'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'exx'",
")",
"output",
".",
"append",
"(",
"'ld hl, %i'",
"%",
"nbytes",
")",
"output",
".",
"append",
"(",
"'jp __EXIT_FUNCTION'",
")",
"return",
"output"
] | Return from a function popping N bytes from the stack
Use '__fastcall__' as 1st parameter, to just return | [
"Return",
"from",
"a",
"function",
"popping",
"N",
"bytes",
"from",
"the",
"stack",
"Use",
"__fastcall__",
"as",
"1st",
"parameter",
"to",
"just",
"return"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1460-L1524 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _enter | 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).
"""
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.extend(['push hl'] * (size_bytes >> 1))
if size_bytes % 2: # odd?
output.append('push hl')
output.append('inc sp')
else:
output.append('ld hl, -%i' % size_bytes) # "Pushes nn bytes"
output.append('add hl, sp')
output.append('ld sp, hl')
output.append('ld (hl), 0')
output.append('ld bc, %i' % (size_bytes - 1))
output.append('ld d, h')
output.append('ld e, l')
output.append('inc de')
output.append('ldir') # Clear with ZEROs
return output | python | 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).
"""
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.extend(['push hl'] * (size_bytes >> 1))
if size_bytes % 2: # odd?
output.append('push hl')
output.append('inc sp')
else:
output.append('ld hl, -%i' % size_bytes) # "Pushes nn bytes"
output.append('add hl, sp')
output.append('ld sp, hl')
output.append('ld (hl), 0')
output.append('ld bc, %i' % (size_bytes - 1))
output.append('ld d, h')
output.append('ld e, l')
output.append('inc de')
output.append('ldir') # Clear with ZEROs
return output | [
"def",
"_enter",
"(",
"ins",
")",
":",
"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",
".",
"extend",
"(",
"[",
"'push hl'",
"]",
"*",
"(",
"size_bytes",
">>",
"1",
")",
")",
"if",
"size_bytes",
"%",
"2",
":",
"# odd?",
"output",
".",
"append",
"(",
"'push hl'",
")",
"output",
".",
"append",
"(",
"'inc sp'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'ld hl, -%i'",
"%",
"size_bytes",
")",
"# \"Pushes nn bytes\"",
"output",
".",
"append",
"(",
"'add hl, sp'",
")",
"output",
".",
"append",
"(",
"'ld sp, hl'",
")",
"output",
".",
"append",
"(",
"'ld (hl), 0'",
")",
"output",
".",
"append",
"(",
"'ld bc, %i'",
"%",
"(",
"size_bytes",
"-",
"1",
")",
")",
"output",
".",
"append",
"(",
"'ld d, h'",
")",
"output",
".",
"append",
"(",
"'ld e, l'",
")",
"output",
".",
"append",
"(",
"'inc de'",
")",
"output",
".",
"append",
"(",
"'ldir'",
")",
"# Clear with ZEROs",
"return",
"output"
] | 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). | [
"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",
")",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1527-L1563 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _param32 | def _param32(ins):
""" Pushes 32bit param into the stack
"""
output = _32bit_oper(ins.quad[1])
output.append('push de')
output.append('push hl')
return output | python | def _param32(ins):
""" Pushes 32bit param into the stack
"""
output = _32bit_oper(ins.quad[1])
output.append('push de')
output.append('push hl')
return output | [
"def",
"_param32",
"(",
"ins",
")",
":",
"output",
"=",
"_32bit_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"append",
"(",
"'push de'",
")",
"output",
".",
"append",
"(",
"'push hl'",
")",
"return",
"output"
] | Pushes 32bit param into the stack | [
"Pushes",
"32bit",
"param",
"into",
"the",
"stack"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1582-L1588 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _paramf16 | def _paramf16(ins):
""" Pushes 32bit fixed point param into the stack
"""
output = _f16_oper(ins.quad[1])
output.append('push de')
output.append('push hl')
return output | python | def _paramf16(ins):
""" Pushes 32bit fixed point param into the stack
"""
output = _f16_oper(ins.quad[1])
output.append('push de')
output.append('push hl')
return output | [
"def",
"_paramf16",
"(",
"ins",
")",
":",
"output",
"=",
"_f16_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"append",
"(",
"'push de'",
")",
"output",
".",
"append",
"(",
"'push hl'",
")",
"return",
"output"
] | Pushes 32bit fixed point param into the stack | [
"Pushes",
"32bit",
"fixed",
"point",
"param",
"into",
"the",
"stack"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1591-L1597 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _paramf | def _paramf(ins):
""" Pushes 40bit (float) param into the stack
"""
output = _float_oper(ins.quad[1])
output.extend(_fpush())
return output | python | def _paramf(ins):
""" Pushes 40bit (float) param into the stack
"""
output = _float_oper(ins.quad[1])
output.extend(_fpush())
return output | [
"def",
"_paramf",
"(",
"ins",
")",
":",
"output",
"=",
"_float_oper",
"(",
"ins",
".",
"quad",
"[",
"1",
"]",
")",
"output",
".",
"extend",
"(",
"_fpush",
"(",
")",
")",
"return",
"output"
] | Pushes 40bit (float) param into the stack | [
"Pushes",
"40bit",
"(",
"float",
")",
"param",
"into",
"the",
"stack"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1600-L1605 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _paramstr | 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 :-)
"""
(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('push hl')
return output | python | 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 :-)
"""
(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('push hl')
return output | [
"def",
"_paramstr",
"(",
"ins",
")",
":",
"(",
"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",
"(",
"'push hl'",
")",
"return",
"output"
] | Pushes an 16 bit unsigned value, which points
to a string. For indirect values, it will push
the pointer to the pointer :-) | [
"Pushes",
"an",
"16",
"bit",
"unsigned",
"value",
"which",
"points",
"to",
"a",
"string",
".",
"For",
"indirect",
"values",
"it",
"will",
"push",
"the",
"pointer",
"to",
"the",
"pointer",
":",
"-",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1608-L1622 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _memcopy | def _memcopy(ins):
""" Copies a block of memory from param 2 addr
to param 1 addr.
"""
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 | python | def _memcopy(ins):
""" Copies a block of memory from param 2 addr
to param 1 addr.
"""
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",
")",
":",
"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"
] | Copies a block of memory from param 2 addr
to param 1 addr. | [
"Copies",
"a",
"block",
"of",
"memory",
"from",
"param",
"2",
"addr",
"to",
"param",
"1",
"addr",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1681-L1691 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | _inline | def _inline(ins):
""" Inline code
"""
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
continue
match = RE_LABEL.match(tmp[i])
if not match:
tmp[i] = '\t' + tmp[i]
i += 1
continue
if len(tmp[i][-1]) == ':':
i += 1
continue # This is already a single label
tmp[i] = tmp[i][match.end() + 1:].strip(' \n')
tmp.insert(i, match.group())
i += 1
output = []
if not tmp:
return output
ASMLABEL = new_ASMID()
ASMS[ASMLABEL] = tmp
output.append('#line %s' % ins.quad[2])
output.append(ASMLABEL)
output.append('#line %i' % (int(ins.quad[2]) + len(tmp)))
return output | python | def _inline(ins):
""" Inline code
"""
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
continue
match = RE_LABEL.match(tmp[i])
if not match:
tmp[i] = '\t' + tmp[i]
i += 1
continue
if len(tmp[i][-1]) == ':':
i += 1
continue # This is already a single label
tmp[i] = tmp[i][match.end() + 1:].strip(' \n')
tmp.insert(i, match.group())
i += 1
output = []
if not tmp:
return output
ASMLABEL = new_ASMID()
ASMS[ASMLABEL] = tmp
output.append('#line %s' % ins.quad[2])
output.append(ASMLABEL)
output.append('#line %i' % (int(ins.quad[2]) + len(tmp)))
return output | [
"def",
"_inline",
"(",
"ins",
")",
":",
"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",
"continue",
"match",
"=",
"RE_LABEL",
".",
"match",
"(",
"tmp",
"[",
"i",
"]",
")",
"if",
"not",
"match",
":",
"tmp",
"[",
"i",
"]",
"=",
"'\\t'",
"+",
"tmp",
"[",
"i",
"]",
"i",
"+=",
"1",
"continue",
"if",
"len",
"(",
"tmp",
"[",
"i",
"]",
"[",
"-",
"1",
"]",
")",
"==",
"':'",
":",
"i",
"+=",
"1",
"continue",
"# This is already a single label",
"tmp",
"[",
"i",
"]",
"=",
"tmp",
"[",
"i",
"]",
"[",
"match",
".",
"end",
"(",
")",
"+",
"1",
":",
"]",
".",
"strip",
"(",
"' \\n'",
")",
"tmp",
".",
"insert",
"(",
"i",
",",
"match",
".",
"group",
"(",
")",
")",
"i",
"+=",
"1",
"output",
"=",
"[",
"]",
"if",
"not",
"tmp",
":",
"return",
"output",
"ASMLABEL",
"=",
"new_ASMID",
"(",
")",
"ASMS",
"[",
"ASMLABEL",
"]",
"=",
"tmp",
"output",
".",
"append",
"(",
"'#line %s'",
"%",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"append",
"(",
"ASMLABEL",
")",
"output",
".",
"append",
"(",
"'#line %i'",
"%",
"(",
"int",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"+",
"len",
"(",
"tmp",
")",
")",
")",
"return",
"output"
] | Inline code | [
"Inline",
"code"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L1694-L1733 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | convertToBool | def convertToBool():
""" Convert a byte value to boolean (0 or 1) if
the global flag strictBool is True
"""
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 | python | def convertToBool():
""" Convert a byte value to boolean (0 or 1) if
the global flag strictBool is True
"""
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",
"(",
")",
":",
"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"
] | Convert a byte value to boolean (0 or 1) if
the global flag strictBool is True | [
"Convert",
"a",
"byte",
"value",
"to",
"boolean",
"(",
"0",
"or",
"1",
")",
"if",
"the",
"global",
"flag",
"strictBool",
"is",
"True"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L2193-L2207 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | emit_end | def emit_end(MEMORY=None):
""" This special ending autoinitializes required inits
(mainly alloc.asm) and changes the MEMORY initial address if it is
ORG XXXX to ORG XXXX + heap size
"""
output = []
output.extend(AT_END)
if REQUIRES.intersection(MEMINITS) or '__MEM_INIT' in INITS:
output.append(OPTIONS.heap_start_label.value + ':')
output.append('; Defines DATA END\n' + 'ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP + ZXBASIC_HEAP_SIZE')
else:
output.append('; Defines DATA END --> HEAP size is 0\n' + 'ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP')
output.append('; Defines USER DATA Length in bytes\n' +
'ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA')
if OPTIONS.autorun.value:
output.append('END %s' % START_LABEL)
else:
output.append('END')
return output | python | def emit_end(MEMORY=None):
""" This special ending autoinitializes required inits
(mainly alloc.asm) and changes the MEMORY initial address if it is
ORG XXXX to ORG XXXX + heap size
"""
output = []
output.extend(AT_END)
if REQUIRES.intersection(MEMINITS) or '__MEM_INIT' in INITS:
output.append(OPTIONS.heap_start_label.value + ':')
output.append('; Defines DATA END\n' + 'ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP + ZXBASIC_HEAP_SIZE')
else:
output.append('; Defines DATA END --> HEAP size is 0\n' + 'ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP')
output.append('; Defines USER DATA Length in bytes\n' +
'ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA')
if OPTIONS.autorun.value:
output.append('END %s' % START_LABEL)
else:
output.append('END')
return output | [
"def",
"emit_end",
"(",
"MEMORY",
"=",
"None",
")",
":",
"output",
"=",
"[",
"]",
"output",
".",
"extend",
"(",
"AT_END",
")",
"if",
"REQUIRES",
".",
"intersection",
"(",
"MEMINITS",
")",
"or",
"'__MEM_INIT'",
"in",
"INITS",
":",
"output",
".",
"append",
"(",
"OPTIONS",
".",
"heap_start_label",
".",
"value",
"+",
"':'",
")",
"output",
".",
"append",
"(",
"'; Defines DATA END\\n'",
"+",
"'ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP + ZXBASIC_HEAP_SIZE'",
")",
"else",
":",
"output",
".",
"append",
"(",
"'; Defines DATA END --> HEAP size is 0\\n'",
"+",
"'ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP'",
")",
"output",
".",
"append",
"(",
"'; Defines USER DATA Length in bytes\\n'",
"+",
"'ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA'",
")",
"if",
"OPTIONS",
".",
"autorun",
".",
"value",
":",
"output",
".",
"append",
"(",
"'END %s'",
"%",
"START_LABEL",
")",
"else",
":",
"output",
".",
"append",
"(",
"'END'",
")",
"return",
"output"
] | This special ending autoinitializes required inits
(mainly alloc.asm) and changes the MEMORY initial address if it is
ORG XXXX to ORG XXXX + heap size | [
"This",
"special",
"ending",
"autoinitializes",
"required",
"inits",
"(",
"mainly",
"alloc",
".",
"asm",
")",
"and",
"changes",
"the",
"MEMORY",
"initial",
"address",
"if",
"it",
"is",
"ORG",
"XXXX",
"to",
"ORG",
"XXXX",
"+",
"heap",
"size"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L2210-L2232 |
boriel/zxbasic | arch/zx48k/backend/__init__.py | emit | def emit(mem):
""" Begin converting each quad instruction to asm
by iterating over the "mem" array, and called its
associated function. Each function returns an array of
ASM instructions which will be appended to the
'output' array
"""
def output_join(output, new_chunk):
""" Extends output instruction list
performing a little peep-hole optimization
"""
changed = True and OPTIONS.optimization.value > 0 # Only enter here if -O0 was not set
while changed and new_chunk:
if output:
a1 = output[-1] # Last output instruction
i1 = inst(a1)
o1 = oper(a1)
else:
a1 = i1 = o1 = None
if len(output) > 1:
a0 = output[-2]
i0 = inst(a0)
o0 = oper(a0)
else:
a0 = i0 = o0 = None
a2 = new_chunk[0] # Fist new output instruction
i2 = inst(a2)
o2 = oper(a2)
if OPT00 and i2[-1] == ':':
# Ok, a2 is a label
# check if the above starts with jr / jp
if i1 in ('jp', 'jr') and o1[0] == i2[:-1]:
# Ok remove the above instruction
output.pop()
changed = True
continue
if OPT01 and i1 == 'push' and i2 == 'pop' and o1[0] == o2[0]:
# Ok, we have a push/pop sequence which refers to
# the same register pairs
# Ok, remove these instructions (both)
output.pop()
new_chunk = new_chunk[1:]
changed = True
continue
if (
OPT03 and
(i1 == 'sbc' and
o1[0] == o1[1] == 'a' and
i2 == 'or' and
o2[0] == 'a' and
len(new_chunk) > 1)
):
a3 = new_chunk[1]
i3 = inst(a3)
o3 = oper(a3)
c = condition(a3)
if i3 in ('jp', 'jr') and c in ('z', 'nz'):
c = 'nc' if c == 'z' else 'c'
changed = True
output.pop()
new_chunk.pop(0)
new_chunk[0] = '%s %s, %s' % (i3, c, o3[0])
continue
if OPT04 and i1 == 'push' and i2 == 'pop':
if 'af' in (o1[0], o2[0]):
output.pop()
new_chunk[0] = 'ld %s, %s' % (o2[0][0], o1[0][0])
changed = True
continue
if o1[0] in ('hl', 'de') and o2[0] in ('hl', 'de'):
# push hl; push de; pop hl; pop de || push de; push hl; pop de; pop hl => ex de, hl
if len(new_chunk) > 1 and len(output) > 1 and oper(new_chunk[1])[0] == o1[0] and \
o2[0] == oper(output[-2])[0] and \
inst(output[-2]) == 'push' and inst(new_chunk[1]) == 'pop':
output.pop()
new_chunk.pop(0)
new_chunk.pop(0)
output[-1] = 'ex de, hl'
changed = True
continue
# push hl; pop de || push de ; pop hl
if len(new_chunk) > 1 and inst(new_chunk[1]) in ('pop', 'ld') and oper(new_chunk[1])[0] == o1[0]:
output.pop()
new_chunk[0] = 'ex de, hl'
changed = True
continue
if o1[0] not in ('ix', 'iy') and o2[0] not in ('ix', 'iy'):
# Change push XX, pop YY sequence with ld Yh, Xl; ld Yl, Xl
output.pop()
new_chunk = ['ld %s, %s' % (o2[0][0], o1[0][0])] + new_chunk
new_chunk[1] = 'ld %s, %s' % (o2[0][1], o1[0][1])
changed = True
continue
# ex af, af'; ex af, af' => <nothing>
# ex de, hl ; ex de, hl => <nothing>
if OPT16 and i1 == i2 == 'ex' and o1 == o2:
output.pop()
new_chunk.pop(0)
changed = True
continue
# Tries to optimize:
# jp <condition>, LABEL
# jp OTHER
# LABEL:
# into
# JP !<condition>, OTHER
# LABEL:
if OPT17 and len(output) > 1:
if i0 == i1 == 'jp' \
and i2[-1] == ':' \
and condition(a0) in {'c', 'nc', 'z', 'nz'} \
and condition(a1) is None \
and a2[:-1] in o0:
output.pop()
output.pop()
new_chunk = ['jp %s, %s' % ({'c': 'nc',
'z': 'nz',
'nc': 'c',
'nz': 'z'}[condition(a0)], o1[0])] + new_chunk
changed = True
continue
# Tries to optimize a == b for U/Integers
# call __EQ16
# or a
# jp nz, ...
# into:
# or a
# sbc hl, de
# jp z, ...
if OPT18 and i1 == 'call' and o1[0] == '__EQ16' \
and i2 in {'or', 'and'} and o2[0] == 'a' \
and len(new_chunk) > 1:
a3 = new_chunk[1]
i3 = inst(a3)
c3 = condition(a3)
if i3 == 'jp' and c3 in {'z', 'nz'}:
cond = 'z' if c3 == 'nz' else 'nz'
new_chunk[1] = 'jp %s, %s' % (cond, oper(a3)[0])
output.pop()
new_chunk.insert(1, 'sbc hl, de')
changed = True
continue
# Tries to optimize a == b for U/Bytes
# sub N
# sub 1
# jp nc, __LABEL
# into:
# sub N
# or a
# jp nz, __LABEL
if OPT19 and i1 == 'sub' and '1' in o1 and i2 == 'jp' and len(output) > 1:
c2 = condition(new_chunk[0])
if c2 in {'c', 'nc'}:
cond = 'z' if c2 == 'c' else 'nz'
new_chunk[0] = 'jp %s, %s' % (cond, o2[0])
if i0 in ('sub', 'dec'):
output.pop()
else:
output[-1] = 'or a'
changed = True
continue
# Removes useless or a from sequence:
# sub X
# or a
# jp z/nz ...
if OPT21 and i1 == 'sub' and i2 in {'or', 'and'} and o2[0] == 'a':
new_chunk.pop(0)
changed = True
continue
# Converts:
# ld a, (ix +/- n)
# ld r, a
# pop af
# Into:
# pop af
# ld r, (ix +/- n)
if OPT22 and len(output) > 1 and i1 == 'ld' and o1[0] in 'bcdehl' and o1[1] == 'a' and \
(i2, o2) == ('pop', ['af', 'sp']):
if (i0, o0[:1]) == ('ld', ['a']) and RE_IX_IDX.match(o0[1]):
output.pop() # Removes ld r, a
output.pop() # Removes ld a, (ix + n)
new_chunk.insert(1, 'ld %s, %s' % (o1[0], o0[1])) # Inserts 'ld r, (ix + n)' after 'pop af'
changed = True
continue
# Converts:
# ld hl, (NN) | ld hl, NN | pop hl
# ld b, h
# ld c, l
# in a, (c)
# Into:
# ld bc, (NN) | ld bc, NN | pop bc
# in a, (c)
if OPT23 and len(new_chunk) > 3 and inst(new_chunk[3]) == 'in':
ia = inst(new_chunk[1])
oa = oper(new_chunk[1])
ib = inst(new_chunk[2])
ob = oper(new_chunk[2])
if (ia, oa[0], oa[1], ib, ob[0], ob[1]) == ('ld', 'b', 'h', 'ld', 'c', 'l'):
ii = inst(new_chunk[0])
oi = oper(new_chunk[0])
if ii in ('pop', 'ld') and oi[0] == 'hl':
new_chunk[0] = ii + ' ' + 'bc' + (', %s' % oi[1] if ii == 'ld' else '')
new_chunk.pop(1)
new_chunk.pop(1)
changed = True
continue
# Converts:
# ld hl, (NN) | ld hl, NN | pop hl
# ld b, h
# ld c, l
# out (c), a
# Into:
# ld bc, (NN) | ld bc, NN | pop bc
# out (c), a
if OPT23 and len(new_chunk) > 3 and inst(new_chunk[-1]) == 'out':
ia = inst(new_chunk[-3])
oa = oper(new_chunk[-3])
ib = inst(new_chunk[-2])
ob = oper(new_chunk[-2])
if (ia, oa[0], oa[1], ib, ob[0], ob[1]) == ('ld', 'b', 'h', 'ld', 'c', 'l'):
ii = inst(new_chunk[-4])
oi = oper(new_chunk[-4])
if ii in ('pop', 'ld') and oi[0] == 'hl':
new_chunk[-4] = ii + ' ' + 'bc' + (', %s' % oi[1] if ii == 'ld' else '')
new_chunk.pop(-2)
new_chunk.pop(-2)
changed = True
continue
# Converts:
# or X | and X
# or a | and a
# Into:
# or X | and X
if OPT24 and i1 in ('and', 'or') and new_chunk[0] in ('or a', 'and a'):
new_chunk.pop(0)
changed = True
continue
# Converts:
# ld h, X (X != A)
# ld a, Y
# or/and/cp/add/sub h
# Into:
# ld a, Y
# or/and/cp X
if OPT25 and \
(i1 in ('cp', 'or', 'and') and o1[0] == 'h' or
i1 in ('sub', 'add', 'sbc', 'adc') and o1[1] == 'h') \
and i0 == 'ld' and o0[0] == 'a' and len(output) > 2:
ii = inst(output[-3])
oo = oper(output[-3])
if i1 in ('add', 'adc', 'sbc'):
i1 = i1 + ' a,'
if ii == 'ld' and oo[0] == 'h' and oo[1] != 'a':
output[-1] = '{0} {1}'.format(i1, oo[1])
output.pop(-3)
changed = True
continue
# Converts:
# ld a, (nn) | ld a, (ix+N)
# inc/dec a
# ld (nn), a | ld (ix+N), a
# Into:
# ld hl, _n | <removed>
# inc/dec (hl) | inc/dec (ix+N)
if OPT26 and i1 in ('inc', 'dec') and o1[0] == 'a' and i0 == i2 == 'ld' and \
(o0[0], o0[1]) == (o2[1], o2[0]) and o0[1][0] == '(':
new_chunk.pop(0)
if RE_IX_IDX.match(o0[1]):
output[-1] = '{0} {1}'.format(i1, o0[1])
output.pop(-2)
else:
output[-1] = '{0} (hl)'.format(i1)
output[-2] = 'ld hl, {0}'.format(o0[1][1:-1])
changed = True
continue
# Converts:
# ld X, Y
# ld Y, X
# Into:
# ld X, Y
if OPT02 and i1 == i2 == 'ld' and o1[0] == o2[1] and o2[0] == o1[1]:
# This and previous instruction are LD X, Y
# Ok, previous instruction is LD A, B and current is LD B, A. Remove this one.
new_chunk = new_chunk[1:]
changed = True
continue
# Converts:
# ld h, X
# or/and h
# Into:
# or/and X
if OPT27 and i1 == 'ld' and o1[0] == 'h' and i2 in ('and', 'or') and o2[0] == 'h':
output.pop()
new_chunk[0] = '{0} {1}'.format(i2, o1[1])
changed = True
continue
# Converts
# ld a, r|(ix+/-N)|(hl)
# ld h, a
# ld a, XXX | pop af
# Into:
# ld h, r|(ix+/-N)|(hl)
# ld a, XXX | pop af
if OPT28 and i1 == i0 == 'ld' and o0[0] == 'a' and \
(o0[1] in ('a', 'b', 'c', 'd', 'e', 'h', 'l', '(hl)') or RE_IX_IDX.match(o0[1])) and \
(o1[0], o1[1]) == ('h', 'a') and new_chunk and (new_chunk[0] == 'pop af' or
i2 == 'ld' and o2[0] == 'a'):
output.pop()
output[-1] = 'ld h, {0}'.format(o0[1])
changed = True
continue
# Converts:
# cp 0
# Into:
# or a
if OPT29 and i1 == 'cp' and o1[0] == '0':
output[-1] = 'or a'
changed = True
continue
# Converts:
# or/and X
# jp c/nc XXX
# Into:
# <nothing>/jp XXX
if OPT30 and i1 in ('and', 'or') and i2 == 'jp':
c = condition(new_chunk[0])
if c in ('c', 'nc'):
output.pop()
if c == 'nc':
new_chunk[0] = 'jp {0}'.format(o2[0])
else:
new_chunk.pop(0)
changed = True
continue
# Converts
# jp XXX
# <any inst>
# Into:
# jp XXX
if OPT31 and i1 == 'jp' and not condition(output[-1]) and i2 is not None and \
i2[-1] != ':' and new_chunk[0] not in ASMS:
new_chunk.pop(0)
changed = True
continue
# Converts:
# call __LOADSTR
# ld a, 1
# call __PRINSTR
# Into:
# xor a
# call __PRINTSTR
if OPT32 and i0 == 'call' and o0[0] == '__LOADSTR' and i1 == 'ld' and tuple(o1) == ('a', '1') and \
i2 == 'call' and o2[0] == '__PRINTSTR':
output.pop(-2)
output[-1] = 'xor a'
changed = True
continue
changed, new_chunk = optiblock(new_chunk)
output.extend(new_chunk)
output = []
for i in mem:
output_join(output, QUADS[i.quad[0]][1](i))
if RE_BOOL.match(i.quad[0]): # If it is a boolean operation convert it to 0/1 if the STRICT_BOOL flag is True
output_join(output, convertToBool())
changed = OPTIONS.optimization.value > 1
while changed:
to_remove = []
for i, ins in enumerate(output):
ins = ins[:-1]
if ins not in TMP_LABELS:
continue
for j, ins2 in enumerate(output):
if j == i:
continue
if ins in oper(ins2):
break
else:
to_remove.append(i)
changed = len(to_remove) > 0
to_remove.reverse()
for i in to_remove:
output.pop(i)
tmp = output
output = []
for i in tmp:
output_join(output, [i])
for i in sorted(REQUIRES):
output.append('#include once <%s>' % i)
return output | python | def emit(mem):
""" Begin converting each quad instruction to asm
by iterating over the "mem" array, and called its
associated function. Each function returns an array of
ASM instructions which will be appended to the
'output' array
"""
def output_join(output, new_chunk):
""" Extends output instruction list
performing a little peep-hole optimization
"""
changed = True and OPTIONS.optimization.value > 0 # Only enter here if -O0 was not set
while changed and new_chunk:
if output:
a1 = output[-1] # Last output instruction
i1 = inst(a1)
o1 = oper(a1)
else:
a1 = i1 = o1 = None
if len(output) > 1:
a0 = output[-2]
i0 = inst(a0)
o0 = oper(a0)
else:
a0 = i0 = o0 = None
a2 = new_chunk[0] # Fist new output instruction
i2 = inst(a2)
o2 = oper(a2)
if OPT00 and i2[-1] == ':':
# Ok, a2 is a label
# check if the above starts with jr / jp
if i1 in ('jp', 'jr') and o1[0] == i2[:-1]:
# Ok remove the above instruction
output.pop()
changed = True
continue
if OPT01 and i1 == 'push' and i2 == 'pop' and o1[0] == o2[0]:
# Ok, we have a push/pop sequence which refers to
# the same register pairs
# Ok, remove these instructions (both)
output.pop()
new_chunk = new_chunk[1:]
changed = True
continue
if (
OPT03 and
(i1 == 'sbc' and
o1[0] == o1[1] == 'a' and
i2 == 'or' and
o2[0] == 'a' and
len(new_chunk) > 1)
):
a3 = new_chunk[1]
i3 = inst(a3)
o3 = oper(a3)
c = condition(a3)
if i3 in ('jp', 'jr') and c in ('z', 'nz'):
c = 'nc' if c == 'z' else 'c'
changed = True
output.pop()
new_chunk.pop(0)
new_chunk[0] = '%s %s, %s' % (i3, c, o3[0])
continue
if OPT04 and i1 == 'push' and i2 == 'pop':
if 'af' in (o1[0], o2[0]):
output.pop()
new_chunk[0] = 'ld %s, %s' % (o2[0][0], o1[0][0])
changed = True
continue
if o1[0] in ('hl', 'de') and o2[0] in ('hl', 'de'):
# push hl; push de; pop hl; pop de || push de; push hl; pop de; pop hl => ex de, hl
if len(new_chunk) > 1 and len(output) > 1 and oper(new_chunk[1])[0] == o1[0] and \
o2[0] == oper(output[-2])[0] and \
inst(output[-2]) == 'push' and inst(new_chunk[1]) == 'pop':
output.pop()
new_chunk.pop(0)
new_chunk.pop(0)
output[-1] = 'ex de, hl'
changed = True
continue
# push hl; pop de || push de ; pop hl
if len(new_chunk) > 1 and inst(new_chunk[1]) in ('pop', 'ld') and oper(new_chunk[1])[0] == o1[0]:
output.pop()
new_chunk[0] = 'ex de, hl'
changed = True
continue
if o1[0] not in ('ix', 'iy') and o2[0] not in ('ix', 'iy'):
# Change push XX, pop YY sequence with ld Yh, Xl; ld Yl, Xl
output.pop()
new_chunk = ['ld %s, %s' % (o2[0][0], o1[0][0])] + new_chunk
new_chunk[1] = 'ld %s, %s' % (o2[0][1], o1[0][1])
changed = True
continue
# ex af, af'; ex af, af' => <nothing>
# ex de, hl ; ex de, hl => <nothing>
if OPT16 and i1 == i2 == 'ex' and o1 == o2:
output.pop()
new_chunk.pop(0)
changed = True
continue
# Tries to optimize:
# jp <condition>, LABEL
# jp OTHER
# LABEL:
# into
# JP !<condition>, OTHER
# LABEL:
if OPT17 and len(output) > 1:
if i0 == i1 == 'jp' \
and i2[-1] == ':' \
and condition(a0) in {'c', 'nc', 'z', 'nz'} \
and condition(a1) is None \
and a2[:-1] in o0:
output.pop()
output.pop()
new_chunk = ['jp %s, %s' % ({'c': 'nc',
'z': 'nz',
'nc': 'c',
'nz': 'z'}[condition(a0)], o1[0])] + new_chunk
changed = True
continue
# Tries to optimize a == b for U/Integers
# call __EQ16
# or a
# jp nz, ...
# into:
# or a
# sbc hl, de
# jp z, ...
if OPT18 and i1 == 'call' and o1[0] == '__EQ16' \
and i2 in {'or', 'and'} and o2[0] == 'a' \
and len(new_chunk) > 1:
a3 = new_chunk[1]
i3 = inst(a3)
c3 = condition(a3)
if i3 == 'jp' and c3 in {'z', 'nz'}:
cond = 'z' if c3 == 'nz' else 'nz'
new_chunk[1] = 'jp %s, %s' % (cond, oper(a3)[0])
output.pop()
new_chunk.insert(1, 'sbc hl, de')
changed = True
continue
# Tries to optimize a == b for U/Bytes
# sub N
# sub 1
# jp nc, __LABEL
# into:
# sub N
# or a
# jp nz, __LABEL
if OPT19 and i1 == 'sub' and '1' in o1 and i2 == 'jp' and len(output) > 1:
c2 = condition(new_chunk[0])
if c2 in {'c', 'nc'}:
cond = 'z' if c2 == 'c' else 'nz'
new_chunk[0] = 'jp %s, %s' % (cond, o2[0])
if i0 in ('sub', 'dec'):
output.pop()
else:
output[-1] = 'or a'
changed = True
continue
# Removes useless or a from sequence:
# sub X
# or a
# jp z/nz ...
if OPT21 and i1 == 'sub' and i2 in {'or', 'and'} and o2[0] == 'a':
new_chunk.pop(0)
changed = True
continue
# Converts:
# ld a, (ix +/- n)
# ld r, a
# pop af
# Into:
# pop af
# ld r, (ix +/- n)
if OPT22 and len(output) > 1 and i1 == 'ld' and o1[0] in 'bcdehl' and o1[1] == 'a' and \
(i2, o2) == ('pop', ['af', 'sp']):
if (i0, o0[:1]) == ('ld', ['a']) and RE_IX_IDX.match(o0[1]):
output.pop() # Removes ld r, a
output.pop() # Removes ld a, (ix + n)
new_chunk.insert(1, 'ld %s, %s' % (o1[0], o0[1])) # Inserts 'ld r, (ix + n)' after 'pop af'
changed = True
continue
# Converts:
# ld hl, (NN) | ld hl, NN | pop hl
# ld b, h
# ld c, l
# in a, (c)
# Into:
# ld bc, (NN) | ld bc, NN | pop bc
# in a, (c)
if OPT23 and len(new_chunk) > 3 and inst(new_chunk[3]) == 'in':
ia = inst(new_chunk[1])
oa = oper(new_chunk[1])
ib = inst(new_chunk[2])
ob = oper(new_chunk[2])
if (ia, oa[0], oa[1], ib, ob[0], ob[1]) == ('ld', 'b', 'h', 'ld', 'c', 'l'):
ii = inst(new_chunk[0])
oi = oper(new_chunk[0])
if ii in ('pop', 'ld') and oi[0] == 'hl':
new_chunk[0] = ii + ' ' + 'bc' + (', %s' % oi[1] if ii == 'ld' else '')
new_chunk.pop(1)
new_chunk.pop(1)
changed = True
continue
# Converts:
# ld hl, (NN) | ld hl, NN | pop hl
# ld b, h
# ld c, l
# out (c), a
# Into:
# ld bc, (NN) | ld bc, NN | pop bc
# out (c), a
if OPT23 and len(new_chunk) > 3 and inst(new_chunk[-1]) == 'out':
ia = inst(new_chunk[-3])
oa = oper(new_chunk[-3])
ib = inst(new_chunk[-2])
ob = oper(new_chunk[-2])
if (ia, oa[0], oa[1], ib, ob[0], ob[1]) == ('ld', 'b', 'h', 'ld', 'c', 'l'):
ii = inst(new_chunk[-4])
oi = oper(new_chunk[-4])
if ii in ('pop', 'ld') and oi[0] == 'hl':
new_chunk[-4] = ii + ' ' + 'bc' + (', %s' % oi[1] if ii == 'ld' else '')
new_chunk.pop(-2)
new_chunk.pop(-2)
changed = True
continue
# Converts:
# or X | and X
# or a | and a
# Into:
# or X | and X
if OPT24 and i1 in ('and', 'or') and new_chunk[0] in ('or a', 'and a'):
new_chunk.pop(0)
changed = True
continue
# Converts:
# ld h, X (X != A)
# ld a, Y
# or/and/cp/add/sub h
# Into:
# ld a, Y
# or/and/cp X
if OPT25 and \
(i1 in ('cp', 'or', 'and') and o1[0] == 'h' or
i1 in ('sub', 'add', 'sbc', 'adc') and o1[1] == 'h') \
and i0 == 'ld' and o0[0] == 'a' and len(output) > 2:
ii = inst(output[-3])
oo = oper(output[-3])
if i1 in ('add', 'adc', 'sbc'):
i1 = i1 + ' a,'
if ii == 'ld' and oo[0] == 'h' and oo[1] != 'a':
output[-1] = '{0} {1}'.format(i1, oo[1])
output.pop(-3)
changed = True
continue
# Converts:
# ld a, (nn) | ld a, (ix+N)
# inc/dec a
# ld (nn), a | ld (ix+N), a
# Into:
# ld hl, _n | <removed>
# inc/dec (hl) | inc/dec (ix+N)
if OPT26 and i1 in ('inc', 'dec') and o1[0] == 'a' and i0 == i2 == 'ld' and \
(o0[0], o0[1]) == (o2[1], o2[0]) and o0[1][0] == '(':
new_chunk.pop(0)
if RE_IX_IDX.match(o0[1]):
output[-1] = '{0} {1}'.format(i1, o0[1])
output.pop(-2)
else:
output[-1] = '{0} (hl)'.format(i1)
output[-2] = 'ld hl, {0}'.format(o0[1][1:-1])
changed = True
continue
# Converts:
# ld X, Y
# ld Y, X
# Into:
# ld X, Y
if OPT02 and i1 == i2 == 'ld' and o1[0] == o2[1] and o2[0] == o1[1]:
# This and previous instruction are LD X, Y
# Ok, previous instruction is LD A, B and current is LD B, A. Remove this one.
new_chunk = new_chunk[1:]
changed = True
continue
# Converts:
# ld h, X
# or/and h
# Into:
# or/and X
if OPT27 and i1 == 'ld' and o1[0] == 'h' and i2 in ('and', 'or') and o2[0] == 'h':
output.pop()
new_chunk[0] = '{0} {1}'.format(i2, o1[1])
changed = True
continue
# Converts
# ld a, r|(ix+/-N)|(hl)
# ld h, a
# ld a, XXX | pop af
# Into:
# ld h, r|(ix+/-N)|(hl)
# ld a, XXX | pop af
if OPT28 and i1 == i0 == 'ld' and o0[0] == 'a' and \
(o0[1] in ('a', 'b', 'c', 'd', 'e', 'h', 'l', '(hl)') or RE_IX_IDX.match(o0[1])) and \
(o1[0], o1[1]) == ('h', 'a') and new_chunk and (new_chunk[0] == 'pop af' or
i2 == 'ld' and o2[0] == 'a'):
output.pop()
output[-1] = 'ld h, {0}'.format(o0[1])
changed = True
continue
# Converts:
# cp 0
# Into:
# or a
if OPT29 and i1 == 'cp' and o1[0] == '0':
output[-1] = 'or a'
changed = True
continue
# Converts:
# or/and X
# jp c/nc XXX
# Into:
# <nothing>/jp XXX
if OPT30 and i1 in ('and', 'or') and i2 == 'jp':
c = condition(new_chunk[0])
if c in ('c', 'nc'):
output.pop()
if c == 'nc':
new_chunk[0] = 'jp {0}'.format(o2[0])
else:
new_chunk.pop(0)
changed = True
continue
# Converts
# jp XXX
# <any inst>
# Into:
# jp XXX
if OPT31 and i1 == 'jp' and not condition(output[-1]) and i2 is not None and \
i2[-1] != ':' and new_chunk[0] not in ASMS:
new_chunk.pop(0)
changed = True
continue
# Converts:
# call __LOADSTR
# ld a, 1
# call __PRINSTR
# Into:
# xor a
# call __PRINTSTR
if OPT32 and i0 == 'call' and o0[0] == '__LOADSTR' and i1 == 'ld' and tuple(o1) == ('a', '1') and \
i2 == 'call' and o2[0] == '__PRINTSTR':
output.pop(-2)
output[-1] = 'xor a'
changed = True
continue
changed, new_chunk = optiblock(new_chunk)
output.extend(new_chunk)
output = []
for i in mem:
output_join(output, QUADS[i.quad[0]][1](i))
if RE_BOOL.match(i.quad[0]): # If it is a boolean operation convert it to 0/1 if the STRICT_BOOL flag is True
output_join(output, convertToBool())
changed = OPTIONS.optimization.value > 1
while changed:
to_remove = []
for i, ins in enumerate(output):
ins = ins[:-1]
if ins not in TMP_LABELS:
continue
for j, ins2 in enumerate(output):
if j == i:
continue
if ins in oper(ins2):
break
else:
to_remove.append(i)
changed = len(to_remove) > 0
to_remove.reverse()
for i in to_remove:
output.pop(i)
tmp = output
output = []
for i in tmp:
output_join(output, [i])
for i in sorted(REQUIRES):
output.append('#include once <%s>' % i)
return output | [
"def",
"emit",
"(",
"mem",
")",
":",
"def",
"output_join",
"(",
"output",
",",
"new_chunk",
")",
":",
"\"\"\" Extends output instruction list\n performing a little peep-hole optimization\n \"\"\"",
"changed",
"=",
"True",
"and",
"OPTIONS",
".",
"optimization",
".",
"value",
">",
"0",
"# Only enter here if -O0 was not set",
"while",
"changed",
"and",
"new_chunk",
":",
"if",
"output",
":",
"a1",
"=",
"output",
"[",
"-",
"1",
"]",
"# Last output instruction",
"i1",
"=",
"inst",
"(",
"a1",
")",
"o1",
"=",
"oper",
"(",
"a1",
")",
"else",
":",
"a1",
"=",
"i1",
"=",
"o1",
"=",
"None",
"if",
"len",
"(",
"output",
")",
">",
"1",
":",
"a0",
"=",
"output",
"[",
"-",
"2",
"]",
"i0",
"=",
"inst",
"(",
"a0",
")",
"o0",
"=",
"oper",
"(",
"a0",
")",
"else",
":",
"a0",
"=",
"i0",
"=",
"o0",
"=",
"None",
"a2",
"=",
"new_chunk",
"[",
"0",
"]",
"# Fist new output instruction",
"i2",
"=",
"inst",
"(",
"a2",
")",
"o2",
"=",
"oper",
"(",
"a2",
")",
"if",
"OPT00",
"and",
"i2",
"[",
"-",
"1",
"]",
"==",
"':'",
":",
"# Ok, a2 is a label",
"# check if the above starts with jr / jp",
"if",
"i1",
"in",
"(",
"'jp'",
",",
"'jr'",
")",
"and",
"o1",
"[",
"0",
"]",
"==",
"i2",
"[",
":",
"-",
"1",
"]",
":",
"# Ok remove the above instruction",
"output",
".",
"pop",
"(",
")",
"changed",
"=",
"True",
"continue",
"if",
"OPT01",
"and",
"i1",
"==",
"'push'",
"and",
"i2",
"==",
"'pop'",
"and",
"o1",
"[",
"0",
"]",
"==",
"o2",
"[",
"0",
"]",
":",
"# Ok, we have a push/pop sequence which refers to",
"# the same register pairs",
"# Ok, remove these instructions (both)",
"output",
".",
"pop",
"(",
")",
"new_chunk",
"=",
"new_chunk",
"[",
"1",
":",
"]",
"changed",
"=",
"True",
"continue",
"if",
"(",
"OPT03",
"and",
"(",
"i1",
"==",
"'sbc'",
"and",
"o1",
"[",
"0",
"]",
"==",
"o1",
"[",
"1",
"]",
"==",
"'a'",
"and",
"i2",
"==",
"'or'",
"and",
"o2",
"[",
"0",
"]",
"==",
"'a'",
"and",
"len",
"(",
"new_chunk",
")",
">",
"1",
")",
")",
":",
"a3",
"=",
"new_chunk",
"[",
"1",
"]",
"i3",
"=",
"inst",
"(",
"a3",
")",
"o3",
"=",
"oper",
"(",
"a3",
")",
"c",
"=",
"condition",
"(",
"a3",
")",
"if",
"i3",
"in",
"(",
"'jp'",
",",
"'jr'",
")",
"and",
"c",
"in",
"(",
"'z'",
",",
"'nz'",
")",
":",
"c",
"=",
"'nc'",
"if",
"c",
"==",
"'z'",
"else",
"'c'",
"changed",
"=",
"True",
"output",
".",
"pop",
"(",
")",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"new_chunk",
"[",
"0",
"]",
"=",
"'%s %s, %s'",
"%",
"(",
"i3",
",",
"c",
",",
"o3",
"[",
"0",
"]",
")",
"continue",
"if",
"OPT04",
"and",
"i1",
"==",
"'push'",
"and",
"i2",
"==",
"'pop'",
":",
"if",
"'af'",
"in",
"(",
"o1",
"[",
"0",
"]",
",",
"o2",
"[",
"0",
"]",
")",
":",
"output",
".",
"pop",
"(",
")",
"new_chunk",
"[",
"0",
"]",
"=",
"'ld %s, %s'",
"%",
"(",
"o2",
"[",
"0",
"]",
"[",
"0",
"]",
",",
"o1",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"changed",
"=",
"True",
"continue",
"if",
"o1",
"[",
"0",
"]",
"in",
"(",
"'hl'",
",",
"'de'",
")",
"and",
"o2",
"[",
"0",
"]",
"in",
"(",
"'hl'",
",",
"'de'",
")",
":",
"# push hl; push de; pop hl; pop de || push de; push hl; pop de; pop hl => ex de, hl",
"if",
"len",
"(",
"new_chunk",
")",
">",
"1",
"and",
"len",
"(",
"output",
")",
">",
"1",
"and",
"oper",
"(",
"new_chunk",
"[",
"1",
"]",
")",
"[",
"0",
"]",
"==",
"o1",
"[",
"0",
"]",
"and",
"o2",
"[",
"0",
"]",
"==",
"oper",
"(",
"output",
"[",
"-",
"2",
"]",
")",
"[",
"0",
"]",
"and",
"inst",
"(",
"output",
"[",
"-",
"2",
"]",
")",
"==",
"'push'",
"and",
"inst",
"(",
"new_chunk",
"[",
"1",
"]",
")",
"==",
"'pop'",
":",
"output",
".",
"pop",
"(",
")",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"output",
"[",
"-",
"1",
"]",
"=",
"'ex de, hl'",
"changed",
"=",
"True",
"continue",
"# push hl; pop de || push de ; pop hl",
"if",
"len",
"(",
"new_chunk",
")",
">",
"1",
"and",
"inst",
"(",
"new_chunk",
"[",
"1",
"]",
")",
"in",
"(",
"'pop'",
",",
"'ld'",
")",
"and",
"oper",
"(",
"new_chunk",
"[",
"1",
"]",
")",
"[",
"0",
"]",
"==",
"o1",
"[",
"0",
"]",
":",
"output",
".",
"pop",
"(",
")",
"new_chunk",
"[",
"0",
"]",
"=",
"'ex de, hl'",
"changed",
"=",
"True",
"continue",
"if",
"o1",
"[",
"0",
"]",
"not",
"in",
"(",
"'ix'",
",",
"'iy'",
")",
"and",
"o2",
"[",
"0",
"]",
"not",
"in",
"(",
"'ix'",
",",
"'iy'",
")",
":",
"# Change push XX, pop YY sequence with ld Yh, Xl; ld Yl, Xl",
"output",
".",
"pop",
"(",
")",
"new_chunk",
"=",
"[",
"'ld %s, %s'",
"%",
"(",
"o2",
"[",
"0",
"]",
"[",
"0",
"]",
",",
"o1",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"]",
"+",
"new_chunk",
"new_chunk",
"[",
"1",
"]",
"=",
"'ld %s, %s'",
"%",
"(",
"o2",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"o1",
"[",
"0",
"]",
"[",
"1",
"]",
")",
"changed",
"=",
"True",
"continue",
"# ex af, af'; ex af, af' => <nothing>",
"# ex de, hl ; ex de, hl => <nothing>",
"if",
"OPT16",
"and",
"i1",
"==",
"i2",
"==",
"'ex'",
"and",
"o1",
"==",
"o2",
":",
"output",
".",
"pop",
"(",
")",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"changed",
"=",
"True",
"continue",
"# Tries to optimize:",
"# jp <condition>, LABEL",
"# jp OTHER",
"# LABEL:",
"# into",
"# JP !<condition>, OTHER",
"# LABEL:",
"if",
"OPT17",
"and",
"len",
"(",
"output",
")",
">",
"1",
":",
"if",
"i0",
"==",
"i1",
"==",
"'jp'",
"and",
"i2",
"[",
"-",
"1",
"]",
"==",
"':'",
"and",
"condition",
"(",
"a0",
")",
"in",
"{",
"'c'",
",",
"'nc'",
",",
"'z'",
",",
"'nz'",
"}",
"and",
"condition",
"(",
"a1",
")",
"is",
"None",
"and",
"a2",
"[",
":",
"-",
"1",
"]",
"in",
"o0",
":",
"output",
".",
"pop",
"(",
")",
"output",
".",
"pop",
"(",
")",
"new_chunk",
"=",
"[",
"'jp %s, %s'",
"%",
"(",
"{",
"'c'",
":",
"'nc'",
",",
"'z'",
":",
"'nz'",
",",
"'nc'",
":",
"'c'",
",",
"'nz'",
":",
"'z'",
"}",
"[",
"condition",
"(",
"a0",
")",
"]",
",",
"o1",
"[",
"0",
"]",
")",
"]",
"+",
"new_chunk",
"changed",
"=",
"True",
"continue",
"# Tries to optimize a == b for U/Integers",
"# call __EQ16",
"# or a",
"# jp nz, ...",
"# into:",
"# or a",
"# sbc hl, de",
"# jp z, ...",
"if",
"OPT18",
"and",
"i1",
"==",
"'call'",
"and",
"o1",
"[",
"0",
"]",
"==",
"'__EQ16'",
"and",
"i2",
"in",
"{",
"'or'",
",",
"'and'",
"}",
"and",
"o2",
"[",
"0",
"]",
"==",
"'a'",
"and",
"len",
"(",
"new_chunk",
")",
">",
"1",
":",
"a3",
"=",
"new_chunk",
"[",
"1",
"]",
"i3",
"=",
"inst",
"(",
"a3",
")",
"c3",
"=",
"condition",
"(",
"a3",
")",
"if",
"i3",
"==",
"'jp'",
"and",
"c3",
"in",
"{",
"'z'",
",",
"'nz'",
"}",
":",
"cond",
"=",
"'z'",
"if",
"c3",
"==",
"'nz'",
"else",
"'nz'",
"new_chunk",
"[",
"1",
"]",
"=",
"'jp %s, %s'",
"%",
"(",
"cond",
",",
"oper",
"(",
"a3",
")",
"[",
"0",
"]",
")",
"output",
".",
"pop",
"(",
")",
"new_chunk",
".",
"insert",
"(",
"1",
",",
"'sbc hl, de'",
")",
"changed",
"=",
"True",
"continue",
"# Tries to optimize a == b for U/Bytes",
"# sub N",
"# sub 1",
"# jp nc, __LABEL",
"# into:",
"# sub N",
"# or a",
"# jp nz, __LABEL",
"if",
"OPT19",
"and",
"i1",
"==",
"'sub'",
"and",
"'1'",
"in",
"o1",
"and",
"i2",
"==",
"'jp'",
"and",
"len",
"(",
"output",
")",
">",
"1",
":",
"c2",
"=",
"condition",
"(",
"new_chunk",
"[",
"0",
"]",
")",
"if",
"c2",
"in",
"{",
"'c'",
",",
"'nc'",
"}",
":",
"cond",
"=",
"'z'",
"if",
"c2",
"==",
"'c'",
"else",
"'nz'",
"new_chunk",
"[",
"0",
"]",
"=",
"'jp %s, %s'",
"%",
"(",
"cond",
",",
"o2",
"[",
"0",
"]",
")",
"if",
"i0",
"in",
"(",
"'sub'",
",",
"'dec'",
")",
":",
"output",
".",
"pop",
"(",
")",
"else",
":",
"output",
"[",
"-",
"1",
"]",
"=",
"'or a'",
"changed",
"=",
"True",
"continue",
"# Removes useless or a from sequence:",
"# sub X",
"# or a",
"# jp z/nz ...",
"if",
"OPT21",
"and",
"i1",
"==",
"'sub'",
"and",
"i2",
"in",
"{",
"'or'",
",",
"'and'",
"}",
"and",
"o2",
"[",
"0",
"]",
"==",
"'a'",
":",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# ld a, (ix +/- n)",
"# ld r, a",
"# pop af",
"# Into:",
"# pop af",
"# ld r, (ix +/- n)",
"if",
"OPT22",
"and",
"len",
"(",
"output",
")",
">",
"1",
"and",
"i1",
"==",
"'ld'",
"and",
"o1",
"[",
"0",
"]",
"in",
"'bcdehl'",
"and",
"o1",
"[",
"1",
"]",
"==",
"'a'",
"and",
"(",
"i2",
",",
"o2",
")",
"==",
"(",
"'pop'",
",",
"[",
"'af'",
",",
"'sp'",
"]",
")",
":",
"if",
"(",
"i0",
",",
"o0",
"[",
":",
"1",
"]",
")",
"==",
"(",
"'ld'",
",",
"[",
"'a'",
"]",
")",
"and",
"RE_IX_IDX",
".",
"match",
"(",
"o0",
"[",
"1",
"]",
")",
":",
"output",
".",
"pop",
"(",
")",
"# Removes ld r, a",
"output",
".",
"pop",
"(",
")",
"# Removes ld a, (ix + n)",
"new_chunk",
".",
"insert",
"(",
"1",
",",
"'ld %s, %s'",
"%",
"(",
"o1",
"[",
"0",
"]",
",",
"o0",
"[",
"1",
"]",
")",
")",
"# Inserts 'ld r, (ix + n)' after 'pop af'",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# ld hl, (NN) | ld hl, NN | pop hl",
"# ld b, h",
"# ld c, l",
"# in a, (c)",
"# Into:",
"# ld bc, (NN) | ld bc, NN | pop bc",
"# in a, (c)",
"if",
"OPT23",
"and",
"len",
"(",
"new_chunk",
")",
">",
"3",
"and",
"inst",
"(",
"new_chunk",
"[",
"3",
"]",
")",
"==",
"'in'",
":",
"ia",
"=",
"inst",
"(",
"new_chunk",
"[",
"1",
"]",
")",
"oa",
"=",
"oper",
"(",
"new_chunk",
"[",
"1",
"]",
")",
"ib",
"=",
"inst",
"(",
"new_chunk",
"[",
"2",
"]",
")",
"ob",
"=",
"oper",
"(",
"new_chunk",
"[",
"2",
"]",
")",
"if",
"(",
"ia",
",",
"oa",
"[",
"0",
"]",
",",
"oa",
"[",
"1",
"]",
",",
"ib",
",",
"ob",
"[",
"0",
"]",
",",
"ob",
"[",
"1",
"]",
")",
"==",
"(",
"'ld'",
",",
"'b'",
",",
"'h'",
",",
"'ld'",
",",
"'c'",
",",
"'l'",
")",
":",
"ii",
"=",
"inst",
"(",
"new_chunk",
"[",
"0",
"]",
")",
"oi",
"=",
"oper",
"(",
"new_chunk",
"[",
"0",
"]",
")",
"if",
"ii",
"in",
"(",
"'pop'",
",",
"'ld'",
")",
"and",
"oi",
"[",
"0",
"]",
"==",
"'hl'",
":",
"new_chunk",
"[",
"0",
"]",
"=",
"ii",
"+",
"' '",
"+",
"'bc'",
"+",
"(",
"', %s'",
"%",
"oi",
"[",
"1",
"]",
"if",
"ii",
"==",
"'ld'",
"else",
"''",
")",
"new_chunk",
".",
"pop",
"(",
"1",
")",
"new_chunk",
".",
"pop",
"(",
"1",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# ld hl, (NN) | ld hl, NN | pop hl",
"# ld b, h",
"# ld c, l",
"# out (c), a",
"# Into:",
"# ld bc, (NN) | ld bc, NN | pop bc",
"# out (c), a",
"if",
"OPT23",
"and",
"len",
"(",
"new_chunk",
")",
">",
"3",
"and",
"inst",
"(",
"new_chunk",
"[",
"-",
"1",
"]",
")",
"==",
"'out'",
":",
"ia",
"=",
"inst",
"(",
"new_chunk",
"[",
"-",
"3",
"]",
")",
"oa",
"=",
"oper",
"(",
"new_chunk",
"[",
"-",
"3",
"]",
")",
"ib",
"=",
"inst",
"(",
"new_chunk",
"[",
"-",
"2",
"]",
")",
"ob",
"=",
"oper",
"(",
"new_chunk",
"[",
"-",
"2",
"]",
")",
"if",
"(",
"ia",
",",
"oa",
"[",
"0",
"]",
",",
"oa",
"[",
"1",
"]",
",",
"ib",
",",
"ob",
"[",
"0",
"]",
",",
"ob",
"[",
"1",
"]",
")",
"==",
"(",
"'ld'",
",",
"'b'",
",",
"'h'",
",",
"'ld'",
",",
"'c'",
",",
"'l'",
")",
":",
"ii",
"=",
"inst",
"(",
"new_chunk",
"[",
"-",
"4",
"]",
")",
"oi",
"=",
"oper",
"(",
"new_chunk",
"[",
"-",
"4",
"]",
")",
"if",
"ii",
"in",
"(",
"'pop'",
",",
"'ld'",
")",
"and",
"oi",
"[",
"0",
"]",
"==",
"'hl'",
":",
"new_chunk",
"[",
"-",
"4",
"]",
"=",
"ii",
"+",
"' '",
"+",
"'bc'",
"+",
"(",
"', %s'",
"%",
"oi",
"[",
"1",
"]",
"if",
"ii",
"==",
"'ld'",
"else",
"''",
")",
"new_chunk",
".",
"pop",
"(",
"-",
"2",
")",
"new_chunk",
".",
"pop",
"(",
"-",
"2",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# or X | and X",
"# or a | and a",
"# Into:",
"# or X | and X",
"if",
"OPT24",
"and",
"i1",
"in",
"(",
"'and'",
",",
"'or'",
")",
"and",
"new_chunk",
"[",
"0",
"]",
"in",
"(",
"'or a'",
",",
"'and a'",
")",
":",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# ld h, X (X != A)",
"# ld a, Y",
"# or/and/cp/add/sub h",
"# Into:",
"# ld a, Y",
"# or/and/cp X",
"if",
"OPT25",
"and",
"(",
"i1",
"in",
"(",
"'cp'",
",",
"'or'",
",",
"'and'",
")",
"and",
"o1",
"[",
"0",
"]",
"==",
"'h'",
"or",
"i1",
"in",
"(",
"'sub'",
",",
"'add'",
",",
"'sbc'",
",",
"'adc'",
")",
"and",
"o1",
"[",
"1",
"]",
"==",
"'h'",
")",
"and",
"i0",
"==",
"'ld'",
"and",
"o0",
"[",
"0",
"]",
"==",
"'a'",
"and",
"len",
"(",
"output",
")",
">",
"2",
":",
"ii",
"=",
"inst",
"(",
"output",
"[",
"-",
"3",
"]",
")",
"oo",
"=",
"oper",
"(",
"output",
"[",
"-",
"3",
"]",
")",
"if",
"i1",
"in",
"(",
"'add'",
",",
"'adc'",
",",
"'sbc'",
")",
":",
"i1",
"=",
"i1",
"+",
"' a,'",
"if",
"ii",
"==",
"'ld'",
"and",
"oo",
"[",
"0",
"]",
"==",
"'h'",
"and",
"oo",
"[",
"1",
"]",
"!=",
"'a'",
":",
"output",
"[",
"-",
"1",
"]",
"=",
"'{0} {1}'",
".",
"format",
"(",
"i1",
",",
"oo",
"[",
"1",
"]",
")",
"output",
".",
"pop",
"(",
"-",
"3",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# ld a, (nn) | ld a, (ix+N)",
"# inc/dec a",
"# ld (nn), a | ld (ix+N), a",
"# Into:",
"# ld hl, _n | <removed>",
"# inc/dec (hl) | inc/dec (ix+N)",
"if",
"OPT26",
"and",
"i1",
"in",
"(",
"'inc'",
",",
"'dec'",
")",
"and",
"o1",
"[",
"0",
"]",
"==",
"'a'",
"and",
"i0",
"==",
"i2",
"==",
"'ld'",
"and",
"(",
"o0",
"[",
"0",
"]",
",",
"o0",
"[",
"1",
"]",
")",
"==",
"(",
"o2",
"[",
"1",
"]",
",",
"o2",
"[",
"0",
"]",
")",
"and",
"o0",
"[",
"1",
"]",
"[",
"0",
"]",
"==",
"'('",
":",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"if",
"RE_IX_IDX",
".",
"match",
"(",
"o0",
"[",
"1",
"]",
")",
":",
"output",
"[",
"-",
"1",
"]",
"=",
"'{0} {1}'",
".",
"format",
"(",
"i1",
",",
"o0",
"[",
"1",
"]",
")",
"output",
".",
"pop",
"(",
"-",
"2",
")",
"else",
":",
"output",
"[",
"-",
"1",
"]",
"=",
"'{0} (hl)'",
".",
"format",
"(",
"i1",
")",
"output",
"[",
"-",
"2",
"]",
"=",
"'ld hl, {0}'",
".",
"format",
"(",
"o0",
"[",
"1",
"]",
"[",
"1",
":",
"-",
"1",
"]",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# ld X, Y",
"# ld Y, X",
"# Into:",
"# ld X, Y",
"if",
"OPT02",
"and",
"i1",
"==",
"i2",
"==",
"'ld'",
"and",
"o1",
"[",
"0",
"]",
"==",
"o2",
"[",
"1",
"]",
"and",
"o2",
"[",
"0",
"]",
"==",
"o1",
"[",
"1",
"]",
":",
"# This and previous instruction are LD X, Y",
"# Ok, previous instruction is LD A, B and current is LD B, A. Remove this one.",
"new_chunk",
"=",
"new_chunk",
"[",
"1",
":",
"]",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# ld h, X",
"# or/and h",
"# Into:",
"# or/and X",
"if",
"OPT27",
"and",
"i1",
"==",
"'ld'",
"and",
"o1",
"[",
"0",
"]",
"==",
"'h'",
"and",
"i2",
"in",
"(",
"'and'",
",",
"'or'",
")",
"and",
"o2",
"[",
"0",
"]",
"==",
"'h'",
":",
"output",
".",
"pop",
"(",
")",
"new_chunk",
"[",
"0",
"]",
"=",
"'{0} {1}'",
".",
"format",
"(",
"i2",
",",
"o1",
"[",
"1",
"]",
")",
"changed",
"=",
"True",
"continue",
"# Converts",
"# ld a, r|(ix+/-N)|(hl)",
"# ld h, a",
"# ld a, XXX | pop af",
"# Into:",
"# ld h, r|(ix+/-N)|(hl)",
"# ld a, XXX | pop af",
"if",
"OPT28",
"and",
"i1",
"==",
"i0",
"==",
"'ld'",
"and",
"o0",
"[",
"0",
"]",
"==",
"'a'",
"and",
"(",
"o0",
"[",
"1",
"]",
"in",
"(",
"'a'",
",",
"'b'",
",",
"'c'",
",",
"'d'",
",",
"'e'",
",",
"'h'",
",",
"'l'",
",",
"'(hl)'",
")",
"or",
"RE_IX_IDX",
".",
"match",
"(",
"o0",
"[",
"1",
"]",
")",
")",
"and",
"(",
"o1",
"[",
"0",
"]",
",",
"o1",
"[",
"1",
"]",
")",
"==",
"(",
"'h'",
",",
"'a'",
")",
"and",
"new_chunk",
"and",
"(",
"new_chunk",
"[",
"0",
"]",
"==",
"'pop af'",
"or",
"i2",
"==",
"'ld'",
"and",
"o2",
"[",
"0",
"]",
"==",
"'a'",
")",
":",
"output",
".",
"pop",
"(",
")",
"output",
"[",
"-",
"1",
"]",
"=",
"'ld h, {0}'",
".",
"format",
"(",
"o0",
"[",
"1",
"]",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# cp 0",
"# Into:",
"# or a",
"if",
"OPT29",
"and",
"i1",
"==",
"'cp'",
"and",
"o1",
"[",
"0",
"]",
"==",
"'0'",
":",
"output",
"[",
"-",
"1",
"]",
"=",
"'or a'",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# or/and X",
"# jp c/nc XXX",
"# Into:",
"# <nothing>/jp XXX",
"if",
"OPT30",
"and",
"i1",
"in",
"(",
"'and'",
",",
"'or'",
")",
"and",
"i2",
"==",
"'jp'",
":",
"c",
"=",
"condition",
"(",
"new_chunk",
"[",
"0",
"]",
")",
"if",
"c",
"in",
"(",
"'c'",
",",
"'nc'",
")",
":",
"output",
".",
"pop",
"(",
")",
"if",
"c",
"==",
"'nc'",
":",
"new_chunk",
"[",
"0",
"]",
"=",
"'jp {0}'",
".",
"format",
"(",
"o2",
"[",
"0",
"]",
")",
"else",
":",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"changed",
"=",
"True",
"continue",
"# Converts",
"# jp XXX",
"# <any inst>",
"# Into:",
"# jp XXX",
"if",
"OPT31",
"and",
"i1",
"==",
"'jp'",
"and",
"not",
"condition",
"(",
"output",
"[",
"-",
"1",
"]",
")",
"and",
"i2",
"is",
"not",
"None",
"and",
"i2",
"[",
"-",
"1",
"]",
"!=",
"':'",
"and",
"new_chunk",
"[",
"0",
"]",
"not",
"in",
"ASMS",
":",
"new_chunk",
".",
"pop",
"(",
"0",
")",
"changed",
"=",
"True",
"continue",
"# Converts:",
"# call __LOADSTR",
"# ld a, 1",
"# call __PRINSTR",
"# Into:",
"# xor a",
"# call __PRINTSTR",
"if",
"OPT32",
"and",
"i0",
"==",
"'call'",
"and",
"o0",
"[",
"0",
"]",
"==",
"'__LOADSTR'",
"and",
"i1",
"==",
"'ld'",
"and",
"tuple",
"(",
"o1",
")",
"==",
"(",
"'a'",
",",
"'1'",
")",
"and",
"i2",
"==",
"'call'",
"and",
"o2",
"[",
"0",
"]",
"==",
"'__PRINTSTR'",
":",
"output",
".",
"pop",
"(",
"-",
"2",
")",
"output",
"[",
"-",
"1",
"]",
"=",
"'xor a'",
"changed",
"=",
"True",
"continue",
"changed",
",",
"new_chunk",
"=",
"optiblock",
"(",
"new_chunk",
")",
"output",
".",
"extend",
"(",
"new_chunk",
")",
"output",
"=",
"[",
"]",
"for",
"i",
"in",
"mem",
":",
"output_join",
"(",
"output",
",",
"QUADS",
"[",
"i",
".",
"quad",
"[",
"0",
"]",
"]",
"[",
"1",
"]",
"(",
"i",
")",
")",
"if",
"RE_BOOL",
".",
"match",
"(",
"i",
".",
"quad",
"[",
"0",
"]",
")",
":",
"# If it is a boolean operation convert it to 0/1 if the STRICT_BOOL flag is True",
"output_join",
"(",
"output",
",",
"convertToBool",
"(",
")",
")",
"changed",
"=",
"OPTIONS",
".",
"optimization",
".",
"value",
">",
"1",
"while",
"changed",
":",
"to_remove",
"=",
"[",
"]",
"for",
"i",
",",
"ins",
"in",
"enumerate",
"(",
"output",
")",
":",
"ins",
"=",
"ins",
"[",
":",
"-",
"1",
"]",
"if",
"ins",
"not",
"in",
"TMP_LABELS",
":",
"continue",
"for",
"j",
",",
"ins2",
"in",
"enumerate",
"(",
"output",
")",
":",
"if",
"j",
"==",
"i",
":",
"continue",
"if",
"ins",
"in",
"oper",
"(",
"ins2",
")",
":",
"break",
"else",
":",
"to_remove",
".",
"append",
"(",
"i",
")",
"changed",
"=",
"len",
"(",
"to_remove",
")",
">",
"0",
"to_remove",
".",
"reverse",
"(",
")",
"for",
"i",
"in",
"to_remove",
":",
"output",
".",
"pop",
"(",
"i",
")",
"tmp",
"=",
"output",
"output",
"=",
"[",
"]",
"for",
"i",
"in",
"tmp",
":",
"output_join",
"(",
"output",
",",
"[",
"i",
"]",
")",
"for",
"i",
"in",
"sorted",
"(",
"REQUIRES",
")",
":",
"output",
".",
"append",
"(",
"'#include once <%s>'",
"%",
"i",
")",
"return",
"output"
] | Begin converting each quad instruction to asm
by iterating over the "mem" array, and called its
associated function. Each function returns an array of
ASM instructions which will be appended to the
'output' array | [
"Begin",
"converting",
"each",
"quad",
"instruction",
"to",
"asm",
"by",
"iterating",
"over",
"the",
"mem",
"array",
"and",
"called",
"its",
"associated",
"function",
".",
"Each",
"function",
"returns",
"an",
"array",
"of",
"ASM",
"instructions",
"which",
"will",
"be",
"appended",
"to",
"the",
"output",
"array"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__init__.py#L2351-L2779 |
boriel/zxbasic | zxbpplex.py | Lexer.t_asm_CONTINUE | def t_asm_CONTINUE(self, t):
r'[\\_]\r?\n'
t.lexer.lineno += 1
t.value = t.value[1:]
return t | python | def t_asm_CONTINUE(self, t):
r'[\\_]\r?\n'
t.lexer.lineno += 1
t.value = t.value[1:]
return t | [
"def",
"t_asm_CONTINUE",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"t",
".",
"value",
"=",
"t",
".",
"value",
"[",
"1",
":",
"]",
"return",
"t"
] | r'[\\_]\r?\n | [
"r",
"[",
"\\\\",
"_",
"]",
"\\",
"r?",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L89-L93 |
boriel/zxbasic | zxbpplex.py | Lexer.t_asmcomment_NEWLINE | def t_asmcomment_NEWLINE(self, t):
r'\r?\n'
# New line => remove whatever state in top of the stack and replace it with INITIAL
t.lexer.lineno += 1
t.lexer.pop_state()
return t | python | def t_asmcomment_NEWLINE(self, t):
r'\r?\n'
# New line => remove whatever state in top of the stack and replace it with INITIAL
t.lexer.lineno += 1
t.lexer.pop_state()
return t | [
"def",
"t_asmcomment_NEWLINE",
"(",
"self",
",",
"t",
")",
":",
"# New line => remove whatever state in top of the stack and replace it with INITIAL",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"t",
".",
"lexer",
".",
"pop_state",
"(",
")",
"return",
"t"
] | r'\r?\n | [
"r",
"\\",
"r?",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L102-L107 |
boriel/zxbasic | zxbpplex.py | Lexer.t_prepro_define_defargs_defargsopt_defexpr_pragma_if_NEWLINE | def t_prepro_define_defargs_defargsopt_defexpr_pragma_if_NEWLINE(self, t):
r'\r?\n'
t.lexer.lineno += 1
t.lexer.pop_state()
return t | python | def t_prepro_define_defargs_defargsopt_defexpr_pragma_if_NEWLINE(self, t):
r'\r?\n'
t.lexer.lineno += 1
t.lexer.pop_state()
return t | [
"def",
"t_prepro_define_defargs_defargsopt_defexpr_pragma_if_NEWLINE",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"t",
".",
"lexer",
".",
"pop_state",
"(",
")",
"return",
"t"
] | r'\r?\n | [
"r",
"\\",
"r?",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L137-L141 |
boriel/zxbasic | zxbpplex.py | Lexer.t_singlecomment_NEWLINE | def t_singlecomment_NEWLINE(self, t):
r'\r?\n'
t.lexer.pop_state() # Back to initial
t.lexer.lineno += 1
return t | python | def t_singlecomment_NEWLINE(self, t):
r'\r?\n'
t.lexer.pop_state() # Back to initial
t.lexer.lineno += 1
return t | [
"def",
"t_singlecomment_NEWLINE",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"lexer",
".",
"pop_state",
"(",
")",
"# Back to initial",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"return",
"t"
] | r'\r?\n | [
"r",
"\\",
"r?",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L152-L156 |
boriel/zxbasic | zxbpplex.py | Lexer.t_comment_endBlock | def t_comment_endBlock(self, t):
r"'/"
self.__COMMENT_LEVEL -= 1
if not self.__COMMENT_LEVEL:
t.lexer.begin('INITIAL') | python | def t_comment_endBlock(self, t):
r"'/"
self.__COMMENT_LEVEL -= 1
if not self.__COMMENT_LEVEL:
t.lexer.begin('INITIAL') | [
"def",
"t_comment_endBlock",
"(",
"self",
",",
"t",
")",
":",
"self",
".",
"__COMMENT_LEVEL",
"-=",
"1",
"if",
"not",
"self",
".",
"__COMMENT_LEVEL",
":",
"t",
".",
"lexer",
".",
"begin",
"(",
"'INITIAL'",
")"
] | r"'/ | [
"r",
"/"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L173-L177 |
boriel/zxbasic | zxbpplex.py | Lexer.t_msg_STRING | def t_msg_STRING(self, t):
r'.*\n'
t.lexer.lineno += 1
t.lexer.begin('INITIAL')
t.value = t.value.strip() # remove newline an spaces
return t | python | def t_msg_STRING(self, t):
r'.*\n'
t.lexer.lineno += 1
t.lexer.begin('INITIAL')
t.value = t.value.strip() # remove newline an spaces
return t | [
"def",
"t_msg_STRING",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"t",
".",
"lexer",
".",
"begin",
"(",
"'INITIAL'",
")",
"t",
".",
"value",
"=",
"t",
".",
"value",
".",
"strip",
"(",
")",
"# remove newline an spaces",
"return",
"t"
] | r'.*\n | [
"r",
".",
"*",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L179-L184 |
boriel/zxbasic | zxbpplex.py | Lexer.t_defexpr_CONTINUE | def t_defexpr_CONTINUE(self, t):
r'[\\_]\r?\n'
t.lexer.lineno += 1
t.value = t.value[1:]
return t | python | def t_defexpr_CONTINUE(self, t):
r'[\\_]\r?\n'
t.lexer.lineno += 1
t.value = t.value[1:]
return t | [
"def",
"t_defexpr_CONTINUE",
"(",
"self",
",",
"t",
")",
":",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"t",
".",
"value",
"=",
"t",
".",
"value",
"[",
"1",
":",
"]",
"return",
"t"
] | r'[\\_]\r?\n | [
"r",
"[",
"\\\\",
"_",
"]",
"\\",
"r?",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L191-L195 |
boriel/zxbasic | zxbpplex.py | Lexer.t_prepro_ID | def t_prepro_ID(self, t):
r'[_a-zA-Z][_a-zA-Z0-9]*' # preprocessor directives
t.type = reserved_directives.get(t.value.lower(), 'ID')
states_ = {
'DEFINE': 'define',
'PRAGMA': 'pragma',
'IF': 'if',
'ERROR': 'msg',
'WARNING': 'msg'
}
if t.type in states_:
t.lexer.begin(states_[t.type])
elif t.type == 'ID' and self.expectingDirective:
self.error("invalid directive #%s" % t.value)
self.expectingDirective = False
return t | python | def t_prepro_ID(self, t):
r'[_a-zA-Z][_a-zA-Z0-9]*' # preprocessor directives
t.type = reserved_directives.get(t.value.lower(), 'ID')
states_ = {
'DEFINE': 'define',
'PRAGMA': 'pragma',
'IF': 'if',
'ERROR': 'msg',
'WARNING': 'msg'
}
if t.type in states_:
t.lexer.begin(states_[t.type])
elif t.type == 'ID' and self.expectingDirective:
self.error("invalid directive #%s" % t.value)
self.expectingDirective = False
return t | [
"def",
"t_prepro_ID",
"(",
"self",
",",
"t",
")",
":",
"# preprocessor directives",
"t",
".",
"type",
"=",
"reserved_directives",
".",
"get",
"(",
"t",
".",
"value",
".",
"lower",
"(",
")",
",",
"'ID'",
")",
"states_",
"=",
"{",
"'DEFINE'",
":",
"'define'",
",",
"'PRAGMA'",
":",
"'pragma'",
",",
"'IF'",
":",
"'if'",
",",
"'ERROR'",
":",
"'msg'",
",",
"'WARNING'",
":",
"'msg'",
"}",
"if",
"t",
".",
"type",
"in",
"states_",
":",
"t",
".",
"lexer",
".",
"begin",
"(",
"states_",
"[",
"t",
".",
"type",
"]",
")",
"elif",
"t",
".",
"type",
"==",
"'ID'",
"and",
"self",
".",
"expectingDirective",
":",
"self",
".",
"error",
"(",
"\"invalid directive #%s\"",
"%",
"t",
".",
"value",
")",
"self",
".",
"expectingDirective",
"=",
"False",
"return",
"t"
] | r'[_a-zA-Z][_a-zA-Z0-9]* | [
"r",
"[",
"_a",
"-",
"zA",
"-",
"Z",
"]",
"[",
"_a",
"-",
"zA",
"-",
"Z0",
"-",
"9",
"]",
"*"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L224-L241 |
boriel/zxbasic | zxbpplex.py | Lexer.t_pragma_ID | def t_pragma_ID(self, t):
r'[_a-zA-Z][_a-zA-Z0-9]*' # pragma directives
if t.value.upper() in ('PUSH', 'POP'):
t.type = t.value.upper()
return t | python | def t_pragma_ID(self, t):
r'[_a-zA-Z][_a-zA-Z0-9]*' # pragma directives
if t.value.upper() in ('PUSH', 'POP'):
t.type = t.value.upper()
return t | [
"def",
"t_pragma_ID",
"(",
"self",
",",
"t",
")",
":",
"# pragma directives",
"if",
"t",
".",
"value",
".",
"upper",
"(",
")",
"in",
"(",
"'PUSH'",
",",
"'POP'",
")",
":",
"t",
".",
"type",
"=",
"t",
".",
"value",
".",
"upper",
"(",
")",
"return",
"t"
] | r'[_a-zA-Z][_a-zA-Z0-9]* | [
"r",
"[",
"_a",
"-",
"zA",
"-",
"Z",
"]",
"[",
"_a",
"-",
"zA",
"-",
"Z0",
"-",
"9",
"]",
"*"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L259-L263 |
boriel/zxbasic | zxbpplex.py | Lexer.t_INITIAL_asm_sharp | def t_INITIAL_asm_sharp(self, t):
r'[ \t]*\#' # Only matches if at beginning of line and "#"
if self.find_column(t) == 1:
t.lexer.push_state('prepro') # Start preprocessor
self.expectingDirective = True | python | def t_INITIAL_asm_sharp(self, t):
r'[ \t]*\#' # Only matches if at beginning of line and "#"
if self.find_column(t) == 1:
t.lexer.push_state('prepro') # Start preprocessor
self.expectingDirective = True | [
"def",
"t_INITIAL_asm_sharp",
"(",
"self",
",",
"t",
")",
":",
"# Only matches if at beginning of line and \"#\"",
"if",
"self",
".",
"find_column",
"(",
"t",
")",
"==",
"1",
":",
"t",
".",
"lexer",
".",
"push_state",
"(",
"'prepro'",
")",
"# Start preprocessor",
"self",
".",
"expectingDirective",
"=",
"True"
] | r'[ \t]*\# | [
"r",
"[",
"\\",
"t",
"]",
"*",
"\\",
"#"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L329-L333 |
boriel/zxbasic | zxbpplex.py | Lexer.put_current_line | def put_current_line(self, prefix='', suffix=''):
""" Returns line and file for include / end of include sequences.
"""
return '%s#line %i "%s"%s' % (prefix, self.lex.lineno, self.filestack[-1][0], suffix) | python | def put_current_line(self, prefix='', suffix=''):
""" Returns line and file for include / end of include sequences.
"""
return '%s#line %i "%s"%s' % (prefix, self.lex.lineno, self.filestack[-1][0], suffix) | [
"def",
"put_current_line",
"(",
"self",
",",
"prefix",
"=",
"''",
",",
"suffix",
"=",
"''",
")",
":",
"return",
"'%s#line %i \"%s\"%s'",
"%",
"(",
"prefix",
",",
"self",
".",
"lex",
".",
"lineno",
",",
"self",
".",
"filestack",
"[",
"-",
"1",
"]",
"[",
"0",
"]",
",",
"suffix",
")"
] | Returns line and file for include / end of include sequences. | [
"Returns",
"line",
"and",
"file",
"for",
"include",
"/",
"end",
"of",
"include",
"sequences",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L385-L388 |
boriel/zxbasic | zxbpplex.py | Lexer.include_end | def include_end(self):
""" Performs and end of include.
"""
self.lex = self.filestack[-1][2]
self.input_data = self.filestack[-1][3]
self.filestack.pop()
if not self.filestack: # End of input?
return
self.filestack[-1][1] += 1 # Increment line counter of previous file
result = lex.LexToken()
result.value = self.put_current_line(suffix='\n')
result.type = '_ENDFILE_'
result.lineno = self.lex.lineno
result.lexpos = self.lex.lexpos
return result | python | def include_end(self):
""" Performs and end of include.
"""
self.lex = self.filestack[-1][2]
self.input_data = self.filestack[-1][3]
self.filestack.pop()
if not self.filestack: # End of input?
return
self.filestack[-1][1] += 1 # Increment line counter of previous file
result = lex.LexToken()
result.value = self.put_current_line(suffix='\n')
result.type = '_ENDFILE_'
result.lineno = self.lex.lineno
result.lexpos = self.lex.lexpos
return result | [
"def",
"include_end",
"(",
"self",
")",
":",
"self",
".",
"lex",
"=",
"self",
".",
"filestack",
"[",
"-",
"1",
"]",
"[",
"2",
"]",
"self",
".",
"input_data",
"=",
"self",
".",
"filestack",
"[",
"-",
"1",
"]",
"[",
"3",
"]",
"self",
".",
"filestack",
".",
"pop",
"(",
")",
"if",
"not",
"self",
".",
"filestack",
":",
"# End of input?",
"return",
"self",
".",
"filestack",
"[",
"-",
"1",
"]",
"[",
"1",
"]",
"+=",
"1",
"# Increment line counter of previous file",
"result",
"=",
"lex",
".",
"LexToken",
"(",
")",
"result",
".",
"value",
"=",
"self",
".",
"put_current_line",
"(",
"suffix",
"=",
"'\\n'",
")",
"result",
".",
"type",
"=",
"'_ENDFILE_'",
"result",
".",
"lineno",
"=",
"self",
".",
"lex",
".",
"lineno",
"result",
".",
"lexpos",
"=",
"self",
".",
"lex",
".",
"lexpos",
"return",
"result"
] | Performs and end of include. | [
"Performs",
"and",
"end",
"of",
"include",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L419-L437 |
boriel/zxbasic | zxbpplex.py | Lexer.input | def input(self, str, filename=''):
""" Defines input string, removing current lexer.
"""
self.filestack.append([filename, 1, self.lex, self.input_data])
self.input_data = str
self.lex = lex.lex(object=self)
self.lex.input(self.input_data) | python | def input(self, str, filename=''):
""" Defines input string, removing current lexer.
"""
self.filestack.append([filename, 1, self.lex, self.input_data])
self.input_data = str
self.lex = lex.lex(object=self)
self.lex.input(self.input_data) | [
"def",
"input",
"(",
"self",
",",
"str",
",",
"filename",
"=",
"''",
")",
":",
"self",
".",
"filestack",
".",
"append",
"(",
"[",
"filename",
",",
"1",
",",
"self",
".",
"lex",
",",
"self",
".",
"input_data",
"]",
")",
"self",
".",
"input_data",
"=",
"str",
"self",
".",
"lex",
"=",
"lex",
".",
"lex",
"(",
"object",
"=",
"self",
")",
"self",
".",
"lex",
".",
"input",
"(",
"self",
".",
"input_data",
")"
] | Defines input string, removing current lexer. | [
"Defines",
"input",
"string",
"removing",
"current",
"lexer",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L439-L446 |
boriel/zxbasic | zxbpplex.py | Lexer.token | def token(self):
""" Returns a token from the current input. If tok is None
from the current input, it means we are at end of current input
(e.g. at end of include file). If so, closes the current input
and discards it; then pops the previous input and lexer from
the input stack, and gets another token.
If new token is again None, repeat the process described above
until the token is either not None, or self.lex is None, wich
means we must effectively return None, because parsing has
ended.
"""
tok = None
if self.next_token is not None:
tok = lex.LexToken()
tok.value = ''
tok.lineno = self.lex.lineno
tok.lexpos = self.lex.lexpos
tok.type = self.next_token
self.next_token = None
while self.lex is not None and tok is None:
tok = self.lex.token()
if tok is not None:
break
tok = self.include_end()
return tok | python | def token(self):
""" Returns a token from the current input. If tok is None
from the current input, it means we are at end of current input
(e.g. at end of include file). If so, closes the current input
and discards it; then pops the previous input and lexer from
the input stack, and gets another token.
If new token is again None, repeat the process described above
until the token is either not None, or self.lex is None, wich
means we must effectively return None, because parsing has
ended.
"""
tok = None
if self.next_token is not None:
tok = lex.LexToken()
tok.value = ''
tok.lineno = self.lex.lineno
tok.lexpos = self.lex.lexpos
tok.type = self.next_token
self.next_token = None
while self.lex is not None and tok is None:
tok = self.lex.token()
if tok is not None:
break
tok = self.include_end()
return tok | [
"def",
"token",
"(",
"self",
")",
":",
"tok",
"=",
"None",
"if",
"self",
".",
"next_token",
"is",
"not",
"None",
":",
"tok",
"=",
"lex",
".",
"LexToken",
"(",
")",
"tok",
".",
"value",
"=",
"''",
"tok",
".",
"lineno",
"=",
"self",
".",
"lex",
".",
"lineno",
"tok",
".",
"lexpos",
"=",
"self",
".",
"lex",
".",
"lexpos",
"tok",
".",
"type",
"=",
"self",
".",
"next_token",
"self",
".",
"next_token",
"=",
"None",
"while",
"self",
".",
"lex",
"is",
"not",
"None",
"and",
"tok",
"is",
"None",
":",
"tok",
"=",
"self",
".",
"lex",
".",
"token",
"(",
")",
"if",
"tok",
"is",
"not",
"None",
":",
"break",
"tok",
"=",
"self",
".",
"include_end",
"(",
")",
"return",
"tok"
] | Returns a token from the current input. If tok is None
from the current input, it means we are at end of current input
(e.g. at end of include file). If so, closes the current input
and discards it; then pops the previous input and lexer from
the input stack, and gets another token.
If new token is again None, repeat the process described above
until the token is either not None, or self.lex is None, wich
means we must effectively return None, because parsing has
ended. | [
"Returns",
"a",
"token",
"from",
"the",
"current",
"input",
".",
"If",
"tok",
"is",
"None",
"from",
"the",
"current",
"input",
"it",
"means",
"we",
"are",
"at",
"end",
"of",
"current",
"input",
"(",
"e",
".",
"g",
".",
"at",
"end",
"of",
"include",
"file",
")",
".",
"If",
"so",
"closes",
"the",
"current",
"input",
"and",
"discards",
"it",
";",
"then",
"pops",
"the",
"previous",
"input",
"and",
"lexer",
"from",
"the",
"input",
"stack",
"and",
"gets",
"another",
"token",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L448-L476 |
boriel/zxbasic | zxbpplex.py | Lexer.find_column | def find_column(self, token):
""" Compute column:
- token is a token instance
"""
i = token.lexpos
while i > 0:
if self.input_data[i - 1] == '\n':
break
i -= 1
column = token.lexpos - i + 1
return column | python | def find_column(self, token):
""" Compute column:
- token is a token instance
"""
i = token.lexpos
while i > 0:
if self.input_data[i - 1] == '\n':
break
i -= 1
column = token.lexpos - i + 1
return column | [
"def",
"find_column",
"(",
"self",
",",
"token",
")",
":",
"i",
"=",
"token",
".",
"lexpos",
"while",
"i",
">",
"0",
":",
"if",
"self",
".",
"input_data",
"[",
"i",
"-",
"1",
"]",
"==",
"'\\n'",
":",
"break",
"i",
"-=",
"1",
"column",
"=",
"token",
".",
"lexpos",
"-",
"i",
"+",
"1",
"return",
"column"
] | Compute column:
- token is a token instance | [
"Compute",
"column",
":",
"-",
"token",
"is",
"a",
"token",
"instance"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbpplex.py#L478-L489 |
boriel/zxbasic | arch/zx48k/beep.py | getDEHL | def getDEHL(duration, pitch):
"""Converts duration,pitch to a pair of unsigned 16 bit integers,
to be loaded in DE,HL, following the ROM listing.
Returns a t-uple with the DE, HL values.
"""
intPitch = int(pitch)
fractPitch = pitch - intPitch # Gets fractional part
tmp = 1 + 0.0577622606 * fractPitch
if not -60 <= intPitch <= 127:
raise BeepError('Pitch out of range: must be between [-60, 127]')
if duration < 0 or duration > 10:
raise BeepError('Invalid duration: must be between [0, 10]')
A = intPitch + 60
B = -5 + int(A / 12) # -5 <= B <= 10
A %= 0xC # Semitones above C
frec = TABLE[A]
tmp2 = tmp * frec
f = tmp2 * 2.0 ** B
DE = int(0.5 + f * duration - 1)
HL = int(0.5 + 437500.0 / f - 30.125)
return DE, HL | python | def getDEHL(duration, pitch):
"""Converts duration,pitch to a pair of unsigned 16 bit integers,
to be loaded in DE,HL, following the ROM listing.
Returns a t-uple with the DE, HL values.
"""
intPitch = int(pitch)
fractPitch = pitch - intPitch # Gets fractional part
tmp = 1 + 0.0577622606 * fractPitch
if not -60 <= intPitch <= 127:
raise BeepError('Pitch out of range: must be between [-60, 127]')
if duration < 0 or duration > 10:
raise BeepError('Invalid duration: must be between [0, 10]')
A = intPitch + 60
B = -5 + int(A / 12) # -5 <= B <= 10
A %= 0xC # Semitones above C
frec = TABLE[A]
tmp2 = tmp * frec
f = tmp2 * 2.0 ** B
DE = int(0.5 + f * duration - 1)
HL = int(0.5 + 437500.0 / f - 30.125)
return DE, HL | [
"def",
"getDEHL",
"(",
"duration",
",",
"pitch",
")",
":",
"intPitch",
"=",
"int",
"(",
"pitch",
")",
"fractPitch",
"=",
"pitch",
"-",
"intPitch",
"# Gets fractional part",
"tmp",
"=",
"1",
"+",
"0.0577622606",
"*",
"fractPitch",
"if",
"not",
"-",
"60",
"<=",
"intPitch",
"<=",
"127",
":",
"raise",
"BeepError",
"(",
"'Pitch out of range: must be between [-60, 127]'",
")",
"if",
"duration",
"<",
"0",
"or",
"duration",
">",
"10",
":",
"raise",
"BeepError",
"(",
"'Invalid duration: must be between [0, 10]'",
")",
"A",
"=",
"intPitch",
"+",
"60",
"B",
"=",
"-",
"5",
"+",
"int",
"(",
"A",
"/",
"12",
")",
"# -5 <= B <= 10",
"A",
"%=",
"0xC",
"# Semitones above C",
"frec",
"=",
"TABLE",
"[",
"A",
"]",
"tmp2",
"=",
"tmp",
"*",
"frec",
"f",
"=",
"tmp2",
"*",
"2.0",
"**",
"B",
"DE",
"=",
"int",
"(",
"0.5",
"+",
"f",
"*",
"duration",
"-",
"1",
")",
"HL",
"=",
"int",
"(",
"0.5",
"+",
"437500.0",
"/",
"f",
"-",
"30.125",
")",
"return",
"DE",
",",
"HL"
] | Converts duration,pitch to a pair of unsigned 16 bit integers,
to be loaded in DE,HL, following the ROM listing.
Returns a t-uple with the DE, HL values. | [
"Converts",
"duration",
"pitch",
"to",
"a",
"pair",
"of",
"unsigned",
"16",
"bit",
"integers",
"to",
"be",
"loaded",
"in",
"DE",
"HL",
"following",
"the",
"ROM",
"listing",
".",
"Returns",
"a",
"t",
"-",
"uple",
"with",
"the",
"DE",
"HL",
"values",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/beep.py#L36-L60 |
boriel/zxbasic | symbols/block.py | SymbolBLOCK.make_node | def make_node(cls, *args):
""" Creates a chain of code blocks.
"""
new_args = []
args = [x for x in args if not is_null(x)]
for x in args:
assert isinstance(x, Symbol)
if x.token == 'BLOCK':
new_args.extend(SymbolBLOCK.make_node(*x.children).children)
else:
new_args.append(x)
result = SymbolBLOCK(*new_args)
return result | python | def make_node(cls, *args):
""" Creates a chain of code blocks.
"""
new_args = []
args = [x for x in args if not is_null(x)]
for x in args:
assert isinstance(x, Symbol)
if x.token == 'BLOCK':
new_args.extend(SymbolBLOCK.make_node(*x.children).children)
else:
new_args.append(x)
result = SymbolBLOCK(*new_args)
return result | [
"def",
"make_node",
"(",
"cls",
",",
"*",
"args",
")",
":",
"new_args",
"=",
"[",
"]",
"args",
"=",
"[",
"x",
"for",
"x",
"in",
"args",
"if",
"not",
"is_null",
"(",
"x",
")",
"]",
"for",
"x",
"in",
"args",
":",
"assert",
"isinstance",
"(",
"x",
",",
"Symbol",
")",
"if",
"x",
".",
"token",
"==",
"'BLOCK'",
":",
"new_args",
".",
"extend",
"(",
"SymbolBLOCK",
".",
"make_node",
"(",
"*",
"x",
".",
"children",
")",
".",
"children",
")",
"else",
":",
"new_args",
".",
"append",
"(",
"x",
")",
"result",
"=",
"SymbolBLOCK",
"(",
"*",
"new_args",
")",
"return",
"result"
] | Creates a chain of code blocks. | [
"Creates",
"a",
"chain",
"of",
"code",
"blocks",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/block.py#L23-L37 |
boriel/zxbasic | zxblex.py | t_MACROS | def t_MACROS(t):
r'__[a-zA-Z]+__'
if t.value in macros:
t.type = t.value
return t
syntax_error(t.lexer.lineno, "unknown macro '%s'" % t.value) | python | def t_MACROS(t):
r'__[a-zA-Z]+__'
if t.value in macros:
t.type = t.value
return t
syntax_error(t.lexer.lineno, "unknown macro '%s'" % t.value) | [
"def",
"t_MACROS",
"(",
"t",
")",
":",
"if",
"t",
".",
"value",
"in",
"macros",
":",
"t",
".",
"type",
"=",
"t",
".",
"value",
"return",
"t",
"syntax_error",
"(",
"t",
".",
"lexer",
".",
"lineno",
",",
"\"unknown macro '%s'\"",
"%",
"t",
".",
"value",
")"
] | r'__[a-zA-Z]+__ | [
"r",
"__",
"[",
"a",
"-",
"zA",
"-",
"Z",
"]",
"+",
"__"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L245-L252 |
boriel/zxbasic | zxblex.py | t_string_NGRAPH | def t_string_NGRAPH(t):
r"\\[ '.:][ '.:]"
global __STRING
P = {' ': 0, "'": 2, '.': 8, ':': 10}
N = {' ': 0, "'": 1, '.': 4, ':': 5}
__STRING += chr(128 + P[t.value[1]] + N[t.value[2]]) | python | def t_string_NGRAPH(t):
r"\\[ '.:][ '.:]"
global __STRING
P = {' ': 0, "'": 2, '.': 8, ':': 10}
N = {' ': 0, "'": 1, '.': 4, ':': 5}
__STRING += chr(128 + P[t.value[1]] + N[t.value[2]]) | [
"def",
"t_string_NGRAPH",
"(",
"t",
")",
":",
"global",
"__STRING",
"P",
"=",
"{",
"' '",
":",
"0",
",",
"\"'\"",
":",
"2",
",",
"'.'",
":",
"8",
",",
"':'",
":",
"10",
"}",
"N",
"=",
"{",
"' '",
":",
"0",
",",
"\"'\"",
":",
"1",
",",
"'.'",
":",
"4",
",",
"':'",
":",
"5",
"}",
"__STRING",
"+=",
"chr",
"(",
"128",
"+",
"P",
"[",
"t",
".",
"value",
"[",
"1",
"]",
"]",
"+",
"N",
"[",
"t",
".",
"value",
"[",
"2",
"]",
"]",
")"
] | r"\\[ '.:][ '.:] | [
"r",
"\\\\",
"[",
".",
":",
"]",
"[",
".",
":",
"]"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L274-L281 |
boriel/zxbasic | zxblex.py | t_string_STRC | def t_string_STRC(t):
r'"'
global __STRING
t.lexer.begin('INITIAL')
t.value = __STRING
__STRING = ''
return t | python | def t_string_STRC(t):
r'"'
global __STRING
t.lexer.begin('INITIAL')
t.value = __STRING
__STRING = ''
return t | [
"def",
"t_string_STRC",
"(",
"t",
")",
":",
"global",
"__STRING",
"t",
".",
"lexer",
".",
"begin",
"(",
"'INITIAL'",
")",
"t",
".",
"value",
"=",
"__STRING",
"__STRING",
"=",
"''",
"return",
"t"
] | r'" | [
"r"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L363-L371 |
boriel/zxbasic | zxblex.py | t_asm | def t_asm(t):
r'\b[aA][sS][mM]\b'
global ASM, ASMLINENO, IN_STATE
t.lexer.begin('asm')
ASM = ''
ASMLINENO = t.lexer.lineno
IN_STATE = True | python | def t_asm(t):
r'\b[aA][sS][mM]\b'
global ASM, ASMLINENO, IN_STATE
t.lexer.begin('asm')
ASM = ''
ASMLINENO = t.lexer.lineno
IN_STATE = True | [
"def",
"t_asm",
"(",
"t",
")",
":",
"global",
"ASM",
",",
"ASMLINENO",
",",
"IN_STATE",
"t",
".",
"lexer",
".",
"begin",
"(",
"'asm'",
")",
"ASM",
"=",
"''",
"ASMLINENO",
"=",
"t",
".",
"lexer",
".",
"lineno",
"IN_STATE",
"=",
"True"
] | r'\b[aA][sS][mM]\b | [
"r",
"\\",
"b",
"[",
"aA",
"]",
"[",
"sS",
"]",
"[",
"mM",
"]",
"\\",
"b"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L381-L389 |
boriel/zxbasic | zxblex.py | t_asm_ASM | def t_asm_ASM(t):
r'\b[eE][nN][dD][ \t]+[aA][sS][mM]\b'
global IN_STATE
t.lexer.begin('INITIAL')
t.value = ASM
t.lineno = ASMLINENO - 1
IN_STATE = False
return t | python | def t_asm_ASM(t):
r'\b[eE][nN][dD][ \t]+[aA][sS][mM]\b'
global IN_STATE
t.lexer.begin('INITIAL')
t.value = ASM
t.lineno = ASMLINENO - 1
IN_STATE = False
return t | [
"def",
"t_asm_ASM",
"(",
"t",
")",
":",
"global",
"IN_STATE",
"t",
".",
"lexer",
".",
"begin",
"(",
"'INITIAL'",
")",
"t",
".",
"value",
"=",
"ASM",
"t",
".",
"lineno",
"=",
"ASMLINENO",
"-",
"1",
"IN_STATE",
"=",
"False",
"return",
"t"
] | r'\b[eE][nN][dD][ \t]+[aA][sS][mM]\b | [
"r",
"\\",
"b",
"[",
"eE",
"]",
"[",
"nN",
"]",
"[",
"dD",
"]",
"[",
"\\",
"t",
"]",
"+",
"[",
"aA",
"]",
"[",
"sS",
"]",
"[",
"mM",
"]",
"\\",
"b"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L392-L402 |
boriel/zxbasic | zxblex.py | t_EmptyRem | def t_EmptyRem(t):
r"([']|[Rr][Ee][Mm])\r?\n"
t.lexer.begin('INITIAL')
t.lexer.lineno += 1
t.value = '\n'
t.type = 'NEWLINE'
return t | python | def t_EmptyRem(t):
r"([']|[Rr][Ee][Mm])\r?\n"
t.lexer.begin('INITIAL')
t.lexer.lineno += 1
t.value = '\n'
t.type = 'NEWLINE'
return t | [
"def",
"t_EmptyRem",
"(",
"t",
")",
":",
"t",
".",
"lexer",
".",
"begin",
"(",
"'INITIAL'",
")",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"t",
".",
"value",
"=",
"'\\n'",
"t",
".",
"type",
"=",
"'NEWLINE'",
"return",
"t"
] | r"([']|[Rr][Ee][Mm])\r?\n | [
"r",
"(",
"[",
"]",
"|",
"[",
"Rr",
"]",
"[",
"Ee",
"]",
"[",
"Mm",
"]",
")",
"\\",
"r?",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L437-L445 |
boriel/zxbasic | zxblex.py | t_preproc_ID | def t_preproc_ID(t):
r'[_A-Za-z]+'
t.value = t.value.strip()
t.type = preprocessor.get(t.value.lower(), 'ID')
return t | python | def t_preproc_ID(t):
r'[_A-Za-z]+'
t.value = t.value.strip()
t.type = preprocessor.get(t.value.lower(), 'ID')
return t | [
"def",
"t_preproc_ID",
"(",
"t",
")",
":",
"t",
".",
"value",
"=",
"t",
".",
"value",
".",
"strip",
"(",
")",
"t",
".",
"type",
"=",
"preprocessor",
".",
"get",
"(",
"t",
".",
"value",
".",
"lower",
"(",
")",
",",
"'ID'",
")",
"return",
"t"
] | r'[_A-Za-z]+ | [
"r",
"[",
"_A",
"-",
"Za",
"-",
"z",
"]",
"+"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L448-L453 |
boriel/zxbasic | zxblex.py | t_ID | def t_ID(t):
r'[a-zA-Z][a-zA-Z0-9]*[$%]?'
t.type = reserved.get(t.value.lower(), 'ID')
callables = {
api.constants.CLASS.array: 'ARRAY_ID',
}
if t.type != 'ID':
t.value = t.type
else:
entry = api.global_.SYMBOL_TABLE.get_entry(t.value) if api.global_.SYMBOL_TABLE is not None else None
if entry:
t.type = callables.get(entry.class_, t.type)
if t.type == 'BIN':
t.lexer.begin('bin')
return None
return t | python | def t_ID(t):
r'[a-zA-Z][a-zA-Z0-9]*[$%]?'
t.type = reserved.get(t.value.lower(), 'ID')
callables = {
api.constants.CLASS.array: 'ARRAY_ID',
}
if t.type != 'ID':
t.value = t.type
else:
entry = api.global_.SYMBOL_TABLE.get_entry(t.value) if api.global_.SYMBOL_TABLE is not None else None
if entry:
t.type = callables.get(entry.class_, t.type)
if t.type == 'BIN':
t.lexer.begin('bin')
return None
return t | [
"def",
"t_ID",
"(",
"t",
")",
":",
"t",
".",
"type",
"=",
"reserved",
".",
"get",
"(",
"t",
".",
"value",
".",
"lower",
"(",
")",
",",
"'ID'",
")",
"callables",
"=",
"{",
"api",
".",
"constants",
".",
"CLASS",
".",
"array",
":",
"'ARRAY_ID'",
",",
"}",
"if",
"t",
".",
"type",
"!=",
"'ID'",
":",
"t",
".",
"value",
"=",
"t",
".",
"type",
"else",
":",
"entry",
"=",
"api",
".",
"global_",
".",
"SYMBOL_TABLE",
".",
"get_entry",
"(",
"t",
".",
"value",
")",
"if",
"api",
".",
"global_",
".",
"SYMBOL_TABLE",
"is",
"not",
"None",
"else",
"None",
"if",
"entry",
":",
"t",
".",
"type",
"=",
"callables",
".",
"get",
"(",
"entry",
".",
"class_",
",",
"t",
".",
"type",
")",
"if",
"t",
".",
"type",
"==",
"'BIN'",
":",
"t",
".",
"lexer",
".",
"begin",
"(",
"'bin'",
")",
"return",
"None",
"return",
"t"
] | r'[a-zA-Z][a-zA-Z0-9]*[$%]? | [
"r",
"[",
"a",
"-",
"zA",
"-",
"Z",
"]",
"[",
"a",
"-",
"zA",
"-",
"Z0",
"-",
"9",
"]",
"*",
"[",
"$%",
"]",
"?"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L495-L513 |
boriel/zxbasic | zxblex.py | t_HEXA | def t_HEXA(t):
r'([0-9][0-9a-fA-F]*[hH])|(\$[0-9a-fA-F]+)|(0x[0-9a-fA-F]+)'
if t.value[0] == '$':
t.value = t.value[1:] # Remove initial '$'
elif t.value[:2] == '0x':
t.value = t.value[2:] # Remove initial '0x'
else:
t.value = t.value[:-1] # Remove last 'h'
t.value = int(t.value, 16) # Convert to decimal
t.type = 'NUMBER'
return t | python | def t_HEXA(t):
r'([0-9][0-9a-fA-F]*[hH])|(\$[0-9a-fA-F]+)|(0x[0-9a-fA-F]+)'
if t.value[0] == '$':
t.value = t.value[1:] # Remove initial '$'
elif t.value[:2] == '0x':
t.value = t.value[2:] # Remove initial '0x'
else:
t.value = t.value[:-1] # Remove last 'h'
t.value = int(t.value, 16) # Convert to decimal
t.type = 'NUMBER'
return t | [
"def",
"t_HEXA",
"(",
"t",
")",
":",
"if",
"t",
".",
"value",
"[",
"0",
"]",
"==",
"'$'",
":",
"t",
".",
"value",
"=",
"t",
".",
"value",
"[",
"1",
":",
"]",
"# Remove initial '$'",
"elif",
"t",
".",
"value",
"[",
":",
"2",
"]",
"==",
"'0x'",
":",
"t",
".",
"value",
"=",
"t",
".",
"value",
"[",
"2",
":",
"]",
"# Remove initial '0x'",
"else",
":",
"t",
".",
"value",
"=",
"t",
".",
"value",
"[",
":",
"-",
"1",
"]",
"# Remove last 'h'",
"t",
".",
"value",
"=",
"int",
"(",
"t",
".",
"value",
",",
"16",
")",
"# Convert to decimal",
"t",
".",
"type",
"=",
"'NUMBER'",
"return",
"t"
] | r'([0-9][0-9a-fA-F]*[hH])|(\$[0-9a-fA-F]+)|(0x[0-9a-fA-F]+) | [
"r",
"(",
"[",
"0",
"-",
"9",
"]",
"[",
"0",
"-",
"9a",
"-",
"fA",
"-",
"F",
"]",
"*",
"[",
"hH",
"]",
")",
"|",
"(",
"\\",
"$",
"[",
"0",
"-",
"9a",
"-",
"fA",
"-",
"F",
"]",
"+",
")",
"|",
"(",
"0x",
"[",
"0",
"-",
"9a",
"-",
"fA",
"-",
"F",
"]",
"+",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L516-L528 |
boriel/zxbasic | zxblex.py | t_OCTAL | def t_OCTAL(t):
r'[0-7]+[oO]'
t.value = t.value[:-1]
t.type = 'NUMBER'
t.value = int(t.value, 8)
return t | python | def t_OCTAL(t):
r'[0-7]+[oO]'
t.value = t.value[:-1]
t.type = 'NUMBER'
t.value = int(t.value, 8)
return t | [
"def",
"t_OCTAL",
"(",
"t",
")",
":",
"t",
".",
"value",
"=",
"t",
".",
"value",
"[",
":",
"-",
"1",
"]",
"t",
".",
"type",
"=",
"'NUMBER'",
"t",
".",
"value",
"=",
"int",
"(",
"t",
".",
"value",
",",
"8",
")",
"return",
"t"
] | r'[0-7]+[oO] | [
"r",
"[",
"0",
"-",
"7",
"]",
"+",
"[",
"oO",
"]"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L531-L537 |
boriel/zxbasic | zxblex.py | t_bin_NUMBER | def t_bin_NUMBER(t):
r'[01]+' # A binary integer
t.value = int(t.value, 2)
t.lexer.begin('INITIAL')
return t | python | def t_bin_NUMBER(t):
r'[01]+' # A binary integer
t.value = int(t.value, 2)
t.lexer.begin('INITIAL')
return t | [
"def",
"t_bin_NUMBER",
"(",
"t",
")",
":",
"# A binary integer",
"t",
".",
"value",
"=",
"int",
"(",
"t",
".",
"value",
",",
"2",
")",
"t",
".",
"lexer",
".",
"begin",
"(",
"'INITIAL'",
")",
"return",
"t"
] | r'[01]+ | [
"r",
"[",
"01",
"]",
"+"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L557-L562 |
boriel/zxbasic | zxblex.py | t_NUMBER | def t_NUMBER(t):
# This pattern must come AFTER t_HEXA and t_BIN
r'(([0-9]+(\.[0-9]+)?)|(\.[0-9]+))([eE][-+]?[0-9]+)?'
t.text = t.value
t.value = float(t.value)
if t.value == int(t.value) and is_label(t):
t.value = int(t.value)
t.type = 'LABEL'
return t | python | def t_NUMBER(t):
# This pattern must come AFTER t_HEXA and t_BIN
r'(([0-9]+(\.[0-9]+)?)|(\.[0-9]+))([eE][-+]?[0-9]+)?'
t.text = t.value
t.value = float(t.value)
if t.value == int(t.value) and is_label(t):
t.value = int(t.value)
t.type = 'LABEL'
return t | [
"def",
"t_NUMBER",
"(",
"t",
")",
":",
"# This pattern must come AFTER t_HEXA and t_BIN",
"t",
".",
"text",
"=",
"t",
".",
"value",
"t",
".",
"value",
"=",
"float",
"(",
"t",
".",
"value",
")",
"if",
"t",
".",
"value",
"==",
"int",
"(",
"t",
".",
"value",
")",
"and",
"is_label",
"(",
"t",
")",
":",
"t",
".",
"value",
"=",
"int",
"(",
"t",
".",
"value",
")",
"t",
".",
"type",
"=",
"'LABEL'",
"return",
"t"
] | r'(([0-9]+(\.[0-9]+)?)|(\.[0-9]+))([eE][-+]?[0-9]+)? | [
"r",
"((",
"[",
"0",
"-",
"9",
"]",
"+",
"(",
"\\",
".",
"[",
"0",
"-",
"9",
"]",
"+",
")",
"?",
")",
"|",
"(",
"\\",
".",
"[",
"0",
"-",
"9",
"]",
"+",
"))",
"(",
"[",
"eE",
"]",
"[",
"-",
"+",
"]",
"?",
"[",
"0",
"-",
"9",
"]",
"+",
")",
"?"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L565-L575 |
boriel/zxbasic | zxblex.py | t_bin_ZERO | def t_bin_ZERO(t):
r'[^01]'
t.lexer.begin('INITIAL')
t.type = 'NUMBER'
t.value = 0
t.lexer.lexpos -= 1
return t | python | def t_bin_ZERO(t):
r'[^01]'
t.lexer.begin('INITIAL')
t.type = 'NUMBER'
t.value = 0
t.lexer.lexpos -= 1
return t | [
"def",
"t_bin_ZERO",
"(",
"t",
")",
":",
"t",
".",
"lexer",
".",
"begin",
"(",
"'INITIAL'",
")",
"t",
".",
"type",
"=",
"'NUMBER'",
"t",
".",
"value",
"=",
"0",
"t",
".",
"lexer",
".",
"lexpos",
"-=",
"1",
"return",
"t"
] | r'[^01] | [
"r",
"[",
"^01",
"]"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L592-L598 |
boriel/zxbasic | zxblex.py | t_INITIAL_bin_NEWLINE | def t_INITIAL_bin_NEWLINE(t):
r'\r?\n'
global LABELS_ALLOWED
t.lexer.lineno += 1
t.value = '\n'
LABELS_ALLOWED = True
return t | python | def t_INITIAL_bin_NEWLINE(t):
r'\r?\n'
global LABELS_ALLOWED
t.lexer.lineno += 1
t.value = '\n'
LABELS_ALLOWED = True
return t | [
"def",
"t_INITIAL_bin_NEWLINE",
"(",
"t",
")",
":",
"global",
"LABELS_ALLOWED",
"t",
".",
"lexer",
".",
"lineno",
"+=",
"1",
"t",
".",
"value",
"=",
"'\\n'",
"LABELS_ALLOWED",
"=",
"True",
"return",
"t"
] | r'\r?\n | [
"r",
"\\",
"r?",
"\\",
"n"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L602-L609 |
boriel/zxbasic | zxblex.py | find_column | def find_column(token):
""" Compute column:
input is the input text string
token is a token instance
"""
i = token.lexpos
input = token.lexer.lexdata
while i > 0:
if input[i - 1] == '\n':
break
i -= 1
column = token.lexpos - i + 1
return column | python | def find_column(token):
""" Compute column:
input is the input text string
token is a token instance
"""
i = token.lexpos
input = token.lexer.lexdata
while i > 0:
if input[i - 1] == '\n':
break
i -= 1
column = token.lexpos - i + 1
return column | [
"def",
"find_column",
"(",
"token",
")",
":",
"i",
"=",
"token",
".",
"lexpos",
"input",
"=",
"token",
".",
"lexer",
".",
"lexdata",
"while",
"i",
">",
"0",
":",
"if",
"input",
"[",
"i",
"-",
"1",
"]",
"==",
"'\\n'",
":",
"break",
"i",
"-=",
"1",
"column",
"=",
"token",
".",
"lexpos",
"-",
"i",
"+",
"1",
"return",
"column"
] | Compute column:
input is the input text string
token is a token instance | [
"Compute",
"column",
":",
"input",
"is",
"the",
"input",
"text",
"string",
"token",
"is",
"a",
"token",
"instance"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L625-L640 |
boriel/zxbasic | zxblex.py | is_label | def is_label(token):
""" Return whether the token is a label (an integer number or id
at the beginning of a line.
To do so, we compute find_column() and moves back to the beginning
of the line if previous chars are spaces or tabs. If column 0 is
reached, it's a label.
"""
if not LABELS_ALLOWED:
return False
c = i = token.lexpos
input = token.lexer.lexdata
c -= 1
while c > 0 and input[c] in (' ', '\t'):
c -= 1
while i > 0:
if input[i] == '\n':
break
i -= 1
column = c - i
if column == 0:
column += 1
return column == 1 | python | def is_label(token):
""" Return whether the token is a label (an integer number or id
at the beginning of a line.
To do so, we compute find_column() and moves back to the beginning
of the line if previous chars are spaces or tabs. If column 0 is
reached, it's a label.
"""
if not LABELS_ALLOWED:
return False
c = i = token.lexpos
input = token.lexer.lexdata
c -= 1
while c > 0 and input[c] in (' ', '\t'):
c -= 1
while i > 0:
if input[i] == '\n':
break
i -= 1
column = c - i
if column == 0:
column += 1
return column == 1 | [
"def",
"is_label",
"(",
"token",
")",
":",
"if",
"not",
"LABELS_ALLOWED",
":",
"return",
"False",
"c",
"=",
"i",
"=",
"token",
".",
"lexpos",
"input",
"=",
"token",
".",
"lexer",
".",
"lexdata",
"c",
"-=",
"1",
"while",
"c",
">",
"0",
"and",
"input",
"[",
"c",
"]",
"in",
"(",
"' '",
",",
"'\\t'",
")",
":",
"c",
"-=",
"1",
"while",
"i",
">",
"0",
":",
"if",
"input",
"[",
"i",
"]",
"==",
"'\\n'",
":",
"break",
"i",
"-=",
"1",
"column",
"=",
"c",
"-",
"i",
"if",
"column",
"==",
"0",
":",
"column",
"+=",
"1",
"return",
"column",
"==",
"1"
] | Return whether the token is a label (an integer number or id
at the beginning of a line.
To do so, we compute find_column() and moves back to the beginning
of the line if previous chars are spaces or tabs. If column 0 is
reached, it's a label. | [
"Return",
"whether",
"the",
"token",
"is",
"a",
"label",
"(",
"an",
"integer",
"number",
"or",
"id",
"at",
"the",
"beginning",
"of",
"a",
"line",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxblex.py#L643-L670 |
boriel/zxbasic | symbols/number.py | _get_val | def _get_val(other):
""" Given a Number, a Numeric Constant or a python number return its value
"""
assert isinstance(other, (numbers.Number, SymbolNUMBER, SymbolCONST))
if isinstance(other, SymbolNUMBER):
return other.value
if isinstance(other, SymbolCONST):
return other.expr.value
return other | python | def _get_val(other):
""" Given a Number, a Numeric Constant or a python number return its value
"""
assert isinstance(other, (numbers.Number, SymbolNUMBER, SymbolCONST))
if isinstance(other, SymbolNUMBER):
return other.value
if isinstance(other, SymbolCONST):
return other.expr.value
return other | [
"def",
"_get_val",
"(",
"other",
")",
":",
"assert",
"isinstance",
"(",
"other",
",",
"(",
"numbers",
".",
"Number",
",",
"SymbolNUMBER",
",",
"SymbolCONST",
")",
")",
"if",
"isinstance",
"(",
"other",
",",
"SymbolNUMBER",
")",
":",
"return",
"other",
".",
"value",
"if",
"isinstance",
"(",
"other",
",",
"SymbolCONST",
")",
":",
"return",
"other",
".",
"expr",
".",
"value",
"return",
"other"
] | Given a Number, a Numeric Constant or a python number return its value | [
"Given",
"a",
"Number",
"a",
"Numeric",
"Constant",
"or",
"a",
"python",
"number",
"return",
"its",
"value"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/number.py#L21-L31 |
boriel/zxbasic | prepro/id_.py | ID.__dumptable | def __dumptable(self, table):
""" Dumps table on screen
for debugging purposes
"""
for x in table.table.keys():
sys.stdout.write("{0}\t<--- {1} {2}".format(x, table[x], type(table[x])))
if isinstance(table[x], ID):
sys.stdout(" {0}".format(table[x].value)),
sys.stdout.write("\n") | python | def __dumptable(self, table):
""" Dumps table on screen
for debugging purposes
"""
for x in table.table.keys():
sys.stdout.write("{0}\t<--- {1} {2}".format(x, table[x], type(table[x])))
if isinstance(table[x], ID):
sys.stdout(" {0}".format(table[x].value)),
sys.stdout.write("\n") | [
"def",
"__dumptable",
"(",
"self",
",",
"table",
")",
":",
"for",
"x",
"in",
"table",
".",
"table",
".",
"keys",
"(",
")",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\"{0}\\t<--- {1} {2}\"",
".",
"format",
"(",
"x",
",",
"table",
"[",
"x",
"]",
",",
"type",
"(",
"table",
"[",
"x",
"]",
")",
")",
")",
"if",
"isinstance",
"(",
"table",
"[",
"x",
"]",
",",
"ID",
")",
":",
"sys",
".",
"stdout",
"(",
"\" {0}\"",
".",
"format",
"(",
"table",
"[",
"x",
"]",
".",
"value",
")",
")",
",",
"sys",
".",
"stdout",
".",
"write",
"(",
"\"\\n\"",
")"
] | Dumps table on screen
for debugging purposes | [
"Dumps",
"table",
"on",
"screen",
"for",
"debugging",
"purposes"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/prepro/id_.py#L44-L52 |
boriel/zxbasic | api/optimize.py | OptimizerVisitor.visit_RETURN | def visit_RETURN(self, node):
""" Visits only children[1], since children[0] points to
the current function being returned from (if any), and
might cause infinite recursion.
"""
if len(node.children) == 2:
node.children[1] = (yield ToVisit(node.children[1]))
yield node | python | def visit_RETURN(self, node):
""" Visits only children[1], since children[0] points to
the current function being returned from (if any), and
might cause infinite recursion.
"""
if len(node.children) == 2:
node.children[1] = (yield ToVisit(node.children[1]))
yield node | [
"def",
"visit_RETURN",
"(",
"self",
",",
"node",
")",
":",
"if",
"len",
"(",
"node",
".",
"children",
")",
"==",
"2",
":",
"node",
".",
"children",
"[",
"1",
"]",
"=",
"(",
"yield",
"ToVisit",
"(",
"node",
".",
"children",
"[",
"1",
"]",
")",
")",
"yield",
"node"
] | Visits only children[1], since children[0] points to
the current function being returned from (if any), and
might cause infinite recursion. | [
"Visits",
"only",
"children",
"[",
"1",
"]",
"since",
"children",
"[",
"0",
"]",
"points",
"to",
"the",
"current",
"function",
"being",
"returned",
"from",
"(",
"if",
"any",
")",
"and",
"might",
"cause",
"infinite",
"recursion",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/api/optimize.py#L160-L167 |
boriel/zxbasic | symbols/vararray.py | SymbolVARARRAY.count | def count(self):
""" Total number of array cells
"""
return functools.reduce(lambda x, y: x * y, (x.count for x in self.bounds)) | python | def count(self):
""" Total number of array cells
"""
return functools.reduce(lambda x, y: x * y, (x.count for x in self.bounds)) | [
"def",
"count",
"(",
"self",
")",
":",
"return",
"functools",
".",
"reduce",
"(",
"lambda",
"x",
",",
"y",
":",
"x",
"*",
"y",
",",
"(",
"x",
".",
"count",
"for",
"x",
"in",
"self",
".",
"bounds",
")",
")"
] | Total number of array cells | [
"Total",
"number",
"of",
"array",
"cells"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/vararray.py#L38-L41 |
boriel/zxbasic | symbols/vararray.py | SymbolVARARRAY.memsize | def memsize(self):
""" Total array cell + indexes size
"""
return self.size + 1 + TYPE.size(gl.BOUND_TYPE) * len(self.bounds) | python | def memsize(self):
""" Total array cell + indexes size
"""
return self.size + 1 + TYPE.size(gl.BOUND_TYPE) * len(self.bounds) | [
"def",
"memsize",
"(",
"self",
")",
":",
"return",
"self",
".",
"size",
"+",
"1",
"+",
"TYPE",
".",
"size",
"(",
"gl",
".",
"BOUND_TYPE",
")",
"*",
"len",
"(",
"self",
".",
"bounds",
")"
] | Total array cell + indexes size | [
"Total",
"array",
"cell",
"+",
"indexes",
"size"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/vararray.py#L48-L51 |
boriel/zxbasic | symbols/typecast.py | SymbolTYPECAST.make_node | def make_node(cls, new_type, node, lineno):
""" Creates a node containing the type cast of
the given one. If new_type == node.type, then
nothing is done, and the same node is
returned.
Returns None on failure (and calls syntax_error)
"""
assert isinstance(new_type, SymbolTYPE)
# None (null) means the given AST node is empty (usually an error)
if node is None:
return None # Do nothing. Return None
assert isinstance(node, Symbol), '<%s> is not a Symbol' % node
# The source and dest types are the same
if new_type == node.type_:
return node # Do nothing. Return as is
STRTYPE = TYPE.string
# Typecasting, at the moment, only for number
if node.type_ == STRTYPE:
syntax_error(lineno, 'Cannot convert string to a value. '
'Use VAL() function')
return None
# Converting from string to number is done by STR
if new_type == STRTYPE:
syntax_error(lineno, 'Cannot convert value to string. '
'Use STR() function')
return None
# If the given operand is a constant, perform a static typecast
if is_CONST(node):
node.expr = cls(new_type, node.expr, lineno)
return node
if not is_number(node) and not is_const(node):
return cls(new_type, node, lineno)
# It's a number. So let's convert it directly
if is_const(node):
node = SymbolNUMBER(node.value, node.lineno, node.type_)
if new_type.is_basic and not TYPE.is_integral(new_type): # not an integer
node.value = float(node.value)
else: # It's an integer
new_val = (int(node.value) & ((1 << (8 * new_type.size)) - 1)) # Mask it
if node.value >= 0 and node.value != new_val:
errmsg.warning_conversion_lose_digits(node.lineno)
node.value = new_val
elif node.value < 0 and (1 << (new_type.size * 8)) + \
node.value != new_val: # Test for positive to negative coercion
errmsg.warning_conversion_lose_digits(node.lineno)
node.value = new_val - (1 << (new_type.size * 8))
node.type_ = new_type
return node | python | def make_node(cls, new_type, node, lineno):
""" Creates a node containing the type cast of
the given one. If new_type == node.type, then
nothing is done, and the same node is
returned.
Returns None on failure (and calls syntax_error)
"""
assert isinstance(new_type, SymbolTYPE)
# None (null) means the given AST node is empty (usually an error)
if node is None:
return None # Do nothing. Return None
assert isinstance(node, Symbol), '<%s> is not a Symbol' % node
# The source and dest types are the same
if new_type == node.type_:
return node # Do nothing. Return as is
STRTYPE = TYPE.string
# Typecasting, at the moment, only for number
if node.type_ == STRTYPE:
syntax_error(lineno, 'Cannot convert string to a value. '
'Use VAL() function')
return None
# Converting from string to number is done by STR
if new_type == STRTYPE:
syntax_error(lineno, 'Cannot convert value to string. '
'Use STR() function')
return None
# If the given operand is a constant, perform a static typecast
if is_CONST(node):
node.expr = cls(new_type, node.expr, lineno)
return node
if not is_number(node) and not is_const(node):
return cls(new_type, node, lineno)
# It's a number. So let's convert it directly
if is_const(node):
node = SymbolNUMBER(node.value, node.lineno, node.type_)
if new_type.is_basic and not TYPE.is_integral(new_type): # not an integer
node.value = float(node.value)
else: # It's an integer
new_val = (int(node.value) & ((1 << (8 * new_type.size)) - 1)) # Mask it
if node.value >= 0 and node.value != new_val:
errmsg.warning_conversion_lose_digits(node.lineno)
node.value = new_val
elif node.value < 0 and (1 << (new_type.size * 8)) + \
node.value != new_val: # Test for positive to negative coercion
errmsg.warning_conversion_lose_digits(node.lineno)
node.value = new_val - (1 << (new_type.size * 8))
node.type_ = new_type
return node | [
"def",
"make_node",
"(",
"cls",
",",
"new_type",
",",
"node",
",",
"lineno",
")",
":",
"assert",
"isinstance",
"(",
"new_type",
",",
"SymbolTYPE",
")",
"# None (null) means the given AST node is empty (usually an error)",
"if",
"node",
"is",
"None",
":",
"return",
"None",
"# Do nothing. Return None",
"assert",
"isinstance",
"(",
"node",
",",
"Symbol",
")",
",",
"'<%s> is not a Symbol'",
"%",
"node",
"# The source and dest types are the same",
"if",
"new_type",
"==",
"node",
".",
"type_",
":",
"return",
"node",
"# Do nothing. Return as is",
"STRTYPE",
"=",
"TYPE",
".",
"string",
"# Typecasting, at the moment, only for number",
"if",
"node",
".",
"type_",
"==",
"STRTYPE",
":",
"syntax_error",
"(",
"lineno",
",",
"'Cannot convert string to a value. '",
"'Use VAL() function'",
")",
"return",
"None",
"# Converting from string to number is done by STR",
"if",
"new_type",
"==",
"STRTYPE",
":",
"syntax_error",
"(",
"lineno",
",",
"'Cannot convert value to string. '",
"'Use STR() function'",
")",
"return",
"None",
"# If the given operand is a constant, perform a static typecast",
"if",
"is_CONST",
"(",
"node",
")",
":",
"node",
".",
"expr",
"=",
"cls",
"(",
"new_type",
",",
"node",
".",
"expr",
",",
"lineno",
")",
"return",
"node",
"if",
"not",
"is_number",
"(",
"node",
")",
"and",
"not",
"is_const",
"(",
"node",
")",
":",
"return",
"cls",
"(",
"new_type",
",",
"node",
",",
"lineno",
")",
"# It's a number. So let's convert it directly",
"if",
"is_const",
"(",
"node",
")",
":",
"node",
"=",
"SymbolNUMBER",
"(",
"node",
".",
"value",
",",
"node",
".",
"lineno",
",",
"node",
".",
"type_",
")",
"if",
"new_type",
".",
"is_basic",
"and",
"not",
"TYPE",
".",
"is_integral",
"(",
"new_type",
")",
":",
"# not an integer",
"node",
".",
"value",
"=",
"float",
"(",
"node",
".",
"value",
")",
"else",
":",
"# It's an integer",
"new_val",
"=",
"(",
"int",
"(",
"node",
".",
"value",
")",
"&",
"(",
"(",
"1",
"<<",
"(",
"8",
"*",
"new_type",
".",
"size",
")",
")",
"-",
"1",
")",
")",
"# Mask it",
"if",
"node",
".",
"value",
">=",
"0",
"and",
"node",
".",
"value",
"!=",
"new_val",
":",
"errmsg",
".",
"warning_conversion_lose_digits",
"(",
"node",
".",
"lineno",
")",
"node",
".",
"value",
"=",
"new_val",
"elif",
"node",
".",
"value",
"<",
"0",
"and",
"(",
"1",
"<<",
"(",
"new_type",
".",
"size",
"*",
"8",
")",
")",
"+",
"node",
".",
"value",
"!=",
"new_val",
":",
"# Test for positive to negative coercion",
"errmsg",
".",
"warning_conversion_lose_digits",
"(",
"node",
".",
"lineno",
")",
"node",
".",
"value",
"=",
"new_val",
"-",
"(",
"1",
"<<",
"(",
"new_type",
".",
"size",
"*",
"8",
")",
")",
"node",
".",
"type_",
"=",
"new_type",
"return",
"node"
] | Creates a node containing the type cast of
the given one. If new_type == node.type, then
nothing is done, and the same node is
returned.
Returns None on failure (and calls syntax_error) | [
"Creates",
"a",
"node",
"containing",
"the",
"type",
"cast",
"of",
"the",
"given",
"one",
".",
"If",
"new_type",
"==",
"node",
".",
"type",
"then",
"nothing",
"is",
"done",
"and",
"the",
"same",
"node",
"is",
"returned",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/typecast.py#L44-L102 |
boriel/zxbasic | asmparse.py | normalize_namespace | def normalize_namespace(namespace):
""" Given a namespace (e.g. '.' or 'mynamespace'),
returns it in normalized form. That is:
- always prefixed with a dot
- no trailing dots
- any double dots are converted to single dot (..my..namespace => .my.namespace)
- one or more dots (e.g. '.', '..', '...') are converted to '.' (Global namespace)
"""
namespace = (DOT + DOT.join(RE_DOTS.split(namespace))).rstrip(DOT) + DOT
return namespace | python | def normalize_namespace(namespace):
""" Given a namespace (e.g. '.' or 'mynamespace'),
returns it in normalized form. That is:
- always prefixed with a dot
- no trailing dots
- any double dots are converted to single dot (..my..namespace => .my.namespace)
- one or more dots (e.g. '.', '..', '...') are converted to '.' (Global namespace)
"""
namespace = (DOT + DOT.join(RE_DOTS.split(namespace))).rstrip(DOT) + DOT
return namespace | [
"def",
"normalize_namespace",
"(",
"namespace",
")",
":",
"namespace",
"=",
"(",
"DOT",
"+",
"DOT",
".",
"join",
"(",
"RE_DOTS",
".",
"split",
"(",
"namespace",
")",
")",
")",
".",
"rstrip",
"(",
"DOT",
")",
"+",
"DOT",
"return",
"namespace"
] | Given a namespace (e.g. '.' or 'mynamespace'),
returns it in normalized form. That is:
- always prefixed with a dot
- no trailing dots
- any double dots are converted to single dot (..my..namespace => .my.namespace)
- one or more dots (e.g. '.', '..', '...') are converted to '.' (Global namespace) | [
"Given",
"a",
"namespace",
"(",
"e",
".",
"g",
".",
".",
"or",
"mynamespace",
")",
"returns",
"it",
"in",
"normalized",
"form",
".",
"That",
"is",
":",
"-",
"always",
"prefixed",
"with",
"a",
"dot",
"-",
"no",
"trailing",
"dots",
"-",
"any",
"double",
"dots",
"are",
"converted",
"to",
"single",
"dot",
"(",
"..",
"my",
"..",
"namespace",
"=",
">",
".",
"my",
".",
"namespace",
")",
"-",
"one",
"or",
"more",
"dots",
"(",
"e",
".",
"g",
".",
".",
"..",
"...",
")",
"are",
"converted",
"to",
".",
"(",
"Global",
"namespace",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L55-L64 |
boriel/zxbasic | asmparse.py | init | def init():
""" Initializes this module
"""
global ORG
global LEXER
global MEMORY
global INITS
global AUTORUN_ADDR
global NAMESPACE
ORG = 0 # Origin of CODE
INITS = []
MEMORY = None # Memory for instructions (Will be initialized with a Memory() instance)
AUTORUN_ADDR = None # Where to start the execution automatically
NAMESPACE = GLOBAL_NAMESPACE # Current namespace (defaults to ''). It's a prefix added to each global label
gl.has_errors = 0
gl.error_msg_cache.clear() | python | def init():
""" Initializes this module
"""
global ORG
global LEXER
global MEMORY
global INITS
global AUTORUN_ADDR
global NAMESPACE
ORG = 0 # Origin of CODE
INITS = []
MEMORY = None # Memory for instructions (Will be initialized with a Memory() instance)
AUTORUN_ADDR = None # Where to start the execution automatically
NAMESPACE = GLOBAL_NAMESPACE # Current namespace (defaults to ''). It's a prefix added to each global label
gl.has_errors = 0
gl.error_msg_cache.clear() | [
"def",
"init",
"(",
")",
":",
"global",
"ORG",
"global",
"LEXER",
"global",
"MEMORY",
"global",
"INITS",
"global",
"AUTORUN_ADDR",
"global",
"NAMESPACE",
"ORG",
"=",
"0",
"# Origin of CODE",
"INITS",
"=",
"[",
"]",
"MEMORY",
"=",
"None",
"# Memory for instructions (Will be initialized with a Memory() instance)",
"AUTORUN_ADDR",
"=",
"None",
"# Where to start the execution automatically",
"NAMESPACE",
"=",
"GLOBAL_NAMESPACE",
"# Current namespace (defaults to ''). It's a prefix added to each global label",
"gl",
".",
"has_errors",
"=",
"0",
"gl",
".",
"error_msg_cache",
".",
"clear",
"(",
")"
] | Initializes this module | [
"Initializes",
"this",
"module"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L67-L83 |
boriel/zxbasic | asmparse.py | p_program | def p_program(p):
""" program : line
"""
if p[1] is not None:
[MEMORY.add_instruction(x) for x in p[1] if isinstance(x, Asm)] | python | def p_program(p):
""" program : line
"""
if p[1] is not None:
[MEMORY.add_instruction(x) for x in p[1] if isinstance(x, Asm)] | [
"def",
"p_program",
"(",
"p",
")",
":",
"if",
"p",
"[",
"1",
"]",
"is",
"not",
"None",
":",
"[",
"MEMORY",
".",
"add_instruction",
"(",
"x",
")",
"for",
"x",
"in",
"p",
"[",
"1",
"]",
"if",
"isinstance",
"(",
"x",
",",
"Asm",
")",
"]"
] | program : line | [
"program",
":",
"line"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L601-L605 |
boriel/zxbasic | asmparse.py | p_program_line | def p_program_line(p):
""" program : program line
"""
if p[2] is not None:
[MEMORY.add_instruction(x) for x in p[2] if isinstance(x, Asm)] | python | def p_program_line(p):
""" program : program line
"""
if p[2] is not None:
[MEMORY.add_instruction(x) for x in p[2] if isinstance(x, Asm)] | [
"def",
"p_program_line",
"(",
"p",
")",
":",
"if",
"p",
"[",
"2",
"]",
"is",
"not",
"None",
":",
"[",
"MEMORY",
".",
"add_instruction",
"(",
"x",
")",
"for",
"x",
"in",
"p",
"[",
"2",
"]",
"if",
"isinstance",
"(",
"x",
",",
"Asm",
")",
"]"
] | program : program line | [
"program",
":",
"program",
"line"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L608-L612 |
boriel/zxbasic | asmparse.py | p_def_label | def p_def_label(p):
""" line : ID EQU expr NEWLINE
| ID EQU pexpr NEWLINE
"""
p[0] = None
__DEBUG__("Declaring '%s%s' in %i" % (NAMESPACE, p[1], p.lineno(1)))
MEMORY.declare_label(p[1], p.lineno(1), p[3]) | python | def p_def_label(p):
""" line : ID EQU expr NEWLINE
| ID EQU pexpr NEWLINE
"""
p[0] = None
__DEBUG__("Declaring '%s%s' in %i" % (NAMESPACE, p[1], p.lineno(1)))
MEMORY.declare_label(p[1], p.lineno(1), p[3]) | [
"def",
"p_def_label",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"None",
"__DEBUG__",
"(",
"\"Declaring '%s%s' in %i\"",
"%",
"(",
"NAMESPACE",
",",
"p",
"[",
"1",
"]",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")",
")",
"MEMORY",
".",
"declare_label",
"(",
"p",
"[",
"1",
"]",
",",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"p",
"[",
"3",
"]",
")"
] | line : ID EQU expr NEWLINE
| ID EQU pexpr NEWLINE | [
"line",
":",
"ID",
"EQU",
"expr",
"NEWLINE",
"|",
"ID",
"EQU",
"pexpr",
"NEWLINE"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L615-L621 |
boriel/zxbasic | asmparse.py | p_line_label_asm | def p_line_label_asm(p):
""" line : LABEL asms NEWLINE
"""
p[0] = p[2]
__DEBUG__("Declaring '%s%s' (value %04Xh) in %i" % (NAMESPACE, p[1], MEMORY.org, p.lineno(1)))
MEMORY.declare_label(p[1], p.lineno(1)) | python | def p_line_label_asm(p):
""" line : LABEL asms NEWLINE
"""
p[0] = p[2]
__DEBUG__("Declaring '%s%s' (value %04Xh) in %i" % (NAMESPACE, p[1], MEMORY.org, p.lineno(1)))
MEMORY.declare_label(p[1], p.lineno(1)) | [
"def",
"p_line_label_asm",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"p",
"[",
"2",
"]",
"__DEBUG__",
"(",
"\"Declaring '%s%s' (value %04Xh) in %i\"",
"%",
"(",
"NAMESPACE",
",",
"p",
"[",
"1",
"]",
",",
"MEMORY",
".",
"org",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")",
")",
"MEMORY",
".",
"declare_label",
"(",
"p",
"[",
"1",
"]",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")"
] | line : LABEL asms NEWLINE | [
"line",
":",
"LABEL",
"asms",
"NEWLINE"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L624-L629 |
boriel/zxbasic | asmparse.py | p_asm_ld8 | def p_asm_ld8(p):
""" asm : LD reg8 COMMA reg8_hl
| LD reg8_hl COMMA reg8
| LD reg8 COMMA reg8
| LD SP COMMA HL
| LD SP COMMA reg16i
| LD A COMMA reg8
| LD reg8 COMMA A
| LD reg8_hl COMMA A
| LD A COMMA reg8_hl
| LD A COMMA A
| LD A COMMA I
| LD I COMMA A
| LD A COMMA R
| LD R COMMA A
| LD A COMMA reg8i
| LD reg8i COMMA A
| LD reg8 COMMA reg8i
| LD reg8i COMMA regBCDE
| LD reg8i COMMA reg8i
"""
if p[2] in ('H', 'L') and p[4] in ('IXH', 'IXL', 'IYH', 'IYL'):
p[0] = None
error(p.lineno(0), "Unexpected token '%s'" % p[4])
else:
p[0] = Asm(p.lineno(1), 'LD %s,%s' % (p[2], p[4])) | python | def p_asm_ld8(p):
""" asm : LD reg8 COMMA reg8_hl
| LD reg8_hl COMMA reg8
| LD reg8 COMMA reg8
| LD SP COMMA HL
| LD SP COMMA reg16i
| LD A COMMA reg8
| LD reg8 COMMA A
| LD reg8_hl COMMA A
| LD A COMMA reg8_hl
| LD A COMMA A
| LD A COMMA I
| LD I COMMA A
| LD A COMMA R
| LD R COMMA A
| LD A COMMA reg8i
| LD reg8i COMMA A
| LD reg8 COMMA reg8i
| LD reg8i COMMA regBCDE
| LD reg8i COMMA reg8i
"""
if p[2] in ('H', 'L') and p[4] in ('IXH', 'IXL', 'IYH', 'IYL'):
p[0] = None
error(p.lineno(0), "Unexpected token '%s'" % p[4])
else:
p[0] = Asm(p.lineno(1), 'LD %s,%s' % (p[2], p[4])) | [
"def",
"p_asm_ld8",
"(",
"p",
")",
":",
"if",
"p",
"[",
"2",
"]",
"in",
"(",
"'H'",
",",
"'L'",
")",
"and",
"p",
"[",
"4",
"]",
"in",
"(",
"'IXH'",
",",
"'IXL'",
",",
"'IYH'",
",",
"'IYL'",
")",
":",
"p",
"[",
"0",
"]",
"=",
"None",
"error",
"(",
"p",
".",
"lineno",
"(",
"0",
")",
",",
"\"Unexpected token '%s'\"",
"%",
"p",
"[",
"4",
"]",
")",
"else",
":",
"p",
"[",
"0",
"]",
"=",
"Asm",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"'LD %s,%s'",
"%",
"(",
"p",
"[",
"2",
"]",
",",
"p",
"[",
"4",
"]",
")",
")"
] | asm : LD reg8 COMMA reg8_hl
| LD reg8_hl COMMA reg8
| LD reg8 COMMA reg8
| LD SP COMMA HL
| LD SP COMMA reg16i
| LD A COMMA reg8
| LD reg8 COMMA A
| LD reg8_hl COMMA A
| LD A COMMA reg8_hl
| LD A COMMA A
| LD A COMMA I
| LD I COMMA A
| LD A COMMA R
| LD R COMMA A
| LD A COMMA reg8i
| LD reg8i COMMA A
| LD reg8 COMMA reg8i
| LD reg8i COMMA regBCDE
| LD reg8i COMMA reg8i | [
"asm",
":",
"LD",
"reg8",
"COMMA",
"reg8_hl",
"|",
"LD",
"reg8_hl",
"COMMA",
"reg8",
"|",
"LD",
"reg8",
"COMMA",
"reg8",
"|",
"LD",
"SP",
"COMMA",
"HL",
"|",
"LD",
"SP",
"COMMA",
"reg16i",
"|",
"LD",
"A",
"COMMA",
"reg8",
"|",
"LD",
"reg8",
"COMMA",
"A",
"|",
"LD",
"reg8_hl",
"COMMA",
"A",
"|",
"LD",
"A",
"COMMA",
"reg8_hl",
"|",
"LD",
"A",
"COMMA",
"A",
"|",
"LD",
"A",
"COMMA",
"I",
"|",
"LD",
"I",
"COMMA",
"A",
"|",
"LD",
"A",
"COMMA",
"R",
"|",
"LD",
"R",
"COMMA",
"A",
"|",
"LD",
"A",
"COMMA",
"reg8i",
"|",
"LD",
"reg8i",
"COMMA",
"A",
"|",
"LD",
"reg8",
"COMMA",
"reg8i",
"|",
"LD",
"reg8i",
"COMMA",
"regBCDE",
"|",
"LD",
"reg8i",
"COMMA",
"reg8i"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L657-L682 |
boriel/zxbasic | asmparse.py | p_LOCAL | def p_LOCAL(p):
""" asm : LOCAL id_list
"""
p[0] = None
for label, line in p[2]:
__DEBUG__("Setting label '%s' as local at line %i" % (label, line))
MEMORY.set_label(label, line, local=True) | python | def p_LOCAL(p):
""" asm : LOCAL id_list
"""
p[0] = None
for label, line in p[2]:
__DEBUG__("Setting label '%s' as local at line %i" % (label, line))
MEMORY.set_label(label, line, local=True) | [
"def",
"p_LOCAL",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"None",
"for",
"label",
",",
"line",
"in",
"p",
"[",
"2",
"]",
":",
"__DEBUG__",
"(",
"\"Setting label '%s' as local at line %i\"",
"%",
"(",
"label",
",",
"line",
")",
")",
"MEMORY",
".",
"set_label",
"(",
"label",
",",
"line",
",",
"local",
"=",
"True",
")"
] | asm : LOCAL id_list | [
"asm",
":",
"LOCAL",
"id_list"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L708-L715 |
boriel/zxbasic | asmparse.py | p_DEFS | def p_DEFS(p): # Define bytes
""" asm : DEFS number_list
"""
if len(p[2]) > 2:
error(p.lineno(1), "too many arguments for DEFS")
if len(p[2]) < 2:
num = Expr.makenode(Container(0, p.lineno(1))) # Defaults to 0
p[2] = p[2] + (num,)
p[0] = Asm(p.lineno(1), 'DEFS', p[2]) | python | def p_DEFS(p): # Define bytes
""" asm : DEFS number_list
"""
if len(p[2]) > 2:
error(p.lineno(1), "too many arguments for DEFS")
if len(p[2]) < 2:
num = Expr.makenode(Container(0, p.lineno(1))) # Defaults to 0
p[2] = p[2] + (num,)
p[0] = Asm(p.lineno(1), 'DEFS', p[2]) | [
"def",
"p_DEFS",
"(",
"p",
")",
":",
"# Define bytes",
"if",
"len",
"(",
"p",
"[",
"2",
"]",
")",
">",
"2",
":",
"error",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"\"too many arguments for DEFS\"",
")",
"if",
"len",
"(",
"p",
"[",
"2",
"]",
")",
"<",
"2",
":",
"num",
"=",
"Expr",
".",
"makenode",
"(",
"Container",
"(",
"0",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")",
")",
"# Defaults to 0",
"p",
"[",
"2",
"]",
"=",
"p",
"[",
"2",
"]",
"+",
"(",
"num",
",",
")",
"p",
"[",
"0",
"]",
"=",
"Asm",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"'DEFS'",
",",
"p",
"[",
"2",
"]",
")"
] | asm : DEFS number_list | [
"asm",
":",
"DEFS",
"number_list"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L737-L747 |
boriel/zxbasic | asmparse.py | p_ind8_I | def p_ind8_I(p):
""" reg8_I : LP IX PLUS expr RP
| LP IX MINUS expr RP
| LP IY PLUS expr RP
| LP IY MINUS expr RP
| LP IX PLUS pexpr RP
| LP IX MINUS pexpr RP
| LP IY PLUS pexpr RP
| LP IY MINUS pexpr RP
"""
expr = p[4]
if p[3] == '-':
expr = Expr.makenode(Container('-', p.lineno(3)), expr)
p[0] = ('(%s+N)' % p[2], expr) | python | def p_ind8_I(p):
""" reg8_I : LP IX PLUS expr RP
| LP IX MINUS expr RP
| LP IY PLUS expr RP
| LP IY MINUS expr RP
| LP IX PLUS pexpr RP
| LP IX MINUS pexpr RP
| LP IY PLUS pexpr RP
| LP IY MINUS pexpr RP
"""
expr = p[4]
if p[3] == '-':
expr = Expr.makenode(Container('-', p.lineno(3)), expr)
p[0] = ('(%s+N)' % p[2], expr) | [
"def",
"p_ind8_I",
"(",
"p",
")",
":",
"expr",
"=",
"p",
"[",
"4",
"]",
"if",
"p",
"[",
"3",
"]",
"==",
"'-'",
":",
"expr",
"=",
"Expr",
".",
"makenode",
"(",
"Container",
"(",
"'-'",
",",
"p",
".",
"lineno",
"(",
"3",
")",
")",
",",
"expr",
")",
"p",
"[",
"0",
"]",
"=",
"(",
"'(%s+N)'",
"%",
"p",
"[",
"2",
"]",
",",
"expr",
")"
] | reg8_I : LP IX PLUS expr RP
| LP IX MINUS expr RP
| LP IY PLUS expr RP
| LP IY MINUS expr RP
| LP IX PLUS pexpr RP
| LP IX MINUS pexpr RP
| LP IY PLUS pexpr RP
| LP IY MINUS pexpr RP | [
"reg8_I",
":",
"LP",
"IX",
"PLUS",
"expr",
"RP",
"|",
"LP",
"IX",
"MINUS",
"expr",
"RP",
"|",
"LP",
"IY",
"PLUS",
"expr",
"RP",
"|",
"LP",
"IY",
"MINUS",
"expr",
"RP",
"|",
"LP",
"IX",
"PLUS",
"pexpr",
"RP",
"|",
"LP",
"IX",
"MINUS",
"pexpr",
"RP",
"|",
"LP",
"IY",
"PLUS",
"pexpr",
"RP",
"|",
"LP",
"IY",
"MINUS",
"pexpr",
"RP"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L790-L804 |
boriel/zxbasic | asmparse.py | p_namespace | def p_namespace(p):
""" asm : NAMESPACE ID
"""
global NAMESPACE
NAMESPACE = normalize_namespace(p[2])
__DEBUG__('Setting namespace to ' + (NAMESPACE.rstrip(DOT) or DOT), level=1) | python | def p_namespace(p):
""" asm : NAMESPACE ID
"""
global NAMESPACE
NAMESPACE = normalize_namespace(p[2])
__DEBUG__('Setting namespace to ' + (NAMESPACE.rstrip(DOT) or DOT), level=1) | [
"def",
"p_namespace",
"(",
"p",
")",
":",
"global",
"NAMESPACE",
"NAMESPACE",
"=",
"normalize_namespace",
"(",
"p",
"[",
"2",
"]",
")",
"__DEBUG__",
"(",
"'Setting namespace to '",
"+",
"(",
"NAMESPACE",
".",
"rstrip",
"(",
"DOT",
")",
"or",
"DOT",
")",
",",
"level",
"=",
"1",
")"
] | asm : NAMESPACE ID | [
"asm",
":",
"NAMESPACE",
"ID"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L826-L832 |
boriel/zxbasic | asmparse.py | p_align | def p_align(p):
""" asm : ALIGN expr
| ALIGN pexpr
"""
align = p[2].eval()
if align < 2:
error(p.lineno(1), "ALIGN value must be greater than 1")
return
MEMORY.set_org(MEMORY.org + (align - MEMORY.org % align) % align, p.lineno(1)) | python | def p_align(p):
""" asm : ALIGN expr
| ALIGN pexpr
"""
align = p[2].eval()
if align < 2:
error(p.lineno(1), "ALIGN value must be greater than 1")
return
MEMORY.set_org(MEMORY.org + (align - MEMORY.org % align) % align, p.lineno(1)) | [
"def",
"p_align",
"(",
"p",
")",
":",
"align",
"=",
"p",
"[",
"2",
"]",
".",
"eval",
"(",
")",
"if",
"align",
"<",
"2",
":",
"error",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"\"ALIGN value must be greater than 1\"",
")",
"return",
"MEMORY",
".",
"set_org",
"(",
"MEMORY",
".",
"org",
"+",
"(",
"align",
"-",
"MEMORY",
".",
"org",
"%",
"align",
")",
"%",
"align",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")"
] | asm : ALIGN expr
| ALIGN pexpr | [
"asm",
":",
"ALIGN",
"expr",
"|",
"ALIGN",
"pexpr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L835-L844 |
boriel/zxbasic | asmparse.py | p_incbin | def p_incbin(p):
""" asm : INCBIN STRING
"""
try:
fname = zxbpp.search_filename(p[2], p.lineno(2), local_first=True)
if not fname:
p[0] = None
return
with api.utils.open_file(fname, 'rb') as f:
filecontent = f.read()
except IOError:
error(p.lineno(2), "cannot read file '%s'" % p[2])
p[0] = None
return
p[0] = Asm(p.lineno(1), 'DEFB', filecontent) | python | def p_incbin(p):
""" asm : INCBIN STRING
"""
try:
fname = zxbpp.search_filename(p[2], p.lineno(2), local_first=True)
if not fname:
p[0] = None
return
with api.utils.open_file(fname, 'rb') as f:
filecontent = f.read()
except IOError:
error(p.lineno(2), "cannot read file '%s'" % p[2])
p[0] = None
return
p[0] = Asm(p.lineno(1), 'DEFB', filecontent) | [
"def",
"p_incbin",
"(",
"p",
")",
":",
"try",
":",
"fname",
"=",
"zxbpp",
".",
"search_filename",
"(",
"p",
"[",
"2",
"]",
",",
"p",
".",
"lineno",
"(",
"2",
")",
",",
"local_first",
"=",
"True",
")",
"if",
"not",
"fname",
":",
"p",
"[",
"0",
"]",
"=",
"None",
"return",
"with",
"api",
".",
"utils",
".",
"open_file",
"(",
"fname",
",",
"'rb'",
")",
"as",
"f",
":",
"filecontent",
"=",
"f",
".",
"read",
"(",
")",
"except",
"IOError",
":",
"error",
"(",
"p",
".",
"lineno",
"(",
"2",
")",
",",
"\"cannot read file '%s'\"",
"%",
"p",
"[",
"2",
"]",
")",
"p",
"[",
"0",
"]",
"=",
"None",
"return",
"p",
"[",
"0",
"]",
"=",
"Asm",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"'DEFB'",
",",
"filecontent",
")"
] | asm : INCBIN STRING | [
"asm",
":",
"INCBIN",
"STRING"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L847-L862 |
boriel/zxbasic | asmparse.py | p_LD_reg_val | def p_LD_reg_val(p):
""" asm : LD reg8 COMMA expr
| LD reg8 COMMA pexpr
| LD reg16 COMMA expr
| LD reg8_hl COMMA expr
| LD A COMMA expr
| LD SP COMMA expr
| LD reg8i COMMA expr
"""
s = 'LD %s,N' % p[2]
if p[2] in REGS16:
s += 'N'
p[0] = Asm(p.lineno(1), s, p[4]) | python | def p_LD_reg_val(p):
""" asm : LD reg8 COMMA expr
| LD reg8 COMMA pexpr
| LD reg16 COMMA expr
| LD reg8_hl COMMA expr
| LD A COMMA expr
| LD SP COMMA expr
| LD reg8i COMMA expr
"""
s = 'LD %s,N' % p[2]
if p[2] in REGS16:
s += 'N'
p[0] = Asm(p.lineno(1), s, p[4]) | [
"def",
"p_LD_reg_val",
"(",
"p",
")",
":",
"s",
"=",
"'LD %s,N'",
"%",
"p",
"[",
"2",
"]",
"if",
"p",
"[",
"2",
"]",
"in",
"REGS16",
":",
"s",
"+=",
"'N'",
"p",
"[",
"0",
"]",
"=",
"Asm",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"s",
",",
"p",
"[",
"4",
"]",
")"
] | asm : LD reg8 COMMA expr
| LD reg8 COMMA pexpr
| LD reg16 COMMA expr
| LD reg8_hl COMMA expr
| LD A COMMA expr
| LD SP COMMA expr
| LD reg8i COMMA expr | [
"asm",
":",
"LD",
"reg8",
"COMMA",
"expr",
"|",
"LD",
"reg8",
"COMMA",
"pexpr",
"|",
"LD",
"reg16",
"COMMA",
"expr",
"|",
"LD",
"reg8_hl",
"COMMA",
"expr",
"|",
"LD",
"A",
"COMMA",
"expr",
"|",
"LD",
"SP",
"COMMA",
"expr",
"|",
"LD",
"reg8i",
"COMMA",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L886-L899 |
boriel/zxbasic | asmparse.py | p_JP_hl | def p_JP_hl(p):
""" asm : JP reg8_hl
| JP LP reg16i RP
"""
s = 'JP '
if p[2] == '(HL)':
s += p[2]
else:
s += '(%s)' % p[3]
p[0] = Asm(p.lineno(1), s) | python | def p_JP_hl(p):
""" asm : JP reg8_hl
| JP LP reg16i RP
"""
s = 'JP '
if p[2] == '(HL)':
s += p[2]
else:
s += '(%s)' % p[3]
p[0] = Asm(p.lineno(1), s) | [
"def",
"p_JP_hl",
"(",
"p",
")",
":",
"s",
"=",
"'JP '",
"if",
"p",
"[",
"2",
"]",
"==",
"'(HL)'",
":",
"s",
"+=",
"p",
"[",
"2",
"]",
"else",
":",
"s",
"+=",
"'(%s)'",
"%",
"p",
"[",
"3",
"]",
"p",
"[",
"0",
"]",
"=",
"Asm",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"s",
")"
] | asm : JP reg8_hl
| JP LP reg16i RP | [
"asm",
":",
"JP",
"reg8_hl",
"|",
"JP",
"LP",
"reg16i",
"RP"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L908-L918 |
boriel/zxbasic | asmparse.py | p_BIT | def p_BIT(p):
""" asm : bitop expr COMMA A
| bitop pexpr COMMA A
| bitop expr COMMA reg8
| bitop pexpr COMMA reg8
| bitop expr COMMA reg8_hl
| bitop pexpr COMMA reg8_hl
"""
bit = p[2].eval()
if bit < 0 or bit > 7:
error(p.lineno(3), 'Invalid bit position %i. Must be in [0..7]' % bit)
p[0] = None
return
p[0] = Asm(p.lineno(3), '%s %i,%s' % (p[1], bit, p[4])) | python | def p_BIT(p):
""" asm : bitop expr COMMA A
| bitop pexpr COMMA A
| bitop expr COMMA reg8
| bitop pexpr COMMA reg8
| bitop expr COMMA reg8_hl
| bitop pexpr COMMA reg8_hl
"""
bit = p[2].eval()
if bit < 0 or bit > 7:
error(p.lineno(3), 'Invalid bit position %i. Must be in [0..7]' % bit)
p[0] = None
return
p[0] = Asm(p.lineno(3), '%s %i,%s' % (p[1], bit, p[4])) | [
"def",
"p_BIT",
"(",
"p",
")",
":",
"bit",
"=",
"p",
"[",
"2",
"]",
".",
"eval",
"(",
")",
"if",
"bit",
"<",
"0",
"or",
"bit",
">",
"7",
":",
"error",
"(",
"p",
".",
"lineno",
"(",
"3",
")",
",",
"'Invalid bit position %i. Must be in [0..7]'",
"%",
"bit",
")",
"p",
"[",
"0",
"]",
"=",
"None",
"return",
"p",
"[",
"0",
"]",
"=",
"Asm",
"(",
"p",
".",
"lineno",
"(",
"3",
")",
",",
"'%s %i,%s'",
"%",
"(",
"p",
"[",
"1",
"]",
",",
"bit",
",",
"p",
"[",
"4",
"]",
")",
")"
] | asm : bitop expr COMMA A
| bitop pexpr COMMA A
| bitop expr COMMA reg8
| bitop pexpr COMMA reg8
| bitop expr COMMA reg8_hl
| bitop pexpr COMMA reg8_hl | [
"asm",
":",
"bitop",
"expr",
"COMMA",
"A",
"|",
"bitop",
"pexpr",
"COMMA",
"A",
"|",
"bitop",
"expr",
"COMMA",
"reg8",
"|",
"bitop",
"pexpr",
"COMMA",
"reg8",
"|",
"bitop",
"expr",
"COMMA",
"reg8_hl",
"|",
"bitop",
"pexpr",
"COMMA",
"reg8_hl"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1045-L1059 |
boriel/zxbasic | asmparse.py | p_BIT_ix | def p_BIT_ix(p):
""" asm : bitop expr COMMA reg8_I
| bitop pexpr COMMA reg8_I
"""
bit = p[2].eval()
if bit < 0 or bit > 7:
error(p.lineno(3), 'Invalid bit position %i. Must be in [0..7]' % bit)
p[0] = None
return
p[0] = Asm(p.lineno(3), '%s %i,%s' % (p[1], bit, p[4][0]), p[4][1]) | python | def p_BIT_ix(p):
""" asm : bitop expr COMMA reg8_I
| bitop pexpr COMMA reg8_I
"""
bit = p[2].eval()
if bit < 0 or bit > 7:
error(p.lineno(3), 'Invalid bit position %i. Must be in [0..7]' % bit)
p[0] = None
return
p[0] = Asm(p.lineno(3), '%s %i,%s' % (p[1], bit, p[4][0]), p[4][1]) | [
"def",
"p_BIT_ix",
"(",
"p",
")",
":",
"bit",
"=",
"p",
"[",
"2",
"]",
".",
"eval",
"(",
")",
"if",
"bit",
"<",
"0",
"or",
"bit",
">",
"7",
":",
"error",
"(",
"p",
".",
"lineno",
"(",
"3",
")",
",",
"'Invalid bit position %i. Must be in [0..7]'",
"%",
"bit",
")",
"p",
"[",
"0",
"]",
"=",
"None",
"return",
"p",
"[",
"0",
"]",
"=",
"Asm",
"(",
"p",
".",
"lineno",
"(",
"3",
")",
",",
"'%s %i,%s'",
"%",
"(",
"p",
"[",
"1",
"]",
",",
"bit",
",",
"p",
"[",
"4",
"]",
"[",
"0",
"]",
")",
",",
"p",
"[",
"4",
"]",
"[",
"1",
"]",
")"
] | asm : bitop expr COMMA reg8_I
| bitop pexpr COMMA reg8_I | [
"asm",
":",
"bitop",
"expr",
"COMMA",
"reg8_I",
"|",
"bitop",
"pexpr",
"COMMA",
"reg8_I"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/asmparse.py#L1062-L1072 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.