CattleProgram

CattleProgram — Brainfuck program (and possibly its input)

Synopsis

#include <cattle/cattle.h>

struct              CattleProgram;
CattleProgram *      cattle_program_new                 (void);
gboolean            cattle_program_load                 (CattleProgram *program,
                                                         const gchar *string,
                                                         GError **error);
void                cattle_program_set_instructions     (CattleProgram *program,
                                                         CattleInstruction *instructions);
CattleInstruction *  cattle_program_get_instructions    (CattleProgram *program);
void                cattle_program_set_input            (CattleProgram *program,
                                                         const gchar *input);
gchar *              cattle_program_get_input           (CattleProgram *program);

Object Hierarchy

  GObject
   +----CattleProgram

Properties

  "input"                    gchar*                : Read / Write
  "instructions"             CattleInstruction*    : Read / Write

Description

A CattleProgram represents a complete Brainfuck program, that is, the instructions to be executed and possibly its input.

The input for a program can optionally be specified in the source file, and it's separated from the program code by a bang (!) symbol. For example, given the following input:

1
,+.!sometext

the program's code is ",+." while the program's input is "sometext".

Any Brainfuck instruction after the bang symbol is considered part of the input, and as such is not executed. Subsequent bang symbols are also considered part of the input.

Details

struct CattleProgram

struct CattleProgram;

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


cattle_program_new ()

CattleProgram *      cattle_program_new                 (void);

Create a new CattleProgram.

A single instance of a program can be shared between multiple interpreters, as long as the object is not modified after it has been initialized.

Returns :

a new CattleProgram. [transfer full]

cattle_program_load ()

gboolean            cattle_program_load                 (CattleProgram *program,
                                                         const gchar *string,
                                                         GError **error);

Load program from string.

The string can optionally contain also the input for the program: in that case, the input must be separated from the code by a bang (!) character.

In case of failure, error is filled with detailed information. The error domain is CATTLE_ERROR, and the error code is from the CattleError enumeration.

program :

a CattleProgram

string :

the source code of the program

error :

return location for a GError. [allow-none]

Returns :

TRUE on success, FALSE otherwise

cattle_program_set_instructions ()

void                cattle_program_set_instructions     (CattleProgram *program,
                                                         CattleInstruction *instructions);

Set the instructions for program.

You shouldn't usually need to use this: see cattle_program_load() for the standard way to load a program.

program :

a CattleProgram

instructions :

instructions for program

cattle_program_get_instructions ()

CattleInstruction *  cattle_program_get_instructions    (CattleProgram *program);

Get the instructions for program. See cattle_program_load() and cattle_program_set_instructions().

program :

a CattleProgram

Returns :

the first instruction in program. [transfer full]

cattle_program_set_input ()

void                cattle_program_set_input            (CattleProgram *program,
                                                         const gchar *input);

Set the input for program.

If input is NULL, the input will be retrieved at runtime.

program :

a CattleProgram

input :

input for program, or NULL. [allow-none]

cattle_program_get_input ()

gchar *              cattle_program_get_input           (CattleProgram *program);

Get the input for program. See cattle_program_set_input().

program :

a CattleProgram

Returns :

input for program, or NULL. [transfer full]

Property Details

The "input" property

  "input"                    gchar*                : Read / Write

Input for the program, or NULL if no input was available at the time of loading.

Changes to this property are not notified.

Default value: NULL


The "instructions" property

  "instructions"             CattleInstruction*    : Read / Write

Instructions for the program.

Changes to this property are not notified.