Wrap all STL includes to support drv:: and eng::

This commit is contained in:
2022-02-23 23:08:28 -05:00
parent f2ab8d9e34
commit acc00289fb
63 changed files with 552 additions and 237 deletions

View File

@@ -65,7 +65,7 @@ LUA_OBJ_FILES=\
CORE_OBJ_FILES=\ CORE_OBJ_FILES=\
obj/invocation.o\ obj/invocation.o\
obj/spookyv2.o\ obj/spookyv2.o\
obj/eng-malloc.o\ obj/two-mallocs.o\
obj/debugcollector.o\ obj/debugcollector.o\
obj/drivenengine.o\ obj/drivenengine.o\
obj/dummycert.o\ obj/dummycert.o\
@@ -103,7 +103,7 @@ lobj/%.o: ../eris-master/src/%.c
gcc -Wall $(OPT) -DLUA_USE_APICHECK $(LUAFLAGS) -c -MMD $< -o $@ gcc -Wall $(OPT) -DLUA_USE_APICHECK $(LUAFLAGS) -c -MMD $< -o $@
obj/%.o: cpp/%.cpp 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) $(EXE): $(CORE_OBJ_FILES) $(LUA_OBJ_FILES)
g++ -std=c++17 -Wall $(OPT) -o $@ $(CORE_OBJ_FILES) $(LUA_OBJ_FILES) $(LIBS) g++ -std=c++17 -Wall $(OPT) -o $@ $(CORE_OBJ_FILES) $(LUA_OBJ_FILES) $(LIBS)

View File

@@ -5,3 +5,4 @@ Finish documenting all builtins.
Get rid of source_install_builtins after 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. - but don't forget that source_install_builtins sets the string metatable.
Do something about std::cerr && std::cout once and for all.

View File

@@ -1,11 +1,11 @@
#include "animqueue.hpp"
#include "wrap-sstream.hpp"
#include <limits> #include <limits>
#include <map> #include "wrap-map.hpp"
#include <cmath> #include <cmath>
#include "luastack.hpp" #include "luastack.hpp"
#include "animqueue.hpp"
#include "streambuffer.hpp" #include "streambuffer.hpp"
#include <ostream>
#include <sstream>
AnimStep::AnimStep() { AnimStep::AnimStep() {
clear(); clear();

View File

@@ -45,12 +45,14 @@
#ifndef ANIMQUEUE_HPP #ifndef ANIMQUEUE_HPP
#define ANIMQUEUE_HPP #define ANIMQUEUE_HPP
#include <set> #include "wrap-set.hpp"
#include <string> #include "wrap-string.hpp"
#include <deque> #include "wrap-deque.hpp"
#include "wrap-ostream.hpp"
#include "wrap-unordered-map.hpp"
#include <cassert> #include <cassert>
#include <ostream>
#include <unordered_map>
#include "streambuffer.hpp" #include "streambuffer.hpp"
#include "debugcollector.hpp" #include "debugcollector.hpp"
#include "util.hpp" #include "util.hpp"

View File

@@ -1,7 +1,9 @@
#include "wrap-algorithm.hpp"
#include <cstring>
#include "debugcollector.hpp" #include "debugcollector.hpp"
#include <algorithm>
#include <cstring>
#include "util.hpp" #include "util.hpp"
void DebugCollector::flush() { void DebugCollector::flush() {

View File

@@ -1,11 +1,11 @@
#ifndef DEBUGCOLLECTOR_HPP #ifndef DEBUGCOLLECTOR_HPP
#define DEBUGCOLLECTOR_HPP #define DEBUGCOLLECTOR_HPP
#include <vector> #include "wrap-vector.hpp"
#include <string> #include "wrap-string.hpp"
#include <memory> #include "wrap-memory.hpp"
#include <ostream> #include "wrap-ostream.hpp"
#include <sstream> #include "wrap-sstream.hpp"
class DebugCollector { class DebugCollector {
private: private:

View File

@@ -1,10 +1,12 @@
#include "drivenengine.hpp" #include "wrap-string.hpp"
#include <string> #include "wrap-vector.hpp"
#include <vector> #include "wrap-utility.hpp"
#include <utility>
#include <iostream> #include <iostream>
#include <cstring> #include <cstring>
#include "drivenengine.hpp"
static std::vector<std::pair<std::string, DrivenEngineMaker>> makers; static std::vector<std::pair<std::string, DrivenEngineMaker>> makers;
void DrivenEngine::register_maker(const char *kind, DrivenEngineMaker maker) { void DrivenEngine::register_maker(const char *kind, DrivenEngineMaker maker) {

View File

@@ -92,12 +92,13 @@
#ifndef DRIVENENGINE_HPP #ifndef DRIVENENGINE_HPP
#define DRIVENENGINE_HPP #define DRIVENENGINE_HPP
#include <memory> #include "wrap-memory.hpp"
#include <string> #include "wrap-string.hpp"
#include <vector> #include "wrap-vector.hpp"
#include <ostream> #include "wrap-ostream.hpp"
#include "streambuffer.hpp"
#include "util.hpp" #include "util.hpp"
#include "streambuffer.hpp"
class DrivenEngine; class DrivenEngine;
using UniqueDrivenEngine = std::unique_ptr<DrivenEngine>; using UniqueDrivenEngine = std::unique_ptr<DrivenEngine>;

View File

@@ -1,5 +1,7 @@
#include "wrap-map.hpp"
#include "wrap-vector.hpp"
#include "wrap-string.hpp"
#include "driver.hpp"
#include "driver-util.hpp" #include "driver-util.hpp"
#include "drivenengine.hpp" #include "drivenengine.hpp"
#include "dummycert.hpp" #include "dummycert.hpp"
@@ -9,8 +11,7 @@
#include "lpxserver.hpp" #include "lpxserver.hpp"
#include "drivertests.hpp" #include "drivertests.hpp"
#include "source.hpp" #include "source.hpp"
#include <map>
#include <vector>
#include <iostream> #include <iostream>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>

View File

@@ -1,7 +1,10 @@
#define WINVER 0x0600 #define WINVER 0x0600
#define _WIN32_WINNT 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 "driver-util.hpp"
#include "drivenengine.hpp" #include "drivenengine.hpp"
#include "dummycert.hpp" #include "dummycert.hpp"
@@ -11,7 +14,7 @@
#include "lpxserver.hpp" #include "lpxserver.hpp"
#include "drivertests.hpp" #include "drivertests.hpp"
#include "source.hpp" #include "source.hpp"
#include <map>
#include <iostream> #include <iostream>
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>

View File

@@ -1,4 +1,7 @@
#include "wrap-string.hpp"
#include "wrap-vector.hpp"
#include "driver-util.hpp" #include "driver-util.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "util.hpp" #include "util.hpp"

View File

@@ -2,10 +2,9 @@
#ifndef DRIVER_UTIL_HPP #ifndef DRIVER_UTIL_HPP
#define DRIVER_UTIL_HPP #define DRIVER_UTIL_HPP
#include <string> #include "wrap-string.hpp"
#include <vector> #include "wrap-vector.hpp"
#include <map> #include "wrap-map.hpp"
namespace drv { namespace drv {

View File

@@ -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

View File

@@ -1,7 +1,10 @@
#include "wrap-string.hpp"
#include "drivertests.hpp" #include "drivertests.hpp"
#include "drivenengine.hpp" #include "drivenengine.hpp"
#include "streambuffer.hpp"
#include "world.hpp" #include "world.hpp"
#include "eng-malloc.hpp"
#include <iomanip> #include <iomanip>
static void write_closed_message(Channel *ch, StreamBuffer *out) { static void write_closed_message(Channel *ch, StreamBuffer *out) {

View File

@@ -1,105 +0,0 @@
#ifndef ENG_MALLOC_HPP
#define ENG_MALLOC_HPP
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
// 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 T>
class EngAllocator
{
public:
using value_type = T;
EngAllocator() noexcept {}
template <class U> EngAllocator(EngAllocator<U> const&) noexcept {}
value_type* allocate(std::size_t n)
{
return static_cast<value_type*>(dlmalloc(n*sizeof(value_type)));
}
void deallocate(value_type* p, std::size_t) noexcept
{
dlfree(p);
}
};
template <class T, class U>
bool operator==(EngAllocator<T> const&, EngAllocator<U> const&) noexcept
{
return true;
}
template <class T, class U>
bool operator!=(EngAllocator<T> const&, EngAllocator<U> const&) noexcept
{
return false;
}
namespace eng {
template<class T>
using hash = std::hash<T>;
template<class T>
using less = std::less<T>;
template<class T>
using equal_to = std::equal_to<T>;
template<class T>
using char_traits = std::char_traits<T>;
template<class A, class B>
using pair = std::pair<A, B>;
template<class C, class T=char_traits<C>>
using basic_string = std::basic_string<C, T, EngAllocator<C>>;
template<class C, class T=char_traits<C>>
using basic_stringstream = std::basic_stringstream<C, T, EngAllocator<C>>;
template<class T>
using vector = std::vector<T, EngAllocator<T>>;
template<class K, class V, class C=less<K>>
using map = std::map<K, V, C, EngAllocator<pair<const K, V>>>;
template<class K, class V, class H=hash<K>, class E=equal_to<K>>
using unordered_map = std::unordered_map<K, V, H, E, EngAllocator<pair<const K, V>>>;
template<class K, class C=std::less<K>>
using set = std::set<K, C, EngAllocator<K>>;
template<class K, class H=hash<K>, class E=equal_to<K>>
using unordered_set = std::unordered_set<K, H, E, EngAllocator<K>>;
using string = basic_string<char>;
using stringstream = basic_stringstream<char>;
}
#endif // ENG_MALLOC_HPP

View File

@@ -26,8 +26,6 @@
#ifndef GLOBALDB_HPP #ifndef GLOBALDB_HPP
#define GLOBALDB_HPP #define GLOBALDB_HPP
#include "luastack.hpp"
#endif // GLOBALDB_HPP #endif // GLOBALDB_HPP

View File

@@ -1,3 +1,7 @@
#include "wrap-string.hpp"
#include "wrap-map.hpp"
#include "wrap-vector.hpp"
#include "gui.hpp" #include "gui.hpp"
#include "luastack.hpp" #include "luastack.hpp"

View File

@@ -1,9 +1,10 @@
#ifndef GUI_HPP #ifndef GUI_HPP
#define GUI_HPP #define GUI_HPP
#include <string> #include "wrap-string.hpp"
#include <map> #include "wrap-map.hpp"
#include <vector> #include "wrap-vector.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "streambuffer.hpp" #include "streambuffer.hpp"

View File

@@ -1,7 +1,9 @@
#include "wrap-map.hpp"
#include "wrap-sstream.hpp"
#include "wrap-ostream.hpp"
#include "wrap-deque.hpp"
#include "idalloc.hpp" #include "idalloc.hpp"
#include <map>
#include <sstream>
#include <ostream>

View File

@@ -65,13 +65,17 @@
#ifndef IDALLOC_HPP #ifndef IDALLOC_HPP
#define IDALLOC_HPP #define IDALLOC_HPP
#include <cstdint> #include "wrap-map.hpp"
#include <vector> #include "wrap-sstream.hpp"
#include <deque> #include "wrap-ostream.hpp"
#include "wrap-deque.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "streambuffer.hpp" #include "streambuffer.hpp"
#include "debugcollector.hpp" #include "debugcollector.hpp"
#include <cstdint>
class IdGlobalPool { class IdGlobalPool {
public: public:
// Construct and destroy global pools. Note that after constructing // Construct and destroy global pools. Note that after constructing

View File

@@ -1,6 +1,10 @@
#include "wrap-string.hpp"
#include "wrap-map.hpp"
#include "wrap-deque.hpp"
#include "wrap-sstream.hpp"
#include "invocation.hpp" #include "invocation.hpp"
#include <sstream>
const std::string &InvocationData::get(const std::string &key) const { const std::string &InvocationData::get(const std::string &key) const {
static std::string blank_; static std::string blank_;

View File

@@ -1,9 +1,10 @@
#ifndef INVOCATION_HPP #ifndef INVOCATION_HPP
#define INVOCATION_HPP #define INVOCATION_HPP
#include <string> #include "wrap-string.hpp"
#include <map> #include "wrap-map.hpp"
#include <deque> #include "wrap-deque.hpp"
#include "streambuffer.hpp" #include "streambuffer.hpp"

View File

@@ -1,12 +1,14 @@
#include "lpxclient.hpp" #include "wrap-memory.hpp"
#include "wrap-string.hpp"
#include "wrap-vector.hpp"
#include "drivenengine.hpp" #include "drivenengine.hpp"
#include "lpxclient.hpp"
#include "world.hpp" #include "world.hpp"
#include "luaconsole.hpp" #include "luaconsole.hpp"
#include "invocation.hpp" #include "invocation.hpp"
#include "util.hpp" #include "util.hpp"
#include "printbuffer.hpp" #include "printbuffer.hpp"
#include <memory>
class LpxClient : public DrivenEngine { class LpxClient : public DrivenEngine {
public: public:

View File

@@ -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 "world.hpp"
#include "drivenengine.hpp" #include "drivenengine.hpp"
#include "luaconsole.hpp" #include "luaconsole.hpp"
#include "util.hpp" #include "util.hpp"
#include "printbuffer.hpp" #include "printbuffer.hpp"
#include <memory>
class Client { class Client {
public: public:

View File

@@ -1,7 +1,10 @@
#include "wrap-string.hpp"
#include "wrap-vector.hpp"
#include <string.h>
#include "luaconsole.hpp" #include "luaconsole.hpp"
#include "util.hpp" #include "util.hpp"
#include <cstring>
#include <iostream> #include <iostream>
LuaConsole::LuaConsole() { LuaConsole::LuaConsole() {

View File

@@ -42,7 +42,9 @@
#ifndef LUACONSOLE_HPP #ifndef LUACONSOLE_HPP
#define LUACONSOLE_HPP #define LUACONSOLE_HPP
#include <string> #include "wrap-string.hpp"
#include "wrap-vector.hpp"
#include "luastack.hpp" #include "luastack.hpp"
class LuaConsole { class LuaConsole {

View File

@@ -1,8 +1,12 @@
#include "wrap-sstream.hpp"
#include "wrap-string.hpp"
#include "luasnap.hpp" #include "luasnap.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "streambuffer.hpp"
#include <cassert> #include <cassert>
#include <sstream>
LuaSnap::LuaSnap() { LuaSnap::LuaSnap() {

View File

@@ -154,6 +154,9 @@
#ifndef LUASTACK_HPP #ifndef LUASTACK_HPP
#define LUASTACK_HPP #define LUASTACK_HPP
#include "wrap-string.hpp"
#include "wrap-vector.hpp"
extern "C" { extern "C" {
#include "lua.h" #include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
@@ -161,10 +164,6 @@ extern "C" {
#include "eris.h" #include "eris.h"
} }
#include <string>
#include <vector>
#include <string_view>
class LuaSlot { class LuaSlot {
protected: protected:
int index_; int index_;

View File

@@ -1,9 +1,11 @@
#include <cmath> #include "wrap-algorithm.hpp"
#include <algorithm>
#include "luastack.hpp" #include "luastack.hpp"
#include "util.hpp" #include "util.hpp"
#include "planemap.hpp" #include "planemap.hpp"
#include <cmath>
// Cell X, Y coordinates are packed such that they have 24 bits for X and Y. // Cell X, Y coordinates are packed such that they have 24 bits for X and Y.
// A cell is 10 Meters square. // A cell is 10 Meters square.
// Cell ID zero is used to represent an invalid position. // Cell ID zero is used to represent an invalid position.

View File

@@ -73,11 +73,14 @@
#ifndef PLANEMAP_HPP #ifndef PLANEMAP_HPP
#define PLANEMAP_HPP #define PLANEMAP_HPP
#include <cstdint> #include "wrap-vector.hpp"
#include <vector> #include "wrap-map.hpp"
#include <map> #include "wrap-string.hpp"
#include "util.hpp" #include "util.hpp"
#include <cstdint>
class PlaneMap; class PlaneMap;
class PlaneItem { class PlaneItem {

View File

@@ -1,7 +1,9 @@
#include "wrap-ostream.hpp"
#include "pprint.hpp" #include "pprint.hpp"
#include "util.hpp" #include "util.hpp"
#include "table.hpp" #include "table.hpp"
#include <ostream>
#include <iostream> #include <iostream>

View File

@@ -19,6 +19,8 @@
#ifndef PPRINT_HPP #ifndef PPRINT_HPP
#define PPRINT_HPP #define PPRINT_HPP
#include "wrap-ostream.hpp"
#include "luastack.hpp" #include "luastack.hpp"
// Atomic print to a stream. // Atomic print to a stream.

View File

@@ -1,6 +1,7 @@
#include "wrap-algorithm.hpp"
#include "wrap-sstream.hpp"
#include "printbuffer.hpp" #include "printbuffer.hpp"
#include <algorithm>
#include <sstream>
struct PrintBufferCore { struct PrintBufferCore {
// The most recent lines printed. // The most recent lines printed.

View File

@@ -77,14 +77,15 @@
#ifndef PRINTBUFFER_HPP #ifndef PRINTBUFFER_HPP
#define 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 "streambuffer.hpp"
#include "util.hpp" #include "util.hpp"
#include "invocation.hpp" #include "invocation.hpp"
#include "debugcollector.hpp" #include "debugcollector.hpp"
#include <deque>
#include <string>
#include <memory>
#include <ostream>
struct PrintBufferCore; struct PrintBufferCore;

View File

@@ -1,9 +1,10 @@
#include "wrap-sstream.hpp"
#include "wrap-ostream.hpp"
#include "sched.hpp" #include "sched.hpp"
#include "streambuffer.hpp" #include "streambuffer.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include <sstream>
#include <ostream>
bool SchedEntry::operator < (const SchedEntry &other) const { bool SchedEntry::operator < (const SchedEntry &other) const {
if (clock_ < other.clock_) return true; if (clock_ < other.clock_) return true;

View File

@@ -1,10 +1,12 @@
#ifndef SCHED_HPP #ifndef SCHED_HPP
#define SCHED_HPP #define SCHED_HPP
#include <cstdint> #include "wrap-set.hpp"
#include <set>
#include "streambuffer.hpp" #include "streambuffer.hpp"
#include <cstdint>
class SchedEntry { class SchedEntry {
private: private:
friend class Schedule; friend class Schedule;

View File

@@ -1,20 +1,21 @@
#include <string> #include "wrap-string.hpp"
#include <vector> #include "wrap-vector.hpp"
#include <map> #include "wrap-map.hpp"
#include <set> #include "wrap-set.hpp"
#include <algorithm> #include "wrap-algorithm.hpp"
#include <sstream> #include "wrap-sstream.hpp"
#include <fstream>
#include <iostream>
#include "util.hpp" #include "util.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "traceback.hpp" #include "traceback.hpp"
#include "table.hpp" #include "table.hpp"
#include "source.hpp" #include "source.hpp"
#include "luasnap.hpp" #include "luasnap.hpp"
#include <fstream>
#include <iostream>
LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") { LuaDefine(makeclass, "classname", "create a class if it doesn't already exist") {
LuaArg classname; LuaArg classname;
LuaRet classtab; LuaRet classtab;
@@ -375,7 +376,7 @@ static std::string source_load_lfunctions(lua_State *L) {
} }
// Now call the closures in the proper order. // Now call the closures in the proper order.
std::stringstream errss; std::ostringstream errss;
for (const auto &p : indices) { for (const auto &p : indices) {
LS.rawget(info, sourcedb, p.second); LS.rawget(info, sourcedb, p.second);
LS.rawget(closure, info, "loadresult"); LS.rawget(closure, info, "loadresult");

View File

@@ -120,6 +120,8 @@
#ifndef SOURCE_HPP #ifndef SOURCE_HPP
#define SOURCE_HPP #define SOURCE_HPP
#include "wrap-string.hpp"
#include "util.hpp" #include "util.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "streambuffer.hpp" #include "streambuffer.hpp"

View File

@@ -29,9 +29,8 @@
#ifndef SPOOKYV2_HPP #ifndef SPOOKYV2_HPP
#define SPOOKYV2_HPP #define SPOOKYV2_HPP
#include <stddef.h> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <utility>
class SpookyHash class SpookyHash
{ {

View File

@@ -1,5 +1,9 @@
#include "wrap-string.hpp"
#include "two-mallocs.hpp"
#include "streambuffer.hpp" #include "streambuffer.hpp"
#include "spookyv2.hpp" #include "spookyv2.hpp"
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>

View File

@@ -212,13 +212,15 @@
#ifndef STREAMBUFFER_HPP #ifndef STREAMBUFFER_HPP
#define STREAMBUFFER_HPP #define STREAMBUFFER_HPP
#include "wrap-string.hpp"
#include "wrap-sstream.hpp"
#include "wrap-utility.hpp"
#include "luastack.hpp" #include "luastack.hpp"
#include "util.hpp" #include "util.hpp"
#include <cstdint> #include <cstdint>
#include <string>
#include <sstream>
#include <cassert> #include <cassert>
#include <utility>
class StreamException class StreamException
{ {

View File

@@ -1,3 +1,6 @@
#include "wrap-string.hpp"
#include "table.hpp" #include "table.hpp"
#include "source.hpp" #include "source.hpp"

View File

@@ -1,10 +1,9 @@
#include <stdio.h> #include "wrap-vector.hpp"
#include <stdlib.h> #include "wrap-string.hpp"
#include <string.h> #include "wrap-memory.hpp"
#include <signal.h> #include "wrap-algorithm.hpp"
#include <vector>
#include <string>
#include "luastack.hpp" #include "luastack.hpp"
#include "util.hpp" #include "util.hpp"
#include "gui.hpp" #include "gui.hpp"
@@ -15,9 +14,10 @@
#include "luaconsole.hpp" #include "luaconsole.hpp"
#include "pprint.hpp" #include "pprint.hpp"
#include "printbuffer.hpp" #include "printbuffer.hpp"
#include <memory>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <csignal>
class TextGame : public DrivenEngine { class TextGame : public DrivenEngine {
private: private:

View File

@@ -1,10 +1,10 @@
#include <cstring>
#include "traceback.hpp" #include "traceback.hpp"
#include <cstring>
#define TRACEBACK_LEVELS1 12 #define TRACEBACK_LEVELS1 12
#define TRACEBACK_LEVELS2 10 #define TRACEBACK_LEVELS2 10
// Call this with the error message on top of the stack. // Call this with the error message on top of the stack.
// The error message is replaced with a traceback. // The error message is replaced with a traceback.
// //

View File

@@ -0,0 +1,78 @@
#ifndef TWO_MALLOCS_HPP
#define TWO_MALLOCS_HPP
#include <cstddef>
// 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 T>
class EngAllocator
{
public:
using value_type = T;
EngAllocator() noexcept {}
template <class U> EngAllocator(EngAllocator<U> const&) noexcept {}
value_type* allocate(std::size_t n)
{
return static_cast<value_type*>(dlmalloc(n*sizeof(value_type)));
}
void deallocate(value_type* p, std::size_t) noexcept
{
dlfree(p);
}
};
template <class T, class U>
bool operator==(EngAllocator<T> const&, EngAllocator<U> const&) noexcept
{
return true;
}
template <class T, class U>
bool operator!=(EngAllocator<T> const&, EngAllocator<U> const&) noexcept
{
return false;
}
// namespace eng {
// template<class T>
// using hash = std::hash<T>;
// template<class T>
// using less = std::less<T>;
// template<class T>
// using equal_to = std::equal_to<T>;
// template<class T>
// using char_traits = std::char_traits<T>;
// template<class A, class B>
// using pair = std::pair<A, B>;
// }
#endif // TWO_MALLOCS_HPP

View File

@@ -1,14 +1,16 @@
#include <string> #include "wrap-string.hpp"
#include <vector> #include "wrap-vector.hpp"
#include <fstream> #include "wrap-algorithm.hpp"
#include <cstdlib>
#include "util.hpp" #include "util.hpp"
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <cmath> #include <cmath>
#include <iomanip> #include <iomanip>
#include <cassert> #include <cassert>
#include <algorithm> #include <fstream>
#include <cstdlib>
#ifdef WIN32 #ifdef WIN32
#endif #endif

View File

@@ -1,16 +1,16 @@
#ifndef UTIL_HPP #ifndef UTIL_HPP
#define UTIL_HPP #define UTIL_HPP
#include <string> #include "wrap-string.hpp"
#include <string_view> #include "wrap-string-view.hpp"
#include <set> #include "wrap-set.hpp"
#include <map> #include "wrap-map.hpp"
#include <algorithm> #include "wrap-algorithm.hpp"
#include <sstream> #include "wrap-sstream.hpp"
#include <ostream> #include "wrap-ostream.hpp"
#include <memory> #include "wrap-memory.hpp"
#include <tuple> #include "wrap-utility.hpp"
#include <utility>
#include "luastack.hpp" #include "luastack.hpp"
#include "spookyv2.hpp" #include "spookyv2.hpp"

View File

@@ -2,6 +2,12 @@
#ifndef WORLD_HPP #ifndef WORLD_HPP
#define 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 "luastack.hpp"
#include "planemap.hpp" #include "planemap.hpp"
#include "idalloc.hpp" #include "idalloc.hpp"
@@ -14,10 +20,6 @@
#include "source.hpp" #include "source.hpp"
#include "gui.hpp" #include "gui.hpp"
#include "luasnap.hpp" #include "luasnap.hpp"
#include <set>
#include <utility>
#include <memory>
#include <unordered_map>
class World; class World;

22
luprex/core/wrap/mkstub.py Executable file
View File

@@ -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)

View File

@@ -0,0 +1,13 @@
#ifndef WRAP_ALGORITHM_HPP
#define WRAP_ALGORITHM_HPP
#include "two-mallocs.hpp"
#include <algorithm>
namespace eng {
} // namespace eng
namespace drv {
} // namespace drv
#endif // WRAP_ALGORITHM_HPP

View File

@@ -0,0 +1,17 @@
#ifndef WRAP_DEQUE_HPP
#define WRAP_DEQUE_HPP
#include "two-mallocs.hpp"
#include <deque>
namespace eng {
template<class T>
using deque = std::deque<T, EngAllocator<T>>;
} // namespace eng
namespace drv {
template<class T>
using deque = std::deque<T, std::allocator<T>>;
} // namespace drv
#endif // WRAP_DEQUE_HPP

View File

@@ -0,0 +1,25 @@
#ifndef WRAP_MAP_HPP
#define WRAP_MAP_HPP
#include "two-mallocs.hpp"
#include <map>
namespace eng {
template<class T>
using less = std::less<T>;
template<class A, class B>
using pair = std::pair<A, B>;
template<class K, class V, class C=std::less<K>>
using map = std::map<K, V, C, EngAllocator<std::pair<const K, V>>>;
} // namespace eng
namespace drv {
template<class T>
using less = std::less<T>;
template<class A, class B>
using pair = std::pair<A, B>;
template<class K, class V, class C=std::less<K>>
using map = std::map<K, V, C, std::allocator<std::pair<const K, V>>>;
} // namespace drv
#endif // WRAP_MAP_HPP

View File

@@ -0,0 +1,21 @@
#ifndef WRAP_MEMORY_HPP
#define WRAP_MEMORY_HPP
#include "two-mallocs.hpp"
#include <memory>
namespace eng {
template<class T, class D=std::default_delete<T>>
using unique_ptr = std::unique_ptr<T, D>;
template<class T>
using shared_ptr = std::shared_ptr<T>;
} // namespace eng
namespace drv {
template<class T, class D=std::default_delete<T>>
using unique_ptr = std::unique_ptr<T, D>;
template<class T>
using shared_ptr = std::shared_ptr<T>;
} // namespace drv
#endif // WRAP_MEMORY_HPP

View File

@@ -0,0 +1,15 @@
#ifndef WRAP_OSTREAM_HPP
#define WRAP_OSTREAM_HPP
#include "two-mallocs.hpp"
#include <ostream>
namespace eng {
using ostream = std::ostream;
} // namespace eng
namespace drv {
using ostream = std::ostream;
} // namespace drv
#endif // WRAP_OSTREAM_HPP

View File

@@ -0,0 +1,21 @@
#ifndef WRAP_SET_HPP
#define WRAP_SET_HPP
#include "two-mallocs.hpp"
#include <set>
namespace eng {
template<class T>
using less = std::less<T>;
template<class K, class C=std::less<K>>
using set = std::set<K, C, EngAllocator<K>>;
} // namespace eng
namespace drv {
template<class T>
using less = std::less<T>;
template<class K, class C=std::less<K>>
using set = std::set<K, C, std::allocator<K>>;
} // namespace drv
#endif // WRAP_SET_HPP

View File

@@ -0,0 +1,19 @@
#ifndef WRAP_SSTREAM_HPP
#define WRAP_SSTREAM_HPP
#include "two-mallocs.hpp"
#include <sstream>
namespace eng {
template<class C, class T=std::char_traits<C>>
using basic_ostringstream = std::basic_ostringstream<C, T, EngAllocator<C>>;
using ostringstream = std::basic_ostringstream<char>;
} // namespace eng
namespace drv {
template<class C, class T=std::char_traits<C>>
using basic_ostringstream = std::basic_ostringstream<C, T, std::allocator<C>>;
using ostringstream = std::basic_ostringstream<char>;
} // namespace drv
#endif // WRAP_SSTREAM_HPP

View File

@@ -0,0 +1,19 @@
#ifndef WRAP_STRING_VIEW_HPP
#define WRAP_STRING_VIEW_HPP
#include "two-mallocs.hpp"
#include <string_view>
namespace eng {
template<class C, class T=std::char_traits<C>>
using basic_string_view = std::basic_string_view<C, T>;
using string_view = basic_string_view<char>;
} // namespace eng
namespace drv {
template<class C, class T=std::char_traits<C>>
using basic_string_view = std::basic_string_view<C, T>;
using string_view = basic_string_view<char>;
} // namespace drv
#endif // WRAP_STRING_VIEW_HPP

View File

@@ -0,0 +1,19 @@
#ifndef WRAP_STRING_HPP
#define WRAP_STRING_HPP
#include "two-mallocs.hpp"
#include <string>
namespace eng {
template<class C, class T=std::char_traits<C>>
using basic_string = std::basic_string<C, T, EngAllocator<C>>;
using string = basic_string<char>;
} // namespace eng
namespace drv {
template<class C, class T=std::char_traits<C>>
using basic_string = std::basic_string<C, T, std::allocator<C>>;
using string = basic_string<char>;
} // namespace drv
#endif // WRAP_STRING_HPP

View File

@@ -0,0 +1,29 @@
#ifndef WRAP_UNORDERED_MAP_HPP
#define WRAP_UNORDERED_MAP_HPP
#include "two-mallocs.hpp"
#include <unordered_map>
namespace eng {
template<class T>
using hash = std::hash<T>;
template<class T>
using equal_to = std::equal_to<T>;
template<class A, class B>
using pair = std::pair<A, B>;
template<class K, class V, class H=std::hash<K>, class E=std::equal_to<K>>
using unordered_map = std::unordered_map<K, V, H, E, EngAllocator<std::pair<const K, V>>>;
} // namespace eng
namespace drv {
template<class T>
using hash = std::hash<T>;
template<class T>
using equal_to = std::equal_to<T>;
template<class A, class B>
using pair = std::pair<A, B>;
template<class K, class V, class H=std::hash<K>, class E=std::equal_to<K>>
using unordered_map = std::unordered_map<K, V, H, E, std::allocator<std::pair<const K, V>>>;
} // namespace drv
#endif // WRAP_UNORDERED_MAP_HPP

View File

@@ -0,0 +1,25 @@
#ifndef WRAP_UNORDERED_SET_HPP
#define WRAP_UNORDERED_SET_HPP
#include "two-mallocs.hpp"
#include <unordered_set>
namespace eng {
template<class T>
using hash = std::hash<T>;
template<class T>
using equal_to = std::equal_to<T>;
template<class K, class H=std::hash<K>, class E=std::equal_to<K>>
using unordered_set = std::unordered_set<K, H, E, EngAllocator<K>>;
} // namespace eng
namespace drv {
template<class T>
using hash = std::hash<T>;
template<class T>
using equal_to = std::equal_to<T>;
template<class K, class H=std::hash<K>, class E=std::equal_to<K>>
using unordered_set = std::unordered_set<K, H, E, std::allocator<K>>;
} // namespace drv
#endif // WRAP_UNORDERED_SET_HPP

View File

@@ -0,0 +1,17 @@
#ifndef WRAP_UTILITY_HPP
#define WRAP_UTILITY_HPP
#include "two-mallocs.hpp"
#include <utility>
namespace eng {
template<class A, class B>
using pair = std::pair<A, B>;
} // namespace eng
namespace drv {
template<class A, class B>
using pair = std::pair<A, B>;
} // namespace drv
#endif // WRAP_UTILITY_HPP

View File

@@ -0,0 +1,17 @@
#ifndef WRAP_VECTOR_HPP
#define WRAP_VECTOR_HPP
#include "two-mallocs.hpp"
#include <vector>
namespace eng {
template<class T>
using vector = std::vector<T, EngAllocator<T>>;
} // namespace eng
namespace drv {
template<class T>
using vector = std::vector<T, EngAllocator<T>>;
} // namespace drv
#endif // WRAP_VECTOR_HPP