repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_documentation_string stringlengths 1 47.2k | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|
boriel/zxbasic | 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 | Initializes global memory array with the given one | 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... | Cleans up initial memory. Each label must be
ALONE. Each instruction must have an space, etc... | 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... | Traverses memory, to make any local label a unique
global one. At this point there's only a single code
block | 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... | This will remove useless instructions | 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... | Initial state | 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 | Resets flags to an "unknown state" | 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_... | Returns precomputed value of the given expression | 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 | Like the above, but returns the <int> value. | 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... | True if values of r1 and r2 registers are equal | 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))
... | Does inc on the register and precomputes flags | 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)) | Does a ROTATION to the RIGHT |>> | 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
... | Like the above, bus uses carry | 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)) | Does a ROTATION to the LEFT <<| | 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
... | Like the above, bus uses carry | 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:
... | True if value of r is val. | 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... | Tries to update the registers values with the given
instruction. | 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... | Returns a list of operators this mnemonic uses | 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... | 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... | 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... | Returns the registers, operands, etc. required by an instruction. | 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 | Returns if this instruction affects any of the registers
in reglist. | 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 | Returns if this instruction need any of the registers
in reglist. | 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=... | Returns a list of required labels for this instruction | 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:])
... | Replaces old label with a new one | 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... | Returns if this block can be partitiones in 2 or more blocks,
because if contains enders. | 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
... | 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. | 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... | This simulates a set. Adds the basic_block to the comes_from
list if not done already. | 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:
... | 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 | 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 ... | 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() | 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:
... | Checks whether any of the given regs are required from the given point
to the end or not. | 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 ... | 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... | 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
... | 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 | 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... | Returns a list of registers this block destroys
By default checks from the beginning (i = 0). | 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] | Swaps mem positions a and b | 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):
... | Returns whether any of the goes_to block requires any of
the given registers. | 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 | Returns the index of a label.
Returns None if not found. | 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 | Returns the memcell of the given block, which is
not a LABEL. | 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... | Tries to detect peep-hole patterns in this basic block
and remove them. | 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... | 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. | 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... | Outputs a FREEMEM sequence for 1 or 2 ops | 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 | Compares & pops top 2 strings out of the stack.
Temporal values are freed from memory. (a$ != b$) | 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 | Returns string length | 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).
... | 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... | 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_... | 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 | 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... | 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 ... | 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... | 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... | 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... | 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 | 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... | 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 | 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... | 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 | 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... | 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 | 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... | 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 | 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... | 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 | 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') # ... | 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 | 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... | 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 | 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')... | 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 | 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... | 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 | 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... | 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 | 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... | 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 | 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 | Negates (Logical NOT) top of the stack (8 bits in AF) | 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 | Negates (BITWISE NOT) top of the stack (8 bits in AF) | 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 | Negates top of the stack (8 bits in AF) | 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 | Absolute value of top of the stack (8 bits in AF) | 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)
... | 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 | 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_) | True if this macro has been defined | 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:
... | Creates an array BOUND LIST. | 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
... | Initializes parser state | 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) | Wrapper: creates a constant number node. | 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) | Wrapper: returns a Typecast node | 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_) | Wrapper: returns a Binary node | 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_) | Wrapper: returns a Unary node | 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... | Wrapper: returns a Builtin function node.
Can be a Symbol, tuple or list of Symbols
If operand is an iterable, they will be expanded. | 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) | Wrapper: returns String Slice node | 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) | Wrapper: returns a Sentence node | 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_) | This will return a node with the symbol as a function. | 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) | Wrapper: Creates a node containing an ARGUMENT | 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) | This will return an AST node for a sub/procedure call. | 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) | This will return an AST node for a function call. | 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) | Creates an array access. A(x1, x2, ..., xn).
This is an RVALUE (Read the element) | 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... | 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
... | 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... | 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 | 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) | Wrapper: Creates an array bound | 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 | Creates a label entry. Returns None on error. | 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... | Checks if --enable-break is set, and if so, calls
BREAK keyboard interruption for this line if it has not been already
checked | 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... | start : program | 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])) | program : program program_line | 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]) | statements : statement
| statements_co statement | 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 | label_line : LABEL statements
| LABEL co_statements | 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 | label_line_co : LABEL statements_co
| LABEL co_statements_co
| LABEL | 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 | var_decl : DIM idlist typedef | 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... | var_decl : DIM idlist typedef AT expr | 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... | var_decl : DIM idlist typedef EQ expr
| CONST idlist typedef EQ expr | 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][... | var_arr_decl : DIM idlist LP bound_list RP typedef | 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
"""
... | var_arr_decl : DIM idlist LP bound_list RP typedef RIGHTARROW const_vector
| DIM idlist LP bound_list RP typedef EQ const_vector | 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) | bound : expr | 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)
... | const_number_list : expr | 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... | const_number_list : const_number_list COMMA expr | 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]] | const_vector_list : const_vector_list COMMA const_vector | 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))) | statement : BORDER expr | 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))) | statement : PLOT expr COMMA expr | 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]) | statement : PLOT attr_list expr COMMA expr | 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[... | statement : DRAW expr COMMA expr COMMA expr | 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.