Commit 283f90df authored by Travis Hance's avatar Travis Hance

remove the llvm::StringRef from BoxedString

parent 8802a933
...@@ -59,14 +59,14 @@ bool containsYield(AST* ast) { ...@@ -59,14 +59,14 @@ bool containsYield(AST* ast) {
BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) { BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) {
assert(id); assert(id);
assert(private_name); assert(private_name);
int len = id->s.size(); int len = id->size();
if (len < 2 || id->s[0] != '_' || id->s[1] != '_') if (len < 2 || id->s()[0] != '_' || id->s()[1] != '_')
return id; return id;
if ((id->s[len - 2] == '_' && id->s[len - 1] == '_') || id->s.find('.') != llvm::StringRef::npos) if ((id->s()[len - 2] == '_' && id->s()[len - 1] == '_') || id->s().find('.') != llvm::StringRef::npos)
return id; return id;
const char* p = private_name->s.data(); const char* p = private_name->data();
while (*p == '_') { while (*p == '_') {
p++; p++;
len--; len--;
...@@ -74,7 +74,7 @@ BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) { ...@@ -74,7 +74,7 @@ BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) {
if (*p == '\0') if (*p == '\0')
return id; return id;
return static_cast<BoxedString*>(boxStringTwine("_" + (p + id->s))); return static_cast<BoxedString*>(boxStringTwine("_" + (p + id->s())));
} }
static void mangleNameInPlace(InternedString& id, const std::string* private_name, static void mangleNameInPlace(InternedString& id, const std::string* private_name,
......
...@@ -421,9 +421,9 @@ extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept { ...@@ -421,9 +421,9 @@ extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept {
extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject* value) noexcept { extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject* value) noexcept {
try { try {
if (value == NULL) if (value == NULL)
delattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s), NULL); delattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s()), NULL);
else else
setattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s), value, NULL); setattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s()), value, NULL);
} catch (ExcInfo e) { } catch (ExcInfo e) {
setCAPIException(e); setCAPIException(e);
return -1; return -1;
...@@ -445,9 +445,9 @@ extern "C" int PyObject_SetAttr(PyObject* obj, PyObject* name, PyObject* value) ...@@ -445,9 +445,9 @@ extern "C" int PyObject_SetAttr(PyObject* obj, PyObject* name, PyObject* value)
try { try {
if (value == NULL) if (value == NULL)
delattr(obj, static_cast<BoxedString*>(name)->s.data()); delattr(obj, static_cast<BoxedString*>(name)->data());
else else
setattr(obj, static_cast<BoxedString*>(name)->s.data(), value); setattr(obj, static_cast<BoxedString*>(name)->data(), value);
} catch (ExcInfo e) { } catch (ExcInfo e) {
setCAPIException(e); setCAPIException(e);
return -1; return -1;
......
...@@ -1303,7 +1303,7 @@ Box* astInterpretFrom(CompiledFunction* cf, AST_expr* after_expr, AST_stmt* encl ...@@ -1303,7 +1303,7 @@ Box* astInterpretFrom(CompiledFunction* cf, AST_expr* after_expr, AST_stmt* encl
for (const auto& p : frame_state.locals->d) { for (const auto& p : frame_state.locals->d) {
assert(p.first->cls == str_cls); assert(p.first->cls == str_cls);
auto& name = static_cast<BoxedString*>(p.first)->s; auto name = static_cast<BoxedString*>(p.first)->s();
if (name == PASSED_GENERATOR_NAME) { if (name == PASSED_GENERATOR_NAME) {
interpreter.setGenerator(p.second); interpreter.setGenerator(p.second);
} else if (name == PASSED_CLOSURE_NAME) { } else if (name == PASSED_CLOSURE_NAME) {
......
...@@ -456,8 +456,8 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) { ...@@ -456,8 +456,8 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
} }
RELEASE_ASSERT(isSubclass(type->cls, str_cls), ""); RELEASE_ASSERT(isSubclass(type->cls, str_cls), "");
llvm::StringRef filename_str = static_cast<BoxedString*>(fn)->s; llvm::StringRef filename_str = static_cast<BoxedString*>(fn)->s();
llvm::StringRef type_str = static_cast<BoxedString*>(type)->s; llvm::StringRef type_str = static_cast<BoxedString*>(type)->s();
if (iflags & ~(/*PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | */ PyCF_ONLY_AST)) { if (iflags & ~(/*PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | */ PyCF_ONLY_AST)) {
raiseExcHelper(ValueError, "compile(): unrecognised flags"); raiseExcHelper(ValueError, "compile(): unrecognised flags");
...@@ -473,7 +473,7 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) { ...@@ -473,7 +473,7 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
parsed = unboxAst(source); parsed = unboxAst(source);
} else { } else {
RELEASE_ASSERT(isSubclass(source->cls, str_cls), ""); RELEASE_ASSERT(isSubclass(source->cls, str_cls), "");
llvm::StringRef source_str = static_cast<BoxedString*>(source)->s; llvm::StringRef source_str = static_cast<BoxedString*>(source)->s();
if (type_str == "exec") { if (type_str == "exec") {
parsed = parseExec(source_str); parsed = parseExec(source_str);
...@@ -542,7 +542,7 @@ Box* eval(Box* boxedCode, Box* globals, Box* locals) { ...@@ -542,7 +542,7 @@ Box* eval(Box* boxedCode, Box* globals, Box* locals) {
CLFunction* cl; CLFunction* cl;
if (boxedCode->cls == str_cls) { if (boxedCode->cls == str_cls) {
AST_Expression* parsed = parseEval(static_cast<BoxedString*>(boxedCode)->s); AST_Expression* parsed = parseEval(static_cast<BoxedString*>(boxedCode)->s());
cl = compileEval(parsed, "<string>"); cl = compileEval(parsed, "<string>");
} else if (boxedCode->cls == code_cls) { } else if (boxedCode->cls == code_cls) {
cl = clfunctionFromCode(boxedCode); cl = clfunctionFromCode(boxedCode);
...@@ -609,7 +609,7 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) { ...@@ -609,7 +609,7 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) {
CLFunction* cl; CLFunction* cl;
if (boxedCode->cls == str_cls) { if (boxedCode->cls == str_cls) {
AST_Suite* parsed = parseExec(static_cast<BoxedString*>(boxedCode)->s); AST_Suite* parsed = parseExec(static_cast<BoxedString*>(boxedCode)->s());
cl = compileExec(parsed, "<string>"); cl = compileExec(parsed, "<string>");
} else if (boxedCode->cls == code_cls) { } else if (boxedCode->cls == code_cls) {
cl = clfunctionFromCode(boxedCode); cl = clfunctionFromCode(boxedCode);
......
...@@ -932,7 +932,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi ...@@ -932,7 +932,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
BoxedString* str_utf8 = (BoxedString*)PyUnicode_AsUTF8String(str); BoxedString* str_utf8 = (BoxedString*)PyUnicode_AsUTF8String(str);
assert(str_utf8->cls == str_cls); assert(str_utf8->cls == str_cls);
checkAndThrowCAPIException(); checkAndThrowCAPIException();
return str_utf8->s.str(); return str_utf8->s().str();
} }
bool need_encoding = encoding != "utf-8" && encoding != "iso-8859-1"; bool need_encoding = encoding != "utf-8" && encoding != "iso-8859-1";
...@@ -943,7 +943,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi ...@@ -943,7 +943,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
throwCAPIException(); throwCAPIException();
BoxedString* str = (BoxedString*)PyUnicode_AsEncodedString(u, encoding.c_str(), NULL); BoxedString* str = (BoxedString*)PyUnicode_AsEncodedString(u, encoding.c_str(), NULL);
assert(str->cls == str_cls); assert(str->cls == str_cls);
return str->s.str(); return str->s().str();
} else { } else {
return s; return s;
} }
...@@ -954,12 +954,12 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi ...@@ -954,12 +954,12 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
if (!decoded) if (!decoded)
throwCAPIException(); throwCAPIException();
assert(decoded->cls == str_cls); assert(decoded->cls == str_cls);
return decoded->s.str(); return decoded->s().str();
} catch (ExcInfo e) { } catch (ExcInfo e) {
error = true; error = true;
BoxedString* error_message = str(e.value); BoxedString* error_message = str(e.value);
if (error_message && error_message->cls == str_cls) if (error_message && error_message->cls == str_cls)
return std::string(error_message->s); return std::string(error_message->s());
return "Encountered an unknown error inside pypaEscapeDecoder"; return "Encountered an unknown error inside pypaEscapeDecoder";
} }
} }
...@@ -1080,7 +1080,7 @@ std::string PystonSourceReader::get_line() { ...@@ -1080,7 +1080,7 @@ std::string PystonSourceReader::get_line() {
if (!line->size()) if (!line->size())
is_eof = true; is_eof = true;
++line_number; ++line_number;
return line->s; return line->s();
} }
AST_Module* pypa_parse(char const* file_path) { AST_Module* pypa_parse(char const* file_path) {
......
...@@ -2479,7 +2479,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) { ...@@ -2479,7 +2479,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
if (source->scoping->areGlobalsFromModule()) { if (source->scoping->areGlobalsFromModule()) {
Box* module_name = source->parent_module->getattr("__name__", NULL); Box* module_name = source->parent_module->getattr("__name__", NULL);
assert(module_name->cls == str_cls); assert(module_name->cls == str_cls);
module_assign->value = new AST_Str(static_cast<BoxedString*>(module_name)->s); module_assign->value = new AST_Str(static_cast<BoxedString*>(module_name)->s());
} else { } else {
module_assign->value module_assign->value
= new AST_Name(source->getInternedStrings().get("__name__"), AST_TYPE::Load, source->ast->lineno); = new AST_Name(source->getInternedStrings().get("__name__"), AST_TYPE::Load, source->ast->lineno);
......
...@@ -402,7 +402,7 @@ Box* bltinImport(Box* name, Box* globals, Box* locals, Box** args) { ...@@ -402,7 +402,7 @@ Box* bltinImport(Box* name, Box* globals, Box* locals, Box** args) {
raiseExcHelper(TypeError, "an integer is required"); raiseExcHelper(TypeError, "an integer is required");
} }
std::string _name = static_cast<BoxedString*>(name)->s; std::string _name = static_cast<BoxedString*>(name)->s();
return importModuleLevel(_name, globals, fromlist, ((BoxedInt*)level)->n); return importModuleLevel(_name, globals, fromlist, ((BoxedInt*)level)->n);
} }
...@@ -412,7 +412,7 @@ Box* delattrFunc(Box* obj, Box* _str) { ...@@ -412,7 +412,7 @@ Box* delattrFunc(Box* obj, Box* _str) {
if (_str->cls != str_cls) if (_str->cls != str_cls)
raiseExcHelper(TypeError, "attribute name must be string, not '%s'", getTypeName(_str)); raiseExcHelper(TypeError, "attribute name must be string, not '%s'", getTypeName(_str));
BoxedString* str = static_cast<BoxedString*>(_str); BoxedString* str = static_cast<BoxedString*>(_str);
delattr(obj, str->s.data()); delattr(obj, str->data());
return None; return None;
} }
...@@ -427,7 +427,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) { ...@@ -427,7 +427,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
Box* rtn = NULL; Box* rtn = NULL;
try { try {
rtn = getattr(obj, str->s.data()); rtn = getattr(obj, str->data());
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (!e.matches(AttributeError)) if (!e.matches(AttributeError))
throw e; throw e;
...@@ -437,7 +437,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) { ...@@ -437,7 +437,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
if (default_value) if (default_value)
return default_value; return default_value;
else else
raiseExcHelper(AttributeError, "'%s' object has no attribute '%s'", getTypeName(obj), str->s.data()); raiseExcHelper(AttributeError, "'%s' object has no attribute '%s'", getTypeName(obj), str->data());
} }
return rtn; return rtn;
...@@ -451,7 +451,7 @@ Box* setattrFunc(Box* obj, Box* _str, Box* value) { ...@@ -451,7 +451,7 @@ Box* setattrFunc(Box* obj, Box* _str, Box* value) {
} }
BoxedString* str = static_cast<BoxedString*>(_str); BoxedString* str = static_cast<BoxedString*>(_str);
setattr(obj, str->s.data(), value); setattr(obj, str->data(), value);
return None; return None;
} }
...@@ -465,7 +465,7 @@ Box* hasattr(Box* obj, Box* _str) { ...@@ -465,7 +465,7 @@ Box* hasattr(Box* obj, Box* _str) {
BoxedString* str = static_cast<BoxedString*>(_str); BoxedString* str = static_cast<BoxedString*>(_str);
Box* attr; Box* attr;
try { try {
attr = getattrInternal(obj, str->s, NULL); attr = getattrInternal(obj, str->s(), NULL);
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (e.matches(Exception)) if (e.matches(Exception))
return False; return False;
...@@ -672,7 +672,7 @@ Box* exceptionRepr(Box* b) { ...@@ -672,7 +672,7 @@ Box* exceptionRepr(Box* b) {
assert(message->cls == str_cls); assert(message->cls == str_cls);
BoxedString* message_s = static_cast<BoxedString*>(message); BoxedString* message_s = static_cast<BoxedString*>(message);
return boxStringTwine(llvm::Twine(getTypeName(b)) + "(" + message_s->s + ",)"); return boxStringTwine(llvm::Twine(getTypeName(b)) + "(" + message_s->s() + ",)");
} }
static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int size = 0) { static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int size = 0) {
...@@ -833,14 +833,14 @@ Box* execfile(Box* _fn) { ...@@ -833,14 +833,14 @@ Box* execfile(Box* _fn) {
#endif #endif
#else #else
bool exists = llvm::sys::fs::exists(std::string(fn->s)); bool exists = llvm::sys::fs::exists(std::string(fn->s()));
#endif #endif
if (!exists) if (!exists)
raiseExcHelper(IOError, "No such file or directory: '%s'", fn->s.data()); raiseExcHelper(IOError, "No such file or directory: '%s'", fn->data());
// Run directly inside the current module: // Run directly inside the current module:
AST_Module* ast = caching_parse_file(fn->s.data()); AST_Module* ast = caching_parse_file(fn->data());
ASSERT(getExecutionPoint().cf->clfunc->source->scoping->areGlobalsFromModule(), "need to pass custom globals in"); ASSERT(getExecutionPoint().cf->clfunc->source->scoping->areGlobalsFromModule(), "need to pass custom globals in");
compileAndRunModule(ast, getCurrentModule()); compileAndRunModule(ast, getCurrentModule());
......
...@@ -30,7 +30,7 @@ static Box* setOption(Box* option, Box* value) { ...@@ -30,7 +30,7 @@ static Box* setOption(Box* option, Box* value) {
int n = ((BoxedInt*)value)->n; int n = ((BoxedInt*)value)->n;
#define CHECK(_s) \ #define CHECK(_s) \
if (option_string->s == STRINGIFY(_s)) \ if (option_string->s() == STRINGIFY(_s)) \
_s = n _s = n
// :) // :)
...@@ -43,7 +43,7 @@ static Box* setOption(Box* option, Box* value) { ...@@ -43,7 +43,7 @@ static Box* setOption(Box* option, Box* value) {
else CHECK(REOPT_THRESHOLD_BASELINE); else CHECK(REOPT_THRESHOLD_BASELINE);
else CHECK(OSR_THRESHOLD_BASELINE); else CHECK(OSR_THRESHOLD_BASELINE);
else CHECK(SPECULATION_THRESHOLD); else CHECK(SPECULATION_THRESHOLD);
else raiseExcHelper(ValueError, "unknown option name '%s", option_string->s.data()); else raiseExcHelper(ValueError, "unknown option name '%s", option_string->data());
return None; return None;
} }
......
...@@ -168,7 +168,7 @@ public: ...@@ -168,7 +168,7 @@ public:
} }
static Box* setattrPyston(Box* obj, Box* name, Box* val) noexcept { static Box* setattrPyston(Box* obj, Box* name, Box* val) noexcept {
if (isSubclass(name->cls, str_cls) && static_cast<BoxedString*>(name)->s == "__dict__") { if (isSubclass(name->cls, str_cls) && static_cast<BoxedString*>(name)->s() == "__dict__") {
raiseExcHelper(AttributeError, "'%.50s' object attribute '__dict__' is read-only", Py_TYPE(obj)->tp_name); raiseExcHelper(AttributeError, "'%.50s' object attribute '__dict__' is read-only", Py_TYPE(obj)->tp_name);
} }
...@@ -189,7 +189,7 @@ public: ...@@ -189,7 +189,7 @@ public:
static Box* getattro(Box* obj, Box* name) noexcept { static Box* getattro(Box* obj, Box* name) noexcept {
assert(name->cls == str_cls); assert(name->cls == str_cls);
llvm::StringRef s = static_cast<BoxedString*>(name)->s; llvm::StringRef s = static_cast<BoxedString*>(name)->s();
Box* tls_obj = getThreadLocalObject(obj); Box* tls_obj = getThreadLocalObject(obj);
if (s == "__dict__") if (s == "__dict__")
......
...@@ -258,7 +258,7 @@ extern "C" PyObject* PyObject_GetAttr(PyObject* o, PyObject* attr_name) noexcept ...@@ -258,7 +258,7 @@ extern "C" PyObject* PyObject_GetAttr(PyObject* o, PyObject* attr_name) noexcept
extern "C" PyObject* PyObject_GenericGetAttr(PyObject* o, PyObject* name) noexcept { extern "C" PyObject* PyObject_GenericGetAttr(PyObject* o, PyObject* name) noexcept {
try { try {
Box* r = getattrInternalGeneric(o, static_cast<BoxedString*>(name)->s.data(), NULL, false, false, NULL, NULL); Box* r = getattrInternalGeneric(o, static_cast<BoxedString*>(name)->data(), NULL, false, false, NULL, NULL);
if (!r) if (!r)
PyErr_Format(PyExc_AttributeError, "'%.50s' object has no attribute '%.400s'", o->cls->tp_name, PyErr_Format(PyExc_AttributeError, "'%.50s' object has no attribute '%.400s'", o->cls->tp_name,
PyString_AS_STRING(name)); PyString_AS_STRING(name));
...@@ -868,7 +868,7 @@ extern "C" PyObject* PyImport_Import(PyObject* module_name) noexcept { ...@@ -868,7 +868,7 @@ extern "C" PyObject* PyImport_Import(PyObject* module_name) noexcept {
RELEASE_ASSERT(module_name->cls == str_cls, ""); RELEASE_ASSERT(module_name->cls == str_cls, "");
try { try {
std::string _module_name = static_cast<BoxedString*>(module_name)->s; std::string _module_name = static_cast<BoxedString*>(module_name)->s();
return importModuleLevel(_module_name, None, None, -1); return importModuleLevel(_module_name, None, None, -1);
} catch (ExcInfo e) { } catch (ExcInfo e) {
fatalOrError(PyExc_NotImplementedError, "unimplemented"); fatalOrError(PyExc_NotImplementedError, "unimplemented");
......
...@@ -104,7 +104,7 @@ Box* classobjNew(Box* _cls, Box* _name, Box* _bases, Box** _args) { ...@@ -104,7 +104,7 @@ Box* classobjNew(Box* _cls, Box* _name, Box* _bases, Box** _args) {
for (auto& p : dict->d) { for (auto& p : dict->d) {
RELEASE_ASSERT(p.first->cls == str_cls, ""); RELEASE_ASSERT(p.first->cls == str_cls, "");
made->setattr(std::string(static_cast<BoxedString*>(p.first)->s), p.second, NULL); made->setattr(std::string(static_cast<BoxedString*>(p.first)->s()), p.second, NULL);
} }
// Note: make sure to do this after assigning the attrs, since it will overwrite any defined __name__ // Note: make sure to do this after assigning the attrs, since it will overwrite any defined __name__
...@@ -148,21 +148,21 @@ static Box* classobjGetattribute(Box* _cls, Box* _attr) { ...@@ -148,21 +148,21 @@ static Box* classobjGetattribute(Box* _cls, Box* _attr) {
BoxedString* attr = static_cast<BoxedString*>(_attr); BoxedString* attr = static_cast<BoxedString*>(_attr);
// These are special cases in CPython as well: // These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') { if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s == "__dict__") if (attr->s() == "__dict__")
return cls->getAttrWrapper(); return cls->getAttrWrapper();
if (attr->s == "__bases__") if (attr->s() == "__bases__")
return cls->bases; return cls->bases;
if (attr->s == "__name__") { if (attr->s() == "__name__") {
if (cls->name) if (cls->name)
return cls->name; return cls->name;
return None; return None;
} }
} }
Box* r = classLookup(cls, std::string(attr->s)); Box* r = classLookup(cls, std::string(attr->s()));
if (!r) if (!r)
raiseExcHelper(AttributeError, "class %s has no attribute '%s'", cls->name->data(), attr->data()); raiseExcHelper(AttributeError, "class %s has no attribute '%s'", cls->name->data(), attr->data());
...@@ -206,7 +206,7 @@ static void classobjSetattr(Box* _cls, Box* _attr, Box* _value) { ...@@ -206,7 +206,7 @@ static void classobjSetattr(Box* _cls, Box* _attr, Box* _value) {
RELEASE_ASSERT(_attr->cls == str_cls, ""); RELEASE_ASSERT(_attr->cls == str_cls, "");
BoxedString* attr = static_cast<BoxedString*>(_attr); BoxedString* attr = static_cast<BoxedString*>(_attr);
if (attr->s == "__bases__") { if (attr->s() == "__bases__") {
const char* error_str = set_bases((PyClassObject*)cls, _value); const char* error_str = set_bases((PyClassObject*)cls, _value);
if (error_str && error_str[0] != '\0') if (error_str && error_str[0] != '\0')
raiseExcHelper(TypeError, "%s", error_str); raiseExcHelper(TypeError, "%s", error_str);
...@@ -242,7 +242,7 @@ Box* classobjStr(Box* _obj) { ...@@ -242,7 +242,7 @@ Box* classobjStr(Box* _obj) {
Box* _mod = cls->getattr("__module__"); Box* _mod = cls->getattr("__module__");
RELEASE_ASSERT(_mod, ""); RELEASE_ASSERT(_mod, "");
RELEASE_ASSERT(_mod->cls == str_cls, ""); RELEASE_ASSERT(_mod->cls == str_cls, "");
return boxStringTwine(llvm::Twine(static_cast<BoxedString*>(_mod)->s) + "." + cls->name->s); return boxStringTwine(llvm::Twine(static_cast<BoxedString*>(_mod)->s()) + "." + cls->name->s());
} }
static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing) { static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing) {
...@@ -253,19 +253,19 @@ static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing) ...@@ -253,19 +253,19 @@ static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing)
BoxedString* attr = static_cast<BoxedString*>(_attr); BoxedString* attr = static_cast<BoxedString*>(_attr);
// These are special cases in CPython as well: // These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') { if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s == "__dict__") if (attr->s() == "__dict__")
return inst->getAttrWrapper(); return inst->getAttrWrapper();
if (attr->s == "__class__") if (attr->s() == "__class__")
return inst->inst_cls; return inst->inst_cls;
} }
Box* r = inst->getattr(attr->s); Box* r = inst->getattr(attr->s());
if (r) if (r)
return r; return r;
r = classLookup(inst->inst_cls, attr->s); r = classLookup(inst->inst_cls, attr->s());
if (r) { if (r) {
return processDescriptor(r, inst, inst->inst_cls); return processDescriptor(r, inst, inst->inst_cls);
} }
...@@ -308,11 +308,11 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) { ...@@ -308,11 +308,11 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
assert(value); assert(value);
// These are special cases in CPython as well: // These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') { if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s == "__dict__") if (attr->s() == "__dict__")
Py_FatalError("unimplemented"); Py_FatalError("unimplemented");
if (attr->s == "__class__") { if (attr->s() == "__class__") {
if (value->cls != classobj_cls) if (value->cls != classobj_cls)
raiseExcHelper(TypeError, "__class__ must be set to a class"); raiseExcHelper(TypeError, "__class__ must be set to a class");
...@@ -329,7 +329,7 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) { ...@@ -329,7 +329,7 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
return runtimeCall(setattr, ArgPassSpec(2), _attr, value, NULL, NULL, NULL); return runtimeCall(setattr, ArgPassSpec(2), _attr, value, NULL, NULL, NULL);
} }
_inst->setattr(attr->s, value, NULL); _inst->setattr(attr->s(), value, NULL);
return None; return None;
} }
...@@ -341,11 +341,11 @@ Box* instanceDelattr(Box* _inst, Box* _attr) { ...@@ -341,11 +341,11 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
BoxedString* attr = static_cast<BoxedString*>(_attr); BoxedString* attr = static_cast<BoxedString*>(_attr);
// These are special cases in CPython as well: // These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') { if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s == "__dict__") if (attr->s() == "__dict__")
raiseExcHelper(TypeError, "__dict__ must be set to a dictionary"); raiseExcHelper(TypeError, "__dict__ must be set to a dictionary");
if (attr->s == "__class__") if (attr->s() == "__class__")
raiseExcHelper(TypeError, "__class__ must be set to a class"); raiseExcHelper(TypeError, "__class__ must be set to a class");
} }
...@@ -357,7 +357,7 @@ Box* instanceDelattr(Box* _inst, Box* _attr) { ...@@ -357,7 +357,7 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
return runtimeCall(delattr, ArgPassSpec(1), _attr, NULL, NULL, NULL, NULL); return runtimeCall(delattr, ArgPassSpec(1), _attr, NULL, NULL, NULL, NULL);
} }
_inst->delattr(attr->s, NULL); _inst->delattr(attr->s(), NULL);
return None; return None;
} }
......
...@@ -38,10 +38,10 @@ Box* dictRepr(BoxedDict* self) { ...@@ -38,10 +38,10 @@ Box* dictRepr(BoxedDict* self) {
BoxedString* k = static_cast<BoxedString*>(repr(p.first)); BoxedString* k = static_cast<BoxedString*>(repr(p.first));
BoxedString* v = static_cast<BoxedString*>(repr(p.second)); BoxedString* v = static_cast<BoxedString*>(repr(p.second));
chars.insert(chars.end(), k->s.begin(), k->s.end()); chars.insert(chars.end(), k->s().begin(), k->s().end());
chars.push_back(':'); chars.push_back(':');
chars.push_back(' '); chars.push_back(' ');
chars.insert(chars.end(), v->s.begin(), v->s.end()); chars.insert(chars.end(), v->s().begin(), v->s().end());
} }
chars.push_back('}'); chars.push_back('}');
return boxString(llvm::StringRef(&chars[0], chars.size())); return boxString(llvm::StringRef(&chars[0], chars.size()));
......
...@@ -971,7 +971,7 @@ Box* fileNew(BoxedClass* cls, Box* s, Box* m, Box** args) { ...@@ -971,7 +971,7 @@ Box* fileNew(BoxedClass* cls, Box* s, Box* m, Box** args) {
abort(); // unreachable; abort(); // unreachable;
} }
auto file = new BoxedFile(f, fn->s, PyString_AsString(m)); auto file = new BoxedFile(f, fn->s(), PyString_AsString(m));
PyFile_SetBufSize(file, buffering->n); PyFile_SetBufSize(file, buffering->n);
return file; return file;
} }
...@@ -1110,7 +1110,7 @@ error: ...@@ -1110,7 +1110,7 @@ error:
Box* fileIterNext(BoxedFile* s) { Box* fileIterNext(BoxedFile* s) {
Box* rtn = fileReadline1(s); Box* rtn = fileReadline1(s);
assert(!rtn || rtn->cls == str_cls); assert(!rtn || rtn->cls == str_cls);
if (!rtn || ((BoxedString*)rtn)->s.empty()) if (!rtn || ((BoxedString*)rtn)->s().empty())
raiseExcHelper(StopIteration, ""); raiseExcHelper(StopIteration, "");
return rtn; return rtn;
} }
......
...@@ -627,7 +627,7 @@ BoxedFloat* _floatNew(Box* a) { ...@@ -627,7 +627,7 @@ BoxedFloat* _floatNew(Box* a) {
} else if (isSubclass(a->cls, int_cls)) { } else if (isSubclass(a->cls, int_cls)) {
return new BoxedFloat(static_cast<BoxedInt*>(a)->n); return new BoxedFloat(static_cast<BoxedInt*>(a)->n);
} else if (a->cls == str_cls) { } else if (a->cls == str_cls) {
const std::string& s = static_cast<BoxedString*>(a)->s; const std::string& s = static_cast<BoxedString*>(a)->s();
if (s == "nan") if (s == "nan")
return new BoxedFloat(NAN); return new BoxedFloat(NAN);
if (s == "-nan") if (s == "-nan")
......
...@@ -220,7 +220,7 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B ...@@ -220,7 +220,7 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
BoxedString* p = static_cast<BoxedString*>(_p); BoxedString* p = static_cast<BoxedString*>(_p);
joined_path.clear(); joined_path.clear();
llvm::sys::path::append(joined_path, std::string(p->s), name); llvm::sys::path::append(joined_path, std::string(p->s()), name);
std::string dn(joined_path.str()); std::string dn(joined_path.str());
llvm::sys::path::append(joined_path, "__init__.py"); llvm::sys::path::append(joined_path, "__init__.py");
...@@ -242,14 +242,14 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B ...@@ -242,14 +242,14 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
return SearchResult(std::move(dn), SearchResult::PKG_DIRECTORY); return SearchResult(std::move(dn), SearchResult::PKG_DIRECTORY);
joined_path.clear(); joined_path.clear();
llvm::sys::path::append(joined_path, std::string(p->s), name + ".py"); llvm::sys::path::append(joined_path, std::string(p->s()), name + ".py");
fn = joined_path.str(); fn = joined_path.str();
if (pathExists(fn)) if (pathExists(fn))
return SearchResult(std::move(fn), SearchResult::PY_SOURCE); return SearchResult(std::move(fn), SearchResult::PY_SOURCE);
joined_path.clear(); joined_path.clear();
llvm::sys::path::append(joined_path, p->s, name + ".pyston.so"); llvm::sys::path::append(joined_path, p->s(), name + ".pyston.so");
fn = joined_path.str(); fn = joined_path.str();
if (pathExists(fn)) if (pathExists(fn))
...@@ -291,7 +291,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) { ...@@ -291,7 +291,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
if (len > PATH_MAX) { if (len > PATH_MAX) {
raiseExcHelper(ValueError, "Package name too long"); raiseExcHelper(ValueError, "Package name too long");
} }
buf += pkgname->s; buf += pkgname->s();
} else { } else {
/* __package__ not set, so figure it out and set it */ /* __package__ not set, so figure it out and set it */
BoxedString* modname = static_cast<BoxedString*>(getFromGlobals(globals, name_str)); BoxedString* modname = static_cast<BoxedString*>(getFromGlobals(globals, name_str));
...@@ -305,11 +305,11 @@ static Box* getParent(Box* globals, int level, std::string& buf) { ...@@ -305,11 +305,11 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
if (modname->size() > PATH_MAX) { if (modname->size() > PATH_MAX) {
raiseExcHelper(ValueError, "Module name too long"); raiseExcHelper(ValueError, "Module name too long");
} }
buf += modname->s; buf += modname->s();
setGlobal(globals, package_str, modname); setGlobal(globals, package_str, modname);
} else { } else {
/* Normal module, so work out the package name if any */ /* Normal module, so work out the package name if any */
size_t lastdot = modname->s.rfind('.'); size_t lastdot = modname->s().rfind('.');
if (lastdot == std::string::npos && level > 0) { if (lastdot == std::string::npos && level > 0) {
raiseExcHelper(ValueError, "Attempted relative import in non-package"); raiseExcHelper(ValueError, "Attempted relative import in non-package");
} }
...@@ -321,7 +321,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) { ...@@ -321,7 +321,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
raiseExcHelper(ValueError, "Module name too long"); raiseExcHelper(ValueError, "Module name too long");
} }
buf = std::string(modname->s, 0, lastdot); buf = std::string(modname->s(), 0, lastdot);
setGlobal(globals, package_str, boxStringPtr(&buf)); setGlobal(globals, package_str, boxStringPtr(&buf));
} }
} }
...@@ -562,7 +562,7 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re ...@@ -562,7 +562,7 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
assert(_s->cls == str_cls); assert(_s->cls == str_cls);
BoxedString* s = static_cast<BoxedString*>(_s); BoxedString* s = static_cast<BoxedString*>(_s);
if (s->s[0] == '*') { if (s->s()[0] == '*') {
// If __all__ contains a '*', just skip it: // If __all__ contains a '*', just skip it:
if (recursive) if (recursive)
continue; continue;
...@@ -574,12 +574,12 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re ...@@ -574,12 +574,12 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
continue; continue;
} }
Box* attr = getattrInternal(module, s->s, NULL); Box* attr = getattrInternal(module, s->s(), NULL);
if (attr != NULL) if (attr != NULL)
continue; continue;
// Just want to import it and add it to the modules list for now: // Just want to import it and add it to the modules list for now:
importSub(s->s, (llvm::Twine(buf) + "." + s->s).str(), module); importSub(s->s(), (llvm::Twine(buf) + "." + s->s()).str(), module);
} }
} }
...@@ -651,7 +651,7 @@ Box* nullImporterInit(Box* self, Box* _path) { ...@@ -651,7 +651,7 @@ Box* nullImporterInit(Box* self, Box* _path) {
raiseExcHelper(TypeError, "must be string, not %s", getTypeName(_path)); raiseExcHelper(TypeError, "must be string, not %s", getTypeName(_path));
BoxedString* path = (BoxedString*)_path; BoxedString* path = (BoxedString*)_path;
if (path->s.empty()) if (path->s().empty())
raiseExcHelper(ImportError, "empty pathname"); raiseExcHelper(ImportError, "empty pathname");
if (isdir(path->data())) if (isdir(path->data()))
...@@ -676,7 +676,7 @@ Box* impFindModule(Box* _name, BoxedList* path) { ...@@ -676,7 +676,7 @@ Box* impFindModule(Box* _name, BoxedList* path) {
BoxedString* name = static_cast<BoxedString*>(_name); BoxedString* name = static_cast<BoxedString*>(_name);
BoxedList* path_list = path && path != None ? path : getSysPath(); BoxedList* path_list = path && path != None ? path : getSysPath();
SearchResult sr = findModule(name->s, name->s, path_list); SearchResult sr = findModule(name->s(), name->s(), path_list);
if (sr.type == SearchResult::SEARCH_ERROR) if (sr.type == SearchResult::SEARCH_ERROR)
raiseExcHelper(ImportError, "%s", name->data()); raiseExcHelper(ImportError, "%s", name->data());
...@@ -726,13 +726,13 @@ Box* impLoadModule(Box* _name, Box* _file, Box* _pathname, Box** args) { ...@@ -726,13 +726,13 @@ Box* impLoadModule(Box* _name, Box* _file, Box* _pathname, Box** args) {
if (type->n == SearchResult::PKG_DIRECTORY) { if (type->n == SearchResult::PKG_DIRECTORY) {
RELEASE_ASSERT(suffix->cls == str_cls, ""); RELEASE_ASSERT(suffix->cls == str_cls, "");
RELEASE_ASSERT(suffix->s.empty(), ""); RELEASE_ASSERT(suffix->s().empty(), "");
RELEASE_ASSERT(mode->s.empty(), ""); RELEASE_ASSERT(mode->s().empty(), "");
RELEASE_ASSERT(_file == None, ""); RELEASE_ASSERT(_file == None, "");
return createAndRunModule(name->s, (llvm::Twine(pathname->s) + "/__init__.py").str(), pathname->s); return createAndRunModule(name->s(), (llvm::Twine(pathname->s()) + "/__init__.py").str(), pathname->s());
} else if (type->n == SearchResult::PY_SOURCE) { } else if (type->n == SearchResult::PY_SOURCE) {
RELEASE_ASSERT(_file->cls == file_cls, ""); RELEASE_ASSERT(_file->cls == file_cls, "");
return createAndRunModule(name->s, pathname->s); return createAndRunModule(name->s(), pathname->s());
} }
Py_FatalError("unimplemented"); Py_FatalError("unimplemented");
...@@ -744,7 +744,7 @@ Box* impLoadSource(Box* _name, Box* _pathname, Box* _file) { ...@@ -744,7 +744,7 @@ Box* impLoadSource(Box* _name, Box* _pathname, Box* _file) {
RELEASE_ASSERT(_name->cls == str_cls, ""); RELEASE_ASSERT(_name->cls == str_cls, "");
RELEASE_ASSERT(_pathname->cls == str_cls, ""); RELEASE_ASSERT(_pathname->cls == str_cls, "");
return createAndRunModule(static_cast<BoxedString*>(_name)->s, static_cast<BoxedString*>(_pathname)->s); return createAndRunModule(static_cast<BoxedString*>(_name)->s(), static_cast<BoxedString*>(_pathname)->s());
} }
Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) { Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) {
...@@ -755,16 +755,16 @@ Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) { ...@@ -755,16 +755,16 @@ Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) {
BoxedString* name = (BoxedString*)_name; BoxedString* name = (BoxedString*)_name;
BoxedString* pathname = (BoxedString*)_pathname; BoxedString* pathname = (BoxedString*)_pathname;
const char* lastdot = strrchr(name->s.data(), '.'); const char* lastdot = strrchr(name->s().data(), '.');
const char* shortname; const char* shortname;
if (lastdot == NULL) { if (lastdot == NULL) {
shortname = name->s.data(); shortname = name->s().data();
} else { } else {
shortname = lastdot + 1; shortname = lastdot + 1;
} }
return importCExtension(name->s, shortname, pathname->s); return importCExtension(name->s(), shortname, pathname->s());
} }
Box* impGetSuffixes() { Box* impGetSuffixes() {
......
...@@ -76,7 +76,7 @@ extern "C" Box* listRepr(BoxedList* self) { ...@@ -76,7 +76,7 @@ extern "C" Box* listRepr(BoxedList* self) {
assert(r->cls == str_cls); assert(r->cls == str_cls);
BoxedString* s = static_cast<BoxedString*>(r); BoxedString* s = static_cast<BoxedString*>(r);
os << s->s; os << s->s();
} }
os << ']'; os << ']';
return boxString(os.str()); return boxString(os.str());
......
...@@ -566,7 +566,7 @@ BoxedLong* _longNew(Box* val, Box* _base) { ...@@ -566,7 +566,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
raiseExcHelper(TypeError, "long() can't convert non-string with explicit base"); raiseExcHelper(TypeError, "long() can't convert non-string with explicit base");
BoxedString* s = static_cast<BoxedString*>(val); BoxedString* s = static_cast<BoxedString*>(val);
rtn = (BoxedLong*)PyLong_FromString(s->s.str().c_str(), NULL, base); rtn = (BoxedLong*)PyLong_FromString(s->data(), NULL, base);
checkAndThrowCAPIException(); checkAndThrowCAPIException();
} else { } else {
if (isSubclass(val->cls, long_cls)) { if (isSubclass(val->cls, long_cls)) {
...@@ -579,7 +579,7 @@ BoxedLong* _longNew(Box* val, Box* _base) { ...@@ -579,7 +579,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
} else if (isSubclass(val->cls, int_cls)) { } else if (isSubclass(val->cls, int_cls)) {
mpz_init_set_si(rtn->n, static_cast<BoxedInt*>(val)->n); mpz_init_set_si(rtn->n, static_cast<BoxedInt*>(val)->n);
} else if (val->cls == str_cls) { } else if (val->cls == str_cls) {
const std::string& s = static_cast<BoxedString*>(val)->s; const std::string& s = static_cast<BoxedString*>(val)->s();
int r = mpz_init_set_str(rtn->n, s.c_str(), 10); int r = mpz_init_set_str(rtn->n, s.c_str(), 10);
RELEASE_ASSERT(r == 0, ""); RELEASE_ASSERT(r == 0, "");
} else if (val->cls == float_cls) { } else if (val->cls == float_cls) {
......
...@@ -146,7 +146,7 @@ bool PyEq::operator()(Box* lhs, Box* rhs) const { ...@@ -146,7 +146,7 @@ bool PyEq::operator()(Box* lhs, Box* rhs) const {
if (lhs->cls == rhs->cls) { if (lhs->cls == rhs->cls) {
if (lhs->cls == str_cls) { if (lhs->cls == str_cls) {
return static_cast<BoxedString*>(lhs)->s == static_cast<BoxedString*>(rhs)->s; return static_cast<BoxedString*>(lhs)->s() == static_cast<BoxedString*>(rhs)->s();
} }
} }
...@@ -464,7 +464,7 @@ std::string getFullNameOfClass(BoxedClass* cls) { ...@@ -464,7 +464,7 @@ std::string getFullNameOfClass(BoxedClass* cls) {
BoxedString* module = static_cast<BoxedString*>(b); BoxedString* module = static_cast<BoxedString*>(b);
return (llvm::Twine(module->s) + "." + cls->tp_name).str(); return (llvm::Twine(module->s()) + "." + cls->tp_name).str();
} }
std::string getFullTypeName(Box* o) { std::string getFullTypeName(Box* o) {
...@@ -3104,7 +3104,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe ...@@ -3104,7 +3104,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
if (param_names.takes_param_names) { if (param_names.takes_param_names) {
assert(!rewrite_args && "would need to make sure that this didn't need to go into r_kwargs"); assert(!rewrite_args && "would need to make sure that this didn't need to go into r_kwargs");
placeKeyword(param_names, params_filled, s->s, p.second, oarg1, oarg2, oarg3, oargs, okwargs, f); placeKeyword(param_names, params_filled, s->s(), p.second, oarg1, oarg2, oarg3, oargs, okwargs, f);
} else { } else {
assert(!rewrite_args && "would need to make sure that this didn't need to go into r_kwargs"); assert(!rewrite_args && "would need to make sure that this didn't need to go into r_kwargs");
assert(okwargs); assert(okwargs);
...@@ -4261,14 +4261,14 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) { ...@@ -4261,14 +4261,14 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
Box* tmp = slots[i]; Box* tmp = slots[i];
assertValidSlotIdentifier(tmp); assertValidSlotIdentifier(tmp);
assert(PyString_Check(tmp)); assert(PyString_Check(tmp));
if (static_cast<BoxedString*>(tmp)->s == "__dict__") { if (static_cast<BoxedString*>(tmp)->s() == "__dict__") {
if (!may_add_dict || add_dict) { if (!may_add_dict || add_dict) {
raiseExcHelper(TypeError, "__dict__ slot disallowed: " raiseExcHelper(TypeError, "__dict__ slot disallowed: "
"we already got one"); "we already got one");
} }
add_dict++; add_dict++;
continue; continue;
} else if (static_cast<BoxedString*>(tmp)->s == "__weakref__") { } else if (static_cast<BoxedString*>(tmp)->s() == "__weakref__") {
if (!may_add_weak || add_weak) { if (!may_add_weak || add_weak) {
raiseExcHelper(TypeError, "__weakref__ slot disallowed: " raiseExcHelper(TypeError, "__weakref__ slot disallowed: "
"either we already got one, " "either we already got one, "
...@@ -4356,7 +4356,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) { ...@@ -4356,7 +4356,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
// Add the member descriptors // Add the member descriptors
size_t offset = base->tp_basicsize; size_t offset = base->tp_basicsize;
for (size_t i = 0; i < final_slot_names.size(); i++) { for (size_t i = 0; i < final_slot_names.size(); i++) {
made->giveAttr(static_cast<BoxedString*>(slotsTuple->elts[i])->s.data(), made->giveAttr(static_cast<BoxedString*>(slotsTuple->elts[i])->data(),
new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT_EX, offset, false /* read only */)); new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT_EX, offset, false /* read only */));
slot_offsets[i] = offset; slot_offsets[i] = offset;
offset += sizeof(Box*); offset += sizeof(Box*);
...@@ -4381,7 +4381,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) { ...@@ -4381,7 +4381,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
auto k = coerceUnicodeToStr(p.first); auto k = coerceUnicodeToStr(p.first);
RELEASE_ASSERT(k->cls == str_cls, ""); RELEASE_ASSERT(k->cls == str_cls, "");
made->setattr(static_cast<BoxedString*>(k)->s, p.second, NULL); made->setattr(static_cast<BoxedString*>(k)->s(), p.second, NULL);
} }
if (!made->hasattr("__module__")) { if (!made->hasattr("__module__")) {
...@@ -4911,11 +4911,11 @@ extern "C" Box* importStar(Box* _from_module, Box* to_globals) { ...@@ -4911,11 +4911,11 @@ extern "C" Box* importStar(Box* _from_module, Box* to_globals) {
raiseExcHelper(TypeError, "attribute name must be string, not '%s'", getTypeName(attr_name)); raiseExcHelper(TypeError, "attribute name must be string, not '%s'", getTypeName(attr_name));
BoxedString* casted_attr_name = static_cast<BoxedString*>(attr_name); BoxedString* casted_attr_name = static_cast<BoxedString*>(attr_name);
Box* attr_value = from_module->getattr(casted_attr_name->s); Box* attr_value = from_module->getattr(casted_attr_name->s());
if (!attr_value) if (!attr_value)
raiseExcHelper(AttributeError, "'module' object has no attribute '%s'", casted_attr_name->data()); raiseExcHelper(AttributeError, "'module' object has no attribute '%s'", casted_attr_name->data());
setGlobal(to_globals, casted_attr_name->s, attr_value); setGlobal(to_globals, casted_attr_name->s(), attr_value);
} }
return None; return None;
} }
......
...@@ -106,7 +106,7 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) { ...@@ -106,7 +106,7 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
if (!first) { if (!first) {
os << ", "; os << ", ";
} }
os << static_cast<BoxedString*>(repr(elt))->s; os << static_cast<BoxedString*>(repr(elt))->s();
first = false; first = false;
} }
os << "])"; os << "])";
......
...@@ -52,7 +52,7 @@ extern "C" PyObject* string_splitlines(PyStringObject* self, PyObject* args) noe ...@@ -52,7 +52,7 @@ extern "C" PyObject* string_splitlines(PyStringObject* self, PyObject* args) noe
namespace pyston { namespace pyston {
BoxedString::BoxedString(const char* s, size_t n) : s(storage(), n), interned_state(SSTATE_NOT_INTERNED) { BoxedString::BoxedString(const char* s, size_t n) : interned_state(SSTATE_NOT_INTERNED) {
RELEASE_ASSERT(n != llvm::StringRef::npos, ""); RELEASE_ASSERT(n != llvm::StringRef::npos, "");
if (s) { if (s) {
memmove(data(), s, n); memmove(data(), s, n);
...@@ -62,21 +62,20 @@ BoxedString::BoxedString(const char* s, size_t n) : s(storage(), n), interned_st ...@@ -62,21 +62,20 @@ BoxedString::BoxedString(const char* s, size_t n) : s(storage(), n), interned_st
} }
} }
BoxedString::BoxedString(llvm::StringRef lhs, llvm::StringRef rhs) BoxedString::BoxedString(llvm::StringRef lhs, llvm::StringRef rhs) : interned_state(SSTATE_NOT_INTERNED) {
: s(storage(), lhs.size() + rhs.size()), interned_state(SSTATE_NOT_INTERNED) {
RELEASE_ASSERT(lhs.size() + rhs.size() != llvm::StringRef::npos, ""); RELEASE_ASSERT(lhs.size() + rhs.size() != llvm::StringRef::npos, "");
memmove(data(), lhs.data(), lhs.size()); memmove(data(), lhs.data(), lhs.size());
memmove(data() + lhs.size(), rhs.data(), rhs.size()); memmove(data() + lhs.size(), rhs.data(), rhs.size());
data()[lhs.size() + rhs.size()] = 0; data()[lhs.size() + rhs.size()] = 0;
} }
BoxedString::BoxedString(llvm::StringRef s) : s(storage(), s.size()), interned_state(SSTATE_NOT_INTERNED) { BoxedString::BoxedString(llvm::StringRef s) : interned_state(SSTATE_NOT_INTERNED) {
RELEASE_ASSERT(s.size() != llvm::StringRef::npos, ""); RELEASE_ASSERT(s.size() != llvm::StringRef::npos, "");
memmove(data(), s.data(), s.size()); memmove(data(), s.data(), s.size());
data()[s.size()] = 0; data()[s.size()] = 0;
} }
BoxedString::BoxedString(size_t n, char c) : s(storage(), n), interned_state(SSTATE_NOT_INTERNED) { BoxedString::BoxedString(size_t n, char c) : interned_state(SSTATE_NOT_INTERNED) {
RELEASE_ASSERT(n != llvm::StringRef::npos, ""); RELEASE_ASSERT(n != llvm::StringRef::npos, "");
memset(data(), c, n); memset(data(), c, n);
data()[n] = 0; data()[n] = 0;
...@@ -84,7 +83,7 @@ BoxedString::BoxedString(size_t n, char c) : s(storage(), n), interned_state(SST ...@@ -84,7 +83,7 @@ BoxedString::BoxedString(size_t n, char c) : s(storage(), n), interned_state(SST
extern "C" char PyString_GetItem(PyObject* op, ssize_t n) noexcept { extern "C" char PyString_GetItem(PyObject* op, ssize_t n) noexcept {
RELEASE_ASSERT(PyString_Check(op), ""); RELEASE_ASSERT(PyString_Check(op), "");
return static_cast<const BoxedString*>(op)->s[n]; return static_cast<const BoxedString*>(op)->s()[n];
} }
extern "C" PyObject* PyString_FromFormatV(const char* format, va_list vargs) noexcept { extern "C" PyObject* PyString_FromFormatV(const char* format, va_list vargs) noexcept {
...@@ -342,7 +341,7 @@ extern "C" Box* strAdd(BoxedString* lhs, Box* _rhs) { ...@@ -342,7 +341,7 @@ extern "C" Box* strAdd(BoxedString* lhs, Box* _rhs) {
} }
BoxedString* rhs = static_cast<BoxedString*>(_rhs); BoxedString* rhs = static_cast<BoxedString*>(_rhs);
return new (lhs->size() + rhs->size()) BoxedString(lhs->s, rhs->s); return new (lhs->size() + rhs->size()) BoxedString(lhs->s(), rhs->s());
} }
static llvm::StringMap<Box*> interned_strings; static llvm::StringMap<Box*> interned_strings;
...@@ -369,7 +368,7 @@ extern "C" void PyString_InternInPlace(PyObject** p) noexcept { ...@@ -369,7 +368,7 @@ extern "C" void PyString_InternInPlace(PyObject** p) noexcept {
if (PyString_CHECK_INTERNED(s)) if (PyString_CHECK_INTERNED(s))
return; return;
auto& entry = interned_strings[s->s]; auto& entry = interned_strings[s->s()];
if (entry) if (entry)
*p = entry; *p = entry;
else { else {
...@@ -1161,7 +1160,7 @@ extern "C" Box* strLt(BoxedString* lhs, Box* rhs) { ...@@ -1161,7 +1160,7 @@ extern "C" Box* strLt(BoxedString* lhs, Box* rhs) {
return NotImplemented; return NotImplemented;
BoxedString* srhs = static_cast<BoxedString*>(rhs); BoxedString* srhs = static_cast<BoxedString*>(rhs);
return boxBool(lhs->s < srhs->s); return boxBool(lhs->s() < srhs->s());
} }
extern "C" Box* strLe(BoxedString* lhs, Box* rhs) { extern "C" Box* strLe(BoxedString* lhs, Box* rhs) {
...@@ -1171,7 +1170,7 @@ extern "C" Box* strLe(BoxedString* lhs, Box* rhs) { ...@@ -1171,7 +1170,7 @@ extern "C" Box* strLe(BoxedString* lhs, Box* rhs) {
return NotImplemented; return NotImplemented;
BoxedString* srhs = static_cast<BoxedString*>(rhs); BoxedString* srhs = static_cast<BoxedString*>(rhs);
return boxBool(lhs->s <= srhs->s); return boxBool(lhs->s() <= srhs->s());
} }
extern "C" Box* strGt(BoxedString* lhs, Box* rhs) { extern "C" Box* strGt(BoxedString* lhs, Box* rhs) {
...@@ -1181,7 +1180,7 @@ extern "C" Box* strGt(BoxedString* lhs, Box* rhs) { ...@@ -1181,7 +1180,7 @@ extern "C" Box* strGt(BoxedString* lhs, Box* rhs) {
return NotImplemented; return NotImplemented;
BoxedString* srhs = static_cast<BoxedString*>(rhs); BoxedString* srhs = static_cast<BoxedString*>(rhs);
return boxBool(lhs->s > srhs->s); return boxBool(lhs->s() > srhs->s());
} }
extern "C" Box* strGe(BoxedString* lhs, Box* rhs) { extern "C" Box* strGe(BoxedString* lhs, Box* rhs) {
...@@ -1191,7 +1190,7 @@ extern "C" Box* strGe(BoxedString* lhs, Box* rhs) { ...@@ -1191,7 +1190,7 @@ extern "C" Box* strGe(BoxedString* lhs, Box* rhs) {
return NotImplemented; return NotImplemented;
BoxedString* srhs = static_cast<BoxedString*>(rhs); BoxedString* srhs = static_cast<BoxedString*>(rhs);
return boxBool(lhs->s >= srhs->s); return boxBool(lhs->s() >= srhs->s());
} }
extern "C" Box* strEq(BoxedString* lhs, Box* rhs) { extern "C" Box* strEq(BoxedString* lhs, Box* rhs) {
...@@ -1201,7 +1200,7 @@ extern "C" Box* strEq(BoxedString* lhs, Box* rhs) { ...@@ -1201,7 +1200,7 @@ extern "C" Box* strEq(BoxedString* lhs, Box* rhs) {
return NotImplemented; return NotImplemented;
BoxedString* srhs = static_cast<BoxedString*>(rhs); BoxedString* srhs = static_cast<BoxedString*>(rhs);
return boxBool(lhs->s == srhs->s); return boxBool(lhs->s() == srhs->s());
} }
extern "C" Box* strNe(BoxedString* lhs, Box* rhs) { extern "C" Box* strNe(BoxedString* lhs, Box* rhs) {
...@@ -1211,7 +1210,7 @@ extern "C" Box* strNe(BoxedString* lhs, Box* rhs) { ...@@ -1211,7 +1210,7 @@ extern "C" Box* strNe(BoxedString* lhs, Box* rhs) {
return NotImplemented; return NotImplemented;
BoxedString* srhs = static_cast<BoxedString*>(rhs); BoxedString* srhs = static_cast<BoxedString*>(rhs);
return boxBool(lhs->s != srhs->s); return boxBool(lhs->s() != srhs->s());
} }
#define JUST_LEFT 0 #define JUST_LEFT 0
...@@ -1229,11 +1228,11 @@ static Box* pad(BoxedString* self, Box* width, Box* fillchar, int justType) { ...@@ -1229,11 +1228,11 @@ static Box* pad(BoxedString* self, Box* width, Box* fillchar, int justType) {
return self; return self;
} else { } else {
// If self isn't a string but a subclass of str, then make a new string to return // If self isn't a string but a subclass of str, then make a new string to return
return boxString(self->s); return boxString(self->s());
} }
} }
char c = static_cast<BoxedString*>(fillchar)->s[0]; char c = static_cast<BoxedString*>(fillchar)->s()[0];
int padLeft, padRight; int padLeft, padRight;
int nNeeded = targetWidth - curWidth; int nNeeded = targetWidth - curWidth;
...@@ -1255,7 +1254,7 @@ static Box* pad(BoxedString* self, Box* width, Box* fillchar, int justType) { ...@@ -1255,7 +1254,7 @@ static Box* pad(BoxedString* self, Box* width, Box* fillchar, int justType) {
} }
// TODO this is probably slow // TODO this is probably slow
return boxStringTwine(llvm::Twine(std::string(padLeft, c)) + self->s + std::string(padRight, c)); return boxStringTwine(llvm::Twine(std::string(padLeft, c)) + self->s() + std::string(padRight, c));
} }
extern "C" Box* strLjust(BoxedString* lhs, Box* width, Box* fillchar) { extern "C" Box* strLjust(BoxedString* lhs, Box* width, Box* fillchar) {
return pad(lhs, width, fillchar, JUST_LEFT); return pad(lhs, width, fillchar, JUST_LEFT);
...@@ -1279,7 +1278,7 @@ extern "C" Box* strStr(BoxedString* self) { ...@@ -1279,7 +1278,7 @@ extern "C" Box* strStr(BoxedString* self) {
if (self->cls == str_cls) if (self->cls == str_cls)
return self; return self;
return boxString(self->s); return boxString(self->s());
} }
static bool _needs_escaping[256] static bool _needs_escaping[256]
...@@ -1307,7 +1306,7 @@ extern "C" PyObject* PyString_Repr(PyObject* obj, int smartquotes) noexcept { ...@@ -1307,7 +1306,7 @@ extern "C" PyObject* PyString_Repr(PyObject* obj, int smartquotes) noexcept {
std::ostringstream os(""); std::ostringstream os("");
llvm::StringRef s(self->s); llvm::StringRef s(self->s());
char quote = '\''; char quote = '\'';
if (smartquotes && s.find('\'', 0) != std::string::npos && s.find('\"', 0) == std::string::npos) { if (smartquotes && s.find('\'', 0) != std::string::npos && s.find('\"', 0) == std::string::npos) {
quote = '\"'; quote = '\"';
...@@ -1572,7 +1571,7 @@ extern "C" Box* strNew(BoxedClass* cls, Box* obj) { ...@@ -1572,7 +1571,7 @@ extern "C" Box* strNew(BoxedClass* cls, Box* obj) {
BoxedString* _rtn = static_cast<BoxedString*>(rtn); BoxedString* _rtn = static_cast<BoxedString*>(rtn);
return new (cls, _rtn->size()) BoxedString(_rtn->s); return new (cls, _rtn->size()) BoxedString(_rtn->s());
} }
extern "C" Box* basestringNew(BoxedClass* cls, Box* args, Box* kwargs) { extern "C" Box* basestringNew(BoxedClass* cls, Box* args, Box* kwargs) {
...@@ -1582,7 +1581,7 @@ extern "C" Box* basestringNew(BoxedClass* cls, Box* args, Box* kwargs) { ...@@ -1582,7 +1581,7 @@ extern "C" Box* basestringNew(BoxedClass* cls, Box* args, Box* kwargs) {
Box* _strSlice(BoxedString* self, i64 start, i64 stop, i64 step, i64 length) { Box* _strSlice(BoxedString* self, i64 start, i64 stop, i64 step, i64 length) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef s = self->s; llvm::StringRef s = self->s();
assert(step != 0); assert(step != 0);
if (step > 0) { if (step > 0) {
...@@ -1604,7 +1603,7 @@ Box* _strSlice(BoxedString* self, i64 start, i64 stop, i64 step, i64 length) { ...@@ -1604,7 +1603,7 @@ Box* _strSlice(BoxedString* self, i64 start, i64 stop, i64 step, i64 length) {
Box* strIsAlpha(BoxedString* self) { Box* strIsAlpha(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef str(self->s); llvm::StringRef str(self->s());
if (str.empty()) if (str.empty())
return False; return False;
...@@ -1619,7 +1618,7 @@ Box* strIsAlpha(BoxedString* self) { ...@@ -1619,7 +1618,7 @@ Box* strIsAlpha(BoxedString* self) {
Box* strIsDigit(BoxedString* self) { Box* strIsDigit(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef str(self->s); llvm::StringRef str(self->s());
if (str.empty()) if (str.empty())
return False; return False;
...@@ -1634,7 +1633,7 @@ Box* strIsDigit(BoxedString* self) { ...@@ -1634,7 +1633,7 @@ Box* strIsDigit(BoxedString* self) {
Box* strIsAlnum(BoxedString* self) { Box* strIsAlnum(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef str(self->s); llvm::StringRef str(self->s());
if (str.empty()) if (str.empty())
return False; return False;
...@@ -1649,7 +1648,7 @@ Box* strIsAlnum(BoxedString* self) { ...@@ -1649,7 +1648,7 @@ Box* strIsAlnum(BoxedString* self) {
Box* strIsLower(BoxedString* self) { Box* strIsLower(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef str(self->s); llvm::StringRef str(self->s());
bool lowered = false; bool lowered = false;
if (str.empty()) if (str.empty())
...@@ -1671,7 +1670,7 @@ Box* strIsLower(BoxedString* self) { ...@@ -1671,7 +1670,7 @@ Box* strIsLower(BoxedString* self) {
Box* strIsUpper(BoxedString* self) { Box* strIsUpper(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef str(self->s); llvm::StringRef str(self->s());
if (str.empty()) if (str.empty())
return False; return False;
...@@ -1690,7 +1689,7 @@ Box* strIsUpper(BoxedString* self) { ...@@ -1690,7 +1689,7 @@ Box* strIsUpper(BoxedString* self) {
Box* strIsSpace(BoxedString* self) { Box* strIsSpace(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef str(self->s); llvm::StringRef str(self->s());
if (str.empty()) if (str.empty())
return False; return False;
...@@ -1705,7 +1704,7 @@ Box* strIsSpace(BoxedString* self) { ...@@ -1705,7 +1704,7 @@ Box* strIsSpace(BoxedString* self) {
Box* strIsTitle(BoxedString* self) { Box* strIsTitle(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
llvm::StringRef str(self->s); llvm::StringRef str(self->s());
if (str.empty()) if (str.empty())
return False; return False;
...@@ -1767,12 +1766,12 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) { ...@@ -1767,12 +1766,12 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) {
int max_replaces = static_cast<BoxedInt*>(_maxreplace)->n; int max_replaces = static_cast<BoxedInt*>(_maxreplace)->n;
size_t start_pos = 0; size_t start_pos = 0;
std::string s = self->s; std::string s = self->s();
for (int num_replaced = 0; num_replaced < max_replaces || max_replaces < 0; ++num_replaced) { for (int num_replaced = 0; num_replaced < max_replaces || max_replaces < 0; ++num_replaced) {
start_pos = s.find(old->s, start_pos); start_pos = s.find(old->s(), start_pos);
if (start_pos == std::string::npos) if (start_pos == std::string::npos)
break; break;
s.replace(start_pos, old->size(), new_->s); s.replace(start_pos, old->size(), new_->s());
start_pos += new_->size(); // Handles case where 'to' is a substring of 'from' start_pos += new_->size(); // Handles case where 'to' is a substring of 'from'
} }
return boxString(s); return boxString(s);
...@@ -1782,7 +1781,7 @@ Box* strPartition(BoxedString* self, BoxedString* sep) { ...@@ -1782,7 +1781,7 @@ Box* strPartition(BoxedString* self, BoxedString* sep) {
RELEASE_ASSERT(isSubclass(self->cls, str_cls), ""); RELEASE_ASSERT(isSubclass(self->cls, str_cls), "");
RELEASE_ASSERT(isSubclass(sep->cls, str_cls), ""); RELEASE_ASSERT(isSubclass(sep->cls, str_cls), "");
size_t found_idx = self->s.find(sep->s); size_t found_idx = self->s().find(sep->s());
if (found_idx == std::string::npos) if (found_idx == std::string::npos)
return BoxedTuple::create({ self, EmptyString, EmptyString }); return BoxedTuple::create({ self, EmptyString, EmptyString });
...@@ -1796,7 +1795,7 @@ Box* strRpartition(BoxedString* self, BoxedString* sep) { ...@@ -1796,7 +1795,7 @@ Box* strRpartition(BoxedString* self, BoxedString* sep) {
RELEASE_ASSERT(isSubclass(self->cls, str_cls), ""); RELEASE_ASSERT(isSubclass(self->cls, str_cls), "");
RELEASE_ASSERT(isSubclass(sep->cls, str_cls), ""); RELEASE_ASSERT(isSubclass(sep->cls, str_cls), "");
size_t found_idx = self->s.rfind(sep->s); size_t found_idx = self->s().rfind(sep->s());
if (found_idx == std::string::npos) if (found_idx == std::string::npos)
return BoxedTuple::create({ EmptyString, EmptyString, self }); return BoxedTuple::create({ EmptyString, EmptyString, self });
...@@ -1819,10 +1818,10 @@ Box* strFormat(BoxedString* self, BoxedTuple* args, BoxedDict* kwargs) { ...@@ -1819,10 +1818,10 @@ Box* strFormat(BoxedString* self, BoxedTuple* args, BoxedDict* kwargs) {
Box* strStrip(BoxedString* self, Box* chars) { Box* strStrip(BoxedString* self, Box* chars) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
auto str = self->s; auto str = self->s();
if (isSubclass(chars->cls, str_cls)) { if (isSubclass(chars->cls, str_cls)) {
auto chars_str = static_cast<BoxedString*>(chars)->s; auto chars_str = static_cast<BoxedString*>(chars)->s();
return boxStringRef(str.trim(chars_str)); return boxStringRef(str.trim(chars_str));
} else if (chars->cls == none_cls) { } else if (chars->cls == none_cls) {
return boxStringRef(str.trim(" \t\n\r\f\v")); return boxStringRef(str.trim(" \t\n\r\f\v"));
...@@ -1843,10 +1842,10 @@ Box* strStrip(BoxedString* self, Box* chars) { ...@@ -1843,10 +1842,10 @@ Box* strStrip(BoxedString* self, Box* chars) {
Box* strLStrip(BoxedString* self, Box* chars) { Box* strLStrip(BoxedString* self, Box* chars) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
auto str = self->s; auto str = self->s();
if (isSubclass(chars->cls, str_cls)) { if (isSubclass(chars->cls, str_cls)) {
auto chars_str = static_cast<BoxedString*>(chars)->s; auto chars_str = static_cast<BoxedString*>(chars)->s();
return boxStringRef(str.ltrim(chars_str)); return boxStringRef(str.ltrim(chars_str));
} else if (chars->cls == none_cls) { } else if (chars->cls == none_cls) {
return boxStringRef(str.ltrim(" \t\n\r\f\v")); return boxStringRef(str.ltrim(" \t\n\r\f\v"));
...@@ -1867,10 +1866,10 @@ Box* strLStrip(BoxedString* self, Box* chars) { ...@@ -1867,10 +1866,10 @@ Box* strLStrip(BoxedString* self, Box* chars) {
Box* strRStrip(BoxedString* self, Box* chars) { Box* strRStrip(BoxedString* self, Box* chars) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
auto str = self->s; auto str = self->s();
if (isSubclass(chars->cls, str_cls)) { if (isSubclass(chars->cls, str_cls)) {
auto chars_str = static_cast<BoxedString*>(chars)->s; auto chars_str = static_cast<BoxedString*>(chars)->s();
return boxStringRef(str.rtrim(chars_str)); return boxStringRef(str.rtrim(chars_str));
} else if (chars->cls == none_cls) { } else if (chars->cls == none_cls) {
return boxStringRef(str.rtrim(" \t\n\r\f\v")); return boxStringRef(str.rtrim(" \t\n\r\f\v"));
...@@ -1892,7 +1891,7 @@ Box* strRStrip(BoxedString* self, Box* chars) { ...@@ -1892,7 +1891,7 @@ Box* strRStrip(BoxedString* self, Box* chars) {
Box* strCapitalize(BoxedString* self) { Box* strCapitalize(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
std::string s(self->s); std::string s(self->s());
for (auto& i : s) { for (auto& i : s) {
i = std::tolower(i); i = std::tolower(i);
...@@ -1908,7 +1907,7 @@ Box* strCapitalize(BoxedString* self) { ...@@ -1908,7 +1907,7 @@ Box* strCapitalize(BoxedString* self) {
Box* strTitle(BoxedString* self) { Box* strTitle(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
std::string s(self->s); std::string s(self->s());
bool start_of_word = false; bool start_of_word = false;
for (auto& i : s) { for (auto& i : s) {
...@@ -1938,7 +1937,7 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha ...@@ -1938,7 +1937,7 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha
if (delete_chars) { if (delete_chars) {
if (!isSubclass(delete_chars->cls, str_cls)) if (!isSubclass(delete_chars->cls, str_cls))
raiseExcHelper(TypeError, "expected a character buffer object"); raiseExcHelper(TypeError, "expected a character buffer object");
delete_set.insert(delete_chars->s.begin(), delete_chars->s.end()); delete_set.insert(delete_chars->s().begin(), delete_chars->s().end());
} }
bool have_table = table != None; bool have_table = table != None;
...@@ -1950,9 +1949,9 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha ...@@ -1950,9 +1949,9 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha
} }
std::string str; std::string str;
for (const char c : self->s) { for (const char c : self->s()) {
if (!delete_set.count(c)) if (!delete_set.count(c))
str.append(1, have_table ? table->s[(unsigned char)c] : c); str.append(1, have_table ? table->s()[(unsigned char)c] : c);
} }
return boxString(str); return boxString(str);
} }
...@@ -1960,7 +1959,7 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha ...@@ -1960,7 +1959,7 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha
Box* strLower(BoxedString* self) { Box* strLower(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s)); BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s()));
for (int i = 0; i < rtn->size(); i++) for (int i = 0; i < rtn->size(); i++)
rtn->data()[i] = std::tolower(rtn->data()[i]); rtn->data()[i] = std::tolower(rtn->data()[i]);
return rtn; return rtn;
...@@ -1968,7 +1967,7 @@ Box* strLower(BoxedString* self) { ...@@ -1968,7 +1967,7 @@ Box* strLower(BoxedString* self) {
Box* strUpper(BoxedString* self) { Box* strUpper(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s)); BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s()));
for (int i = 0; i < rtn->size(); i++) for (int i = 0; i < rtn->size(); i++)
rtn->data()[i] = std::toupper(rtn->data()[i]); rtn->data()[i] = std::toupper(rtn->data()[i]);
return rtn; return rtn;
...@@ -1976,7 +1975,7 @@ Box* strUpper(BoxedString* self) { ...@@ -1976,7 +1975,7 @@ Box* strUpper(BoxedString* self) {
Box* strSwapcase(BoxedString* self) { Box* strSwapcase(BoxedString* self) {
assert(isSubclass(self->cls, str_cls)); assert(isSubclass(self->cls, str_cls));
BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s)); BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s()));
for (int i = 0; i < rtn->size(); i++) { for (int i = 0; i < rtn->size(); i++) {
char c = rtn->data()[i]; char c = rtn->data()[i];
if (std::islower(c)) if (std::islower(c))
...@@ -2002,7 +2001,7 @@ Box* strContains(BoxedString* self, Box* elt) { ...@@ -2002,7 +2001,7 @@ Box* strContains(BoxedString* self, Box* elt) {
BoxedString* sub = static_cast<BoxedString*>(elt); BoxedString* sub = static_cast<BoxedString*>(elt);
size_t found_idx = self->s.find(sub->s); size_t found_idx = self->s().find(sub->s());
if (found_idx == std::string::npos) if (found_idx == std::string::npos)
return False; return False;
return True; return True;
...@@ -2078,7 +2077,7 @@ Box* strStartswith(BoxedString* self, Box* elt, Box* start, Box** _args) { ...@@ -2078,7 +2077,7 @@ Box* strStartswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
return False; return False;
if (sub->size() > compare_len) if (sub->size() > compare_len)
return False; return False;
return boxBool(compareStringRefs(self->s, istart, sub->size(), sub->s) == 0); return boxBool(compareStringRefs(self->s(), istart, sub->size(), sub->s()) == 0);
} }
Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) { Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
...@@ -2143,7 +2142,7 @@ Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) { ...@@ -2143,7 +2142,7 @@ Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
return False; return False;
// XXX: this line is the only difference between startswith and endswith: // XXX: this line is the only difference between startswith and endswith:
istart += compare_len - sub->size(); istart += compare_len - sub->size();
return boxBool(compareStringRefs(self->s, istart, sub->size(), sub->s) == 0); return boxBool(compareStringRefs(self->s(), istart, sub->size(), sub->s()) == 0);
} }
Box* strDecode(BoxedString* self, Box* encoding, Box* error) { Box* strDecode(BoxedString* self, Box* encoding, Box* error) {
...@@ -2211,7 +2210,7 @@ extern "C" Box* strGetitem(BoxedString* self, Box* slice) { ...@@ -2211,7 +2210,7 @@ extern "C" Box* strGetitem(BoxedString* self, Box* slice) {
raiseExcHelper(IndexError, "string index out of range"); raiseExcHelper(IndexError, "string index out of range");
} }
char c = self->s[n]; char c = self->s()[n];
return boxStringRef(llvm::StringRef(&c, 1)); return boxStringRef(llvm::StringRef(&c, 1));
} else if (slice->cls == slice_cls) { } else if (slice->cls == slice_cls) {
BoxedSlice* sslice = static_cast<BoxedSlice*>(slice); BoxedSlice* sslice = static_cast<BoxedSlice*>(slice);
...@@ -2236,7 +2235,7 @@ public: ...@@ -2236,7 +2235,7 @@ public:
BoxedString* s; BoxedString* s;
std::string::const_iterator it, end; std::string::const_iterator it, end;
BoxedStringIterator(BoxedString* s) : s(s), it(s->s.begin()), end(s->s.end()) {} BoxedStringIterator(BoxedString* s) : s(s), it(s->s().begin()), end(s->s().end()) {}
DEFAULT_CLASS(str_iterator_cls); DEFAULT_CLASS(str_iterator_cls);
...@@ -2371,7 +2370,7 @@ extern "C" int _PyString_Resize(PyObject** pv, Py_ssize_t newsize) noexcept { ...@@ -2371,7 +2370,7 @@ extern "C" int _PyString_Resize(PyObject** pv, Py_ssize_t newsize) noexcept {
if (newsize < s->size()) { if (newsize < s->size()) {
// XXX resize the box (by reallocating) smaller if it makes sense // XXX resize the box (by reallocating) smaller if it makes sense
s->s = llvm::StringRef(s->data(), newsize); s->ob_size = newsize;
s->data()[newsize] = 0; s->data()[newsize] = 0;
return 0; return 0;
} }
...@@ -2583,7 +2582,7 @@ static int string_print(PyObject* _op, FILE* fp, int flags) noexcept { ...@@ -2583,7 +2582,7 @@ static int string_print(PyObject* _op, FILE* fp, int flags) noexcept {
with the GIL released. */ with the GIL released. */
// Pyston change: // Pyston change:
// c = op->ob_sval[i]; // c = op->ob_sval[i];
c = op->s[i]; c = op->s()[i];
if (c == quote || c == '\\') if (c == quote || c == '\\')
fprintf(fp, "\\%c", c); fprintf(fp, "\\%c", c);
else if (c == '\t') else if (c == '\t')
......
...@@ -64,7 +64,7 @@ Box* superGetattribute(Box* _s, Box* _attr) { ...@@ -64,7 +64,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
if (!skip) { if (!skip) {
// Looks like __class__ is supposed to be "super", not the class of the the proxied object. // Looks like __class__ is supposed to be "super", not the class of the the proxied object.
skip = (attr->s == class_str); skip = (attr->s() == class_str);
} }
if (!skip) { if (!skip) {
...@@ -101,7 +101,7 @@ Box* superGetattribute(Box* _s, Box* _attr) { ...@@ -101,7 +101,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
continue; continue;
res = PyDict_GetItem(dict, name); res = PyDict_GetItem(dict, name);
#endif #endif
res = tmp->getattr(std::string(attr->s)); res = tmp->getattr(std::string(attr->s()));
if (res != NULL) { if (res != NULL) {
// Pyston change: // Pyston change:
...@@ -128,7 +128,7 @@ Box* superGetattribute(Box* _s, Box* _attr) { ...@@ -128,7 +128,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
} }
} }
Box* r = typeLookup(s->cls, std::string(attr->s), NULL); Box* r = typeLookup(s->cls, std::string(attr->s()), NULL);
// TODO implement this // TODO implement this
RELEASE_ASSERT(r, "should call the equivalent of objectGetattr here"); RELEASE_ASSERT(r, "should call the equivalent of objectGetattr here");
return processDescriptor(r, s, s->cls); return processDescriptor(r, s, s->cls);
......
...@@ -215,7 +215,7 @@ Box* tupleRepr(BoxedTuple* t) { ...@@ -215,7 +215,7 @@ Box* tupleRepr(BoxedTuple* t) {
os << ", "; os << ", ";
BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i])); BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i]));
os << elt_repr->s; os << elt_repr->s();
} }
if (n == 1) if (n == 1)
os << ","; os << ",";
...@@ -376,7 +376,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) { ...@@ -376,7 +376,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
auto const seq = *(kwargs->d.begin()); auto const seq = *(kwargs->d.begin());
auto const kw = static_cast<BoxedString*>(seq.first); auto const kw = static_cast<BoxedString*>(seq.first);
if (kw->s == "sequence") if (kw->s() == "sequence")
elements = seq.second; elements = seq.second;
else else
raiseExcHelper(TypeError, "'%s' is an invalid keyword argument for this function", kw->data()); raiseExcHelper(TypeError, "'%s' is an invalid keyword argument for this function", kw->data());
......
...@@ -401,7 +401,7 @@ std::string BoxedModule::name() { ...@@ -401,7 +401,7 @@ std::string BoxedModule::name() {
return "?"; return "?";
} else { } else {
BoxedString* sname = static_cast<BoxedString*>(name); BoxedString* sname = static_cast<BoxedString*>(name);
return sname->s; return sname->s();
} }
} }
...@@ -1038,7 +1038,7 @@ Box* sliceRepr(BoxedSlice* self) { ...@@ -1038,7 +1038,7 @@ Box* sliceRepr(BoxedSlice* self) {
BoxedString* start = static_cast<BoxedString*>(repr(self->start)); BoxedString* start = static_cast<BoxedString*>(repr(self->start));
BoxedString* stop = static_cast<BoxedString*>(repr(self->stop)); BoxedString* stop = static_cast<BoxedString*>(repr(self->stop));
BoxedString* step = static_cast<BoxedString*>(repr(self->step)); BoxedString* step = static_cast<BoxedString*>(repr(self->step));
return boxStringTwine(llvm::Twine("slice(") + start->s + ", " + stop->s + ", " + step->s + ")"); return boxStringTwine(llvm::Twine("slice(") + start->s() + ", " + stop->s() + ", " + step->s() + ")");
} }
extern "C" int PySlice_GetIndices(PySliceObject* r, Py_ssize_t length, Py_ssize_t* start, Py_ssize_t* stop, extern "C" int PySlice_GetIndices(PySliceObject* r, Py_ssize_t length, Py_ssize_t* start, Py_ssize_t* stop,
...@@ -1150,8 +1150,8 @@ Box* typeRepr(BoxedClass* self) { ...@@ -1150,8 +1150,8 @@ Box* typeRepr(BoxedClass* self) {
Box* m = self->getattr("__module__"); Box* m = self->getattr("__module__");
if (m && m->cls == str_cls) { if (m && m->cls == str_cls) {
BoxedString* sm = static_cast<BoxedString*>(m); BoxedString* sm = static_cast<BoxedString*>(m);
if (sm->s != "__builtin__") if (sm->s() != "__builtin__")
os << sm->s << '.'; os << sm->s() << '.';
} }
os << self->tp_name; os << self->tp_name;
...@@ -1347,7 +1347,7 @@ public: ...@@ -1347,7 +1347,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, ""); RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key); BoxedString* key = static_cast<BoxedString*>(_key);
self->b->setattr(key->s, value, NULL); self->b->setattr(key->s(), value, NULL);
return None; return None;
} }
...@@ -1360,10 +1360,10 @@ public: ...@@ -1360,10 +1360,10 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, ""); RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key); BoxedString* key = static_cast<BoxedString*>(_key);
Box* cur = self->b->getattr(key->s); Box* cur = self->b->getattr(key->s());
if (cur) if (cur)
return cur; return cur;
self->b->setattr(key->s, value, NULL); self->b->setattr(key->s(), value, NULL);
return value; return value;
} }
...@@ -1376,7 +1376,7 @@ public: ...@@ -1376,7 +1376,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, ""); RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key); BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s); Box* r = self->b->getattr(key->s());
if (!r) if (!r)
return def; return def;
return r; return r;
...@@ -1391,7 +1391,7 @@ public: ...@@ -1391,7 +1391,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "%s", _key->cls->tp_name); RELEASE_ASSERT(_key->cls == str_cls, "%s", _key->cls->tp_name);
BoxedString* key = static_cast<BoxedString*>(_key); BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s); Box* r = self->b->getattr(key->s());
if (!r) if (!r)
raiseExcHelper(KeyError, "'%s'", key->data()); raiseExcHelper(KeyError, "'%s'", key->data());
return r; return r;
...@@ -1405,9 +1405,9 @@ public: ...@@ -1405,9 +1405,9 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, ""); RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key); BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s); Box* r = self->b->getattr(key->s());
if (r) { if (r) {
self->b->delattr(key->s, NULL); self->b->delattr(key->s(), NULL);
return r; return r;
} else { } else {
if (default_) if (default_)
...@@ -1425,8 +1425,8 @@ public: ...@@ -1425,8 +1425,8 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "%s", _key->cls->tp_name); RELEASE_ASSERT(_key->cls == str_cls, "%s", _key->cls->tp_name);
BoxedString* key = static_cast<BoxedString*>(_key); BoxedString* key = static_cast<BoxedString*>(_key);
if (self->b->getattr(key->s)) if (self->b->getattr(key->s()))
self->b->delattr(key->s, NULL); self->b->delattr(key->s(), NULL);
else else
raiseExcHelper(KeyError, "'%s'", key->data()); raiseExcHelper(KeyError, "'%s'", key->data());
return None; return None;
...@@ -1450,7 +1450,7 @@ public: ...@@ -1450,7 +1450,7 @@ public:
first = false; first = false;
BoxedString* v = attrs->attr_list->attrs[p.second]->reprICAsString(); BoxedString* v = attrs->attr_list->attrs[p.second]->reprICAsString();
os << p.first().str() << ": " << v->s; os << p.first().str() << ": " << v->s();
} }
os << "})"; os << "})";
return boxString(os.str()); return boxString(os.str());
...@@ -1464,7 +1464,7 @@ public: ...@@ -1464,7 +1464,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, ""); RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key); BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s); Box* r = self->b->getattr(key->s());
return r ? True : False; return r ? True : False;
} }
...@@ -1728,7 +1728,7 @@ Box* objectSetattr(Box* obj, Box* attr, Box* value) { ...@@ -1728,7 +1728,7 @@ Box* objectSetattr(Box* obj, Box* attr, Box* value) {
} }
BoxedString* attr_str = static_cast<BoxedString*>(attr); BoxedString* attr_str = static_cast<BoxedString*>(attr);
setattrGeneric(obj, attr_str->s, value, NULL); setattrGeneric(obj, attr_str->s(), value, NULL);
return None; return None;
} }
......
...@@ -427,11 +427,14 @@ public: ...@@ -427,11 +427,14 @@ public:
class BoxedString : public BoxVar { class BoxedString : public BoxVar {
public: public:
llvm::StringRef s; // llvm::StringRef is basically just a pointer and a length, so with proper compiler
// optimizations and inlining, creating a new one each time shouldn't have any cost.
llvm::StringRef s() const { return llvm::StringRef(s_data, ob_size); };
char interned_state; char interned_state;
char* data() { return const_cast<char*>(s.data()); } char* data() { return s_data; }
size_t size() { return s.size(); } size_t size() { return this->ob_size; }
// DEFAULT_CLASS_VAR_SIMPLE doesn't work because of the +1 for the null byte // DEFAULT_CLASS_VAR_SIMPLE doesn't work because of the +1 for the null byte
void* operator new(size_t size, BoxedClass* cls, size_t nitems) __attribute__((visibility("default"))) { void* operator new(size_t size, BoxedClass* cls, size_t nitems) __attribute__((visibility("default"))) {
...@@ -465,11 +468,9 @@ public: ...@@ -465,11 +468,9 @@ public:
explicit BoxedString(llvm::StringRef lhs, llvm::StringRef rhs) __attribute__((visibility("default"))); explicit BoxedString(llvm::StringRef lhs, llvm::StringRef rhs) __attribute__((visibility("default")));
private: private:
// used only in ctors to give our llvm::StringRef the proper pointer
// Note: sizeof(BoxedString) = str_cls->tp_basicsize - 1
char* storage() { return (char*)this + sizeof(BoxedString); }
void* operator new(size_t size) = delete; void* operator new(size_t size) = delete;
char s_data[0];
}; };
template <typename T> struct StringHash { template <typename T> struct StringHash {
......
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