CattleProgram

CattleProgram — Brainfuck program (and possibly its input)

Functions

Properties

CattleBuffer * input Read / Write
CattleInstruction * instructions Read / Write

Types and Values

struct CattleProgram

Object Hierarchy

    GObject
    ╰── CattleProgram

Includes

#include <cattle/cattle.h>

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.

Functions

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,
                     CattleBuffer *buffer,
                     GError **error);

Load program from buffer .

The buffer 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.

Parameters

program

a CattleProgram

 

buffer

a CattleBuffer containing the code.

[transfer full]

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.

Parameters

program

a CattleProgram

 

instructions

instructions for program .

[transfer full]

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

Parameters

program

a CattleProgram

 

Returns

the first instruction in program .

[transfer full]


cattle_program_set_input ()

void
cattle_program_set_input (CattleProgram *program,
                          CattleBuffer *input);

Set the input for program .

If the size of input is zero, the program's input will be retrieved at runtime.

Parameters

program

a CattleProgram

 

input

input for program .

[transfer full]

cattle_program_get_input ()

CattleBuffer *
cattle_program_get_input (CattleProgram *program);

Get the input for program . See cattle_program_set_input().

Parameters

program

a CattleProgram

 

Returns

input for program .

[transfer full]

Types and Values

struct CattleProgram

struct CattleProgram;

Opaque data structure representing a program. It should never be accessed directly.

Property Details

The “input” property

  “input”                    CattleBuffer *

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

Changes to this property are not notified.

Owner: CattleProgram

Flags: Read / Write


The “instructions” property

  “instructions”             CattleInstruction *

Instructions for the program.

Changes to this property are not notified.

Owner: CattleProgram

Flags: Read / Write