Commit 17b548d9 authored by Marius Wachtler's avatar Marius Wachtler Committed by Boxiang Sun

BST: use constant table for the interned strings

parent 53a1a557
...@@ -279,10 +279,11 @@ private: ...@@ -279,10 +279,11 @@ private:
void visit_callattr(BST_CallAttr* node) override { void visit_callattr(BST_CallAttr* node) override {
CompilerType* t = getType(node->vreg_value); CompilerType* t = getType(node->vreg_value);
CompilerType* func = t->getattrType(node->attr, false); InternedString attr = getCodeConstants().getInternedString(node->index_attr);
CompilerType* func = t->getattrType(attr, false);
if (VERBOSITY() >= 2 && func == UNDEF) { if (VERBOSITY() >= 2 && func == UNDEF) {
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno); printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), attr.c_str(), node->lineno);
print_bst(node, code_constants); print_bst(node, code_constants);
printf("\n"); printf("\n");
} }
...@@ -292,10 +293,11 @@ private: ...@@ -292,10 +293,11 @@ private:
void visit_callclsattr(BST_CallClsAttr* node) override { void visit_callclsattr(BST_CallClsAttr* node) override {
CompilerType* t = getType(node->vreg_value); CompilerType* t = getType(node->vreg_value);
CompilerType* func = t->getattrType(node->attr, true); InternedString attr = getCodeConstants().getInternedString(node->index_attr);
CompilerType* func = t->getattrType(attr, true);
if (VERBOSITY() >= 2 && func == UNDEF) { if (VERBOSITY() >= 2 && func == UNDEF) {
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno); printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), attr.c_str(), node->lineno);
print_bst(node, code_constants); print_bst(node, code_constants);
printf("\n"); printf("\n");
} }
...@@ -379,7 +381,8 @@ private: ...@@ -379,7 +381,8 @@ private:
auto name_scope = node->lookup_type; auto name_scope = node->lookup_type;
if (name_scope == ScopeInfo::VarScopeType::GLOBAL) { if (name_scope == ScopeInfo::VarScopeType::GLOBAL) {
if (node->id.s() == "None") InternedString id = getCodeConstants().getInternedString(node->index_id);
if (id.s() == "None")
t = NONE; t = NONE;
} else if (name_scope == ScopeInfo::VarScopeType::FAST || name_scope == ScopeInfo::VarScopeType::CLOSURE) } else if (name_scope == ScopeInfo::VarScopeType::FAST || name_scope == ScopeInfo::VarScopeType::CLOSURE)
t = getType(node->vreg); t = getType(node->vreg);
...@@ -389,7 +392,8 @@ private: ...@@ -389,7 +392,8 @@ private:
void visit_loadattr(BST_LoadAttr* node) override { void visit_loadattr(BST_LoadAttr* node) override {
CompilerType* t = getType(node->vreg_value); CompilerType* t = getType(node->vreg_value);
CompilerType* rtn = t->getattrType(node->attr, node->clsonly); InternedString attr = getCodeConstants().getInternedString(node->index_attr);
CompilerType* rtn = t->getattrType(attr, node->clsonly);
if (speculation != TypeAnalysis::NONE) { if (speculation != TypeAnalysis::NONE) {
BoxedClass* speculated_class = predictClassFor(node); BoxedClass* speculated_class = predictClassFor(node);
...@@ -397,7 +401,7 @@ private: ...@@ -397,7 +401,7 @@ private:
} }
if (VERBOSITY() >= 2 && rtn == UNDEF) { if (VERBOSITY() >= 2 && rtn == UNDEF) {
printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), node->attr.c_str(), node->lineno); printf("Think %s.%s is undefined, at %d\n", t->debugName().c_str(), attr.c_str(), node->lineno);
print_bst(node, code_constants); print_bst(node, code_constants);
printf("\n"); printf("\n");
} }
......
...@@ -1263,7 +1263,8 @@ Value ASTInterpreter::visit_makeClass(BST_MakeClass* mkclass) { ...@@ -1263,7 +1263,8 @@ Value ASTInterpreter::visit_makeClass(BST_MakeClass* mkclass) {
ArgPassSpec(0), 0, 0, 0, 0, 0); ArgPassSpec(0), 0, 0, 0, 0, 0);
AUTO_DECREF(attrDict); AUTO_DECREF(attrDict);
Box* classobj = createUserClass(node->name.getBox(), bases_tuple, attrDict); InternedString name = getCodeConstants().getInternedString(node->index_name);
Box* classobj = createUserClass(name.getBox(), bases_tuple, attrDict);
for (int i = decorators.size() - 1; i >= 0; i--) { for (int i = decorators.size() - 1; i >= 0; i--) {
classobj = runtimeCall(autoDecref(decorators[i]), ArgPassSpec(1), autoDecref(classobj), 0, 0, 0, 0); classobj = runtimeCall(autoDecref(decorators[i]), ArgPassSpec(1), autoDecref(classobj), 0, 0, 0, 0);
...@@ -1311,7 +1312,7 @@ void ASTInterpreter::visit_assert(BST_Assert* node) { ...@@ -1311,7 +1312,7 @@ void ASTInterpreter::visit_assert(BST_Assert* node) {
void ASTInterpreter::visit_deleteattr(BST_DeleteAttr* node) { void ASTInterpreter::visit_deleteattr(BST_DeleteAttr* node) {
Value target = getVReg(node->vreg_value); Value target = getVReg(node->vreg_value);
AUTO_DECREF(target.o); AUTO_DECREF(target.o);
BoxedString* str = node->attr.getBox(); BoxedString* str = getCodeConstants().getInternedString(node->index_attr).getBox();
if (jit) if (jit)
jit->emitDelAttr(target, str); jit->emitDelAttr(target, str);
delattr(target.o, str); delattr(target.o, str);
...@@ -1344,27 +1345,28 @@ void ASTInterpreter::visit_deletename(BST_DeleteName* target) { ...@@ -1344,27 +1345,28 @@ void ASTInterpreter::visit_deletename(BST_DeleteName* target) {
assert(target->lookup_type != ScopeInfo::VarScopeType::UNKNOWN); assert(target->lookup_type != ScopeInfo::VarScopeType::UNKNOWN);
ScopeInfo::VarScopeType vst = target->lookup_type; ScopeInfo::VarScopeType vst = target->lookup_type;
InternedString id = getCodeConstants().getInternedString(target->index_id);
if (vst == ScopeInfo::VarScopeType::GLOBAL) { if (vst == ScopeInfo::VarScopeType::GLOBAL) {
if (jit) if (jit)
jit->emitDelGlobal(target->id.getBox()); jit->emitDelGlobal(id.getBox());
delGlobal(frame_info.globals, target->id.getBox()); delGlobal(frame_info.globals, id.getBox());
} else if (vst == ScopeInfo::VarScopeType::NAME) { } else if (vst == ScopeInfo::VarScopeType::NAME) {
if (jit) if (jit)
jit->emitDelName(target->id); jit->emitDelName(id);
ASTInterpreterJitInterface::delNameHelper(this, target->id); ASTInterpreterJitInterface::delNameHelper(this, id);
} else { } else {
assert(vst == ScopeInfo::VarScopeType::FAST); assert(vst == ScopeInfo::VarScopeType::FAST);
assert(getVRegInfo().getVReg(target->id) == target->vreg); assert(getVRegInfo().getVReg(id) == target->vreg);
if (target->id.s()[0] == '#') { if (id.s()[0] == '#') {
assert(vregs[target->vreg] != NULL); assert(vregs[target->vreg] != NULL);
if (jit) if (jit)
jit->emitKillTemporary(target->vreg); jit->emitKillTemporary(target->vreg);
} else { } else {
abortJITing(); abortJITing();
if (vregs[target->vreg] == 0) { if (vregs[target->vreg] == 0) {
assertNameDefined(0, target->id.c_str(), NameError, true /* local_var_msg */); assertNameDefined(0, id.c_str(), NameError, true /* local_var_msg */);
return; return;
} }
} }
...@@ -1428,14 +1430,14 @@ Value ASTInterpreter::visit_call(BST_Call* node) { ...@@ -1428,14 +1430,14 @@ Value ASTInterpreter::visit_call(BST_Call* node) {
callattr_clsonly = false; callattr_clsonly = false;
auto* attr_ast = bst_cast<BST_CallAttr>(node); auto* attr_ast = bst_cast<BST_CallAttr>(node);
func = getVReg(attr_ast->vreg_value); func = getVReg(attr_ast->vreg_value);
attr = attr_ast->attr; attr = getCodeConstants().getInternedString(attr_ast->index_attr);
vreg_elts = bst_cast<BST_CallAttr>(node)->elts; vreg_elts = bst_cast<BST_CallAttr>(node)->elts;
} else if (node->type == BST_TYPE::CallClsAttr) { } else if (node->type == BST_TYPE::CallClsAttr) {
is_callattr = true; is_callattr = true;
callattr_clsonly = true; callattr_clsonly = true;
auto* attr_ast = bst_cast<BST_CallClsAttr>(node); auto* attr_ast = bst_cast<BST_CallClsAttr>(node);
func = getVReg(attr_ast->vreg_value); func = getVReg(attr_ast->vreg_value);
attr = attr_ast->attr; attr = getCodeConstants().getInternedString(attr_ast->index_attr);
vreg_elts = bst_cast<BST_CallClsAttr>(node)->elts; vreg_elts = bst_cast<BST_CallClsAttr>(node)->elts;
} else { } else {
auto* attr_ast = bst_cast<BST_CallFunc>(node); auto* attr_ast = bst_cast<BST_CallFunc>(node);
...@@ -1577,14 +1579,14 @@ Value ASTInterpreter::getVReg(int vreg, bool is_kill) { ...@@ -1577,14 +1579,14 @@ Value ASTInterpreter::getVReg(int vreg, bool is_kill) {
Value ASTInterpreter::visit_loadname(BST_LoadName* node) { Value ASTInterpreter::visit_loadname(BST_LoadName* node) {
assert(node->lookup_type != ScopeInfo::VarScopeType::UNKNOWN); assert(node->lookup_type != ScopeInfo::VarScopeType::UNKNOWN);
InternedString id = getCodeConstants().getInternedString(node->index_id);
switch (node->lookup_type) { switch (node->lookup_type) {
case ScopeInfo::VarScopeType::GLOBAL: { case ScopeInfo::VarScopeType::GLOBAL: {
Value v; Value v;
if (jit) if (jit)
v.var = jit->emitGetGlobal(node->id.getBox()); v.var = jit->emitGetGlobal(id.getBox());
v.o = getGlobal(frame_info.globals, node->id.getBox()); v.o = getGlobal(frame_info.globals, id.getBox());
return v; return v;
} }
case ScopeInfo::VarScopeType::DEREF: { case ScopeInfo::VarScopeType::DEREF: {
...@@ -1601,13 +1603,13 @@ Value ASTInterpreter::visit_loadname(BST_LoadName* node) { ...@@ -1601,13 +1603,13 @@ Value ASTInterpreter::visit_loadname(BST_LoadName* node) {
} }
if (is_live) if (is_live)
v.var = jit->emitGetLocal(node->id, node->vreg); v.var = jit->emitGetLocal(id, node->vreg);
else else
v.var = jit->emitGetBlockLocal(node->id, node->vreg); v.var = jit->emitGetBlockLocal(id, node->vreg);
} }
assert(node->vreg >= 0); assert(node->vreg >= 0);
assert(getVRegInfo().getVReg(node->id) == node->vreg); assert(getVRegInfo().getVReg(id) == node->vreg);
frame_info.num_vregs = std::max(frame_info.num_vregs, node->vreg + 1); frame_info.num_vregs = std::max(frame_info.num_vregs, node->vreg + 1);
Box* val = vregs[node->vreg]; Box* val = vregs[node->vreg];
...@@ -1617,14 +1619,14 @@ Value ASTInterpreter::visit_loadname(BST_LoadName* node) { ...@@ -1617,14 +1619,14 @@ Value ASTInterpreter::visit_loadname(BST_LoadName* node) {
return v; return v;
} }
assertNameDefined(0, node->id.c_str(), UnboundLocalError, true); assertNameDefined(0, id.c_str(), UnboundLocalError, true);
RELEASE_ASSERT(0, "should be unreachable"); RELEASE_ASSERT(0, "should be unreachable");
} }
case ScopeInfo::VarScopeType::NAME: { case ScopeInfo::VarScopeType::NAME: {
Value v; Value v;
if (jit) if (jit)
v.var = jit->emitGetBoxedLocal(node->id.getBox()); v.var = jit->emitGetBoxedLocal(id.getBox());
v.o = boxedLocalsGet(frame_info.boxedLocals, node->id.getBox(), frame_info.globals); v.o = boxedLocalsGet(frame_info.boxedLocals, id.getBox(), frame_info.globals);
return v; return v;
} }
default: default:
...@@ -1636,7 +1638,7 @@ Value ASTInterpreter::visit_loadattr(BST_LoadAttr* node) { ...@@ -1636,7 +1638,7 @@ Value ASTInterpreter::visit_loadattr(BST_LoadAttr* node) {
Value v = getVReg(node->vreg_value); Value v = getVReg(node->vreg_value);
AUTO_DECREF(v.o); AUTO_DECREF(v.o);
BoxedString* attr = node->attr.getBox(); BoxedString* attr = getCodeConstants().getInternedString(node->index_attr).getBox();
Value r; Value r;
if (node->clsonly) if (node->clsonly)
r = Value(getclsattr(v.o, attr), jit ? jit->emitGetClsAttr(v, attr) : NULL); r = Value(getclsattr(v.o, attr), jit ? jit->emitGetClsAttr(v, attr) : NULL);
...@@ -1680,7 +1682,7 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) { ...@@ -1680,7 +1682,7 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) {
assert(node->lookup_type != ScopeInfo::VarScopeType::UNKNOWN); assert(node->lookup_type != ScopeInfo::VarScopeType::UNKNOWN);
InternedString name = node->id; InternedString name = getCodeConstants().getInternedString(node->index_id);
ScopeInfo::VarScopeType vst = node->lookup_type; ScopeInfo::VarScopeType vst = node->lookup_type;
if (vst == ScopeInfo::VarScopeType::GLOBAL) { if (vst == ScopeInfo::VarScopeType::GLOBAL) {
if (jit) if (jit)
...@@ -1711,7 +1713,7 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) { ...@@ -1711,7 +1713,7 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) {
if (closure) { if (closure) {
ASTInterpreterJitInterface::setLocalClosureHelper(this, node->vreg, node->closure_offset, value.o); ASTInterpreterJitInterface::setLocalClosureHelper(this, node->vreg, node->closure_offset, value.o);
} else { } else {
assert(getVRegInfo().getVReg(node->id) == node->vreg); assert(getVRegInfo().getVReg(name) == node->vreg);
frame_info.num_vregs = std::max(frame_info.num_vregs, node->vreg + 1); frame_info.num_vregs = std::max(frame_info.num_vregs, node->vreg + 1);
Box* prev = vregs[node->vreg]; Box* prev = vregs[node->vreg];
vregs[node->vreg] = value.o; vregs[node->vreg] = value.o;
...@@ -1724,11 +1726,12 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) { ...@@ -1724,11 +1726,12 @@ void ASTInterpreter::visit_storename(BST_StoreName* node) {
void ASTInterpreter::visit_storeattr(BST_StoreAttr* node) { void ASTInterpreter::visit_storeattr(BST_StoreAttr* node) {
Value value = getVReg(node->vreg_value); Value value = getVReg(node->vreg_value);
Value o = getVReg(node->vreg_target); Value o = getVReg(node->vreg_target);
InternedString attr = getCodeConstants().getInternedString(node->index_attr);
if (jit) { if (jit) {
jit->emitSetAttr(node, o, node->attr.getBox(), value); jit->emitSetAttr(node, o, attr.getBox(), value);
} }
AUTO_DECREF(o.o); AUTO_DECREF(o.o);
pyston::setattr(o.o, node->attr.getBox(), value.o); pyston::setattr(o.o, attr.getBox(), value.o);
} }
void ASTInterpreter::visit_storesub(BST_StoreSub* node) { void ASTInterpreter::visit_storesub(BST_StoreSub* node) {
...@@ -1860,8 +1863,8 @@ Box* ASTInterpreterJitInterface::derefHelper(void* _interpreter, BST_LoadName* n ...@@ -1860,8 +1863,8 @@ Box* ASTInterpreterJitInterface::derefHelper(void* _interpreter, BST_LoadName* n
} }
Box* val = closure->elts[deref_info.offset]; Box* val = closure->elts[deref_info.offset];
if (val == NULL) { if (val == NULL) {
raiseExcHelper(NameError, "free variable '%s' referenced before assignment in enclosing scope", InternedString id = interpreter->getCodeConstants().getInternedString(node->index_id);
node->id.c_str()); raiseExcHelper(NameError, "free variable '%s' referenced before assignment in enclosing scope", id.c_str());
} }
Py_INCREF(val); Py_INCREF(val);
return val; return val;
......
This diff is collapsed.
...@@ -837,7 +837,7 @@ bool PrintVisitor::visit_callattr(BST_CallAttr* node) { ...@@ -837,7 +837,7 @@ bool PrintVisitor::visit_callattr(BST_CallAttr* node) {
visit_vreg(&node->vreg_dst, true); visit_vreg(&node->vreg_dst, true);
visit_vreg(&node->vreg_value); visit_vreg(&node->vreg_value);
stream << "."; stream << ".";
stream << node->attr.s(); stream << code_constants.getInternedString(node->index_attr).s();
stream << "("; stream << "(";
bool prevarg = false; bool prevarg = false;
...@@ -867,7 +867,7 @@ bool PrintVisitor::visit_callclsattr(BST_CallClsAttr* node) { ...@@ -867,7 +867,7 @@ bool PrintVisitor::visit_callclsattr(BST_CallClsAttr* node) {
visit_vreg(&node->vreg_dst, true); visit_vreg(&node->vreg_dst, true);
visit_vreg(&node->vreg_value); visit_vreg(&node->vreg_value);
stream << ":"; stream << ":";
stream << node->attr.s(); stream << code_constants.getInternedString(node->index_attr).s();
stream << "("; stream << "(";
bool prevarg = false; bool prevarg = false;
...@@ -909,7 +909,7 @@ bool PrintVisitor::visit_classdef(BST_ClassDef* node) { ...@@ -909,7 +909,7 @@ bool PrintVisitor::visit_classdef(BST_ClassDef* node) {
stream << "\n"; stream << "\n";
printIndent(); printIndent();
} }
stream << "class " << node->name.s() << "("; stream << "class " << code_constants.getInternedString(node->index_name).s() << "(";
visit_vreg(&node->vreg_bases_tuple); visit_vreg(&node->vreg_bases_tuple);
stream << ")"; stream << ")";
...@@ -954,7 +954,7 @@ bool PrintVisitor::visit_deleteattr(BST_DeleteAttr* node) { ...@@ -954,7 +954,7 @@ bool PrintVisitor::visit_deleteattr(BST_DeleteAttr* node) {
stream << "del "; stream << "del ";
visit_vreg(&node->vreg_value); visit_vreg(&node->vreg_value);
stream << '.'; stream << '.';
stream << node->attr.s(); stream << code_constants.getInternedString(node->index_attr).s();
return true; return true;
} }
bool PrintVisitor::visit_deletename(BST_DeleteName* node) { bool PrintVisitor::visit_deletename(BST_DeleteName* node) {
...@@ -963,7 +963,7 @@ bool PrintVisitor::visit_deletename(BST_DeleteName* node) { ...@@ -963,7 +963,7 @@ bool PrintVisitor::visit_deletename(BST_DeleteName* node) {
visit_vreg(&node->vreg); visit_vreg(&node->vreg);
stream << " "; stream << " ";
} }
stream << node->id.s(); stream << code_constants.getInternedString(node->index_id).s();
return true; return true;
} }
...@@ -999,8 +999,8 @@ bool PrintVisitor::visit_functiondef(BST_FunctionDef* node) { ...@@ -999,8 +999,8 @@ bool PrintVisitor::visit_functiondef(BST_FunctionDef* node) {
} }
stream << "def "; stream << "def ";
if (node->name != InternedString()) if (node->index_name != VREG_UNDEFINED)
stream << node->name.s(); stream << code_constants.getInternedString(node->index_name).s();
else else
stream << "<lambda>"; stream << "<lambda>";
stream << "("; stream << "(";
...@@ -1226,14 +1226,14 @@ bool PrintVisitor::visit_loadname(BST_LoadName* node) { ...@@ -1226,14 +1226,14 @@ bool PrintVisitor::visit_loadname(BST_LoadName* node) {
visit_vreg(&node->vreg); visit_vreg(&node->vreg);
stream << " "; stream << " ";
} }
stream << node->id.s(); stream << code_constants.getInternedString(node->index_id).s();
return true; return true;
} }
bool PrintVisitor::visit_loadattr(BST_LoadAttr* node) { bool PrintVisitor::visit_loadattr(BST_LoadAttr* node) {
visit_vreg(&node->vreg_dst, true); visit_vreg(&node->vreg_dst, true);
visit_vreg(&node->vreg_value); visit_vreg(&node->vreg_value);
stream << (node->clsonly ? ':' : '.') << node->attr.s(); stream << (node->clsonly ? ':' : '.') << code_constants.getInternedString(node->index_attr).s();
return true; return true;
} }
...@@ -1265,7 +1265,7 @@ bool PrintVisitor::visit_storename(BST_StoreName* node) { ...@@ -1265,7 +1265,7 @@ bool PrintVisitor::visit_storename(BST_StoreName* node) {
visit_vreg(&node->vreg); visit_vreg(&node->vreg);
stream << " "; stream << " ";
} }
stream << node->id.s(); stream << code_constants.getInternedString(node->index_id).s();
stream << " = "; stream << " = ";
visit_vreg(&node->vreg_value); visit_vreg(&node->vreg_value);
return true; return true;
...@@ -1273,7 +1273,7 @@ bool PrintVisitor::visit_storename(BST_StoreName* node) { ...@@ -1273,7 +1273,7 @@ bool PrintVisitor::visit_storename(BST_StoreName* node) {
bool PrintVisitor::visit_storeattr(BST_StoreAttr* node) { bool PrintVisitor::visit_storeattr(BST_StoreAttr* node) {
visit_vreg(&node->vreg_target); visit_vreg(&node->vreg_target);
stream << "." << node->attr.s() << " = "; stream << "." << code_constants.getInternedString(node->index_attr).s() << " = ";
visit_vreg(&node->vreg_value); visit_vreg(&node->vreg_value);
return true; return true;
} }
......
...@@ -258,7 +258,7 @@ class BST_StoreName : public BST_stmt { ...@@ -258,7 +258,7 @@ class BST_StoreName : public BST_stmt {
public: public:
int vreg_value = VREG_UNDEFINED; int vreg_value = VREG_UNDEFINED;
InternedString id; int index_id = VREG_UNDEFINED;
ScopeInfo::VarScopeType lookup_type; ScopeInfo::VarScopeType lookup_type;
int vreg = VREG_UNDEFINED; int vreg = VREG_UNDEFINED;
...@@ -272,7 +272,7 @@ public: ...@@ -272,7 +272,7 @@ public:
class BST_StoreAttr : public BST_stmt { class BST_StoreAttr : public BST_stmt {
public: public:
InternedString attr; int index_attr = VREG_UNDEFINED;
int vreg_target = VREG_UNDEFINED; int vreg_target = VREG_UNDEFINED;
int vreg_value = VREG_UNDEFINED; int vreg_value = VREG_UNDEFINED;
...@@ -299,7 +299,7 @@ public: ...@@ -299,7 +299,7 @@ public:
class BST_LoadName : public BST_stmt_with_dest { class BST_LoadName : public BST_stmt_with_dest {
public: public:
InternedString id; int index_id = VREG_UNDEFINED;
ScopeInfo::VarScopeType lookup_type; ScopeInfo::VarScopeType lookup_type;
// LoadName does not kill this vreg // LoadName does not kill this vreg
int vreg = VREG_UNDEFINED; int vreg = VREG_UNDEFINED;
...@@ -314,7 +314,7 @@ public: ...@@ -314,7 +314,7 @@ public:
class BST_LoadAttr : public BST_stmt_with_dest { class BST_LoadAttr : public BST_stmt_with_dest {
public: public:
InternedString attr; int index_attr = VREG_UNDEFINED;
int vreg_value = VREG_UNDEFINED; int vreg_value = VREG_UNDEFINED;
bool clsonly = false; bool clsonly = false;
...@@ -376,7 +376,7 @@ public: ...@@ -376,7 +376,7 @@ public:
class BST_CallAttr : public BST_Call { class BST_CallAttr : public BST_Call {
public: public:
int vreg_value = VREG_UNDEFINED; int vreg_value = VREG_UNDEFINED;
InternedString attr; int index_attr = VREG_UNDEFINED;
int elts[1]; int elts[1];
BSTVARVREGS2CALL(CallAttr, num_args, num_keywords, elts) BSTVARVREGS2CALL(CallAttr, num_args, num_keywords, elts)
...@@ -385,7 +385,7 @@ public: ...@@ -385,7 +385,7 @@ public:
class BST_CallClsAttr : public BST_Call { class BST_CallClsAttr : public BST_Call {
public: public:
int vreg_value = VREG_UNDEFINED; int vreg_value = VREG_UNDEFINED;
InternedString attr; int index_attr = VREG_UNDEFINED;
int elts[1]; int elts[1];
BSTVARVREGS2CALL(CallClsAttr, num_args, num_keywords, elts) BSTVARVREGS2CALL(CallClsAttr, num_args, num_keywords, elts)
...@@ -403,8 +403,8 @@ public: ...@@ -403,8 +403,8 @@ public:
class BST_ClassDef : public BST_stmt { class BST_ClassDef : public BST_stmt {
public: public:
InternedString name; int index_name = VREG_UNDEFINED;
int vreg_bases_tuple; int vreg_bases_tuple = VREG_UNDEFINED;
const int num_decorator; const int num_decorator;
int decorator[1]; int decorator[1];
...@@ -419,14 +419,14 @@ public: ...@@ -419,14 +419,14 @@ public:
class BST_DeleteAttr : public BST_stmt { class BST_DeleteAttr : public BST_stmt {
public: public:
int vreg_value = VREG_UNDEFINED; int vreg_value = VREG_UNDEFINED;
InternedString attr; int index_attr = VREG_UNDEFINED;
BSTFIXEDVREGS(DeleteAttr, BST_stmt) BSTFIXEDVREGS(DeleteAttr, BST_stmt)
}; };
class BST_DeleteName : public BST_stmt { class BST_DeleteName : public BST_stmt {
public: public:
InternedString id; int index_id = VREG_UNDEFINED;
ScopeInfo::VarScopeType lookup_type; ScopeInfo::VarScopeType lookup_type;
int vreg = VREG_UNDEFINED; int vreg = VREG_UNDEFINED;
...@@ -466,7 +466,7 @@ public: ...@@ -466,7 +466,7 @@ public:
class BST_FunctionDef : public BST_stmt { class BST_FunctionDef : public BST_stmt {
public: public:
InternedString name; // if the name is not set this is a lambda int index_name = VREG_UNDEFINED; // if the name is not set this is a lambda
const int num_decorator; const int num_decorator;
const int num_defaults; const int num_defaults;
......
This diff is collapsed.
...@@ -86,6 +86,14 @@ public: ...@@ -86,6 +86,14 @@ public:
bool isCompilerCreatedName() const; bool isCompilerCreatedName() const;
static InternedString unsafe(BoxedString* str) {
#ifndef NDEBUG
return InternedString(str, NULL);
#else
return InternedString(str);
#endif
}
friend class InternedStringPool; friend class InternedStringPool;
friend struct std::hash<InternedString>; friend struct std::hash<InternedString>;
friend struct std::less<InternedString>; friend struct std::less<InternedString>;
......
...@@ -1099,12 +1099,15 @@ public: ...@@ -1099,12 +1099,15 @@ public:
BORROWED(Box*) getConstant(int vreg) const { return constants[-(vreg + 1)]; } BORROWED(Box*) getConstant(int vreg) const { return constants[-(vreg + 1)]; }
InternedString getInternedString(int vreg) const { return InternedString::unsafe((BoxedString*)getConstant(vreg)); }
// returns the vreg num for the constant (which is a negative number) // returns the vreg num for the constant (which is a negative number)
int createVRegEntryForConstant(Box* o) { int createVRegEntryForConstant(Box* o) {
constants.push_back(o); constants.push_back(o);
return -constants.size(); return -constants.size();
} }
void addOwnedRef(Box* o) const { owned_refs.emplace_back(o); } void addOwnedRef(Box* o) const { owned_refs.emplace_back(o); }
BORROWED(BoxedInt*) getIntConstant(int64_t n) const; BORROWED(BoxedInt*) getIntConstant(int64_t n) const;
...@@ -1113,6 +1116,9 @@ public: ...@@ -1113,6 +1116,9 @@ public:
std::pair<BST_stmt*, BORROWED(BoxedCode*)> getFuncOrClass(int constant) const { std::pair<BST_stmt*, BORROWED(BoxedCode*)> getFuncOrClass(int constant) const {
return funcs_and_classes[constant]; return funcs_and_classes[constant];
} }
int addInternedString(InternedString s) { return createVRegEntryForConstant(s.getBox()); }
int addFuncOrClass(BST_stmt* stmt, STOLEN(BoxedCode*) code) { int addFuncOrClass(BST_stmt* stmt, STOLEN(BoxedCode*) code) {
funcs_and_classes.emplace_back(stmt, code); funcs_and_classes.emplace_back(stmt, code);
return funcs_and_classes.size() - 1; return funcs_and_classes.size() - 1;
......
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