goloxx is a Go implementation of the Lox programming language interpreter based on clox from Crafting Interpreters.
- REPL and file execution
- Non global Scanner, Parser, Compiler and VM
- Loxx language
- Embeddable
Loxx is a superset of the Lox language (like C++ and C).
- Better
printstatement breakandcontinuestatements in loops- Ternary expression
cond ? then : else - Import modules
import myModule - Classes for all types
"abc".reverse() 0x,0oand0bnumber literals- Underscores in number literals
- Auto semicolons
- Escape sequences in strings
- Arrays
[0, "1", nil] - Maps
{"key": "value"} - Box type (userdata)
- Thread type functions (coroutine)
var(mutable) andconst(immutable) declarations
fun inc(i) {
if (i > 5) return false
else yield true
while (i < 5) i = i + yield i
if (i >= 5) return i
}
const seq = []
if (inc(1))
while (inc.status() != "done")
seq.append(resume inc with 1)
print seq // <array 1, 2, 3, 4, 5>import "github.com/kirochk4/goloxx/loxx"
events := make(map[string]*loxx.Closure)
clicks := 0
// create vm instance
var vm *loxx.VM = loxx.New(".")
// define native function
vm.Globals["addEvent"] = loxx.NewNativeFunction(
2, func(this loxx.Value, args []loxx.Value) (loxx.Value, error) {
name := args[0].(loxx.String)
fun := args[1].(*loxx.Closure)
events[string(name)] = fun
return loxx.Nil{}, nil
},
)
// define outer reference
vm.Globals["outer"] = loxx.Box{
"clicks": &clicks,
}
// load and interpret your script
source, _ := os.OpenFile("./your_script.loxx")
vm.Interpret(source)
// call added event function
vm.Call(events["onclick"])fun onClick() {
print "click"
// this will change outer value
outer.clicks = outer.clicks + 1
}
addEvent("onclick", onClick)Use this script to build loxx.
Use this script to run tests.
Use this script to run benchmarks.