From cb23d0955cbfa157866242502f2e91753919af29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Ferdinand=20Rivera=20Morell?= Date: Sat, 9 Apr 2022 10:08:55 -0500 Subject: [PATCH] Workarounds for old msvc compile errors. --- src/engine/function.cpp | 50 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/engine/function.cpp b/src/engine/function.cpp index 31a07c0a9..fe95a0ab3 100644 --- a/src/engine/function.cpp +++ b/src/engine/function.cpp @@ -326,29 +326,12 @@ struct _stack // Move "v" to a new slot in ther stack. Returns a reference to the new item. template - remove_cref_t & push( T&& v ) - { - using U = remove_cref_t; - check_alignment(); - data = (char *)data - sizeof(U); - check_alignment(); - cleanups.push_back(cleanup_info{&_stack::cleanup_item, this, 1}); - return top() = v; - } + remove_cref_t & push( T&& v ); // Copy "v" into "n" new items at the top of the stack. Returns a pointer // to the first, i.e. top most, new item. template - remove_cref_t * push( T v, int32_t n ) - { - using U = remove_cref_t; - check_alignment(); - data = (char *)data - ( n * sizeof(U) ); - check_alignment(); - std::uninitialized_fill_n( reinterpret_cast( data ), n, v ); - cleanups.push_back(cleanup_info{&_stack::cleanup_item, this, n}); - return reinterpret_cast( data ); - } + remove_cref_t * push( T v, int32_t n ); // Removes the top most "T" item from the stack and returns a copy of it. template @@ -436,7 +419,7 @@ struct _stack } template - static void cleanup_item(_stack * s, int32_t n) + static void cleanup_item(_stack * s, int32_t n, T*_=nullptr) { s->data = (char *)s->data + ( n * sizeof(remove_cref_t) ); s->check_alignment(); @@ -444,7 +427,7 @@ struct _stack }; template <> -void _stack::cleanup_item(_stack * s, int32_t n) +void _stack::cleanup_item(_stack * s, int32_t n, LIST**) { for (int32_t i = 0; i < n; ++i) { @@ -454,6 +437,31 @@ void _stack::cleanup_item(_stack * s, int32_t n) s->check_alignment(); } +template +remove_cref_t & _stack::push( T&& v ) +{ + using U = remove_cref_t; + check_alignment(); + data = (char *)data - sizeof(U); + check_alignment(); + cleanup_info ci = { (cleanup_f)&_stack::cleanup_item, this, 1}; + cleanups.push_back(ci); + return top() = v; +} + +template +remove_cref_t * _stack::push( T v, int32_t n ) +{ + using U = remove_cref_t; + check_alignment(); + data = (char *)data - ( n * sizeof(U) ); + check_alignment(); + std::uninitialized_fill_n( reinterpret_cast( data ), n, v ); + cleanup_info ci = { (cleanup_f)&_stack::cleanup_item, this, n}; + cleanups.push_back(ci); + return reinterpret_cast( data ); +} + STACK * stack_global() { static STACK result;