Beispiel #1
0
 def del_name(self, name, lineno=None):
     sym_tb = self.sym_tb
     if name in sym_tb.cellvars:
         self.bc.append(Instr('DELETE_DEREF', CellVar(name), lineno=lineno))
     elif name in sym_tb.freevars:
         self.bc.append(Instr('DELETE_DEREF', FreeVar(name), lineno=lineno))
     elif name in sym_tb.bounds:
         self.bc.append(Instr('DELETE_FAST', name, lineno=lineno))
     else:
         self.bc.append(Instr("DELETE_GLOBAL", name, lineno=lineno))
Beispiel #2
0
 def store_name(self, name, lineno=None):
     sym_tb = self.sym_tb
     if name in sym_tb.cellvars:
         self.bc.append(Instr('STORE_DEREF', CellVar(name), lineno=lineno))
     elif name in sym_tb.freevars:
         self.bc.append(Instr('STORE_DEREF', FreeVar(name), lineno=lineno))
     elif name in sym_tb.bounds:
         under_class = ContextType.ClassDef in self.cts
         self.bc.append(
             Instr('STORE_NAME' if under_class else 'STORE_FAST', name, lineno=lineno))
     else:
         self.bc.append(Instr("STORE_GLOBAL", name, lineno=lineno))
Beispiel #3
0
    def load_closure(self, lineno=None):
        parent = self.parent
        freevars = self.sym_tb.freevars
        cellvars = parent.sym_tb.cellvars

        for each in freevars:
            if each in cellvars:
                parent.bc.append(Instr('LOAD_CLOSURE', CellVar(each), lineno=lineno))
            else:
                assert each in freevars
                parent.bc.append(Instr('LOAD_CLOSURE', FreeVar(each), lineno=lineno))

        parent.bc.append(Instr('BUILD_TUPLE', len(freevars)))
Beispiel #4
0
 def del_name(self, name, lineno=None):
     sym_tb = self.sym_tb
     if name in sym_tb.cellvars:
         # TODO: no DELETE_CLASSDEREF?
         self.bc.append(Instr('DELETE_DEREF', CellVar(name), lineno=lineno))
     elif name in sym_tb.freevars:
         self.bc.append(Instr('DELETE_DEREF', FreeVar(name), lineno=lineno))
     elif name in sym_tb.bounds:
         under_class = ContextType.ClassDef in self.cts
         self.bc.append(
             Instr(
                 'DELETE_NAME' if under_class else 'DELETE_FAST', name, lineno=lineno))
     else:
         self.bc.append(Instr("DELETE_GLOBAL", name, lineno=lineno))
Beispiel #5
0
 def load_closure(self, lineno=None):
     parent = self.parent
     freevars = self.sym_tb.freevars
     if freevars:
         for each in self.sym_tb.freevars:
             if each in parent.sym_tb.cellvars:
                 parent.bc.append(
                     Instr('LOAD_CLOSURE', CellVar(each), lineno=lineno))
             elif each in parent.sym_tb.borrowed_cellvars:
                 parent.bc.append(
                     Instr('LOAD_CLOSURE', FreeVar(each), lineno=lineno))
             else:
                 raise RuntimeError
         parent.bc.append(Instr('BUILD_TUPLE', len(freevars)))
Beispiel #6
0
 def load_name(self, name, lineno=None):
     sym_tb = self.sym_tb
     under_class = ContextType.ClassDef in self.cts
     if name in sym_tb.cellvars:
         self.bc.append(
             Instr(
                 'LOAD_CLASSDEREF' if under_class else 'LOAD_DEREF',
                 CellVar(name),
                 lineno=lineno))
     elif name in sym_tb.freevars:
         self.bc.append(
             Instr(
                 'LOAD_CLASSDEREF' if under_class else 'LOAD_DEREF',
                 FreeVar(name),
                 lineno=lineno))
     elif name in sym_tb.bounds:
         self.bc.append(
             Instr('LOAD_NAME' if under_class else 'LOAD_FAST', name, lineno=lineno))
     else:
         self.bc.append(Instr("LOAD_GLOBAL", name, lineno=lineno))