Skip to content

Stack-based programming language inspired by Forth.

License

Notifications You must be signed in to change notification settings

burning-eggs/whim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

whim

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

Example

Simple program that prints numbers from 10 to 1 in descending order:

10 while dup 0 > do
    dup .
   1 -
end

Quick Start

Simulation

Simulating a .whm simply interprets the program.

$ cat program.whm
50 50 + .
$ ./whim.py sim program.whm
100

Compiling

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

Language Reference

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.

Stack Manipulation

  • <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.

Comparison

  • = - checks if two elements on top of the stack are equal. Removes the element from the stack and pushes 1 if they are equal, 0 if not.

  • > - checks if the element below the top element is greater than the top element.

Badges

Code style: black

About

Stack-based programming language inspired by Forth.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages