diff --git a/luprex/core/Makefile b/luprex/core/Makefile index 6c9cac9e..3a333203 100644 --- a/luprex/core/Makefile +++ b/luprex/core/Makefile @@ -65,7 +65,7 @@ LUA_OBJ_FILES=\ CORE_OBJ_FILES=\ obj/invocation.o\ obj/spookyv2.o\ - obj/eng-malloc.o\ + obj/two-mallocs.o\ obj/debugcollector.o\ obj/drivenengine.o\ obj/dummycert.o\ @@ -103,7 +103,7 @@ lobj/%.o: ../eris-master/src/%.c gcc -Wall $(OPT) -DLUA_USE_APICHECK $(LUAFLAGS) -c -MMD $< -o $@ obj/%.o: cpp/%.cpp - g++ -std=c++17 -Wall $(OPT) -I../eris-master/src -Icpp $(INCS) -c -MMD $< -o $@ + g++ -std=c++17 -Wall $(OPT) -I../eris-master/src -Iwrap -Icpp $(INCS) -c -MMD $< -o $@ $(EXE): $(CORE_OBJ_FILES) $(LUA_OBJ_FILES) g++ -std=c++17 -Wall $(OPT) -o $@ $(CORE_OBJ_FILES) $(LUA_OBJ_FILES) $(LIBS) diff --git a/luprex/core/TODO b/luprex/core/TODO index a9d9da58..50e2b987 100644 --- a/luprex/core/TODO +++ b/luprex/core/TODO @@ -5,3 +5,4 @@ Finish documenting all builtins. Get rid of source_install_builtins after documenting all builtins. - but don't forget that source_install_builtins sets the string metatable. +Do something about std::cerr && std::cout once and for all. diff --git a/luprex/core/cpp/animqueue.cpp b/luprex/core/cpp/animqueue.cpp index 80ca40ce..44bc64cd 100644 --- a/luprex/core/cpp/animqueue.cpp +++ b/luprex/core/cpp/animqueue.cpp @@ -1,11 +1,11 @@ + +#include "animqueue.hpp" +#include "wrap-sstream.hpp" #include -#include +#include "wrap-map.hpp" #include #include "luastack.hpp" -#include "animqueue.hpp" #include "streambuffer.hpp" -#include -#include AnimStep::AnimStep() { clear(); diff --git a/luprex/core/cpp/animqueue.hpp b/luprex/core/cpp/animqueue.hpp index 51c3ae60..de551aff 100644 --- a/luprex/core/cpp/animqueue.hpp +++ b/luprex/core/cpp/animqueue.hpp @@ -45,12 +45,14 @@ #ifndef ANIMQUEUE_HPP #define ANIMQUEUE_HPP -#include -#include -#include +#include "wrap-set.hpp" +#include "wrap-string.hpp" +#include "wrap-deque.hpp" +#include "wrap-ostream.hpp" +#include "wrap-unordered-map.hpp" + #include -#include -#include + #include "streambuffer.hpp" #include "debugcollector.hpp" #include "util.hpp" diff --git a/luprex/core/cpp/debugcollector.cpp b/luprex/core/cpp/debugcollector.cpp index 24494be1..70b8667d 100644 --- a/luprex/core/cpp/debugcollector.cpp +++ b/luprex/core/cpp/debugcollector.cpp @@ -1,7 +1,9 @@ +#include "wrap-algorithm.hpp" + +#include + #include "debugcollector.hpp" -#include -#include #include "util.hpp" void DebugCollector::flush() { diff --git a/luprex/core/cpp/debugcollector.hpp b/luprex/core/cpp/debugcollector.hpp index 80b5b617..6ded7da6 100644 --- a/luprex/core/cpp/debugcollector.hpp +++ b/luprex/core/cpp/debugcollector.hpp @@ -1,11 +1,11 @@ #ifndef DEBUGCOLLECTOR_HPP #define DEBUGCOLLECTOR_HPP -#include -#include -#include -#include -#include +#include "wrap-vector.hpp" +#include "wrap-string.hpp" +#include "wrap-memory.hpp" +#include "wrap-ostream.hpp" +#include "wrap-sstream.hpp" class DebugCollector { private: diff --git a/luprex/core/cpp/drivenengine.cpp b/luprex/core/cpp/drivenengine.cpp index 5ee9dbfb..140093a0 100644 --- a/luprex/core/cpp/drivenengine.cpp +++ b/luprex/core/cpp/drivenengine.cpp @@ -1,10 +1,12 @@ -#include "drivenengine.hpp" -#include -#include -#include +#include "wrap-string.hpp" +#include "wrap-vector.hpp" +#include "wrap-utility.hpp" + #include #include +#include "drivenengine.hpp" + static std::vector> makers; void DrivenEngine::register_maker(const char *kind, DrivenEngineMaker maker) { diff --git a/luprex/core/cpp/drivenengine.hpp b/luprex/core/cpp/drivenengine.hpp index 96c6b081..64750540 100644 --- a/luprex/core/cpp/drivenengine.hpp +++ b/luprex/core/cpp/drivenengine.hpp @@ -92,12 +92,13 @@ #ifndef DRIVENENGINE_HPP #define DRIVENENGINE_HPP -#include -#include -#include -#include -#include "streambuffer.hpp" +#include "wrap-memory.hpp" +#include "wrap-string.hpp" +#include "wrap-vector.hpp" +#include "wrap-ostream.hpp" + #include "util.hpp" +#include "streambuffer.hpp" class DrivenEngine; using UniqueDrivenEngine = std::unique_ptr; diff --git a/luprex/core/cpp/driver-linux.cpp b/luprex/core/cpp/driver-linux.cpp index fa149cad..333362af 100644 --- a/luprex/core/cpp/driver-linux.cpp +++ b/luprex/core/cpp/driver-linux.cpp @@ -1,5 +1,7 @@ +#include "wrap-map.hpp" +#include "wrap-vector.hpp" +#include "wrap-string.hpp" -#include "driver.hpp" #include "driver-util.hpp" #include "drivenengine.hpp" #include "dummycert.hpp" @@ -9,8 +11,7 @@ #include "lpxserver.hpp" #include "drivertests.hpp" #include "source.hpp" -#include -#include + #include #include #include diff --git a/luprex/core/cpp/driver-mingw.cpp b/luprex/core/cpp/driver-mingw.cpp index 5b70fef2..d3afa4ab 100644 --- a/luprex/core/cpp/driver-mingw.cpp +++ b/luprex/core/cpp/driver-mingw.cpp @@ -1,7 +1,10 @@ #define WINVER 0x0600 #define _WIN32_WINNT 0x0600 -#include "driver.hpp" +#include "wrap-map.hpp" +#include "wrap-string.hpp" +#include "wrap-vector.hpp" + #include "driver-util.hpp" #include "drivenengine.hpp" #include "dummycert.hpp" @@ -11,7 +14,7 @@ #include "lpxserver.hpp" #include "drivertests.hpp" #include "source.hpp" -#include + #include #include #include diff --git a/luprex/core/cpp/driver-util.cpp b/luprex/core/cpp/driver-util.cpp index e6bdd4d9..a0d78b63 100644 --- a/luprex/core/cpp/driver-util.cpp +++ b/luprex/core/cpp/driver-util.cpp @@ -1,4 +1,7 @@ +#include "wrap-string.hpp" +#include "wrap-vector.hpp" + #include "driver-util.hpp" #include "luastack.hpp" #include "util.hpp" diff --git a/luprex/core/cpp/driver-util.hpp b/luprex/core/cpp/driver-util.hpp index 0b7fb83b..80cc239c 100644 --- a/luprex/core/cpp/driver-util.hpp +++ b/luprex/core/cpp/driver-util.hpp @@ -2,10 +2,9 @@ #ifndef DRIVER_UTIL_HPP #define DRIVER_UTIL_HPP -#include -#include -#include - +#include "wrap-string.hpp" +#include "wrap-vector.hpp" +#include "wrap-map.hpp" namespace drv { diff --git a/luprex/core/cpp/driver.hpp b/luprex/core/cpp/driver.hpp deleted file mode 100644 index e1b0cbb6..00000000 --- a/luprex/core/cpp/driver.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef DRIVER_HPP -#define DRIVER_HPP - -class DrivenEngine; - -void driver_sysinit(int argc, char *argv[]); -void driver_drive(int argc, char *argv[]); - -#endif // DRIVER_HPP diff --git a/luprex/core/cpp/drivertests.cpp b/luprex/core/cpp/drivertests.cpp index 8b86941c..670226fa 100644 --- a/luprex/core/cpp/drivertests.cpp +++ b/luprex/core/cpp/drivertests.cpp @@ -1,7 +1,10 @@ +#include "wrap-string.hpp" + #include "drivertests.hpp" #include "drivenengine.hpp" +#include "streambuffer.hpp" #include "world.hpp" -#include "eng-malloc.hpp" + #include static void write_closed_message(Channel *ch, StreamBuffer *out) { diff --git a/luprex/core/cpp/eng-malloc.hpp b/luprex/core/cpp/eng-malloc.hpp deleted file mode 100644 index dad4d845..00000000 --- a/luprex/core/cpp/eng-malloc.hpp +++ /dev/null @@ -1,105 +0,0 @@ - - -#ifndef ENG_MALLOC_HPP -#define ENG_MALLOC_HPP - -#include -#include -#include -#include -#include -#include -#include - -// dlmalloc is only used on linux. -extern "C" { -#ifdef __linux__ -void* dlmalloc(size_t x); -void dlfree(void *p); -void* dlrealloc(void*, size_t); -#else -void* dlmalloc(size_t x) { return malloc(x); } -void dlfree(void *p) { free(p); } -void* dlrealloc(void *p, size_t x) { return realloc(p,x); } -#endif -} - -// Return the current state of the dlmalloc allocator as a 30-bit hash. -extern int dlmalloc_hash(); - -// EngAllocator: a class meant to be used as an STL Allocator. -// Causes objects to be allocated using dlmalloc and dlfree. -template -class EngAllocator -{ -public: - using value_type = T; - EngAllocator() noexcept {} - template EngAllocator(EngAllocator const&) noexcept {} - - value_type* allocate(std::size_t n) - { - return static_cast(dlmalloc(n*sizeof(value_type))); - } - - void deallocate(value_type* p, std::size_t) noexcept - { - dlfree(p); - } -}; - -template -bool operator==(EngAllocator const&, EngAllocator const&) noexcept -{ - return true; -} - -template -bool operator!=(EngAllocator const&, EngAllocator const&) noexcept -{ - return false; -} - -namespace eng { - -template -using hash = std::hash; - -template -using less = std::less; - -template -using equal_to = std::equal_to; - -template -using char_traits = std::char_traits; - -template -using pair = std::pair; - -template> -using basic_string = std::basic_string>; - -template> -using basic_stringstream = std::basic_stringstream>; - -template -using vector = std::vector>; - -template> -using map = std::map>>; - -template, class E=equal_to> -using unordered_map = std::unordered_map>>; - -template> -using set = std::set>; - -template, class E=equal_to> -using unordered_set = std::unordered_set>; - -using string = basic_string; -using stringstream = basic_stringstream; -} -#endif // ENG_MALLOC_HPP - diff --git a/luprex/core/cpp/globaldb.hpp b/luprex/core/cpp/globaldb.hpp index 73f831cf..423a2a7e 100644 --- a/luprex/core/cpp/globaldb.hpp +++ b/luprex/core/cpp/globaldb.hpp @@ -26,8 +26,6 @@ #ifndef GLOBALDB_HPP #define GLOBALDB_HPP -#include "luastack.hpp" - #endif // GLOBALDB_HPP diff --git a/luprex/core/cpp/gui.cpp b/luprex/core/cpp/gui.cpp index 8ab7398d..35e99722 100644 --- a/luprex/core/cpp/gui.cpp +++ b/luprex/core/cpp/gui.cpp @@ -1,3 +1,7 @@ +#include "wrap-string.hpp" +#include "wrap-map.hpp" +#include "wrap-vector.hpp" + #include "gui.hpp" #include "luastack.hpp" diff --git a/luprex/core/cpp/gui.hpp b/luprex/core/cpp/gui.hpp index f4018d1c..5a42be8e 100644 --- a/luprex/core/cpp/gui.hpp +++ b/luprex/core/cpp/gui.hpp @@ -1,9 +1,10 @@ #ifndef GUI_HPP #define GUI_HPP -#include -#include -#include +#include "wrap-string.hpp" +#include "wrap-map.hpp" +#include "wrap-vector.hpp" + #include "luastack.hpp" #include "streambuffer.hpp" diff --git a/luprex/core/cpp/idalloc.cpp b/luprex/core/cpp/idalloc.cpp index 2c0d5cc3..0c3f9221 100644 --- a/luprex/core/cpp/idalloc.cpp +++ b/luprex/core/cpp/idalloc.cpp @@ -1,7 +1,9 @@ +#include "wrap-map.hpp" +#include "wrap-sstream.hpp" +#include "wrap-ostream.hpp" +#include "wrap-deque.hpp" + #include "idalloc.hpp" -#include -#include -#include diff --git a/luprex/core/cpp/idalloc.hpp b/luprex/core/cpp/idalloc.hpp index 1c868266..df226e04 100644 --- a/luprex/core/cpp/idalloc.hpp +++ b/luprex/core/cpp/idalloc.hpp @@ -65,13 +65,17 @@ #ifndef IDALLOC_HPP #define IDALLOC_HPP -#include -#include -#include +#include "wrap-map.hpp" +#include "wrap-sstream.hpp" +#include "wrap-ostream.hpp" +#include "wrap-deque.hpp" + #include "luastack.hpp" #include "streambuffer.hpp" #include "debugcollector.hpp" +#include + class IdGlobalPool { public: // Construct and destroy global pools. Note that after constructing diff --git a/luprex/core/cpp/invocation.cpp b/luprex/core/cpp/invocation.cpp index f98855e1..b25c7537 100644 --- a/luprex/core/cpp/invocation.cpp +++ b/luprex/core/cpp/invocation.cpp @@ -1,6 +1,10 @@ +#include "wrap-string.hpp" +#include "wrap-map.hpp" +#include "wrap-deque.hpp" +#include "wrap-sstream.hpp" + #include "invocation.hpp" -#include const std::string &InvocationData::get(const std::string &key) const { static std::string blank_; diff --git a/luprex/core/cpp/invocation.hpp b/luprex/core/cpp/invocation.hpp index 2a1540b6..3bc2b4c2 100644 --- a/luprex/core/cpp/invocation.hpp +++ b/luprex/core/cpp/invocation.hpp @@ -1,9 +1,10 @@ #ifndef INVOCATION_HPP #define INVOCATION_HPP -#include -#include -#include +#include "wrap-string.hpp" +#include "wrap-map.hpp" +#include "wrap-deque.hpp" + #include "streambuffer.hpp" diff --git a/luprex/core/cpp/lpxclient.cpp b/luprex/core/cpp/lpxclient.cpp index 3a45cd0a..d6d4c132 100644 --- a/luprex/core/cpp/lpxclient.cpp +++ b/luprex/core/cpp/lpxclient.cpp @@ -1,12 +1,14 @@ -#include "lpxclient.hpp" +#include "wrap-memory.hpp" +#include "wrap-string.hpp" +#include "wrap-vector.hpp" #include "drivenengine.hpp" +#include "lpxclient.hpp" #include "world.hpp" #include "luaconsole.hpp" #include "invocation.hpp" #include "util.hpp" #include "printbuffer.hpp" -#include class LpxClient : public DrivenEngine { public: diff --git a/luprex/core/cpp/lpxserver.cpp b/luprex/core/cpp/lpxserver.cpp index c9896ee1..de45fa13 100644 --- a/luprex/core/cpp/lpxserver.cpp +++ b/luprex/core/cpp/lpxserver.cpp @@ -1,11 +1,13 @@ -#include "lpxserver.hpp" +#include "wrap-memory.hpp" +#include "wrap-string.hpp" +#include "wrap-vector.hpp" +#include "lpxserver.hpp" #include "world.hpp" #include "drivenengine.hpp" #include "luaconsole.hpp" #include "util.hpp" #include "printbuffer.hpp" -#include class Client { public: diff --git a/luprex/core/cpp/luaconsole.cpp b/luprex/core/cpp/luaconsole.cpp index b03737df..7c31731f 100644 --- a/luprex/core/cpp/luaconsole.cpp +++ b/luprex/core/cpp/luaconsole.cpp @@ -1,7 +1,10 @@ +#include "wrap-string.hpp" +#include "wrap-vector.hpp" -#include #include "luaconsole.hpp" #include "util.hpp" + +#include #include LuaConsole::LuaConsole() { diff --git a/luprex/core/cpp/luaconsole.hpp b/luprex/core/cpp/luaconsole.hpp index debdea8d..cc050851 100644 --- a/luprex/core/cpp/luaconsole.hpp +++ b/luprex/core/cpp/luaconsole.hpp @@ -42,7 +42,9 @@ #ifndef LUACONSOLE_HPP #define LUACONSOLE_HPP -#include +#include "wrap-string.hpp" +#include "wrap-vector.hpp" + #include "luastack.hpp" class LuaConsole { diff --git a/luprex/core/cpp/luasnap.cpp b/luprex/core/cpp/luasnap.cpp index db9f49de..6f3e91b9 100644 --- a/luprex/core/cpp/luasnap.cpp +++ b/luprex/core/cpp/luasnap.cpp @@ -1,8 +1,12 @@ +#include "wrap-sstream.hpp" +#include "wrap-string.hpp" + #include "luasnap.hpp" #include "luastack.hpp" +#include "streambuffer.hpp" + #include -#include LuaSnap::LuaSnap() { diff --git a/luprex/core/cpp/luastack.hpp b/luprex/core/cpp/luastack.hpp index 30b08e55..0204dc30 100644 --- a/luprex/core/cpp/luastack.hpp +++ b/luprex/core/cpp/luastack.hpp @@ -154,6 +154,9 @@ #ifndef LUASTACK_HPP #define LUASTACK_HPP +#include "wrap-string.hpp" +#include "wrap-vector.hpp" + extern "C" { #include "lua.h" #include "lauxlib.h" @@ -161,10 +164,6 @@ extern "C" { #include "eris.h" } -#include -#include -#include - class LuaSlot { protected: int index_; diff --git a/luprex/core/cpp/planemap.cpp b/luprex/core/cpp/planemap.cpp index 38b567cc..f2d7e99a 100644 --- a/luprex/core/cpp/planemap.cpp +++ b/luprex/core/cpp/planemap.cpp @@ -1,9 +1,11 @@ -#include -#include +#include "wrap-algorithm.hpp" + #include "luastack.hpp" #include "util.hpp" #include "planemap.hpp" +#include + // Cell X, Y coordinates are packed such that they have 24 bits for X and Y. // A cell is 10 Meters square. // Cell ID zero is used to represent an invalid position. diff --git a/luprex/core/cpp/planemap.hpp b/luprex/core/cpp/planemap.hpp index 0ecd4b6f..99565fd5 100644 --- a/luprex/core/cpp/planemap.hpp +++ b/luprex/core/cpp/planemap.hpp @@ -73,11 +73,14 @@ #ifndef PLANEMAP_HPP #define PLANEMAP_HPP -#include -#include -#include +#include "wrap-vector.hpp" +#include "wrap-map.hpp" +#include "wrap-string.hpp" + #include "util.hpp" +#include + class PlaneMap; class PlaneItem { diff --git a/luprex/core/cpp/pprint.cpp b/luprex/core/cpp/pprint.cpp index 9cdd9298..b8549053 100644 --- a/luprex/core/cpp/pprint.cpp +++ b/luprex/core/cpp/pprint.cpp @@ -1,7 +1,9 @@ +#include "wrap-ostream.hpp" + #include "pprint.hpp" #include "util.hpp" #include "table.hpp" -#include + #include diff --git a/luprex/core/cpp/pprint.hpp b/luprex/core/cpp/pprint.hpp index a805f5a4..0e2980a9 100644 --- a/luprex/core/cpp/pprint.hpp +++ b/luprex/core/cpp/pprint.hpp @@ -19,6 +19,8 @@ #ifndef PPRINT_HPP #define PPRINT_HPP +#include "wrap-ostream.hpp" + #include "luastack.hpp" // Atomic print to a stream. diff --git a/luprex/core/cpp/printbuffer.cpp b/luprex/core/cpp/printbuffer.cpp index 9b355083..3a547b73 100644 --- a/luprex/core/cpp/printbuffer.cpp +++ b/luprex/core/cpp/printbuffer.cpp @@ -1,6 +1,7 @@ +#include "wrap-algorithm.hpp" +#include "wrap-sstream.hpp" + #include "printbuffer.hpp" -#include -#include struct PrintBufferCore { // The most recent lines printed. diff --git a/luprex/core/cpp/printbuffer.hpp b/luprex/core/cpp/printbuffer.hpp index 953cf4be..02488e1f 100644 --- a/luprex/core/cpp/printbuffer.hpp +++ b/luprex/core/cpp/printbuffer.hpp @@ -77,14 +77,15 @@ #ifndef PRINTBUFFER_HPP #define PRINTBUFFER_HPP +#include "wrap-deque.hpp" +#include "wrap-string.hpp" +#include "wrap-memory.hpp" +#include "wrap-ostream.hpp" + #include "streambuffer.hpp" #include "util.hpp" #include "invocation.hpp" #include "debugcollector.hpp" -#include -#include -#include -#include struct PrintBufferCore; diff --git a/luprex/core/cpp/sched.cpp b/luprex/core/cpp/sched.cpp index 4dac2674..655b83ad 100644 --- a/luprex/core/cpp/sched.cpp +++ b/luprex/core/cpp/sched.cpp @@ -1,9 +1,10 @@ +#include "wrap-sstream.hpp" +#include "wrap-ostream.hpp" + #include "sched.hpp" #include "streambuffer.hpp" #include "luastack.hpp" -#include -#include bool SchedEntry::operator < (const SchedEntry &other) const { if (clock_ < other.clock_) return true; diff --git a/luprex/core/cpp/sched.hpp b/luprex/core/cpp/sched.hpp index 252cc6a0..4f0bb934 100644 --- a/luprex/core/cpp/sched.hpp +++ b/luprex/core/cpp/sched.hpp @@ -1,10 +1,12 @@ #ifndef SCHED_HPP #define SCHED_HPP -#include -#include +#include "wrap-set.hpp" + #include "streambuffer.hpp" +#include + class SchedEntry { private: friend class Schedule; diff --git a/luprex/core/cpp/source.cpp b/luprex/core/cpp/source.cpp index 173e308b..73071c0a 100644 --- a/luprex/core/cpp/source.cpp +++ b/luprex/core/cpp/source.cpp @@ -1,20 +1,21 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include "wrap-string.hpp" +#include "wrap-vector.hpp" +#include "wrap-map.hpp" +#include "wrap-set.hpp" +#include "wrap-algorithm.hpp" +#include "wrap-sstream.hpp" + #include "util.hpp" - #include "luastack.hpp" #include "traceback.hpp" #include "table.hpp" #include "source.hpp" #include "luasnap.hpp" +#include +#include + LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") { LuaArg classname; LuaRet classtab; @@ -375,7 +376,7 @@ static std::string source_load_lfunctions(lua_State *L) { } // Now call the closures in the proper order. - std::stringstream errss; + std::ostringstream errss; for (const auto &p : indices) { LS.rawget(info, sourcedb, p.second); LS.rawget(closure, info, "loadresult"); diff --git a/luprex/core/cpp/source.hpp b/luprex/core/cpp/source.hpp index 4fed96e0..de263da6 100644 --- a/luprex/core/cpp/source.hpp +++ b/luprex/core/cpp/source.hpp @@ -120,6 +120,8 @@ #ifndef SOURCE_HPP #define SOURCE_HPP +#include "wrap-string.hpp" + #include "util.hpp" #include "luastack.hpp" #include "streambuffer.hpp" diff --git a/luprex/core/cpp/spookyv2.hpp b/luprex/core/cpp/spookyv2.hpp index 813fba1b..735fcc33 100644 --- a/luprex/core/cpp/spookyv2.hpp +++ b/luprex/core/cpp/spookyv2.hpp @@ -29,9 +29,8 @@ #ifndef SPOOKYV2_HPP #define SPOOKYV2_HPP -#include +#include #include -#include class SpookyHash { diff --git a/luprex/core/cpp/streambuffer.cpp b/luprex/core/cpp/streambuffer.cpp index 84d33d9e..3253f771 100644 --- a/luprex/core/cpp/streambuffer.cpp +++ b/luprex/core/cpp/streambuffer.cpp @@ -1,5 +1,9 @@ +#include "wrap-string.hpp" + +#include "two-mallocs.hpp" #include "streambuffer.hpp" #include "spookyv2.hpp" + #include #include diff --git a/luprex/core/cpp/streambuffer.hpp b/luprex/core/cpp/streambuffer.hpp index 59011dc8..7bef6576 100644 --- a/luprex/core/cpp/streambuffer.hpp +++ b/luprex/core/cpp/streambuffer.hpp @@ -212,13 +212,15 @@ #ifndef STREAMBUFFER_HPP #define STREAMBUFFER_HPP +#include "wrap-string.hpp" +#include "wrap-sstream.hpp" +#include "wrap-utility.hpp" + #include "luastack.hpp" #include "util.hpp" + #include -#include -#include #include -#include class StreamException { diff --git a/luprex/core/cpp/table.cpp b/luprex/core/cpp/table.cpp index 5a25c1a2..1661f9b7 100644 --- a/luprex/core/cpp/table.cpp +++ b/luprex/core/cpp/table.cpp @@ -1,3 +1,6 @@ + +#include "wrap-string.hpp" + #include "table.hpp" #include "source.hpp" diff --git a/luprex/core/cpp/textgame.cpp b/luprex/core/cpp/textgame.cpp index 2749b370..f72868a8 100644 --- a/luprex/core/cpp/textgame.cpp +++ b/luprex/core/cpp/textgame.cpp @@ -1,10 +1,9 @@ -#include -#include -#include -#include -#include -#include +#include "wrap-vector.hpp" +#include "wrap-string.hpp" +#include "wrap-memory.hpp" +#include "wrap-algorithm.hpp" + #include "luastack.hpp" #include "util.hpp" #include "gui.hpp" @@ -15,9 +14,10 @@ #include "luaconsole.hpp" #include "pprint.hpp" #include "printbuffer.hpp" -#include -#include +#include +#include +#include class TextGame : public DrivenEngine { private: diff --git a/luprex/core/cpp/traceback.cpp b/luprex/core/cpp/traceback.cpp index 7f586f8c..f5fd9d3e 100644 --- a/luprex/core/cpp/traceback.cpp +++ b/luprex/core/cpp/traceback.cpp @@ -1,10 +1,10 @@ -#include #include "traceback.hpp" +#include + #define TRACEBACK_LEVELS1 12 #define TRACEBACK_LEVELS2 10 - // Call this with the error message on top of the stack. // The error message is replaced with a traceback. // diff --git a/luprex/core/cpp/eng-malloc.cpp b/luprex/core/cpp/two-mallocs.cpp similarity index 100% rename from luprex/core/cpp/eng-malloc.cpp rename to luprex/core/cpp/two-mallocs.cpp diff --git a/luprex/core/cpp/two-mallocs.hpp b/luprex/core/cpp/two-mallocs.hpp new file mode 100644 index 00000000..7dd89597 --- /dev/null +++ b/luprex/core/cpp/two-mallocs.hpp @@ -0,0 +1,78 @@ + + +#ifndef TWO_MALLOCS_HPP +#define TWO_MALLOCS_HPP + +#include + +// dlmalloc is only used on linux. +extern "C" { +#ifdef __linux__ +void* dlmalloc(size_t x); +void dlfree(void *p); +void* dlrealloc(void*, size_t); +#else +void* dlmalloc(size_t x) { return malloc(x); } +void dlfree(void *p) { free(p); } +void* dlrealloc(void *p, size_t x) { return realloc(p,x); } +#endif +} + +// Return the current state of the dlmalloc allocator as a 30-bit hash. +extern int dlmalloc_hash(); + +// EngAllocator: a class meant to be used as an STL Allocator. +// Causes objects to be allocated using dlmalloc and dlfree. +template +class EngAllocator +{ +public: + using value_type = T; + EngAllocator() noexcept {} + template EngAllocator(EngAllocator const&) noexcept {} + + value_type* allocate(std::size_t n) + { + return static_cast(dlmalloc(n*sizeof(value_type))); + } + + void deallocate(value_type* p, std::size_t) noexcept + { + dlfree(p); + } +}; + +template +bool operator==(EngAllocator const&, EngAllocator const&) noexcept +{ + return true; +} + +template +bool operator!=(EngAllocator const&, EngAllocator const&) noexcept +{ + return false; +} + +// namespace eng { + +// template +// using hash = std::hash; + +// template +// using less = std::less; + +// template +// using equal_to = std::equal_to; + +// template +// using char_traits = std::char_traits; + +// template +// using pair = std::pair; + + + +// } +#endif // TWO_MALLOCS_HPP + diff --git a/luprex/core/cpp/util.cpp b/luprex/core/cpp/util.cpp index 898d8076..6c8be2ca 100644 --- a/luprex/core/cpp/util.cpp +++ b/luprex/core/cpp/util.cpp @@ -1,14 +1,16 @@ -#include -#include -#include -#include +#include "wrap-string.hpp" +#include "wrap-vector.hpp" +#include "wrap-algorithm.hpp" + #include "util.hpp" + #include #include #include #include #include -#include +#include +#include #ifdef WIN32 #endif diff --git a/luprex/core/cpp/util.hpp b/luprex/core/cpp/util.hpp index 93a1e638..d807d979 100644 --- a/luprex/core/cpp/util.hpp +++ b/luprex/core/cpp/util.hpp @@ -1,16 +1,16 @@ #ifndef UTIL_HPP #define UTIL_HPP -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "wrap-string.hpp" +#include "wrap-string-view.hpp" +#include "wrap-set.hpp" +#include "wrap-map.hpp" +#include "wrap-algorithm.hpp" +#include "wrap-sstream.hpp" +#include "wrap-ostream.hpp" +#include "wrap-memory.hpp" +#include "wrap-utility.hpp" + #include "luastack.hpp" #include "spookyv2.hpp" diff --git a/luprex/core/cpp/world.hpp b/luprex/core/cpp/world.hpp index 70d827f6..d0aa98fa 100644 --- a/luprex/core/cpp/world.hpp +++ b/luprex/core/cpp/world.hpp @@ -2,6 +2,12 @@ #ifndef WORLD_HPP #define WORLD_HPP +#include "wrap-set.hpp" +#include "wrap-utility.hpp" +#include "wrap-memory.hpp" +#include "wrap-unordered-map.hpp" +#include "wrap-map.hpp" + #include "luastack.hpp" #include "planemap.hpp" #include "idalloc.hpp" @@ -14,10 +20,6 @@ #include "source.hpp" #include "gui.hpp" #include "luasnap.hpp" -#include -#include -#include -#include class World; diff --git a/luprex/core/wrap/mkstub.py b/luprex/core/wrap/mkstub.py new file mode 100755 index 00000000..fd40bdba --- /dev/null +++ b/luprex/core/wrap/mkstub.py @@ -0,0 +1,22 @@ +#!/usr/bin/python3 + +import sys + +base=sys.argv[1] +ubase=base.upper() +dash=base.replace("_", "-") + +with open(f"wrap-{dash}.hpp", "w") as f: + print(f"#ifndef WRAP_{ubase}_HPP", file=f) + print(f"#define WRAP_{ubase}_HPP", file=f) + print("", file=f) + print('#include "two-mallocs.hpp"', file=f) + print(f"#include <{base}>", file=f) + print("", file=f) + print("namespace eng {", file=f) + print("} // namespace eng", file=f) + print("", file=f) + print("namespace drv {", file=f) + print("} // namespace drv", file=f) + print("", file=f) + print(f"#endif // WRAP_{ubase}_HPP", file=f) diff --git a/luprex/core/wrap/wrap-algorithm.hpp b/luprex/core/wrap/wrap-algorithm.hpp new file mode 100644 index 00000000..68809345 --- /dev/null +++ b/luprex/core/wrap/wrap-algorithm.hpp @@ -0,0 +1,13 @@ +#ifndef WRAP_ALGORITHM_HPP +#define WRAP_ALGORITHM_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +} // namespace eng + +namespace drv { +} // namespace drv + +#endif // WRAP_ALGORITHM_HPP diff --git a/luprex/core/wrap/wrap-deque.hpp b/luprex/core/wrap/wrap-deque.hpp new file mode 100644 index 00000000..2da70f1d --- /dev/null +++ b/luprex/core/wrap/wrap-deque.hpp @@ -0,0 +1,17 @@ +#ifndef WRAP_DEQUE_HPP +#define WRAP_DEQUE_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template +using deque = std::deque>; +} // namespace eng + +namespace drv { +template +using deque = std::deque>; +} // namespace drv + +#endif // WRAP_DEQUE_HPP diff --git a/luprex/core/wrap/wrap-map.hpp b/luprex/core/wrap/wrap-map.hpp new file mode 100644 index 00000000..3d45ad25 --- /dev/null +++ b/luprex/core/wrap/wrap-map.hpp @@ -0,0 +1,25 @@ +#ifndef WRAP_MAP_HPP +#define WRAP_MAP_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template +using less = std::less; +template +using pair = std::pair; +template> +using map = std::map>>; +} // namespace eng + +namespace drv { +template +using less = std::less; +template +using pair = std::pair; +template> +using map = std::map>>; +} // namespace drv + +#endif // WRAP_MAP_HPP diff --git a/luprex/core/wrap/wrap-memory.hpp b/luprex/core/wrap/wrap-memory.hpp new file mode 100644 index 00000000..cddfddb1 --- /dev/null +++ b/luprex/core/wrap/wrap-memory.hpp @@ -0,0 +1,21 @@ +#ifndef WRAP_MEMORY_HPP +#define WRAP_MEMORY_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template> +using unique_ptr = std::unique_ptr; +template +using shared_ptr = std::shared_ptr; +} // namespace eng + +namespace drv { +template> +using unique_ptr = std::unique_ptr; +template +using shared_ptr = std::shared_ptr; +} // namespace drv + +#endif // WRAP_MEMORY_HPP diff --git a/luprex/core/wrap/wrap-ostream.hpp b/luprex/core/wrap/wrap-ostream.hpp new file mode 100644 index 00000000..03c1b2bf --- /dev/null +++ b/luprex/core/wrap/wrap-ostream.hpp @@ -0,0 +1,15 @@ +#ifndef WRAP_OSTREAM_HPP +#define WRAP_OSTREAM_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +using ostream = std::ostream; +} // namespace eng + +namespace drv { +using ostream = std::ostream; +} // namespace drv + +#endif // WRAP_OSTREAM_HPP diff --git a/luprex/core/wrap/wrap-set.hpp b/luprex/core/wrap/wrap-set.hpp new file mode 100644 index 00000000..205482ff --- /dev/null +++ b/luprex/core/wrap/wrap-set.hpp @@ -0,0 +1,21 @@ +#ifndef WRAP_SET_HPP +#define WRAP_SET_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template +using less = std::less; +template> +using set = std::set>; +} // namespace eng + +namespace drv { +template +using less = std::less; +template> +using set = std::set>; +} // namespace drv + +#endif // WRAP_SET_HPP diff --git a/luprex/core/wrap/wrap-sstream.hpp b/luprex/core/wrap/wrap-sstream.hpp new file mode 100644 index 00000000..84db092c --- /dev/null +++ b/luprex/core/wrap/wrap-sstream.hpp @@ -0,0 +1,19 @@ +#ifndef WRAP_SSTREAM_HPP +#define WRAP_SSTREAM_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template> +using basic_ostringstream = std::basic_ostringstream>; +using ostringstream = std::basic_ostringstream; +} // namespace eng + +namespace drv { +template> +using basic_ostringstream = std::basic_ostringstream>; +using ostringstream = std::basic_ostringstream; +} // namespace drv + +#endif // WRAP_SSTREAM_HPP diff --git a/luprex/core/wrap/wrap-string-view.hpp b/luprex/core/wrap/wrap-string-view.hpp new file mode 100644 index 00000000..98ff780e --- /dev/null +++ b/luprex/core/wrap/wrap-string-view.hpp @@ -0,0 +1,19 @@ +#ifndef WRAP_STRING_VIEW_HPP +#define WRAP_STRING_VIEW_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template> +using basic_string_view = std::basic_string_view; +using string_view = basic_string_view; +} // namespace eng + +namespace drv { +template> +using basic_string_view = std::basic_string_view; +using string_view = basic_string_view; +} // namespace drv + +#endif // WRAP_STRING_VIEW_HPP diff --git a/luprex/core/wrap/wrap-string.hpp b/luprex/core/wrap/wrap-string.hpp new file mode 100644 index 00000000..4af14b4a --- /dev/null +++ b/luprex/core/wrap/wrap-string.hpp @@ -0,0 +1,19 @@ +#ifndef WRAP_STRING_HPP +#define WRAP_STRING_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template> +using basic_string = std::basic_string>; +using string = basic_string; +} // namespace eng + +namespace drv { +template> +using basic_string = std::basic_string>; +using string = basic_string; +} // namespace drv + +#endif // WRAP_STRING_HPP diff --git a/luprex/core/wrap/wrap-unordered-map.hpp b/luprex/core/wrap/wrap-unordered-map.hpp new file mode 100644 index 00000000..b2e5c1a7 --- /dev/null +++ b/luprex/core/wrap/wrap-unordered-map.hpp @@ -0,0 +1,29 @@ +#ifndef WRAP_UNORDERED_MAP_HPP +#define WRAP_UNORDERED_MAP_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template +using hash = std::hash; +template +using equal_to = std::equal_to; +template +using pair = std::pair; +template, class E=std::equal_to> +using unordered_map = std::unordered_map>>; +} // namespace eng + +namespace drv { +template +using hash = std::hash; +template +using equal_to = std::equal_to; +template +using pair = std::pair; +template, class E=std::equal_to> +using unordered_map = std::unordered_map>>; +} // namespace drv + +#endif // WRAP_UNORDERED_MAP_HPP diff --git a/luprex/core/wrap/wrap-unordered-set.hpp b/luprex/core/wrap/wrap-unordered-set.hpp new file mode 100644 index 00000000..4c2d414f --- /dev/null +++ b/luprex/core/wrap/wrap-unordered-set.hpp @@ -0,0 +1,25 @@ +#ifndef WRAP_UNORDERED_SET_HPP +#define WRAP_UNORDERED_SET_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template +using hash = std::hash; +template +using equal_to = std::equal_to; +template, class E=std::equal_to> +using unordered_set = std::unordered_set>; +} // namespace eng + +namespace drv { +template +using hash = std::hash; +template +using equal_to = std::equal_to; +template, class E=std::equal_to> +using unordered_set = std::unordered_set>; +} // namespace drv + +#endif // WRAP_UNORDERED_SET_HPP diff --git a/luprex/core/wrap/wrap-utility.hpp b/luprex/core/wrap/wrap-utility.hpp new file mode 100644 index 00000000..2aadc0ed --- /dev/null +++ b/luprex/core/wrap/wrap-utility.hpp @@ -0,0 +1,17 @@ +#ifndef WRAP_UTILITY_HPP +#define WRAP_UTILITY_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template +using pair = std::pair; +} // namespace eng + +namespace drv { +template +using pair = std::pair; +} // namespace drv + +#endif // WRAP_UTILITY_HPP diff --git a/luprex/core/wrap/wrap-vector.hpp b/luprex/core/wrap/wrap-vector.hpp new file mode 100644 index 00000000..8ee5daa6 --- /dev/null +++ b/luprex/core/wrap/wrap-vector.hpp @@ -0,0 +1,17 @@ +#ifndef WRAP_VECTOR_HPP +#define WRAP_VECTOR_HPP + +#include "two-mallocs.hpp" +#include + +namespace eng { +template +using vector = std::vector>; +} // namespace eng + +namespace drv { +template +using vector = std::vector>; +} // namespace drv + +#endif // WRAP_VECTOR_HPP