Commit cf8e55ef authored by Boxiang Sun's avatar Boxiang Sun

Change the vreg_name to index_id in BST_ImportName and BST_ImportFrom

This commit is a preperation of the commit which for add co_names field.
BST_StoreName and some other nodes use `index_id` and InteredString to
store variable name. But BST_ImportName use vreg and vreg_name. We can't
get the module name inside code object in this way. So change it to the
way which BST_StoreName used.
parent 57deb0bf
......@@ -819,25 +819,24 @@ Value ASTInterpreter::visit_importfrom(BST_ImportFrom* node) {
Value module = getVReg(node->vreg_module);
AUTO_DECREF(module.o);
Value name_boxed = getVReg(node->vreg_name);
AUTO_DECREF(name_boxed.o);
InternedString name = getCodeConstants().getInternedString(node->index_id);
Value v;
if (jit)
v.var = jit->emitImportFrom(module, name_boxed);
v.o = importFrom(module.o, (BoxedString*)name_boxed.o);
v.var = jit->emitImportFrom(module, name);
v.o = importFrom(module.o, (BoxedString*)name);
return v;
}
Value ASTInterpreter::visit_importname(BST_ImportName* node) {
int level = node->level;
Value froms = getVReg(node->vreg_from);
AUTO_DECREF(froms.o);
Value module_name = getVReg(node->vreg_name);
AUTO_DECREF(module_name.o);
InternedString name = getCodeConstants().getInternedString(node->index_id);
Value v;
if (jit)
v.var = jit->emitImportName(level, froms, module_name);
v.o = import(level, froms.o, (BoxedString*)module_name.o);
v.var = jit->emitImportName(level, froms, name.getBox());
v.o = import(level, froms.o, (BoxedString*)name);
return v;
}
......
......@@ -482,12 +482,12 @@ RewriterVar* JitFragmentWriter::emitHasnext(RewriterVar* v) {
return rtn;
}
RewriterVar* JitFragmentWriter::emitImportFrom(RewriterVar* module, RewriterVar* name) {
return call(false, (void*)importFrom, module, name)->setType(RefType::OWNED);
RewriterVar* JitFragmentWriter::emitImportFrom(RewriterVar* module, BoxedString* s) {
return call(false, (void*)importFrom, module, imm(s))->setType(RefType::OWNED);
}
RewriterVar* JitFragmentWriter::emitImportName(int level, RewriterVar* from_imports, RewriterVar* module_name) {
return call(false, (void*)import, imm(level), from_imports, module_name)->setType(RefType::OWNED);
RewriterVar* JitFragmentWriter::emitImportName(int level, RewriterVar* from_imports, BoxedString* s) {
return call(false, (void*)import, imm(level), from_imports, imm(s))->setType(RefType::OWNED);
}
RewriterVar* JitFragmentWriter::emitImportStar(RewriterVar* module) {
......
......@@ -293,8 +293,8 @@ public:
RewriterVar* emitGetLocalMustExist(int vreg);
RewriterVar* emitGetPystonIter(RewriterVar* v);
RewriterVar* emitHasnext(RewriterVar* v);
RewriterVar* emitImportFrom(RewriterVar* module, RewriterVar* name);
RewriterVar* emitImportName(int level, RewriterVar* from_imports, RewriterVar* module_name);
RewriterVar* emitImportFrom(RewriterVar* module, BoxedString* s);
RewriterVar* emitImportName(int level, RewriterVar* from_imports, BoxedString* s);
RewriterVar* emitImportStar(RewriterVar* module);
RewriterVar* emitLandingpad();
RewriterVar* emitNonzero(RewriterVar* v);
......
......@@ -943,11 +943,11 @@ private:
CompilerVariable* module = evalVReg(node->vreg_module);
ConcreteCompilerVariable* converted_module = module->makeConverted(emitter, module->getBoxType());
CompilerVariable* name = evalVReg(node->vreg_name);
ConcreteCompilerVariable* converted_name = name->makeConverted(emitter, name->getBoxType());
InternedString name = irstate->getCodeConstants().getInternedString(node->index_id);
llvm::Value* converted_name = embedRelocatablePtr(name, g.llvm_boxedstring_type_ptr);
llvm::Value* r = emitter.createCall2(unw_info, g.funcs.importFrom, converted_module->getValue(),
converted_name->getValue());
converted_name);
emitter.setType(r, RefType::OWNED);
CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r);
......@@ -973,12 +973,12 @@ private:
CompilerVariable* froms = evalVReg(node->vreg_from);
ConcreteCompilerVariable* converted_froms = froms->makeConverted(emitter, froms->getBoxType());
CompilerVariable* name = evalVReg(node->vreg_name);
ConcreteCompilerVariable* converted_name = name->makeConverted(emitter, name->getBoxType());
InternedString name = irstate->getCodeConstants().getInternedString(node->index_id);
llvm::Value* converted_name = embedRelocatablePtr(name, g.llvm_boxedstring_type_ptr);
llvm::Value* imported
= emitter.createCall(unw_info, g.funcs.import, { getConstantInt(level, g.i32), converted_froms->getValue(),
converted_name->getValue() });
converted_name });
emitter.setType(imported, RefType::OWNED);
ConcreteCompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, imported);
return v;
......
......@@ -300,7 +300,7 @@ void BST_ImportFrom::accept(BSTVisitor* v) {
return;
v->visit_vreg(&vreg_module);
v->visit_vreg(&vreg_name);
v->visit_vreg(&index_id);
v->visit_vreg(&vreg_dst, true);
}
......@@ -314,7 +314,7 @@ void BST_ImportName::accept(BSTVisitor* v) {
return;
v->visit_vreg(&vreg_from);
v->visit_vreg(&vreg_name);
v->visit_vreg(&index_id);
v->visit_vreg(&vreg_dst, true);
}
......@@ -1007,7 +1007,7 @@ bool PrintVisitor::visit_importfrom(BST_ImportFrom* node) {
stream << ":IMPORT_FROM(";
visit_vreg(&node->vreg_module);
stream << ", ";
visit_vreg(&node->vreg_name);
visit_vreg(&node->index_id);
stream << ")";
return true;
}
......@@ -1018,7 +1018,7 @@ bool PrintVisitor::visit_importname(BST_ImportName* node) {
stream << ":IMPORT_NAME(";
visit_vreg(&node->vreg_from);
stream << ", ";
visit_vreg(&node->vreg_name);
visit_vreg(&node->index_id);
stream << ", " << node->level << ")";
return true;
}
......
......@@ -661,7 +661,7 @@ public:
class BST_ImportFrom : public BST_stmt_with_dest {
public:
int vreg_module = VREG_UNDEFINED;
int vreg_name = VREG_UNDEFINED;
int index_id = VREG_UNDEFINED;
BSTFIXEDVREGS(ImportFrom, BST_stmt_with_dest)
} PACKED;
......@@ -670,7 +670,7 @@ class BST_ImportName : public BST_stmt_with_dest {
public:
int vreg_from = VREG_UNDEFINED;
int level = VREG_UNDEFINED;
int vreg_name = VREG_UNDEFINED;
int index_id = VREG_UNDEFINED;
BSTFIXEDVREGS(ImportName, BST_stmt_with_dest)
} PACKED;
......
......@@ -1998,7 +1998,7 @@ public:
import->level = level;
unmapExpr(makeNone(node->lineno), &import->vreg_from);
unmapExpr(makeStr(a->name.s(), node->lineno), &import->vreg_name);
import->index_id = remapInternedString(a->name);
TmpValue tmpname = createDstName(import);
......@@ -2057,8 +2057,8 @@ public:
import->level = level;
unmapExpr(tuple_name, &import->vreg_from);
unmapExpr(makeStr(node->module.s()), &import->vreg_name);
import->index_id = remapInternedString(internString(node->module.s()));
TmpValue tmp_module_name = createDstName(import);
int i = 0;
......@@ -2076,7 +2076,7 @@ public:
BST_ImportFrom* import_from = allocAndPush<BST_ImportFrom>();
import_from->lineno = node->lineno;
unmapExpr(remapped_tmp_module_name, &import_from->vreg_module);
unmapExpr(makeStr(a->name.s()), &import_from->vreg_name);
import_from->index_id = remapInternedString(a->name);
TmpValue tmp_import_name = createDstName(import_from);
pushAssign(a->asname.s().size() ? a->asname : a->name, tmp_import_name);
......
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