https://github.com/aaronc81/garnet
A stack-based language based on Ruby
https://github.com/aaronc81/garnet
Last synced: 10 months ago
JSON representation
A stack-based language based on Ruby
- Host: GitHub
- URL: https://github.com/aaronc81/garnet
- Owner: AaronC81
- Created: 2018-11-23T23:12:49.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-23T23:19:08.000Z (about 7 years ago)
- Last Synced: 2025-03-06T15:17:08.145Z (10 months ago)
- Language: Ruby
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Garnet
Garnet is a **stack-based language running on Ruby.** It doesn't introduce
a new set of functions and data types; rather, code is evaluated directly
as a Ruby `Module` using `instance_eval`.
It's still really basic, but could be developed into a useful, minimalistic
alternative to Ruby.
## Basic usage
You push things onto a stack, then call functions to reduce the stack. All
functions will push one return value onto the stack, even if it's `nil`.
Example program:
```
8 2 #+ puts$1 #
```
- `8 2` - Pushes 8 and then 2 onto the stack.
- `#+` - Calls the instance method `+` on `2`, with one argument `8`. The argument count can be determined automatically because `+` *always* takes one argument.
- `puts$1` - Calls `puts`. The argument count must be specified explicitly because `puts` takes `*args`, hence the `$1` for 1 argument.
- `#` - Discard the top element of the stack, which will be `nil` because `puts` returns `nil`.