Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling to Go? #43

Open
oubiwann opened this issue Feb 26, 2019 · 4 comments
Open

Compiling to Go? #43

oubiwann opened this issue Feb 26, 2019 · 4 comments
Labels

Comments

@oubiwann
Copy link

oubiwann commented Feb 26, 2019

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 ;-)

@glycerine
Copy link
Owner

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

@glycerine
Copy link
Owner

I'll leave this open as a question.

@gorakhargosh
Copy link

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

@glycerine
Copy link
Owner

How did Stalin? Bigloo? Gambit?

Only with alot of work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants