Awesome Go

evie

CategoryEmbeddable Scripting Languages
SubcategoryEmbeddable Scripting Languages
Stars4

Embeddable scripting language with classes, fibers and per-engine sandboxing

About evie

The Evie Programming Language

Go Reference CI codecov

Evie is a lightweight, dynamically typed scripting language written in pure Go without CGO. Combining the dynamic ergonomics of JavaScript and Python with Go's simplicity and Rust's safe-by-default immutability, Evie features cooperative fibers with go and await, first-class OOP with classes and inheritance, and seamless Go host embedding.

On an eight-workload cross-language suite, Evie is the fastest of the languages a Go program can embed: 3 to 10 times faster than Kavun, gopher-lua, Tengo, Starlark, goja and Yaegi. It is also slightly faster overall than PUC Lua 5.4, written in C, and about twice as fast as Google's V8 Ignition JavaScript interpreter. See here.

Website · Try it in your browser · Language guide


Showcase

Recursive Fibonacci (examples/fib.ev)

String Interpolation & I/O (examples/input.ev)

Concurrent Tasks with go (examples/go.ev)

Tasks spawned with go run as fibers of the instance and return stateful, memoized Task handles that can be awaited (await task, await.all, await.any, await.race, await.timeout) or cancelled (task.cancel()). Only one fiber of an instance executes Evie code at a time; a fiber hands over at await and inside blocking host functions such as time.wait, so shared state never needs locking and a script can never race.

To test this program, run go run ./evie -t ./examples/go.ev.

The flag -t prints how long the program took, parsing and compiling included.

Shared state without locks (examples/race.ev)

Two tasks incrementing one global always end at the exact total, because fibers of an instance interleave only at await and in blocking host calls. To use several CPU cores, a host creates several instances; each has its own heap and nothing is shared between them.


Key Features

  • Cooperative & Expressive Concurrency:
    • go spawns concurrent fibers returning stateful Task instances.
    • await pauses the fiber until task resolution with multi-await memoization.
    • Multi-task coordination, deadlines, and cancellation via await.all(), await.any(), await.race(), await.timeout(), and task.cancel().
  • One Running Fiber per Instance:
    • Fibers hand over at await and inside blocking host functions, so arrays, objects, classes and globals need no locks and cannot race.
    • Parallelism across instances: every vm.Instance has its own runner and heap.
  • Safe-by-Default Immutability:
    • x := 10 creates an immutable binding.
    • var x := 10 is explicitly required for mutability.
  • First-Class Classes & OOP:
    • Fixed-shape classes with declared body fields (field := ... immutable, var field := ... mutable) and per-instance initializers.
    • Encapsulated methods with implicit this.
    • Classical single inheritance (class Sub : Super { ... }) with super.method() calls.
    • First-class bound methods (fnVal := p.greet).
    • Polymorphic type checks (p is Person, dog is Animal).
  • Modern Control Flow & Collections:
    • if, else, switch, while, break, and continue.
    • for item in collection and for idx, item in collection over arrays, objects, strings, and buffers.
    • Indexing and slicing (arr[a:b], str[a:b], buf[a:b]) with UTF-8 character semantics on strings.
  • Robust Error Handling:
    • throw and catch(expr) or catch { ... } with first-class error values: a message, a kind such as "notFound" or "timeout" to tell failures apart, any fields and a cause, and the file, line, column and call trace.
    • Compiler-grade diagnostics: every error shows the offending line with the span underlined, related places, a hint, and suggestions for misspelled names.
  • Compact 16-Byte Tagged Value:
    • Compact 16-byte tagged Value (uint64 + unsafe.Pointer) storing number, bool, and nil inline without heap allocation (number, bool, string, buffer, array, object, class, task, error, function, nil).
  • Seamless Go Host Embedding:
    • Go functions become natives through typed wrappers (vm.Func1(goFunc)) or reflection (vm.Reflect(goFunc)).
    • Bidirectional marshaling and unmarshaling into native Go structs (val.Unmarshal(&struct), json.Marshal(val)).
    • Per-engine stdlib sandboxing (Options.Stdlib, Options.NoStdlib), virtual/embedded filesystems (Options.FS confines imports and the fs package, which can then only read from it), and custom I/O streams (Options.Stdin, Options.Stdout).
    • Parse once, run anywhere: evie.ParseFile, ParseProject and ParseSource produce an immutable *evie.Bundle that eng.RunBundle runs in any number of independent engines at once.
    • One-line script execution (evie.Eval(...)).
    • Stopping runaway scripts with Interrupt() or a context deadline, without the script being able to catch it.
    • A call depth limit (Options.MaxCallDepth, 10,000 by default): runaway recursion raises a catchable "stackOverflow" error instead of crashing the host.
  • Pure Go (Zero CGO):
    • 100% Go codebase, fast builds, effortless cross-compilation, and zero external dependencies.

Go Host Embedding Example

Embedding Evie in your Go application requires no CGO or complicated bindings:

package main

import (
    "fmt"
    "github.com/hxkhan/evie"
    "github.com/hxkhan/evie/vm"
)

func main() {
    // 1. A host package the script can import. Func1 wraps a Go function without reflection.
    api := vm.NewPackage("api")
    api.Native("fetchData", vm.Func1(func(id int) map[string]any {
        return map[string]any{"id": id, "status": "active"}
    }))

    // 2. An engine with the standard library and the host package
    eng := evie.New(evie.Options{Packages: []*vm.Package{api}})
    defer eng.Close()

    // 3. Load a script
    _, err := eng.Eval(`package main imports("api")
        fn status(id) {
            data := api.fetchData(id)
            return data.status
        }`)
    if err != nil {
        panic(err)
    }

    // 4. Call into it with Go arguments; evie.Format prints an error the way the CLI does
    val, err := eng.Call("main.status", 42)
    if err != nil {
        fmt.Print(evie.Format(err, false))
    }
    fmt.Println(val) // active

    // 5. One-line evaluation
    result, _ := evie.Eval("return [1, 2, 3].len() * 10")
    fmt.Println(result) // 30
}

Natives can also be written against the call context directly, which is the fastest path and gives full control over argument checking (use c.Async for background tasks tied to the engine's lifecycle):

pkg.Func("wait", 1, func(c vm.Call) (vm.Value, error) {
    ms, err := c.Number(0) // "wait: argument 1 must be a number, got string"
    if err != nil {
        return vm.Value{}, err
    }
    timer := time.NewTimer(time.Duration(ms) * time.Millisecond)
    defer timer.Stop()
    select {
    case <-timer.C:
        return vm.Value{}, nil
    case <-c.Context().Done(): // the script was stopped
        return vm.Value{}, context.Cause(c.Context())
    }
}).Blocking = true // gives the instance to other fibers while it sleeps

Runaway scripts can be stopped from any goroutine with eng.Interrupt(), or bounded by a context:

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
_, err := eng.CallContext(ctx, "main.status", 42) // errors.Is(err, context.DeadlineExceeded) after 2s

Recursion is bounded too: a call more than Options.MaxCallDepth deep (10,000 unless set) raises an error of kind "stackOverflow", which scripts can catch, so a script cannot exhaust the Go stack and take the process down.


Features Checklist

  • Variables & Immutability (:= vs var :=)
  • Functions, Closures & Variadic Arguments (...args)
  • Primitive types (number, bool, nil)
  • Reference types (string, buffer, array, object, function, task, error)
  • Classes & OOP (fixed-shape layout, body fields, methods, this, single inheritance, super, bound methods)
  • Control flow (if, else, switch, while, break, continue)
  • For loops (for item in col, for idx, item in col) & slicing (arr[a:b], str[a:b], buf[a:b])
  • Operators (+, -, *, /, %, ==, !=, <, <=, >, >=, ?)
  • Logical operators (!, &&, ||)
  • Type checking (is operator)
  • Concurrency (go, await, await.all, await.any, await.race, await.timeout, Task, task.cancel)
  • One running fiber per instance (no locks, no data races, cooperative await)
  • Scoping (global, package, function, block, captured closures)
  • Error handling (throw, catch, error values with kinds, fields and causes)
  • Go Host Embedding (bidirectional marshaling, function reflection, struct unmarshaling, stdlib sandboxing, custom I/O)
  • Standard library (io, fs, math, time, json)
  • Compiler-style diagnostics (source excerpts, spans, hints, did-you-mean, stack traces)
  • Interrupts and deadlines for runaway scripts (Interrupt, RunFileContext, CallContext)
  • Interactive REPL (evie with multi-line input, persistent vm.Session state, and :help commands)
  • Package management ⏳

Documentation

For a comprehensive guide covering grammar, types, standard methods, and concurrency patterns, see:


Benchmarks

Across the 8-workload checksum-verified cross-language suite (median wall time of 5 runs after 1 warm-up on P-cores, process startup included). Every program must print the same checksum in every language, so a broken port fails instead of posting a time.

Languages you can embed in Go. Evie is the fastest on every benchmark:

BenchmarkEvieKavungopher-luaTengoStarlarkgoja (JS)Yaegi (Go)
classes30.7ms101.7ms161.0ms135.0ms217.5ms176.2ms1.58s
closures32.9ms79.6ms194.9ms124.3ms265.8ms188.3ms894.4ms
fib319.9ms1.26s1.65s1.65s4.53s2.44s20.45s
mandelbrot76.4ms300.1ms262.7ms532.4ms716.7ms1.13s459.8ms
matmul36.4ms118.0ms104.8ms192.8ms247.0ms246.6ms194.8ms
objects32.8ms63.7ms99.5ms105.5ms100.6ms130.5ms108.2ms
sieve58.1ms194.8ms203.5ms390.8ms413.2ms561.9ms342.8ms
strings37.3ms95.4ms269.5ms82.6ms59.9ms91.0ms87.8ms
Geomean53.2ms159.9ms229.8ms236.2ms321.9ms332.7ms550.4ms
vs Evie1.00x3.01x4.32x4.44x6.05x6.26x10.35x

Interpreters written in C and C++. Evie is slightly ahead of Lua 5.4 overall, though Lua still wins numeric loops and big dictionaries:

BenchmarkEvie (Go)Lua 5.4 (C)QuickJS (C)Python 3 (C)V8 --jitless (C++)Wren (C)
classes30.7ms36.3ms45.0ms67.9ms72.4ms52.9ms
closures32.9ms33.9ms47.7ms83.9ms78.3ms74.7ms
fib319.9ms414.6ms586.0ms848.2ms625.2ms894.6ms
mandelbrot76.4ms59.1ms142.7ms212.3ms158.7ms228.2ms
matmul36.4ms26.6ms58.8ms79.5ms91.5ms125.0ms
objects32.8ms21.9ms37.7ms49.6ms67.1ms58.2ms
sieve58.1ms51.5ms100.7ms126.7ms118.1ms147.2ms
strings37.3ms84.8ms40.6ms39.4ms77.0ms327.0ms
Geomean53.2ms54.4ms79.7ms109.2ms115.4ms151.8ms
vs Evie1.00x1.02x1.50x2.05x2.17x2.86x

Measured on an Intel i5-13400F under Windows 11 (.\benchmarks\compare\bench.ps1 -Runs 5 -Warmup 1 -Affinity 0x0FFF). >1.00x means Evie is faster.

The internal benchmark suite tracks 30 programs covering calls, closures, classes, method dispatch, host calls, strings, objects, errors and tasks; results/latest.md has the current numbers.


Setup & Quick Start

Prerequisites

Install or Build

# Install the CLI directly with Go
go install github.com/hxkhan/evie/evie@latest

# Or clone and build from source
git clone https://github.com/hxkhan/evie.git
cd evie
go build ./evie

# Start an interactive REPL (multi-line input, persistent state, :help for commands)
./evie

# Run an example
./evie ./examples/fib.ev

# Ctrl+C stops a running script with an error that shows where it was; press it again to exit at once

# Run code without a file; the standard packages it names are imported for it
./evie -e 'math.sqrt(2)'
./evie -e 'for w in "go evie go".fields() { io.println(w.toUpper()) }'

# Inspect compiled packages, globals, classes, slots, escapes and closure captures without running main
./evie -dump ./examples/captures.ev

# Report syntax and compile errors without running anything; exit status 1 when there are any
./evie -check ./examples/fib.ev

# Print the version (also -v), or the commit the binary was built from
./evie --version

Editor Support

The VS Code extension in extensions/vscode shows errors as you type, and offers go to definition, find all references, hover, completion and an outline. Its analysis is Evie's own compiler, compiled to WebAssembly, so it needs nothing else installed. Build it with npm install && npm run package in that folder, then install the .vsix. Other tools can use the analysis package directly.

Run Tests

go test ./...
go vet ./...

License

Licensed under the Apache License, Version 2.0. See NOTICE for attribution details.

Frequently Asked Questions

What is evie?

evie is a Embeddable Scripting Languages library for the Go programming language. Embeddable scripting language with classes, fibers and per-engine sandboxing

How do I install evie?

Install evie with the Go module system using `go get hxkhan/evie`. Check the repository for the current installation instructions.

What category does evie belong to?

evie is listed under Embeddable Scripting Languages, specifically Embeddable Scripting Languages.

← Back to Embeddable Scripting Languages