||2 years ago|
|examples||2 years ago|
|.gitignore||2 years ago|
|README.md||2 years ago|
|builtins.go||2 years ago|
|builtins_test.go||2 years ago|
|eval.go||2 years ago|
|flags.go||2 years ago|
|go.mod||2 years ago|
|go.sum||2 years ago|
|main.go||2 years ago|
|mem.go||2 years ago|
|mem_test.go||2 years ago|
|stack.go||2 years ago|
|stack_test.go||2 years ago|
|words.go||2 years ago|
|words_test.go||2 years ago|
Prosper is a Forth-like stack-based language. While taking specific influence from Forth, it does not attempt to emulate or implement the ANS Forth standards.
Currently, the language is entirely interactive -- to explore, simply run
go run . in the root of this project and an interactive session will begin.
Prosper is stack-based, as mentioned, so all the standard stack semantics are present:
> 1 2 3 4 + * - ok > . -13 ok
New words can be defined using
> : SQUARE DUP * ; ok > 10 SQUARE . 100 ok
It has a single loop construct,
> : TOFIVE 5 0 DO I . LOOP ; ok > TOFIVE 0 1 2 3 4 ok
IF ELSE THEN work:
> : EMOJI 0 < IF 128201 EMIT ELSE 128200 EMIT THEN ; ok > 100 EMOJI 📈 ok > -100 EMOJI 📉 ok
Here's a Fibonacci implementation:
> : FIB 2DUP + ; ok > : FIBN 0 1 ROT 1 DO FIB ROT DROP LOOP SWAP DROP ; ok > 10 FIBN . 55 ok
Propser also has a basic off-stack memory model using variables, constants, and pointers:
> VARIABLE FOO ok > 10 FOO ! ok > FOO @ ok > . 10 ok > 100 CONSTANT HUNDRED ok > HUNDRED HUNDRED * . 10000 ok
And, of course, it knows how to quit:
> BYE bye
- Rearchitect how compilation works -- currently, non-built-in words are stored as raw sets of strings, which means in the case of things like IF/ELSE/THEN we have to re-parse the tree and use the IFStack to track the parse status. It'd be better to compile to some intermediate representation so that the compiler can store the JMP locations inline and execution just flows from instruction to instruction instead of re-parsing the entire descent-tree every time.
- More looping constructs (
WHILEwould be nice).
- Add ways for Prosper words to hook into the input/output streams (probably required for self-hosting a prosper compiler in prosper, which is a long way off).