def assign(self):
from .parser import (
make_setter,
)
# Assignment (eg. x[4] = y)
if len(self.stmt.targets) != 1:
raise StructureException("Assignment statement must have one target", self.stmt)
sub = Expr(self.stmt.value, self.context).lll_node
if isinstance(self.stmt.targets[0], ast.Name) and self.stmt.targets[0].id not in self.context.vars:
pos = self.context.new_variable(self.stmt.targets[0].id, set_default_units(sub.typ))
variable_loc = LLLnode.from_list(pos, typ=sub.typ, location='memory', pos=getpos(self.stmt), annotation=self.stmt.targets[0].id)
o = make_setter(variable_loc, sub, 'memory', pos=getpos(self.stmt))
else:
# Checks to see if assignment is valid
target = self.get_target(self.stmt.targets[0])
o = make_setter(target, sub, target.location, pos=getpos(self.stmt))
o.pos = getpos(self.stmt)
return o
评论列表
文章目录