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

A backend targeting the Go language #15

Open
np opened this issue Oct 26, 2015 · 0 comments
Open

A backend targeting the Go language #15

np opened this issue Oct 26, 2015 · 0 comments

Comments

@np
Copy link
Owner

np commented Oct 26, 2015

So far Ling has a backend to C. However supporting multiple target language would be interesting.

Go seems like a good target language which would strike a balance between modern and efficient.
While Go has a GC, it is claimed that "Go gives the programmer considerable control over memory layout and allocation, much more than is typical in garbage-collected languages." which seems just about what we need.

The task would be to follow what has been done for C.

Here is a rough roadmap:

AST/Printer for Go

While there is a package on hackage it seems unmaintained and incomplete.
Moreover we do not need a something complete as we target a small subset anyway (at least at first).
So I would recommend writing down the grammar for the subset we are interested in using BNFC.

Ling.Compile.C

This module converts a sequentialized Ling program to C, what matters the most are the following parts:

  • Ling terms gets translated to Go expressions (starting with function application and literals)
  • Ling actions gets translated to Go statments (starting with send/recv, then new, then split)
  • Ling processes defined at top-level gets translated to Go functions (no return type, at first only basic sessions such ?Int and !Int)
  • Ling sessions and types gets translated to Go types (atomic types such as Int and Double, then arrays of those)

Let's keep in mind that the processes are sequentialized at that point. So new(c:S,d) declares a variable l of a type translated from S and we now track c and d has being associated to l.
The command send c t assigns the result of the expression translated from t to the location associated to c. The command recv c (x : A) assigns the variable associated to c to a local variable derived from x.

@np np added the enhancement label Oct 26, 2015
@diakopter diakopter removed their assignment Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants