Mimsy

Mimsy is an esoteric programming language invented by Michael Patraw. The language has a lot of similarities to assembly, but there are some differences. For one, branching instructions scan the code space at runtime for branch points. No computation of any kind is done at compile-time.

Etymology
The language is named after a word found in Lewis Carroll's book: Through The Looking-Glass. It can be thought of as the combination of the two words: "flimsy" and "miserable".

Memory
Mimsy's memory is an array (standard is a size of 256). Two hundred and fifty of the memory locations, indexed from 0 to 249, are used for typical storage locations. The remaining six memory locations are reserved for special function pseudo-registers, they're "pseudo" because they don't carry the same advantages as typical hardware registers. Every instruction in Mimsy does something involving these memory locations. There are three data types in Mimsy: Dynamic arrays, integers and floats. Every memory location can contain any mixture of these types. A dynamic array containing dynamic arrays containing floats and integers, for examples

Register Name			To Select this Register		Description The Hand			(@)				This resembles the functionality of the accumulator in some assembly languages. Code				(!)				This is a dynamic array of opcodes. It can be modified at runtime. Instruction Pointer (IP)	(*)				This is always an integer, which represents the current location of execution. Jump Stack (JMP)		(^)				A dynamic array treated as a stack. Saves jump points. Flags				(?)				A dynamic array of four integers representing equality, inequality, less-than, greater-than. 1 is true, 0 is false. Select				Can't				This is the currently selected location in memory. It's a dynamic array of integers representing memory location indices. [0] would be the first memory location, while [0 0] would assume memory location 0 to be a dynamic array and select the first element in it.

Instructions
Each instruction is represented by a single opcode. When the source file is run it is translated into the opcodes, then the opcodes are transferred over to the Code register the program begins execution of them. There are examples below for most of the instructions. Here is the list of instructions:

Code		Description
 * 1) 		Anything past this (on the line) is a comment and never makes it into the Code register.

(...)          The selection operator. The only way to access memory locations. Here is a list of possible arguments: (x)	-- x is an integer. (x,y)	-- x and y are integers. (,y)	-- y is a integer. Goes to the index of the current selection. For example, if Select is [0], (,0) would make it [0 0] -- Goes back. For example, if Select is [0 0], would make it [0] ($)    -- Selects the location pointed to by The Hand. If The Hand is [0 0], Select becomes [0 0]. (...)  -- The remaining arguments are for selecting different registers: (@) -- Selects The Hand (!) -- Selects Code (*) -- Selects IP			  (^) -- Selects JMP (?) -- Selects Flags

<		Moves whatever is in The Hand into the current selection. Dynamic arrays are deep copied. >		Moves whatever is currently selected into The Hand. Dynamic arrays are deep copied.

/		Divides whatever is currently selected by what's in The Hand and places the result in The Hand. %		Mods whatever is currently selected by what's in The Hand and places a dynamic array with the result and remainder in The Hand. -		Subtracts whatever is currently selected by what's in The Hand and places the result in The Hand. +		Adds whatever is currently selected by what's in The Hand and places the result in The Hand. &		ANDs whatever is currently selected by what's in The Hand and places the result in The Hand. ^		XORs whatever is currently selected by what's in The Hand and places the result in The Hand. ~		Negates what's in The Hand. !		NOTs what's in The Hand. 0 becomes 1, anything else becomes 0. =		Compares whatever is currently selected by what's in The Hand and sets the Flags.
 * Multiplies whatever is currently selected by what's in The Hand and places the result in The Hand.
 * ORs whatever is currently selected by what's in The Hand and places the result in The Hand.

$		Gets the length of whatever is in The Hand and stores the result in The Hand. -1 if not a dynamic array.

,		The dynamic array manipulation operator: Depends on what's in The Hand.

If what's in The Hand is an integer, whatever is currently selected is increased in size by N and filled with 0's, where N is what's in The Hand. If what's in The Hand is zero, whatever is currently selected is removed. If what's in The Hand is a dynamic array of size one, a 0 is inserted at index N, where N is the number in the dynamic array.

@		Searches for the next ; in the code and stores it on top of the JMP stack. Can search backwards are forwards from where the @ is. This instruction requires an integer in The Hand. If it's negative it searches backwards and if it's positive it searches forwards. The integer specifies how many to skip, for example 1@ skips the next ; and saves the one following it. _1@ saves the ; directly preceding the @, _2@ skips that one and searches for the next.


 * Searches for the next ; in the code and stores it in the IP. Can search backwards are forwards from

where the @ is. This instruction requires an integer in The Hand. If it's negative it searches backwards and if it's positive it searches forwards. The integer specifies how many to skip, for example 1@ skips the next ; and saves the one following it. _1@ saves the ; directly preceding the @, _2@ skips that one and searches for the next.


 * Place holder. Jump point.

?		Executes the next instruction only if what's currently selected is not 0 or None, otherwise it skips it.

'		Pops the JMP stack and places it in IP.

`		Stores whatever is in The Hand on top of the JMP stack.

[data...]	Creates a dynamic array and puts it in The Hand. For example, [0 0 0 0]. "string"	Creates a dynamic array of integers and puts it in The Hand. For examples, "  " would put [32 32 32 32] in The Hand. (32 is the decimal ASCII value for space). _12394		Puts an integer in The Hand. NOTE: To use negatives a _ is used instead of -. 123095.045	Puts a float in The Hand.

{name data}	Creates a macro at runtime. Whenever the macro is referred to by an instruction the data is placed in The Hand. For examples, {count 0} would create a macro. Having just "count" in your source file (without the quotes) would put 0 in The Hand. name           If the macro exists it stores it's value in The Hand or executes the code associated with it. Macros are the only way (so far) to execute external functions.

Here are a couple example programs to illustrate some of the instructions:

(0)2<		# Store 2 at memory location 0. (1)1<		# Store 1 at memory location 1. (1)1+<	# Selects memory location 1, put 1 in The Hand, add the two and store. (0)2*<	# Selects memory location 0, put 2 in The Hand, multiply the two and store. 1024=	# Compare what's in The Hand with 1024. Sets Flags. (?)(,0)_1?:    # Select the EQ index, 0, of the Flags, put -1 in The Hand (jump point offset). Check # the current selection, if it's 1, skip the jump. xOutputMemory	# Output the memory.
 * 1) Multiplies two by two by two... until the result is 1024. A count is kept track. Memory
 * 2) location 0 should contain 1024 and memory location 1 should contain 10 by the end of
 * 3) this program's execution.
 * 1) this program's execution.
 * # Create a jump point.


 * 1) This program creates a dynamic array of size 100 at location 0.
 * 2) Then sets each element to 5.
 * 1) Then sets each element to 5.

(0)100,			# Create the 100 elements. [1]{ptr}		# Store the location of the ptr variable. ptr($)[0 0]<		# Set the variable to [0 0]. ptr($)>($)		# Get the location pointed by ptr. 5<			# Store the five at the new selection. ptr($)(,_1)>	# Get the last element of ptr. 1+<			# Add one and store it. 100=		# Compare it to 100 (the size of the dynamic array) (?)(,0)_1?:		# Check Flag 0 (equality), skip the jump if it's equal. null{ptr}		# Always a good idea to remove the entry.
 * # Jump point.

xOutputMemory

Sample programs
A cat program in Mimsy:

(0)0<;(0)>xPut xGet(0)<_1=(?)(,0)_1?:

A Hello, World! program in Mimsy:

0@(^)(,_1)>{printString}0,2:;(0)<(1)$<(2)null<2,;(2)>($)>xPut(2,1)1+<(1)>(2,1)=(?)(,0)_1?:13xPut10xPut'; 0@printString`"Hello, world!"';

External resources

 * The inventor's interpreter (written in Python)