Top |
CattleConfiguration * | configuration | Read / Write |
CattleProgram * | program | Read / Write |
CattleTape * | tape | Read / Write |
An instance of CattleInterpreter represents a Brainfuck interpreter, that is, an object which is capable of executing a CattleProgram.
CattleInterpreter handles all the aspects of execution, including
input and output. It also hides all the details to the user, who
only needs to initialize the interpreter and call
cattle_interpreter_run()
to execute a Brainfuck program.
The behaviour of an interpreter can be modified by providing a suitable CattleConfiguration object.
Once initialized, a CattleInterpreter can run the assigned program as many times as needed; the memory tape, however, is not automatically cleared between executions.
CattleInterpreter *
cattle_interpreter_new (void
);
Create and initialize a new interpreter.
gboolean cattle_interpreter_run (CattleInterpreter *interpreter
,GError **error
);
Make the interpreter run the loaded program.
void cattle_interpreter_feed (CattleInterpreter *interpreter
,CattleBuffer *input
);
Feed interpreter
with more input.
This method is meant to be used inside an input handler assigned to
interpreter
; calling it in any other context is pointless, since the
input is reset each time cattle_interpreter_run()
is called.
void cattle_interpreter_set_configuration (CattleInterpreter *interpreter
,CattleConfiguration *configuration
);
Set the configuration for interpreter
.
The same configuration can be used for several interpreters, but modifying it after it has been assigned to an interpreter may result in undefined behaviour, and as such is discouraged.
CattleConfiguration *
cattle_interpreter_get_configuration (CattleInterpreter *interpreter
);
Get the configuration for interpreter
.
See cattle_interpreter_set_configuration()
.
void cattle_interpreter_set_program (CattleInterpreter *interpreter
,CattleProgram *program
);
Set the program to be executed by interpreter
.
A single program can be shared between multiple interpreters, as long as care is taken not to modify it after it has been assigned to any of them.
CattleProgram *
cattle_interpreter_get_program (CattleInterpreter *interpreter
);
Get the program for interpreter
.
See cattle_interpreter_set_program()
.
void cattle_interpreter_set_tape (CattleInterpreter *interpreter
,CattleTape *tape
);
Set the memory tape used by interpreter
.
CattleTape *
cattle_interpreter_get_tape (CattleInterpreter *interpreter
);
Get the memory tape used by interpreter
.
See cattle_interpreter_set_tape()
.
gboolean (*CattleInputHandler) (CattleInterpreter *interpreter
,gpointer data
,GError **error
);
Handler for an input operation.
void cattle_interpreter_set_input_handler (CattleInterpreter *interpreter
,CattleInputHandler handler
,gpointer user_data
);
Set the input handler for interpreter
.
The handler will be invoked every time interpreter
needs to perform
an input action; if handler
is NULL
, the default input handler will
be used.
interpreter |
||
handler |
input handler, or |
[scope notified][allow-none] |
user_data |
user data for |
[allow-none] |
gboolean (*CattleOutputHandler) (CattleInterpreter *interpreter
,gint8 output
,gpointer data
,GError **error
);
Handler for an output operation.
void cattle_interpreter_set_output_handler (CattleInterpreter *interpreter
,CattleOutputHandler handler
,gpointer user_data
);
Set the output handler for interpreter
.
The handler will be invoked every time interpreter
needs to perform
an output action; if handler
is NULL
, the default output handler will
be used.
interpreter |
||
handler |
output handler, or |
[scope notified][allow-none] |
user_data |
user data for |
[allow-none] |
gboolean (*CattleDebugHandler) (CattleInterpreter *interpreter
,gpointer data
,GError **error
);
Handler for a debug operation.
void cattle_interpreter_set_debug_handler (CattleInterpreter *interpreter
,CattleInputHandler handler
,gpointer user_data
);
Set the debug handler for interpreter
.
The handler will be invoked every time interpreter
needs to perform
a debug action; if handler
is NULL
, the default debug handler will
be used.
interpreter |
||
handler |
debug handler, or |
[scope notified][allow-none] |
user_data |
user data for |
[allow-none] |
“configuration”
property“configuration” CattleConfiguration *
Configuration used by the interpreter.
Changes to this property are not notified.
Owner: CattleInterpreter
Flags: Read / Write
“program”
property“program” CattleProgram *
Program executed by the interpreter.
Changes to this property are not notified.
Owner: CattleInterpreter
Flags: Read / Write
“tape”
property“tape” CattleTape *
Tape used to store the data needed by the program.
Changes to this property are not notified.
Owner: CattleInterpreter
Flags: Read / Write