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 listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
boriel/zxbasic | arch/zx48k/optimizer.py | initialize_memory | def initialize_memory(basic_block):
""" Initializes global memory array with the given one
"""
global MEMORY
MEMORY = basic_block.mem
get_labels(MEMORY, basic_block)
basic_block.mem = MEMORY | python | def initialize_memory(basic_block):
""" Initializes global memory array with the given one
"""
global MEMORY
MEMORY = basic_block.mem
get_labels(MEMORY, basic_block)
basic_block.mem = MEMORY | [
"def",
"initialize_memory",
"(",
"basic_block",
")",
":",
"global",
"MEMORY",
"MEMORY",
"=",
"basic_block",
".",
"mem",
"get_labels",
"(",
"MEMORY",
",",
"basic_block",
")",
"basic_block",
".",
"mem",
"=",
"MEMORY"
] | Initializes global memory array with the given one | [
"Initializes",
"global",
"memory",
"array",
"with",
"the",
"given",
"one"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L2182-L2189 |
boriel/zxbasic | arch/zx48k/optimizer.py | cleanupmem | def cleanupmem(initial_memory):
""" Cleans up initial memory. Each label must be
ALONE. Each instruction must have an space, etc...
"""
i = 0
while i < len(initial_memory):
tmp = initial_memory[i]
match = RE_LABEL.match(tmp)
if not match:
i += 1
contin... | python | def cleanupmem(initial_memory):
""" Cleans up initial memory. Each label must be
ALONE. Each instruction must have an space, etc...
"""
i = 0
while i < len(initial_memory):
tmp = initial_memory[i]
match = RE_LABEL.match(tmp)
if not match:
i += 1
contin... | [
"def",
"cleanupmem",
"(",
"initial_memory",
")",
":",
"i",
"=",
"0",
"while",
"i",
"<",
"len",
"(",
"initial_memory",
")",
":",
"tmp",
"=",
"initial_memory",
"[",
"i",
"]",
"match",
"=",
"RE_LABEL",
".",
"match",
"(",
"tmp",
")",
"if",
"not",
"match"... | Cleans up initial memory. Each label must be
ALONE. Each instruction must have an space, etc... | [
"Cleans",
"up",
"initial",
"memory",
".",
"Each",
"label",
"must",
"be",
"ALONE",
".",
"Each",
"instruction",
"must",
"have",
"an",
"space",
"etc",
"..."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L2223-L2241 |
boriel/zxbasic | arch/zx48k/optimizer.py | cleanup_local_labels | def cleanup_local_labels(block):
""" Traverses memory, to make any local label a unique
global one. At this point there's only a single code
block
"""
global PROC_COUNTER
stack = [[]]
hashes = [{}]
stackprc = [PROC_COUNTER]
used = [{}] # List of hashes of unresolved labels per scop... | python | def cleanup_local_labels(block):
""" Traverses memory, to make any local label a unique
global one. At this point there's only a single code
block
"""
global PROC_COUNTER
stack = [[]]
hashes = [{}]
stackprc = [PROC_COUNTER]
used = [{}] # List of hashes of unresolved labels per scop... | [
"def",
"cleanup_local_labels",
"(",
"block",
")",
":",
"global",
"PROC_COUNTER",
"stack",
"=",
"[",
"[",
"]",
"]",
"hashes",
"=",
"[",
"{",
"}",
"]",
"stackprc",
"=",
"[",
"PROC_COUNTER",
"]",
"used",
"=",
"[",
"{",
"}",
"]",
"# List of hashes of unresol... | Traverses memory, to make any local label a unique
global one. At this point there's only a single code
block | [
"Traverses",
"memory",
"to",
"make",
"any",
"local",
"label",
"a",
"unique",
"global",
"one",
".",
"At",
"this",
"point",
"there",
"s",
"only",
"a",
"single",
"code",
"block"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L2261-L2342 |
boriel/zxbasic | arch/zx48k/optimizer.py | optimize | def optimize(initial_memory):
""" This will remove useless instructions
"""
global BLOCKS
global PROC_COUNTER
LABELS.clear()
JUMP_LABELS.clear()
del MEMORY[:]
PROC_COUNTER = 0
cleanupmem(initial_memory)
if OPTIONS.optimization.value <= 2:
return '\n'.join(x for x in ini... | python | def optimize(initial_memory):
""" This will remove useless instructions
"""
global BLOCKS
global PROC_COUNTER
LABELS.clear()
JUMP_LABELS.clear()
del MEMORY[:]
PROC_COUNTER = 0
cleanupmem(initial_memory)
if OPTIONS.optimization.value <= 2:
return '\n'.join(x for x in ini... | [
"def",
"optimize",
"(",
"initial_memory",
")",
":",
"global",
"BLOCKS",
"global",
"PROC_COUNTER",
"LABELS",
".",
"clear",
"(",
")",
"JUMP_LABELS",
".",
"clear",
"(",
")",
"del",
"MEMORY",
"[",
":",
"]",
"PROC_COUNTER",
"=",
"0",
"cleanupmem",
"(",
"initial... | This will remove useless instructions | [
"This",
"will",
"remove",
"useless",
"instructions"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L2345-L2388 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.reset | def reset(self):
""" Initial state
"""
self.regs = {}
self.stack = []
self.mem = defaultdict(new_tmp_val) # Dict of label -> value in memory
for i in 'abcdefhl':
self.regs[i] = new_tmp_val() # Initial unknown state
self.regs["%s'" % i] = new_tmp... | python | def reset(self):
""" Initial state
"""
self.regs = {}
self.stack = []
self.mem = defaultdict(new_tmp_val) # Dict of label -> value in memory
for i in 'abcdefhl':
self.regs[i] = new_tmp_val() # Initial unknown state
self.regs["%s'" % i] = new_tmp... | [
"def",
"reset",
"(",
"self",
")",
":",
"self",
".",
"regs",
"=",
"{",
"}",
"self",
".",
"stack",
"=",
"[",
"]",
"self",
".",
"mem",
"=",
"defaultdict",
"(",
"new_tmp_val",
")",
"# Dict of label -> value in memory",
"for",
"i",
"in",
"'abcdefhl'",
":",
... | Initial state | [
"Initial",
"state"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L373-L410 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.reset_flags | def reset_flags(self):
""" Resets flags to an "unknown state"
"""
self.C = None
self.Z = None
self.P = None
self.S = None | python | def reset_flags(self):
""" Resets flags to an "unknown state"
"""
self.C = None
self.Z = None
self.P = None
self.S = None | [
"def",
"reset_flags",
"(",
"self",
")",
":",
"self",
".",
"C",
"=",
"None",
"self",
".",
"Z",
"=",
"None",
"self",
".",
"P",
"=",
"None",
"self",
".",
"S",
"=",
"None"
] | Resets flags to an "unknown state" | [
"Resets",
"flags",
"to",
"an",
"unknown",
"state"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L412-L418 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.get | def get(self, r):
""" Returns precomputed value of the given expression
"""
if r is None:
return None
if r.lower() == '(sp)' and self.stack:
return self.stack[-1]
if r[:1] == '(':
return self.mem[r[1:-1]]
r = r.lower()
if is_... | python | def get(self, r):
""" Returns precomputed value of the given expression
"""
if r is None:
return None
if r.lower() == '(sp)' and self.stack:
return self.stack[-1]
if r[:1] == '(':
return self.mem[r[1:-1]]
r = r.lower()
if is_... | [
"def",
"get",
"(",
"self",
",",
"r",
")",
":",
"if",
"r",
"is",
"None",
":",
"return",
"None",
"if",
"r",
".",
"lower",
"(",
")",
"==",
"'(sp)'",
"and",
"self",
".",
"stack",
":",
"return",
"self",
".",
"stack",
"[",
"-",
"1",
"]",
"if",
"r",... | Returns precomputed value of the given expression | [
"Returns",
"precomputed",
"value",
"of",
"the",
"given",
"expression"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L503-L522 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.getv | def getv(self, r):
""" Like the above, but returns the <int> value.
"""
v = self.get(r)
if not is_unknown(v):
try:
v = int(v)
except ValueError:
v = None
else:
v = None
return v | python | def getv(self, r):
""" Like the above, but returns the <int> value.
"""
v = self.get(r)
if not is_unknown(v):
try:
v = int(v)
except ValueError:
v = None
else:
v = None
return v | [
"def",
"getv",
"(",
"self",
",",
"r",
")",
":",
"v",
"=",
"self",
".",
"get",
"(",
"r",
")",
"if",
"not",
"is_unknown",
"(",
"v",
")",
":",
"try",
":",
"v",
"=",
"int",
"(",
"v",
")",
"except",
"ValueError",
":",
"v",
"=",
"None",
"else",
"... | Like the above, but returns the <int> value. | [
"Like",
"the",
"above",
"but",
"returns",
"the",
"<int",
">",
"value",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L524-L535 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.eq | def eq(self, r1, r2):
""" True if values of r1 and r2 registers are equal
"""
if not is_register(r1) or not is_register(r2):
return False
if self.regs[r1] is None or self.regs[r2] is None: # HINT: This's been never USED??
return False
return self.regs[r... | python | def eq(self, r1, r2):
""" True if values of r1 and r2 registers are equal
"""
if not is_register(r1) or not is_register(r2):
return False
if self.regs[r1] is None or self.regs[r2] is None: # HINT: This's been never USED??
return False
return self.regs[r... | [
"def",
"eq",
"(",
"self",
",",
"r1",
",",
"r2",
")",
":",
"if",
"not",
"is_register",
"(",
"r1",
")",
"or",
"not",
"is_register",
"(",
"r2",
")",
":",
"return",
"False",
"if",
"self",
".",
"regs",
"[",
"r1",
"]",
"is",
"None",
"or",
"self",
"."... | True if values of r1 and r2 registers are equal | [
"True",
"if",
"values",
"of",
"r1",
"and",
"r2",
"registers",
"are",
"equal"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L537-L546 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.inc | def inc(self, r):
""" Does inc on the register and precomputes flags
"""
self.set_flag(None)
if not is_register(r):
if r[0] == '(': # a memory position, basically: inc(hl)
r_ = r[1:-1].strip()
v_ = self.getv(self.mem.get(r_, None))
... | python | def inc(self, r):
""" Does inc on the register and precomputes flags
"""
self.set_flag(None)
if not is_register(r):
if r[0] == '(': # a memory position, basically: inc(hl)
r_ = r[1:-1].strip()
v_ = self.getv(self.mem.get(r_, None))
... | [
"def",
"inc",
"(",
"self",
",",
"r",
")",
":",
"self",
".",
"set_flag",
"(",
"None",
")",
"if",
"not",
"is_register",
"(",
"r",
")",
":",
"if",
"r",
"[",
"0",
"]",
"==",
"'('",
":",
"# a memory position, basically: inc(hl)",
"r_",
"=",
"r",
"[",
"1... | Does inc on the register and precomputes flags | [
"Does",
"inc",
"on",
"the",
"register",
"and",
"precomputes",
"flags"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L561-L581 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.rrc | def rrc(self, r):
""" Does a ROTATION to the RIGHT |>>
"""
if not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
v_ = self.getv(self.regs[r]) & 0xFF
self.regs[r] = str((v_ >> 1) | ((v_ & 1) << 7)) | python | def rrc(self, r):
""" Does a ROTATION to the RIGHT |>>
"""
if not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
v_ = self.getv(self.regs[r]) & 0xFF
self.regs[r] = str((v_ >> 1) | ((v_ & 1) << 7)) | [
"def",
"rrc",
"(",
"self",
",",
"r",
")",
":",
"if",
"not",
"is_number",
"(",
"self",
".",
"regs",
"[",
"r",
"]",
")",
":",
"self",
".",
"set",
"(",
"r",
",",
"None",
")",
"self",
".",
"set_flag",
"(",
"None",
")",
"return",
"v_",
"=",
"self"... | Does a ROTATION to the RIGHT |>> | [
"Does",
"a",
"ROTATION",
"to",
"the",
"RIGHT",
"|",
">>"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L605-L614 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.rr | def rr(self, r):
""" Like the above, bus uses carry
"""
if self.C is None or not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
self.rrc(r)
tmp = self.C
v_ = self.getv(self.regs[r])
self.C = v_ >> 7
... | python | def rr(self, r):
""" Like the above, bus uses carry
"""
if self.C is None or not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
self.rrc(r)
tmp = self.C
v_ = self.getv(self.regs[r])
self.C = v_ >> 7
... | [
"def",
"rr",
"(",
"self",
",",
"r",
")",
":",
"if",
"self",
".",
"C",
"is",
"None",
"or",
"not",
"is_number",
"(",
"self",
".",
"regs",
"[",
"r",
"]",
")",
":",
"self",
".",
"set",
"(",
"r",
",",
"None",
")",
"self",
".",
"set_flag",
"(",
"... | Like the above, bus uses carry | [
"Like",
"the",
"above",
"bus",
"uses",
"carry"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L616-L628 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.rlc | def rlc(self, r):
""" Does a ROTATION to the LEFT <<|
"""
if not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
v_ = self.getv(self.regs[r]) & 0xFF
self.set(r, ((v_ << 1) & 0xFF) | (v_ >> 7)) | python | def rlc(self, r):
""" Does a ROTATION to the LEFT <<|
"""
if not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
v_ = self.getv(self.regs[r]) & 0xFF
self.set(r, ((v_ << 1) & 0xFF) | (v_ >> 7)) | [
"def",
"rlc",
"(",
"self",
",",
"r",
")",
":",
"if",
"not",
"is_number",
"(",
"self",
".",
"regs",
"[",
"r",
"]",
")",
":",
"self",
".",
"set",
"(",
"r",
",",
"None",
")",
"self",
".",
"set_flag",
"(",
"None",
")",
"return",
"v_",
"=",
"self"... | Does a ROTATION to the LEFT <<| | [
"Does",
"a",
"ROTATION",
"to",
"the",
"LEFT",
"<<|"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L630-L639 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.rl | def rl(self, r):
""" Like the above, bus uses carry
"""
if self.C is None or not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
self.rlc(r)
tmp = self.C
v_ = self.getv(self.regs[r])
self.C = v_ & 1
... | python | def rl(self, r):
""" Like the above, bus uses carry
"""
if self.C is None or not is_number(self.regs[r]):
self.set(r, None)
self.set_flag(None)
return
self.rlc(r)
tmp = self.C
v_ = self.getv(self.regs[r])
self.C = v_ & 1
... | [
"def",
"rl",
"(",
"self",
",",
"r",
")",
":",
"if",
"self",
".",
"C",
"is",
"None",
"or",
"not",
"is_number",
"(",
"self",
".",
"regs",
"[",
"r",
"]",
")",
":",
"self",
".",
"set",
"(",
"r",
",",
"None",
")",
"self",
".",
"set_flag",
"(",
"... | Like the above, bus uses carry | [
"Like",
"the",
"above",
"bus",
"uses",
"carry"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L641-L653 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers._is | def _is(self, r, val):
""" True if value of r is val.
"""
if not is_register(r) or val is None:
return False
r = r.lower()
if is_register(val):
return self.eq(r, val)
if is_number(val):
val = str(valnum(val))
else:
... | python | def _is(self, r, val):
""" True if value of r is val.
"""
if not is_register(r) or val is None:
return False
r = r.lower()
if is_register(val):
return self.eq(r, val)
if is_number(val):
val = str(valnum(val))
else:
... | [
"def",
"_is",
"(",
"self",
",",
"r",
",",
"val",
")",
":",
"if",
"not",
"is_register",
"(",
"r",
")",
"or",
"val",
"is",
"None",
":",
"return",
"False",
"r",
"=",
"r",
".",
"lower",
"(",
")",
"if",
"is_register",
"(",
"val",
")",
":",
"return",... | True if value of r is val. | [
"True",
"if",
"value",
"of",
"r",
"is",
"val",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L655-L673 |
boriel/zxbasic | arch/zx48k/optimizer.py | Registers.op | def op(self, i, o):
""" Tries to update the registers values with the given
instruction.
"""
for ii in range(len(o)):
if is_register(o[ii]):
o[ii] = o[ii].lower()
if i == 'ld':
self.set(o[0], o[1])
return
if i == 'push... | python | def op(self, i, o):
""" Tries to update the registers values with the given
instruction.
"""
for ii in range(len(o)):
if is_register(o[ii]):
o[ii] = o[ii].lower()
if i == 'ld':
self.set(o[0], o[1])
return
if i == 'push... | [
"def",
"op",
"(",
"self",
",",
"i",
",",
"o",
")",
":",
"for",
"ii",
"in",
"range",
"(",
"len",
"(",
"o",
")",
")",
":",
"if",
"is_register",
"(",
"o",
"[",
"ii",
"]",
")",
":",
"o",
"[",
"ii",
"]",
"=",
"o",
"[",
"ii",
"]",
".",
"lower... | Tries to update the registers values with the given
instruction. | [
"Tries",
"to",
"update",
"the",
"registers",
"values",
"with",
"the",
"given",
"instruction",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L675-L887 |
boriel/zxbasic | arch/zx48k/optimizer.py | MemCell.opers | def opers(self):
""" Returns a list of operators this mnemonic uses
"""
i = [x for x in self.asm.strip(' \t\n').split(' ') if x != '']
if len(i) == 1:
return []
i = ''.join(i[1:]).split(',')
if self.condition_flag is not None:
i = i[1:]
e... | python | def opers(self):
""" Returns a list of operators this mnemonic uses
"""
i = [x for x in self.asm.strip(' \t\n').split(' ') if x != '']
if len(i) == 1:
return []
i = ''.join(i[1:]).split(',')
if self.condition_flag is not None:
i = i[1:]
e... | [
"def",
"opers",
"(",
"self",
")",
":",
"i",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"asm",
".",
"strip",
"(",
"' \\t\\n'",
")",
".",
"split",
"(",
"' '",
")",
"if",
"x",
"!=",
"''",
"]",
"if",
"len",
"(",
"i",
")",
"==",
"1",
":",
"... | Returns a list of operators this mnemonic uses | [
"Returns",
"a",
"list",
"of",
"operators",
"this",
"mnemonic",
"uses"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L948-L963 |
boriel/zxbasic | arch/zx48k/optimizer.py | MemCell.destroys | def destroys(self):
""" Returns which single registers (including f, flag)
this instruction changes.
Registers are: a, b, c, d, e, i, h, l, ixh, ixl, iyh, iyl, r
LD a, X => Destroys a
LD a, a => Destroys nothing
INC a => Destroys a, f
POP af => Destroys a, f, s... | python | def destroys(self):
""" Returns which single registers (including f, flag)
this instruction changes.
Registers are: a, b, c, d, e, i, h, l, ixh, ixl, iyh, iyl, r
LD a, X => Destroys a
LD a, a => Destroys nothing
INC a => Destroys a, f
POP af => Destroys a, f, s... | [
"def",
"destroys",
"(",
"self",
")",
":",
"if",
"self",
".",
"asm",
"in",
"arch",
".",
"zx48k",
".",
"backend",
".",
"ASMS",
":",
"return",
"ALL_REGS",
"res",
"=",
"set",
"(",
"[",
"]",
")",
"i",
"=",
"self",
".",
"inst",
"o",
"=",
"self",
".",... | Returns which single registers (including f, flag)
this instruction changes.
Registers are: a, b, c, d, e, i, h, l, ixh, ixl, iyh, iyl, r
LD a, X => Destroys a
LD a, a => Destroys nothing
INC a => Destroys a, f
POP af => Destroys a, f, sp
PUSH af => Destroys sp... | [
"Returns",
"which",
"single",
"registers",
"(",
"including",
"f",
"flag",
")",
"this",
"instruction",
"changes",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L966-L1027 |
boriel/zxbasic | arch/zx48k/optimizer.py | MemCell.requires | def requires(self):
""" Returns the registers, operands, etc. required by an instruction.
"""
if self.asm in arch.zx48k.backend.ASMS:
return ALL_REGS
if self.inst == '#pragma':
tmp = self.__instr.split(' ')[1:]
if tmp[0] != 'opt':
retu... | python | def requires(self):
""" Returns the registers, operands, etc. required by an instruction.
"""
if self.asm in arch.zx48k.backend.ASMS:
return ALL_REGS
if self.inst == '#pragma':
tmp = self.__instr.split(' ')[1:]
if tmp[0] != 'opt':
retu... | [
"def",
"requires",
"(",
"self",
")",
":",
"if",
"self",
".",
"asm",
"in",
"arch",
".",
"zx48k",
".",
"backend",
".",
"ASMS",
":",
"return",
"ALL_REGS",
"if",
"self",
".",
"inst",
"==",
"'#pragma'",
":",
"tmp",
"=",
"self",
".",
"__instr",
".",
"spl... | Returns the registers, operands, etc. required by an instruction. | [
"Returns",
"the",
"registers",
"operands",
"etc",
".",
"required",
"by",
"an",
"instruction",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1030-L1168 |
boriel/zxbasic | arch/zx48k/optimizer.py | MemCell.affects | def affects(self, reglist):
""" Returns if this instruction affects any of the registers
in reglist.
"""
if isinstance(reglist, str):
reglist = [reglist]
reglist = single_registers(reglist)
return len([x for x in self.destroys if x in reglist]) > 0 | python | def affects(self, reglist):
""" Returns if this instruction affects any of the registers
in reglist.
"""
if isinstance(reglist, str):
reglist = [reglist]
reglist = single_registers(reglist)
return len([x for x in self.destroys if x in reglist]) > 0 | [
"def",
"affects",
"(",
"self",
",",
"reglist",
")",
":",
"if",
"isinstance",
"(",
"reglist",
",",
"str",
")",
":",
"reglist",
"=",
"[",
"reglist",
"]",
"reglist",
"=",
"single_registers",
"(",
"reglist",
")",
"return",
"len",
"(",
"[",
"x",
"for",
"x... | Returns if this instruction affects any of the registers
in reglist. | [
"Returns",
"if",
"this",
"instruction",
"affects",
"any",
"of",
"the",
"registers",
"in",
"reglist",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1170-L1179 |
boriel/zxbasic | arch/zx48k/optimizer.py | MemCell.needs | def needs(self, reglist):
""" Returns if this instruction need any of the registers
in reglist.
"""
if isinstance(reglist, str):
reglist = [reglist]
reglist = single_registers(reglist)
return len([x for x in self.requires if x in reglist]) > 0 | python | def needs(self, reglist):
""" Returns if this instruction need any of the registers
in reglist.
"""
if isinstance(reglist, str):
reglist = [reglist]
reglist = single_registers(reglist)
return len([x for x in self.requires if x in reglist]) > 0 | [
"def",
"needs",
"(",
"self",
",",
"reglist",
")",
":",
"if",
"isinstance",
"(",
"reglist",
",",
"str",
")",
":",
"reglist",
"=",
"[",
"reglist",
"]",
"reglist",
"=",
"single_registers",
"(",
"reglist",
")",
"return",
"len",
"(",
"[",
"x",
"for",
"x",... | Returns if this instruction need any of the registers
in reglist. | [
"Returns",
"if",
"this",
"instruction",
"need",
"any",
"of",
"the",
"registers",
"in",
"reglist",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1181-L1190 |
boriel/zxbasic | arch/zx48k/optimizer.py | MemCell.used_labels | def used_labels(self):
""" Returns a list of required labels for this instruction
"""
result = []
tmp = self.asm.strip(' \n\r\t')
if not len(tmp) or tmp[0] in ('#', ';'):
return result
try:
tmpLexer = asmlex.lex.lex(object=asmlex.Lexer(), lextab=... | python | def used_labels(self):
""" Returns a list of required labels for this instruction
"""
result = []
tmp = self.asm.strip(' \n\r\t')
if not len(tmp) or tmp[0] in ('#', ';'):
return result
try:
tmpLexer = asmlex.lex.lex(object=asmlex.Lexer(), lextab=... | [
"def",
"used_labels",
"(",
"self",
")",
":",
"result",
"=",
"[",
"]",
"tmp",
"=",
"self",
".",
"asm",
".",
"strip",
"(",
"' \\n\\r\\t'",
")",
"if",
"not",
"len",
"(",
"tmp",
")",
"or",
"tmp",
"[",
"0",
"]",
"in",
"(",
"'#'",
",",
"';'",
")",
... | Returns a list of required labels for this instruction | [
"Returns",
"a",
"list",
"of",
"required",
"labels",
"for",
"this",
"instruction"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1193-L1216 |
boriel/zxbasic | arch/zx48k/optimizer.py | MemCell.replace_label | def replace_label(self, oldLabel, newLabel):
""" Replaces old label with a new one
"""
if oldLabel == newLabel:
return
tmp = re.compile(r'\b' + oldLabel + r'\b')
last = 0
l = len(newLabel)
while True:
match = tmp.search(self.asm[last:])
... | python | def replace_label(self, oldLabel, newLabel):
""" Replaces old label with a new one
"""
if oldLabel == newLabel:
return
tmp = re.compile(r'\b' + oldLabel + r'\b')
last = 0
l = len(newLabel)
while True:
match = tmp.search(self.asm[last:])
... | [
"def",
"replace_label",
"(",
"self",
",",
"oldLabel",
",",
"newLabel",
")",
":",
"if",
"oldLabel",
"==",
"newLabel",
":",
"return",
"tmp",
"=",
"re",
".",
"compile",
"(",
"r'\\b'",
"+",
"oldLabel",
"+",
"r'\\b'",
")",
"last",
"=",
"0",
"l",
"=",
"len... | Replaces old label with a new one | [
"Replaces",
"old",
"label",
"with",
"a",
"new",
"one"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1218-L1234 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.is_partitionable | def is_partitionable(self):
""" Returns if this block can be partitiones in 2 or more blocks,
because if contains enders.
"""
if len(self.mem) < 2:
return False # An atomic block
if any(x.is_ender or x.asm in arch.zx48k.backend.ASMS for x in self.mem):
r... | python | def is_partitionable(self):
""" Returns if this block can be partitiones in 2 or more blocks,
because if contains enders.
"""
if len(self.mem) < 2:
return False # An atomic block
if any(x.is_ender or x.asm in arch.zx48k.backend.ASMS for x in self.mem):
r... | [
"def",
"is_partitionable",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"mem",
")",
"<",
"2",
":",
"return",
"False",
"# An atomic block",
"if",
"any",
"(",
"x",
".",
"is_ender",
"or",
"x",
".",
"asm",
"in",
"arch",
".",
"zx48k",
".",
"bac... | Returns if this block can be partitiones in 2 or more blocks,
because if contains enders. | [
"Returns",
"if",
"this",
"block",
"can",
"be",
"partitiones",
"in",
"2",
"or",
"more",
"blocks",
"because",
"if",
"contains",
"enders",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1305-L1319 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.delete_from | def delete_from(self, basic_block):
""" Removes the basic_block ptr from the list for "comes_from"
if it exists. It also sets self.prev to None if it is basic_block.
"""
if basic_block is None:
return
if self.lock:
return
self.lock = True
... | python | def delete_from(self, basic_block):
""" Removes the basic_block ptr from the list for "comes_from"
if it exists. It also sets self.prev to None if it is basic_block.
"""
if basic_block is None:
return
if self.lock:
return
self.lock = True
... | [
"def",
"delete_from",
"(",
"self",
",",
"basic_block",
")",
":",
"if",
"basic_block",
"is",
"None",
":",
"return",
"if",
"self",
".",
"lock",
":",
"return",
"self",
".",
"lock",
"=",
"True",
"if",
"self",
".",
"prev",
"is",
"basic_block",
":",
"if",
... | Removes the basic_block ptr from the list for "comes_from"
if it exists. It also sets self.prev to None if it is basic_block. | [
"Removes",
"the",
"basic_block",
"ptr",
"from",
"the",
"list",
"for",
"comes_from",
"if",
"it",
"exists",
".",
"It",
"also",
"sets",
"self",
".",
"prev",
"to",
"None",
"if",
"it",
"is",
"basic_block",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1327-L1349 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.add_comes_from | def add_comes_from(self, basic_block):
""" This simulates a set. Adds the basic_block to the comes_from
list if not done already.
"""
if basic_block is None:
return
if self.lock:
return
# Return if already added
if basic_block in self.com... | python | def add_comes_from(self, basic_block):
""" This simulates a set. Adds the basic_block to the comes_from
list if not done already.
"""
if basic_block is None:
return
if self.lock:
return
# Return if already added
if basic_block in self.com... | [
"def",
"add_comes_from",
"(",
"self",
",",
"basic_block",
")",
":",
"if",
"basic_block",
"is",
"None",
":",
"return",
"if",
"self",
".",
"lock",
":",
"return",
"# Return if already added",
"if",
"basic_block",
"in",
"self",
".",
"comes_from",
":",
"return",
... | This simulates a set. Adds the basic_block to the comes_from
list if not done already. | [
"This",
"simulates",
"a",
"set",
".",
"Adds",
"the",
"basic_block",
"to",
"the",
"comes_from",
"list",
"if",
"not",
"done",
"already",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1376-L1393 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.update_next_block | def update_next_block(self):
""" If the last instruction of this block is a JP, JR or RET (with no
conditions) then the next and goes_to sets just contains a
single block
"""
last = self.mem[-1]
if last.inst not in ('ret', 'jp', 'jr') or last.condition_flag is not None:
... | python | def update_next_block(self):
""" If the last instruction of this block is a JP, JR or RET (with no
conditions) then the next and goes_to sets just contains a
single block
"""
last = self.mem[-1]
if last.inst not in ('ret', 'jp', 'jr') or last.condition_flag is not None:
... | [
"def",
"update_next_block",
"(",
"self",
")",
":",
"last",
"=",
"self",
".",
"mem",
"[",
"-",
"1",
"]",
"if",
"last",
".",
"inst",
"not",
"in",
"(",
"'ret'",
",",
"'jp'",
",",
"'jr'",
")",
"or",
"last",
".",
"condition_flag",
"is",
"not",
"None",
... | If the last instruction of this block is a JP, JR or RET (with no
conditions) then the next and goes_to sets just contains a
single block | [
"If",
"the",
"last",
"instruction",
"of",
"this",
"block",
"is",
"a",
"JP",
"JR",
"or",
"RET",
"(",
"with",
"no",
"conditions",
")",
"then",
"the",
"next",
"and",
"goes_to",
"sets",
"just",
"contains",
"a",
"single",
"block"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1413-L1443 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.update_goes_and_comes | def update_goes_and_comes(self):
""" Once the block is a Basic one, check the last instruction and updates
goes_to and comes_from set of the receivers.
Note: jp, jr and ret are already done in update_next_block()
"""
# Remove any block from the comes_from and goes_to list except ... | python | def update_goes_and_comes(self):
""" Once the block is a Basic one, check the last instruction and updates
goes_to and comes_from set of the receivers.
Note: jp, jr and ret are already done in update_next_block()
"""
# Remove any block from the comes_from and goes_to list except ... | [
"def",
"update_goes_and_comes",
"(",
"self",
")",
":",
"# Remove any block from the comes_from and goes_to list except the PREVIOUS and NEXT",
"if",
"not",
"len",
"(",
"self",
")",
":",
"return",
"if",
"self",
".",
"mem",
"[",
"-",
"1",
"]",
".",
"inst",
"==",
"'r... | Once the block is a Basic one, check the last instruction and updates
goes_to and comes_from set of the receivers.
Note: jp, jr and ret are already done in update_next_block() | [
"Once",
"the",
"block",
"is",
"a",
"Basic",
"one",
"check",
"the",
"last",
"instruction",
"and",
"updates",
"goes_to",
"and",
"comes_from",
"set",
"of",
"the",
"receivers",
".",
"Note",
":",
"jp",
"jr",
"and",
"ret",
"are",
"already",
"done",
"in",
"upda... | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1466-L1529 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.is_used | def is_used(self, regs, i, top=None):
""" Checks whether any of the given regs are required from the given point
to the end or not.
"""
if i < 0:
i = 0
if self.lock:
return True
regs = list(regs) # make a copy
if top is None:
... | python | def is_used(self, regs, i, top=None):
""" Checks whether any of the given regs are required from the given point
to the end or not.
"""
if i < 0:
i = 0
if self.lock:
return True
regs = list(regs) # make a copy
if top is None:
... | [
"def",
"is_used",
"(",
"self",
",",
"regs",
",",
"i",
",",
"top",
"=",
"None",
")",
":",
"if",
"i",
"<",
"0",
":",
"i",
"=",
"0",
"if",
"self",
".",
"lock",
":",
"return",
"True",
"regs",
"=",
"list",
"(",
"regs",
")",
"# make a copy",
"if",
... | Checks whether any of the given regs are required from the given point
to the end or not. | [
"Checks",
"whether",
"any",
"of",
"the",
"given",
"regs",
"are",
"required",
"from",
"the",
"given",
"point",
"to",
"the",
"end",
"or",
"not",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1531-L1563 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.safe_to_write | def safe_to_write(self, regs, i=0, end_=0):
""" Given a list of registers (8 or 16 bits) returns a list of them
that are safe to modify from the given index until the position given
which, if omitted, defaults to the end of the block.
:param regs: register or iterable of registers (8 or ... | python | def safe_to_write(self, regs, i=0, end_=0):
""" Given a list of registers (8 or 16 bits) returns a list of them
that are safe to modify from the given index until the position given
which, if omitted, defaults to the end of the block.
:param regs: register or iterable of registers (8 or ... | [
"def",
"safe_to_write",
"(",
"self",
",",
"regs",
",",
"i",
"=",
"0",
",",
"end_",
"=",
"0",
")",
":",
"if",
"is_register",
"(",
"regs",
")",
":",
"regs",
"=",
"set",
"(",
"single_registers",
"(",
"regs",
")",
")",
"else",
":",
"regs",
"=",
"set"... | Given a list of registers (8 or 16 bits) returns a list of them
that are safe to modify from the given index until the position given
which, if omitted, defaults to the end of the block.
:param regs: register or iterable of registers (8 or 16 bit one)
:param i: initial position of the bl... | [
"Given",
"a",
"list",
"of",
"registers",
"(",
"8",
"or",
"16",
"bits",
")",
"returns",
"a",
"list",
"of",
"them",
"that",
"are",
"safe",
"to",
"modify",
"from",
"the",
"given",
"index",
"until",
"the",
"position",
"given",
"which",
"if",
"omitted",
"de... | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1565-L1578 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.requires | def requires(self, i=0, end_=None):
""" Returns a list of registers and variables this block requires.
By default checks from the beginning (i = 0).
:param i: initial position of the block to examine
:param end_: final position to examine
:returns: registers safe to write
... | python | def requires(self, i=0, end_=None):
""" Returns a list of registers and variables this block requires.
By default checks from the beginning (i = 0).
:param i: initial position of the block to examine
:param end_: final position to examine
:returns: registers safe to write
... | [
"def",
"requires",
"(",
"self",
",",
"i",
"=",
"0",
",",
"end_",
"=",
"None",
")",
":",
"if",
"i",
"<",
"0",
":",
"i",
"=",
"0",
"end_",
"=",
"len",
"(",
"self",
")",
"if",
"end_",
"is",
"None",
"or",
"end_",
">",
"len",
"(",
"self",
")",
... | Returns a list of registers and variables this block requires.
By default checks from the beginning (i = 0).
:param i: initial position of the block to examine
:param end_: final position to examine
:returns: registers safe to write | [
"Returns",
"a",
"list",
"of",
"registers",
"and",
"variables",
"this",
"block",
"requires",
".",
"By",
"default",
"checks",
"from",
"the",
"beginning",
"(",
"i",
"=",
"0",
")",
".",
":",
"param",
"i",
":",
"initial",
"position",
"of",
"the",
"block",
"... | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1580-L1608 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.destroys | def destroys(self, i=0):
""" Returns a list of registers this block destroys
By default checks from the beginning (i = 0).
"""
regs = {'a', 'b', 'c', 'd', 'e', 'f', 'h', 'l', 'i', 'ixh', 'ixl', 'iyh', 'iyl', 'sp'}
top = len(self)
result = []
for ii in range(i, to... | python | def destroys(self, i=0):
""" Returns a list of registers this block destroys
By default checks from the beginning (i = 0).
"""
regs = {'a', 'b', 'c', 'd', 'e', 'f', 'h', 'l', 'i', 'ixh', 'ixl', 'iyh', 'iyl', 'sp'}
top = len(self)
result = []
for ii in range(i, to... | [
"def",
"destroys",
"(",
"self",
",",
"i",
"=",
"0",
")",
":",
"regs",
"=",
"{",
"'a'",
",",
"'b'",
",",
"'c'",
",",
"'d'",
",",
"'e'",
",",
"'f'",
",",
"'h'",
",",
"'l'",
",",
"'i'",
",",
"'ixh'",
",",
"'ixl'",
",",
"'iyh'",
",",
"'iyl'",
"... | Returns a list of registers this block destroys
By default checks from the beginning (i = 0). | [
"Returns",
"a",
"list",
"of",
"registers",
"this",
"block",
"destroys",
"By",
"default",
"checks",
"from",
"the",
"beginning",
"(",
"i",
"=",
"0",
")",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1610-L1627 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.swap | def swap(self, a, b):
""" Swaps mem positions a and b
"""
self.mem[a], self.mem[b] = self.mem[b], self.mem[a]
self.asm[a], self.asm[b] = self.asm[b], self.asm[a] | python | def swap(self, a, b):
""" Swaps mem positions a and b
"""
self.mem[a], self.mem[b] = self.mem[b], self.mem[a]
self.asm[a], self.asm[b] = self.asm[b], self.asm[a] | [
"def",
"swap",
"(",
"self",
",",
"a",
",",
"b",
")",
":",
"self",
".",
"mem",
"[",
"a",
"]",
",",
"self",
".",
"mem",
"[",
"b",
"]",
"=",
"self",
".",
"mem",
"[",
"b",
"]",
",",
"self",
".",
"mem",
"[",
"a",
"]",
"self",
".",
"asm",
"["... | Swaps mem positions a and b | [
"Swaps",
"mem",
"positions",
"a",
"and",
"b"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1629-L1633 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.goes_requires | def goes_requires(self, regs):
""" Returns whether any of the goes_to block requires any of
the given registers.
"""
if len(self) and self.mem[-1].inst == 'call' and self.mem[-1].condition_flag is None:
for block in self.calls:
if block.is_used(regs, 0):
... | python | def goes_requires(self, regs):
""" Returns whether any of the goes_to block requires any of
the given registers.
"""
if len(self) and self.mem[-1].inst == 'call' and self.mem[-1].condition_flag is None:
for block in self.calls:
if block.is_used(regs, 0):
... | [
"def",
"goes_requires",
"(",
"self",
",",
"regs",
")",
":",
"if",
"len",
"(",
"self",
")",
"and",
"self",
".",
"mem",
"[",
"-",
"1",
"]",
".",
"inst",
"==",
"'call'",
"and",
"self",
".",
"mem",
"[",
"-",
"1",
"]",
".",
"condition_flag",
"is",
"... | Returns whether any of the goes_to block requires any of
the given registers. | [
"Returns",
"whether",
"any",
"of",
"the",
"goes_to",
"block",
"requires",
"any",
"of",
"the",
"given",
"registers",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1635-L1652 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.get_label_idx | def get_label_idx(self, label):
""" Returns the index of a label.
Returns None if not found.
"""
for i in range(len(self)):
if self.mem[i].is_label and self.mem[i].inst == label:
return i
return None | python | def get_label_idx(self, label):
""" Returns the index of a label.
Returns None if not found.
"""
for i in range(len(self)):
if self.mem[i].is_label and self.mem[i].inst == label:
return i
return None | [
"def",
"get_label_idx",
"(",
"self",
",",
"label",
")",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
")",
")",
":",
"if",
"self",
".",
"mem",
"[",
"i",
"]",
".",
"is_label",
"and",
"self",
".",
"mem",
"[",
"i",
"]",
".",
"inst",
"... | Returns the index of a label.
Returns None if not found. | [
"Returns",
"the",
"index",
"of",
"a",
"label",
".",
"Returns",
"None",
"if",
"not",
"found",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1654-L1662 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.get_first_non_label_instruction | def get_first_non_label_instruction(self):
""" Returns the memcell of the given block, which is
not a LABEL.
"""
for i in range(len(self)):
if not self.mem[i].is_label:
return self.mem[i]
return None | python | def get_first_non_label_instruction(self):
""" Returns the memcell of the given block, which is
not a LABEL.
"""
for i in range(len(self)):
if not self.mem[i].is_label:
return self.mem[i]
return None | [
"def",
"get_first_non_label_instruction",
"(",
"self",
")",
":",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
")",
")",
":",
"if",
"not",
"self",
".",
"mem",
"[",
"i",
"]",
".",
"is_label",
":",
"return",
"self",
".",
"mem",
"[",
"i",
"]",
... | Returns the memcell of the given block, which is
not a LABEL. | [
"Returns",
"the",
"memcell",
"of",
"the",
"given",
"block",
"which",
"is",
"not",
"a",
"LABEL",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1664-L1672 |
boriel/zxbasic | arch/zx48k/optimizer.py | BasicBlock.optimize | def optimize(self):
""" Tries to detect peep-hole patterns in this basic block
and remove them.
"""
changed = OPTIONS.optimization.value > 2 # only with -O3 will enter here
while changed:
changed = False
regs = Registers()
if len(self) and s... | python | def optimize(self):
""" Tries to detect peep-hole patterns in this basic block
and remove them.
"""
changed = OPTIONS.optimization.value > 2 # only with -O3 will enter here
while changed:
changed = False
regs = Registers()
if len(self) and s... | [
"def",
"optimize",
"(",
"self",
")",
":",
"changed",
"=",
"OPTIONS",
".",
"optimization",
".",
"value",
">",
"2",
"# only with -O3 will enter here",
"while",
"changed",
":",
"changed",
"=",
"False",
"regs",
"=",
"Registers",
"(",
")",
"if",
"len",
"(",
"se... | Tries to detect peep-hole patterns in this basic block
and remove them. | [
"Tries",
"to",
"detect",
"peep",
"-",
"hole",
"patterns",
"in",
"this",
"basic",
"block",
"and",
"remove",
"them",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/optimizer.py#L1674-L2037 |
boriel/zxbasic | arch/zx48k/backend/__str.py | _str_oper | def _str_oper(op1, op2=None, reversed=False, no_exaf=False):
''' Returns pop sequence for 16 bits operands
1st operand in HL, 2nd operand in DE
You can swap operators extraction order
by setting reversed to True.
If no_exaf = True => No bits flags in A' will be used.
This s... | python | def _str_oper(op1, op2=None, reversed=False, no_exaf=False):
''' Returns pop sequence for 16 bits operands
1st operand in HL, 2nd operand in DE
You can swap operators extraction order
by setting reversed to True.
If no_exaf = True => No bits flags in A' will be used.
This s... | [
"def",
"_str_oper",
"(",
"op1",
",",
"op2",
"=",
"None",
",",
"reversed",
"=",
"False",
",",
"no_exaf",
"=",
"False",
")",
":",
"output",
"=",
"[",
"]",
"if",
"op2",
"is",
"not",
"None",
"and",
"reversed",
":",
"op1",
",",
"op2",
"=",
"op2",
",",... | Returns pop sequence for 16 bits operands
1st operand in HL, 2nd operand in DE
You can swap operators extraction order
by setting reversed to True.
If no_exaf = True => No bits flags in A' will be used.
This saves two bytes. | [
"Returns",
"pop",
"sequence",
"for",
"16",
"bits",
"operands",
"1st",
"operand",
"in",
"HL",
"2nd",
"operand",
"in",
"DE"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__str.py#L16-L99 |
boriel/zxbasic | arch/zx48k/backend/__str.py | _free_sequence | def _free_sequence(tmp1, tmp2=False):
''' Outputs a FREEMEM sequence for 1 or 2 ops
'''
if not tmp1 and not tmp2:
return []
output = []
if tmp1 and tmp2:
output.append('pop de')
output.append('ex (sp), hl')
output.append('push de')
output.append('call __MEM_F... | python | def _free_sequence(tmp1, tmp2=False):
''' Outputs a FREEMEM sequence for 1 or 2 ops
'''
if not tmp1 and not tmp2:
return []
output = []
if tmp1 and tmp2:
output.append('pop de')
output.append('ex (sp), hl')
output.append('push de')
output.append('call __MEM_F... | [
"def",
"_free_sequence",
"(",
"tmp1",
",",
"tmp2",
"=",
"False",
")",
":",
"if",
"not",
"tmp1",
"and",
"not",
"tmp2",
":",
"return",
"[",
"]",
"output",
"=",
"[",
"]",
"if",
"tmp1",
"and",
"tmp2",
":",
"output",
".",
"append",
"(",
"'pop de'",
")",... | Outputs a FREEMEM sequence for 1 or 2 ops | [
"Outputs",
"a",
"FREEMEM",
"sequence",
"for",
"1",
"or",
"2",
"ops"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__str.py#L102-L122 |
boriel/zxbasic | arch/zx48k/backend/__str.py | _nestr | def _nestr(ins):
''' Compares & pops top 2 strings out of the stack.
Temporal values are freed from memory. (a$ != b$)
'''
(tmp1, tmp2, output) = _str_oper(ins.quad[2], ins.quad[3])
output.append('call __STRNE')
output.append('push af')
REQUIRES.add('string.asm')
return output | python | def _nestr(ins):
''' Compares & pops top 2 strings out of the stack.
Temporal values are freed from memory. (a$ != b$)
'''
(tmp1, tmp2, output) = _str_oper(ins.quad[2], ins.quad[3])
output.append('call __STRNE')
output.append('push af')
REQUIRES.add('string.asm')
return output | [
"def",
"_nestr",
"(",
"ins",
")",
":",
"(",
"tmp1",
",",
"tmp2",
",",
"output",
")",
"=",
"_str_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"ins",
".",
"quad",
"[",
"3",
"]",
")",
"output",
".",
"append",
"(",
"'call __STRNE'",
")",
"ou... | Compares & pops top 2 strings out of the stack.
Temporal values are freed from memory. (a$ != b$) | [
"Compares",
"&",
"pops",
"top",
"2",
"strings",
"out",
"of",
"the",
"stack",
".",
"Temporal",
"values",
"are",
"freed",
"from",
"memory",
".",
"(",
"a$",
"!",
"=",
"b$",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__str.py#L199-L207 |
boriel/zxbasic | arch/zx48k/backend/__str.py | _lenstr | def _lenstr(ins):
''' Returns string length
'''
(tmp1, output) = _str_oper(ins.quad[2], no_exaf=True)
if tmp1:
output.append('push hl')
output.append('call __STRLEN')
output.extend(_free_sequence(tmp1))
output.append('push hl')
REQUIRES.add('strlen.asm')
return output | python | def _lenstr(ins):
''' Returns string length
'''
(tmp1, output) = _str_oper(ins.quad[2], no_exaf=True)
if tmp1:
output.append('push hl')
output.append('call __STRLEN')
output.extend(_free_sequence(tmp1))
output.append('push hl')
REQUIRES.add('strlen.asm')
return output | [
"def",
"_lenstr",
"(",
"ins",
")",
":",
"(",
"tmp1",
",",
"output",
")",
"=",
"_str_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"no_exaf",
"=",
"True",
")",
"if",
"tmp1",
":",
"output",
".",
"append",
"(",
"'push hl'",
")",
"output",
".",... | Returns string length | [
"Returns",
"string",
"length"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__str.py#L210-L221 |
boriel/zxbasic | symbols/builtin.py | SymbolBUILTIN.make_node | def make_node(cls, lineno, fname, func=None, type_=None, *operands):
""" Creates a node for a unary operation. E.g. -x or LEN(a$)
Parameters:
-func: function used on constant folding when possible
-type_: the resulting type (by default, the same as the argument).
... | python | def make_node(cls, lineno, fname, func=None, type_=None, *operands):
""" Creates a node for a unary operation. E.g. -x or LEN(a$)
Parameters:
-func: function used on constant folding when possible
-type_: the resulting type (by default, the same as the argument).
... | [
"def",
"make_node",
"(",
"cls",
",",
"lineno",
",",
"fname",
",",
"func",
"=",
"None",
",",
"type_",
"=",
"None",
",",
"*",
"operands",
")",
":",
"if",
"func",
"is",
"not",
"None",
"and",
"len",
"(",
"operands",
")",
"==",
"1",
":",
"# Try constant... | Creates a node for a unary operation. E.g. -x or LEN(a$)
Parameters:
-func: function used on constant folding when possible
-type_: the resulting type (by default, the same as the argument).
For example, for LEN (str$), result type is 'u16'
and arg type i... | [
"Creates",
"a",
"node",
"for",
"a",
"unary",
"operation",
".",
"E",
".",
"g",
".",
"-",
"x",
"or",
"LEN",
"(",
"a$",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/builtin.py#L70-L83 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _8bit_oper | def _8bit_oper(op1, op2=None, reversed_=False):
""" Returns pop sequence for 8 bits operands
1st operand in H, 2nd operand in A (accumulator)
For some operations (like comparisons), you can swap
operands extraction by setting reversed = True
"""
output = []
if op2 is not None and reversed_... | python | def _8bit_oper(op1, op2=None, reversed_=False):
""" Returns pop sequence for 8 bits operands
1st operand in H, 2nd operand in A (accumulator)
For some operations (like comparisons), you can swap
operands extraction by setting reversed = True
"""
output = []
if op2 is not None and reversed_... | [
"def",
"_8bit_oper",
"(",
"op1",
",",
"op2",
"=",
"None",
",",
"reversed_",
"=",
"False",
")",
":",
"output",
"=",
"[",
"]",
"if",
"op2",
"is",
"not",
"None",
"and",
"reversed_",
":",
"tmp",
"=",
"op1",
"op1",
"=",
"op2",
"op2",
"=",
"tmp",
"op",... | Returns pop sequence for 8 bits operands
1st operand in H, 2nd operand in A (accumulator)
For some operations (like comparisons), you can swap
operands extraction by setting reversed = True | [
"Returns",
"pop",
"sequence",
"for",
"8",
"bits",
"operands",
"1st",
"operand",
"in",
"H",
"2nd",
"operand",
"in",
"A",
"(",
"accumulator",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L23-L124 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _add8 | def _add8(ins):
""" Pops last 2 bytes from the stack and adds them.
Then push the result onto the stack.
Optimizations:
* If any of the operands is ZERO,
then do NOTHING: A + 0 = 0 + A = A
* If any of the operands is 1, then
INC is used
* If any of the operands is -1 (25... | python | def _add8(ins):
""" Pops last 2 bytes from the stack and adds them.
Then push the result onto the stack.
Optimizations:
* If any of the operands is ZERO,
then do NOTHING: A + 0 = 0 + A = A
* If any of the operands is 1, then
INC is used
* If any of the operands is -1 (25... | [
"def",
"_add8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"_int_ops",
"(",
"op1",
",",
"op2",
")",
"is",
"not",
"None",
":",
"op1",
",",
"op2",
"=",
"_int_ops",
"(",
"op1",
... | Pops last 2 bytes from the stack and adds them.
Then push the result onto the stack.
Optimizations:
* If any of the operands is ZERO,
then do NOTHING: A + 0 = 0 + A = A
* If any of the operands is 1, then
INC is used
* If any of the operands is -1 (255), then
DEC is ... | [
"Pops",
"last",
"2",
"bytes",
"from",
"the",
"stack",
"and",
"adds",
"them",
".",
"Then",
"push",
"the",
"result",
"onto",
"the",
"stack",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L127-L173 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _sub8 | def _sub8(ins):
""" Pops last 2 bytes from the stack and subtract them.
Then push the result onto the stack. Top-1 of the stack is
subtracted Top
_sub8 t1, a, b === t1 <-- a - b
Optimizations:
* If 2nd op is ZERO,
then do NOTHING: A - 0 = A
* If 1st operand is 0, then
j... | python | def _sub8(ins):
""" Pops last 2 bytes from the stack and subtract them.
Then push the result onto the stack. Top-1 of the stack is
subtracted Top
_sub8 t1, a, b === t1 <-- a - b
Optimizations:
* If 2nd op is ZERO,
then do NOTHING: A - 0 = A
* If 1st operand is 0, then
j... | [
"def",
"_sub8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"is_int",
"(",
"op2",
")",
":",
"# 2nd operand",
"op2",
"=",
"int8",
"(",
"op2",
")",
"output",
"=",
"_8bit_oper",
"(... | Pops last 2 bytes from the stack and subtract them.
Then push the result onto the stack. Top-1 of the stack is
subtracted Top
_sub8 t1, a, b === t1 <-- a - b
Optimizations:
* If 2nd op is ZERO,
then do NOTHING: A - 0 = A
* If 1st operand is 0, then
just do a NEG
* If... | [
"Pops",
"last",
"2",
"bytes",
"from",
"the",
"stack",
"and",
"subtract",
"them",
".",
"Then",
"push",
"the",
"result",
"onto",
"the",
"stack",
".",
"Top",
"-",
"1",
"of",
"the",
"stack",
"is",
"subtracted",
"Top",
"_sub8",
"t1",
"a",
"b",
"===",
"t1"... | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L176-L241 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _mul8 | def _mul8(ins):
""" Multiplies 2 las values from the stack.
Optimizations:
* If any of the ops is ZERO,
then do A = 0 ==> XOR A, cause A * 0 = 0 * A = 0
* If any ot the ops is ONE, do NOTHING
A * 1 = 1 * A = A
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is... | python | def _mul8(ins):
""" Multiplies 2 las values from the stack.
Optimizations:
* If any of the ops is ZERO,
then do A = 0 ==> XOR A, cause A * 0 = 0 * A = 0
* If any ot the ops is ONE, do NOTHING
A * 1 = 1 * A = A
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is... | [
"def",
"_mul8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"_int_ops",
"(",
"op1",
",",
"op2",
")",
"is",
"not",
"None",
":",
"op1",
",",
"op2",
"=",
"_int_ops",
"(",
"op1",
... | Multiplies 2 las values from the stack.
Optimizations:
* If any of the ops is ZERO,
then do A = 0 ==> XOR A, cause A * 0 = 0 * A = 0
* If any ot the ops is ONE, do NOTHING
A * 1 = 1 * A = A | [
"Multiplies",
"2",
"las",
"values",
"from",
"the",
"stack",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L244-L290 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _divu8 | def _divu8(ins):
""" Divides 2 8bit unsigned integers. The result is pushed onto the stack.
Optimizations:
* If 2nd op is 1 then
do nothing
* If 2nd op is 2 then
Shift Right Logical
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
op2 = int8(op2)
outp... | python | def _divu8(ins):
""" Divides 2 8bit unsigned integers. The result is pushed onto the stack.
Optimizations:
* If 2nd op is 1 then
do nothing
* If 2nd op is 2 then
Shift Right Logical
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
op2 = int8(op2)
outp... | [
"def",
"_divu8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"is_int",
"(",
"op2",
")",
":",
"op2",
"=",
"int8",
"(",
"op2",
")",
"output",
"=",
"_8bit_oper",
"(",
"op1",
")",... | Divides 2 8bit unsigned integers. The result is pushed onto the stack.
Optimizations:
* If 2nd op is 1 then
do nothing
* If 2nd op is 2 then
Shift Right Logical | [
"Divides",
"2",
"8bit",
"unsigned",
"integers",
".",
"The",
"result",
"is",
"pushed",
"onto",
"the",
"stack",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L293-L336 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _ltu8 | def _ltu8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3])
output.append('cp h')
output.append('sb... | python | def _ltu8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3])
output.append('cp h')
output.append('sb... | [
"def",
"_ltu8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"ins",
".",
"quad",
"[",
"3",
"]",
")",
"output",
".",
"append",
"(",
"'cp h'",
")",
"output",
".",
"append",
"(",
"'sbc a, a'",
")",
... | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version | [
"Compares",
"&",
"pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"the",
"1st",
"operand",
"<",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
".",
"Pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L490-L502 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _lti8 | def _lti8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version
"""
output = []
output.extend(_8bit_oper(ins.quad[2], ins.quad[3]))
output.append('call __L... | python | def _lti8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version
"""
output = []
output.extend(_8bit_oper(ins.quad[2], ins.quad[3]))
output.append('call __L... | [
"def",
"_lti8",
"(",
"ins",
")",
":",
"output",
"=",
"[",
"]",
"output",
".",
"extend",
"(",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"ins",
".",
"quad",
"[",
"3",
"]",
")",
")",
"output",
".",
"append",
"(",
"'call __LTI8'",
... | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand < 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version | [
"Compares",
"&",
"pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"the",
"1st",
"operand",
"<",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
".",
"Pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L505-L518 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _gtu8 | def _gtu8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand > 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3], reversed_=True)
output.append('cp h')
o... | python | def _gtu8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand > 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3], reversed_=True)
output.append('cp h')
o... | [
"def",
"_gtu8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"ins",
".",
"quad",
"[",
"3",
"]",
",",
"reversed_",
"=",
"True",
")",
"output",
".",
"append",
"(",
"'cp h'",
")",
"output",
".",
"... | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand > 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version | [
"Compares",
"&",
"pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"the",
"1st",
"operand",
">",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
".",
"Pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L521-L533 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _eq8 | def _eq8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand == 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit un/signed version
"""
if is_int(ins.quad[3]):
output = _8bit_oper(ins.quad[2])
n = int8(ins.quad[3... | python | def _eq8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand == 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit un/signed version
"""
if is_int(ins.quad[3]):
output = _8bit_oper(ins.quad[2])
n = int8(ins.quad[3... | [
"def",
"_eq8",
"(",
"ins",
")",
":",
"if",
"is_int",
"(",
"ins",
".",
"quad",
"[",
"3",
"]",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"n",
"=",
"int8",
"(",
"ins",
".",
"quad",
"[",
"3",
"]",
")",
... | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand == 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit un/signed version | [
"Compares",
"&",
"pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"the",
"1st",
"operand",
"==",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
".",
"Pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L551-L574 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _leu8 | def _leu8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand <= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3], reversed_=True)
output.append('sub h') # ... | python | def _leu8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand <= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3], reversed_=True)
output.append('sub h') # ... | [
"def",
"_leu8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"ins",
".",
"quad",
"[",
"3",
"]",
",",
"reversed_",
"=",
"True",
")",
"output",
".",
"append",
"(",
"'sub h'",
")",
"# Carry if H > A",... | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand <= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit unsigned version | [
"Compares",
"&",
"pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"the",
"1st",
"operand",
"<",
"=",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
".",
"Pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"... | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L577-L590 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _lei8 | def _lei8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand <= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3])
output.append('call __LEI8')
output.appe... | python | def _lei8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand <= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3])
output.append('call __LEI8')
output.appe... | [
"def",
"_lei8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"ins",
".",
"quad",
"[",
"3",
"]",
")",
"output",
".",
"append",
"(",
"'call __LEI8'",
")",
"output",
".",
"append",
"(",
"'push af'",
... | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand <= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version | [
"Compares",
"&",
"pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"the",
"1st",
"operand",
"<",
"=",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
".",
"Pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"... | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L593-L605 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _gei8 | def _gei8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand >= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3], reversed_=True)
output.append('call __LEI8')... | python | def _gei8(ins):
""" Compares & pops top 2 operands out of the stack, and checks
if the 1st operand >= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version
"""
output = _8bit_oper(ins.quad[2], ins.quad[3], reversed_=True)
output.append('call __LEI8')... | [
"def",
"_gei8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
",",
"ins",
".",
"quad",
"[",
"3",
"]",
",",
"reversed_",
"=",
"True",
")",
"output",
".",
"append",
"(",
"'call __LEI8'",
")",
"output",
"... | Compares & pops top 2 operands out of the stack, and checks
if the 1st operand >= 2nd operand (top of the stack).
Pushes 0 if False, 1 if True.
8 bit signed version | [
"Compares",
"&",
"pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"the",
"1st",
"operand",
">",
"=",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
".",
"Pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"... | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L633-L645 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _and8 | def _and8(ins):
""" Pops top 2 operands out of the stack, and checks
if 1st operand AND (logical) 2nd operand (top of the stack),
pushes 0 if False, not 0 if True.
8 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
op1, op2 = _i... | python | def _and8(ins):
""" Pops top 2 operands out of the stack, and checks
if 1st operand AND (logical) 2nd operand (top of the stack),
pushes 0 if False, not 0 if True.
8 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
op1, op2 = _i... | [
"def",
"_and8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"_int_ops",
"(",
"op1",
",",
"op2",
")",
"is",
"not",
"None",
":",
"op1",
",",
"op2",
"=",
"_int_ops",
"(",
"op1",
... | Pops top 2 operands out of the stack, and checks
if 1st operand AND (logical) 2nd operand (top of the stack),
pushes 0 if False, not 0 if True.
8 bit un/signed version | [
"Pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"1st",
"operand",
"AND",
"(",
"logical",
")",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
"pushes",
"0",
"if",
"False",
"not",
"0",
"if",
"True",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L730-L761 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _band8 | def _band8(ins):
""" Pops top 2 operands out of the stack, and does
1st AND (bitwise) 2nd operand (top of the stack),
pushes the result.
8 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
op1, op2 = _int_ops(op1, op2)
o... | python | def _band8(ins):
""" Pops top 2 operands out of the stack, and does
1st AND (bitwise) 2nd operand (top of the stack),
pushes the result.
8 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
op1, op2 = _int_ops(op1, op2)
o... | [
"def",
"_band8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"_int_ops",
"(",
"op1",
",",
"op2",
")",
"is",
"not",
"None",
":",
"op1",
",",
"op2",
"=",
"_int_ops",
"(",
"op1",... | Pops top 2 operands out of the stack, and does
1st AND (bitwise) 2nd operand (top of the stack),
pushes the result.
8 bit un/signed version | [
"Pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"does",
"1st",
"AND",
"(",
"bitwise",
")",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
"pushes",
"the",
"result",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L764-L791 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _xor8 | def _xor8(ins):
""" Pops top 2 operands out of the stack, and checks
if 1st operand XOR (logical) 2nd operand (top of the stack),
pushes 0 if False, 1 if True.
8 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
op1, op2 = _int_o... | python | def _xor8(ins):
""" Pops top 2 operands out of the stack, and checks
if 1st operand XOR (logical) 2nd operand (top of the stack),
pushes 0 if False, 1 if True.
8 bit un/signed version
"""
op1, op2 = tuple(ins.quad[2:])
if _int_ops(op1, op2) is not None:
op1, op2 = _int_o... | [
"def",
"_xor8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"_int_ops",
"(",
"op1",
",",
"op2",
")",
"is",
"not",
"None",
":",
"op1",
",",
"op2",
"=",
"_int_ops",
"(",
"op1",
... | Pops top 2 operands out of the stack, and checks
if 1st operand XOR (logical) 2nd operand (top of the stack),
pushes 0 if False, 1 if True.
8 bit un/signed version | [
"Pops",
"top",
"2",
"operands",
"out",
"of",
"the",
"stack",
"and",
"checks",
"if",
"1st",
"operand",
"XOR",
"(",
"logical",
")",
"2nd",
"operand",
"(",
"top",
"of",
"the",
"stack",
")",
"pushes",
"0",
"if",
"False",
"1",
"if",
"True",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L794-L820 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _not8 | def _not8(ins):
""" Negates (Logical NOT) top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('sub 1') # Gives carry only if A = 0
output.append('sbc a, a') # Gives FF only if Carry else 0
output.append('push af')
return output | python | def _not8(ins):
""" Negates (Logical NOT) top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('sub 1') # Gives carry only if A = 0
output.append('sbc a, a') # Gives FF only if Carry else 0
output.append('push af')
return output | [
"def",
"_not8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"append",
"(",
"'sub 1'",
")",
"# Gives carry only if A = 0",
"output",
".",
"append",
"(",
"'sbc a, a'",
")",
"# Gives FF only i... | Negates (Logical NOT) top of the stack (8 bits in AF) | [
"Negates",
"(",
"Logical",
"NOT",
")",
"top",
"of",
"the",
"stack",
"(",
"8",
"bits",
"in",
"AF",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L853-L861 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _bnot8 | def _bnot8(ins):
""" Negates (BITWISE NOT) top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('cpl') # Gives carry only if A = 0
output.append('push af')
return output | python | def _bnot8(ins):
""" Negates (BITWISE NOT) top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('cpl') # Gives carry only if A = 0
output.append('push af')
return output | [
"def",
"_bnot8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"append",
"(",
"'cpl'",
")",
"# Gives carry only if A = 0",
"output",
".",
"append",
"(",
"'push af'",
")",
"return",
"output"... | Negates (BITWISE NOT) top of the stack (8 bits in AF) | [
"Negates",
"(",
"BITWISE",
"NOT",
")",
"top",
"of",
"the",
"stack",
"(",
"8",
"bits",
"in",
"AF",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L864-L871 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _neg8 | def _neg8(ins):
""" Negates top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('neg')
output.append('push af')
return output | python | def _neg8(ins):
""" Negates top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('neg')
output.append('push af')
return output | [
"def",
"_neg8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"append",
"(",
"'neg'",
")",
"output",
".",
"append",
"(",
"'push af'",
")",
"return",
"output"
] | Negates top of the stack (8 bits in AF) | [
"Negates",
"top",
"of",
"the",
"stack",
"(",
"8",
"bits",
"in",
"AF",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L874-L881 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _abs8 | def _abs8(ins):
""" Absolute value of top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('call __ABS8')
output.append('push af')
REQUIRES.add('abs8.asm')
return output | python | def _abs8(ins):
""" Absolute value of top of the stack (8 bits in AF)
"""
output = _8bit_oper(ins.quad[2])
output.append('call __ABS8')
output.append('push af')
REQUIRES.add('abs8.asm')
return output | [
"def",
"_abs8",
"(",
"ins",
")",
":",
"output",
"=",
"_8bit_oper",
"(",
"ins",
".",
"quad",
"[",
"2",
"]",
")",
"output",
".",
"append",
"(",
"'call __ABS8'",
")",
"output",
".",
"append",
"(",
"'push af'",
")",
"REQUIRES",
".",
"add",
"(",
"'abs8.as... | Absolute value of top of the stack (8 bits in AF) | [
"Absolute",
"value",
"of",
"top",
"of",
"the",
"stack",
"(",
"8",
"bits",
"in",
"AF",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L884-L891 |
boriel/zxbasic | arch/zx48k/backend/__8bit.py | _shru8 | def _shru8(ins):
""" Shift 8bit unsigned integer to the right. The result is pushed onto the stack.
Optimizations:
* If 1nd or 2nd op is 0 then
do nothing
* If 2nd op is < 4 then
unroll loop
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
op2 = int8(op2)
... | python | def _shru8(ins):
""" Shift 8bit unsigned integer to the right. The result is pushed onto the stack.
Optimizations:
* If 1nd or 2nd op is 0 then
do nothing
* If 2nd op is < 4 then
unroll loop
"""
op1, op2 = tuple(ins.quad[2:])
if is_int(op2):
op2 = int8(op2)
... | [
"def",
"_shru8",
"(",
"ins",
")",
":",
"op1",
",",
"op2",
"=",
"tuple",
"(",
"ins",
".",
"quad",
"[",
"2",
":",
"]",
")",
"if",
"is_int",
"(",
"op2",
")",
":",
"op2",
"=",
"int8",
"(",
"op2",
")",
"output",
"=",
"_8bit_oper",
"(",
"op1",
")",... | Shift 8bit unsigned integer to the right. The result is pushed onto the stack.
Optimizations:
* If 1nd or 2nd op is 0 then
do nothing
* If 2nd op is < 4 then
unroll loop | [
"Shift",
"8bit",
"unsigned",
"integer",
"to",
"the",
"right",
".",
"The",
"result",
"is",
"pushed",
"onto",
"the",
"stack",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/arch/zx48k/backend/__8bit.py#L894-L945 |
boriel/zxbasic | prepro/macrocall.py | MacroCall.is_defined | def is_defined(self, symbolTable=None):
""" True if this macro has been defined
"""
if symbolTable is None:
symbolTable = self.table
return symbolTable.defined(self.id_) | python | def is_defined(self, symbolTable=None):
""" True if this macro has been defined
"""
if symbolTable is None:
symbolTable = self.table
return symbolTable.defined(self.id_) | [
"def",
"is_defined",
"(",
"self",
",",
"symbolTable",
"=",
"None",
")",
":",
"if",
"symbolTable",
"is",
"None",
":",
"symbolTable",
"=",
"self",
".",
"table",
"return",
"symbolTable",
".",
"defined",
"(",
"self",
".",
"id_",
")"
] | True if this macro has been defined | [
"True",
"if",
"this",
"macro",
"has",
"been",
"defined"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/prepro/macrocall.py#L89-L95 |
boriel/zxbasic | symbols/boundlist.py | SymbolBOUNDLIST.make_node | def make_node(cls, node, *args):
''' Creates an array BOUND LIST.
'''
if node is None:
return cls.make_node(SymbolBOUNDLIST(), *args)
if node.token != 'BOUNDLIST':
return cls.make_node(None, node, *args)
for arg in args:
if arg is None:
... | python | def make_node(cls, node, *args):
''' Creates an array BOUND LIST.
'''
if node is None:
return cls.make_node(SymbolBOUNDLIST(), *args)
if node.token != 'BOUNDLIST':
return cls.make_node(None, node, *args)
for arg in args:
if arg is None:
... | [
"def",
"make_node",
"(",
"cls",
",",
"node",
",",
"*",
"args",
")",
":",
"if",
"node",
"is",
"None",
":",
"return",
"cls",
".",
"make_node",
"(",
"SymbolBOUNDLIST",
"(",
")",
",",
"*",
"args",
")",
"if",
"node",
".",
"token",
"!=",
"'BOUNDLIST'",
"... | Creates an array BOUND LIST. | [
"Creates",
"an",
"array",
"BOUND",
"LIST",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/symbols/boundlist.py#L35-L49 |
boriel/zxbasic | zxbparser.py | init | def init():
""" Initializes parser state
"""
global LABELS
global LET_ASSIGNMENT
global PRINT_IS_USED
global SYMBOL_TABLE
global ast
global data_ast
global optemps
global OPTIONS
global last_brk_linenum
LABELS = {}
LET_ASSIGNMENT = False
PRINT_IS_USED = False
... | python | def init():
""" Initializes parser state
"""
global LABELS
global LET_ASSIGNMENT
global PRINT_IS_USED
global SYMBOL_TABLE
global ast
global data_ast
global optemps
global OPTIONS
global last_brk_linenum
LABELS = {}
LET_ASSIGNMENT = False
PRINT_IS_USED = False
... | [
"def",
"init",
"(",
")",
":",
"global",
"LABELS",
"global",
"LET_ASSIGNMENT",
"global",
"PRINT_IS_USED",
"global",
"SYMBOL_TABLE",
"global",
"ast",
"global",
"data_ast",
"global",
"optemps",
"global",
"OPTIONS",
"global",
"last_brk_linenum",
"LABELS",
"=",
"{",
"}... | Initializes parser state | [
"Initializes",
"parser",
"state"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L113-L149 |
boriel/zxbasic | zxbparser.py | make_number | def make_number(value, lineno, type_=None):
""" Wrapper: creates a constant number node.
"""
return symbols.NUMBER(value, type_=type_, lineno=lineno) | python | def make_number(value, lineno, type_=None):
""" Wrapper: creates a constant number node.
"""
return symbols.NUMBER(value, type_=type_, lineno=lineno) | [
"def",
"make_number",
"(",
"value",
",",
"lineno",
",",
"type_",
"=",
"None",
")",
":",
"return",
"symbols",
".",
"NUMBER",
"(",
"value",
",",
"type_",
"=",
"type_",
",",
"lineno",
"=",
"lineno",
")"
] | Wrapper: creates a constant number node. | [
"Wrapper",
":",
"creates",
"a",
"constant",
"number",
"node",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L171-L174 |
boriel/zxbasic | zxbparser.py | make_typecast | def make_typecast(type_, node, lineno):
""" Wrapper: returns a Typecast node
"""
assert isinstance(type_, symbols.TYPE)
return symbols.TYPECAST.make_node(type_, node, lineno) | python | def make_typecast(type_, node, lineno):
""" Wrapper: returns a Typecast node
"""
assert isinstance(type_, symbols.TYPE)
return symbols.TYPECAST.make_node(type_, node, lineno) | [
"def",
"make_typecast",
"(",
"type_",
",",
"node",
",",
"lineno",
")",
":",
"assert",
"isinstance",
"(",
"type_",
",",
"symbols",
".",
"TYPE",
")",
"return",
"symbols",
".",
"TYPECAST",
".",
"make_node",
"(",
"type_",
",",
"node",
",",
"lineno",
")"
] | Wrapper: returns a Typecast node | [
"Wrapper",
":",
"returns",
"a",
"Typecast",
"node"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L177-L181 |
boriel/zxbasic | zxbparser.py | make_binary | def make_binary(lineno, operator, left, right, func=None, type_=None):
""" Wrapper: returns a Binary node
"""
return symbols.BINARY.make_node(operator, left, right, lineno, func, type_) | python | def make_binary(lineno, operator, left, right, func=None, type_=None):
""" Wrapper: returns a Binary node
"""
return symbols.BINARY.make_node(operator, left, right, lineno, func, type_) | [
"def",
"make_binary",
"(",
"lineno",
",",
"operator",
",",
"left",
",",
"right",
",",
"func",
"=",
"None",
",",
"type_",
"=",
"None",
")",
":",
"return",
"symbols",
".",
"BINARY",
".",
"make_node",
"(",
"operator",
",",
"left",
",",
"right",
",",
"li... | Wrapper: returns a Binary node | [
"Wrapper",
":",
"returns",
"a",
"Binary",
"node"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L184-L187 |
boriel/zxbasic | zxbparser.py | make_unary | def make_unary(lineno, operator, operand, func=None, type_=None):
""" Wrapper: returns a Unary node
"""
return symbols.UNARY.make_node(lineno, operator, operand, func, type_) | python | def make_unary(lineno, operator, operand, func=None, type_=None):
""" Wrapper: returns a Unary node
"""
return symbols.UNARY.make_node(lineno, operator, operand, func, type_) | [
"def",
"make_unary",
"(",
"lineno",
",",
"operator",
",",
"operand",
",",
"func",
"=",
"None",
",",
"type_",
"=",
"None",
")",
":",
"return",
"symbols",
".",
"UNARY",
".",
"make_node",
"(",
"lineno",
",",
"operator",
",",
"operand",
",",
"func",
",",
... | Wrapper: returns a Unary node | [
"Wrapper",
":",
"returns",
"a",
"Unary",
"node"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L190-L193 |
boriel/zxbasic | zxbparser.py | make_builtin | def make_builtin(lineno, fname, operands, func=None, type_=None):
""" Wrapper: returns a Builtin function node.
Can be a Symbol, tuple or list of Symbols
If operand is an iterable, they will be expanded.
"""
if operands is None:
operands = []
assert isinstance(operands, Symbol) or isinst... | python | def make_builtin(lineno, fname, operands, func=None, type_=None):
""" Wrapper: returns a Builtin function node.
Can be a Symbol, tuple or list of Symbols
If operand is an iterable, they will be expanded.
"""
if operands is None:
operands = []
assert isinstance(operands, Symbol) or isinst... | [
"def",
"make_builtin",
"(",
"lineno",
",",
"fname",
",",
"operands",
",",
"func",
"=",
"None",
",",
"type_",
"=",
"None",
")",
":",
"if",
"operands",
"is",
"None",
":",
"operands",
"=",
"[",
"]",
"assert",
"isinstance",
"(",
"operands",
",",
"Symbol",
... | Wrapper: returns a Builtin function node.
Can be a Symbol, tuple or list of Symbols
If operand is an iterable, they will be expanded. | [
"Wrapper",
":",
"returns",
"a",
"Builtin",
"function",
"node",
".",
"Can",
"be",
"a",
"Symbol",
"tuple",
"or",
"list",
"of",
"Symbols",
"If",
"operand",
"is",
"an",
"iterable",
"they",
"will",
"be",
"expanded",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L196-L208 |
boriel/zxbasic | zxbparser.py | make_strslice | def make_strslice(lineno, s, lower, upper):
""" Wrapper: returns String Slice node
"""
return symbols.STRSLICE.make_node(lineno, s, lower, upper) | python | def make_strslice(lineno, s, lower, upper):
""" Wrapper: returns String Slice node
"""
return symbols.STRSLICE.make_node(lineno, s, lower, upper) | [
"def",
"make_strslice",
"(",
"lineno",
",",
"s",
",",
"lower",
",",
"upper",
")",
":",
"return",
"symbols",
".",
"STRSLICE",
".",
"make_node",
"(",
"lineno",
",",
"s",
",",
"lower",
",",
"upper",
")"
] | Wrapper: returns String Slice node | [
"Wrapper",
":",
"returns",
"String",
"Slice",
"node"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L215-L218 |
boriel/zxbasic | zxbparser.py | make_sentence | def make_sentence(sentence, *args, **kwargs):
""" Wrapper: returns a Sentence node
"""
return symbols.SENTENCE(*([sentence] + list(args)), **kwargs) | python | def make_sentence(sentence, *args, **kwargs):
""" Wrapper: returns a Sentence node
"""
return symbols.SENTENCE(*([sentence] + list(args)), **kwargs) | [
"def",
"make_sentence",
"(",
"sentence",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"symbols",
".",
"SENTENCE",
"(",
"*",
"(",
"[",
"sentence",
"]",
"+",
"list",
"(",
"args",
")",
")",
",",
"*",
"*",
"kwargs",
")"
] | Wrapper: returns a Sentence node | [
"Wrapper",
":",
"returns",
"a",
"Sentence",
"node"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L221-L224 |
boriel/zxbasic | zxbparser.py | make_func_declaration | def make_func_declaration(func_name, lineno, type_=None):
""" This will return a node with the symbol as a function.
"""
return symbols.FUNCDECL.make_node(func_name, lineno, type_=type_) | python | def make_func_declaration(func_name, lineno, type_=None):
""" This will return a node with the symbol as a function.
"""
return symbols.FUNCDECL.make_node(func_name, lineno, type_=type_) | [
"def",
"make_func_declaration",
"(",
"func_name",
",",
"lineno",
",",
"type_",
"=",
"None",
")",
":",
"return",
"symbols",
".",
"FUNCDECL",
".",
"make_node",
"(",
"func_name",
",",
"lineno",
",",
"type_",
"=",
"type_",
")"
] | This will return a node with the symbol as a function. | [
"This",
"will",
"return",
"a",
"node",
"with",
"the",
"symbol",
"as",
"a",
"function",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L252-L255 |
boriel/zxbasic | zxbparser.py | make_argument | def make_argument(expr, lineno, byref=None):
""" Wrapper: Creates a node containing an ARGUMENT
"""
if expr is None:
return # There were a syntax / semantic error
if byref is None:
byref = OPTIONS.byref.value
return symbols.ARGUMENT(expr, lineno=lineno, byref=byref) | python | def make_argument(expr, lineno, byref=None):
""" Wrapper: Creates a node containing an ARGUMENT
"""
if expr is None:
return # There were a syntax / semantic error
if byref is None:
byref = OPTIONS.byref.value
return symbols.ARGUMENT(expr, lineno=lineno, byref=byref) | [
"def",
"make_argument",
"(",
"expr",
",",
"lineno",
",",
"byref",
"=",
"None",
")",
":",
"if",
"expr",
"is",
"None",
":",
"return",
"# There were a syntax / semantic error",
"if",
"byref",
"is",
"None",
":",
"byref",
"=",
"OPTIONS",
".",
"byref",
".",
"val... | Wrapper: Creates a node containing an ARGUMENT | [
"Wrapper",
":",
"Creates",
"a",
"node",
"containing",
"an",
"ARGUMENT"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L264-L272 |
boriel/zxbasic | zxbparser.py | make_sub_call | def make_sub_call(id_, lineno, params):
""" This will return an AST node for a sub/procedure call.
"""
return symbols.CALL.make_node(id_, params, lineno) | python | def make_sub_call(id_, lineno, params):
""" This will return an AST node for a sub/procedure call.
"""
return symbols.CALL.make_node(id_, params, lineno) | [
"def",
"make_sub_call",
"(",
"id_",
",",
"lineno",
",",
"params",
")",
":",
"return",
"symbols",
".",
"CALL",
".",
"make_node",
"(",
"id_",
",",
"params",
",",
"lineno",
")"
] | This will return an AST node for a sub/procedure call. | [
"This",
"will",
"return",
"an",
"AST",
"node",
"for",
"a",
"sub",
"/",
"procedure",
"call",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L281-L284 |
boriel/zxbasic | zxbparser.py | make_func_call | def make_func_call(id_, lineno, params):
""" This will return an AST node for a function call.
"""
return symbols.FUNCCALL.make_node(id_, params, lineno) | python | def make_func_call(id_, lineno, params):
""" This will return an AST node for a function call.
"""
return symbols.FUNCCALL.make_node(id_, params, lineno) | [
"def",
"make_func_call",
"(",
"id_",
",",
"lineno",
",",
"params",
")",
":",
"return",
"symbols",
".",
"FUNCCALL",
".",
"make_node",
"(",
"id_",
",",
"params",
",",
"lineno",
")"
] | This will return an AST node for a function call. | [
"This",
"will",
"return",
"an",
"AST",
"node",
"for",
"a",
"function",
"call",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L287-L290 |
boriel/zxbasic | zxbparser.py | make_array_access | def make_array_access(id_, lineno, arglist):
""" Creates an array access. A(x1, x2, ..., xn).
This is an RVALUE (Read the element)
"""
return symbols.ARRAYACCESS.make_node(id_, arglist, lineno) | python | def make_array_access(id_, lineno, arglist):
""" Creates an array access. A(x1, x2, ..., xn).
This is an RVALUE (Read the element)
"""
return symbols.ARRAYACCESS.make_node(id_, arglist, lineno) | [
"def",
"make_array_access",
"(",
"id_",
",",
"lineno",
",",
"arglist",
")",
":",
"return",
"symbols",
".",
"ARRAYACCESS",
".",
"make_node",
"(",
"id_",
",",
"arglist",
",",
"lineno",
")"
] | Creates an array access. A(x1, x2, ..., xn).
This is an RVALUE (Read the element) | [
"Creates",
"an",
"array",
"access",
".",
"A",
"(",
"x1",
"x2",
"...",
"xn",
")",
".",
"This",
"is",
"an",
"RVALUE",
"(",
"Read",
"the",
"element",
")"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L293-L297 |
boriel/zxbasic | zxbparser.py | make_call | def make_call(id_, lineno, args):
""" This will return an AST node for a function call/array access.
A "call" is just an ID followed by a list of arguments.
E.g. a(4)
- a(4) can be a function call if 'a' is a function
- a(4) can be a string slice if a is a string variable: a$(4)
- a(4) can be a... | python | def make_call(id_, lineno, args):
""" This will return an AST node for a function call/array access.
A "call" is just an ID followed by a list of arguments.
E.g. a(4)
- a(4) can be a function call if 'a' is a function
- a(4) can be a string slice if a is a string variable: a$(4)
- a(4) can be a... | [
"def",
"make_call",
"(",
"id_",
",",
"lineno",
",",
"args",
")",
":",
"assert",
"isinstance",
"(",
"args",
",",
"symbols",
".",
"ARGLIST",
")",
"entry",
"=",
"SYMBOL_TABLE",
".",
"access_call",
"(",
"id_",
",",
"lineno",
")",
"if",
"entry",
"is",
"None... | This will return an AST node for a function call/array access.
A "call" is just an ID followed by a list of arguments.
E.g. a(4)
- a(4) can be a function call if 'a' is a function
- a(4) can be a string slice if a is a string variable: a$(4)
- a(4) can be an access to an array if a is an array
... | [
"This",
"will",
"return",
"an",
"AST",
"node",
"for",
"a",
"function",
"call",
"/",
"array",
"access",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L331-L379 |
boriel/zxbasic | zxbparser.py | make_type | def make_type(typename, lineno, implicit=False):
""" Converts a typename identifier (e.g. 'float') to
its internal symbol table entry representation.
Creates a type usage symbol stored in a AST
E.g. DIM a As Integer
will access Integer type
"""
assert isinstance(typename, str)
if not SY... | python | def make_type(typename, lineno, implicit=False):
""" Converts a typename identifier (e.g. 'float') to
its internal symbol table entry representation.
Creates a type usage symbol stored in a AST
E.g. DIM a As Integer
will access Integer type
"""
assert isinstance(typename, str)
if not SY... | [
"def",
"make_type",
"(",
"typename",
",",
"lineno",
",",
"implicit",
"=",
"False",
")",
":",
"assert",
"isinstance",
"(",
"typename",
",",
"str",
")",
"if",
"not",
"SYMBOL_TABLE",
".",
"check_is_declared",
"(",
"typename",
",",
"lineno",
",",
"'type'",
")"... | Converts a typename identifier (e.g. 'float') to
its internal symbol table entry representation.
Creates a type usage symbol stored in a AST
E.g. DIM a As Integer
will access Integer type | [
"Converts",
"a",
"typename",
"identifier",
"(",
"e",
".",
"g",
".",
"float",
")",
"to",
"its",
"internal",
"symbol",
"table",
"entry",
"representation",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L388-L401 |
boriel/zxbasic | zxbparser.py | make_bound | def make_bound(lower, upper, lineno):
""" Wrapper: Creates an array bound
"""
return symbols.BOUND.make_node(lower, upper, lineno) | python | def make_bound(lower, upper, lineno):
""" Wrapper: Creates an array bound
"""
return symbols.BOUND.make_node(lower, upper, lineno) | [
"def",
"make_bound",
"(",
"lower",
",",
"upper",
",",
"lineno",
")",
":",
"return",
"symbols",
".",
"BOUND",
".",
"make_node",
"(",
"lower",
",",
"upper",
",",
"lineno",
")"
] | Wrapper: Creates an array bound | [
"Wrapper",
":",
"Creates",
"an",
"array",
"bound"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L404-L407 |
boriel/zxbasic | zxbparser.py | make_label | def make_label(id_, lineno):
""" Creates a label entry. Returns None on error.
"""
entry = SYMBOL_TABLE.declare_label(id_, lineno)
if entry:
gl.DATA_LABELS[id_] = gl.DATA_PTR_CURRENT # This label points to the current DATA block index
return entry | python | def make_label(id_, lineno):
""" Creates a label entry. Returns None on error.
"""
entry = SYMBOL_TABLE.declare_label(id_, lineno)
if entry:
gl.DATA_LABELS[id_] = gl.DATA_PTR_CURRENT # This label points to the current DATA block index
return entry | [
"def",
"make_label",
"(",
"id_",
",",
"lineno",
")",
":",
"entry",
"=",
"SYMBOL_TABLE",
".",
"declare_label",
"(",
"id_",
",",
"lineno",
")",
"if",
"entry",
":",
"gl",
".",
"DATA_LABELS",
"[",
"id_",
"]",
"=",
"gl",
".",
"DATA_PTR_CURRENT",
"# This label... | Creates a label entry. Returns None on error. | [
"Creates",
"a",
"label",
"entry",
".",
"Returns",
"None",
"on",
"error",
"."
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L416-L422 |
boriel/zxbasic | zxbparser.py | make_break | def make_break(lineno, p):
""" Checks if --enable-break is set, and if so, calls
BREAK keyboard interruption for this line if it has not been already
checked """
global last_brk_linenum
if not OPTIONS.enableBreak.value or lineno == last_brk_linenum or is_null(p):
return None
last_brk_l... | python | def make_break(lineno, p):
""" Checks if --enable-break is set, and if so, calls
BREAK keyboard interruption for this line if it has not been already
checked """
global last_brk_linenum
if not OPTIONS.enableBreak.value or lineno == last_brk_linenum or is_null(p):
return None
last_brk_l... | [
"def",
"make_break",
"(",
"lineno",
",",
"p",
")",
":",
"global",
"last_brk_linenum",
"if",
"not",
"OPTIONS",
".",
"enableBreak",
".",
"value",
"or",
"lineno",
"==",
"last_brk_linenum",
"or",
"is_null",
"(",
"p",
")",
":",
"return",
"None",
"last_brk_linenum... | Checks if --enable-break is set, and if so, calls
BREAK keyboard interruption for this line if it has not been already
checked | [
"Checks",
"if",
"--",
"enable",
"-",
"break",
"is",
"set",
"and",
"if",
"so",
"calls",
"BREAK",
"keyboard",
"interruption",
"for",
"this",
"line",
"if",
"it",
"has",
"not",
"been",
"already",
"checked"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L425-L435 |
boriel/zxbasic | zxbparser.py | p_start | def p_start(p):
""" start : program
"""
global ast, data_ast
user_data = make_label('.ZXBASIC_USER_DATA', 0)
make_label('.ZXBASIC_USER_DATA_LEN', 0)
if PRINT_IS_USED:
zxbpp.ID_TABLE.define('___PRINT_IS_USED___', 1)
# zxbasmpp.ID_TABLE.define('___PRINT_IS_USED___', 1)
if zx... | python | def p_start(p):
""" start : program
"""
global ast, data_ast
user_data = make_label('.ZXBASIC_USER_DATA', 0)
make_label('.ZXBASIC_USER_DATA_LEN', 0)
if PRINT_IS_USED:
zxbpp.ID_TABLE.define('___PRINT_IS_USED___', 1)
# zxbasmpp.ID_TABLE.define('___PRINT_IS_USED___', 1)
if zx... | [
"def",
"p_start",
"(",
"p",
")",
":",
"global",
"ast",
",",
"data_ast",
"user_data",
"=",
"make_label",
"(",
"'.ZXBASIC_USER_DATA'",
",",
"0",
")",
"make_label",
"(",
"'.ZXBASIC_USER_DATA_LEN'",
",",
"0",
")",
"if",
"PRINT_IS_USED",
":",
"zxbpp",
".",
"ID_TA... | start : program | [
"start",
":",
"program"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L468-L515 |
boriel/zxbasic | zxbparser.py | p_program | def p_program(p):
""" program : program program_line
"""
p[0] = make_block(p[1], p[2], make_break(p.lineno(2), p[2])) | python | def p_program(p):
""" program : program program_line
"""
p[0] = make_block(p[1], p[2], make_break(p.lineno(2), p[2])) | [
"def",
"p_program",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"make_block",
"(",
"p",
"[",
"1",
"]",
",",
"p",
"[",
"2",
"]",
",",
"make_break",
"(",
"p",
".",
"lineno",
"(",
"2",
")",
",",
"p",
"[",
"2",
"]",
")",
")"
] | program : program program_line | [
"program",
":",
"program",
"program_line"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L524-L527 |
boriel/zxbasic | zxbparser.py | p_statements_statement | def p_statements_statement(p):
""" statements : statement
| statements_co statement
"""
if len(p) == 2:
p[0] = make_block(p[1])
else:
p[0] = make_block(p[1], p[2]) | python | def p_statements_statement(p):
""" statements : statement
| statements_co statement
"""
if len(p) == 2:
p[0] = make_block(p[1])
else:
p[0] = make_block(p[1], p[2]) | [
"def",
"p_statements_statement",
"(",
"p",
")",
":",
"if",
"len",
"(",
"p",
")",
"==",
"2",
":",
"p",
"[",
"0",
"]",
"=",
"make_block",
"(",
"p",
"[",
"1",
"]",
")",
"else",
":",
"p",
"[",
"0",
"]",
"=",
"make_block",
"(",
"p",
"[",
"1",
"]... | statements : statement
| statements_co statement | [
"statements",
":",
"statement",
"|",
"statements_co",
"statement"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L563-L570 |
boriel/zxbasic | zxbparser.py | p_program_line_label | def p_program_line_label(p):
""" label_line : LABEL statements
| LABEL co_statements
"""
lbl = make_label(p[1], p.lineno(1))
p[0] = make_block(lbl, p[2]) if len(p) == 3 else lbl | python | def p_program_line_label(p):
""" label_line : LABEL statements
| LABEL co_statements
"""
lbl = make_label(p[1], p.lineno(1))
p[0] = make_block(lbl, p[2]) if len(p) == 3 else lbl | [
"def",
"p_program_line_label",
"(",
"p",
")",
":",
"lbl",
"=",
"make_label",
"(",
"p",
"[",
"1",
"]",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")",
"p",
"[",
"0",
"]",
"=",
"make_block",
"(",
"lbl",
",",
"p",
"[",
"2",
"]",
")",
"if",
"len",
... | label_line : LABEL statements
| LABEL co_statements | [
"label_line",
":",
"LABEL",
"statements",
"|",
"LABEL",
"co_statements"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L579-L584 |
boriel/zxbasic | zxbparser.py | p_label_line_co | def p_label_line_co(p):
""" label_line_co : LABEL statements_co
| LABEL co_statements_co
| LABEL
"""
lbl = make_label(p[1], p.lineno(1))
p[0] = make_block(lbl, p[2]) if len(p) == 3 else lbl | python | def p_label_line_co(p):
""" label_line_co : LABEL statements_co
| LABEL co_statements_co
| LABEL
"""
lbl = make_label(p[1], p.lineno(1))
p[0] = make_block(lbl, p[2]) if len(p) == 3 else lbl | [
"def",
"p_label_line_co",
"(",
"p",
")",
":",
"lbl",
"=",
"make_label",
"(",
"p",
"[",
"1",
"]",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")",
"p",
"[",
"0",
"]",
"=",
"make_block",
"(",
"lbl",
",",
"p",
"[",
"2",
"]",
")",
"if",
"len",
"(",... | label_line_co : LABEL statements_co
| LABEL co_statements_co
| LABEL | [
"label_line_co",
":",
"LABEL",
"statements_co",
"|",
"LABEL",
"co_statements_co",
"|",
"LABEL"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L593-L599 |
boriel/zxbasic | zxbparser.py | p_var_decl | def p_var_decl(p):
""" var_decl : DIM idlist typedef
"""
for vardata in p[2]:
SYMBOL_TABLE.declare_variable(vardata[0], vardata[1], p[3])
p[0] = None | python | def p_var_decl(p):
""" var_decl : DIM idlist typedef
"""
for vardata in p[2]:
SYMBOL_TABLE.declare_variable(vardata[0], vardata[1], p[3])
p[0] = None | [
"def",
"p_var_decl",
"(",
"p",
")",
":",
"for",
"vardata",
"in",
"p",
"[",
"2",
"]",
":",
"SYMBOL_TABLE",
".",
"declare_variable",
"(",
"vardata",
"[",
"0",
"]",
",",
"vardata",
"[",
"1",
"]",
",",
"p",
"[",
"3",
"]",
")",
"p",
"[",
"0",
"]",
... | var_decl : DIM idlist typedef | [
"var_decl",
":",
"DIM",
"idlist",
"typedef"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L611-L617 |
boriel/zxbasic | zxbparser.py | p_var_decl_at | def p_var_decl_at(p):
""" var_decl : DIM idlist typedef AT expr
"""
p[0] = None
if len(p[2]) != 1:
syntax_error(p.lineno(1),
'Only one variable at a time can be declared this way')
return
idlist = p[2][0]
entry = SYMBOL_TABLE.declare_variable(idlist[0], id... | python | def p_var_decl_at(p):
""" var_decl : DIM idlist typedef AT expr
"""
p[0] = None
if len(p[2]) != 1:
syntax_error(p.lineno(1),
'Only one variable at a time can be declared this way')
return
idlist = p[2][0]
entry = SYMBOL_TABLE.declare_variable(idlist[0], id... | [
"def",
"p_var_decl_at",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"None",
"if",
"len",
"(",
"p",
"[",
"2",
"]",
")",
"!=",
"1",
":",
"syntax_error",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"'Only one variable at a time can be declared this way'... | var_decl : DIM idlist typedef AT expr | [
"var_decl",
":",
"DIM",
"idlist",
"typedef",
"AT",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L620-L659 |
boriel/zxbasic | zxbparser.py | p_var_decl_ini | def p_var_decl_ini(p):
""" var_decl : DIM idlist typedef EQ expr
| CONST idlist typedef EQ expr
"""
p[0] = None
if len(p[2]) != 1:
syntax_error(p.lineno(1),
"Initialized variables must be declared one by one.")
return
if p[5] is None:
re... | python | def p_var_decl_ini(p):
""" var_decl : DIM idlist typedef EQ expr
| CONST idlist typedef EQ expr
"""
p[0] = None
if len(p[2]) != 1:
syntax_error(p.lineno(1),
"Initialized variables must be declared one by one.")
return
if p[5] is None:
re... | [
"def",
"p_var_decl_ini",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"None",
"if",
"len",
"(",
"p",
"[",
"2",
"]",
")",
"!=",
"1",
":",
"syntax_error",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"\"Initialized variables must be declared one by one.\... | var_decl : DIM idlist typedef EQ expr
| CONST idlist typedef EQ expr | [
"var_decl",
":",
"DIM",
"idlist",
"typedef",
"EQ",
"expr",
"|",
"CONST",
"idlist",
"typedef",
"EQ",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L662-L693 |
boriel/zxbasic | zxbparser.py | p_decl_arr | def p_decl_arr(p):
""" var_arr_decl : DIM idlist LP bound_list RP typedef
"""
if len(p[2]) != 1:
syntax_error(p.lineno(1), "Array declaration only allows one variable name at a time")
else:
id_, lineno = p[2][0]
SYMBOL_TABLE.declare_array(id_, lineno, p[6], p[4])
p[0] = p[2][... | python | def p_decl_arr(p):
""" var_arr_decl : DIM idlist LP bound_list RP typedef
"""
if len(p[2]) != 1:
syntax_error(p.lineno(1), "Array declaration only allows one variable name at a time")
else:
id_, lineno = p[2][0]
SYMBOL_TABLE.declare_array(id_, lineno, p[6], p[4])
p[0] = p[2][... | [
"def",
"p_decl_arr",
"(",
"p",
")",
":",
"if",
"len",
"(",
"p",
"[",
"2",
"]",
")",
"!=",
"1",
":",
"syntax_error",
"(",
"p",
".",
"lineno",
"(",
"1",
")",
",",
"\"Array declaration only allows one variable name at a time\"",
")",
"else",
":",
"id_",
","... | var_arr_decl : DIM idlist LP bound_list RP typedef | [
"var_arr_decl",
":",
"DIM",
"idlist",
"LP",
"bound_list",
"RP",
"typedef"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L716-L724 |
boriel/zxbasic | zxbparser.py | p_arr_decl_initialized | def p_arr_decl_initialized(p):
""" var_arr_decl : DIM idlist LP bound_list RP typedef RIGHTARROW const_vector
| DIM idlist LP bound_list RP typedef EQ const_vector
"""
def check_bound(boundlist, remaining):
""" Checks if constant vector bounds matches the array one
"""
... | python | def p_arr_decl_initialized(p):
""" var_arr_decl : DIM idlist LP bound_list RP typedef RIGHTARROW const_vector
| DIM idlist LP bound_list RP typedef EQ const_vector
"""
def check_bound(boundlist, remaining):
""" Checks if constant vector bounds matches the array one
"""
... | [
"def",
"p_arr_decl_initialized",
"(",
"p",
")",
":",
"def",
"check_bound",
"(",
"boundlist",
",",
"remaining",
")",
":",
"\"\"\" Checks if constant vector bounds matches the array one\n \"\"\"",
"lineno",
"=",
"p",
".",
"lineno",
"(",
"8",
")",
"if",
"not",
"... | var_arr_decl : DIM idlist LP bound_list RP typedef RIGHTARROW const_vector
| DIM idlist LP bound_list RP typedef EQ const_vector | [
"var_arr_decl",
":",
"DIM",
"idlist",
"LP",
"bound_list",
"RP",
"typedef",
"RIGHTARROW",
"const_vector",
"|",
"DIM",
"idlist",
"LP",
"bound_list",
"RP",
"typedef",
"EQ",
"const_vector"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L727-L765 |
boriel/zxbasic | zxbparser.py | p_bound | def p_bound(p):
""" bound : expr
"""
p[0] = make_bound(make_number(OPTIONS.array_base.value,
lineno=p.lineno(1)), p[1], p.lexer.lineno) | python | def p_bound(p):
""" bound : expr
"""
p[0] = make_bound(make_number(OPTIONS.array_base.value,
lineno=p.lineno(1)), p[1], p.lexer.lineno) | [
"def",
"p_bound",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"make_bound",
"(",
"make_number",
"(",
"OPTIONS",
".",
"array_base",
".",
"value",
",",
"lineno",
"=",
"p",
".",
"lineno",
"(",
"1",
")",
")",
",",
"p",
"[",
"1",
"]",
",",
"p",
"... | bound : expr | [
"bound",
":",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L780-L784 |
boriel/zxbasic | zxbparser.py | p_const_vector_elem_list | def p_const_vector_elem_list(p):
""" const_number_list : expr
"""
if p[1] is None:
return
if not is_static(p[1]):
if isinstance(p[1], symbols.UNARY):
tmp = make_constexpr(p.lineno(1), p[1])
else:
api.errmsg.syntax_error_not_constant(p.lexer.lineno)
... | python | def p_const_vector_elem_list(p):
""" const_number_list : expr
"""
if p[1] is None:
return
if not is_static(p[1]):
if isinstance(p[1], symbols.UNARY):
tmp = make_constexpr(p.lineno(1), p[1])
else:
api.errmsg.syntax_error_not_constant(p.lexer.lineno)
... | [
"def",
"p_const_vector_elem_list",
"(",
"p",
")",
":",
"if",
"p",
"[",
"1",
"]",
"is",
"None",
":",
"return",
"if",
"not",
"is_static",
"(",
"p",
"[",
"1",
"]",
")",
":",
"if",
"isinstance",
"(",
"p",
"[",
"1",
"]",
",",
"symbols",
".",
"UNARY",
... | const_number_list : expr | [
"const_number_list",
":",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L800-L816 |
boriel/zxbasic | zxbparser.py | p_const_vector_elem_list_list | def p_const_vector_elem_list_list(p):
""" const_number_list : const_number_list COMMA expr
"""
if p[1] is None or p[3] is None:
return
if not is_static(p[3]):
if isinstance(p[3], symbols.UNARY):
tmp = make_constexpr(p.lineno(2), p[3])
else:
api.errmsg.syn... | python | def p_const_vector_elem_list_list(p):
""" const_number_list : const_number_list COMMA expr
"""
if p[1] is None or p[3] is None:
return
if not is_static(p[3]):
if isinstance(p[3], symbols.UNARY):
tmp = make_constexpr(p.lineno(2), p[3])
else:
api.errmsg.syn... | [
"def",
"p_const_vector_elem_list_list",
"(",
"p",
")",
":",
"if",
"p",
"[",
"1",
"]",
"is",
"None",
"or",
"p",
"[",
"3",
"]",
"is",
"None",
":",
"return",
"if",
"not",
"is_static",
"(",
"p",
"[",
"3",
"]",
")",
":",
"if",
"isinstance",
"(",
"p",
... | const_number_list : const_number_list COMMA expr | [
"const_number_list",
":",
"const_number_list",
"COMMA",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L819-L837 |
boriel/zxbasic | zxbparser.py | p_const_vector_vector_list | def p_const_vector_vector_list(p):
""" const_vector_list : const_vector_list COMMA const_vector
"""
if len(p[3]) != len(p[1][0]):
syntax_error(p.lineno(2), 'All rows must have the same number of elements')
p[0] = None
return
p[0] = p[1] + [p[3]] | python | def p_const_vector_vector_list(p):
""" const_vector_list : const_vector_list COMMA const_vector
"""
if len(p[3]) != len(p[1][0]):
syntax_error(p.lineno(2), 'All rows must have the same number of elements')
p[0] = None
return
p[0] = p[1] + [p[3]] | [
"def",
"p_const_vector_vector_list",
"(",
"p",
")",
":",
"if",
"len",
"(",
"p",
"[",
"3",
"]",
")",
"!=",
"len",
"(",
"p",
"[",
"1",
"]",
"[",
"0",
"]",
")",
":",
"syntax_error",
"(",
"p",
".",
"lineno",
"(",
"2",
")",
",",
"'All rows must have t... | const_vector_list : const_vector_list COMMA const_vector | [
"const_vector_list",
":",
"const_vector_list",
"COMMA",
"const_vector"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L846-L854 |
boriel/zxbasic | zxbparser.py | p_statement_border | def p_statement_border(p):
""" statement : BORDER expr
"""
p[0] = make_sentence('BORDER',
make_typecast(TYPE.ubyte, p[2], p.lineno(1))) | python | def p_statement_border(p):
""" statement : BORDER expr
"""
p[0] = make_sentence('BORDER',
make_typecast(TYPE.ubyte, p[2], p.lineno(1))) | [
"def",
"p_statement_border",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"make_sentence",
"(",
"'BORDER'",
",",
"make_typecast",
"(",
"TYPE",
".",
"ubyte",
",",
"p",
"[",
"2",
"]",
",",
"p",
".",
"lineno",
"(",
"1",
")",
")",
")"
] | statement : BORDER expr | [
"statement",
":",
"BORDER",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L863-L867 |
boriel/zxbasic | zxbparser.py | p_statement_plot | def p_statement_plot(p):
""" statement : PLOT expr COMMA expr
"""
p[0] = make_sentence('PLOT',
make_typecast(TYPE.ubyte, p[2], p.lineno(3)),
make_typecast(TYPE.ubyte, p[4], p.lineno(3))) | python | def p_statement_plot(p):
""" statement : PLOT expr COMMA expr
"""
p[0] = make_sentence('PLOT',
make_typecast(TYPE.ubyte, p[2], p.lineno(3)),
make_typecast(TYPE.ubyte, p[4], p.lineno(3))) | [
"def",
"p_statement_plot",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"make_sentence",
"(",
"'PLOT'",
",",
"make_typecast",
"(",
"TYPE",
".",
"ubyte",
",",
"p",
"[",
"2",
"]",
",",
"p",
".",
"lineno",
"(",
"3",
")",
")",
",",
"make_typecast",
"... | statement : PLOT expr COMMA expr | [
"statement",
":",
"PLOT",
"expr",
"COMMA",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L870-L875 |
boriel/zxbasic | zxbparser.py | p_statement_plot_attr | def p_statement_plot_attr(p):
""" statement : PLOT attr_list expr COMMA expr
"""
p[0] = make_sentence('PLOT',
make_typecast(TYPE.ubyte, p[3], p.lineno(4)),
make_typecast(TYPE.ubyte, p[5], p.lineno(4)), p[2]) | python | def p_statement_plot_attr(p):
""" statement : PLOT attr_list expr COMMA expr
"""
p[0] = make_sentence('PLOT',
make_typecast(TYPE.ubyte, p[3], p.lineno(4)),
make_typecast(TYPE.ubyte, p[5], p.lineno(4)), p[2]) | [
"def",
"p_statement_plot_attr",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"make_sentence",
"(",
"'PLOT'",
",",
"make_typecast",
"(",
"TYPE",
".",
"ubyte",
",",
"p",
"[",
"3",
"]",
",",
"p",
".",
"lineno",
"(",
"4",
")",
")",
",",
"make_typecast"... | statement : PLOT attr_list expr COMMA expr | [
"statement",
":",
"PLOT",
"attr_list",
"expr",
"COMMA",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L878-L883 |
boriel/zxbasic | zxbparser.py | p_statement_draw3 | def p_statement_draw3(p):
""" statement : DRAW expr COMMA expr COMMA expr
"""
p[0] = make_sentence('DRAW3',
make_typecast(TYPE.integer, p[2], p.lineno(3)),
make_typecast(TYPE.integer, p[4], p.lineno(5)),
make_typecast(TYPE.float_, p[... | python | def p_statement_draw3(p):
""" statement : DRAW expr COMMA expr COMMA expr
"""
p[0] = make_sentence('DRAW3',
make_typecast(TYPE.integer, p[2], p.lineno(3)),
make_typecast(TYPE.integer, p[4], p.lineno(5)),
make_typecast(TYPE.float_, p[... | [
"def",
"p_statement_draw3",
"(",
"p",
")",
":",
"p",
"[",
"0",
"]",
"=",
"make_sentence",
"(",
"'DRAW3'",
",",
"make_typecast",
"(",
"TYPE",
".",
"integer",
",",
"p",
"[",
"2",
"]",
",",
"p",
".",
"lineno",
"(",
"3",
")",
")",
",",
"make_typecast",... | statement : DRAW expr COMMA expr COMMA expr | [
"statement",
":",
"DRAW",
"expr",
"COMMA",
"expr",
"COMMA",
"expr"
] | train | https://github.com/boriel/zxbasic/blob/23b28db10e41117805bdb3c0f78543590853b132/zxbparser.py#L886-L892 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.