![]() |
![]() |
![]() |
Cattle Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties |
#include <cattle/cattle.h> struct CattleTape; CattleTape * cattle_tape_new (void
); void cattle_tape_set_current_value (CattleTape *tape
,gchar value
); gchar cattle_tape_get_current_value (CattleTape *tape
); void cattle_tape_increase_current_value (CattleTape *tape
); void cattle_tape_increase_current_value_by (CattleTape *tape
,gint value
); void cattle_tape_decrease_current_value (CattleTape *tape
); void cattle_tape_decrease_current_value_by (CattleTape *tape
,gint value
); void cattle_tape_move_left (CattleTape *tape
); void cattle_tape_move_left_by (CattleTape *tape
,gint steps
); void cattle_tape_move_right (CattleTape *tape
); void cattle_tape_move_right_by (CattleTape *tape
,gint steps
); gboolean cattle_tape_is_at_beginning (CattleTape *tape
); gboolean cattle_tape_is_at_end (CattleTape *tape
); void cattle_tape_push_bookmark (CattleTape *tape
); gboolean cattle_tape_pop_bookmark (CattleTape *tape
);
A CattleTape represents an infinte-length memory tape, which is used by a CattleInterpreter to store its data. The tape contains a virtually infinte number of memory cells, each one able to store a single ASCII character.
A tape supports three kinds of operations: reading the value of the current cell, updating the value of the current cell (either by increasing/decreasing it or by setting it to a certain value), and moving the current cell pointer (either to the left or to the right).
The tape grows automatically as more cells are needed, the only limit
being the amount of available memory. It is possible to check if the
current cell is at the beginning or at the end of the tape using
cattle_tape_is_at_beginning()
and cattle_tape_is_at_end()
.
struct CattleTape;
Opaque data structure representing a memory tape. It should never be accessed directly; use the methods below instead.
CattleTape * cattle_tape_new (void
);
Create and initialize a new memory tape.
Returns : |
a new CattleTape. [transfer full] |
void cattle_tape_set_current_value (CattleTape *tape
,gchar value
);
Set the value of the current cell.
Accepted values are ASCII values or EOF.
|
a CattleTape |
|
the current cell's new value |
gchar cattle_tape_get_current_value (CattleTape *tape
);
Get the value of the current cell. See
cattle_tape_set_current_value()
.
|
a CattleTape |
Returns : |
the value of the current cell |
void cattle_tape_increase_current_value (CattleTape *tape
);
Increase the value in the current cell by one.
If the value in the current cell has ASCII code 127, the new value will have ASCII code 0.
|
a CattleTape |
void cattle_tape_increase_current_value_by (CattleTape *tape
,gint value
);
Increase the value in the current cell by value
.
The value is wrapped if needed to keep it in the ASCII code.
Increasing the value this way is much faster than calling
cattle_tape_increase_current_value()
multiple times.
|
a CattleTape |
|
increase amount |
void cattle_tape_decrease_current_value (CattleTape *tape
);
Decrease the value in the current cell by one.
If the value in the current cell has ASCII value 0, the new value will have ASCII value 127.
|
a CattleTape |
void cattle_tape_decrease_current_value_by (CattleTape *tape
,gint value
);
Decrease the value in the current cell by value
.
The value is wrapped if needed to keep it in the ASCII code.
Decreasing the value this way is much faster than calling
cattle_tape_decrease_current_value()
multiple times.
|
a CattleTape |
|
decrease amount |
void cattle_tape_move_left (CattleTape *tape
);
Move tape
one cell to the left.
If there are no memory cells on the left of the current one, one will be created on the fly.
|
a CattleTape |
void cattle_tape_move_left_by (CattleTape *tape
,gint steps
);
Move tape
steps
cells to the left.
Moving this way is much faster than calling
cattle_tape_move_left()
multiple times.
|
a CattleTape |
|
number of steps |
void cattle_tape_move_right (CattleTape *tape
);
Move tape
one cell to the right.
If there are no memory cells on the right of the current one, one will be created on the fly.
|
a CattleTape |
void cattle_tape_move_right_by (CattleTape *tape
,gint steps
);
Move tape
steps
cells to the right.
Moving this way is much faster than calling
cattle_tape_move_right()
multiple times.
|
a CattleTape |
|
number of steps |
gboolean cattle_tape_is_at_beginning (CattleTape *tape
);
Check if the current cell is the first one of tape
.
Since the tape grows automatically as more cells are needed, it is possible to move left from the first cell.
|
a CattleTape |
Returns : |
TRUE if the current cell is the first one, FALSE otherwise |
gboolean cattle_tape_is_at_end (CattleTape *tape
);
Check if the current cell is the last one of tape
.
Since the tape grows automatically as more cells are needed, it is possible to move right from the last cell.
|
a CattleTape |
Returns : |
TRUE if the current cell is the last one, FALSE otherwise |
void cattle_tape_push_bookmark (CattleTape *tape
);
Create a bookmark to the current tape position and save it on the bookmark stack.
|
a CattleTape |
gboolean cattle_tape_pop_bookmark (CattleTape *tape
);
Restore the previously-saved tape position.
See cattle_tape_push_bookmark()
.
|
a CattleTape |
Returns : |
FALSE if the bookmarks stack is empty, TRUE otherwise |
"current-value"
property"current-value" gchar : Read / Write
Value of the current cell.
Changes to this property are not notified.
Allowed values: >= -1
Default value: 0