Stack based programming language inspired by Forth.
QUICK DISCLAIMER: COMPILING .whm FILES CURRENTLY DOESNT WORK ON WINDOWS.
Whim is planned to be
- Compiled
- Native
- Stack-Based
- Turing-Complete
- Statically Typed
- Self-Hosted
Simple program that prints numbers from 10 to 1 in descending order:
10 while dup 0 > do
dup .
1 -
end
Simulating a .whm
simply interprets the program.
$ cat program.whm
50 50 + .
$ ./whim.py sim program.whm
100
Compiling a .whm
file generates assembly code and compiles it with nasm, and then links it with GNU ld. Make sure you have both available in your $PATH
.
$ cat program.whm
30 30 + .
$ ./whim.py com program.whm
[COMPILE] Generating 'program.asm'
[CMD] nasm -felf64 program.asm
[CMD] ld -o program.asm program.o
[CMD] rm -rf program.o
$ ./program.asm
60
This is what the language supports so far. Since the language is a work in progress, the exact set of operations is subject to change.
-
<integer>
- push an integer onto the stack. Right now the integer is anything that can be parsed by the int function. -
dup
- duplicate an element on top of the stack. -
.
- print the element on top of the stack and remove it from the stack.
-
=
- checks if two elements on top of the stack are equal. Removes the element from the stack and pushes1
if they are equal,0
if not. -
>
- checks if the element below the top element is greater than the top element.