bfx
An interpreter, compiler, and REPL for brainfuck-like languages
Loading...
Searching...
No Matches
grin.c File Reference
#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)
 

Detailed Description

This file contains the implementation of the Grin interpreter.

Macro Definition Documentation

◆ BFX_CONVERT

#define BFX_CONVERT (   a)    ((BFX_GRIN_DATA->unit == BFX_GRIN_DEG) ? (a * M_PI / 180.0) : a)

◆ BFX_GRIN_DATA

#define BFX_GRIN_DATA   ((BFX_GrinData*) bfx->lang_data)

Function Documentation

◆ bfx_grin_init()

BFX_Error bfx_grin_init ( BFX bfx)

Initialize the Grin interpreter.

Parameters
bfxPointer to the already-allocated interpreter struct

◆ bfx_grin_run()

BFX_Error bfx_grin_run ( BFX bfx)

Run the Grin interpreter.

This function initializes and runs the Grin interpreter.

Parameters
bfxPointer to the interpreter struct
Returns
Error code

◆ bfx_op_grin_add()

BFX_Error bfx_op_grin_add ( BFX bfx,
BFX_FileIndex index 
)

Add register to current cell (Grin)

◆ bfx_op_grin_arccos()

BFX_Error bfx_op_grin_arccos ( BFX bfx,
BFX_FileIndex index 
)

Arccosine of current cell value (Grin)

◆ bfx_op_grin_arcsin()

BFX_Error bfx_op_grin_arcsin ( BFX bfx,
BFX_FileIndex index 
)

Arcsine of current cell value (Grin)

◆ bfx_op_grin_arctan()

BFX_Error bfx_op_grin_arctan ( BFX bfx,
BFX_FileIndex index 
)

Arctangent of current cell value (Grin)

◆ bfx_op_grin_cos()

BFX_Error bfx_op_grin_cos ( BFX bfx,
BFX_FileIndex index 
)

Cosine of current cell value (Grin)

◆ bfx_op_grin_dec_t()

BFX_Error bfx_op_grin_dec_t ( BFX bfx,
BFX_FileIndex index 
)

Decrement value at tape pointer (Grin).

◆ bfx_op_grin_div()

BFX_Error bfx_op_grin_div ( BFX bfx,
BFX_FileIndex index 
)

Divide current cell by register (Grin)

◆ bfx_op_grin_e()

BFX_Error bfx_op_grin_e ( BFX bfx,
BFX_FileIndex index 
)

Set current cell to Euler's number (Grin)

◆ bfx_op_grin_exit()

BFX_Error bfx_op_grin_exit ( BFX bfx,
BFX_FileIndex index 
)

Exit the program (Grin)

◆ bfx_op_grin_exp()

BFX_Error bfx_op_grin_exp ( BFX bfx,
BFX_FileIndex index 
)

Raise current cell to the power of register (Grin)

◆ bfx_op_grin_getchar_ascii()

BFX_Error bfx_op_grin_getchar_ascii ( BFX bfx,
BFX_FileIndex index 
)

Set current cell to inputted ASCII character (Grin)

◆ bfx_op_grin_getchar_number()

BFX_Error bfx_op_grin_getchar_number ( BFX bfx,
BFX_FileIndex index 
)

Set current cell to inputted number (Grin)

◆ bfx_op_grin_inc_t()

BFX_Error bfx_op_grin_inc_t ( BFX bfx,
BFX_FileIndex index 
)

Increment value at tape pointer (Grin).

◆ bfx_op_grin_inv()

BFX_Error bfx_op_grin_inv ( BFX bfx,
BFX_FileIndex index 
)

Inverse of current cell value (Grin)

◆ bfx_op_grin_jump()

BFX_Error bfx_op_grin_jump ( BFX bfx,
BFX_FileIndex index 
)

Jump n instructions, n=register value (Grin)

◆ bfx_op_grin_ln()

BFX_Error bfx_op_grin_ln ( BFX bfx,
BFX_FileIndex index 
)

Natural logarithm of current cell value (Grin)

◆ bfx_op_grin_load()

BFX_Error bfx_op_grin_load ( BFX bfx,
BFX_FileIndex index 
)

Store register value in current cell (Grin)

◆ bfx_op_grin_log()

BFX_Error bfx_op_grin_log ( BFX bfx,
BFX_FileIndex index 
)

Base-10 logarithm of current cell value (Grin)

◆ bfx_op_grin_loop_end()

BFX_Error bfx_op_grin_loop_end ( BFX bfx,
BFX_FileIndex index 
)

End of loop (Grin).

◆ bfx_op_grin_loop_start()

BFX_Error bfx_op_grin_loop_start ( BFX bfx,
BFX_FileIndex index 
)

Start of loop (Grin).

◆ bfx_op_grin_mean()

BFX_Error bfx_op_grin_mean ( BFX bfx,
BFX_FileIndex index 
)

Mean of current cell value and register value (Grin)

◆ bfx_op_grin_mod()

BFX_Error bfx_op_grin_mod ( BFX bfx,
BFX_FileIndex index 
)

Modulo (Grin)

◆ bfx_op_grin_mod2()

BFX_Error bfx_op_grin_mod2 ( BFX bfx,
BFX_FileIndex index 
)

Modulo of current cell value by 2 (Grin)

◆ bfx_op_grin_mul()

BFX_Error bfx_op_grin_mul ( BFX bfx,
BFX_FileIndex index 
)

Multiply current cell by register (Grin)

◆ bfx_op_grin_nand()

BFX_Error bfx_op_grin_nand ( BFX bfx,
BFX_FileIndex index 
)

NAND current cell value with register value (Grin)

◆ bfx_op_grin_negate()

BFX_Error bfx_op_grin_negate ( BFX bfx,
BFX_FileIndex index 
)

Negate current cell value (Grin)

◆ bfx_op_grin_newline()

BFX_Error bfx_op_grin_newline ( BFX bfx,
BFX_FileIndex index 
)

Print a newline (Grin)

◆ bfx_op_grin_not()

BFX_Error bfx_op_grin_not ( BFX bfx,
BFX_FileIndex index 
)

NOT current cell value (Grin)

◆ bfx_op_grin_or()

BFX_Error bfx_op_grin_or ( BFX bfx,
BFX_FileIndex index 
)

OR current cell value with register value (Grin)

◆ bfx_op_grin_pi()

BFX_Error bfx_op_grin_pi ( BFX bfx,
BFX_FileIndex index 
)

Set current cell to Pi (Grin)

◆ bfx_op_grin_print()

BFX_Error bfx_op_grin_print ( BFX bfx,
BFX_FileIndex index 
)

Print from instruction pointer to next ')' (Grin)

◆ bfx_op_grin_putchar_ascii()

BFX_Error bfx_op_grin_putchar_ascii ( BFX bfx,
BFX_FileIndex index 
)

Output current cell as ASCII character (Grin)

◆ bfx_op_grin_putchar_number()

BFX_Error bfx_op_grin_putchar_number ( BFX bfx,
BFX_FileIndex index 
)

Output current cell as a number (Grin)

◆ bfx_op_grin_putchar_register_ascii()

BFX_Error bfx_op_grin_putchar_register_ascii ( BFX bfx,
BFX_FileIndex index 
)

Print register as ASCII character (Grin)

◆ bfx_op_grin_putchar_register_number()

BFX_Error bfx_op_grin_putchar_register_number ( BFX bfx,
BFX_FileIndex index 
)

Print register as number (Grin)

◆ bfx_op_grin_round()

BFX_Error bfx_op_grin_round ( BFX bfx,
BFX_FileIndex index 
)

Round current cell value (Grin)

◆ bfx_op_grin_simplify()

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

BFX_Error bfx_op_grin_sin ( BFX bfx,
BFX_FileIndex index 
)

Sine of current cell value (Grin)

◆ bfx_op_grin_sqrt()

BFX_Error bfx_op_grin_sqrt ( BFX bfx,
BFX_FileIndex index 
)

Square root of current cell value (Grin)

◆ bfx_op_grin_store()

BFX_Error bfx_op_grin_store ( BFX bfx,
BFX_FileIndex index 
)

Store current cell value in register (Grin)

◆ bfx_op_grin_sub()

BFX_Error bfx_op_grin_sub ( BFX bfx,
BFX_FileIndex index 
)

Subtract register from current cell (Grin)

◆ bfx_op_grin_swap()

BFX_Error bfx_op_grin_swap ( BFX bfx,
BFX_FileIndex index 
)

Swap current cell value with register value (Grin)

◆ bfx_op_grin_tan()

BFX_Error bfx_op_grin_tan ( BFX bfx,
BFX_FileIndex index 
)

Tangent of current cell value (Grin)

◆ bfx_op_grin_toggle_deg_rad()

BFX_Error bfx_op_grin_toggle_deg_rad ( BFX bfx,
BFX_FileIndex index 
)

Toggle between degrees and radians (Grin)

◆ bfx_op_grin_zero()

BFX_Error bfx_op_grin_zero ( BFX bfx,
BFX_FileIndex index 
)

Zero current cell value (Grin)

◆ bfx_op_grin_zero_ptr()

BFX_Error bfx_op_grin_zero_ptr ( BFX bfx,
BFX_FileIndex index 
)

Zero cell at register value (Grin)