This commit is contained in:
blueloveTH 2022-12-05 02:42:46 +08:00
parent 2cd5d46ee9
commit 3f5842092f
4 changed files with 13 additions and 13 deletions

View File

@ -46,7 +46,7 @@ public:
Compiler(VM* vm, const char* source, _Str filename, CompileMode mode){ Compiler(VM* vm, const char* source, _Str filename, CompileMode mode){
this->vm = vm; this->vm = vm;
this->parser = std::make_unique<Parser>( this->parser = std::make_unique<Parser>(
std::make_shared<SourceMetadata>(source, filename, mode) pkpy::make_shared<SourceMetadata>(source, filename, mode)
); );
// http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/ // http://journal.stuffwithstuff.com/2011/03/19/pratt-parsers-expression-parsing-made-easy/
@ -357,13 +357,13 @@ public:
} }
void exprLambda() { void exprLambda() {
_Func func = std::make_shared<Function>(); _Func func = pkpy::make_shared<Function>();
func->name = "<lambda>"; func->name = "<lambda>";
if(!match(TK(":"))){ if(!match(TK(":"))){
__compileFunctionArgs(func); __compileFunctionArgs(func);
consume(TK(":")); consume(TK(":"));
} }
func->code = std::make_shared<CodeObject>(parser->src, func->name); func->code = pkpy::make_shared<CodeObject>(parser->src, func->name);
this->codes.push(func->code); this->codes.push(func->code);
EXPR_TUPLE(); EXPR_TUPLE();
emitCode(OP_RETURN_VALUE); emitCode(OP_RETURN_VALUE);
@ -924,7 +924,7 @@ __LISTCOMP:
if(match(TK("pass"))) return; if(match(TK("pass"))) return;
consume(TK("def")); consume(TK("def"));
} }
_Func func = std::make_shared<Function>(); _Func func = pkpy::make_shared<Function>();
consume(TK("@id")); consume(TK("@id"));
func->name = parser->previous.str(); func->name = parser->previous.str();
@ -933,7 +933,7 @@ __LISTCOMP:
consume(TK(")")); consume(TK(")"));
} }
func->code = std::make_shared<CodeObject>(parser->src, func->name); func->code = pkpy::make_shared<CodeObject>(parser->src, func->name);
this->codes.push(func->code); this->codes.push(func->code);
compileBlockBody(); compileBlockBody();
this->codes.pop(); this->codes.pop();
@ -971,7 +971,7 @@ __LISTCOMP:
} }
_Code __fillCode(){ _Code __fillCode(){
_Code code = std::make_shared<CodeObject>(parser->src, _Str("<module>")); _Code code = pkpy::make_shared<CodeObject>(parser->src, _Str("<module>"));
codes.push(code); codes.push(code);
// Lex initial tokens. current <-- next. // Lex initial tokens. current <-- next.

View File

@ -53,7 +53,7 @@ struct SourceMetadata {
} }
}; };
typedef std::shared_ptr<SourceMetadata> _Source; typedef pkpy::shared_ptr<SourceMetadata> _Source;
class _Error : public std::exception { class _Error : public std::exception {
private: private:

View File

@ -12,7 +12,7 @@ class Frame;
typedef pkpy::shared_ptr<const BasePointer> _Pointer; typedef pkpy::shared_ptr<const BasePointer> _Pointer;
typedef PyVar (*_CppFunc)(VM*, const pkpy::ArgList&); typedef PyVar (*_CppFunc)(VM*, const pkpy::ArgList&);
typedef std::shared_ptr<CodeObject> _Code; typedef pkpy::shared_ptr<CodeObject> _Code;
struct Function { struct Function {
_Str name; _Str name;
@ -64,7 +64,7 @@ public:
_Iterator(VM* vm, PyVar _ref) : vm(vm), _ref(_ref) {} _Iterator(VM* vm, PyVar _ref) : vm(vm), _ref(_ref) {}
}; };
typedef std::shared_ptr<Function> _Func; typedef pkpy::shared_ptr<Function> _Func;
typedef std::variant<PyVar,_Int,_Float,bool,_Str,PyVarList,_CppFunc,_Func,std::shared_ptr<_Iterator>,_BoundedMethod,_Range,_Slice,_Pointer> _Value; typedef std::variant<PyVar,_Int,_Float,bool,_Str,PyVarList,_CppFunc,_Func,std::shared_ptr<_Iterator>,_BoundedMethod,_Range,_Slice,_Pointer> _Value;
const int _SIZEOF_VALUE = sizeof(_Value); const int _SIZEOF_VALUE = sizeof(_Value);

View File

@ -55,7 +55,7 @@ public:
}; };
std::map<std::string, std::shared_ptr<_StrMemory>, std::less<>> _strIntern; std::map<std::string, pkpy::shared_ptr<_StrMemory>, std::less<>> _strIntern;
class _StrLiteral : public std::string_view { class _StrLiteral : public std::string_view {
@ -69,7 +69,7 @@ inline constexpr _StrLiteral operator "" _c(const char* str, size_t len){
class _Str { class _Str {
private: private:
std::shared_ptr<_StrMemory> _s; pkpy::shared_ptr<_StrMemory> _s;
bool interned = false; bool interned = false;
public: public:
_Str(const _StrLiteral& s){ _Str(const _StrLiteral& s){
@ -92,7 +92,7 @@ public:
// for move constructor, we do not check if the string is interned!! // for move constructor, we do not check if the string is interned!!
_Str(std::string&& s){ _Str(std::string&& s){
this->_s = std::make_shared<_StrMemory>(std::move(s)); this->_s = pkpy::make_shared<_StrMemory>(std::move(s));
} }
void construct(const std::string_view& sv){ void construct(const std::string_view& sv){
@ -101,7 +101,7 @@ public:
this->_s = it->second; this->_s = it->second;
interned = true; interned = true;
}else{ }else{
this->_s = std::make_shared<_StrMemory>(std::string(sv)); this->_s = pkpy::make_shared<_StrMemory>(std::string(sv));
} }
} }