Commit b4d71529 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Set the frame-local ExcInfo from the ast interpreter

Seems like it kinda works
parent a9fe6120
......@@ -598,6 +598,18 @@ Value ASTInterpreter::visit_langPrimitive(AST_LangPrimitive* node) {
assert(node->args.size() == 1);
Value obj = visit_expr(node->args[0]);
v = boxBool(nonzero(obj.o));
} else if (node->opcode == AST_LangPrimitive::SET_EXC_INFO) {
assert(node->args.size() == 3);
Value type = visit_expr(node->args[0]);
assert(type.o);
Value value = visit_expr(node->args[1]);
assert(value.o);
Value traceback = visit_expr(node->args[2]);
assert(traceback.o);
getFrameInfo()->exc = ExcInfo(type.o, value.o, traceback.o);
v = None;
} else
RELEASE_ASSERT(0, "not implemented");
return v;
......
......@@ -1455,6 +1455,9 @@ bool PrintVisitor::visit_langprimitive(AST_LangPrimitive* node) {
case AST_LangPrimitive::NONZERO:
printf("NONZERO");
break;
case AST_LangPrimitive::SET_EXC_INFO:
printf("SET_EXC_INFO");
break;
default:
RELEASE_ASSERT(0, "%d", node->opcode);
}
......
......@@ -977,6 +977,7 @@ public:
IMPORT_STAR,
NONE,
NONZERO,
SET_EXC_INFO,
} opcode;
std::vector<AST_expr*> args;
......
......@@ -968,6 +968,8 @@ private:
rtn = remapIfExp(ast_cast<AST_IfExp>(node));
break;
case AST_TYPE::Index:
if (ast_cast<AST_Index>(node)->value->type == AST_TYPE::Num)
return node;
rtn = remapIndex(ast_cast<AST_Index>(node));
break;
case AST_TYPE::Lambda:
......@@ -1851,7 +1853,7 @@ public:
cfg->placeBlock(exc_handler_block);
curblock = exc_handler_block;
// TODO: this should be an EXCEPTION_MATCHES(exc_type_name)
// TODO This is supposed to be exc_type_name (value doesn't matter for checking matches)
AST_expr* exc_obj = makeName(exc_value_name, AST_TYPE::Load, node->lineno);
bool caught_all = false;
......@@ -1862,6 +1864,7 @@ public:
if (exc_handler->type) {
AST_expr* handled_type = remapExpr(exc_handler->type);
// TODO: this should be an EXCEPTION_MATCHES(exc_type_name)
AST_LangPrimitive* is_caught_here = new AST_LangPrimitive(AST_LangPrimitive::ISINSTANCE);
is_caught_here->args.push_back(_dup(exc_obj));
is_caught_here->args.push_back(handled_type);
......@@ -1883,6 +1886,12 @@ public:
caught_all = true;
}
AST_LangPrimitive* set_exc_info = new AST_LangPrimitive(AST_LangPrimitive::SET_EXC_INFO);
set_exc_info->args.push_back(makeName(exc_type_name, AST_TYPE::Load, node->lineno));
set_exc_info->args.push_back(makeName(exc_value_name, AST_TYPE::Load, node->lineno));
set_exc_info->args.push_back(makeName(exc_traceback_name, AST_TYPE::Load, node->lineno));
push_back(makeExpr(set_exc_info));
if (exc_handler->name) {
pushAssign(exc_handler->name, _dup(exc_obj));
}
......
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