Commit 52fe1669 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get some basic eval() cases working

parent 66200ef5
......@@ -153,8 +153,6 @@ private:
public:
~ASTInterpreter() {
Py_XDECREF(frame_info.boxedLocals);
Py_DECREF(frame_info.globals);
Py_XDECREF(this->created_closure);
}
......@@ -186,7 +184,7 @@ public:
void setGenerator(Box* gen);
void setPassedClosure(Box* closure);
void setCreatedClosure(Box* closure);
void setBoxedLocals(Box*);
void setBoxedLocals(STOLEN(Box*));
void setFrameInfo(const FrameInfo* frame_info);
void setGlobals(Box* globals);
......@@ -219,6 +217,7 @@ void ASTInterpreter::setCreatedClosure(Box* closure) {
}
void ASTInterpreter::setBoxedLocals(Box* boxedLocals) {
assert(!this->frame_info.boxedLocals);
this->frame_info.boxedLocals = boxedLocals;
}
......@@ -230,7 +229,7 @@ void ASTInterpreter::setFrameInfo(const FrameInfo* frame_info) {
void ASTInterpreter::setGlobals(Box* globals) {
assert(!this->frame_info.globals);
this->frame_info.globals = incref(globals);
this->frame_info.globals = globals;
}
ASTInterpreter::ASTInterpreter(FunctionMetadata* md, Box** vregs, int num_vregs)
......@@ -1951,7 +1950,7 @@ Box* astInterpretFunctionEval(FunctionMetadata* md, Box* globals, Box* boxedLoca
ASTInterpreter interpreter(md, vregs, num_vregs);
interpreter.initArguments(NULL, NULL, NULL, NULL, NULL, NULL);
interpreter.setBoxedLocals(boxedLocals);
interpreter.setBoxedLocals(incref(boxedLocals));
assert(!md->source->scoping->areGlobalsFromModule());
assert(globals);
......
......@@ -356,6 +356,8 @@ Box* evalOrExec(FunctionMetadata* md, Box* globals, Box* boxedLocals) {
if (doc_string != None) {
static BoxedString* doc_box = getStaticString("__doc__");
setGlobal(boxedLocals, doc_box, doc_string);
} else {
Py_DECREF(doc_string);
}
return astInterpretFunctionEval(md, globals, boxedLocals);
......@@ -413,13 +415,13 @@ extern "C" PyCodeObject* PyAST_Compile(struct _mod* _mod, const char* filename,
if (parsed->type != AST_TYPE::Module) {
raiseExcHelper(TypeError, "expected Module node, got %s", AST_TYPE::stringify(parsed->type));
}
md = compileExec(static_cast<AST_Module*>(parsed), boxString(filename), flags);
md = compileExec(static_cast<AST_Module*>(parsed), autoDecref(boxString(filename)), flags);
break;
case Expression_kind:
if (parsed->type != AST_TYPE::Expression) {
raiseExcHelper(TypeError, "expected Expression node, got %s", AST_TYPE::stringify(parsed->type));
}
md = compileEval(static_cast<AST_Expression*>(parsed), boxString(filename), flags);
md = compileEval(static_cast<AST_Expression*>(parsed), autoDecref(boxString(filename)), flags);
break;
case Suite_kind:
PyErr_SetString(PyExc_SystemError, "suite should not be possible");
......@@ -469,7 +471,6 @@ extern "C" int PyEval_MergeCompilerFlags(PyCompilerFlags* cf) noexcept {
}
static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
assert(0 && "check refcounting");
if (globals == None)
globals = NULL;
......@@ -502,9 +503,7 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
if (globals->cls == module_cls)
globals_dict = globals->getAttrWrapper();
else
globals_dict = incref(globals);
AUTO_DECREF(globals_dict);
globals_dict = globals;
auto requested_builtins = PyDict_GetItemString(globals_dict, "__builtins__");
if (requested_builtins == NULL)
......@@ -517,7 +516,6 @@ static void pickGlobalsAndLocals(Box*& globals, Box*& locals) {
}
extern "C" PyObject* PyEval_EvalCode(PyCodeObject* co, PyObject* globals, PyObject* locals) noexcept {
assert(0 && "check refcounting");
try {
pickGlobalsAndLocals(globals, locals);
return evalOrExec(metadataFromCode((Box*)co), globals, locals);
......
......@@ -736,7 +736,7 @@ BORROWED(Box*) getGlobalsDict() {
return globals;
}
BoxedModule* getCurrentModule() {
BORROWED(BoxedModule*) getCurrentModule() {
FunctionMetadata* md = getTopPythonFunction();
if (!md)
return NULL;
......
......@@ -35,7 +35,7 @@ uint64_t getCXXUnwindSymbolAddress(llvm::StringRef sym);
bool isUnwinding(); // use this instead of std::uncaught_exception
void setupUnwinding();
BoxedModule* getCurrentModule();
BORROWED(BoxedModule*) getCurrentModule();
BORROWED(Box*) getGlobals(); // returns either the module or a globals dict
BORROWED(Box*) getGlobalsDict(); // always returns a dict-like object
CompiledFunction* getCFForAddress(uint64_t addr);
......
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