From afc8c544872a6e9faa2c184ba32492fd5099f39a Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Thu, 18 May 2023 18:45:56 +0800 Subject: [PATCH] :sparkles: gc::extend uses std::nothrow --- CMakeLists.txt | 4 +--- doc/vs.md | 4 ++-- nasal_gc.h | 26 ++++++++++++++------------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 278dcd9..9fe5c8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,9 +27,7 @@ target_include_directories(nasock PRIVATE ${CMAKE_SOURCE_DIR}) add_executable(nasal main.cpp) -if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") - message("Ignore linking dl lib") -else() +if(NOT CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") target_link_libraries(nasal dl) endif() diff --git a/doc/vs.md b/doc/vs.md index afcf8b3..b828435 100644 --- a/doc/vs.md +++ b/doc/vs.md @@ -2,9 +2,9 @@ ## First | 首先 -We give a __CMakeLists.txt__ for you to create new VS project from it. +We give a [__CMakeLists.txt__](../CMakeLists.txt) for you to create new VS project from it. -我们为你提供了 __CMakeLists.txt__ 用于创建新的 VS 工程。 +我们为你提供了 [__CMakeLists.txt__](../CMakeLists.txt) 用于创建新的 VS 工程。 If you are using this way, you will __not need__ to continue reading. diff --git a/nasal_gc.h b/nasal_gc.h index 271405a..baa673a 100644 --- a/nasal_gc.h +++ b/nasal_gc.h @@ -1,4 +1,6 @@ #pragma once + +// avoid MSVC warnings #ifdef _MSC_VER #pragma warning (disable:4244) #pragma warning (disable:4267) @@ -64,7 +66,7 @@ struct nas_vec; // vector struct nas_hash; // hashmap(dict) struct nas_func; // function(lambda) struct nas_upval; // upvalue -struct nas_obj; // special objects +struct nas_ghost; // objects struct nas_co; // coroutine struct nas_val; // nas_val includes gc-managed types @@ -117,7 +119,7 @@ public: nas_hash& hash(); nas_func& func(); nas_upval& upval(); - nas_obj& obj (); + nas_ghost& obj (); nas_co& co (); }; @@ -261,7 +263,7 @@ public: } }; -struct nas_obj { +struct nas_ghost { public: usize type; void* ptr; @@ -270,13 +272,13 @@ private: ghost_register_table* ghost_type_table; public: - nas_obj(): type(0), ptr(nullptr), ghost_type_table(nullptr) {} - ~nas_obj() {clear();} + nas_ghost(): type(0), ptr(nullptr), ghost_type_table(nullptr) {} + ~nas_ghost() {clear();} void set(usize, void*, ghost_register_table*); void clear(); public: - friend std::ostream& operator<<(std::ostream& out, nas_obj& ghost) { + friend std::ostream& operator<<(std::ostream& out, nas_ghost& ghost) { out<<"get_ghost_name(ghost.type); out<<" at 0x"<"; return out; @@ -313,7 +315,7 @@ struct nas_val { nas_hash* hash; nas_func* func; nas_upval* upval; - nas_obj* obj; + nas_ghost* obj; nas_co* co; } ptr; @@ -419,13 +421,13 @@ void nas_func::clear() { keys.clear(); } -void nas_obj::set(usize t, void* p, ghost_register_table* table) { +void nas_ghost::set(usize t, void* p, ghost_register_table* table) { type=t; ptr=p; ghost_type_table=table; } -void nas_obj::clear() { +void nas_ghost::clear() { if (!ptr) { return; } @@ -459,7 +461,7 @@ nas_val::nas_val(u8 val_type) { case vm_hash: ptr.hash=new nas_hash; break; case vm_func: ptr.func=new nas_func; break; case vm_upval:ptr.upval=new nas_upval;break; - case vm_obj: ptr.obj=new nas_obj; break; + case vm_obj: ptr.obj=new nas_ghost; break; case vm_co: ptr.co=new nas_co; break; } } @@ -561,7 +563,7 @@ nas_vec& var::vec () {return *val.gcobj->ptr.vec; } nas_hash& var::hash () {return *val.gcobj->ptr.hash; } nas_func& var::func () {return *val.gcobj->ptr.func; } nas_upval& var::upval() {return *val.gcobj->ptr.upval;} -nas_obj& var::obj () {return *val.gcobj->ptr.obj; } +nas_ghost& var::obj () {return *val.gcobj->ptr.obj; } nas_co& var::co () {return *val.gcobj->ptr.co; } const var zero=var::num(0); @@ -747,7 +749,7 @@ void gc::extend(u8 type) { size[index]+=incr[index]; for(u32 i=0;i