Skip to content

kryptamine/rune

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ci Go Python

Rune Interpreter

Rune is a dynamically typed interpreted programming language inspired by Lox and built following concepts from the book Crafting Interpreters by Robert Nystrom. This interpreter is implemented in Go and is designed to be cross-platform, compiling into a statically linked binary.

Features

  • Dynamically typed language with a simple syntax
  • Supports expressions, statements, variables, and functions
  • Built-in functions for array manipulation, JSON parsing, and timing
  • Recursive descent parser and tree-walk interpreter
  • Cross-platform, compiles to a single binary

Installation

To build the interpreter, you need to have Go installed. Clone the repository and run:

make build

This will generate an executable binary named rune in the project directory.

Running the Interpreter

You can execute Rune scripts using the run command:

./rune run script.rn

Alternatively, you can specify the file in the Makefile and use:

make run

Interpreter Commands

The Rune interpreter supports the following commands:

  • tokenize — Tokenizes the given input file.
  • evaluate — Evaluates a single expression from the file.
  • run — Executes the entire program from the input file.

Example usage:

./rune run program.rn

Running Tests

Test Framework with tests suites is stolen from Ben Hoyt and patched.

make test

To run a specific test or filter tests by category:

python3 test.py <filter>

For example, to run only the arrays tests:

python3 test.py arrays

Built-in Functions

Rune provides several built-in functions:

  • len(arr) — Returns the length of an array.
  • append(arr, value1, value2, ...) — Appends values to an array and returns the new array.
  • json(url) — Fetches and parses JSON from a URL, error handling is not implemented.
  • clock() — Returns the current time in seconds.

Example Program

Here’s a simple Rune script that calculates the sum of an array:

fun sumArray(arr) {
    var total = 0;
    for (var i = 0; i < len(arr); i = i + 1) {
        total = total + arr[i];
    }
    return total;
}

print sumArray([1, 2, 3, 4, 5]);

License

This project is open-source and follows the MIT license.

References

About

Rune programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published