| e8555c89 Andy McCall |
1 |
#ifndef INTERPRETER_HH |
| 2 |
#define INTERPRETER_HH |
| 3 |
|
| 4 |
#include "TclObject.hh" |
| 5 |
#include "TclParser.hh" |
| 6 |
|
| 7 |
#include "zstring_view.hh" |
| 8 |
|
| 9 |
#include "tcl.hh" |
| 10 |
|
| 11 |
#include <span> |
| 12 |
#include <string> |
| 13 |
#include <string_view> |
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
class Command; |
| 18 |
class BaseSetting; |
| 19 |
class InterpreterOutput; |
| 20 |
|
| 21 |
class Interpreter |
| 22 |
{ |
| 23 |
public: |
| 24 |
Interpreter(); |
| 25 |
Interpreter(const Interpreter&) = delete; |
| 26 |
Interpreter(Interpreter&&) = delete; |
| 27 |
Interpreter& operator=(const Interpreter&) = delete; |
| 28 |
Interpreter& operator=(Interpreter&&) = delete; |
| 29 |
~Interpreter(); |
| 30 |
|
| 31 |
void setOutput(InterpreterOutput* output_) { output = output_; } |
| 32 |
|
| 33 |
void init(const char* programName) const; |
| 34 |
[[nodiscard]] bool hasCommand(zstring_view name) const; |
| 35 |
void registerCommand(zstring_view name, Command& command); |
| 36 |
void unregisterCommand(Command& command); |
| 37 |
[[nodiscard]] TclObject getCommandNames(); |
| 38 |
[[nodiscard]] bool isComplete(zstring_view command) const; |
| 39 |
TclObject execute(zstring_view command); |
| 40 |
TclObject executeFile(zstring_view filename); |
| 41 |
|
| 42 |
void setVariable(const TclObject& name, const TclObject& value); |
| 43 |
void setVariable(const TclObject& arrayName, const TclObject& arrayIndex, const TclObject& value); |
| 44 |
void unsetVariable(const char* name); |
| 45 |
void registerSetting(BaseSetting& variable); |
| 46 |
void unregisterSetting(BaseSetting& variable); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
void createNamespace(const std::string& name); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
void deleteNamespace(const std::string& name); |
| 57 |
|
| 58 |
[[nodiscard]] TclParser parse(std::string_view command); |
| 59 |
[[nodiscard]] bool validExpression(std::string_view expression); |
| 60 |
[[nodiscard]] std::string parseCommandError(std::string_view command); |
| 61 |
[[nodiscard]] std::string parseExpressionError(std::string_view expression); |
| 62 |
|
| 63 |
void poll() const; |
| 64 |
|
| 65 |
[[noreturn]] void wrongNumArgs(unsigned argc, std::span<const TclObject> tokens, const char* message); |
| 66 |
|
| 67 |
private: |
| 68 |
static int outputProc(ClientData clientData, const char* buf, |
| 69 |
int toWrite, int* errorCodePtr); |
| 70 |
static int commandProc(ClientData clientData, Tcl_Interp* interp, |
| 71 |
int objc, Tcl_Obj* const* objv); |
| 72 |
static char* traceProc(ClientData clientData, Tcl_Interp* interp, |
| 73 |
const char* part1, const char* part2, int flags); |
| 74 |
|
| 75 |
static Tcl_ChannelType channelType; |
| 76 |
Tcl_Interp* interp; |
| 77 |
InterpreterOutput* output; |
| 78 |
|
| 79 |
friend class TclObject; |
| 80 |
}; |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
#endif |