|
bfx
An interpreter, compiler, and REPL for brainfuck-like languages
|
#include "grin.h"#include "bfx.h"#include "brainfuck.h"#include "util.h"#include <ctype.h>#include <math.h>Macros | |
| #define | BFX_GRIN_DATA ((BFX_GrinData*) bfx->lang_data) |
| #define | BFX_CONVERT(a) ((BFX_GRIN_DATA->unit == BFX_GRIN_DEG) ? (a * M_PI / 180.0) : a) |
Functions | |
| BFX_Error | bfx_grin_init (BFX *bfx) |
| Initialize the Grin interpreter. | |
| BFX_Error | bfx_grin_run (BFX *bfx) |
| Run the Grin interpreter. | |
| BFX_Error | bfx_op_grin_inc_t (BFX *bfx, BFX_FileIndex *index) |
| Increment value at tape pointer (Grin). | |
| BFX_Error | bfx_op_grin_dec_t (BFX *bfx, BFX_FileIndex *index) |
| Decrement value at tape pointer (Grin). | |
| BFX_Error | bfx_op_grin_loop_start (BFX *bfx, BFX_FileIndex *index) |
| Start of loop (Grin). | |
| BFX_Error | bfx_op_grin_loop_end (BFX *bfx, BFX_FileIndex *index) |
| End of loop (Grin). | |
| BFX_Error | bfx_op_grin_putchar_ascii (BFX *bfx, BFX_FileIndex *index) |
| Output current cell as ASCII character (Grin) | |
| BFX_Error | bfx_op_grin_putchar_number (BFX *bfx, BFX_FileIndex *index) |
| Output current cell as a number (Grin) | |
| BFX_Error | bfx_op_grin_getchar_ascii (BFX *bfx, BFX_FileIndex *index) |
| Set current cell to inputted ASCII character (Grin) | |
| BFX_Error | bfx_op_grin_getchar_number (BFX *bfx, BFX_FileIndex *index) |
| Set current cell to inputted number (Grin) | |
| BFX_Error | bfx_op_grin_putchar_register_ascii (BFX *bfx, BFX_FileIndex *index) |
| Print register as ASCII character (Grin) | |
| BFX_Error | bfx_op_grin_putchar_register_number (BFX *bfx, BFX_FileIndex *index) |
| Print register as number (Grin) | |
| BFX_Error | bfx_op_grin_add (BFX *bfx, BFX_FileIndex *index) |
| Add register to current cell (Grin) | |
| BFX_Error | bfx_op_grin_sub (BFX *bfx, BFX_FileIndex *index) |
| Subtract register from current cell (Grin) | |
| BFX_Error | bfx_op_grin_mul (BFX *bfx, BFX_FileIndex *index) |
| Multiply current cell by register (Grin) | |
| BFX_Error | bfx_op_grin_div (BFX *bfx, BFX_FileIndex *index) |
| Divide current cell by register (Grin) | |
| BFX_Error | bfx_op_grin_exp (BFX *bfx, BFX_FileIndex *index) |
| Raise current cell to the power of register (Grin) | |
| BFX_Error | bfx_op_grin_store (BFX *bfx, BFX_FileIndex *index) |
| Store current cell value in register (Grin) | |
| BFX_Error | bfx_op_grin_load (BFX *bfx, BFX_FileIndex *index) |
| Store register value in current cell (Grin) | |
| BFX_Error | bfx_op_grin_swap (BFX *bfx, BFX_FileIndex *index) |
| Swap current cell value with register value (Grin) | |
| BFX_Error | bfx_op_grin_zero (BFX *bfx, BFX_FileIndex *index) |
| Zero current cell value (Grin) | |
| BFX_Error | bfx_op_grin_zero_ptr (BFX *bfx, BFX_FileIndex *index) |
| Zero cell at register value (Grin) | |
| BFX_Error | bfx_op_grin_mod (BFX *bfx, BFX_FileIndex *index) |
| Modulo (Grin) | |
| BFX_Error | bfx_op_grin_round (BFX *bfx, BFX_FileIndex *index) |
| Round current cell value (Grin) | |
| BFX_Error | bfx_op_grin_nand (BFX *bfx, BFX_FileIndex *index) |
| NAND current cell value with register value (Grin) | |
| BFX_Error | bfx_op_grin_or (BFX *bfx, BFX_FileIndex *index) |
| OR current cell value with register value (Grin) | |
| BFX_Error | bfx_op_grin_not (BFX *bfx, BFX_FileIndex *index) |
| NOT current cell value (Grin) | |
| BFX_Error | bfx_op_grin_negate (BFX *bfx, BFX_FileIndex *index) |
| Negate current cell value (Grin) | |
| BFX_Error | bfx_op_grin_simplify (BFX *bfx, BFX_FileIndex *index) |
| Simplify current cell value (set to -1.0 if < -1.0, 1.0 if > 1.0, 0.0 otherwise) (Grin) | |
| BFX_Error | bfx_op_grin_print (BFX *bfx, BFX_FileIndex *index) |
| Print from instruction pointer to next ')' (Grin) | |
| BFX_Error | bfx_op_grin_newline (BFX *bfx, BFX_FileIndex *index) |
| Print a newline (Grin) | |
| BFX_Error | bfx_op_grin_sin (BFX *bfx, BFX_FileIndex *index) |
| Sine of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_cos (BFX *bfx, BFX_FileIndex *index) |
| Cosine of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_tan (BFX *bfx, BFX_FileIndex *index) |
| Tangent of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_arcsin (BFX *bfx, BFX_FileIndex *index) |
| Arcsine of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_arccos (BFX *bfx, BFX_FileIndex *index) |
| Arccosine of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_arctan (BFX *bfx, BFX_FileIndex *index) |
| Arctangent of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_inv (BFX *bfx, BFX_FileIndex *index) |
| Inverse of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_mod2 (BFX *bfx, BFX_FileIndex *index) |
| Modulo of current cell value by 2 (Grin) | |
| BFX_Error | bfx_op_grin_e (BFX *bfx, BFX_FileIndex *index) |
| Set current cell to Euler's number (Grin) | |
| BFX_Error | bfx_op_grin_pi (BFX *bfx, BFX_FileIndex *index) |
| Set current cell to Pi (Grin) | |
| BFX_Error | bfx_op_grin_ln (BFX *bfx, BFX_FileIndex *index) |
| Natural logarithm of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_mean (BFX *bfx, BFX_FileIndex *index) |
| Mean of current cell value and register value (Grin) | |
| BFX_Error | bfx_op_grin_sqrt (BFX *bfx, BFX_FileIndex *index) |
| Square root of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_log (BFX *bfx, BFX_FileIndex *index) |
| Base-10 logarithm of current cell value (Grin) | |
| BFX_Error | bfx_op_grin_jump (BFX *bfx, BFX_FileIndex *index) |
| Jump n instructions, n=register value (Grin) | |
| BFX_Error | bfx_op_grin_toggle_deg_rad (BFX *bfx, BFX_FileIndex *index) |
| Toggle between degrees and radians (Grin) | |
| BFX_Error | bfx_op_grin_exit (BFX *bfx, BFX_FileIndex *index) |
| Exit the program (Grin) | |
This file contains the implementation of the Grin interpreter.
| #define BFX_CONVERT | ( | a | ) | ((BFX_GRIN_DATA->unit == BFX_GRIN_DEG) ? (a * M_PI / 180.0) : a) |
| #define BFX_GRIN_DATA ((BFX_GrinData*) bfx->lang_data) |
Initialize the Grin interpreter.
| bfx | Pointer to the already-allocated interpreter struct |
Run the Grin interpreter.
This function initializes and runs the Grin interpreter.
| bfx | Pointer to the interpreter struct |
| BFX_Error bfx_op_grin_add | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Add register to current cell (Grin)
| BFX_Error bfx_op_grin_arccos | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Arccosine of current cell value (Grin)
| BFX_Error bfx_op_grin_arcsin | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Arcsine of current cell value (Grin)
| BFX_Error bfx_op_grin_arctan | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Arctangent of current cell value (Grin)
| BFX_Error bfx_op_grin_cos | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Cosine of current cell value (Grin)
| BFX_Error bfx_op_grin_dec_t | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Decrement value at tape pointer (Grin).
| BFX_Error bfx_op_grin_div | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Divide current cell by register (Grin)
| BFX_Error bfx_op_grin_e | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Set current cell to Euler's number (Grin)
| BFX_Error bfx_op_grin_exit | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Exit the program (Grin)
| BFX_Error bfx_op_grin_exp | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Raise current cell to the power of register (Grin)
| BFX_Error bfx_op_grin_getchar_ascii | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Set current cell to inputted ASCII character (Grin)
| BFX_Error bfx_op_grin_getchar_number | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Set current cell to inputted number (Grin)
| BFX_Error bfx_op_grin_inc_t | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Increment value at tape pointer (Grin).
| BFX_Error bfx_op_grin_inv | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Inverse of current cell value (Grin)
| BFX_Error bfx_op_grin_jump | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Jump n instructions, n=register value (Grin)
| BFX_Error bfx_op_grin_ln | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Natural logarithm of current cell value (Grin)
| BFX_Error bfx_op_grin_load | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Store register value in current cell (Grin)
| BFX_Error bfx_op_grin_log | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Base-10 logarithm of current cell value (Grin)
| BFX_Error bfx_op_grin_loop_end | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
End of loop (Grin).
| BFX_Error bfx_op_grin_loop_start | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Start of loop (Grin).
| BFX_Error bfx_op_grin_mean | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Mean of current cell value and register value (Grin)
| BFX_Error bfx_op_grin_mod | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Modulo (Grin)
| BFX_Error bfx_op_grin_mod2 | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Modulo of current cell value by 2 (Grin)
| BFX_Error bfx_op_grin_mul | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Multiply current cell by register (Grin)
| BFX_Error bfx_op_grin_nand | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
NAND current cell value with register value (Grin)
| BFX_Error bfx_op_grin_negate | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Negate current cell value (Grin)
| BFX_Error bfx_op_grin_newline | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Print a newline (Grin)
| BFX_Error bfx_op_grin_not | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
NOT current cell value (Grin)
| BFX_Error bfx_op_grin_or | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
OR current cell value with register value (Grin)
| BFX_Error bfx_op_grin_pi | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Set current cell to Pi (Grin)
| BFX_Error bfx_op_grin_print | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Print from instruction pointer to next ')' (Grin)
| BFX_Error bfx_op_grin_putchar_ascii | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Output current cell as ASCII character (Grin)
| BFX_Error bfx_op_grin_putchar_number | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Output current cell as a number (Grin)
| BFX_Error bfx_op_grin_putchar_register_ascii | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Print register as ASCII character (Grin)
| BFX_Error bfx_op_grin_putchar_register_number | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Print register as number (Grin)
| BFX_Error bfx_op_grin_round | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Round current cell value (Grin)
| BFX_Error bfx_op_grin_simplify | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Simplify current cell value (set to -1.0 if < -1.0, 1.0 if > 1.0, 0.0 otherwise) (Grin)
| BFX_Error bfx_op_grin_sin | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Sine of current cell value (Grin)
| BFX_Error bfx_op_grin_sqrt | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Square root of current cell value (Grin)
| BFX_Error bfx_op_grin_store | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Store current cell value in register (Grin)
| BFX_Error bfx_op_grin_sub | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Subtract register from current cell (Grin)
| BFX_Error bfx_op_grin_swap | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Swap current cell value with register value (Grin)
| BFX_Error bfx_op_grin_tan | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Tangent of current cell value (Grin)
| BFX_Error bfx_op_grin_toggle_deg_rad | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Toggle between degrees and radians (Grin)
| BFX_Error bfx_op_grin_zero | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Zero current cell value (Grin)
| BFX_Error bfx_op_grin_zero_ptr | ( | BFX * | bfx, |
| BFX_FileIndex * | index | ||
| ) |
Zero cell at register value (Grin)