ginger/main.go

48 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"github.com/mediocregopher/ginger/lang"
"github.com/mediocregopher/ginger/vm"
)
func main() {
2017-02-12 18:44:10 +00:00
mkcmd := func(a lang.Atom, args ...lang.Term) lang.Tuple {
2017-02-15 22:41:14 +00:00
if len(args) == 1 {
return lang.Tuple{a, args[0]}
}
return lang.Tuple{a, lang.Tuple(args)}
2017-02-12 18:44:10 +00:00
}
mkint := func(i string) lang.Tuple {
return lang.Tuple{vm.Int, lang.Const(i)}
}
2017-02-15 22:41:14 +00:00
//foo := lang.Atom("foo")
//tt := []lang.Term{
// mkcmd(vm.Assign, foo, mkint("1")),
// mkcmd(vm.Add, mkcmd(vm.Tuple, mkcmd(vm.Var, foo), mkint("2"))),
//}
2017-02-15 22:41:14 +00:00
foo := lang.Atom("foo")
bar := lang.Atom("bar")
baz := lang.Atom("baz")
tt := []lang.Term{
mkcmd(vm.Assign, foo, mkcmd(vm.Tuple, mkint("1"), mkint("2"))),
mkcmd(vm.Assign, bar, mkcmd(vm.Add, mkcmd(vm.Var, foo))),
mkcmd(vm.Assign, baz, mkcmd(vm.Add, mkcmd(vm.Var, foo))),
mkcmd(vm.Add, mkcmd(vm.Tuple, mkcmd(vm.Var, bar), mkcmd(vm.Var, baz))),
}
mod, err := vm.Build(tt...)
if err != nil {
panic(err)
}
defer mod.Dispose()
mod.Dump()
out, err := mod.Run()
fmt.Printf("\n\n########\nout: %v %v\n", out, err)
}