This commit is contained in:
blueloveTH 2023-01-11 17:50:10 +08:00
parent 41b7c1adb9
commit 944f98be6f
4 changed files with 5 additions and 67 deletions

View File

@ -19,6 +19,7 @@
#include <string_view>
#include <queue>
#include <iomanip>
#include <memory>
#include <atomic>
#include <iostream>

View File

@ -19,7 +19,7 @@ enum StringType { NORMAL_STRING, RAW_STRING, F_STRING };
class Compiler {
public:
pkpy::unique_ptr<Parser> parser;
std::unique_ptr<Parser> parser;
std::stack<_Code> codes;
bool isCompilingClass = false;
int lexingCnt = 0;
@ -37,7 +37,7 @@ public:
Compiler(VM* vm, const char* source, _Str filename, CompileMode mode){
this->vm = vm;
this->parser = pkpy::make_unique<Parser>(
this->parser = std::make_unique<Parser>(
pkpy::make_shared<SourceMetadata>(source, filename, mode)
);

View File

@ -96,67 +96,4 @@ namespace pkpy{
new(p+1) T(std::forward<Args>(args)...);
return shared_ptr<T>(p);
}
template <typename T>
class unique_ptr {
T* ptr;
public:
unique_ptr() : ptr(nullptr) {}
unique_ptr(T* ptr) : ptr(ptr) {}
unique_ptr(const unique_ptr& other) = delete;
unique_ptr(unique_ptr&& other) : ptr(other.ptr) {
other.ptr = nullptr;
}
~unique_ptr() {
delete ptr;
}
bool operator==(const unique_ptr& other) const {
return ptr == other.ptr;
}
bool operator!=(const unique_ptr& other) const {
return ptr != other.ptr;
}
bool operator==(std::nullptr_t) const {
return ptr == nullptr;
}
bool operator!=(std::nullptr_t) const {
return ptr != nullptr;
}
unique_ptr& operator=(const unique_ptr& other) = delete;
unique_ptr& operator=(unique_ptr&& other) {
if (this != &other) {
delete ptr;
ptr = other.ptr;
other.ptr = nullptr;
}
return *this;
}
T& operator*() const {
return *ptr;
}
T* operator->() const {
return ptr;
}
T* get() const {
return ptr;
}
void reset(){
delete ptr;
ptr = nullptr;
}
};
template <typename T, typename... Args>
unique_ptr<T> make_unique(Args&&... args) {
return unique_ptr<T>(new T(std::forward<Args>(args)...));
}
};

View File

@ -26,7 +26,7 @@ class VM {
PyVarDict _modules; // loaded modules
emhash8::HashMap<_Str, _Str> _lazy_modules; // lazy loaded modules
protected:
std::deque< pkpy::unique_ptr<Frame> > callstack;
std::deque< std::unique_ptr<Frame> > callstack;
PyVar __py2py_call_signal;
inline void test_stop_flag(){
@ -580,7 +580,7 @@ public:
throw RuntimeError("RecursionError", "maximum recursion depth exceeded", _cleanErrorAndGetSnapshots());
}
Frame* frame = new Frame(code, _module, std::move(locals));
callstack.emplace_back(pkpy::unique_ptr<Frame>(frame));
callstack.emplace_back(std::unique_ptr<Frame>(frame));
return frame;
}