a terrible forth-like language for making memes https://szy.io/memeforth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11KB

Table of Contents

InterpreterState

Type: Object

Properties

  • stack Array<any> The current stack
  • tokens Array<any> The current tokenized program
  • words Object The current set of defined words
  • memory Array<any> The current interpreter “memory”.
  • currentWord string The current word being defined.
  • output string The output from printing commands.

hacker

Converts the top of the stack to :hacker_X: emojis.

Parameters

sm64

Converts the top of the stack to :sm64_X: emojis.

Parameters

concat

Concatenates the top two elements on the stack.

Parameters

drop

Drops the top element of the stack.

Parameters

dup

Duplicate the top element of the stack.

Parameters

swap

Swap the top two elements of the stack

Parameters

rot

Rotate the top three elements of the stack.

Parameters

litstring

Parse a literal string until we find a string ending with "

Parameters

add

Adds two values on the stack. (This is subject to JavaScript's type coercion system.)

Parameters

sub

Subtracts two values on the stack. (This is subject to JavaScript's type coercion system.)

Parameters

mul

Multiplies two values on the stack. (This is subject to JavaScript's type coercion system.)

Parameters

divmod

Divides two values on the stack, and pushes the quotient and its remainder. (This is subject to JavaScript's type coercion system.)

Parameters

len

Replaces a string on the stack with its length. Replaces integers or other values on the stack with 0.

Parameters

print

Return the first element in the stack, staging it for output.

Parameters

printStack

Print the entire Forth stack. This does not affect the Forth stack at all - it merely shows it.

Parameters

store

Store a stack element into memory.

Parameters

fetch

Load from memory and push to the stack.

Parameters

defvar

Defines a variable by defining a word as a location in memory where the variable will be stored.

Parameters

  • state InterpreterState The current interpreter state.

  • Throws TypeError Throws an exception if a non-string variable name is given.

gt

Greater than comparison

Parameters

lt

Less than comparison

Parameters

ge

Greater than or equal comparison

Parameters

le

Less than or equal comparison

Parameters

eq

Equals comparison

Parameters

ne

Not equals comparison

Parameters

and

Logical AND

Parameters

or

Logical OR

Parameters

not

Logical NOT

Parameters

rand

Generate a random number between a min and a max

Parameters

litTrue

Push a literal true boolean onto the stack.

Parameters

litFalse

Push a literal false boolean onto the stack.

Parameters

colon

Defines a word until a ;

Parameters

strSlice

Slice a string based on substring indices.

Parameters

  • state InterpreterState The current interpreter state.

  • Throws TypeError Throws an exception if invalid types are given for indicies or the string to slice.

dictionary

The base dictionary of supported MemeForth tokens.

ifword

Parse an IF block.

Parameters

doLoop

Parse a DO loop.

Parameters

interpret

Interprets a Forth token list.

Parameters

Returns InterpreterState The final state of the interpreter after execution.

runMemeForth

Runs a Forth program and returns the stack.

Parameters

  • program string A Forth program, in string form.
  • stack Stack The initial stack. (optional, default new Stack())
  • mem (optional, default [])
  • memory Array<any> The intial memory.

Returns InterpreterState The result of the program execution

Stack

The Memeforth program stack.

Parameters

  • arr Array<any>? The initial stack to use, as an array.

pop

Pop the top value from the stack. Removes the item from the stack in-place.

Returns any The value popped from the stack.

push

Push a value onto the top of the stack.

Parameters

  • values ...any The values to push onto the stack.