The original version of LAIN used a tree walking interpreter and the current version uses a single pass bytecode compiler with a companion virtual machine. LAIN code, after being interpreted or compiled with the bytecode compiler / VM combo is eventually executed in Go.
Getting started
$ go get gitlab.com/thatzopoulos/lain
$ ./lain -h
Usage: lain [options] [<filename>]
-d enable debug mode
-e string
engine to use (eval or vm) (default "vm")
-i enable interactive mode
-v display version information
To execute a lain script simply pass the name to the interpreter:
$ ./lain ./scripts/hello.lain
Scripts can be made executable by adding a suitable shebang line:
$ cat hello.lain
#!/usr/bin/env lain
puts( "Hello, Lain!" );
Execution then works as you would expect:
$ chmod 755 hello.lain
$ ./hello.lain
Hello, Lain!
If a script is not passed into the interpreter, the user will be dropped into a REPL.
Language Details
Basic
s1 = "hello LAIN" // strings
i = 1000 // int
b = true // bool
a = [1, "2"] // array
h = {"name": "Lain", "OS": "Copland"} // hash
n = null // null
let add = fn(a, b) { a + b }; // function
let newAdder = fn(x) { fn(y) { x + y } }; // closure
Types
Type | Syntax | Comments
--------- | ----------------------------------------- | -----------------------
null | `null` |
bool | `true false` |
int | 123 | a signed 64-bit integer
str | `"" "foo" "foo"+"bar"` |
array | `[] [1,2]` |
hashes | `{"name": "Lain", "OS": "Copland"}` |
Infix Operators
Arithmetic
5 + 5;
5 - 5;
5 * 5;
5 / 5;
Other
5 > 5;
5 < 5;
5 == 5;
5 != 5;
Prefix operators
!
-
Builtins
len() // Return the number of characters in a string
puts() // Takes an unlimited number of args, prints each on a separate line and returns null
push(array,value) // Returns a new array with value pushed onto the end of array
rest(array) // Returns a new array with the first element of array removed
first(array) // Returns the first element of the array
last(array) // Returns the last element of the array
Other Notes
Parameters in functions are evaluated from left to right. LAIN cannot make assertions about the order of argument evaluation.
Compiling an identifier is done with a 16-bit opcode instruction, so LAIN is limited to a maximum of 65536 global bindings.
Similarly, due to the 2 byte size of the OpArray opcode, the max number of elements that an array can hold is capped at 655355.
Syntax Highlighting Plugins For Various Text Editors