Commit dd25db82 authored by Michael Arntzenius's avatar Michael Arntzenius

make tuple indexing work in JIT mode

parent 386b688f
......@@ -2154,21 +2154,28 @@ public:
assert(v->getType() == g.i64);
if (llvm::ConstantInt* ci = llvm::dyn_cast<llvm::ConstantInt>(v)) {
int64_t i = ci->getSExtValue();
if (i >= 0 && i < var->getValue()->size()) {
CompilerVariable* rtn = (*var->getValue())[i];
auto elts = var->getValue();
if (i >= 0 && i < elts->size()) {
CompilerVariable* rtn = (*elts)[i];
rtn->incvref();
return rtn;
} else if (i < 0 && -i <= elts->size()) {
CompilerVariable* rtn = (*elts)[elts->size() + i];
rtn->incvref();
return rtn;
} else {
llvm::CallSite call = emitter.createCall2(info.unw_info, g.funcs.raiseAttributeErrorStr,
getStringConstantPtr(debugName() + '\0'),
getStringConstantPtr("__getitem__\0"));
llvm::CallSite call = emitter.createCall(info.unw_info, g.funcs.raiseIndexErrorStr,
getStringConstantPtr("tuple\0"));
call.setDoesNotReturn();
return undefVariable();
}
}
}
RELEASE_ASSERT(0, "");
// return getConstantInt(var->getValue()->size(), g.i64);
ConcreteCompilerVariable* converted = var->makeConverted(emitter, BOXED_TUPLE);
CompilerVariable* rtn = converted->getitem(emitter, info, slice);
converted->decvref(emitter);
return rtn;
}
ConcreteCompilerVariable* len(IREmitter& emitter, const OpInfo& info, VAR* var) override {
......
......@@ -214,6 +214,7 @@ void initGlobalFuncs(GlobalState& g) {
GET(unpackIntoArray);
GET(raiseAttributeError);
GET(raiseAttributeErrorStr);
GET(raiseIndexErrorStr);
GET(raiseNotIterableError);
GET(assertNameDefined);
GET(assertFailDerefNameDefined);
......
......@@ -41,7 +41,7 @@ struct GlobalFuncs {
*exceptionMatches, *yield, *getiterHelper, *hasnext;
llvm::Value* unpackIntoArray, *raiseAttributeError, *raiseAttributeErrorStr, *raiseNotIterableError,
*assertNameDefined, *assertFail, *assertFailDerefNameDefined;
*raiseIndexErrorStr, *assertNameDefined, *assertFail, *assertFailDerefNameDefined;
llvm::Value* printFloat, *listAppendInternal, *getSysStdout;
llvm::Value* runtimeCall0, *runtimeCall1, *runtimeCall2, *runtimeCall3, *runtimeCall, *runtimeCallN;
llvm::Value* callattr0, *callattr1, *callattr2, *callattr3, *callattr, *callattrN;
......
......@@ -96,6 +96,7 @@ void force() {
FORCE(unpackIntoArray);
FORCE(raiseAttributeError);
FORCE(raiseAttributeErrorStr);
FORCE(raiseIndexErrorStr);
FORCE(raiseNotIterableError);
FORCE(assertNameDefined);
FORCE(assertFailDerefNameDefined);
......
......@@ -252,6 +252,10 @@ extern "C" void raiseAttributeError(Box* obj, const char* attr) {
}
}
extern "C" void raiseIndexErrorStr(const char* typeName) {
raiseExcHelper(IndexError, "%s index out of range", typeName);
}
extern "C" void raiseNotIterableError(const char* typeName) {
raiseExcHelper(TypeError, "'%s' object is not iterable", typeName);
}
......
......@@ -132,6 +132,7 @@ Box* typeLookup(BoxedClass* cls, const std::string& attr, GetattrRewriteArgs* re
extern "C" void raiseAttributeErrorStr(const char* typeName, const char* attr) __attribute__((__noreturn__));
extern "C" void raiseAttributeError(Box* obj, const char* attr) __attribute__((__noreturn__));
extern "C" void raiseNotIterableError(const char* typeName) __attribute__((__noreturn__));
extern "C" void raiseIndexErrorStr(const char* typeName) __attribute__((__noreturn__));
Box* typeCall(Box*, BoxedTuple*, BoxedDict*);
Box* typeNew(Box* cls, Box* arg1, Box* arg2, Box** _args);
......
def f():
print (1,2,3)[-1]
f()
def f2():
try:
print (1,2,3)[4]
except IndexError as e:
print e
try:
print (1,2,3)[-4]
except IndexError as e:
print e
f2()
def f3():
try:
print (1,2,3)['hello']
except TypeError as e:
print e
f3()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment