Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zeroflag/equinox
Forth Programming Language on Lua
https://github.com/zeroflag/equinox
concatenative-language forth gamdev love2d lua programming-language tic80
Last synced: 8 days ago
JSON representation
Forth Programming Language on Lua
- Host: GitHub
- URL: https://github.com/zeroflag/equinox
- Owner: zeroflag
- Created: 2017-12-22T11:33:09.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-02-08T13:44:54.000Z (11 days ago)
- Last Synced: 2025-02-08T14:29:03.375Z (11 days ago)
- Topics: concatenative-language, forth, gamdev, love2d, lua, programming-language, tic80
- Language: Lua
- Homepage:
- Size: 4.26 MB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Equinox - Forth Programming Language That Targets Lua π

```forth
_____ _ _____ _ _
| ____|__ _ _ _(_)_ __ _____ __ | ___|__ _ __| |_| |__
| _| / _` | | | | | '_ \ / _ \ \/ / | |_ / _ \| '__| __| '_ \
| |__| (_| | |_| | | | | | (_) > < | _| (_) | | | |_| | | |
|_____\__, |\__,_|_|_| |_|\___/_/\_\ |_| \___/|_| \__|_| |_|
|_|: fibonacci ( n -- .. ) 0 1 rot 0 do 2dup + loop ;
10 fibonacci .s
```## π Design goals
* Compiles directly to (optimized) Lua source code.
* Modeless with no interpretation mode, no return stack.
* Lua table and array support.
* Fixes Lua's accidental global problem.
* GameDev support via [Love2D](https://love2d.org/) and [TIC-80](https://tic80.com/) (later).
* Self-hosted compiler (later).## π Install
```bash
$ luarocks install equinox
```The easiest way to install Equinox is by using Lua's package manager, [Luarocks](https://luarocks.org/).
Equinox requires Lua 5.1 or later.
### π» Start the REPL
```bash
$ equinox
```
If you're a first-time Forth user, I suggest you start with the built-in tutorial.
In the REPL, type:
```
load-file tutorial
```### Compile and execute a file:
```bash
$ equinox file.eqx
```### Embed Into Lua Project
For Love2D sample project see this repository: [VimSnake](https://github.com/zeroflag/vimsnake).
## π Why Equinox?
Popular retro gaming platforms like the [TIC-80](https://tic80.com/) tiny computer and 2D game engines like [Love2D](https://love2d.org/) usually use [Lua](https://www.lua.org/) for scripting.
While Lua's a cool, lightweight language, it doesnβt quite give you that old-school game dev vibe. Forth, on the other hand, really brings you back to the golden age of gaming with that nostalgic feel.
Lua has some questionable semantics, like how a simple typo can accidentally create a global variable when you wanted to modify a local one. Equinox fixes this problem by preventing accidental creation of globals.
Unlike Lua, Equinox syntactically distinguishes between sequential tables `[]` and hash maps `{}`. While the underlying data structure is the same, this differentiation helps make the code easier to read, in my opinion.
## β Why Not Equinox?
Equinox is a Forth that uses postfix notation and a stack to manage the parameters of words. This is quite different from how mainstream programming languages work and look. Some people might find this style unusual or hard to read.
While I believe Forth helps make people better programmers by teaching them to value simplicity and break down definitions into small, manageable pieces (which is more of a must than an option), Iβm fully aware itβs not for everyone.
Equinox is generally slower than Lua, mainly due to the stack operations. While the compiler uses various optimization rules to minimize these operations, it's still in its early phase, so the end result is often slower compared to a pure Lua counterpart.
However, this performance difference is expected to improve in the future.
## Differences from Other Forth Languages
* Equinox can leverage Lua's high-level data structure, the table, which can be used as an array or a dictionary.
* `!` (put) and `@` (at) are used for table access and modification, rather than variable assignment.
* You can use control structures such as `if`, `then`, as well as loops, outside of word definitions because Equinox does not have an interpretation mode.
* String literals are supported at the syntax level and are denoted with double quotes (`"`).
* Equinox doesn't have a dedicated return stack (no `>r`, `r>` words), but it has an auxiliary stack that can be used similarly (`a>`, `>a`).
* `DO` loops use Lua local variables internally instead of the return stack, so no `unloop` is needed for an early exit.
* `DO` loops have safer semantics as they check the condition before entering the loop, so `1 1 do i . loop` won't do anything.
* Equinox doesn't have its own standard library besides the stack manipulation words and a few others for table construction, so you need to use Lua functions.
* The majority of the Equinox words are macros (immediate words), including the arithmetic operators and stack manipulation words.
* In the current version user defined immediate words are not supported.## Tutorial
* [Core](doc/core.md)
* [Variables](doc/vars.md)
* [Lua Interop](doc/interop.md)
* [Table Operations](doc/table.md)
* [Modules](doc/modules.md)
## The NameThe USS Equinox, `NCC-72381`, was a small, Nova class Federation science vessel that stuck in the Delta Quadrant and was (will?) destroyed in 2376.
RIP Captain Ransom and crew.
Source [Wikipedia](https://en.wikipedia.org/wiki/Equinox_(Star_Trek:_Voyager)).
(If you have good ASCII art or logo of a Nova-class starship, let me know, and I'll replace the Constitution one.)