Spice
Summary
A programming language for 'Golfing' in an assembly-like/lite environment.
- Spice is an interpreted assembly-like language with a handful of operators: ADD, `SUB`, MUL`, `DIV`, `MOD`, `PUT`, `GET`, `SWI`, `BRK`, `ALS`, `OUT`, `LOD`, `SIN`, `COS`, `TAN`, `POW`, `REA`, `CLR`, `LEN`, `NUL`. For full descriptions of each operator see the link to the language README in the resources section
- Spice programs are split into two sections; declaration and instruction, split with an @
character.
- All values are dynamically sized double
arrays with the exception of string literals, "Some string"
, which may be used in OUT
statements, but not stored
- The end of instructions is denoted by a user-defined character - the first character of the program
Example code
Hello world:
;@ OUT "Hello World"
Or, doing slightly more useful things:
;in;temp;res;@ OUT "Addition calculator - first no:"; REA in; OUT "second no:"; REA temp; ADD in temp res; OUT "= " res;
Example module for sorting a passed array from the standard library (std::sort.spice):
;unsorted;unsortedVal;currSorted;outerIterator;innerIterator;unsortedLength;sortedLength;finalSortedIndex;return@ LEN unsorted unsortedLength; NUL initalise outer counter to 0; ADD 0 0 outerIterator; NUL ===== START OUTER LOOP =========; GET outerIterator unsorted unsortedVal; LEN return sortedLength; SUB sortedLength 1 finalSortedIndex; ADD 0 -1 innerIterator; NUL ===== START INNER LOOP =========; ADD innerIterator 1 innerIterator; NUL deal with over-running end of list; SWI finalSortedIndex innerIterator 15; NUL otherwise, get the current val, and if it's more than unsorted, insert at innerIterator-1; GET innerIterator return currSorted; SWI currSorted unsortedVal 8; NUL ====== END INNER LOOP ==========; PUT innerIterator return unsortedVal; ADD outerIterator 1 outerIterator; SWI outerIterator unsortedLength 3; NUL ===== END OUTER LOOP ===========;
Interpreters
A single Spice interpreter exists. See Resources.
External resources
- Spice interpreter on GitHub
- Language README direct link