Strada REPL & Scripting

Interactive shell, command-line evaluation, and script execution. File execution uses the bytecode VM (4-5x faster than Perl). The REPL uses the tree-walking backend. No C compiler needed at runtime.

Quick Start

# Interactive REPL (uses tree-walking backend)
strada --repl

# Evaluate code from the command line
strada-interp -e 'say("hello world")'

# Run a script file (uses bytecode VM by default)
strada-interp program.strada

# Use tree-walking backend instead
strada-interp --tree-walk program.strada
strada --script program.strada

Command-Line Evaluation

Use -e to evaluate Strada code directly. No func main() boilerplate needed — code is automatically wrapped:

# Expressions
strada-interp -e 'say(2 ** 10)'
1024

# Variables persist across -e flags
strada-interp -e 'my str $name = "Strada";' -e 'say("Hello, " . $name . "!")'
Hello, Strada!

# Map, grep, and functional operations
strada-interp -e 'say(join(", ", map { $_ * 2 } [1, 2, 3, 4, 5]))'
2, 4, 6, 8, 10

# Multi-statement programs
strada-interp -e 'my int $sum = 0;' \
              -e 'my int $i = 1;' \
              -e 'while ($i <= 100) { $sum = $sum + $i; $i = $i + 1; }' \
              -e 'say($sum)'
5050

Interactive REPL

The REPL supports readline with line editing, history, and arrow keys:

$ strada --repl
Strada Interpreter v0.3 (tree-walking REPL, VM file execution)
Type expressions or statements. Enter .help for commands, .quit to exit.

strada> my int $x = 42;
strada> $x * 2
84
strada> my array @nums = (1, 2, 3);
strada> push(@nums, 4);
strada> say(join(", ", @nums))
1, 2, 3, 4

Multi-line Input

The REPL automatically detects incomplete input (unbalanced braces, parentheses, or brackets) and prompts for continuation:

strada> func greet(str $name) void {
...         say("Hello, " . $name . "!");
...     }
strada> greet("World")
Hello, World!

REPL Commands

Command Description
.help Show help message
.vars List variables in scope with current values
.funcs List defined functions with parameter counts
.load FILE Load and execute code from a file (registers functions, skips main)
.clear Reset all state (variables, functions, enums)
.quit Exit the REPL

OOP in the REPL

Packages, inheritance, and method calls all work interactively:

strada> package Dog;
strada> has ro str $name (required);
strada> func bark(scalar $self) void { say($self->name() . " says woof!"); }

strada> my scalar $d = Dog::new("name", "Rex");
strada> $d->bark()
Rex says woof!

Script Execution

Run Strada programs without compilation. Scripts with a func main() entry point run just like compiled programs:

# Run a program
strada-interp program.strada

# With library search paths
strada-interp -L lib program.strada

# Via the strada command
strada --script program.strada

Shebang Scripts

Create executable scripts for direct execution:

#!/usr/bin/env strada-interp

func main() int {
    say("Hello from script!");
    return 0;
}
chmod +x myscript.strada
./myscript.strada

Interpreter vs Compiled

Feature Interpreter (VM) Compiled
Startup Instant (no compilation step) Compilation required
Execution speed Bytecode VM (4-5x faster than Perl 5.38) Native machine code
Requires C compiler No (except __C__ blocks) Yes (gcc)
__C__ blocks JIT-compiled and cached (bytecode VM); skipped (tree-walk fallback) Fully supported
async/await Not supported Fully supported
Best for Quick tasks, REPL, scripting Production, performance

Command-Line Options

Option Description
-e CODE Evaluate code string (multiple allowed, concatenated)
-L PATH Add library search path
-h, --help Show help message
--vm Use bytecode VM backend (default for file execution)
--tree-walk Use tree-walking backend (default for REPL)
-- Stop option parsing (remaining args passed to script)

JIT REPL (Alternative)

Strada also provides a JIT-based REPL (strada-jit) that compiles code to C at runtime using tcc or gcc. It offers faster execution for compute-heavy operations but requires a C compiler installed. Additional JIT-only features include .debug, .compiler, .memprof, and .funcprof commands.

# Explicitly start the JIT REPL
./tools/strada-jit

The interpreter REPL is the default. The JIT REPL is used as a fallback if the interpreter is not available.