def _found(self, name, symbol): self.table[name] = symbol return symbol class ForLoopBlockSymbolTable(BlockSymbolTable): def get_loopvar(self, n=0): return self.parent.get_loopvar(n + 1) class Environment(BaseEnvironment): FIELDS = ('filename', 'symtable') visit = Visitor() def nop(env, node): pass def default(env, node): for field in node._node_fields: if isinstance(getattr(node.__class__, field), NodeListField): for subnode in getattr(node, field): visit(env, subnode) else: visit(env, getattr(node, field))
"<goto {}> at line {:d} jumps into the scope of local '{}'" .format(name, goto.lineno, self.locals[nlocals])) def got_goto(self, goto): label = self.labels.get(goto.target, None) if label is None: self.gotos[goto] = len(self.locals) else: goto.label = label.label class Environment(BaseEnvironment): FIELDS = ('filename', 'label_table') visit = Visitor() def nop(env, node): pass def visit_topblock(env, node): label_table = LabelTable() for subnode in node.body: visit(env(label_table=label_table), subnode) label_table.close(True) return node
def got_goto(self, goto): label = self.labels.get(goto.target, None) if label is None: self.gotos[goto] = len(self.locals) else: goto.label = label.label class Environment(BaseEnvironment): FIELDS = ('filename', 'label_table') visit = Visitor() def nop(env, node): pass def visit_topblock(env, node): label_table = LabelTable() for subnode in node.body: visit(env(label_table=label_table), subnode) label_table.close(True) return node
class ForLoopBlockSymbolTable(BlockSymbolTable): def get_loopvar(self, n=0): return self.parent.get_loopvar(n+1) class Environment(BaseEnvironment): FIELDS = ('filename', 'symtable') visit = Visitor() def nop(env, node): pass def default(env, node): for field in node._node_fields: if isinstance(getattr(node.__class__, field), NodeListField): for subnode in getattr(node, field): visit(env, subnode) else: visit(env, getattr(node, field))
from . import ast from .asm import Assembly, Label from .runtime.builtins import to_number class Context(object): Load = object() Store = object() class Environment(BaseEnvironment): FIELDS = ('asm', 'stringtable', 'break_target', 'context', 'filename') visit = Visitor() def set_lineno(func): def wrapper(env, node): asm = getattr(env, "asm", None) if asm is not None: asm.set_lineno(node.lineno) return func(env, node) return wrapper def visit_function(env, name, node): argcount = len(node.args)