mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
use pool128 for Expr_
This commit is contained in:
parent
458dd32af8
commit
4cfe93ee51
@ -62,9 +62,9 @@ class Compiler {
|
||||
Expr_ EXPR_VARS(); // special case for `for loop` and `comp`
|
||||
|
||||
template <typename T, typename... Args>
|
||||
unique_ptr_64<T> make_expr(Args&&... args) {
|
||||
void* p = pool64_alloc(sizeof(T));
|
||||
unique_ptr_64<T> expr(new (p) T(std::forward<Args>(args)...));
|
||||
unique_ptr_128<T> make_expr(Args&&... args) {
|
||||
void* p = pool128_alloc(sizeof(T));
|
||||
unique_ptr_128<T> expr(new (p) T(std::forward<Args>(args)...));
|
||||
expr->line = prev().line;
|
||||
return expr;
|
||||
}
|
||||
@ -72,7 +72,7 @@ class Compiler {
|
||||
template<typename T>
|
||||
void _consume_comp(Expr_ expr){
|
||||
static_assert(std::is_base_of<CompExpr, T>::value);
|
||||
unique_ptr_64<CompExpr> ce = make_expr<T>();
|
||||
unique_ptr_128<CompExpr> ce = make_expr<T>();
|
||||
ce->expr = std::move(expr);
|
||||
ce->vars = EXPR_VARS();
|
||||
consume(TK("in"));
|
||||
|
@ -11,46 +11,46 @@ namespace pkpy{
|
||||
struct CodeEmitContext;
|
||||
struct Expr;
|
||||
|
||||
#define PK_POOL64_DELETE(ptr) if(ptr != nullptr) { ptr->~T(); pool64_dealloc(ptr); ptr = nullptr; }
|
||||
#define PK_POOL128_DELETE(ptr) if(ptr != nullptr) { ptr->~T(); pool128_dealloc(ptr); ptr = nullptr; }
|
||||
|
||||
template<typename T>
|
||||
class unique_ptr_64{
|
||||
class unique_ptr_128{
|
||||
T* ptr;
|
||||
public:
|
||||
unique_ptr_64(): ptr(nullptr) {}
|
||||
unique_ptr_64(T* ptr): ptr(ptr) {}
|
||||
unique_ptr_128(): ptr(nullptr) {}
|
||||
unique_ptr_128(T* ptr): ptr(ptr) {}
|
||||
T* operator->() const { return ptr; }
|
||||
T* get() const { return ptr; }
|
||||
T* release() { T* p = ptr; ptr = nullptr; return p; }
|
||||
|
||||
unique_ptr_64(const unique_ptr_64&) = delete;
|
||||
unique_ptr_64& operator=(const unique_ptr_64&) = delete;
|
||||
unique_ptr_128(const unique_ptr_128&) = delete;
|
||||
unique_ptr_128& operator=(const unique_ptr_128&) = delete;
|
||||
|
||||
bool operator==(std::nullptr_t) const { return ptr == nullptr; }
|
||||
bool operator!=(std::nullptr_t) const { return ptr != nullptr; }
|
||||
|
||||
~unique_ptr_64(){ PK_POOL64_DELETE(ptr) }
|
||||
~unique_ptr_128(){ PK_POOL128_DELETE(ptr) }
|
||||
|
||||
template<typename U>
|
||||
unique_ptr_64(unique_ptr_64<U>&& other): ptr(other.release()) {}
|
||||
unique_ptr_128(unique_ptr_128<U>&& other): ptr(other.release()) {}
|
||||
|
||||
operator bool() const { return ptr != nullptr; }
|
||||
|
||||
template<typename U>
|
||||
unique_ptr_64& operator=(unique_ptr_64<U>&& other) {
|
||||
PK_POOL64_DELETE(ptr)
|
||||
unique_ptr_128& operator=(unique_ptr_128<U>&& other) {
|
||||
PK_POOL128_DELETE(ptr)
|
||||
ptr = other.release();
|
||||
return *this;
|
||||
}
|
||||
|
||||
unique_ptr_64& operator=(std::nullptr_t) {
|
||||
PK_POOL64_DELETE(ptr)
|
||||
unique_ptr_128& operator=(std::nullptr_t) {
|
||||
PK_POOL128_DELETE(ptr)
|
||||
ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
typedef unique_ptr_64<Expr> Expr_;
|
||||
typedef unique_ptr_128<Expr> Expr_;
|
||||
typedef small_vector<Expr_, 6> Expr_vector;
|
||||
|
||||
struct Expr{
|
||||
|
Loading…
x
Reference in New Issue
Block a user