add emplace

This commit is contained in:
blueloveTH 2024-05-19 19:14:14 +08:00
parent 9a085d1767
commit 3a475a78b3
4 changed files with 11 additions and 3 deletions

View File

@ -21,7 +21,7 @@ jobs:
run: | run: |
python amalgamate.py python amalgamate.py
cd amalgamated 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 - uses: actions/upload-artifact@v3
with: with:
path: amalgamated/pkpy.exe path: amalgamated/pkpy.exe

View File

@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC) 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() else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -frtti -O2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -frtti -O2")

View File

@ -59,6 +59,12 @@ struct ValueStack {
void clear() { _sp = _begin; } void clear() { _sp = _begin; }
bool is_overflow() const { return _sp >= _max_end; } bool is_overflow() const { return _sp >= _max_end; }
template<typename... Args>
void emplace(Args&&... args){
new(_sp) PyVar(std::forward<Args>(args)...);
++_sp;
}
PyVar operator[](int i) const { return _begin[i]; } PyVar operator[](int i) const { return _begin[i]; }
PyVar& operator[](int i) { return _begin[i]; } PyVar& operator[](int i) { return _begin[i]; }

View File

@ -157,7 +157,9 @@ __NEXT_STEP:
case OP_LOAD_TRUE: PUSH(True); DISPATCH() case OP_LOAD_TRUE: PUSH(True); DISPATCH()
case OP_LOAD_FALSE: PUSH(False); 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_ELLIPSIS: PUSH(Ellipsis); DISPATCH()
case OP_LOAD_FUNCTION: { case OP_LOAD_FUNCTION: {