More work on moving engine into dlmalloc heap

This commit is contained in:
2022-02-25 19:57:23 -05:00
parent 08f6aa2092
commit ff932dba10
52 changed files with 351 additions and 484 deletions

View File

@@ -92,16 +92,18 @@
#ifndef DRIVENENGINE_HPP
#define DRIVENENGINE_HPP
#include "wrap-memory.hpp"
#include "wrap-string.hpp"
#include "wrap-vector.hpp"
#include "wrap-ostream.hpp"
#include <ostream>
#include <memory>
#include <string_view>
#include "util.hpp"
#include "streambuffer.hpp"
class DrivenEngine;
using UniqueDrivenEngine = eng::unique_ptr<DrivenEngine>;
using UniqueDrivenEngine = std::unique_ptr<DrivenEngine>;
using DrivenEngineMaker = UniqueDrivenEngine (*)();
class Channel {
@@ -162,13 +164,13 @@ private:
int chid_;
// These are the in/out buffers presented to the user.
eng::shared_ptr<StreamBuffer> sb_in_;
eng::shared_ptr<StreamBuffer> sb_out_;
std::shared_ptr<StreamBuffer> sb_in_;
std::shared_ptr<StreamBuffer> sb_out_;
// If this is stdio, we inject tty echoes into the output stream.
// This buffer holds the users output interleaved with the tty echoes.
// In any other channel, this is just another pointer to sb_out.
eng::shared_ptr<StreamBuffer> sb_drvout_;
std::shared_ptr<StreamBuffer> sb_drvout_;
int port_;
bool closed_;
@@ -186,10 +188,20 @@ private:
friend class DrivenEngine;
};
using SharedChannel = eng::shared_ptr<Channel>;
using SharedChannel = std::shared_ptr<Channel>;
class DrivenEngine {
public:
//////////////////////////////////////////////////////////////
//
// Build the named engine
//
//////////////////////////////////////////////////////////////
static UniqueDrivenEngine make(const char *name);
static void print_usage(std::ostream &strm, const char *progname);
//////////////////////////////////////////////////////////////
//
// The following methods are the 'engine' side of the pipe.
@@ -254,7 +266,7 @@ public:
// Obtain the output buffer of the stdio channel as an ostream.
//
eng::ostream &stdostream() { return get_stdio_channel()->out()->ostream(); }
std::ostream &stdostream() { return get_stdio_channel()->out()->ostream(); }
// Fetches the lua source, and takes ownership of it. The DrivenEngine
// no longer contains the source after calling this.
@@ -408,19 +420,6 @@ public:
static void set(DrivenEngine *de);
static DrivenEngine *get();
public:
//////////////////////////////////////////////////////////////
//
// The Registry of DrivenEngineMakers.
//
//////////////////////////////////////////////////////////////
static void register_maker(const char *kind, DrivenEngineMaker maker);
static void print_usage(eng::ostream &strm, const char *progname);
static UniqueDrivenEngine make(const char *kind);
private:
// Find a currently-unused channel ID. Channel IDs
// are small integers that are reused.
@@ -443,4 +442,19 @@ private:
friend class Channel;
};
struct DrivenEngineReg {
const char *name;
DrivenEngineMaker maker;
DrivenEngineReg *next;
static DrivenEngineReg *All;
DrivenEngineReg(const char *name, DrivenEngineMaker f);
};
#define DrivenEngineDefine(name, cname) \
UniqueDrivenEngine dengmake_##cname() { \
return UniqueDrivenEngine(new cname); \
} \
DrivenEngineReg dengreg_##cname(name, dengmake_##cname);
#endif // DRIVENENGINE_HPP