openMSX
Interpreter.hh
Go to the documentation of this file.
1 #ifndef INTERPRETER_HH
2 #define INTERPRETER_HH
3 
4 #include "TclParser.hh"
5 #include "TclObject.hh"
6 #include <tcl.h>
7 #include <string_view>
8 #include <string>
9 
10 namespace openmsx {
11 
12 class Command;
13 class BaseSetting;
14 class InterpreterOutput;
15 
17 {
18 public:
19  Interpreter(const Interpreter&) = delete;
20  Interpreter& operator=(const Interpreter&) = delete;
21 
22  Interpreter();
23  ~Interpreter();
24 
25  void setOutput(InterpreterOutput* output_) { output = output_; }
26 
27  void init(const char* programName);
28  void registerCommand(const std::string& name, Command& command);
29  void unregisterCommand(Command& command);
30  [[nodiscard]] TclObject getCommandNames();
31  [[nodiscard]] bool isComplete(const std::string& command) const;
32  TclObject execute(const std::string& command);
33  TclObject executeFile(const std::string& filename);
34 
35  void setVariable(const TclObject& name, const TclObject& value);
36  void unsetVariable(const char* name);
37  void registerSetting(BaseSetting& variable);
38  void unregisterSetting(BaseSetting& variable);
39 
43  void createNamespace(const std::string& name);
44 
48  void deleteNamespace(const std::string& name);
49 
50  [[nodiscard]] TclParser parse(std::string_view command);
51 
52  void poll();
53 
54  void wrongNumArgs(unsigned argc, span<const TclObject> tokens, const char* message);
55 
56 private:
57  static int outputProc(ClientData clientData, const char* buf,
58  int toWrite, int* errorCodePtr);
59  static int commandProc(ClientData clientData, Tcl_Interp* interp,
60  int objc, Tcl_Obj* const objv[]);
61  static char* traceProc(ClientData clientData, Tcl_Interp* interp,
62  const char* part1, const char* part2, int flags);
63 
64  static Tcl_ChannelType channelType;
65  Tcl_Interp* interp;
66  InterpreterOutput* output;
67 
68  friend class TclObject;
69 };
70 
71 } // namespace openmsx
72 
73 #endif
openmsx::Interpreter::Interpreter
Interpreter()
Definition: Interpreter.cc:73
TclParser
Definition: TclParser.hh:12
openmsx::Interpreter::wrongNumArgs
void wrongNumArgs(unsigned argc, span< const TclObject > tokens, const char *message)
Definition: Interpreter.cc:452
openmsx::Interpreter::parse
TclParser parse(std::string_view command)
Definition: Interpreter.cc:447
openmsx::Interpreter::operator=
Interpreter & operator=(const Interpreter &)=delete
openmsx::Interpreter::createNamespace
void createNamespace(const std::string &name)
Create the global namespace with given name.
Definition: Interpreter.cc:431
TclObject.hh
openmsx::Interpreter::setVariable
void setVariable(const TclObject &name, const TclObject &value)
Definition: Interpreter.cc:239
openmsx::Interpreter::getCommandNames
TclObject getCommandNames()
Definition: Interpreter.cc:196
openmsx::Interpreter::execute
TclObject execute(const std::string &command)
Definition: Interpreter.cc:206
openmsx::Interpreter::unsetVariable
void unsetVariable(const char *name)
Definition: Interpreter.cc:248
openmsx::Interpreter::unregisterCommand
void unregisterCommand(Command &command)
Definition: Interpreter.cc:153
openmsx::Interpreter::isComplete
bool isComplete(const std::string &command) const
Definition: Interpreter.cc:201
openmsx::Interpreter::~Interpreter
~Interpreter()
Definition: Interpreter.cc:106
openmsx::Interpreter::unregisterSetting
void unregisterSetting(BaseSetting &variable)
Definition: Interpreter.cc:313
span
Definition: span.hh:126
openmsx::Interpreter::setOutput
void setOutput(InterpreterOutput *output_)
Definition: Interpreter.hh:25
openmsx::Interpreter::deleteNamespace
void deleteNamespace(const std::string &name)
Delete the global namespace with given name.
Definition: Interpreter.cc:436
openmsx::Interpreter::registerSetting
void registerSetting(BaseSetting &variable)
Definition: Interpreter.cc:261
openmsx::Interpreter::executeFile
TclObject executeFile(const std::string &filename)
Definition: Interpreter.cc:215
openmsx::Interpreter::poll
void poll()
Definition: Interpreter.cc:441
openmsx::filename
constexpr const char *const filename
Definition: FirmwareSwitch.cc:10
openmsx::BaseSetting
Definition: Setting.hh:19
openmsx::Interpreter::init
void init(const char *programName)
Definition: Interpreter.cc:68
TclParser.hh
openmsx::Interpreter::Interpreter
Interpreter(const Interpreter &)=delete
openmsx::InterpreterOutput
Definition: InterpreterOutput.hh:9
openmsx::Command
Definition: Command.hh:41
openmsx::Interpreter::registerCommand
void registerCommand(const std::string &name, Command &command)
Definition: Interpreter.cc:145
openmsx::TclObject
Definition: TclObject.hh:22
openmsx::Interpreter
Definition: Interpreter.hh:17
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5