![]() |
![]() |
![]() |
Cattle Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties |
#include <cattle/cattle.h> struct CattleInterpreter; CattleInterpreter * cattle_interpreter_new (void
); gboolean cattle_interpreter_run (CattleInterpreter *interpreter
,GError **error
); void cattle_interpreter_feed (CattleInterpreter *interpreter
,const gchar *input
); void cattle_interpreter_set_configuration (CattleInterpreter *interpreter
,CattleConfiguration *configuration
); CattleConfiguration * cattle_interpreter_get_configuration (CattleInterpreter *interpreter
); void cattle_interpreter_set_program (CattleInterpreter *interpreter
,CattleProgram *program
); CattleProgram * cattle_interpreter_get_program (CattleInterpreter *interpreter
); void cattle_interpreter_set_tape (CattleInterpreter *interpreter
,CattleTape *tape
); CattleTape * cattle_interpreter_get_tape (CattleInterpreter *interpreter
); gboolean (*CattleInputHandler) (CattleInterpreter *interpreter
,gpointer data
,GError **error
); void cattle_interpreter_set_input_handler (CattleInterpreter *interpreter
,CattleInputHandler handler
,gpointer user_data
); gboolean (*CattleOutputHandler) (CattleInterpreter *interpreter
,gchar output
,gpointer data
,GError **error
); void cattle_interpreter_set_output_handler (CattleInterpreter *interpreter
,CattleOutputHandler handler
,gpointer user_data
); gboolean (*CattleDebugHandler) (CattleInterpreter *interpreter
,gpointer data
,GError **error
); void cattle_interpreter_set_debug_handler (CattleInterpreter *interpreter
,CattleInputHandler handler
,gpointer user_data
);
"configuration" CattleConfiguration* : Read / Write "program" CattleProgram* : Read / Write "tape" CattleTape* : 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.
struct CattleInterpreter;
Opaque data structure representing an interpreter. It should never be accessed directly; use the methods below instead.
CattleInterpreter * cattle_interpreter_new (void
);
Create and initialize a new interpreter.
Returns : |
a new CattleInterpreter. [transfer full] |
gboolean cattle_interpreter_run (CattleInterpreter *interpreter
,GError **error
);
Make the interpreter run the loaded program.
|
a CattleInterpreter |
|
return location for a GError. [allow-none] |
Returns : |
TRUE on success, FALSE otherwise |
void cattle_interpreter_feed (CattleInterpreter *interpreter
,const gchar *input
);
Feed interpreter
with more input.
This method is meant to be used inside an input handler assigned to
interpreter
; way is pointless, since the input is reset when
cattle_interpreter_run()
is called.
|
a CattleInterpreter |
|
more input to be used by interpreter , or NULL . [allow-none]
|
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.
|
a CattleInterpreter |
|
configuration for interpreter
|
CattleConfiguration * cattle_interpreter_get_configuration
(CattleInterpreter *interpreter
);
Get the configuration for interpreter
.
See cattle_interpreter_set_configuration()
.
|
a CattleInterpreter |
Returns : |
configuration for interpreter . [transfer full]
|
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.
|
a CattleInterpreter |
|
a CattleProgram |
CattleProgram * cattle_interpreter_get_program (CattleInterpreter *interpreter
);
Get the program for interpreter
.
See cattle_interpreter_set_program()
.
|
a CattleInterpreter |
Returns : |
the program for interpreter . [transfer full]
|
void cattle_interpreter_set_tape (CattleInterpreter *interpreter
,CattleTape *tape
);
Set the memory tape used by interpreter
.
|
a CattleInterpreter |
|
a CattleTape |
CattleTape * cattle_interpreter_get_tape (CattleInterpreter *interpreter
);
Get the memory tape used by interpreter
.
See cattle_interpreter_set_tape()
.
|
a CattleInterpreter |
Returns : |
the memory tape for interpreter . [transfer full]
|
gboolean (*CattleInputHandler) (CattleInterpreter *interpreter
,gpointer data
,GError **error
);
Handler for an input operation.
|
a CattleInterpreter |
|
user data passed to the handler |
|
return location for a GError |
Returns : |
TRUE on success, FALSE otherwise |
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.
|
a CattleInterpreter |
|
input handler, or NULL . [scope notified][allow-none]
|
|
user data for handler . [allow-none]
|
gboolean (*CattleOutputHandler) (CattleInterpreter *interpreter
,gchar output
,gpointer data
,GError **error
);
Handler for an output operation.
|
a CattleInterpreter |
|
a gchar to output |
|
user data passed to the handler |
|
return location for a GError |
Returns : |
TRUE on success, FALSE otherwise |
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.
|
a CattleInterpreter |
|
output handler, or NULL . [scope notified][allow-none]
|
|
user data for handler . [allow-none]
|
gboolean (*CattleDebugHandler) (CattleInterpreter *interpreter
,gpointer data
,GError **error
);
Handler for a debug operation.
|
a CattleInterpreter |
|
user data passed to the handler |
|
return location for a GError |
Returns : |
TRUE on success, FALSE otherwise |
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.
|
a CattleInterpreter |
|
debug handler, or NULL . [scope notified][allow-none]
|
|
user data for handler . [allow-none]
|
"configuration"
property"configuration" CattleConfiguration* : Read / Write
Configuration used by the interpreter.
Changes to this property are not notified.
"program"
property"program" CattleProgram* : Read / Write
Program executed by the interpreter.
Changes to this property are not notified.
"tape"
property"tape" CattleTape* : Read / Write
Tape used to store the data needed by the program.
Changes to this property are not notified.