From 3a475a78b3e1ac3692dd10c9706d590fd6b1ffeb Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 19 May 2024 19:14:14 +0800 Subject: [PATCH] add emplace --- .github/workflows/main.yml | 2 +- CMakeLists.txt | 2 +- include/pocketpy/frame.h | 6 ++++++ src/ceval.cpp | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ef2e02c3..f9bc8291 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: run: | python amalgamate.py cd amalgamated - cl.exe /std:c++17 /EHsc /utf-8 /O2 /I. /DPK_ENABLE_OS=1 main.cpp /link /out:pkpy.exe + cl.exe /std:c++17 /EHsc /utf-8 /Ox /I. /DPK_ENABLE_OS=1 main.cpp /link /out:pkpy.exe - uses: actions/upload-artifact@v3 with: path: amalgamated/pkpy.exe diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b582276..9af1a254 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /O2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /utf-8 /Ox /jumptablerdata /GS-") else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -frtti -O2") diff --git a/include/pocketpy/frame.h b/include/pocketpy/frame.h index f239a04c..fafafb83 100644 --- a/include/pocketpy/frame.h +++ b/include/pocketpy/frame.h @@ -59,6 +59,12 @@ struct ValueStack { void clear() { _sp = _begin; } bool is_overflow() const { return _sp >= _max_end; } + template + void emplace(Args&&... args){ + new(_sp) PyVar(std::forward(args)...); + ++_sp; + } + PyVar operator[](int i) const { return _begin[i]; } PyVar& operator[](int i) { return _begin[i]; } diff --git a/src/ceval.cpp b/src/ceval.cpp index c27e0e25..d7ed2d4d 100644 --- a/src/ceval.cpp +++ b/src/ceval.cpp @@ -157,7 +157,9 @@ __NEXT_STEP: case OP_LOAD_TRUE: PUSH(True); DISPATCH() case OP_LOAD_FALSE: PUSH(False); DISPATCH() /*****************************************/ - case OP_LOAD_SMALL_INT: PUSH(VAR((int16_t)byte.arg)); DISPATCH() + case OP_LOAD_SMALL_INT: + s_data.emplace(tp_int, (i64)(int16_t)byte.arg); + DISPATCH() /*****************************************/ case OP_LOAD_ELLIPSIS: PUSH(Ellipsis); DISPATCH() case OP_LOAD_FUNCTION: {