Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nathsou/elox
Interpreter for a superset of Crafting Interpreter's lox language
https://github.com/nathsou/elox
craftinginterpreters interpreter lox rust
Last synced: 8 days ago
JSON representation
Interpreter for a superset of Crafting Interpreter's lox language
- Host: GitHub
- URL: https://github.com/nathsou/elox
- Owner: nathsou
- Created: 2019-06-10T23:12:21.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T07:43:26.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T20:42:55.729Z (25 days ago)
- Topics: craftinginterpreters, interpreter, lox, rust
- Language: Rust
- Homepage: https://nathsou.github.io/Elox/web/dist/index.html
- Size: 2.05 MB
- Stars: 18
- Watchers: 4
- Forks: 2
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Elox
Elox for Extended-lox, is a superset of the lox toy language from Bob Nystrom's book [_Crafting Interpreters_](http://www.craftinginterpreters.com/).
It is an interpreted (both in a VM or directly by walking the AST) or compiled (to WASM), dynamically typed, objected oriented programming language.
You can test it [here](https://nathsou.github.io/Elox/web/dist/index.html)
Its main additions to lox are :
- Native Arrays
- String concatenation of any variable types allowed
- Modulo '%' operator available
- Usual assignment shorthands: +=, -=, ++, --, *=, /=, %=
- Default valued function parameters
- Rest parameters
- Anonymous functions allowed# Running
Elox is written in Rust and can thus target your computer's architecture and [WebAssembly](https://webassembly.org/).
Furthermore, an Elox to wasm compiler is in development
## Compiling and running
In the project folder:
```bash
$ cargo run --release --bin [elox | vm | wasm] [file.elox]
```## Compiling to WebAssembly
### Compiling an elox program to wasm
Elox can target wasm directly, it uses the VM compiled bytecode as
an intermediate representation which is then translated to WebAssembly```bash
$ cargo run --release --bin wasm [file.elox]
```this command produces a file named out.wasm which can be run with :
```bash
$ node run_wasm.js
```### Compiling the project to wasm
Using [wasm-pack](https://rustwasm.github.io/wasm-pack/) in the project folder:
```bash
$ wasm-pack build
```The demo website using the compiled wasm module can be run using:
```bash
$ cd web
$ npm run start
```## Todo
- [ ] Arrow functions
- [ ] standard library
- [ ] Implement [traits](https://www.wikiwand.com/en/Trait_(computer_programming))
- [X] Write a compiler targetting wasm directly
- [ ] Optional type annotations used by a static type checker
- [ ] Function overloading
- [ ] 'const' keyword
- [ ] Replace 'nil' with Option\ or other? => match and enums?
- [ ] bundler to import other elox files
- [ ] extern code execution (C or JS)## Examples
Demos are available in the /demos folder and can be [run online](https://nathsou.github.io/Elox/web/dist/index.html).
```javascript
// Pseudo Random Number Generator
class PRNG {
init(seed = clock() * 1000) {
this.a = 25214903917;
this.c = 11;
this.m = 281474976710656;
this.seed = seed;
}next() {
this.seed = (this.a * this.seed + this.c) % this.m;
return this.seed / this.m;
}
}
var prng = PRNG();
var nums = [];for (var i = 0; i < 10; i++) {
nums.push(prng.next());
}print nums;
```