def getattr(self, name): if name == u"doc": return self.doc elif name == u"loc": source, start, stop = self.source_location obj = space.Exnihilo() obj.setattr(u"source", space.String(source)) obj.setattr(u"start", space.Integer(start)) obj.setattr(u"stop", space.Integer(stop)) return obj elif name == u"spec": argc, optional, variadic, varnames, argtypes = self.spec varnames = [ space.String(name.decode('utf-8')) for name in varnames ] spec = space.Exnihilo() spec.setattr(u'argc', space.Integer(rffi.r_long(argc))) spec.setattr(u'optional', space.Integer(rffi.r_long(optional))) spec.setattr(u'is_variadic', space.boolean(variadic)) spec.setattr(u'varnames', space.List(list(varnames))) if argtypes is not None: spec.setattr(u'argtypes', space.List(list(argtypes))) else: spec.setattr(u'argtypes', space.null) return spec else: return Object.getattr(self, name)
def decode(stream): stream.skipspace() if stream.shift(u'{'): dct = space.Dict() if stream.shift(u'}'): return dct decode_pair(stream, dct) while stream.shift(u','): decode_pair(stream, dct) stream.skipspace() stream.skipspace() stream.expect(u'}') return dct if stream.shift(u'['): lst = [] if stream.shift(u']'): return space.List(lst) lst.append(decode(stream)) while stream.shift(u','): lst.append(decode(stream)) stream.skipspace() stream.skipspace() stream.expect(u']') return space.List(lst) if stream.get() == u'"': return decode_string(stream) if stream.shift(u'f'): stream.expect(u'a') stream.expect(u'l') stream.expect(u's') stream.expect(u'e') return space.false if stream.shift(u't'): stream.expect(u'r') stream.expect(u'u') stream.expect(u'e') return space.true if stream.shift(u'n'): stream.expect(u'u') stream.expect(u'l') stream.expect(u'l') return space.null if stream.shift(u'-'): sign = -1 else: sign = +1 num = digits(stream) if stream.shift(u'.'): num += u'.' + digits(stream) if stream.get() in u'eE': raise space.OldError(u"XXX") return space.Float(float(num.encode('utf-8'))) else: if stream.get() in u'eE': raise space.OldError(u"XXX") return space.Integer(sign*int(num.encode('utf-8'))) raise space.OldError(u"JSON decode error at %s" % stream.get())
def Multimethod_keys(self): out = [] for vec in self.multimethod_table: argt = [] for w in vec: item = w.weakref() if item is None: break argt.append(item) if len(argt) == len(vec): out.append(space.List(argt)) return space.List(out)
def excs_introspection(excs): out = [] for exc in excs: o = space.Exnihilo() o.setattr(u"start", space.Integer(rffi.r_long(exc.start))) o.setattr(u"stop", space.Integer(rffi.r_long(exc.stop))) o.setattr(u"label", space.Integer(rffi.r_long(exc.label))) o.setattr(u"reg", space.Integer(rffi.r_long(exc.reg))) out.append(o) return space.List(out)
def system_init(argv): module_src = argv[0] assert isinstance(module_src, space.String) module = space.Module(u'main', {}, extends=base.module) result = module_resolution.load_module(module_src.string.encode('utf-8'), module) try: main_func = module.getattr(u"main") except space.Error as error: pass else: result = main_func.call([space.List(argv)]) return space.null
def normal_startup(argv): if len(argv) > 0: main_script = argv[0] else: main_script = pathobj.concat(core.get_ec().lever_path, pathobj.parse(u"app/main.lc")) main_script = space.String(pathobj.os_stringify(main_script)) module = module_resolution.start(main_script) try: main_func = module.getattr(u"main") except space.Unwinder as unwinder: pass # in this case main_func just isn't in the module. else: main_func.call([space.List(argv)]) return space.null
def getitem(self, index): if isinstance(index, space.Slice): start, stop, step = index.clamped(0, self.length - 1) if step != 1: result = [] # TODO: keep it as Uint8Array? for i in range(start, stop, step): result.append( numbers.Integer(rffi.r_long(self.uint8data[i]))) return space.List(result) parent = self.parent if isinstance(self, Uint8Slice) else self return Uint8Slice(rffi.ptradd(self.uint8data, start), stop - start, parent) index = space.cast(index, numbers.Integer, u"index not an integer") if not 0 <= index.value < self.length: raise space.unwind(space.LKeyError(self, index)) return numbers.Integer(rffi.r_long(self.uint8data[index.value]))
def decode_json(action, ch, ctx): if action == 0x1: # push list ctx.ds.append(space.List([])) # Push object to ds elif action == 0x2: # push object ctx.ds.append(space.Dict()) elif action == 0x3: # pop & append val = ctx.ds.pop() top = ctx.ds[len(ctx.ds) - 1] assert isinstance(top, List) # we can trust this. top.contents.append(val) elif action == 0x4: # pop pop & setitem val = ctx.ds.pop() key = ctx.ds.pop() top = ctx.ds[len(ctx.ds) - 1] assert isinstance(top, Dict) # again.. top.data[key] = val elif action == 0x5: # push null ctx.ds.append(space.null) elif action == 0x6: # push true ctx.ds.append(space.true) elif action == 0x7: # push false ctx.ds.append(space.false) elif action == 0x8: # push string val = ctx.ss.build() ctx.ds.append(space.String(val)) ctx.ss = UnicodeBuilder() ctx.es = UnicodeBuilder() elif action == 0x9: val = int(ctx.ss.build().encode('utf-8')) # push int ctx.ds.append(space.Integer(val)) ctx.ss = UnicodeBuilder() elif action == 0xA: val = float(ctx.ss.build().encode('utf-8')) # push float ctx.ds.append(space.Float(val)) ctx.ss = UnicodeBuilder() elif action == 0xB: # push ch to ss ctx.ss.append(ch) elif action == 0xC: # push ch to es ctx.es.append(ch) elif action == 0xD: # push escape ctx.ss.append(unichr(escape_characters[ch])) elif action == 0xE: # push unicode point ctx.ss.append(unichr(int(ctx.es.build().encode('utf-8'), 16))) ctx.es = UnicodeBuilder() else: # This is very unlikely to happen. assert False, "JSON decoder bug"
def call(self, argv): varargs = self.function.flags & 1 == 1 argc = self.function.argc topc = self.function.topc L = len(argv) if L < argc: raise space.unwind(space.LCallError(argc, topc, varargs, L)) # We are using this trait. #if L > topc and not varargs: # raise space.Error(u"too many arguments [%d], from %d to %d arguments allowed" % (L, argc, topc)) frame = Frame(self.function, self.frame.module, self.frame) for i in range(min(topc, L)): frame.local[i] = argv[i] if varargs: frame.local[topc] = space.List(argv[min(topc, L):]) regv = new_register_array(self.function.regc) return interpret(0, self.function.block, regv, frame)
def create_frame(parent, function, argv): varargs = jit.promote(function.flags & 1 == 1) argc = function.argc topc = function.topc L = len(argv) if L < argc: # The pc=0 refers to the function itself. This entry # is really helpful when trying to determine the origin of a CallError. head_entry = TraceEntry(rffi.r_long(0), function.unit.sources, function.sourcemap, function.unit.path) unwinder = space.unwind(space.LCallError(argc, topc, varargs, L)) unwinder.traceback.contents.append(head_entry) raise unwinder # We are using this trait. #if L > topc and not varargs: # raise space.Error(u"too many arguments [%d], from %d to %d arguments allowed" % (L, argc, topc)) frame = Frame(function, parent.module, parent, function.regc) A = min(topc, L) for i in range(A): frame.store_local(i, argv[i]) if varargs: frame.store_local(topc, space.List(argv[A:])) return frame
def interpret(pc, block, regv, frame): module = jit.promote(frame.module) unit = jit.promote(frame.unit) excs = jit.promote(frame.excs) try: while pc < len(block): try: jitdriver.jit_merge_point(pc=pc, block=block, module=module, unit=unit, excs=excs, regv=regv, frame=frame) opcode = rffi.r_ulong(block[pc]) >> 8 ix = pc + 1 pc = ix + (rffi.r_ulong(block[pc]) & 255) if opcode == opcode_of('assert'): obj = regv.load(block[ix + 0]) raise space.unwind(space.LAssertionError(obj)) elif opcode == opcode_of('raise'): obj = regv.load(block[ix + 0]) traceback = obj.getattr(u"traceback") if traceback is space.null: traceback = space.List([]) obj.setattr(u"traceback", traceback) elif not isinstance(traceback, space.List): raise space.unwind( space.LError( u"Expected null or list as .traceback: %s" % obj.repr())) raise space.Unwinder(obj, traceback) elif opcode == opcode_of('constant'): regv.store(block[ix + 0], unit.constants[block[ix + 1]]) elif opcode == opcode_of('list'): contents = [] for i in range(ix + 1, pc): contents.append(regv.load(block[i])) regv.store(block[ix], space.List(contents)) elif opcode == opcode_of('move'): regv.store(block[ix + 0], regv.load(block[ix + 1])) elif opcode == opcode_of('call'): op_call(regv, block, ix, pc) elif opcode == opcode_of('callv'): op_callv(regv, block, ix, pc) elif opcode == opcode_of('return'): return regv.load(block[ix + 0]) elif opcode == opcode_of('jump'): pc = rffi.r_ulong(block[ix + 0]) elif opcode == opcode_of('cond'): if space.is_false(regv.load(block[ix + 0])): pc = rffi.r_ulong(block[ix + 2]) else: pc = rffi.r_ulong(block[ix + 1]) elif opcode == opcode_of('func'): regv.store(block[ix + 0], Closure(frame, unit.functions[block[ix + 1]])) elif opcode == opcode_of('iter'): regv.store(block[ix + 0], regv.load(block[ix + 1]).iter()) elif opcode == opcode_of('next'): try: regv.store( block[ix + 0], regv.load(block[ix + 1]).callattr(u'next', [])) except StopIteration as _: pc = rffi.r_ulong(block[ix + 2]) # this is missing. #elif isinstance(op, Yield): # raise YieldIteration(op.block, loop_break, op.i, regv.load(op.value.i)) elif opcode == opcode_of('getattr'): name = get_string(unit, block, ix + 2) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.getattr(name)) elif opcode == opcode_of('setattr'): value = regv.load(block[ix + 3]) name = get_string(unit, block, ix + 2) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.setattr(name, value)) elif opcode == opcode_of('getitem'): index = regv.load(block[ix + 2]) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.getitem(index)) elif opcode == opcode_of('setitem'): item = regv.load(block[ix + 3]) index = regv.load(block[ix + 2]) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.setitem(index, item)) elif opcode == opcode_of('getloc'): regv.store(block[ix + 0], frame.local[block[ix + 1]]) elif opcode == opcode_of('setloc'): value = regv.load(block[ix + 2]) frame.local[block[ix + 1]] = value regv.store(block[ix + 0], value) elif opcode == opcode_of('getupv'): value = get_upframe(frame, block[ix + 1]).local[block[ix + 2]] regv.store(block[ix + 0], value) elif opcode == opcode_of('setupv'): value = regv.load(block[ix + 3]) get_upframe(frame, block[ix + 1]).local[block[ix + 2]] = value regv.store(block[ix + 0], value) elif opcode == opcode_of('getglob'): regv.store(block[ix + 0], module.getattr(get_string(unit, block, ix + 1))) elif opcode == opcode_of('setglob'): regv.store( block[ix + 0], module.setattr(get_string(unit, block, ix + 1), regv.load(block[ix + 2]))) elif opcode == opcode_of('not'): if space.is_false(regv.load(block[ix + 1])): regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) elif opcode == opcode_of('contains'): v0 = regv.load(block[ix + 1]) v1 = regv.load(block[ix + 2]) if v0.contains(v1): regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) else: raise space.unwind( space.LInstructionError( optable.names.get(opcode, str(opcode)).decode('utf-8'), opcode)) except space.Unwinder as unwinder: for exc in excs: if exc.start < pc <= exc.stop: regv.store(exc.reg, unwinder.exception) pc = exc.label break else: raise except StopIteration as stop: unwinder = space.unwind(space.LUncatchedStopIteration()) unwinder.traceback.contents.append( TraceEntry(rffi.r_long(pc), unit.constants, frame.sourcemap)) raise unwinder except space.Unwinder as unwinder: unwinder.traceback.contents.append( TraceEntry(rffi.r_long(pc), unit.constants, frame.sourcemap)) raise return space.null
def interpret(pc, block, frame): function = jit.promote(frame.function) module = jit.promote(frame.module) unit = jit.promote(frame.unit) excs = jit.promote(frame.excs) try: while pc < len(block): try: jitdriver.jit_merge_point(pc=pc, block=block, module=module, unit=unit, excs=excs, function=function, frame=frame) #ec=ec, regv=regv, opcode = rffi.r_ulong(block[pc]) >> 8 ix = pc + 1 pc = ix + (rffi.r_ulong(block[pc]) & 255) # Not sure.. #if ec.debug_hook is not None: # hook, ec.debug_hook = ec.debug_hook, None # res = ec.debug_hook.call([DebugContext(rffi.r_long(ix), unit, frame)]) # if res != space.null: # ec.debug_hook = res #print optable.dec[opcode][0] regv = frame # from now on.. if opcode == opcode_of('assert'): obj = regv.load(block[ix + 0]) raise space.unwind(space.LAssertionError(obj)) elif opcode == opcode_of('raise'): obj = regv.load(block[ix + 0]) traceback = obj.getattr(u"traceback") if traceback is space.null: traceback = space.List([]) obj.setattr(u"traceback", traceback) elif not isinstance(traceback, space.List): raise space.unwind( space.LError( u"Expected null or list as .traceback: %s" % obj.repr())) raise space.Unwinder(obj, traceback) elif opcode == opcode_of('constant'): regv.store(block[ix + 0], unit.constants[block[ix + 1]]) elif opcode == opcode_of('list'): contents = [] for i in range(ix + 1, pc): contents.append(regv.load(block[i])) regv.store(block[ix], space.List(contents)) elif opcode == opcode_of('move'): regv.store(block[ix + 0], regv.load(block[ix + 1])) elif opcode == opcode_of('call'): op_call(regv, block, ix, pc) elif opcode == opcode_of('callv'): op_callv(regv, block, ix, pc) elif opcode == opcode_of('return'): return regv.load(block[ix + 0]) elif opcode == opcode_of('yield'): result = regv.load(block[ix + 0]) jit.hint(frame, force_virtualizable=True) raise Yield(pc, result) elif opcode == opcode_of('jump'): pc = rffi.r_ulong(block[ix + 0]) elif opcode == opcode_of('cond'): if space.is_false(regv.load(block[ix + 0])): pc = rffi.r_ulong(block[ix + 2]) else: pc = rffi.r_ulong(block[ix + 1]) elif opcode == opcode_of('func'): regv.store(block[ix + 0], Closure(frame, unit.functions[block[ix + 1]])) elif opcode == opcode_of('iter'): regv.store(block[ix + 0], regv.load(block[ix + 1]).iter()) elif opcode == opcode_of('next'): try: regv.store( block[ix + 0], regv.load(block[ix + 1]).callattr(u'next', [])) except StopIteration as _: pc = rffi.r_ulong(block[ix + 2]) elif opcode == opcode_of('getattr'): name = get_string(unit, block, ix + 2) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.getattr(name)) elif opcode == opcode_of('setattr'): value = regv.load(block[ix + 3]) name = get_string(unit, block, ix + 2) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.setattr(name, value)) elif opcode == opcode_of('getitem'): index = regv.load(block[ix + 2]) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.getitem(index)) elif opcode == opcode_of('setitem'): item = regv.load(block[ix + 3]) index = regv.load(block[ix + 2]) obj = regv.load(block[ix + 1]) regv.store(block[ix + 0], obj.setitem(index, item)) elif opcode == opcode_of('getloc'): regv.store(block[ix + 0], frame.load_local(block[ix + 1])) elif opcode == opcode_of('setloc'): value = regv.load(block[ix + 2]) frame.store_local(block[ix + 1], value) regv.store(block[ix + 0], value) elif opcode == opcode_of('getupv'): value = get_upframe(frame, block[ix + 1]).load_local( block[ix + 2]) regv.store(block[ix + 0], value) elif opcode == opcode_of('setupv'): value = regv.load(block[ix + 3]) get_upframe(frame, block[ix + 1]).store_local( block[ix + 2], value) regv.store(block[ix + 0], value) elif opcode == opcode_of('getglob'): regv.store(block[ix + 0], module.getattr(get_string(unit, block, ix + 1))) elif opcode == opcode_of('setglob'): regv.store( block[ix + 0], module.setattr(get_string(unit, block, ix + 1), regv.load(block[ix + 2]))) elif opcode == opcode_of('loglob'): src_module = regv.load(block[ix + 0]) assert isinstance(src_module, space.Module) for name in src_module.list_locals(): module.setattr(name, src_module.getattr(name)) elif opcode == opcode_of('not'): if space.is_false(regv.load(block[ix + 1])): regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) elif opcode == opcode_of('isnull'): if regv.load(block[ix + 1]) is space.null: regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) elif opcode == opcode_of('contains'): v0 = regv.load(block[ix + 1]) v1 = regv.load(block[ix + 2]) if v0.contains(v1): regv.store(block[ix + 0], space.true) else: regv.store(block[ix + 0], space.false) else: raise space.unwind( space.LInstructionError( optable.names.get(opcode, str(opcode)).decode('utf-8'), opcode)) except space.Unwinder as unwinder: #print "exception detected, doing unwinds", pc, unwinder.exception.repr() for exc in excs: #print exc.start, exc.stop, exc.label, exc.reg if exc.start < pc <= exc.stop: frame.store(exc.reg, unwinder.exception) pc = exc.label #print "exception handler found" break else: raise except StopIteration as stop: # Doing an exception check to see if .next() was called in try block. unwinder = space.unwind(space.LUncatchedStopIteration()) for exc in excs: if exc.start < pc <= exc.stop: frame.store(exc.reg, unwinder.exception) pc = exc.label break else: raise unwinder except space.Unwinder as unwinder: unwinder.traceback.contents.append( TraceEntry(rffi.r_long(pc), unit.sources, frame.sourcemap, unit.path)) raise return space.null
def Multimethod_keys(self): return space.List([ space.List(list(vec)) for vec in self.multimethod_table ])
def unwind(exc): exc.traceback = traceback = space.List([]) return Unwinder(exc, traceback)
def interpret(pc, block, regv, frame, iterstop=LARGE_PC): module = jit.promote(frame.module) unit = jit.promote(frame.unit) try: while pc < len(block): jitdriver.jit_merge_point( pc=pc, block=block, module=module, unit=unit, iterstop=iterstop, regv=regv, frame=frame) opcode = rffi.r_ulong(block[pc])>>8 ix = pc+1 pc = ix+(rffi.r_ulong(block[pc])&255) if opcode == opcode_of('assert'): if space.is_false(regv.load(block[ix+0])): raise space.Error(u"Assertion error") elif opcode == opcode_of('constant'): regv.store(block[ix+0], unit.constants[block[ix+1]]) elif opcode == opcode_of('list'): contents = [] for i in range(ix+1, pc): contents.append(regv.load(block[i])) regv.store(block[ix], space.List(contents)) elif opcode == opcode_of('move'): regv.store(block[ix+0], regv.load(block[ix+1])) elif opcode == opcode_of('call'): op_call(regv, block, ix, pc) elif opcode == opcode_of('return'): return regv.load(block[ix+0]) elif opcode == opcode_of('jump'): pc = rffi.r_ulong(block[ix+0]) elif opcode == opcode_of('cond'): if space.is_false(regv.load(block[ix+0])): pc = rffi.r_ulong(block[ix+2]) else: pc = rffi.r_ulong(block[ix+1]) elif opcode == opcode_of('func'): regv.store(block[ix+0], Closure(frame, unit.functions[block[ix+1]])) elif opcode == opcode_of('iter'): regv.store(block[ix+0], regv.load(block[ix+1]).iter()) elif opcode == opcode_of('iterstop'): iterstop = rffi.r_ulong(block[ix+0]) elif opcode == opcode_of('next'): regv.store(block[ix+0], regv.load(block[ix+1]).callattr(u'next', [])) # this is missing. #elif isinstance(op, Yield): # raise YieldIteration(op.block, loop_break, op.i, regv.load(op.value.i)) elif opcode == opcode_of('getattr'): name = get_string(unit, block, ix+2) obj = regv.load(block[ix+1]) regv.store(block[ix+0], obj.getattr(name)) elif opcode == opcode_of('setattr'): value = regv.load(block[ix+3]) name = get_string(unit, block, ix+2) obj = regv.load(block[ix+1]) regv.store(block[ix+0], obj.setattr(name, value)) elif opcode == opcode_of('getitem'): index = regv.load(block[ix+2]) obj = regv.load(block[ix+1]) regv.store(block[ix+0], obj.getitem(index)) elif opcode == opcode_of('setitem'): item = regv.load(block[ix+3]) index = regv.load(block[ix+2]) obj = regv.load(block[ix+1]) regv.store(block[ix+0], obj.setitem(index, item)) elif opcode == opcode_of('getloc'): regv.store(block[ix+0], frame.local[block[ix+1]]) elif opcode == opcode_of('setloc'): value = regv.load(block[ix+2]) frame.local[block[ix+1]] = value regv.store(block[ix+0], value) elif opcode == opcode_of('getupv'): value = get_upframe(frame, block[ix+1]).local[block[ix+2]] regv.store(block[ix+0], value) elif opcode == opcode_of('setupv'): value = regv.load(block[ix+3]) get_upframe(frame, block[ix+1]).local[block[ix+2]] = value regv.store(block[ix+0], value) elif opcode == opcode_of('getglob'): regv.store(block[ix+0], module.getattr(get_string(unit, block, ix+1))) elif opcode == opcode_of('setglob'): regv.store(block[ix+0], module.setattr( get_string(unit, block, ix+1), regv.load(block[ix+2]))) else: raise space.Error(u"unexpected instruction: " + optable.names.get(opcode, str(opcode)).decode('utf-8')) except StopIteration as stop: if iterstop != LARGE_PC: return interpret(iterstop, block, regv, frame) else: raise space.Error(u"StopIteration") return space.null
def interpret_body(block, t, cl_frame, loop_break): frame = Frame(t) pc = 0 module = jit.promote(cl_frame.module) try: while pc < len(block): try: jitdriver.jit_merge_point(pc=pc, block=block, loop_break=loop_break, module=module, cl_frame=cl_frame, frame=frame) op = block[pc] pc += 1 if isinstance(op, Call): do_call(frame, op) elif isinstance(op, Assert): if space.is_false(frame.load(op.value.i)): raise space.Error(u"Assertion error") elif isinstance(op, Cond): pc = 0 if space.is_false(frame.load(op.cond.i)): block = op.exit else: block = op.then elif isinstance(op, Jump): pc = 0 block = op.exit elif isinstance(op, Next): frame.store(op.i, frame.load(op.it.i).callattr(u'next', [])) elif isinstance(op, Yield): raise YieldIteration(op.block, loop_break, op.i, frame.load(op.value.i)) elif isinstance(op, SetBreak): loop_break = op.block elif isinstance(op, Iter): frame.store(op.i, frame.load(op.value.i).iter()) elif isinstance(op, Constant): frame.store(op.i, op.value) elif isinstance(op, Variable): frame.store(op.i, lookup(module, cl_frame, op.name)) elif isinstance(op, Merge): frame.store(op.dst.i, frame.load(op.src.i)) elif isinstance(op, Function): frame.store(op.i, Closure(cl_frame, op)) elif isinstance(op, MakeList): contents = [] for val in op.values: contents.append(frame.load(val.i)) frame.store(op.i, space.List(contents)) elif isinstance(op, GetAttr): frame.store(op.i, frame.load(op.value.i).getattr(op.name)) elif isinstance(op, GetItem): frame.store( op.i, frame.load(op.value.i).getitem(frame.load(op.index.i))) elif isinstance(op, SetAttr): frame.store( op.i, frame.load(op.obj.i).setattr(op.name, frame.load(op.value.i))) elif isinstance(op, SetItem): frame.store( op.i, frame.load(op.obj.i).setitem(frame.load(op.index.i), frame.load(op.value.i))) elif isinstance(op, SetLocal): frame.store( op.i, set_local(module, cl_frame, op.name, frame.load(op.value.i), op.upscope)) elif isinstance(op, Return): return frame.load(op.ref.i) else: raise space.Error(u"spaced out") except StopIteration as stopiter: if loop_break is not None: block = loop_break loop_break = None continue op = block[pc - 1] error = space.Error(u"stop iteration") error.stacktrace.append((cl_frame, op.start, op.stop)) raise error raise space.Error(u"crappy compiler") except space.Error as e: op = block[pc - 1] e.stacktrace.append((cl_frame, op.start, op.stop)) raise e
def String_rsplit(self, sep, maxsplit): out = [] m = maxsplit.value if maxsplit else -1 for s in rsplit(self.string, sep.string, m): out.append(String(s)) return space.List(out)