rhu1 / fgg

Mini prototype of FG/FGG/FGR in Go.
Creative Commons Attribution 4.0 International
98 stars 11 forks source link

README for fgg


This fgg package is a minimal and basic prototype of Featherweight Go and Featherweight Generic Go, as presented in:

Featherweight Go
Robert Griesemer, Raymond Hu, Wen Kokke, Julien Lange, Ian Lance Taylor,
Bernardo Toninho, Philip Wadler and Nobuko Yoshida

https://arxiv.org/abs/2005.11710

Currently, many aspects of the code are quite primitive, mainly for the convenience of quick experimentation alongside the above paper. For example, types/functions/variables are not well named, except for some correspondence with the formal definitions. The tool is also not particularly user-friendly:

We plan to improve some of this in the near future. Contact Raymond Hu for issues related to this repository.

See this Go blog post for information about the generics design draft by the Go team, and links to their generic-to-ordinary Go translation tool (including an online playground) based on that draft.

Featherweight-go-gen is tool that enumerates FGG programs and integrates with fgg for testing.


Summary.

This package includes:

Package organisation:

Use the main branch for the latest working version.

Syntax. The best source would be the formal grammars in the paper, or else see the above ANTLR grammars.


Install.

We assume a standard Go set up. That is:

You will also need the ANTLR v4 runtime for Go; e.g., see "Installing ANTLR v4" in this tutorial.

Clone the fgg repo into the src directory of your Go workspace, i.e., $GOPATH/src. It should end up located at src/github.com/rhu1/fgg. You can also use go get -- this should fetch ANTLR for you, but will report that it cannot find the parser packages (that's fine, we generate them in the next step).

Next, either copy over the pre-generated parser files and install by

or generate the parsers yourself using ANTLR and install by

Finally, do:

To test the install -- inside the github.com/rhu1/fgg directory, this command should work:

Afer installing, you can also use the resulting fgg binary directly instead of go run.

This package has been tested using Go version 1.11.5+ on:


A note on syntax.

Two points:


FG/FGG program syntax.

This package implements the grammars defined in the paper. E.g., a basic FGG program has the form:

package main;
/* Type and method decls -- semicolon separated */
func main () { _ = /* main has this specific form */ }

For testing purposes, the package supports this additional form:

package main;
import "fmt";  // Only fmt is allowed
/* Type and method decls -- semicolon separated */
func main () { fmt.Printf("%#v", /* This specific Printf, and only in main */ ) }

Notes:


Example run commands.

Warning: Type checking and nomono errors raise a panic -- basic error messages can be found at the top of the stack trace.

The following commands can be run from the github.com/rhu1/fgg directory.


Example Makefile tests.

The following commands assume make install, and that the resulting fgg binary is on the $PATH.

Running from the github.com/rhu1/fgg directory: