glycerine/zygomys

Compiling to Go?

oubiwann opened this issue · 4 comments

I saw a comment in a ticket from a few years ago here:

In particular, you say "This supports the eventual aim of enabling trivial compile-down to actual Go code" ... was progress ever made on that?

I would love to be able to write Lisp, have it compiled to Go, with all the speed benefits ;-)

As would I. Unfortunately I quickly realized that was impractical. Lisp is too weakly typed, in contrast to Go's strong typing.

However there is a partial solution for critical parts, if you "hand compile", so to speak. Write the speed sensitive components with state in Go structs, and then wire them together with zygo scripts. zygo lets you call native Go methods on those structs. So when invoked, your compiled components run at native Go speed.

https://github.com/glycerine/zygomys/blob/master/tests/event.zy shows this (as does the main Snoopy and friends example https://github.com/glycerine/zygomys/blob/master/zygo/demo_go_structs.go).

Search for the central (togo) function and SexpToGoStructs inside the interpreter. These functions are what create the shadow structs (native Go structs) corresponding to your zygo records/hashmaps.

If you really need a full fledged lisp with JIT compiler, in a separate project, I made chez scheme bindings that let you invoke chez scheme from Go. Chez is way more built out that zygo, but the integration with Go is very light. At its best Chez is maybe 3x slower than compiled Go, in my quick and dirty benchmarks. That may well be good enough for some things.

https://github.com/go-interpreter/chezgo

I'll leave this open as a question.

How does ferret-lang.org manage to compile to C++?

How did Stalin? Bigloo? Gambit?

Only with alot of work.