CattleTape

CattleTape — Infinite-length memory tape

Synopsis

#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);

Object Hierarchy

  GObject
   +----CattleTape

Properties

  "current-value"            gchar                 : Read / Write

Description

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().

Details

struct CattleTape

struct CattleTape;

Opaque data structure representing a memory tape. It should never be accessed directly; use the methods below instead.


cattle_tape_new ()

CattleTape *        cattle_tape_new                     (void);

Create and initialize a new memory tape.

Returns :

a new CattleTape. [transfer full]

cattle_tape_set_current_value ()

void                cattle_tape_set_current_value       (CattleTape *tape,
                                                         gchar value);

Set the value of the current cell.

Accepted values are ASCII values or EOF.

tape :

a CattleTape

value :

the current cell's new value

cattle_tape_get_current_value ()

gchar               cattle_tape_get_current_value       (CattleTape *tape);

Get the value of the current cell. See cattle_tape_set_current_value().

tape :

a CattleTape

Returns :

the value of the current cell

cattle_tape_increase_current_value ()

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.

tape :

a CattleTape

cattle_tape_increase_current_value_by ()

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.

tape :

a CattleTape

value :

increase amount

cattle_tape_decrease_current_value ()

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.

tape :

a CattleTape

cattle_tape_decrease_current_value_by ()

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.

tape :

a CattleTape

value :

decrease amount

cattle_tape_move_left ()

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.

tape :

a CattleTape

cattle_tape_move_left_by ()

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.

tape :

a CattleTape

steps :

number of steps

cattle_tape_move_right ()

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.

tape :

a CattleTape

cattle_tape_move_right_by ()

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.

tape :

a CattleTape

steps :

number of steps

cattle_tape_is_at_beginning ()

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.

tape :

a CattleTape

Returns :

TRUE if the current cell is the first one, FALSE otherwise

cattle_tape_is_at_end ()

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.

tape :

a CattleTape

Returns :

TRUE if the current cell is the last one, FALSE otherwise

cattle_tape_push_bookmark ()

void                cattle_tape_push_bookmark           (CattleTape *tape);

Create a bookmark to the current tape position and save it on the bookmark stack.

tape :

a CattleTape

cattle_tape_pop_bookmark ()

gboolean            cattle_tape_pop_bookmark            (CattleTape *tape);

Restore the previously-saved tape position. See cattle_tape_push_bookmark().

tape :

a CattleTape

Returns :

FALSE if the bookmarks stack is empty, TRUE otherwise

Property Details

The "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