def __setitem__(self, node, code):
self.__code[node] = code
- def transient(self, node,
+ def transient(self,
value="UINT64_C(0)",
bits="(uint8_t)OPPC_XLEN"):
transient = Transient(value=value, bits=bits)
self.traverse(root=transient)
return transient
- def call(self, node, name, code, stmt=False):
+ def call(self, name, code, stmt=False):
def validate(item):
def validate(item):
(level, stmt) = item
def fixup_ternary(self, node):
self[node].clear()
- test = self.call(name="oppc_bool", node=node, code=[
+ test = self.call(name="oppc_bool", code=[
self[node.test],
])
self[node].emit(stmt="(")
code[-1] = (level, stmt[:-1])
if not assign:
- call = self.call(name="oppc_attr", node=root, code=[
+ call = self.call(name="oppc_attr", code=[
code,
])
code = self[call]
return
if isinstance(node.lvalue, pc_ast.SubscriptExpr):
- call = self.call(name="oppc_subscript_assign", node=node, stmt=True, code=[
+ call = self.call(name="oppc_subscript_assign", stmt=True, code=[
self[node.lvalue.subject],
self[node.lvalue.index],
self[node.rvalue],
])
elif isinstance(node.lvalue, pc_ast.RangeSubscriptExpr):
- call = self.call(name="oppc_range_subscript_assign", node=node, stmt=True, code=[
+ call = self.call(name="oppc_range_subscript_assign", stmt=True, code=[
self[node.lvalue.subject],
self[node.lvalue.start],
self[node.lvalue.end],
self[node.rvalue],
])
elif isinstance(node.lvalue, pc_ast.Attribute):
- call = self.call(name="oppc_attr_assign", stmt=True, node=node, code=[
+ call = self.call(name="oppc_attr_assign", stmt=True, code=[
self[node.lvalue],
self[node.rvalue],
])
else:
- call = self.call(name="oppc_assign", stmt=True, node=node, code=[
+ call = self.call(name="oppc_assign", stmt=True, code=[
self[node.lvalue],
self[node.rvalue],
])
self.fixup_attr(node=node.right)
if isinstance(node.op, comparison):
- call = self.call(name=str(self[node.op]), node=node, code=[
+ call = self.call(name=str(self[node.op]), code=[
self[node.left],
self[node.right],
])
else:
- transient = self.transient(node=node)
- call = self.call(name=str(self[node.op]), node=node, code=[
+ transient = self.transient()
+ call = self.call(name=str(self[node.op]), code=[
self[transient],
self[node.left],
self[node.right],
yield node
if isinstance(node.value, pc_ast.IfExpr):
self.fixup_ternary(node=node.value)
- call = self.call(name=str(self[node.op]), node=node, code=[
+ call = self.call(name=str(self[node.op]), code=[
self[node.value],
])
with self.pseudocode(node=node):
if (value > ((2**64) - 1)):
raise NotImplementedError()
value = f"UINT64_C({fmt(value)})"
- transient = self.transient(node=node, value=value, bits=bits)
+ transient = self.transient(value=value, bits=bits)
with self.pseudocode(node=node):
for (level, stmt) in self[transient]:
self[node].emit(stmt=stmt, level=level)
@pc_util.Hook(pc_ast.RepeatExpr)
def RepeatExpr(self, node):
yield node
- transient = self.transient(node=node)
- call = self.call(name="oppc_repeat", node=node, code=[
+ transient = self.transient()
+ call = self.call(name="oppc_repeat", code=[
self[transient],
self[node.subject],
self[node.times],
def XLEN(self, node):
yield node
(value, bits) = ("OPPC_XLEN", "(uint8_t)OPPC_XLEN")
- transient = self.transient(node=node, value=value, bits=bits)
+ transient = self.transient(value=value, bits=bits)
with self.pseudocode(node=node):
for (level, stmt) in self[transient]:
self[node].emit(stmt=stmt, level=level)
@pc_util.Hook(pc_ast.SubscriptExpr)
def SubscriptExpr(self, node):
yield node
- call = self.call(name="oppc_subscript", node=node, code=[
+ call = self.call(name="oppc_subscript", code=[
self[node.subject],
self[node.index],
])
@pc_util.Hook(pc_ast.RangeSubscriptExpr)
def RangeSubscriptExpr(self, node):
yield node
- call = self.call(name="oppc_subscript", node=node, code=[
+ call = self.call(name="oppc_subscript", code=[
self[node.subject],
self[node.start],
self[node.end],
@pc_util.Hook(pc_ast.IfExpr)
def IfExpr(self, node):
yield node
- test = self.call(name="oppc_bool", node=node, code=[
+ test = self.call(name="oppc_bool", code=[
self[node.test],
])
self[node].emit(stmt="if (")
@pc_util.Hook(pc_ast.SwitchExpr)
def SwitchExpr(self, node):
yield node
- subject = self.call(name="oppc_int64", node=node, code=[
+ subject = self.call(name="oppc_int64", code=[
self[node.subject],
])
self[node].emit(stmt="switch (")
def Call(self, node):
yield node
code = tuple(map(lambda arg: self[arg], node.args))
- call = self.call(name=str(node.name), node=node, code=code)
+ call = self.call(name=str(node.name), code=code)
for (level, stmt) in self[call]:
self[node].emit(stmt=stmt, level=level)