14#ifndef BFX_DEFAULT_INPUT_MAX
18#define BFX_DEFAULT_INPUT_MAX 1024
21#ifndef BFX_DEFAULT_TAPE_SIZE
25#define BFX_DEFAULT_TAPE_SIZE 30000
28#ifndef BFX_INITIAL_LOOP_SIZE
32#define BFX_INITIAL_LOOP_SIZE 2048
35#ifndef BFX_PROCEDURE_SIZE
39#define BFX_PROCEDURE_SIZE 128
46#define BFX_VERSION "unknown"
49#ifndef BFX_DEFAULT_LANG
53#define BFX_DEFAULT_LANG BFX_LANG_BRAINFUCK
56#ifndef BFX_DEFAULT_EOF_BEHAVIOR
60#define BFX_DEFAULT_EOF_BEHAVIOR BFX_EOF_BEHAVIOR_ZERO
72#define BFX_FLAG_DEBUG 1
73#define BFX_FLAG_REPL 2
74#define BFX_FLAG_DISABLE_SPECIAL_INSTRUCTIONS 4
75#define BFX_FLAG_LANG_DATA_FLAGS 8
76#define BFX_FLAG_GRAPHICS 16
77#define BFX_FLAG_SEPARATE_INPUT_AND_SOURCE \
79#define BFX_FLAG_DEGREES 64
105#define BFX_ERROR(s) fprintf(stderr, "libbfx: Error: %s\n", s);
110#define BFX_IN_DEBUG_MODE(b) ((b).flags & BFX_FLAG_DEBUG)
115#define BFX_IN_REPL_MODE(b) ((b).flags & BFX_FLAG_REPL)
120#define BFX_SPECIAL_INSTRUCTIONS_ENABLED(b) (!((b).flags & BFX_FLAG_DISABLE_SPECIAL_INSTRUCTIONS))
void bfx_free(BFX *)
Frees the memory allocated for the BFX instance.
Definition: bfx.c:25
BFX_Language
Language options for the interpreter/compiler.
Definition: bfx.h:84
@ BFX_LANG_pbrain
pbrain language
Definition: bfx.h:88
@ BFX_LANG_grin
Grin language.
Definition: bfx.h:89
@ BFX_LANG_weave
Weave language.
Definition: bfx.h:90
@ BFX_LANG_brainfuck
brainfuck language
Definition: bfx.h:86
@ BFX_LANG_UNKNOWN
Unknown language.
Definition: bfx.h:85
@ BFX_LANG_brainfork
brainfork language
Definition: bfx.h:87
BFX_Error
Definition: bfx.h:93
@ BFX_SYNTAX_ERROR
Syntax error.
Definition: bfx.h:97
@ BFX_STACK_OVERFLOW_ERROR
Stack overflow error.
Definition: bfx.h:95
@ BFX_SUCCESS
No error.
Definition: bfx.h:94
@ BFX_OUT_OF_MEMORY_ERROR
Out of memory error.
Definition: bfx.h:98
@ BFX_STACK_UNDERFLOW_ERROR
Stack underflow error.
Definition: bfx.h:96
@ BFX_RUNTIME_ERROR
Runtime error.
Definition: bfx.h:99
BFX_EOFBehavior
Behaviors for the interpreter when an EOF is encountered in input.
Definition: bfx.h:66
@ BFX_EOF_BEHAVIOR_ZERO
Set the current cell to zero.
Definition: bfx.h:67
@ BFX_EOF_BEHAVIOR_DECREMENT
Decrement the current cell by 1.
Definition: bfx.h:68
@ BFX_EOF_BEHAVIOR_UNCHANGED
Leave the current cell unchanged.
Definition: bfx.h:69
BFX_Error bfx_run_file(const char *, BFX *)
Runs the program loaded from a file.
Definition: bfx.c:50
BFX_Error bfx_run_repl(BFX *)
Runs the BFX interpreter in REPL (Read-Eval-Print Loop) mode.
Definition: bfx.c:63
Structure to represent a loop in the brainfuck program. This structure holds the start and end indice...
Definition: bfx.h:140
BFX_FileIndex start
Start index of block.
Definition: bfx.h:141
BFX_FileIndex end
End index of block.
Definition: bfx.h:142
Structure to represent an index in a file (or user input).
Definition: bfx.h:126
int line
Line number in the file or user input.
Definition: bfx.h:128
int idx
Index within the file or user input.
Definition: bfx.h:127
int line_idx
Index within the line.
Definition: bfx.h:129
Structure to store generic data for a brainfuck-like esolang interpreter.
Definition: bfx.h:149
uint8_t * tape
Pointer to the tape array.
Definition: bfx.h:158
size_t loops_len
Length of the loop array.
Definition: bfx.h:163
size_t input_len
Length of the input buffer in the program string.
Definition: bfx.h:157
uint16_t flags
Flags to control compilation and execution behavior.
Definition: bfx.h:150
char * program
Pointer to the program string.
Definition: bfx.h:152
BFX_Language lang
Language identifier for the brainfuck-like esolang.
Definition: bfx.h:167
bool receiving
Indicates whether the interpreter is receiving input.
Definition: bfx.h:151
int eof_behavior
Behavior when encountering EOF.
Definition: bfx.h:166
BFX_Block * loops
Pointer to the loop block array.
Definition: bfx.h:162
int tp
Tape pointer.
Definition: bfx.h:161
size_t input_start
Start index of the input buffer in the program string.
Definition: bfx.h:155
void * lang_data
Pointer to language-specific data structure.
Definition: bfx.h:168
size_t program_size
Size of the program string.
Definition: bfx.h:154
size_t input_ptr
Current index of the input buffer in the program string.
Definition: bfx.h:156
size_t program_len
Length of the program string (not including the input buffer).
Definition: bfx.h:153
int ip
Instruction pointer.
Definition: bfx.h:160
size_t tape_size
Size of the tape array.
Definition: bfx.h:159
size_t loops_size
Size of the loop array.
Definition: bfx.h:164
size_t input_max
Maximum size of the input buffer.
Definition: bfx.h:165