├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── cmd
    ├── fg2fgg
    │   └── main.go
    ├── fggi
    │   └── main.go
    ├── fggsim
    │   └── main.go
    └── fgi
    │   └── main.go
├── copyright.txt
├── examples
    ├── fg
    │   ├── expression
    │   │   └── expression-fg.go
    │   ├── hello
    │   │   ├── fmtprintf
    │   │   │   └── fmtprintf.go
    │   │   └── hello.go
    │   ├── misc
    │   │   ├── booleans
    │   │   │   └── booleans.go
    │   │   ├── compose
    │   │   │   └── compose.go
    │   │   ├── equal
    │   │   │   └── equal.go
    │   │   ├── incr
    │   │   │   └── incr.go
    │   │   ├── map
    │   │   │   └── map.go
    │   │   ├── not
    │   │   │   └── not.go
    │   │   ├── rose
    │   │   │   └── rose.go
    │   │   └── whoopsie
    │   │   │   └── whoopsie.fg
    │   ├── oopsla20
    │   │   ├── fig1
    │   │   │   └── functions.go
    │   │   ├── fig2
    │   │   │   └── equality.go
    │   │   ├── fig3
    │   │   │   └── lists.go
    │   │   └── fig9
    │   │   │   └── monom.go
    │   └── stupidcast
    │   │   └── stupidcast.go
    ├── fgg
    │   ├── expression
    │   │   └── expression-fgg.fgg
    │   ├── hello
    │   │   ├── fmtprintf
    │   │   │   └── fmtprintf.fgg
    │   │   └── hello.fgg
    │   ├── misc
    │   │   ├── booleans
    │   │   │   └── booleans.fgg
    │   │   ├── compose
    │   │   │   └── compose.fgg
    │   │   ├── graph
    │   │   │   └── graph.fgg
    │   │   ├── irregular
    │   │   │   └── irregular.fgg
    │   │   ├── map
    │   │   │   └── map.fgg
    │   │   └── monomorph
    │   │   │   └── monomorph.fgg
    │   ├── monom
    │   │   ├── box
    │   │   │   ├── box.fgg
    │   │   │   └── box2.fgg
    │   │   └── misc
    │   │   │   ├── ifacebox.fgg
    │   │   │   ├── mono-ko
    │   │   │       ├── incompleteness-subtyping.fgg
    │   │   │       ├── monom-imp.fgg
    │   │   │       ├── mutual-poly-rec.fgg
    │   │   │       ├── mutual-rec-iface.fgg
    │   │   │       ├── nested-fix.fgg
    │   │   │       └── two-type-param.fgg
    │   │   │   ├── mono-ok
    │   │   │       ├── Dispatcher.fgg
    │   │   │       ├── Parameterised-Map.fgg
    │   │   │       ├── alternate.fgg
    │   │   │       ├── contamination.fgg
    │   │   │       ├── i-closure-bad.fgg
    │   │   │       ├── i-closure.fgg
    │   │   │       ├── iface-embedding-simple.fgg
    │   │   │       ├── iface-embedding.fgg
    │   │   │       ├── meth-clash.fgg
    │   │   │       ├── no-compo.fgg
    │   │   │       ├── one-pass-prob.fgg
    │   │   │       ├── param-meth-cast.fgg
    │   │   │       ├── poly-rec-iface.fgg
    │   │   │       ├── polyrec
    │   │   │       │   └── lasso.fgg
    │   │   │       ├── rcver-iface.fgg
    │   │   │       └── struct-poly-rec.fgg
    │   │   │   └── todo
    │   │   │       ├── ifacebox-nomethparam.fgg
    │   │   │       ├── nested.fgg
    │   │   │       ├── struct-poly-rec-variant.fgg
    │   │   │       └── struct-prob.fgg
    │   ├── oopsla20
    │   │   ├── fig10
    │   │   │   └── nomono.fgg
    │   │   ├── fig19
    │   │   │   └── dispatcher.fgg
    │   │   ├── fig4
    │   │   │   └── functions.fgg
    │   │   ├── fig5
    │   │   │   └── equality.fgg
    │   │   ├── fig6
    │   │   │   └── lists.fgg
    │   │   ├── fig7
    │   │   │   └── graph.fgg
    │   │   └── fig8
    │   │   │   └── expression.fgg
    │   └── stupidcast
    │   │   └── stupidcast.fgg
    └── fgr
    │   └── oblit
    │       ├── booleans
    │           └── booleans.fgr
    │       ├── box
    │           ├── box.fgr
    │           └── box2.fgr
    │       ├── compose
    │           └── compose.fgr
    │       ├── graph
    │           └── graph.fgr
    │       ├── irregular
    │           └── irregular.fgr
    │       ├── map
    │           └── map.fgr
    │       ├── misc
    │           ├── ifacebox-nomethparam.fgr
    │           └── ifacebox.fgr
    │       └── monomorph
    │           └── monomorph.fgr
├── internal
    ├── base
    │   ├── base.go
    │   └── testutils
    │   │   └── testutil.go
    ├── fg
    │   ├── fg.go
    │   ├── fg_aux.go
    │   ├── fg_decls.go
    │   ├── fg_decls_test.go
    │   ├── fg_exprs.go
    │   ├── fg_test.go
    │   └── fg_util.go
    ├── fgg
    │   ├── fg_wrapping.go
    │   ├── fgg.go
    │   ├── fgg_aux.go
    │   ├── fgg_conv.go
    │   ├── fgg_decls.go
    │   ├── fgg_exprs.go
    │   ├── fgg_ismonom.go
    │   ├── fgg_monom.go
    │   ├── fgg_omega.go
    │   ├── fgg_test.go
    │   └── fgg_util.go
    ├── fgr
    │   ├── fgr.go
    │   ├── fgr_aux.go
    │   ├── fgr_decls.go
    │   ├── fgr_exprs.go
    │   ├── fgr_oblit.go
    │   ├── fgr_test.go
    │   └── fgr_translation.go
    ├── frontend
    │   ├── Frontend.go
    │   ├── fggi.go
    │   ├── fggsim.go
    │   └── fgi.go
    └── parser
    │   ├── fg_adaptor.go
    │   ├── fgg_adaptor.go
    │   └── util
    │       └── util.go
├── main.go
└── parser
    ├── FG.g4
    ├── FGG.g4
    └── pregen
        ├── fg
            └── parser
            │   ├── FG.interp
            │   ├── FG.tokens
            │   ├── FGLexer.interp
            │   ├── FGLexer.tokens
            │   ├── fg_base_listener.go
            │   ├── fg_lexer.go
            │   ├── fg_listener.go
            │   └── fg_parser.go
        └── fgg
            └── parser
                ├── FGG.interp
                ├── FGG.tokens
                ├── FGGLexer.interp
                ├── FGGLexer.tokens
                ├── fgg_base_listener.go
                ├── fgg_lexer.go
                ├── fgg_listener.go
                └── fgg_parser.go
/.gitignore:
--------------------------------------------------------------------------------
1 | parser/fg
2 | parser/fgg
3 | bin/
4 | *.swp
5 | _sess.vim
6 | _scratch.vim
7 | .vscode
8 | _sess.code-workspace
9 | 
--------------------------------------------------------------------------------
/cmd/fg2fgg/main.go:
--------------------------------------------------------------------------------
 1 | package main
 2 | 
 3 | import (
 4 | 	"flag"
 5 | 	"fmt"
 6 | 	"io/ioutil"
 7 | 	"log"
 8 | 	"os"
 9 | 
10 | 	"github.com/rhu1/fgg/internal/fg"
11 | 	"github.com/rhu1/fgg/internal/fgg"
12 | 	"github.com/rhu1/fgg/internal/parser"
13 | )
14 | 
15 | func main() {
16 | 	flag.Parse()
17 | 	if flag.NArg() < 1 {
18 | 		fmt.Fprintln(os.Stderr, "not enough arguments (expected FGG file path)")
19 | 		os.Exit(1)
20 | 	}
21 | 	b, err := ioutil.ReadFile(flag.Arg(0))
22 | 	if err != nil {
23 | 		log.Fatal(err)
24 | 	}
25 | 	fgAdaptor := new(parser.FGAdaptor)
26 | 	fgProg := fgAdaptor.Parse(false, string(b))
27 | 	fggProg, err := fgg.FromFG(fgProg.(fg.FGProgram))
28 | 	if err != nil {
29 | 		log.Fatalf("cannot convert from FG program: %v", err)
30 | 	}
31 | 	fmt.Println(fggProg.String())
32 | }
33 | 
--------------------------------------------------------------------------------
/cmd/fggi/main.go:
--------------------------------------------------------------------------------
 1 | /* See copyright.txt for copyright.
 2 |  */
 3 | 
 4 | package main
 5 | 
 6 | import (
 7 | 	"flag"
 8 | 	"fmt"
 9 | 	"os"
10 | 
11 | 	"github.com/rhu1/fgg/internal/frontend"
12 | )
13 | 
14 | // Command line flags/parameters
15 | var (
16 | 	monomc string // output filename of monomorphised FGG; "--" for stdout -- Go output (no angle bracks)
17 | 
18 | 	oblitc         string // output filename of FGR compilation via oblit; "--" for stdout
19 | 	oblitEvalSteps int    // TODO: A concrete FGR syntax, for oblitc to output
20 | 
21 | 	inlineSrc   string // use content of this as source
22 | 	strictParse bool   // use strict parsing mode
23 | 
24 | 	evalSteps int  // number of steps to evaluate
25 | 	verbose   bool // verbose mode
26 | 	printf    bool // use ToGoString for output (e.g., "main." type prefix)
27 | )
28 | 
29 | func init() {
30 | 
31 | 	flag.StringVar(&monomc, "monomc", "", // Empty string for "false"
32 | 		"monomorphise FGG source to (Go-compatible) FG, i.e., no angle bracks (ignored if -fgg not set)\n"+
33 | 			"specify '--' to print to stdout")
34 | 
35 | 	// Erasure(?) by translation based on type reps -- FGG vs. FGR?
36 | 	flag.StringVar(&oblitc, "oblitc", "", // Empty string for "false"
37 | 		"[WIP] compile FGG source to FGR (ignored if -fgg not set)\n"+
38 | 			"specify '--' to print to stdout")
39 | 	flag.IntVar(&oblitEvalSteps, "oblit-eval", -2,
40 | 		" N ⇒ evaluate N (≥ 0) steps; or\n-1 ⇒ evaluate to value (or panic)")
41 | 
42 | 	// Parsing options
43 | 	flag.StringVar(&inlineSrc, "inline", "",
44 | 		`-inline="[FG/FGG src]", use inline input as source`)
45 | 	flag.BoolVar(&strictParse, "strict", true,
46 | 		"strict parsing (default true, means don't attempt recovery on parsing errors)")
47 | 
48 | 	flag.IntVar(&evalSteps, "eval", frontend.NO_EVAL,
49 | 		" N ⇒ evaluate N (≥ 0) steps; or\n-1 ⇒ evaluate to value (or panic)")
50 | 	flag.BoolVar(&verbose, "v", false,
51 | 		"enable verbose printing")
52 | 	frontend.Verbose = verbose
53 | 	flag.BoolVar(&printf, "printf", false,
54 | 		"use Go style output type name prefixes")
55 | }
56 | 
57 | var usage = func() {
58 | 	fmt.Fprintf(os.Stderr, `Usage:
59 | 
60 | 	fgg [options] path/to/file.fgg
61 | 	fgg [options] -inline "package main; type ...; func main() { ... }"
62 | 
63 | Options:
64 | 
65 | `)
66 | 	flag.PrintDefaults()
67 | 	os.Exit(1)
68 | }
69 | 
70 | func main() {
71 | 	flag.Usage = usage
72 | 	flag.Parse()
73 | 	frontend.OblitEvalSteps = oblitEvalSteps
74 | 
75 | 	// Determine source
76 | 	var src string
77 | 	switch {
78 | 	case inlineSrc != "": // -inline overrules src file
79 | 		src = inlineSrc
80 | 	default:
81 | 		if flag.NArg() < 1 {
82 | 			fmt.Fprintln(os.Stderr, "Input error: need a source .go file (or an -inline program)")
83 | 			flag.Usage()
84 | 		}
85 | 		src = frontend.ReadSourceFile(flag.Arg(0))
86 | 	}
87 | 
88 | 	frontend.FGGmain(verbose, src, strictParse, evalSteps, printf, false, monomc, oblitc)
89 | }
90 | 
--------------------------------------------------------------------------------
/cmd/fggsim/main.go:
--------------------------------------------------------------------------------
 1 | /* See copyright.txt for copyright.
 2 |  */
 3 | 
 4 | package main
 5 | 
 6 | import (
 7 | 	"flag"
 8 | 	"fmt"
 9 | 	"os"
10 | 
11 | 	"github.com/rhu1/fgg/internal/frontend"
12 | )
13 | 
14 | // Command line parameters/flags
15 | var (
16 | 	monomtest bool
17 | 	oblittest bool
18 | 
19 | 	inlineSrc   string // use content of this as source
20 | 	strictParse bool   // use strict parsing mode
21 | 
22 | 	evalSteps int  // number of steps to evaluate
23 | 	verbose   bool // verbose mode
24 | 	printf    bool // use ToGoString for output (e.g., "main." type prefix)
25 | )
26 | 
27 | func init() {
28 | 	flag.BoolVar(&monomtest, "monom", false, `Test monom correctness`)
29 | 	flag.BoolVar(&oblittest, "oblit", false, `[WIP] Test oblit correctness`)
30 | 
31 | 	// Parsing options
32 | 	flag.StringVar(&inlineSrc, "inline", "",
33 | 		`-inline="[FG/FGG src]", use inline input as source`)
34 | 	flag.BoolVar(&strictParse, "strict", true,
35 | 		"strict parsing (default true, means don't attempt recovery on parsing errors)")
36 | 
37 | 	flag.IntVar(&evalSteps, "eval", frontend.NO_EVAL,
38 | 		" N ⇒ evaluate N (≥ 0) steps; or\n-1 ⇒ evaluate to value (or panic)")
39 | 	flag.BoolVar(&verbose, "v", false,
40 | 		"enable verbose printing")
41 | 	frontend.Verbose = verbose
42 | 	flag.BoolVar(&printf, "printf", false,
43 | 		"use Go style output type name prefixes")
44 | }
45 | 
46 | var usage = func() {
47 | 	fmt.Fprintf(os.Stderr, `Usage:
48 | 
49 | 	fggsim [options] path/to/file.fg
50 | 	fggsim [options] -inline "package main; type ...; func main() { ... }"
51 | 
52 | Options:
53 | 
54 | `)
55 | 	flag.PrintDefaults()
56 | 	os.Exit(1)
57 | }
58 | 
59 | func main() {
60 | 	flag.Usage = usage
61 | 	flag.Parse()
62 | 
63 | 	// Determine source
64 | 	var src string
65 | 	switch {
66 | 	case inlineSrc != "": // -inline overrules src file
67 | 		src = inlineSrc
68 | 	default:
69 | 		if flag.NArg() < 1 {
70 | 			fmt.Fprintln(os.Stderr, "Input error: need a source .go file (or an -inline program)")
71 | 			flag.Usage()
72 | 		}
73 | 		src = frontend.ReadSourceFile(flag.Arg(0))
74 | 	}
75 | 
76 | 	// Currently hacked
77 | 	if monomtest {
78 | 		frontend.TestMonom(printf, verbose, src, evalSteps)
79 | 	}
80 | 	if oblittest {
81 | 		frontend.TestOblit(verbose, src, evalSteps)
82 | 		//testOblit(verbose, src, evalSteps)  // TODO: "weak" oblit simulation
83 | 	}
84 | }
85 | 
--------------------------------------------------------------------------------
/cmd/fgi/main.go:
--------------------------------------------------------------------------------
 1 | /* See copyright.txt for copyright.
 2 |  */
 3 | 
 4 | package main
 5 | 
 6 | import (
 7 | 	"flag"
 8 | 	"fmt"
 9 | 	"os"
10 | 
11 | 	"github.com/rhu1/fgg/internal/frontend"
12 | )
13 | 
14 | // Command line flags/parameters
15 | var (
16 | 	inlineSrc   string // use content of this as source
17 | 	strictParse bool   // use strict parsing mode
18 | 
19 | 	evalSteps int  // number of steps to evaluate
20 | 	verbose   bool // verbose mode
21 | 	printf    bool // use ToGoString for output (e.g., "main." type prefix)
22 | )
23 | 
24 | func init() {
25 | 	flag.StringVar(&inlineSrc, "inline", "",
26 | 		`-inline="[FG src]", use inline input as source`)
27 | 	flag.BoolVar(&strictParse, "strict", true,
28 | 		"strict parsing (default true, means don't attempt recovery on parsing errors)")
29 | 
30 | 	flag.IntVar(&evalSteps, "eval", frontend.NO_EVAL,
31 | 		" N ⇒ evaluate N (≥ 0) steps; or\n-1 ⇒ evaluate to value (or panic)")
32 | 	flag.BoolVar(&verbose, "v", false,
33 | 		"enable verbose printing")
34 | 	frontend.Verbose = verbose
35 | 	flag.BoolVar(&printf, "printf", false,
36 | 		"use Go style output type name prefixes")
37 | }
38 | 
39 | var usage = func() {
40 | 	fmt.Fprintf(os.Stderr, `Usage:
41 | 
42 | 	fgg [options] path/to/file.fg
43 | 	fgg [options] -inline "package main; type ...; func main() { ... }"
44 | 
45 | Options:
46 | 
47 | `)
48 | 	flag.PrintDefaults()
49 | 	os.Exit(1)
50 | }
51 | 
52 | func main() {
53 | 	flag.Usage = usage
54 | 	flag.Parse()
55 | 
56 | 	// Determine source
57 | 	var src string
58 | 	switch {
59 | 	case inlineSrc != "": // -inline overrules src file
60 | 		src = inlineSrc
61 | 	default:
62 | 		if flag.NArg() < 1 {
63 | 			fmt.Fprintln(os.Stderr, "Input error: need a source .go file (or an -inline program)")
64 | 			flag.Usage()
65 | 		}
66 | 		src = frontend.ReadSourceFile(flag.Arg(0))
67 | 	}
68 | 
69 | 	frontend.FGmain(verbose, src, strictParse, evalSteps, printf)
70 | }
71 | 
--------------------------------------------------------------------------------
/copyright.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) Raymond Hu, Julien Lange, Bernardo Toninho, and Philip Wadler.
2 | 
3 | fgg is licensed under a Creative Commons Attribution 4.0
4 | International License.
5 | 
6 | You should have received a copy of the license along with this
7 | work. If not, see .
8 | 
--------------------------------------------------------------------------------
/examples/fg/expression/expression-fg.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -eval=-1 -v fg/examples/expression/expression-fg.go
 2 | 
 3 | // An almost-solution to the Expression Problem in FG.
 4 | 
 5 | // 1. Define Eval() on Con and Plus
 6 | // 2. Define String() on Con and Plus
 7 | // 3. Define Eval() on Neg.
 8 | // 4. Define String() on Neg.
 9 | // Each of 1, 2, 3, 4 should be doable without
10 | // altering the answers to the others.
11 | 
12 | // It is not quite a solution, because one wants
13 | // to first define Eval() and only later define String(),
14 | // and to do so *without* altering the Expr interface
15 | // (the line in Expr marked "// 2").
16 | 
17 | package main
18 | 
19 | import "fmt"
20 | 
21 | // 1
22 | 
23 | // TODO
24 | type Int interface{ isInt() Int }
25 | type One struct{}
26 | 
27 | func (x0 One) isInt() Int { return x0 }
28 | 
29 | type Expr interface {
30 | 	Eval() Int
31 | 	String() string // 2  // TODO: WF
32 | }
33 | 
34 | type Con struct {
35 | 	value Int
36 | }
37 | 
38 | func (e Con) Eval() Int {
39 | 	return e.value
40 | }
41 | 
42 | type Add struct {
43 | 	left  Expr
44 | 	right Expr
45 | }
46 | 
47 | func (e Add) Eval() Int {
48 | 	return e.left.Eval() // + e.right.Eval()  // TODO
49 | }
50 | 
51 | // 2
52 | 
53 | func (e Con) String() string {
54 | 	return fmt.Sprintf("%v", e.value)
55 | }
56 | 
57 | func (e Add) String() string {
58 | 	return fmt.Sprintf("(%v+%v)", e.left.String(), e.right.String())
59 | }
60 | 
61 | // 3
62 | 
63 | type Neg struct {
64 | 	expr Expr
65 | }
66 | 
67 | func (e Neg) Eval() Int {
68 | 	//return - e.expr.Eval()
69 | 	return One{} // TODO
70 | }
71 | 
72 | // 4
73 | 
74 | func (e Neg) String() string {
75 | 	return fmt.Sprintf("-%v", e.expr.String())
76 | }
77 | 
78 | func main() {
79 | 	_ = Add{Con{One{}}, Con{One{}}}.String()
80 | }
81 | 
--------------------------------------------------------------------------------
/examples/fg/hello/fmtprintf/fmtprintf.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -v -eval=10 fg/examples/hello/fmtprintf.go
 2 | // Cf.
 3 | //$ go run github.com/rhu1/fgg/fg/examples/hello
 4 | 
 5 | // N.B. FG (or at least this implementation) is intended to be white-space *insensitive*.
 6 | // (E.g., this program could be written all on one line.)
 7 | // So the ';' are mandatory -- cannot replace by newlines (as in actual Go).
 8 | // (Newlines and other whitespace may be freely added, though.)
 9 | package main;
10 | import "fmt";
11 | type World struct{};
12 | func (x0 World) hello() World { return x0.hello() };
13 | func main() {
14 | 	fmt.Printf("%#v", World{}.hello())
15 | }
16 | 
--------------------------------------------------------------------------------
/examples/fg/hello/hello.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -v -eval=10 fg/examples/hello/hello.go
 2 | // Cf.
 3 | //$ go run github.com/rhu1/fgg/fg/examples/hello
 4 | 
 5 | // N.B. FG (or at least this implementation) is intended to be white-space *insensitive*.
 6 | // (E.g., this program could be written all on one line.)
 7 | // So the ';' are mandatory -- cannot replace by newlines (as in actual Go).
 8 | // (Newlines and other whitespace may be freely added, though.)
 9 | package main;
10 | //import "fmt";
11 | type World struct{};
12 | func (x0 World) hello() World { return x0.hello() };
13 | func main() {
14 | 	_ = World{}.hello()
15 | 	//fmt.Printf("%#v", World{}.hello())
16 | }
17 | 
--------------------------------------------------------------------------------
/examples/fg/misc/booleans/booleans.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -v -eval=7 fg/examples/misc/booleans/booleans.go
 2 | // Cf.
 3 | //$ go run github.com/rhu1/fgg/fg/examples/misc/booleans
 4 | 
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | /* Base decls: Any, Booleans */
10 | 
11 | type Any interface {};
12 | 
13 | /* Booleans */
14 | 
15 | type Eq interface {
16 | 	Equal(that Any) Bool
17 | };
18 | type Bool interface {
19 | 	Not() Bool;
20 | 	Equal(that Any) Bool;
21 | 	Cond(br Branches) Any
22 | };
23 | type Branches interface {
24 | 	IfTT() Any;
25 | 	IfFF() Any
26 | };
27 | type TT struct{};
28 | type FF struct{};
29 | 
30 | func (this TT) Not() Bool { return FF{} };
31 | func (this FF) Not() Bool { return TT{} };
32 | func (this TT) Equal(that Any) Bool { return that.(Bool) };
33 | func (this FF) Equal(that Any) Bool { return that.(Bool).Not() };
34 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
35 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
36 | 
37 | /* Example code */
38 | 
39 | type exampleBr struct {
40 | 	x t;
41 | 	y t
42 | };
43 | func (this exampleBr) IfTT() Any {
44 | 	return this.x.m(this.y)
45 | };
46 | func (this exampleBr) IfFF() Any {
47 | 	return this.x
48 | };
49 | 
50 | type t struct { };
51 | func (x0 t) m(x1 t) t { return x1 };
52 | 
53 | type Ex struct {};
54 | func (d Ex) example(b Bool, x t, y t) t {
55 | 	return b.Cond(exampleBr{x,y}).(t). // Main example, .(t)
56 | 			m(t{}) // Extra
57 | };
58 | func main() {
59 | 	//_ = Ex{}.example(TT{}, t{}, t{})
60 | 	fmt.Printf("%#v", Ex{}.example(TT{}, t{}, t{}))
61 | }
62 | 
--------------------------------------------------------------------------------
/examples/fg/misc/compose/compose.go:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -v -eval=46 fg/examples/misc/compose/compose.go
  2 | // Cf.
  3 | //$ go run github.com/rhu1/fgg/fg/examples/misc/compose
  4 | 
  5 | package main;
  6 | 
  7 | import "fmt";
  8 | 
  9 | /* Base decls: Any, Booleans, Nautrals, Functions, Lists */
 10 | 
 11 | type Any interface {};
 12 | 
 13 | /* Booleans */
 14 | 
 15 | type Eq interface {
 16 | 	Equal(that Any) Bool
 17 | };
 18 | type Bool interface {
 19 | 	Not() Bool;
 20 | 	Equal(that Any) Bool;
 21 | 	Cond(br Branches) Any
 22 | };
 23 | type Branches interface {
 24 | 	IfTT() Any;
 25 | 	IfFF() Any
 26 | };
 27 | type TT struct{};
 28 | type FF struct{};
 29 | 
 30 | func (this TT) Not() Bool { return FF{} };
 31 | func (this FF) Not() Bool { return TT{} };
 32 | func (this TT) Equal(that Any) Bool { return that.(Bool) };
 33 | func (this FF) Equal(that Any) Bool { return that.(Bool).Not() };
 34 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
 35 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
 36 | 
 37 | /* Naturals */
 38 | 
 39 | type Nat interface {
 40 | 	Add(n Nat) Nat;
 41 | 	Equal(n Any) Bool;
 42 | 	equalZero() Bool;
 43 | 	equalSucc(m Nat) Bool
 44 | };
 45 | type Zero struct {};
 46 | type Succ struct {pred Nat};
 47 | func (m Zero) Add (n Nat) Nat { return n };
 48 | func (m Succ) Add (n Nat) Nat { return Succ{m.pred.Add(n)} };
 49 | func (m Zero) Equal(n Any) Bool { return n.(Nat).equalZero() };
 50 | func (m Succ) Equal(n Any) Bool { return n.(Nat).equalSucc(m.pred) };
 51 | func (n Zero) equalZero() Bool { return TT{} };
 52 | func (n Succ) equalZero() Bool { return FF{} };
 53 | func (n Zero) equalSucc(m Nat) Bool { return FF{} };
 54 | func (n Succ) equalSucc(m Nat) Bool { return m.Equal(n.pred) };
 55 | 
 56 | /* Functions */
 57 | 
 58 | type Func interface {
 59 | 	Apply(x Any) Any
 60 | };
 61 | type incr struct {
 62 | 	n Nat
 63 | };
 64 | func (this incr) Apply(x Any) Any { return x.(Nat).Add(this.n) };
 65 | type not struct {};
 66 | func (this not) Apply(x Any) Any { return x.(Bool).Not() };
 67 | type compose struct {
 68 | 	f Func;
 69 | 	g Func
 70 | };
 71 | func (this compose) Apply(x Any) Any { return this.g.Apply(this.f.Apply(x)) };
 72 | 
 73 | /* Lists */
 74 | 
 75 | type List interface {
 76 | 	Map(f Func) List;
 77 | 	Member(x Eq) Bool
 78 | };
 79 | type Nil struct {};
 80 | type Cons struct {
 81 | 	head Any;
 82 | 	tail List
 83 | };
 84 | func (xs Nil) Map(f Func) List { return Nil{} };
 85 | func (xs Cons) Map(f Func) List { return Cons{f.Apply(xs.head), xs.tail.Map(f)} };
 86 | type memberBr struct {
 87 | 	xs Cons;
 88 | 	x Eq
 89 | };
 90 | func (this memberBr) IfTT() Any { return TT{} };
 91 | func (this memberBr) IfFF() Any { return this.xs.tail.Member(this.x) };
 92 | func (xs Nil) Member(x Eq) Bool { return FF{} };
 93 | func (xs Cons) Member(x Eq) Bool { return x.Equal(xs.head).Cond(memberBr{xs,x}).(Bool) };
 94 | 
 95 | /* Example code */
 96 | 
 97 | type D struct {};
 98 | func (d D) _1() Nat { return Succ{Zero{}} };
 99 | func (d D) _2() Nat { return D{}._1().Add(D{}._1()) };
100 | func (d D) _3() Nat { return D{}._2().Add(D{}._1()) };
101 | 
102 | func main() {
103 | 	// Submission version: compose{incr{1},incr{2}}.Apply(3).(Nat)
104 | 	//_ = compose{incr{Succ{Zero{}}},incr{Succ{Succ{Zero{}}}}}.Apply(Succ{Succ{Succ{Zero{}}}}).(Nat) // -eval=26
105 | 	/*_ = compose{incr{D{}._1()}, incr{D{}._2()}}.Apply(D{}._3()).
106 | 				(Nat). // Main example (assertion necessary) // -eval=46
107 | 				Add(Zero{}) // Extra*/
108 | 
109 | 	fmt.Printf("%#v", compose{incr{D{}._1()}, incr{D{}._2()}}.Apply(D{}._3()).
110 | 				(Nat). // Main example (assertion necessary) // -eval=46
111 | 				Add(Zero{}))
112 | 
113 | 	// Also: _ = incr{2}.Apply(3).(Nat)
114 | }
115 | 
--------------------------------------------------------------------------------
/examples/fg/misc/equal/equal.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -v -eval=3 fg/examples/misc/equal/equal.go
 2 | // Cf.
 3 | // Cf.
 4 | //$ go run github.com/rhu1/fgg/fg/examples/misc/equals
 5 | 
 6 | package main;
 7 | 
 8 | import "fmt";
 9 | 
10 | type I1 interface { Equal(that Any) Bool };
11 | type I2 interface { Equal(n Any) Bool };
12 | 
13 | type T struct {};
14 | func (t T) Equal(foo Any) Bool { return Bool{} };
15 | type Any interface {};
16 | type ToAny struct { any Any };
17 | type Bool struct {};  // Just for the purposes of this example
18 | 
19 | func main() {
20 | 	//_ = ToAny{T{}}.any.(I1).(I2)
21 | 	fmt.Printf("%#v", ToAny{T{}}.any.(I1).(I2))
22 | }
23 | 
--------------------------------------------------------------------------------
/examples/fg/misc/incr/incr.go:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -v -eval=30 fg/examples/misc/incr/incr.go
  2 | // Cf.
  3 | //$ go run github.com/rhu1/fgg/fg/examples/misc/incr
  4 | 
  5 | package main;
  6 | 
  7 | import "fmt";
  8 | 
  9 | /* Base decls: Any, Booleans, Nautrals, Functions, Lists */
 10 | 
 11 | type Any interface {};
 12 | 
 13 | /* Booleans */
 14 | 
 15 | type Eq interface {
 16 | 	Equal(that Any) Bool
 17 | };
 18 | type Bool interface {
 19 | 	Not() Bool;
 20 | 	Equal(that Any) Bool;
 21 | 	Cond(br Branches) Any
 22 | };
 23 | type Branches interface {
 24 | 	IfTT() Any;
 25 | 	IfFF() Any
 26 | };
 27 | type TT struct{};
 28 | type FF struct{};
 29 | 
 30 | func (this TT) Not() Bool { return FF{} };
 31 | func (this FF) Not() Bool { return TT{} };
 32 | func (this TT) Equal(that Any) Bool { return that.(Bool) };
 33 | func (this FF) Equal(that Any) Bool { return that.(Bool).Not() };
 34 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
 35 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
 36 | 
 37 | /* Naturals */
 38 | 
 39 | type Nat interface {
 40 | 	Add(n Nat) Nat;
 41 | 	Equal(n Any) Bool;
 42 | 	equalZero() Bool;
 43 | 	equalSucc(m Nat) Bool
 44 | };
 45 | type Zero struct {};
 46 | type Succ struct {pred Nat};
 47 | func (m Zero) Add (n Nat) Nat { return n };
 48 | func (m Succ) Add (n Nat) Nat { return Succ{m.pred.Add(n)} };
 49 | func (m Zero) Equal(n Any) Bool { return n.(Nat).equalZero() };
 50 | func (m Succ) Equal(n Any) Bool { return n.(Nat).equalSucc(m.pred) };
 51 | func (n Zero) equalZero() Bool { return TT{} };
 52 | func (n Succ) equalZero() Bool { return FF{} };
 53 | func (n Zero) equalSucc(m Nat) Bool { return FF{} };
 54 | func (n Succ) equalSucc(m Nat) Bool { return m.Equal(n.pred) };
 55 | 
 56 | /* Functions */
 57 | 
 58 | type Func interface {
 59 | 	Apply(x Any) Any
 60 | };
 61 | type incr struct {
 62 | 	n Nat
 63 | };
 64 | func (this incr) Apply(x Any) Any { return x.(Nat).Add(this.n) };
 65 | type not struct {};
 66 | func (this not) Apply(x Any) Any { return x.(Bool).Not() };
 67 | type compose struct {
 68 | 	f Func;
 69 | 	g Func
 70 | };
 71 | func (this compose) Apply(x Any) Any { return this.g.Apply(this.f.Apply(x)) };
 72 | 
 73 | /* Lists */
 74 | 
 75 | type List interface {
 76 | 	Map(f Func) List;
 77 | 	Member(x Eq) Bool
 78 | };
 79 | type Nil struct {};
 80 | type Cons struct {
 81 | 	head Any;
 82 | 	tail List
 83 | };
 84 | func (xs Nil) Map(f Func) List { return Nil{} };
 85 | func (xs Cons) Map(f Func) List { return Cons{f.Apply(xs.head), xs.tail.Map(f)} };
 86 | type memberBr struct {
 87 | 	xs Cons;
 88 | 	x Eq
 89 | };
 90 | func (this memberBr) IfTT() Any { return TT{} };
 91 | func (this memberBr) IfFF() Any { return this.xs.tail.Member(this.x) };
 92 | func (xs Nil) Member(x Eq) Bool { return FF{} };
 93 | func (xs Cons) Member(x Eq) Bool { return x.Equal(xs.head).Cond(memberBr{xs,x}).(Bool) };
 94 | 
 95 | /* Example code */
 96 | 
 97 | type D struct {};
 98 | func (d D) _1() Nat { return Succ{Zero{}} };
 99 | func (d D) _2() Nat { return D{}._1().Add(D{}._1()) };
100 | func (d D) _3() Nat { return D{}._2().Add(D{}._1()) };
101 | 
102 | func main() {
103 | 	// Submission version: incr{2}.Apply(3).(Nat)
104 | 	//_ = incr{D{}._2()}.Apply(D{}._3()).(Nat)
105 | 	fmt.Printf("%#v", incr{D{}._2()}.Apply(D{}._3()).(Nat))
106 | }
107 | 
--------------------------------------------------------------------------------
/examples/fg/misc/map/map.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -v -eval=13 fg/examples/misc/map/map.go
 2 | // Cf.
 3 | //$ go run github.com/rhu1/fgg/fg/examples/misc/map
 4 | 
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | /* Base decls: Any, Booleans, Functions, Lists */
10 | 
11 | type Any interface {};
12 | 
13 | /* Booleans */
14 | 
15 | type Eq interface {
16 | 	Equal(that Any) Bool
17 | };
18 | type Bool interface {
19 | 	Not() Bool;
20 | 	Equal(that Any) Bool;
21 | 	Cond(br Branches) Any
22 | };
23 | type Branches interface {
24 | 	IfTT() Any;
25 | 	IfFF() Any
26 | };
27 | type TT struct{};
28 | type FF struct{};
29 | 
30 | func (this TT) Not() Bool { return FF{} };
31 | func (this FF) Not() Bool { return TT{} };
32 | func (this TT) Equal(that Any) Bool { return that.(Bool) };
33 | func (this FF) Equal(that Any) Bool { return that.(Bool).Not() };
34 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
35 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
36 | 
37 | /* Functions */
38 | 
39 | type Func interface {
40 | 	Apply(x Any) Any
41 | };
42 | type not struct {};
43 | func (this not) Apply(x Any) Any { return x.(Bool).Not() };
44 | type compose struct {
45 | 	f Func;
46 | 	g Func
47 | };
48 | func (this compose) Apply(x Any) Any { return this.g.Apply(this.f.Apply(x)) };
49 | 
50 | /* Lists */
51 | 
52 | type List interface {
53 | 	Map(f Func) List;
54 | 	Member(x Eq) Bool
55 | };
56 | type Nil struct {};
57 | type Cons struct {
58 | 	head Any;
59 | 	tail List
60 | };
61 | func (xs Nil) Map(f Func) List { return Nil{} };
62 | func (xs Cons) Map(f Func) List { return Cons{f.Apply(xs.head), xs.tail.Map(f)} };
63 | type memberBr struct {
64 | 	xs Cons;
65 | 	x Eq
66 | };
67 | func (this memberBr) IfTT() Any { return TT{} };
68 | func (this memberBr) IfFF() Any { return this.xs.tail.Member(this.x) };
69 | func (xs Nil) Member(x Eq) Bool { return FF{} };
70 | func (xs Cons) Member(x Eq) Bool { return x.Equal(xs.head).Cond(memberBr{xs,x}).(Bool) };
71 | 
72 | /* Example code */
73 | 
74 | func main() {
75 | 	// Submission version was missing a "}"
76 | 	/*_ =  Cons{TT{}, Cons{FF{}, Nil{}}}.Map(not{}). // Main example
77 | 			(Cons).head.(Bool).Not() // Extra, assertion necessary*/
78 | 	fmt.Printf("%#v", Cons{TT{}, Cons{FF{}, Nil{}}}.Map(not{}). // Main example
79 | 			(Cons).head.(Bool).Not())
80 | }
81 | 
--------------------------------------------------------------------------------
/examples/fg/misc/not/not.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -v -eval=4 fg/examples/misc/not/not.go
 2 | // Cf.
 3 | //$ go run github.com/rhu1/fgg/fg/examples/misc/not
 4 | 
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | /* Base decls: Any, Booleans, Functions */
10 | 
11 | type Any interface {};
12 | 
13 | /* Booleans */
14 | 
15 | type Eq interface {
16 | 	Equal(that Any) Bool
17 | };
18 | type Bool interface {
19 | 	Not() Bool;
20 | 	Equal(that Any) Bool;
21 | 	Cond(br Branches) Any
22 | };
23 | type Branches interface {
24 | 	IfTT() Any;
25 | 	IfFF() Any
26 | };
27 | type TT struct{};
28 | type FF struct{};
29 | 
30 | func (this TT) Not() Bool { return FF{} };
31 | func (this FF) Not() Bool { return TT{} };
32 | func (this TT) Equal(that Any) Bool { return that.(Bool) };
33 | func (this FF) Equal(that Any) Bool { return that.(Bool).Not() };
34 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
35 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
36 | 
37 | /* Functions */
38 | 
39 | type Func interface {
40 | 	Apply(x Any) Any
41 | };
42 | type not struct {};
43 | func (this not) Apply(x Any) Any { return x.(Bool).Not() };
44 | type compose struct {
45 | 	f Func;
46 | 	g Func
47 | };
48 | func (this compose) Apply(x Any) Any { return this.g.Apply(this.f.Apply(x)) };
49 | 
50 | /* Example code */
51 | 
52 | func main() {
53 | 	//_ = not{}.Apply(TT{}).(Bool)
54 | 	fmt.Printf("%#v", not{}.Apply(TT{}).(Bool))
55 | }
56 | 
--------------------------------------------------------------------------------
/examples/fg/misc/rose/rose.go:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -v -eval=3 fg/examples/misc/whoopsie/rose.go
 2 | 
 3 | package main;
 4 | 
 5 | type RoseByAnotherName interface {};
 6 | 
 7 | type I1 interface { Equal(that Any) Bool };
 8 | type I2 interface { Equal(that RoseByAnotherName) Bool };
 9 | 
10 | type T struct {};
11 | func (t T) Equal(foo Any) Bool { return Bool{} };
12 | type Any interface {};
13 | type ToAny struct { any Any };
14 | type Bool struct {};  // Just for the purposes of this example
15 | 
16 | func main() {
17 | 	_ = ToAny{T{}}.any.(I1).(I2)
18 | }
19 | 
--------------------------------------------------------------------------------
/examples/fg/misc/whoopsie/whoopsie.fg:
--------------------------------------------------------------------------------
1 | //$ go run github.com/rhu1/fgg -v examples/fg/misc/whoopsie/whoopsie.fg
2 | 
3 | // TODO: FG, error not checked yet
4 | // FIXME: GO, bad Go program blocks, e.g., guru
5 | package main;
6 | type KO struct{ whoopsie KO };
7 | type A struct{};
8 | func main() { _ = A{} }
9 | 
--------------------------------------------------------------------------------
/examples/fg/oopsla20/fig1/functions.go:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -eval=-1 -v fg/examples/oopsla20/fig1/functions.go
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | /* Library: Bool, Int */
  8 | 
  9 | type Bool interface {
 10 | 	Not() Bool;
 11 | 	Equal(that Eq) Bool;
 12 | 	Cond(br Branches) Any
 13 | };
 14 | type Branches interface {
 15 | 	IfTT() Any;
 16 | 	IfFF() Any
 17 | };
 18 | type TT struct{};
 19 | func (this TT) Not() Bool { return FF{} };
 20 | func (this TT) Equal(that Eq) Bool { return that.(Bool) };
 21 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
 22 | 
 23 | type FF struct{};
 24 | func (this FF) Not() Bool { return TT{} };
 25 | func (this FF) Equal(that Eq) Bool { return that.(Bool).Not() };
 26 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
 27 | 
 28 | type Int interface {
 29 | 	Inc() Int;
 30 | 	Dec() Int;
 31 | 	Add(x Int) Int;
 32 | 	Gt(x Int) Bool;
 33 | 	IsNeg() Bool
 34 | };
 35 | 
 36 | type Zero struct {};
 37 | func (x0 Zero) Inc() Int { return Pos{x0} };
 38 | func (x0 Zero) Dec() Int { return Neg{x0} };
 39 | func (x0 Zero) Add(x Int) Int { return x };
 40 | func (x0 Zero) Gt(x Int) Bool { return x.IsNeg() };
 41 | func (x0 Zero) IsNeg() Bool { return FF{} };
 42 | 
 43 | type Pos struct { dec Int };
 44 | func (x0 Pos) Inc() Int { return Pos{x0} };
 45 | func (x0 Pos) Dec() Int { return x0.dec };
 46 | func (x0 Pos) Add(x Int) Int { return x0.dec.Add(x.Inc()) };
 47 | func (x0 Pos) Gt(x Int) Bool { return x0.dec.Gt(x.Dec()) };
 48 | func (x0 Pos) IsNeg() Bool { return FF{} };
 49 | 
 50 | type Neg struct { inc Int };
 51 | func (x0 Neg) Inc() Int { return x0.inc };
 52 | func (x0 Neg) Dec() Int { return Neg{x0} };
 53 | func (x0 Neg) Add(x Int) Int { return x0.inc.Add(x.Dec()) };
 54 | func (x0 Neg) Gt(x Int) Bool { return x0.inc.Gt(x.Inc()) };
 55 | func (x0 Neg) IsNeg() Bool { return TT{} };
 56 | 
 57 | type Ints struct {};
 58 | func (d Ints) _1() Int { return Pos{Zero{}} };
 59 | func (d Ints) _2() Int { return d._1().Add(d._1()) };
 60 | func (d Ints) _3() Int { return d._2().Add(d._1()) };
 61 | //func (d Ints) _4() Int { return d._3().Add(d._1()) };
 62 | //func (d Ints) _5() Int { return d._4().Add(d._1()) };
 63 | func (d Ints) __1() Int { return Neg{Zero{}} };
 64 | func (d Ints) __2() Int { return d.__1().Add(d.__1()) };
 65 | func (d Ints) __3() Int { return d.__2().Add(d.__1()) };
 66 | func (d Ints) __4() Int { return d.__3().Add(d.__1()) };
 67 | func (d Ints) __5() Int { return d.__4().Add(d.__1()) };
 68 | 
 69 | 
 70 | /* Later example */
 71 | 
 72 | type Eq interface {
 73 | 	Equal(that Eq) Bool
 74 | };
 75 | 
 76 | 
 77 | /* Example code */
 78 | 
 79 | type Any interface {};
 80 | type Function interface {
 81 | 	Apply(x Any) Any
 82 | };
 83 | //type incr struct { n int };
 84 | type incr struct { n Int };
 85 | func (this incr) Apply(x Any) Any {
 86 | 	//return x.(int) + n
 87 | 	return x.(Int).Add(this.n)
 88 | };
 89 | type pos struct {};  // We already have IsNeg, though
 90 | func (this pos) Apply(x Any) Any {
 91 | 	//return x.(int) > 0
 92 | 	return x.(Int).Gt(Zero{})
 93 | };
 94 | 
 95 | type compose struct {
 96 | 	f Function;
 97 | 	g Function
 98 | };
 99 | func (this compose) Apply(x Any) Any {
100 | 	return this.g.Apply(this.f.Apply(x))
101 | };
102 | 
103 | 
104 | func main() {
105 | 	/*var f Function = compose{incr{-5}, pos{}}
106 | 	var b bool = f.Apply(3).(bool)*/
107 | 	fmt.Printf("%#v", compose{incr{Ints{}.__5()} , pos{}}.Apply(Ints{}._3()).(Bool))
108 | }
109 | 
--------------------------------------------------------------------------------
/examples/fg/oopsla20/fig2/equality.go:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -eval=-1 -v fg/examples/oopsla20/fig2/equality.go
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | /* Library: Bool, Int */
  8 | 
  9 | type Bool interface {
 10 | 	Not() Bool;
 11 | 	Equal(that Eq) Bool;
 12 | 	Cond(br Branches) Any;
 13 | 	And(x Bool) Bool
 14 | };
 15 | type Branches interface {
 16 | 	IfTT() Any;
 17 | 	IfFF() Any
 18 | };
 19 | type TT struct{};
 20 | func (this TT) Not() Bool { return FF{} };
 21 | func (this TT) Equal(that Eq) Bool { return that.(Bool) };
 22 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
 23 | func (this TT) And(x Bool) Bool { return x };
 24 | 
 25 | type FF struct{};
 26 | func (this FF) Not() Bool { return TT{} };
 27 | func (this FF) Equal(that Eq) Bool { return that.(Bool).Not() };
 28 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
 29 | func (this FF) And(x Bool) Bool { return this };
 30 | 
 31 | type Zero struct {};
 32 | func (x0 Zero) Inc() Int { return Pos{x0} };
 33 | func (x0 Zero) Dec() Int { return Neg{x0} };
 34 | func (x0 Zero) Add(x Int) Int { return x };
 35 | func (x0 Zero) Gt(x Int) Bool { return x.IsNeg() };
 36 | func (x0 Zero) IsNeg() Bool { return FF{} };
 37 | func (x0 Zero) IsZero() Bool { return TT{} };
 38 | func (x0 Zero) Ieq(x Int) Bool { return x.IsZero() };
 39 | 
 40 | type Pos struct { dec Int };
 41 | func (x0 Pos) Inc() Int { return Pos{x0} };
 42 | func (x0 Pos) Dec() Int { return x0.dec };
 43 | func (x0 Pos) Add(x Int) Int { return x0.dec.Add(x.Inc()) };
 44 | func (x0 Pos) Gt(x Int) Bool { return x0.dec.Gt(x.Dec()) };
 45 | func (x0 Pos) IsNeg() Bool { return FF{} };
 46 | func (x0 Pos) IsZero() Bool { return FF{} };
 47 | func (x0 Pos) Ieq(x Int) Bool { return x0.dec.Ieq(x.Dec()) };
 48 | 
 49 | type Neg struct { inc Int };
 50 | func (x0 Neg) Inc() Int { return x0.inc };
 51 | func (x0 Neg) Dec() Int { return Neg{x0} };
 52 | func (x0 Neg) Add(x Int) Int { return x0.inc.Add(x.Dec()) };
 53 | func (x0 Neg) Gt(x Int) Bool { return x0.inc.Gt(x.Inc()) };
 54 | func (x0 Neg) IsNeg() Bool { return TT{} };
 55 | func (x0 Neg) IsZero() Bool { return FF{} };
 56 | func (x0 Neg) Ieq(x Int) Bool { return x0.inc.Ieq(x.Inc()) };
 57 | 
 58 | type Ints struct {};
 59 | func (d Ints) _1() Int { return Pos{Zero{}} };
 60 | func (d Ints) _2() Int { return d._1().Add(d._1()) };
 61 | func (d Ints) _3() Int { return d._2().Add(d._1()) };
 62 | //func (d Ints) _4() Int { return d._3().Add(d._1()) };
 63 | //func (d Ints) _5() Int { return d._4().Add(d._1()) };
 64 | func (d Ints) __1() Int { return Neg{Zero{}} };
 65 | func (d Ints) __2() Int { return d.__1().Add(d.__1()) };
 66 | func (d Ints) __3() Int { return d.__2().Add(d.__1()) };
 67 | func (d Ints) __4() Int { return d.__3().Add(d.__1()) };
 68 | func (d Ints) __5() Int { return d.__4().Add(d.__1()) };
 69 | 
 70 | 
 71 | /* Example code */
 72 | 
 73 | type Any interface {};
 74 | type Eq interface {
 75 | 	Equal(that Eq) Bool
 76 | };
 77 | type Int interface {
 78 | 	Inc() Int;
 79 | 	Dec() Int;
 80 | 	Add(x Int) Int;
 81 | 	Gt(x Int) Bool;
 82 | 	IsNeg() Bool;
 83 | 	IsZero() Bool;
 84 | 	Ieq(x Int) Bool;  // ==
 85 | 	Equal(that Eq) Bool
 86 | };
 87 | func (this Zero) Equal(that Eq) Bool {
 88 | 	return this.Ieq(that.(Int))
 89 | };
 90 | func (this Pos) Equal(that Eq) Bool {
 91 | 	return this.Ieq(that.(Int))
 92 | };
 93 | func (this Neg) Equal(that Eq) Bool {
 94 | 	return this.Ieq(that.(Int))
 95 | };
 96 | type Pair struct {
 97 | 	left Eq;
 98 | 	right Eq
 99 | };
100 | func (this Pair) Equal(that Eq) Bool {
101 | 	return this.left.Equal(that.(Pair).left).And(this.right.Equal(that.(Pair).right))
102 | };
103 | func main() {
104 | 	/*var i, j Int = 1, 2
105 | 	var p Pair = Pair{i, j}
106 | 	var _ bool = p.Equal(p) // true*/
107 | 	fmt.Printf("%#v", Pair{Ints{}._1(), Ints{}._2()}.
108 | 			Equal(Pair{Ints{}._1(), Ints{}._2()}))
109 | }
110 | 
--------------------------------------------------------------------------------
/examples/fg/oopsla20/fig3/lists.go:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -eval=-1 -v fg/examples/oopsla20/fig3/lists.go
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | /* Library: Bool, Int */
  8 | 
  9 | type Bool interface {
 10 | 	Not() Bool;
 11 | 	Equal(that Any) Bool;
 12 | 	Cond(br Branches) Any
 13 | };
 14 | type Branches interface {
 15 | 	IfTT() Any;
 16 | 	IfFF() Any
 17 | };
 18 | type TT struct{};
 19 | func (this TT) Not() Bool { return FF{} };
 20 | func (this TT) Equal(that Any) Bool { return that.(Bool) };
 21 | func (this TT) Cond(br Branches) Any { return br.IfTT() };
 22 | 
 23 | type FF struct{};
 24 | func (this FF) Not() Bool { return TT{} };
 25 | func (this FF) Equal(that Any) Bool { return that.(Bool).Not() };
 26 | func (this FF) Cond(br Branches) Any { return br.IfFF() };
 27 | 
 28 | type Int interface {
 29 | 	Inc() Int;
 30 | 	Dec() Int;
 31 | 	Add(x Int) Int;
 32 | 	Gt(x Int) Bool;
 33 | 	IsNeg() Bool;
 34 | 
 35 | 	Equal(x Any) Bool;
 36 | 	EqualZero() Bool;
 37 | 	EqualNonZero(x Int) Bool
 38 | };
 39 | 
 40 | type Zero struct {};
 41 | func (x0 Zero) Inc() Int { return Pos{x0} };
 42 | func (x0 Zero) Dec() Int { return Neg{x0} };
 43 | func (x0 Zero) Add(x Int) Int { return x };
 44 | func (x0 Zero) Gt(x Int) Bool { return x.IsNeg() };
 45 | func (x0 Zero) IsNeg() Bool { return FF{} };
 46 | 
 47 | type Pos struct { dec Int };
 48 | func (x0 Pos) Inc() Int { return Pos{x0} };
 49 | func (x0 Pos) Dec() Int { return x0.dec };
 50 | func (x0 Pos) Add(x Int) Int { return x0.dec.Add(x.Inc()) };
 51 | func (x0 Pos) Gt(x Int) Bool { return x0.dec.Gt(x.Dec()) };
 52 | func (x0 Pos) IsNeg() Bool { return FF{} };
 53 | 
 54 | type Neg struct { inc Int };
 55 | func (x0 Neg) Inc() Int { return x0.inc };
 56 | func (x0 Neg) Dec() Int { return Neg{x0} };
 57 | func (x0 Neg) Add(x Int) Int { return x0.inc.Add(x.Dec()) };
 58 | func (x0 Neg) Gt(x Int) Bool { return x0.inc.Gt(x.Inc()) };
 59 | func (x0 Neg) IsNeg() Bool { return TT{} };
 60 | 
 61 | type Ints struct {};
 62 | func (d Ints) _1() Int { return Pos{Zero{}} };
 63 | func (d Ints) _2() Int { return d._1().Add(d._1()) };
 64 | func (d Ints) _3() Int { return d._2().Add(d._1()) };
 65 | func (d Ints) _4() Int { return d._3().Add(d._1()) };
 66 | func (d Ints) _5() Int { return d._4().Add(d._1()) };
 67 | func (d Ints) _6() Int { return d._5().Add(d._1()) };
 68 | func (d Ints) __1() Int { return Neg{Zero{}} };
 69 | func (d Ints) __2() Int { return d.__1().Add(d.__1()) };
 70 | func (d Ints) __3() Int { return d.__2().Add(d.__1()) };
 71 | func (d Ints) __4() Int { return d.__3().Add(d.__1()) };
 72 | func (d Ints) __5() Int { return d.__4().Add(d.__1()) };
 73 | 
 74 | 
 75 | /* Prev. example */
 76 | 
 77 | type Any interface {};
 78 | type Function interface {
 79 | 	Apply(x Any) Any
 80 | };
 81 | //type incr struct { n int };
 82 | type incr struct { n Int };
 83 | func (this incr) Apply(x Any) Any {
 84 | 	//return x.(int) + n
 85 | 	return x.(Int).Add(this.n)
 86 | };
 87 | type pos struct {};
 88 | func (this pos) Apply(x Any) Any {
 89 | 	//return x.(int) > 0
 90 | 	return x.(Int).Gt(Zero{})
 91 | };
 92 | 
 93 | 
 94 | /* Example code */
 95 | 
 96 | type Eq interface {
 97 | 	Equal(that Eq) Bool
 98 | };
 99 | /*func (this int) Equal(that Eq) bool {
100 | 	return this == that.(int)
101 | };
102 | func (this bool) Equal(that Eq) bool {
103 | 	return this == that.(bool)
104 | };*/
105 | func (x0 Zero) Equal(x Any) Bool { return x.(Int).EqualZero() };
106 | func (x0 Zero) EqualZero() Bool { return TT{} };
107 | func (x0 Zero) EqualNonZero(x Int) Bool { return FF{} };
108 | func (x0 Pos) Equal(x Any) Bool { return x0.EqualNonZero(x.(Int)) };
109 | func (x0 Pos) EqualZero() Bool { return FF{} };
110 | func (x0 Pos) EqualNonZero(x Int) Bool { return x.Equal(x0.dec) };
111 | func (x0 Neg) Equal(x Any) Bool { return x0.EqualNonZero(x.(Int)) };
112 | func (x0 Neg) EqualZero() Bool { return FF{} };
113 | func (x0 Neg) EqualNonZero(x Int) Bool { return x.Equal(x0.inc) };
114 | 
115 | type List interface {
116 | 	Map(f Function) List
117 | };
118 | type Nil struct {};
119 | type Cons struct {
120 | 	head Any;
121 | 	tail List
122 | };
123 | func (xs Nil) Map(f Function) List {
124 | 	return Nil{}
125 | };
126 | func (xs Cons) Map(f Function) List {
127 | 	return Cons{f.Apply(xs.head), xs.tail.Map(f)}
128 | };
129 | 
130 | 
131 | func main() {
132 | 	/*var xs List = Cons{3, Cons{6, Nil{}}}
133 | 	var ys List = xs.Map(incr{-5})
134 | 	var zs List = ys.Map(pos)*/
135 | 	fmt.Printf("%#v", Cons{Ints{}._3(), Cons{Ints{}._6(), Nil{}}}.
136 | 				Map(incr{Ints{}.__5()}).
137 | 				Map(pos{}))  // !!!
138 | }
139 | 
--------------------------------------------------------------------------------
/examples/fg/oopsla20/fig9/monom.go:
--------------------------------------------------------------------------------
  1 | /* This is monom output for fig 9, i.e.:
  2 |  *     go run github.com/rhu1/fgg -fgg -monomc=-- fgg/examples/oopsla20/fi6/lists.fgg
  3 |  */
  4 | 
  5 | //$ go run github.com/rhu1/fgg -eval=-1 -v fg/examples/oopsla20/fig9/monom.go
  6 | 
  7 | package main;
  8 | import "fmt";
  9 | type Boolᐸᐳ interface { Not___Bool__() Top; Equal___Bool___Bool__() Top; Cond__a_Any____Branches_α1__α1() Top };
 10 | type TTᐸᐳ struct {};
 11 | type FFᐸᐳ struct {};
 12 | func (this TTᐸᐳ) Not___Bool__() Top { return this };
 13 | func (this FFᐸᐳ) Not___Bool__() Top { return this };
 14 | func (this TTᐸᐳ) Equal___Bool___Bool__() Top { return this };
 15 | func (this FFᐸᐳ) Equal___Bool___Bool__() Top { return this };
 16 | func (this TTᐸᐳ) Cond__a_Any____Branches_α1__α1() Top { return this };
 17 | func (this FFᐸᐳ) Cond__a_Any____Branches_α1__α1() Top { return this };
 18 | type Intᐸᐳ interface { Incᐸᐳ() Intᐸᐳ; Inc___Int__() Top; Decᐸᐳ() Intᐸᐳ; Dec___Int__() Top; Addᐸᐳ(x Intᐸᐳ) Intᐸᐳ; Add___Int___Int__() Top; Gtᐸᐳ(x Intᐸᐳ) Boolᐸᐳ; Gt___Int___Bool__() Top; IsNegᐸᐳ() Boolᐸᐳ; IsNeg___Bool__() Top; Equal___Int___Bool__() Top; EqualZero___Bool__() Top; EqualNonZero___Int___Bool__() Top };
 19 | type Zeroᐸᐳ struct {};
 20 | func (x0 Zeroᐸᐳ) Incᐸᐳ() Intᐸᐳ { return Posᐸᐳ{x0} };
 21 | func (x0 Zeroᐸᐳ) Inc___Int__() Top { return x0 };
 22 | func (x0 Zeroᐸᐳ) Decᐸᐳ() Intᐸᐳ { return Negᐸᐳ{x0} };
 23 | func (x0 Zeroᐸᐳ) Dec___Int__() Top { return x0 };
 24 | func (x0 Zeroᐸᐳ) Addᐸᐳ(x Intᐸᐳ) Intᐸᐳ { return x };
 25 | func (x0 Zeroᐸᐳ) Add___Int___Int__() Top { return x0 };
 26 | func (x0 Zeroᐸᐳ) Gtᐸᐳ(x Intᐸᐳ) Boolᐸᐳ { return x.IsNegᐸᐳ() };
 27 | func (x0 Zeroᐸᐳ) Gt___Int___Bool__() Top { return x0 };
 28 | func (x0 Zeroᐸᐳ) IsNegᐸᐳ() Boolᐸᐳ { return FFᐸᐳ{} };
 29 | func (x0 Zeroᐸᐳ) IsNeg___Bool__() Top { return x0 };
 30 | type Posᐸᐳ struct { dec Intᐸᐳ };
 31 | func (x0 Posᐸᐳ) Incᐸᐳ() Intᐸᐳ { return Posᐸᐳ{x0} };
 32 | func (x0 Posᐸᐳ) Inc___Int__() Top { return x0 };
 33 | func (x0 Posᐸᐳ) Decᐸᐳ() Intᐸᐳ { return x0.dec };
 34 | func (x0 Posᐸᐳ) Dec___Int__() Top { return x0 };
 35 | func (x0 Posᐸᐳ) Addᐸᐳ(x Intᐸᐳ) Intᐸᐳ { return x0.dec.Addᐸᐳ(x.Incᐸᐳ()) };
 36 | func (x0 Posᐸᐳ) Add___Int___Int__() Top { return x0 };
 37 | func (x0 Posᐸᐳ) Gtᐸᐳ(x Intᐸᐳ) Boolᐸᐳ { return x0.dec.Gtᐸᐳ(x.Decᐸᐳ()) };
 38 | func (x0 Posᐸᐳ) Gt___Int___Bool__() Top { return x0 };
 39 | func (x0 Posᐸᐳ) IsNegᐸᐳ() Boolᐸᐳ { return FFᐸᐳ{} };
 40 | func (x0 Posᐸᐳ) IsNeg___Bool__() Top { return x0 };
 41 | type Negᐸᐳ struct { inc Intᐸᐳ };
 42 | func (x0 Negᐸᐳ) Incᐸᐳ() Intᐸᐳ { return x0.inc };
 43 | func (x0 Negᐸᐳ) Inc___Int__() Top { return x0 };
 44 | func (x0 Negᐸᐳ) Decᐸᐳ() Intᐸᐳ { return Negᐸᐳ{x0} };
 45 | func (x0 Negᐸᐳ) Dec___Int__() Top { return x0 };
 46 | func (x0 Negᐸᐳ) Addᐸᐳ(x Intᐸᐳ) Intᐸᐳ { return x0.inc.Addᐸᐳ(x.Decᐸᐳ()) };
 47 | func (x0 Negᐸᐳ) Add___Int___Int__() Top { return x0 };
 48 | func (x0 Negᐸᐳ) Gtᐸᐳ(x Intᐸᐳ) Boolᐸᐳ { return x0.inc.Gtᐸᐳ(x.Incᐸᐳ()) };
 49 | func (x0 Negᐸᐳ) Gt___Int___Bool__() Top { return x0 };
 50 | func (x0 Negᐸᐳ) IsNegᐸᐳ() Boolᐸᐳ { return TTᐸᐳ{} };
 51 | func (x0 Negᐸᐳ) IsNeg___Bool__() Top { return x0 };
 52 | type Intsᐸᐳ struct {};
 53 | func (d Intsᐸᐳ) _1ᐸᐳ() Intᐸᐳ { return Posᐸᐳ{Zeroᐸᐳ{}} };
 54 | func (d Intsᐸᐳ) _1___Int__() Top { return d };
 55 | func (d Intsᐸᐳ) _2ᐸᐳ() Intᐸᐳ { return d._1ᐸᐳ().Addᐸᐳ(d._1ᐸᐳ()) };
 56 | func (d Intsᐸᐳ) _2___Int__() Top { return d };
 57 | func (d Intsᐸᐳ) _3ᐸᐳ() Intᐸᐳ { return d._2ᐸᐳ().Addᐸᐳ(d._1ᐸᐳ()) };
 58 | func (d Intsᐸᐳ) _3___Int__() Top { return d };
 59 | func (d Intsᐸᐳ) _4ᐸᐳ() Intᐸᐳ { return d._3ᐸᐳ().Addᐸᐳ(d._1ᐸᐳ()) };
 60 | func (d Intsᐸᐳ) _4___Int__() Top { return d };
 61 | func (d Intsᐸᐳ) _5ᐸᐳ() Intᐸᐳ { return d._4ᐸᐳ().Addᐸᐳ(d._1ᐸᐳ()) };
 62 | func (d Intsᐸᐳ) _5___Int__() Top { return d };
 63 | func (d Intsᐸᐳ) _6ᐸᐳ() Intᐸᐳ { return d._5ᐸᐳ().Addᐸᐳ(d._1ᐸᐳ()) };
 64 | func (d Intsᐸᐳ) _6___Int__() Top { return d };
 65 | func (d Intsᐸᐳ) __1ᐸᐳ() Intᐸᐳ { return Negᐸᐳ{Zeroᐸᐳ{}} };
 66 | func (d Intsᐸᐳ) __1___Int__() Top { return d };
 67 | func (d Intsᐸᐳ) __2ᐸᐳ() Intᐸᐳ { return d.__1ᐸᐳ().Addᐸᐳ(d.__1ᐸᐳ()) };
 68 | func (d Intsᐸᐳ) __2___Int__() Top { return d };
 69 | func (d Intsᐸᐳ) __3ᐸᐳ() Intᐸᐳ { return d.__2ᐸᐳ().Addᐸᐳ(d.__1ᐸᐳ()) };
 70 | func (d Intsᐸᐳ) __3___Int__() Top { return d };
 71 | func (d Intsᐸᐳ) __4ᐸᐳ() Intᐸᐳ { return d.__3ᐸᐳ().Addᐸᐳ(d.__1ᐸᐳ()) };
 72 | func (d Intsᐸᐳ) __4___Int__() Top { return d };
 73 | func (d Intsᐸᐳ) __5ᐸᐳ() Intᐸᐳ { return d.__4ᐸᐳ().Addᐸᐳ(d.__1ᐸᐳ()) };
 74 | func (d Intsᐸᐳ) __5___Int__() Top { return d };
 75 | type FunctionᐸIntᐸᐳᐨIntᐸᐳᐳ interface { Applyᐸᐳ(x Intᐸᐳ) Intᐸᐳ; Apply___Int___Int__() Top };
 76 | type FunctionᐸIntᐸᐳᐨBoolᐸᐳᐳ interface { Applyᐸᐳ(x Intᐸᐳ) Boolᐸᐳ; Apply___Int___Bool__() Top };
 77 | type incrᐸᐳ struct { n Intᐸᐳ };
 78 | func (this incrᐸᐳ) Applyᐸᐳ(x Intᐸᐳ) Intᐸᐳ { return x.Addᐸᐳ(this.n) };
 79 | func (this incrᐸᐳ) Apply___Int___Int__() Top { return this };
 80 | type posᐸᐳ struct {};
 81 | func (this posᐸᐳ) Applyᐸᐳ(x Intᐸᐳ) Boolᐸᐳ { return x.Gtᐸᐳ(Zeroᐸᐳ{}) };
 82 | func (this posᐸᐳ) Apply___Int___Bool__() Top { return this };
 83 | func (x0 Zeroᐸᐳ) Equal___Int___Bool__() Top { return x0 };
 84 | func (x0 Zeroᐸᐳ) EqualZero___Bool__() Top { return x0 };
 85 | func (x0 Zeroᐸᐳ) EqualNonZero___Int___Bool__() Top { return x0 };
 86 | func (x0 Posᐸᐳ) Equal___Int___Bool__() Top { return x0 };
 87 | func (x0 Posᐸᐳ) EqualZero___Bool__() Top { return x0 };
 88 | func (x0 Posᐸᐳ) EqualNonZero___Int___Bool__() Top { return x0 };
 89 | func (x0 Negᐸᐳ) Equal___Int___Bool__() Top { return x0 };
 90 | func (x0 Negᐸᐳ) EqualZero___Bool__() Top { return x0 };
 91 | func (x0 Negᐸᐳ) EqualNonZero___Int___Bool__() Top { return x0 };
 92 | type ListᐸIntᐸᐳᐳ interface { MapᐸIntᐸᐳᐳ(f FunctionᐸIntᐸᐳᐨIntᐸᐳᐳ) ListᐸIntᐸᐳᐳ; MapᐸBoolᐸᐳᐳ(f FunctionᐸIntᐸᐳᐨBoolᐸᐳᐳ) ListᐸBoolᐸᐳᐳ; Map__b_Any____Function_Int___α1__List_α1_() Top };
 93 | type ListᐸBoolᐸᐳᐳ interface { Map__b_Any____Function_Bool___α1__List_α1_() Top };
 94 | type NilᐸIntᐸᐳᐳ struct {};
 95 | type NilᐸBoolᐸᐳᐳ struct {};
 96 | type ConsᐸIntᐸᐳᐳ struct { head Intᐸᐳ; tail ListᐸIntᐸᐳᐳ };
 97 | type ConsᐸBoolᐸᐳᐳ struct { head Boolᐸᐳ; tail ListᐸBoolᐸᐳᐳ };
 98 | func (xs NilᐸIntᐸᐳᐳ) MapᐸBoolᐸᐳᐳ(f FunctionᐸIntᐸᐳᐨBoolᐸᐳᐳ) ListᐸBoolᐸᐳᐳ { return NilᐸBoolᐸᐳᐳ{} };
 99 | func (xs NilᐸIntᐸᐳᐳ) MapᐸIntᐸᐳᐳ(f FunctionᐸIntᐸᐳᐨIntᐸᐳᐳ) ListᐸIntᐸᐳᐳ { return NilᐸIntᐸᐳᐳ{} };
100 | func (xs NilᐸIntᐸᐳᐳ) Map__b_Any____Function_Int___α1__List_α1_() Top { return xs };
101 | func (xs NilᐸBoolᐸᐳᐳ) Map__b_Any____Function_Bool___α1__List_α1_() Top { return xs };
102 | func (xs ConsᐸIntᐸᐳᐳ) MapᐸIntᐸᐳᐳ(f FunctionᐸIntᐸᐳᐨIntᐸᐳᐳ) ListᐸIntᐸᐳᐳ { return ConsᐸIntᐸᐳᐳ{f.Applyᐸᐳ(xs.head), xs.tail.MapᐸIntᐸᐳᐳ(f)} };
103 | func (xs ConsᐸIntᐸᐳᐳ) MapᐸBoolᐸᐳᐳ(f FunctionᐸIntᐸᐳᐨBoolᐸᐳᐳ) ListᐸBoolᐸᐳᐳ { return ConsᐸBoolᐸᐳᐳ{f.Applyᐸᐳ(xs.head), xs.tail.MapᐸBoolᐸᐳᐳ(f)} };
104 | func (xs ConsᐸBoolᐸᐳᐳ) Map__b_Any____Function_Bool___α1__List_α1_() Top { return xs };
105 | func (xs ConsᐸIntᐸᐳᐳ) Map__b_Any____Function_Int___α1__List_α1_() Top { return xs };
106 | type Top interface {};
107 | func main() { fmt.Printf("%#v", ConsᐸIntᐸᐳᐳ{Intsᐸᐳ{}._3ᐸᐳ(), ConsᐸIntᐸᐳᐳ{Intsᐸᐳ{}._6ᐸᐳ(), NilᐸIntᐸᐳᐳ{}}}.MapᐸIntᐸᐳᐳ(incrᐸᐳ{Intsᐸᐳ{}.__5ᐸᐳ()}).MapᐸBoolᐸᐳᐳ(posᐸᐳ{})) }
108 | 
--------------------------------------------------------------------------------
/examples/fg/stupidcast/stupidcast.go:
--------------------------------------------------------------------------------
1 | //$ go run github.com/rhu1/fgg -eval=-1 -v fg/examples/stupidcast/stupidcast.go
2 | // Cf.
3 | //$ go run github.com/rhu1/fgg/fg/examples/stupidcast
4 | 
5 | package main; type Any interface{}; type ToAny struct { any Any }; type A struct {}; func main() { _ = ToAny{A{}}.any.(ToAny) }
6 | 
--------------------------------------------------------------------------------
/examples/fgg/expression/expression-fgg.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -v -eval=-1 fgg/examples/expression/expression-fgg.fgg
  2 | //$ go run github.com/rhu1/fgg -fgg -v -monomc=tmp/monom/scratch/scratch.go fgg/examples/expression/expression-fgg.fgg
  3 | 
  4 | // A solution to the Expression Problem in generalised FGG.
  5 | 
  6 | // 1. Define Eval() on Con and Plus
  7 | // 2. Define String() on Con and Plus
  8 | // 3. Define Eval() on Neg.
  9 | // 4. Define String() on Neg.
 10 | // Each of 1, 2, 3, 4 should be doable without
 11 | // altering the answers to the others.
 12 | 
 13 | // We require a generalised version of FGG,
 14 | // where function receivers may put stronger
 15 | // bounds on type variables.
 16 | // Modify rule t-func in FGG, to replace
 17 | //   (\type~t_S(\Phi)~T) \in \ov{D}
 18 | // by
 19 | //   (\type~t_S(\Psi)~T) \in \ov{D}
 20 | //   \and
 21 | //   (\type~\ov{\alpha~\rho_I)) = \Phi
 22 | //   \and
 23 | //   (\type~\ov{\alpha~\tau_I)) = \Psi
 24 | //   \and
 25 | //   \ov{\rho_I \imp \tau_I}
 26 | 
 27 | package main;
 28 | 
 29 | // TODO
 30 | type Int(type ) interface { isInt(type )() Int(); String(type )() string };
 31 | type One(type ) struct {};
 32 | func (x0 One(type )) isInt(type )() Int() { return x0 };
 33 | func (x0 One(type )) String(type )() string { return fmt.Sprintf("%v", x0) };
 34 | 
 35 | 
 36 | // 1
 37 | 
 38 | type Evalable(type ) interface {
 39 |   Eval(type )() Int()
 40 | };
 41 | 
 42 | type Con(type ) struct {
 43 |   value Int()
 44 | };
 45 | 
 46 | func (e Con(type )) Eval(type )() Int() {
 47 |   return e.value
 48 | };
 49 | 
 50 | type Any(type ) interface {};
 51 | 
 52 | type Add(type a Any()) struct {
 53 |   left a;
 54 |   right a
 55 | };
 56 | 
 57 | func (e Add(type a Evalable())) Eval(type )() Int() {
 58 | //func (e Add(type )) Eval(type )() Int() {  // TODO: add test
 59 |   return e.left.Eval()() //+ e.right.Eval()()
 60 | };
 61 | 
 62 | /*
 63 | func main() {
 64 |   //Evalable e = Add(Evalable){Con{1}, Con{2}}
 65 |   _ = Add(Evalable){Con(){1}, Con(){2}}.Eval()()
 66 | }*/
 67 | 
 68 | // 2
 69 | 
 70 | type Stringable(type ) interface {
 71 |   String(type )() string
 72 | };
 73 | 
 74 | func (e Con(type )) String(type )() string {
 75 |   return fmt.Sprintf("%d", e.value)
 76 | };
 77 | 
 78 | func (e Add(type a Stringable())) String(type )() string {
 79 |   return fmt.Sprintf("(%d+%d)", e.left.String()(), e.right.String()())
 80 | };
 81 | 
 82 | /*
 83 | func main() {
 84 |   //Stringable e = Add(Evalable()){Con{1}, Con{2}}
 85 |   _ = Add(Evalable()){Con(){1}, Con(){2}}.String()()
 86 | }*/
 87 | 
 88 | // 3
 89 | 
 90 | type Neg(type a Any()) struct {
 91 |   expr a
 92 | };
 93 | 
 94 | func (e Neg(type a Evalable())) Eval(type )() Int() {
 95 |   return One(){}//- e.expr.Eval()
 96 | };
 97 | 
 98 | // 4
 99 | 
100 | func (e Neg(type a Stringable())) String(type )() string {
101 |   return fmt.Sprintf("-%d", e.expr.String()())
102 | };
103 | 
104 | // 5
105 | 
106 | type Expr(type ) interface {
107 |   //Evalable;  // TODO: WF
108 |   Evalable();
109 |   Stringable()
110 | };
111 | 
112 | 
113 | func main() {
114 |   //Expr e = Add(Expr()){Con{1}, Neg(Expr()){Con{2}}}
115 |   //int v = e.Eval()
116 |   _ = Add(Expr()){Con(){One(){}}, Neg(Expr()){Con(){One(){}}}}.Eval()().String()()
117 | }
118 | 
119 | 
--------------------------------------------------------------------------------
/examples/fgg/hello/fmtprintf/fmtprintf.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -v -eval=10 fgg/examples/hello/fmtprintf.fgg
 2 | 
 3 | // N.B. FGG (or at least this implementation) is intended to be white-space *insensitive*.
 4 | // (E.g., this program could be written all on one line.)
 5 | // So the ';' are mandatory -- cannot replace by newlines (as in actual Go).
 6 | // (Newlines and other whitespace may be freely added, though.)
 7 | package main;
 8 | import "fmt";
 9 | type World(type ) struct {};
10 | func (x0 World(type )) hello(type )() World() { return x0.hello()() };
11 | func main() {
12 | 	fmt.Printf("%#v", World(){}.hello()())
13 | }
14 | 
--------------------------------------------------------------------------------
/examples/fgg/hello/hello.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -v -eval=10 fgg/examples/hello/hello.fgg
 2 | 
 3 | // N.B. FGG (or at least this implementation) is intended to be white-space *insensitive*.
 4 | // (E.g., this program could be written all on one line.)
 5 | // So the ';' are mandatory -- cannot replace by newlines (as in actual Go).
 6 | // (Newlines and other whitespace may be freely added, though.)
 7 | package main;
 8 | //import "fmt";
 9 | type World(type ) struct {};
10 | func (x0 World(type )) hello(type )() World() { return x0.hello()() };
11 | func main() {
12 | 	_ = World(){}.hello()()
13 | 	//fmt.Printf("%#v", World(){}.hello()())
14 | }
15 | 
--------------------------------------------------------------------------------
/examples/fgg/misc/booleans/booleans.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/misc/booleans/booleans.fgg
 2 | 
 3 | package main;
 4 | 
 5 | import "fmt";
 6 | 
 7 | /* Base decls: Any, Booleans */
 8 | 
 9 | type Any(type ) interface {};
10 | 
11 | /* Booleans */
12 | 
13 | type Eq(type a Any()) interface { Equal(type )(that a) Bool() };
14 | type Bool(type ) interface {
15 | 	Not(type )() Bool();
16 | 	Equal(type )(that Bool()) Bool();
17 | 	Cond(type a Any())(br Branches(a)) a
18 | };
19 | type Branches(type a Any()) interface {
20 | 	IfTT(type )() a;
21 | 	IfFF(type )() a
22 | };
23 | type TT(type ) struct {};
24 | type FF(type ) struct {};
25 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
26 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
27 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
28 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
29 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
30 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
31 | 
32 | /* Example code */
33 | 
34 | type exampleBr(type ) struct {
35 | 	x t();
36 | 	y t()
37 | };
38 | func (this exampleBr(type )) IfTT(type )() t() {
39 | 	return this.x.m()(this.y)
40 | };
41 | func (this exampleBr(type )) IfFF(type )() t() {
42 | 	return this.x
43 | };
44 | 
45 | type t(type ) struct { };
46 | func (x0 t(type )) m(type )(x1 t()) t() { return x1 };
47 | 
48 | type Ex(type ) struct {};
49 | func (d Ex(type )) example(type )(b Bool(), x t(), y t()) t() {
50 | 	return b.Cond(t())(exampleBr(){x, y}) // Main example, no type assertion
51 | 			.m()(t(){}) // Extra
52 | };
53 | func main() {
54 | 	//_ = Ex(){}.example()(TT(){}, t(){}, t(){})
55 | 	fmt.Printf("%#v", Ex(){}.example()(TT(){}, t(){}, t(){}))
56 | }
57 | 
--------------------------------------------------------------------------------
/examples/fgg/misc/compose/compose.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/misc/compose/compose.fgg
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | /* Base decls: Any, Booleans, Nautrals, Functions, Lists */
  8 | 
  9 | type Any(type ) interface {};
 10 | type ToAny(type ) struct { any Any() };
 11 | 
 12 | /* Booleans */
 13 | 
 14 | type Eq(type a Any()) interface { Equal(type )(that a) Bool() };
 15 | type Bool(type ) interface {
 16 | 	Not(type )() Bool();
 17 | 	Equal(type )(that Bool()) Bool();
 18 | 	Cond(type a Any())(br Branches(a)) a
 19 | };
 20 | type Branches(type a Any()) interface {
 21 | 	IfTT(type )() a;
 22 | 	IfFF(type )() a
 23 | };
 24 | type TT(type ) struct {};
 25 | type FF(type ) struct {};
 26 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
 27 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
 28 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
 29 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
 30 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
 31 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
 32 | 
 33 | /* Naturals */
 34 | 
 35 | type Nat(type ) interface {
 36 | 	Add(type )(n Nat()) Nat();
 37 | 	Equal(type )(n Nat()) Bool();
 38 | 	equalZero(type )() Bool();
 39 | 	equalSucc(type )(m Nat()) Bool()
 40 | };
 41 | type Zero(type ) struct {};
 42 | type Succ(type ) struct { pred Nat() };
 43 | func (m Zero(type )) Add(type )(n Nat()) Nat() { return n };
 44 | func (m Succ(type )) Add(type )(n Nat()) Nat() { return Succ(){m.pred.Add()(n)} };
 45 | func (m Zero(type )) Equal(type )(n Nat()) Bool() { return n.equalZero()() };
 46 | func (m Succ(type )) Equal(type )(n Nat()) Bool() { return n.equalSucc()(m.pred) };
 47 | func (n Zero(type )) equalZero(type )() Bool() { return TT(){} };
 48 | func (n Succ(type )) equalZero(type )() Bool() { return FF(){} };
 49 | func (n Zero(type )) equalSucc(type )(m Nat()) Bool() { return FF(){} };
 50 | func (n Succ(type )) equalSucc(type )(m Nat()) Bool() { return m.Equal()(n.pred) };
 51 | 
 52 | /* Functions */
 53 | 
 54 | type Func(type a Any(), b Any()) interface {
 55 | 	Apply(type )(x a) b
 56 | };
 57 | type incr(type ) struct {
 58 | 	n Nat()
 59 | };
 60 | func (this incr(type )) Apply(type )(x Nat()) Nat() { return x.Add()(this.n) };
 61 | type not(type ) struct {};
 62 | func (this not(type )) Apply(type )(x Bool()) Bool() { return x.Not()() };
 63 | type compose(type a Any(), b Any(), c Any()) struct {
 64 | 	f Func(a, b);
 65 | 	g Func(b, c)
 66 | };
 67 | func (this compose(type a Any(), b Any(), c Any())) Apply(type )(x a) c {
 68 | 	return this.g.Apply()(this.f.Apply()(x))
 69 | };
 70 | 
 71 | /* Lists */
 72 | 
 73 | type List(type a Eq(a)) interface {
 74 | 	Map(type b Eq(b))(f Func(a, b)) List(b);
 75 | 	Member(type )(x a) Bool()
 76 | };
 77 | type Nil(type a Eq(a)) struct {};
 78 | type Cons(type a Eq(a)) struct {
 79 | 	head a;
 80 | 	tail List(a)
 81 | };
 82 | func (xs Nil(type a Eq(a))) Map(type b Eq(b))(f Func(a, b)) List(b) {
 83 | 	return Nil(b){}
 84 | };
 85 | func (xs Cons(type a Eq(a))) Map(type b Eq(b))(f Func(a, b)) List(b) {
 86 | 	return Cons(b){f.Apply()(xs.head), xs.tail.Map(b)(f)}
 87 | };
 88 | //type memberBr(type b Eq(b)) struct {  // FIXME: alpha
 89 | type memberBr(type a Eq(a)) struct {
 90 | 	xs List(a);
 91 | 	x a
 92 | };
 93 | func (this memberBr(type a Eq(a))) IfTT(type )() Bool() { return TT(){} };
 94 | func (this memberBr(type a Eq(a))) IfFF(type )() Bool() { return this.xs.Member()(this.x) };
 95 | func (xs Nil(type a Eq(a))) Member(type )(x a) Bool() { return FF(){} };
 96 | func (xs Cons(type a Eq(a))) Member(type )(x a) Bool() { return x.Equal()(xs.head).Cond(Bool())(memberBr(a){xs, x}) };
 97 | 
 98 | /* Example code */
 99 | 
100 | type D(type ) struct {};
101 | func (d D(type )) _1(type )() Nat() { return Succ(){Zero(){}} };
102 | func (d D(type )) _2(type )() Nat() { return D(){}._1()().Add()(D(){}._1()()) };
103 | func (d D(type )) _3(type )() Nat() { return D(){}._2()().Add()(D(){}._1()()) };
104 | 
105 | func main() {
106 | 	//_ = 
107 | 	fmt.Printf("%#v",
108 | 	compose(Nat(), Nat(), Nat()){incr(){D(){}._1()()}, incr(){D(){}._2()()}}.
109 | 				Apply()(D(){}._3()()) // Main example (assertion unnecessary)
110 | 				.Add()(Zero(){}) // Extra
111 | 	)
112 | }
113 | 
--------------------------------------------------------------------------------
/examples/fgg/misc/graph/graph.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/misc/graph/graph.fgg
 2 | 
 3 | package main;
 4 | 
 5 | import "fmt";
 6 | 
 7 | 
 8 | type Any(type ) interface {};
 9 | type List(type a Any()) interface { /*snip*/ };
10 | 
11 | type Edge(type e Edge(e, v), v Vertex(e, v)) interface {
12 | 	Source(type )() v;
13 | 	Target(type )() v
14 | };
15 | type Vertex(type e Edge(e, v), v Vertex(e, v)) interface {
16 | 	Edges(type )() List(e)
17 | };
18 | type A(type ) struct {};
19 | func main() {
20 | 	//_ =
21 | 	fmt.Printf("%#v",
22 | 		A(){}
23 | 	)
24 | }
25 | 
--------------------------------------------------------------------------------
/examples/fgg/misc/irregular/irregular.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/misc/irregular/irregular.fgg
  2 | // or
  3 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -compile=tmp/fg/irregular/irregular.go -v fgg/examples/misc/irregular/irregular.fgg
  4 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/fg/irregular/irregular.go
  5 | 
  6 | package main;
  7 | 
  8 | import "fmt";
  9 | 
 10 | /* Base decls: Any, Booleans, Nautrals, Functions -- cut down versions */
 11 | 
 12 | type Any(type ) interface {};
 13 | 
 14 | /* Booleans */
 15 | 
 16 | type Bool(type ) interface {
 17 | 	Not(type )() Bool()
 18 | };
 19 | type TT(type ) struct {};
 20 | type FF(type ) struct {};
 21 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
 22 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
 23 | 
 24 | /* Naturals */
 25 | 
 26 | type Nat(type ) interface {
 27 | 	Add(type )(n Nat()) Nat()
 28 | };
 29 | type Zero(type ) struct {};
 30 | type Succ(type ) struct { pred Nat() };
 31 | func (m Zero(type )) Add(type )(n Nat()) Nat() { return n };
 32 | func (m Succ(type )) Add(type )(n Nat()) Nat() { return Succ(){m.pred.Add()(n)} };
 33 | 
 34 | /* Functions */
 35 | 
 36 | type Func(type a Any(), b Any()) interface {
 37 | 	Apply(type )(x a) b
 38 | };
 39 | type incr(type ) struct {
 40 | 	n Nat()
 41 | };
 42 | func (this incr(type )) Apply(type )(x Nat()) Nat() { return x.Add()(this.n) };
 43 | type not(type ) struct {};
 44 | func (this not(type )) Apply(type )(x Bool()) Bool() { return x.Not()() };
 45 | 
 46 | /* Balanced map using Pairs -- irregular (polymorphic recursion) */
 47 | 
 48 | type Pair(type a Any()) struct {
 49 | 	fst a;
 50 | 	snd a
 51 | };
 52 | type pairMap(type a Any()) struct {
 53 | 	f Func(a, a)
 54 | };
 55 | func (p pairMap(type a Any())) Apply(type )(x Pair(a)) Pair(a) {  // Func(Pair(a),Pair(a))
 56 | 	return Pair(a){ p.f.Apply()(x.fst), p.f.Apply()(x.snd) }
 57 | };
 58 | type Balanced(type a Any()) interface {
 59 | 	BalancedMap(type )(f Func(a, a)) Balanced(a)
 60 | };
 61 | type Leaf(type a Any()) struct {};
 62 | type Node(type a Any()) struct {
 63 | 	label a;
 64 | 	children Balanced(Pair(a))
 65 | };
 66 | func (leaf Leaf(type a Any())) BalancedMap(type )(f Func(a, a)) Balanced(a) {
 67 | 	return Leaf(a){}
 68 | };
 69 | func (node Node(type a Any())) BalancedMap(type )(f Func(a, a)) Balanced(a) {
 70 | 	return Node(a){f.Apply()(node.label), node.children.BalancedMap()(pairMap(a){f})}
 71 | };
 72 | 
 73 | /* Example */
 74 | 
 75 | type D(type ) struct {};
 76 | func (d D(type )) _0(type )() Nat() { return Zero(){} };
 77 | func (d D(type )) _1(type )() Nat() { return Succ(){D(){}._0()()} };
 78 | func (d D(type )) _2(type )() Nat() { return Succ(){D(){}._1()()} };
 79 | func (d D(type )) _3(type )() Nat() { return Succ(){D(){}._2()()} };
 80 | func (d D(type )) _4(type )() Nat() { return Succ(){D(){}._3()()} };
 81 | func (d D(type )) _5(type )() Nat() { return Succ(){D(){}._4()()} };
 82 | func (d D(type )) _6(type )() Nat() { return Succ(){D(){}._5()()} };
 83 | func (d D(type )) _7(type )() Nat() { return Succ(){D(){}._6()()} };
 84 | 
 85 | func main() { 
 86 | 	//_ =
 87 | 	fmt.Printf("%#v",
 88 | 		Node(Nat()){
 89 | 				D(){}._1()(),
 90 | 				Node(Pair(Nat())){
 91 | 					Pair(Nat()){D(){}._2()(), D(){}._3()()},
 92 | 					Node(Pair(Pair(Nat()))){
 93 | 						Pair(Pair(Nat())){
 94 | 							Pair(Nat()){D(){}._4()(), D(){}._5()()}, 
 95 | 							Pair(Nat()){D(){}._6()(), D(){}._7()()}
 96 | 						},
 97 | 						Leaf(Pair(Pair(Pair(Nat())))){}
 98 | 					}
 99 | 				}
100 | 			}.BalancedMap()(incr(){D(){}._1()()})
101 | 	)
102 | }
103 | 
104 | /*func main() {   // TODO: add test (monom)
105 | 	_ = Node(Nat()){
106 | 				D(){}._1()(),
107 | 				Leaf(Pair(Nat())){}
108 | 			}.BalancedMap()(incr(){D(){}._1()()})
109 | }*/
110 | 
--------------------------------------------------------------------------------
/examples/fgg/misc/map/map.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/misc/map/map.fgg
 2 | 
 3 | package main;
 4 | 
 5 | import "fmt";
 6 | 
 7 | /* Base decls: Any, Booleans, Nautrals, Functions, Lists */
 8 | 
 9 | type Any(type ) interface {};
10 | type ToAny(type ) struct { any Any() };
11 | 
12 | /* Booleans */
13 | 
14 | type Eq(type a Any()) interface { Equal(type )(that a) Bool() };
15 | type Bool(type ) interface {
16 | 	Not(type )() Bool();
17 | 	Equal(type )(that Bool()) Bool();
18 | 	Cond(type a Any())(br Branches(a)) a
19 | };
20 | type Branches(type a Any()) interface {
21 | 	IfTT(type )() a;
22 | 	IfFF(type )() a
23 | };
24 | type TT(type ) struct {};
25 | type FF(type ) struct {};
26 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
27 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
28 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
29 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
30 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
31 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
32 | 
33 | /* Functions */
34 | 
35 | type Func(type a Any(), b Any()) interface {
36 | 	Apply(type )(x a) b
37 | };
38 | type not(type ) struct {};
39 | func (this not(type )) Apply(type )(x Bool()) Bool() { return x.Not()() };
40 | type compose(type a Any(), b Any(), c Any()) struct {
41 | 	f Func(a, b);
42 | 	g Func(b, c)
43 | };
44 | func (this compose(type a Any(), b Any(), c Any())) Apply(type )(x a) c {
45 | 	return this.g.Apply()(this.f.Apply()(x))
46 | };
47 | 
48 | /* Lists */
49 | 
50 | type List(type a Eq(a)) interface {
51 | 	Map(type b Eq(b))(f Func(a, b)) List(b);
52 | 	Member(type )(x a) Bool()
53 | };
54 | type Nil(type a Eq(a)) struct {};
55 | type Cons(type a Eq(a)) struct {
56 | 	head a;
57 | 	tail List(a)
58 | };
59 | func (xs Nil(type a Eq(a))) Map(type b Eq(b))(f Func(a, b)) List(b) {
60 | 	return Nil(b){}
61 | };
62 | func (xs Cons(type a Eq(a))) Map(type b Eq(b))(f Func(a, b)) List(b) {
63 | 	return Cons(b){f.Apply()(xs.head), xs.tail.Map(b)(f)}
64 | };
65 | //type memberBr(type b Eq(b)) struct {  // Tests alpha
66 | type memberBr(type a Eq(a)) struct {  // FIXME: oblit
67 | 	xs List(a);
68 | 	x a
69 | };
70 | func (this memberBr(type a Eq(a))) IfTT(type )() Bool() { return TT(){} };
71 | func (this memberBr(type a Eq(a))) IfFF(type )() Bool() { return this.xs.Member()(this.x) };
72 | func (xs Nil(type a Eq(a))) Member(type )(x a) Bool() { return FF(){} };
73 | func (xs Cons(type a Eq(a))) Member(type )(x a) Bool() { return x.Equal()(xs.head).Cond(Bool())(memberBr(a){xs, x}) };
74 | 
75 | /* Example code */
76 | 
77 | func main() {
78 | 	// Submission version was missing a "}"
79 | 	//_ =
80 | 	fmt.Printf("%#v",
81 | 		Cons(Bool()){TT(){}, Cons(Bool()){FF(){}, Nil(Bool()){}}}.Map(Bool())(not(){}). // Main example
82 | 			(Cons(Bool())).head.Not()() // Extra, assertion not necessary
83 | 			//.(Cons(Bool())).head.(Bool()).Not()()
84 | 	)
85 | }
86 | 
--------------------------------------------------------------------------------
/examples/fgg/misc/monomorph/monomorph.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -monom -v fgg/examples/misc/monomorph/monomorph.fgg
 2 | // or
 3 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -compile=tmp/fg/monomorph/monomorph.go -v fgg/examples/misc/monomorph/monomorph.fgg
 4 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/fg/monomorph/monomoprh.go
 5 | 
 6 | package main;
 7 | 
 8 | import "fmt";
 9 | 
10 | /* Base decls: Any, Booleans, Nautrals, Functions -- cut down versions */
11 | 
12 | type Any(type ) interface {};
13 | 
14 | /* Booleans */
15 | 
16 | type Bool(type ) interface {
17 | 	Not(type )() Bool()
18 | };
19 | type TT(type ) struct {};
20 | type FF(type ) struct {};
21 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
22 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
23 | 
24 | /* Naturals */
25 | 
26 | type Nat(type ) interface {
27 | 	Add(type )(n Nat()) Nat()
28 | };
29 | type Zero(type ) struct {};
30 | type Succ(type ) struct { pred Nat() };
31 | func (m Zero(type )) Add(type )(n Nat()) Nat() { return n };
32 | func (m Succ(type )) Add(type )(n Nat()) Nat() { return Succ(){m.pred.Add()(n)} };
33 | 
34 | /* Functions */
35 | 
36 | type Func(type a Any(), b Any()) interface { Apply(type )(x a) b };
37 | 
38 | type incr(type ) struct { n Nat() };
39 | func (this incr(type )) Apply(type )(x Nat()) Nat() { return x.Add()(this.n) };
40 | 
41 | type not(type ) struct {};
42 | func (this not(type )) Apply(type )(x Bool()) Bool() { return x.Not()() };
43 | 
44 | /* Lists */
45 | 
46 | type List(type a Any()) interface {
47 | 	Map(type b Any())(f Func(a,b)) List(b)
48 | };
49 | type Nil(type a Any()) struct {};
50 | type Cons(type a Any()) struct { head a; tail List(a) };
51 | 
52 | func (xs Nil(type a Any())) Map(type b Any())(f Func(a,b)) List(b) { 
53 | 	return Nil(b){} 
54 | };
55 | func (xs Cons(type a Any())) Map(type b Any())(f Func(a,b)) List(b) {
56 | 	return Cons(b){f.Apply()(xs.head), xs.tail.Map(b)(f)}
57 | };
58 | 
59 | /* Example code */
60 | 
61 | type Pair(type a Any(), b Any()) struct { Fst a; Snd b };
62 | 
63 | type D(type ) struct {};
64 | func (d D(type )) _1(type )() Nat() { return Succ(){Zero(){}} };
65 | func (d D(type )) _2(type )() Nat() { return Succ(){D(){}._1()()} };
66 | func (d D(type )) _3(type )() Nat() { return Succ(){D(){}._2()()} };
67 | 
68 | func main() {
69 | 	//_ =
70 | 	fmt.Printf("%#v",
71 | 		Pair(List(Bool()), List(Nat())){
72 | 			Cons(Bool()){TT(){}, Cons(Bool()){FF(){}, Nil(Bool()){}}}
73 | 					.Map(Bool())(not(){}),
74 | 			Cons(Nat()){D(){}._1()(), Cons(Nat()){D(){}._2()(), Cons(Nat()){D(){}._3()(), Nil(Nat()){}}}}
75 | 					.Map(Nat())(incr(){D(){}._1()()})
76 | 		}
77 | 	)
78 | }
79 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/box/box.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg [-monomc=--] -v fgg/examples/monom/box/box.fgg
 2 | 
 3 | //$ go run github.com/rhu1/fgg -fgg -oblitc=tmp/test/fgr/box/box.go -v fgg/examples/monom/box/box.fgg
 4 | 
 5 | package main;
 6 | 
 7 | type Any(type ) interface {};
 8 | type Box(type a Any()) struct { f a };
 9 | //func (x0 Box(type a Any())) unbox(type )() a { return x0.f };
10 | 
11 | type D(type ) struct {};
12 | func (x0 D(type )) bad(type a Any())(x1 a)) Any() {
13 | 	return D(){}.bad(Box(a))(Box(a){x1})
14 | };  
15 | /*func (x0 D(type )) bad(type a Any())(x1 a)) a {
16 | 	return D(){}.bad(Box(a))(Box(a){x1}).unbox()()
17 | };*/
18 | 
19 | type A(type ) struct {};
20 | func main() { _ =  D(){}.bad(A())(A(){})  }
21 | 
22 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/box/box2.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -eval=10 -monomc=tmp/test/fg/monom/box/box2.go fgg/examples/monom/box/box2.fgg
 2 | 
 3 | package main;
 4 | 
 5 | type Any(type ) interface {};
 6 | type Box(type a Any()) struct { f a };
 7 | 
 8 | 
 9 | type D(type ) struct {};
10 | func (x0 D(type )) bad(type a Any())(x1 a)) Any() {
11 | 	return D(){}.bad(a)(x1)
12 | };  
13 | 
14 | type A(type ) struct {};
15 | func main() { _ =  D(){}.bad(A()) (   A(){} )  }
16 | 
17 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/ifacebox.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/misc/ifacebox.go -v fgg/examples/monom/misc/ifacebox.fgg
 2 | //$ go run github.com/rhu1/fgg -eval=-1 tmp/test/fg/misc/ifacebox.go
 3 | 
 4 | //$ go run github.com/rhu1/fgg -fgg -oblitc=tmp/test/fgr/monom/misc/ifacebox.fgr -v -oblit-eval=10 fgg/examples/monom/misc/ifacebox.fgg
 5 | 
 6 | package main;
 7 | 
 8 | import "fmt";
 9 | 
10 | type Any(type ) interface {};
11 | 
12 | type Func(type A Any(), B Any()) interface { apply(type )(a A) B };
13 | 
14 | type Box(type A Any()) interface {
15 | 	Map(type B Any())(f Func(A,B)) Box(B)
16 | };
17 | 
18 | type ABox(type A Any()) struct{
19 | 	value A
20 | };
21 | 
22 | 
23 | func (a ABox(type A Any())) Map(type B Any())(f Func(A,B)) Box(B) {
24 | 	return ABox(B){f.apply()(a.value)}
25 | };
26 | 
27 | type Dummy(type ) struct{};
28 | 
29 | type D(type ) struct {};
30 | type E(type ) struct {};
31 | 
32 | type DtoE(type ) struct {};
33 | func (x0 DtoE(type )) apply(type )(d D()) E() { return E(){} };
34 | 
35 | func (x Dummy(type )) takeBox(type )(b Box(D())) Any() {
36 | 	return b.Map(E())(DtoE(){})  // Map     // m(type a tau) ---> t\dagger
37 | };
38 | 
39 | func main() {
40 | 	//_ =
41 | 	fmt.Printf("%#v",
42 | 		Dummy(){}.takeBox()(ABox(D()){D(){}}) // ABox
43 | 	)
44 | }
45 | 
46 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ko/incompleteness-subtyping.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=-- -v fgg/examples/monom/misc/mono-ko/incompleteness-subtyping.go
 2 | 
 3 | // This is not monomorphisable !
 4 | // panic: Not monomorphisable, potential polymorphic recursion: [{SA m1}]
 5 | 
 6 | package main;
 7 | 
 8 | type Any(type ) interface {};
 9 | 
10 | type Dummy(type ) struct {};
11 | 
12 | type Box(type a Any()) struct {val a};
13 | 
14 | type Pair(type ) struct {fst Any(); snd Any()};
15 | 
16 | func (x Dummy(type )) useInterfaceA(type )(y IA()) S() {
17 | 	return y.m1(S())()
18 | };
19 | 
20 | type IA(type ) interface { m1(type a Any())() S()};
21 | 
22 | type S(type ) struct {};
23 | 
24 | type SA(type ) struct {};
25 | func (x SA(type )) m1(type a Any())() S() {return SA(){}.m1(Box(a))()};
26 | 
27 | type SB(type ) struct {};
28 | func (x SB(type )) m1(type a Any())() S() {return S(){}};
29 | 
30 | func main() { _ =
31 | 		Dummy(){}.useInterfaceA()(SB(){})
32 | 	}
33 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ko/monom-imp.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=-- -v fgg/examples/monom/misc/mono-ko/monom-imp.go
 2 | 
 3 | package main;
 4 | 
 5 | 
 6 | type Any(type ) interface {};
 7 | 
 8 | type A(type ) struct {};
 9 | 
10 | type Box(type a Any()) struct {};
11 | 
12 | type tI(type a Any()) interface {
13 | 	m(type b Any())(y tI(a)) A()
14 | };
15 | 
16 | type tSA(type a Any()) struct {};
17 | 
18 | func (x tSA(type a Any())) m(type b Any())(y tI(a)) A(){
19 | 	return y.m(Box(b))(y)
20 | };
21 | 
22 | type tSB(type a Any()) struct {};
23 | 
24 | func (x tSB(type a Any())) m(type b Any())(y tI(a)) A(){
25 | 	return A(){}
26 | };
27 | 
28 | 
29 | type tSC(type a Any()) struct {};
30 | func (x tSC(type a Any())) m(type b Any())(y tI(a)) A(){
31 | 	return y.m(Box(b))(y)
32 | };
33 | 
34 | 
35 | func (x Dummy) method() { tSA(A).m(tSA) }
36 | 
37 | func main() { _ =
38 | 	tSA(A()){}.m(A())(tSA(A()){})
39 | 
40 | }
41 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ko/mutual-poly-rec.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -v -monomc=-- fgg/examples/monom/misc/mono-ko/mutual-poly-rec.go
 2 | 
 3 | package main;
 4 | 
 5 | type Any(type ) interface {};
 6 | 
 7 | type Box(type a Any()) struct {};
 8 | 
 9 | type A(type ) struct {};
10 | 
11 | type B(type ) struct {};
12 | 
13 | func (x A(type )) m1(type a Any())() A(){
14 | 	return B(){}.m2(Box(a))()
15 | };
16 | 
17 | func (x B(type )) m2(type a Any())() A(){
18 | 	return A(){}.m1(a)()
19 | };
20 | 
21 | func main() { _ =  A(){}.m1(A())() }
22 | 
23 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ko/mutual-rec-iface.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -v -monomc=-- fgg/examples/monom/misc/mono-ko/mutual-poly-rec.go
 2 | 
 3 | // This is not monomorphisable
 4 | // Not monomorphisable, potential polymorphic recursion: [{A m1} {B m2}]
 5 | 
 6 | package main;
 7 | 
 8 | type Any(type ) interface {};
 9 | 
10 | type IBox(type a Any()) interface {};
11 | 
12 | /*
13 | IBox
14 | IBox>
15 | IBox>>>
16 | */
17 | 
18 | type A(type ) struct {};
19 | 
20 | type B(type ) struct {};
21 | 
22 | func (x A(type )) m1(type a Any())() A(){
23 | 	return B(){}.m2(IBox(a))()
24 | };
25 | 
26 | func (x B(type )) m2(type a Any())() A(){
27 | 	return A(){}.m1(a)()
28 | };
29 | 
30 | func main() { _ =  A(){}.m1(A())() }
31 | 
32 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ko/nested-fix.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -v -monomc=-- fgg/examples/monom/misc/mono-ko/nested-fix.go
 2 | 
 3 | package main;
 4 | type Any(type ) interface {};
 5 | type Int(type ) struct {};
 6 | type Box(type a Any()) struct { cell a };
 7 | 
 8 | type Arg(type a Any()) struct {};
 9 | 
10 | func (x Arg(type a Any())) mkNesting(type )(y a) a {
11 | 		return Arg(Box(a)){}.mkNesting()(Box(a){y}).cell
12 | 	};
13 | 
14 | func main() { _ = Arg(Int()){}.mkNesting()(Int(){}) }
15 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ko/two-type-param.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=-- -v fgg/examples/monom/misc/mono-ko/two-type-param.go
 2 | 
 3 | // Will not monomorphise
 4 | package main;
 5 | 
 6 | type Any(type ) interface {};
 7 | 
 8 | type Box(type a Any()) interface { unbox(type )() a};
 9 | 
10 | type SBox(type a Any()) struct {val a};
11 | 
12 | func (x SBox(type a Any())) unbox(type )() a {return x.val};
13 | 
14 | type A(type ) struct {};
15 | 
16 | func (x A(type )) m1(type a Any(), b Any())() A(){
17 | 	return A(){}.m1(Box(b), a)()
18 | };
19 | 
20 | 
21 | func main() { _ =  A(){}.m1(A(),A())() }
22 | 
23 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/Dispatcher.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/mono-ok/one-pass-prob.go fgg/examples/monom/misc/mono-ok/one-pass-prob.go
 2 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/test/fg/monom/misc/mono-ok/one-pass-prob.go
 3 | 
 4 | package main;
 5 | 
 6 | import "fmt";
 7 | 
 8 | type Any(type ) interface {};
 9 | 
10 | type Int(type ) struct {};
11 | 
12 | type Event(type ) interface{
13 | 	Process(type b Any())(y b) Int()
14 | };
15 | 
16 | type UIEvent(type ) struct {};
17 | 
18 | func (x UIEvent(type )) Process(type b Any())(y b) Int() {return Int(){}};
19 | 
20 | type Dispatcher(type ) struct{};
21 | 
22 | func (x Dispatcher(type )) Dispatch(type )(y Event()) Int() {
23 | 	return y.Process(Int())(Int(){}) // IA : MyFunction
24 | };
25 | 
26 | 
27 | func main() {
28 | 	//_ =
29 | 	fmt.Printf("%#v",
30 | 		Dispatcher(){}.Dispatch()(UIEvent(){})
31 | 	)
32 | }
33 | 
34 | 
35 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/Parameterised-Map.fgg:
--------------------------------------------------------------------------------
 1 | package main;
 2 | 
 3 | import "fmt";
 4 | 
 5 | type Any(type ) interface {};
 6 | 
 7 | type Int(type ) struct {};
 8 | type Bool(type ) struct {};
 9 | 
10 | type Func(type a Any(), b Any()) interface {
11 | 	apply(type )(x a) b
12 | };
13 | 
14 | type Bool2Int(type ) struct {};
15 | type ParamBox(type a Any()) struct {v1 a};
16 | func (x ParamBox(type a Any())) map(type b Any())(f Func(a,b)) Box(b) {return ParamBox(b){f.apply()(x.v1)}};
17 | 
18 | 
19 | func (x Bool2Int(type )) apply(type )(y Bool()) Int() {return Int(){} };
20 | 
21 | type Box(type a Any()) interface{
22 | 	map(type b Any())(f Func(a,b)) Box(b)
23 | 
24 | };
25 | 
26 | type IntBox(type ) struct {v1 Int()}; // IntBox <:
27 | func (x IntBox(type )) map(type b Any())(f Func(Int(),b)) Box(b) {return ParamBox(b){f.apply()(x.v1)}};
28 | 
29 | 
30 | type BoolBox(type ) struct {v1 Bool()}; // BoolBox <: IA(Bool())
31 | func (x BoolBox(type )) map(type b Any())(f Func(Bool(),b)) Box(b) {return ParamBox(b){f.apply()(x.v1)}};
32 | 
33 | 
34 | type Dummy(type ) struct{};
35 | 
36 | func (x Dummy(type )) CallFunctionBool(type )(y Box(Bool())) Box(Int()) {
37 | 	return y.map(Int())(Bool2Int(){})
38 | 
39 | };
40 | 
41 | 
42 | func main() {
43 | 	//_ =
44 | 	fmt.Printf("%#v",
45 | 		Dummy(){}.CallFunctionBool()(BoolBox(){Bool(){}})
46 | 	)
47 | }
48 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/alternate.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/mono-ok/alternate.go fgg/examples/monom/misc/mono-ok/alternate.go
 2 | //$ go run github.com/rhu1/fgg -eval=10 -v tmp/test/fg/monom/misc/mono-ok/alternate.go
 3 | 
 4 | // Should monomorphise
 5 | 
 6 | package main;
 7 | 
 8 | import "fmt";
 9 | 
10 | type Any(type ) interface {};
11 | 
12 | type Box(type a Any()) interface { unbox(type )() a};
13 | 
14 | type SBox(type a Any()) struct {val a};
15 | 
16 | func (x SBox(type a Any())) unbox(type )() a {return x.val};
17 | 
18 | type A(type ) struct {};
19 | 
20 | func (x A(type )) m1(type a Any())(y a) A(){
21 | 	return A(){}.m2(a, Box(a))(SBox(a){y})
22 | };
23 | 
24 | func (x A(type )) m2(type a Any(), b Box(a))(y Box(a)) A(){
25 | 	return A(){}.m1(a)(y.unbox()())
26 | };
27 | 
28 | func main() {
29 | 	//_ =
30 | 	fmt.Printf("%#v",
31 | 		A(){}.m1(A())(A(){})
32 | 	)
33 | }
34 | 
35 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/contamination.fgg:
--------------------------------------------------------------------------------
 1 | package main;
 2 | 
 3 | import "fmt";
 4 | 
 5 | type Any(type ) interface {};
 6 | type Bool(type ) struct {};
 7 | 
 8 | type Clothing(type a Any()) interface {
 9 | 	Wash(type )() Bool() ;
10 | 	Wear(type b Any())(y b) Bool()
11 | };
12 | 
13 | type Shirt(type ) struct{};
14 | 
15 | func (x Shirt(type )) Wash(type )() Bool() {return Bool(){}};
16 | func (x Shirt(type )) Wear(type b Any())(y b) Bool() {return Bool(){}};
17 | 
18 | type Tyre(type a Any()) interface {
19 | 	Inflate(type )() Bool() ;
20 | 	Wear(type b Any())(x b) Bool()
21 | };
22 | 
23 | type Bridgestone(type ) struct{};
24 | 
25 | func (x Bridgestone(type )) Inflate(type )() Bool() {return Bool(){}};
26 | func (x Bridgestone(type )) Wear(type b Any())(y b) Bool() {return Bool(){}};
27 | 
28 | 
29 | type Human(type ) struct {};
30 | type Road(type ) struct {};
31 | 
32 | 
33 | type Pair(type a Any(), b Any() ) struct {
34 | 	fst a;
35 | 	snd b
36 | };
37 | 
38 | 
39 | type Dummy(type ) struct {};
40 | func (x Dummy(type )) makePair(type )(c Clothing(Any()), t Tyre(Any())) Pair(Bool(), Bool()) {
41 | 	return 	Pair(Bool(), Bool()){c.Wear(Human())(Human(){}), t.Wear(Road())(Road(){})}
42 | };
43 | 
44 | 
45 | func main() {
46 | 	//_ =
47 | 	fmt.Printf("%#v",
48 | 		Dummy(){}.makePair()(Shirt(){}, Bridgestone(){})
49 | 	)
50 | }
51 | 
52 | 
53 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/i-closure-bad.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/mono-ok/i-closure-bad.go fgg/examples/monom/misc/mono-ok/i-closure-bad.go
 2 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/test/fg/monom/misc/mono-ok/i-closure-bad.go
 3 | 
 4 | // This is monomorphisable ! -- rename "-bad"
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | type Any(type ) interface {};
10 | 
11 | type Dummy(type ) struct {};
12 | 
13 | type Pair(type ) struct {fst Any(); snd Any()};
14 | 
15 | // we need IB <: IA here
16 | func (x Dummy(type )) useInterfaceA(type )(y IA()) IA() {
17 | 	return y.m1(S())() // m1() returns IB
18 | };
19 | 
20 | func (x Dummy(type )) useInterfaceB(type )(y IB()) Any() {
21 | 	return y.m2(S())()
22 | };
23 | 
24 | type IA(type ) interface { m1(type a Any())() IB()};
25 | type IB(type ) interface {
26 | 	m1(type a Any())() IB();   // IB.m1() never occurs => need I-closure()
27 | 	m2(type a Any())() IB() }; // IB <: IA
28 | 
29 | type S(type ) struct {};
30 | func (x S(type )) m1(type a Any())() IB() {return S(){}};
31 | func (x S(type )) m2(type a Any())() IB() {return S(){}};
32 | 
33 | func main() {
34 | 	//_ =
35 | 	fmt.Printf("%#v",
36 | 		Pair(){
37 | 			Dummy(){}.useInterfaceA()(S(){})
38 | 			,
39 | 			Dummy(){}.useInterfaceB()(S(){})
40 | 		}
41 | 	)
42 | }
43 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/i-closure.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/mono-ok/i-closure.go -v fgg/examples/monom/misc/mono-ok/i-closure.go
 2 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/test/fg/monom/misc/mono-ok/i-closure.go
 3 | 
 4 | // This is monomorphisable !
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | type Any(type ) interface {};
10 | 
11 | type Dummy(type ) struct {};
12 | 
13 | func (x Dummy(type )) useInterface(type )(y IA()) Any() {
14 | 	return y.m1(S())()
15 | };
16 | 
17 | // // Adding this fixes the panic
18 | // func (x Dummy(type )) useInterfaceB(type )(y IB()) Any() {
19 | // 	return y.m1(S())()
20 | // };
21 | 
22 | type IA(type ) interface { m1(type a Any())() S() };
23 | type IB(type ) interface { m1(type a Any())() S();  m2(type a Any())() S()};
24 | 
25 | type S(type ) struct {};
26 | func (x S(type )) m1(type a Any())() S() {return S(){}};
27 | func (x S(type )) m2(type a Any())() S() {return S(){}};
28 | 
29 | func main() {
30 | 	//_ =
31 | 	fmt.Printf("%#v",
32 | 		Dummy(){}.useInterface()(S(){}).(IB())
33 | 	)
34 | }
35 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/iface-embedding-simple.fgg:
--------------------------------------------------------------------------------
 1 | // go run github.com/rhu1/fgg -fgg -eval=-1 -monomc=tmp/test/fg/monom/misc/iface-embedding-simple.go fgg/examples/monom/misc/iface-embedding-simple.go
 2 | // go run github.com/rhu1/fgg -eval=-1 tmp/test/fg/monom/misc/iface-embedding-simple.go
 3 | 
 4 | 
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | type Any(type ) interface {};
10 | 
11 | type DummyFunc(type A Any(), B Any()) interface { apply(type )(a A) B };
12 | 
13 | type Func(type A Any(), B Any()) interface { DummyFunc(A,B) };
14 | 
15 | 
16 | 
17 | type Dummy(type ) struct{};
18 | 
19 | type D(type ) struct {};
20 | type E(type ) struct {};
21 | 
22 | type DtoE(type ) struct {};
23 | func (x0 DtoE(type )) apply(type )(d D()) E() { return E(){} };
24 | 
25 | 
26 | func main() {
27 | 	//_ =
28 | 	fmt.Printf("%#v",
29 | 		DtoE(){}.apply()(D(){})
30 | 	)
31 | }
32 | 
33 | 
34 | 
35 | 
36 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/iface-embedding.fgg:
--------------------------------------------------------------------------------
 1 | // go run github.com/rhu1/fgg -fgg -eval=-1 -monomc=tmp/test/fg/monom/misc/iface-embedding.go fgg/examples/monom/misc/iface-embedding.go
 2 | // go run github.com/rhu1/fgg -eval=-1 tmp/test/fg/monom/misc/iface-embedding.go
 3 | 
 4 | package main;
 5 | 
 6 | import "fmt";
 7 | 
 8 | type Any(type ) interface {};
 9 | 
10 | type DummyFunc(type X Any(), Y Any()) interface { apply(type )(a X) Y };
11 | 
12 | type Func(type X Any(), Y Any()) interface { DummyFunc(X,Y) };
13 | 
14 | type Box(type X Any()) interface {
15 | 	Map(type Y Any())(f Func(X,Y)) Box(Y)
16 | };
17 | 
18 | type ABox(type X Any()) struct{
19 | 	value X
20 | };
21 | 
22 | 
23 | func (a ABox(type X Any())) Map(type Y Any())(f Func(X,Y)) Box(Y) {
24 | 	return ABox(Y){f.apply()(a.value)}
25 | };
26 | 
27 | type Dummy(type ) struct{};
28 | 
29 | type D(type ) struct {};
30 | type E(type ) struct {};
31 | 
32 | type DtoE(type ) struct {};
33 | func (x0 DtoE(type )) apply(type )(d D()) E() { return E(){} };
34 | 
35 | func (x Dummy(type )) takeBox(type )(b Box(D())) Any() {
36 | 	return b.Map(E())(DtoE(){})  // Map     // m(type a tau) ---> t\dagger
37 | };
38 | 
39 | func main() {
40 | 	//_ =
41 | 	fmt.Printf("%#v",
42 | 		Dummy(){}.takeBox()(ABox(D()){D(){}}) // ABox
43 | 	)
44 | }
45 | 
46 | 
47 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/meth-clash.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/mono-ok/meth-clash.go fgg/examples/monom/misc/mono-ok/meth-clash.go
 2 | //$ go run github.com/rhu1/fgg -eval=7 -v tmp/test/fg/monom/misc/mono-ok/meth-clash.go
 3 | 
 4 | package main;
 5 | 
 6 | import "fmt";
 7 | 
 8 | type Any(type ) interface {};
 9 | 
10 | type Top(type ) interface {};
11 | 
12 | type Dummy(type ) struct {};
13 | 
14 | func (x Dummy(type )) toAny(type )(y Any()) Any() {
15 | 	return y.(Any())
16 | };
17 | 
18 | type Triple(type ) struct{ fst Any(); snd Any(); thd Any()};
19 | 
20 | type Foo(type ) interface { m(type a Top())() Dummy() };
21 | 
22 | // S 
32 | };
33 | 
34 | 
35 | func main() {
36 | 	//_ =
37 | 	fmt.Printf("%#v",
38 | 		Dummy(){}.CallFunction()(SA(){})
39 | 	)
40 | }
41 | 
42 | 
43 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/param-meth-cast.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/mono-ok/param-meth-cast.go fgg/examples/monom/misc/mono-ok/param-meth-cast.go
 2 | //$ go run github.com/rhu1/fgg -eval=2 -v tmp/test/fg/monom/misc/mono-ok/param-meth-cast.go
 3 | 
 4 | // This illustrates the need to preserve the full method sets when monomorphising
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | type Any(type ) interface {};
10 | 
11 | type S(type ) struct {};
12 | 
13 | type T(type ) struct {};
14 | 
15 | type Foo(type ) interface { m(type a Any())(x a, y S()) Any() }; // m(x Any, y S)
16 | 
17 | type Bar(type ) interface { m(type a Any())(x a, y T()) Any() }; // m(x Any, y T)
18 | 
19 | type V(type ) struct {};
20 | 
21 | func (x V(type )) toAny(type )(y Foo()) Any() {
22 | 	return y.(Any())
23 | };
24 | 
25 | // V <: Foo
26 | func (x V(type )) m(type a Any())(z a, y S()) Any() { // m(x Any, y S)
27 | 	return z.(Any())
28 | };
29 | 
30 | func main() {
31 | 	//_ =
32 | 	fmt.Printf("%#v",
33 | 		V(){}.toAny()(V(){}).(Bar()) // cast fails
34 | 	)
35 | }
36 | 
37 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/poly-rec-iface.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/mono-ok/poly-rec-iface.go fgg/examples/monom/misc/mono-ok/poly-rec-iface.go
 2 | //$ go run github.com/rhu1/fgg -eval=10 -v tmp/test/fg/monom/misc/mono-ok/poly-rec-iface.go
 3 | 
 4 | // This is monomorphisable !
 5 | package main;
 6 | 
 7 | import "fmt";
 8 | 
 9 | type Any(type ) interface {};
10 | 
11 | type Dummy(type ) struct {};
12 | 
13 | func (x Dummy(type )) toAny(type )(y Any()) Any() {
14 | 	return y
15 | };
16 | 
17 | type I(type a Any()) interface { m(type b Any())() I(I(b))};
18 | 
19 | type A(type ) struct {};
20 | 
21 | func (x A(type )) m(type b Any())() I(I(b)) {
22 | 	//return Dummy(){}.toAny()(A(){}).(I(a)).m(a)()
23 | 	return Dummy(){}.toAny()(A(){}).(I(b)).m(b)()
24 | };
25 | 
26 | func main() {
27 | 	//_ =
28 | 	fmt.Printf("%#v",
29 | 		A(){}.m(A())()
30 | 	)
31 | }
32 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/polyrec/lasso.fgg:
--------------------------------------------------------------------------------
 1 | // Should monomorphise (m3() is not called, m2() is not recursive and m1() is not poly-rec)
 2 | 
 3 | package main;
 4 | 
 5 | type Any(type ) interface {};
 6 | 
 7 | type Box(type a Any()) struct {};
 8 | 
 9 | type A(type ) struct {};
10 | 
11 | type B(type ) struct {};
12 | 
13 | func (x A(type )) m1(type a Any())() A(){
14 | 	return A(){}.m1(a)()
15 | };
16 | 
17 | func (x B(type )) m2(type a Any())() A(){
18 | 	return A(){}.m1(Box(a))()
19 | };
20 | 
21 | func (x A(type )) m3(type a Any())() A(){
22 | 	return A(){}.m3(Box(a))()
23 | };
24 | 
25 | func main() { _ =  B(){}.m2(A())() }
26 | 
27 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/rcver-iface.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/monom/misc/rcver-iface.go fgg/examples/monom/misc/rcver-iface.go
 2 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/test/fg/monom/misc/rcver-iface.go
 3 | 
 4 | package main;
 5 | 
 6 | import "fmt";
 7 | 
 8 | /* SA{} is an IA(Int()) and SB an IA(Bool()). In a "method-driven
 9 |  * mono, the call to CallFunctionBool observes that MyFunction(Int) is called
10 |  * on an IA(Bool) and so all possible MyFunction(Int) would be mono'd. This
11 |  * would potentially mono MyFunction(Int) on SA{} which is not an IA(Bool). */
12 | 
13 | type Any(type ) interface {};
14 | 
15 | type Int(type ) struct {};
16 | type Bool(type ) struct {};
17 | 
18 | type IA(type a Any()) interface{
19 | 	MyFunction(type b Any())(x b) a // Instance found: MyFunction(x Int) Bool
20 | 	// Map(type b Any())() // JL to be try with List(a)
21 | };
22 | 
23 | type SA(type ) struct {}; // SA <: IA(Int())
24 | 
25 | // Can't "monomorphise" this method to match "MyFunction(x Int) Bool"
26 | func (x SA(type )) MyFunction(type b Any())(y b) Int() {return Int(){}}; // MyFunction(y Int) : !!!Bool!!!!
27 | 
28 | 
29 | type SB(type ) struct {}; // SB <: IA(Bool())
30 | func (x SB(type )) MyFunction(type b Any())(y b) Bool() {return Bool(){}}; // MyFunction(y Int) : Bool
31 | 
32 | 
33 | type Dummy(type ) struct{};
34 | 
35 | func (x Dummy(type )) CallFunctionBool(type )(y IA(Bool())) Bool() {
36 | 	return y.MyFunction(Int())(Int(){}) // MyFunction: Int -> Bool
37 | 	// IA(Bool) : MyFunction : Bool
38 | };
39 | 
40 | // func (x Dummy(type )) CallFunctionInt(type )(y IA(Int())) Int() {
41 | // 	return y.MyFunction(Int())(Int(){})
42 | // };
43 | 
44 | // type Pair(type a Any(), b Any() ) struct {
45 | // 	fst a;
46 | // 	snd b
47 | // };
48 | 
49 | func main() {
50 | 	//_ =
51 | 	fmt.Printf("%#v",
52 | 		Dummy(){}.CallFunctionBool()(SB(){})
53 | 	)
54 | 
55 | 	// Pair(Int(),Bool()){Dummy(){}.CallFunctionInt()(SA(){}),
56 | 	// 	   Dummy(){}.CallFunctionBool()(SB(){})
57 | 	// 	}
58 | 
59 | 	// Dummy(){}.CallFunctionInt()(SA(){})
60 | 
61 | 	// Pair(Bool(),Int()){
62 | 	// 	Dummy(){}.CallFunctionBool()(SB(){}),
63 | 	// 	SA(){}.MyFunction(Int())(Int(){})}
64 | 
65 | 
66 | 	// Pair(Bool(),IA(Int())){
67 | 	// 	Dummy(){}.CallFunctionBool()(SB(){}),
68 | 	// 	SA(){}
69 | 	// }.snd.MyFunction(Bool())(Bool(){})
70 | 
71 | }
72 | 
73 | 
74 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/mono-ok/struct-poly-rec.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/fg/monom/misc/mono-ok/struct-prob.go -v fgg/examples/monom/misc/mono-ok/struct-poly-rec.go
 2 | //
 3 | //$ go run github.com/rhu1/fgg -eval=-1 tmp/fg/monom/misc/mono-ok/struct-poly-rec.go
 4 | 
 5 | // This should be monomorphisable!
 6 | package main;
 7 | 
 8 | import "fmt";
 9 | 
10 | 
11 | 
12 | type Any(type ) interface {};
13 | 
14 | type A(type ) struct {};
15 | 
16 | type B(type a Any()) struct {val C(a)};
17 | //type B(type a Any()) struct {val C(C(a))};
18 | type C(type a Any()) struct {};
19 | //type C(type a Any()) struct {val B(a)};
20 | 
21 | func (x B(type a Any())) m(type )() B(C(a)) {  // Recurisve type nesting
22 | 	return B(C(a)){C(C(a)){}}  // N.B. but no actual recursion
23 | };
24 | /*
25 | func (x A(type )) m(type a Any())() C(B(a)) {
26 | 	return A(){}.m(a)()
27 | };
28 | */
29 | /*func (x A(type )) m(type a Any())() C(B(a)) {
30 | 	return A(){}.m(a)()
31 | };*/
32 | 
33 | func main() {
34 | 	//_ =
35 | 	fmt.Printf("%#v",
36 | 		B(A()){C(A()){}}.m()()
37 | 	)
38 | }
39 | //func main() { _ =  A(){}.m(A())() }
40 | 
41 | 
42 | /*
43 | 
44 | for all:
45 | type t(type ) struct T,
46 | then t never appears in fields*(T) (transitively / inter-procedurally for struct)
47 | 
48 | */
49 | 
50 | 
51 | 
52 | 
53 | 
54 | 
55 | 
56 | 
57 | 
58 | 
59 | 
60 | 
61 | 
62 | 
63 | 
64 | /*type Box(type a Any()) struct {val IBox(a)};
65 | type IBox(type a Any()) interface { box() IBox(IBox(a)); unbox() a};
66 | 
67 | type Cons(a Any()) struct { head a; tail List(a)};
68 | type Nil(a Any()) struct { };*/
69 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/todo/ifacebox-nomethparam.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/misc/ifacebox-nomethparam.go -v fgg/examples/monom/misc/ifacebox-nomethparam.fgg
 2 | //$ go run github.com/rhu1/fgg -eval=-1 tmp/test/fg/misc/ifacebox-nomethparam.go
 3 | 
 4 | //$ go run github.com/rhu1/fgg -fgg -oblitc=tmp/test/fgr/monom/misc/ifacebox-nomethparam.fgr -v -oblit-eval=10 fgg/examples/monom/misc/ifacebox-nomethparam.fgg
 5 | 
 6 | package main;
 7 | 
 8 | import "fmt";
 9 | 
10 | type Any(type ) interface {};
11 | 
12 | type Func(type A Any(), B Any()) interface { apply(type )(a A) B };
13 | 
14 | type Box(type A Any()) interface {
15 |      	      Make(type )() Box(A)
16 | };
17 | 
18 | type ABox(type A Any()) struct{
19 | };
20 | 
21 | 
22 | func (a ABox(type A Any())) Make(type )() Box(A) {
23 | 	return ABox(A){}
24 | };
25 | 
26 | 
27 | /* BBox is unused */
28 | type BBox(type A Any()) struct{
29 | };
30 | 
31 | 
32 | func (a BBox(type A Any())) Make(type )() Box(A) {
33 | 	return BBox(A){}
34 | };
35 | 
36 | 
37 | 
38 | // TODO: bad recursive struct, what is the actual intent?
39 | type E(type ) struct {val D()};
40 | type D(type ) struct {val E()};
41 | 
42 | 
43 | type Dummy(type ) struct{};
44 | func (x Dummy(type )) doSomething(type )(y Box(E())) Box(E()) {
45 |      	return y.Make()()
46 | };
47 | 
48 | 
49 | func (x Dummy(type )) makeBox(type A Any())() Box(A){
50 |  return ABox(A){}
51 | };
52 | 
53 | func main() {
54 | 	//_ =
55 | 	fmt.Printf("%#v",
56 | 		Dummy(){}.doSomething()(Dummy(){}.makeBox(E())())
57 | 		// Dummy(){}.doSomething()(ABox(E()){})
58 | 	)
59 | }
60 | 
61 | 
62 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/todo/nested.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=-- -v fgg/examples/monom/misc/nested.go
 2 | 
 3 | package main;
 4 | 
 5 | type Any(type ) interface {};
 6 | 
 7 | type Int(type ) struct {};
 8 | 
 9 | type Box(type a Any()) struct { cell a};
10 | 
11 | 
12 | type NestedCons(type a Any()) struct {
13 | 	val a;
14 | 	tail Box(a)
15 | };
16 | 
17 | 
18 | 
19 | type Arg(type a Any()) struct {};
20 | 
21 | 
22 | // Badly typed (correct) -- cf. nested-fix
23 | func (x Arg(type a Any())) mkNesting(type )(y a) Box(a) {
24 | 	return NestedCons(a){
25 | 		y,
26 | 		//Arg(Box(y)){}.mkNesting()(Box(y){y})  // FIXME: ImplsDelta blows up
27 | 		 Arg(Box(a)){}.mkNesting()(Box(a){y})
28 | 		 }.tail
29 | };
30 | 
31 | func main() { _ =  Arg(){}.mkNesting(Int())(Int(){}) }
32 | 
33 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/todo/struct-poly-rec-variant.fgg:
--------------------------------------------------------------------------------
 1 | // This is not monomorphisable but not well-formed (recursive struct)
 2 | package main;
 3 | 
 4 | type Any(type ) interface {};
 5 | 
 6 | type A(type ) struct {};
 7 | 
 8 | type B(type a Any()) struct {val C(a)};
 9 | 
10 | type C(type a Any()) struct {val B(B(a))}; // no monom-related prob with val B(a) (but ruled out by real Go)
11 | 
12 | func (x A(type )) m(type a Any())() B(a) {
13 | 	return A(){}.m(a)()
14 | };
15 | 
16 | func main() { _ =  A(){}.m(A())() }
17 | 
--------------------------------------------------------------------------------
/examples/fgg/monom/misc/todo/struct-prob.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/fg/monom/misc/struct-prob.go -v fgg/examples/monom/misc/struct-prob.go
 2 | 
 3 | package main;
 4 | 
 5 | 
 6 | type Any(type ) interface {};
 7 | 
 8 | type Int(type ) struct {};
 9 | type Bool(type ) struct {};
10 | 
11 | 
12 | type Box(type a Any()) interface {
13 | 	get(type )() a
14 | };
15 | 
16 | type ABox(type a Any()) struct{ val a };
17 | 
18 | func (x ABox(type a Any())) get(type )() a {return x.val};
19 | 
20 | type Func(type a Any(), b Any()) interface {
21 | 	apply(type )(x a) b
22 | };
23 | 
24 | 
25 | //type ABox(type a Any()) struct{ val a };
26 | 
27 | type BadBox(type a Any()) struct {
28 | 		val Box(Box(Box(a)))
29 | 		};
30 | 
31 | type Dummy(type ) struct{};
32 | 
33 | func (x Dummy(type )) toAny(type )(y Any()) Any() {
34 | 	return y.(Any())
35 | 
36 | };
37 | 
38 | 
39 | func main() { _ =
40 | 	Dummy(){}.toAny()(ABox(Bool()){Bool(){}}).(BadBox(Int()))
41 | 
42 | }
43 | 
--------------------------------------------------------------------------------
/examples/fgg/oopsla20/fig10/nomono.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/fg/oopsla20/fig10/nomono.go -v fgg/examples/oopsla20/fig10/nomono.fgg
  2 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/fg/oopsla20/fig10/nomono.go
  3 | 
  4 | package main;
  5 | 
  6 | import "fmt";
  7 | 
  8 | 
  9 | /* Library: Bool, Int */
 10 | 
 11 | type Bool(type ) interface {
 12 | 	Not(type )() Bool();
 13 | 	Equal(type )(that Bool()) Bool();
 14 | 	Cond(type a Any())(br Branches(a)) a
 15 | };
 16 | type Branches(type a Any()) interface {
 17 | 	IfTT(type )() a;
 18 | 	IfFF(type )() a
 19 | };
 20 | type TT(type ) struct {};
 21 | type FF(type ) struct {};
 22 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
 23 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
 24 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
 25 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
 26 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
 27 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
 28 | 
 29 | type Int(type ) interface {
 30 | 	Inc(type )() Int();
 31 | 	Dec(type )() Int();
 32 | 	Equal(type )(x Int()) Bool();
 33 | 	EqualZero(type )() Bool();
 34 | 	EqualNonZero(type )(x Int()) Bool();
 35 | 	Add(type )(x Int()) Int();
 36 | 	Gt(type )(x Int()) Bool();
 37 | 	IsNeg(type )() Bool()
 38 | };
 39 | 
 40 | type Zero(type ) struct {};
 41 | func (x0 Zero(type )) Inc(type )() Int() { return Pos(){x0} };
 42 | func (x0 Zero(type )) Dec(type )() Int() { return Neg(){x0} };
 43 | func (x0 Zero(type )) Equal(type )(x Int()) Bool() { return x.EqualZero()() };
 44 | func (x0 Zero(type )) EqualZero(type )() Bool() { return TT(){} };
 45 | func (x0 Zero(type )) EqualNonZero(type )(x Int()) Bool() { return FF(){} };
 46 | func (x0 Zero(type )) Add(type )(x Int()) Int() { return x };
 47 | func (x0 Zero(type )) Gt(type )(x Int()) Bool() { return x.IsNeg()() };
 48 | func (x0 Zero(type )) IsNeg(type )() Bool() { return FF(){} };
 49 | 
 50 | type Pos(type ) struct { dec Int() };
 51 | func (x0 Pos(type )) Inc(type )() Int() { return Pos(){x0} };
 52 | func (x0 Pos(type )) Dec(type )() Int() { return x0.dec };
 53 | func (x0 Pos(type )) Equal(type )(x Int()) Bool() { return x0.EqualNonZero()(x) };
 54 | func (x0 Pos(type )) EqualZero(type )() Bool() { return FF(){} };
 55 | func (x0 Pos(type )) EqualNonZero(type )(x Int()) Bool() { return x.Equal()(x0.dec) };
 56 | func (x0 Pos(type )) Add(type )(x Int()) Int() { return x0.dec.Add()(x.Inc()()) };
 57 | func (x0 Pos(type )) Gt(type )(x Int()) Bool() { return x0.dec.Gt()(x.Dec()()) };
 58 | func (x0 Pos(type )) IsNeg(type )() Bool() { return FF(){} };
 59 | 
 60 | type Neg(type ) struct { inc Int() };
 61 | func (x0 Neg(type )) Inc(type )() Int() { return x0.inc };
 62 | func (x0 Neg(type )) Dec(type )() Int() { return Neg(){x0} };
 63 | func (x0 Neg(type )) Equal(type )(x Int()) Bool() { return x0.EqualNonZero()(x) };
 64 | func (x0 Neg(type )) EqualZero(type )() Bool() { return FF(){} };
 65 | func (x0 Neg(type )) EqualNonZero(type )(x Int()) Bool() { return x.Equal()(x0.inc) };
 66 | func (x0 Neg(type )) Add(type )(x Int()) Int() { return x0.inc.Add()(x.Dec()()) };
 67 | func (x0 Neg(type )) Gt(type )(x Int()) Bool() { return x0.inc.Gt()(x.Inc()()) };
 68 | func (x0 Neg(type )) IsNeg(type )() Bool() { return TT(){} };
 69 | 
 70 | type Ints(type ) struct {};
 71 | func (d Ints(type )) _1(type )() Int() { return Pos(){Zero(){}} };
 72 | func (d Ints(type )) _2(type )() Int() { return d._1()().Add()(d._1()()) };
 73 | func (d Ints(type )) _3(type )() Int() { return d._2()().Add()(d._1()()) };
 74 | func (d Ints(type )) _4(type )() Int() { return d._3()().Add()(d._1()()) };
 75 | func (d Ints(type )) _5(type )() Int() { return d._4()().Add()(d._1()()) };
 76 | func (d Ints(type )) _6(type )() Int() { return d._5()().Add()(d._1()()) };
 77 | func (d Ints(type )) __1(type )() Int() { return Neg(){Zero(){}} };
 78 | func (d Ints(type )) __2(type )() Int() { return d.__1()().Add()(d.__1()()) };
 79 | func (d Ints(type )) __3(type )() Int() { return d.__2()().Add()(d.__1()()) };
 80 | func (d Ints(type )) __4(type )() Int() { return d.__3()().Add()(d.__1()()) };
 81 | func (d Ints(type )) __5(type )() Int() { return d.__4()().Add()(d.__1()()) };
 82 | 
 83 | 
 84 | /* Example code */
 85 | 
 86 | type Any(type ) interface {};
 87 | 
 88 | type Box(type a Any()) struct {
 89 | 	value a
 90 | };
 91 | 
 92 | type nestBr(type a Any()) struct {
 93 | 	box Box(a);
 94 | 	n Int()
 95 | };
 96 | func (this nestBr(type a Any())) IfTT(type )() Any() { return this.box };
 97 | func (this nestBr(type a Any())) IfFF(type )() Any() {
 98 | 	return Box(Box(a)){this.box}.Nest()(this.n.Add()(Ints(){}.__1()()))  // Cf. below
 99 | 	//return Box(Any()){this.box}.Nest()(this.n.Add()(Ints(){}._1()()))
100 | };
101 | 
102 | func (this Box(type a Any())) Nest(type )(n Int()) Any() {
103 | 	return n.EqualZero()().Cond(Any())(nestBr(a){this, n})
104 | };
105 | 
106 | 
107 | type D(type ) struct { };
108 | 
109 | func main() {
110 | 	fmt.Printf("%#v", Box(D()){D(){}}.Nest()(Ints(){}._3()()))
111 | }
112 | 
113 | 
--------------------------------------------------------------------------------
/examples/fgg/oopsla20/fig19/dispatcher.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -monomc=tmp/test/fg/oopsla20/fig19/dispatcher.go fgg/examples/oopsla20/fig19/dispatcher.go
 2 | //$ go run github.com/rhu1/fgg -eval=-1 -v tmp/test/fg/oopsla20/fig19/dispatcher.go
 3 | 
 4 | package main;
 5 | 
 6 | import "fmt";
 7 | 
 8 | type Any(type ) interface {};
 9 | 
10 | type Int(type ) struct {};
11 | 
12 | type Event(type ) interface{
13 | 	Process(type b Any())(y b) Int()
14 | };
15 | 
16 | type UIEvent(type ) struct {};
17 | 
18 | func (x UIEvent(type )) Process(type b Any())(y b) Int() {return Int(){}};
19 | 
20 | type Dispatcher(type ) struct{};
21 | 
22 | func (x Dispatcher(type )) Dispatch(type )(y Event()) Int() {
23 | 	return y.Process(Int())(Int(){}) // IA : MyFunction
24 | };
25 | 
26 | 
27 | func main() {
28 | 	//_ =
29 | 	fmt.Printf("%#v",
30 | 		Dispatcher(){}.Dispatch()(UIEvent(){})
31 | 	)
32 | }
33 | 
34 | 
35 | 
--------------------------------------------------------------------------------
/examples/fgg/oopsla20/fig4/functions.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/oopsla20/fig4/functions.fgg
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | /* Library: Bool, Int */
  8 | 
  9 | type Bool(type ) interface {
 10 | 	Not(type )() Bool();
 11 | 	Equal(type )(that Bool()) Bool();
 12 | 	Cond(type a Any())(br Branches(a)) a
 13 | };
 14 | type Branches(type a Any()) interface {
 15 | 	IfTT(type )() a;
 16 | 	IfFF(type )() a
 17 | };
 18 | type TT(type ) struct {};
 19 | type FF(type ) struct {};
 20 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
 21 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
 22 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
 23 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
 24 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
 25 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
 26 | 
 27 | type Int(type ) interface {
 28 | 	Inc(type )() Int();
 29 | 	Dec(type )() Int();
 30 | 	Add(type )(x Int()) Int();
 31 | 	Gt(type )(x Int()) Bool();
 32 | 	IsNeg(type )() Bool()
 33 | };
 34 | 
 35 | type Zero(type ) struct {};
 36 | func (x0 Zero(type )) Inc(type )() Int() { return Pos(){x0} };
 37 | func (x0 Zero(type )) Dec(type )() Int() { return Neg(){x0} };
 38 | func (x0 Zero(type )) Add(type )(x Int()) Int() { return x };
 39 | func (x0 Zero(type )) Gt(type )(x Int()) Bool() { return x.IsNeg()() };
 40 | func (x0 Zero(type )) IsNeg(type )() Bool() { return FF(){} };
 41 | 
 42 | type Pos(type ) struct { dec Int() };
 43 | func (x0 Pos(type )) Inc(type )() Int() { return Pos(){x0} };
 44 | func (x0 Pos(type )) Dec(type )() Int() { return x0.dec };
 45 | func (x0 Pos(type )) Add(type )(x Int()) Int() { return x0.dec.Add()(x.Inc()()) };
 46 | func (x0 Pos(type )) Gt(type )(x Int()) Bool() { return x0.dec.Gt()(x.Dec()()) };
 47 | func (x0 Pos(type )) IsNeg(type )() Bool() { return FF(){} };
 48 | 
 49 | type Neg(type ) struct { inc Int() };
 50 | func (x0 Neg(type )) Inc(type )() Int() { return x0.inc };
 51 | func (x0 Neg(type )) Dec(type )() Int() { return Neg(){x0} };
 52 | func (x0 Neg(type )) Add(type )(x Int()) Int() { return x0.inc.Add()(x.Dec()()) };
 53 | func (x0 Neg(type )) Gt(type )(x Int()) Bool() { return x0.inc.Gt()(x.Inc()()) };
 54 | func (x0 Neg(type )) IsNeg(type )() Bool() { return TT(){} };
 55 | 
 56 | type Ints(type ) struct {};
 57 | func (d Ints(type )) _1(type )() Int() { return Pos(){Zero(){}} };
 58 | func (d Ints(type )) _2(type )() Int() { return d._1()().Add()(d._1()()) };
 59 | func (d Ints(type )) _3(type )() Int() { return d._2()().Add()(d._1()()) };
 60 | func (d Ints(type )) __1(type )() Int() { return Neg(){Zero(){}} };
 61 | func (d Ints(type )) __2(type )() Int() { return d.__1()().Add()(d.__1()()) };
 62 | func (d Ints(type )) __3(type )() Int() { return d.__2()().Add()(d.__1()()) };
 63 | func (d Ints(type )) __4(type )() Int() { return d.__3()().Add()(d.__1()()) };
 64 | func (d Ints(type )) __5(type )() Int() { return d.__4()().Add()(d.__1()()) };
 65 | 
 66 | 
 67 | /* Later example */
 68 | 
 69 | type Eq(type a Eq(a)) interface {
 70 | 	Equal(type )(that a) Bool()
 71 | };
 72 | 
 73 | 
 74 | /* Example code */
 75 | 
 76 | type Any(type ) interface {};
 77 | type Function(type a Any(), b Any()) interface {
 78 | 	Apply(type )(x a) b
 79 | };
 80 | type incr(type ) struct { n Int() };
 81 | func (this incr(type )) Apply(type )(x Int()) Int() {
 82 | 	return x.Add()(this.n)
 83 | };
 84 | type pos(type ) struct {};  // We already have IsNeg, though
 85 | func (this pos(type )) Apply(type )(x Int()) Bool() {
 86 | 	return x.Gt()(Zero(){})
 87 | };
 88 | 
 89 | type compose(type a Any(), b Any(), c Any()) struct {
 90 | 	f Function(a, b);
 91 | 	g Function(b, c)
 92 | };
 93 | func (this compose(type a Any(), b Any(), c Any())) 
 94 | 			Apply(type )(x a) c {
 95 | 	return this.g.Apply()(this.f.Apply()(x))
 96 | };
 97 | 
 98 | 
 99 | func main() {
100 | 	/*var f Function(int, bool) =
101 | 				compose(int, int, bool){incr{-5}, pos{}}
102 | 	var b bool = f.Apply(3)*/
103 | 	fmt.Printf("%#v", compose(Int(), Int(), Bool()){incr(){Ints(){}.__5()()} , pos(){}}.  
104 | 			Apply()(Ints(){}._3()()))
105 | }
106 | 
--------------------------------------------------------------------------------
/examples/fgg/oopsla20/fig5/equality.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/oopsla20/fig5/equality.fgg
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | /* Library: Bool, Int */
  8 | 
  9 | type Bool(type ) interface {
 10 | 	Not(type )() Bool();
 11 | 	Equal(type )(that Bool()) Bool();
 12 | 	Cond(type a Any())(br Branches(a)) a;
 13 | 	And(type )(x Bool()) Bool()
 14 | };
 15 | type Branches(type a Any()) interface {
 16 | 	IfTT(type )() a;
 17 | 	IfFF(type )() a
 18 | };
 19 | type TT(type ) struct {};
 20 | type FF(type ) struct {};
 21 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
 22 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
 23 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
 24 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
 25 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
 26 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
 27 | func (this TT(type )) And(type )(x Bool()) Bool() { return x };
 28 | //func (this FF(type )) And(type )(x Bool) Bool() { return this };  // FIXME: Bool
 29 | func (this FF(type )) And(type )(x Bool()) Bool() { return this };
 30 | 
 31 | type Zero(type ) struct {};
 32 | func (x0 Zero(type )) Inc(type )() Int() { return Pos(){x0} };
 33 | func (x0 Zero(type )) Dec(type )() Int() { return Neg(){x0} };
 34 | func (x0 Zero(type )) Add(type )(x Int()) Int() { return x };
 35 | func (x0 Zero(type )) Gt(type )(x Int()) Bool() { return x.IsNeg()() };
 36 | func (x0 Zero(type )) IsNeg(type )() Bool() { return FF(){} };
 37 | func (x0 Zero(type )) IsZero(type )() Bool() { return TT(){} };
 38 | func (x0 Zero(type )) Ieq(type )(x Int()) Bool() { return x.IsZero()() };
 39 | 
 40 | type Pos(type ) struct { dec Int() };
 41 | func (x0 Pos(type )) Inc(type )() Int() { return Pos(){x0} };
 42 | func (x0 Pos(type )) Dec(type )() Int() { return x0.dec };
 43 | func (x0 Pos(type )) Add(type )(x Int()) Int() { return x0.dec.Add()(x.Inc()()) };
 44 | func (x0 Pos(type )) Gt(type )(x Int()) Bool() { return x0.dec.Gt()(x.Dec()()) };
 45 | func (x0 Pos(type )) IsNeg(type )() Bool() { return FF(){} };
 46 | func (x0 Pos(type )) IsZero(type )() Bool() { return FF(){} };
 47 | func (x0 Pos(type )) Ieq(type )(x Int()) Bool() { return x0.dec.Ieq()(x.Dec()()) };
 48 | 
 49 | type Neg(type ) struct { inc Int() };
 50 | func (x0 Neg(type )) Inc(type )() Int() { return x0.inc };
 51 | func (x0 Neg(type )) Dec(type )() Int() { return Neg(){x0} };
 52 | func (x0 Neg(type )) Add(type )(x Int()) Int() { return x0.inc.Add()(x.Dec()()) };
 53 | func (x0 Neg(type )) Gt(type )(x Int()) Bool() { return x0.inc.Gt()(x.Inc()()) };
 54 | func (x0 Neg(type )) IsNeg(type )() Bool() { return TT(){} };
 55 | func (x0 Neg(type )) IsZero(type )() Bool() { return FF(){} };
 56 | func (x0 Neg(type )) Ieq(type )(x Int()) Bool() { return x0.inc.Ieq()(x.Inc()()) };
 57 | 
 58 | type Ints(type ) struct {};
 59 | func (d Ints(type )) _1(type )() Int() { return Pos(){Zero(){}} };
 60 | func (d Ints(type )) _2(type )() Int() { return d._1()().Add()(d._1()()) };
 61 | func (d Ints(type )) _3(type )() Int() { return d._2()().Add()(d._1()()) };
 62 | func (d Ints(type )) __1(type )() Int() { return Neg(){Zero(){}} };
 63 | func (d Ints(type )) __2(type )() Int() { return d.__1()().Add()(d.__1()()) };
 64 | func (d Ints(type )) __3(type )() Int() { return d.__2()().Add()(d.__1()()) };
 65 | func (d Ints(type )) __4(type )() Int() { return d.__3()().Add()(d.__1()()) };
 66 | func (d Ints(type )) __5(type )() Int() { return d.__4()().Add()(d.__1()()) };
 67 | 
 68 | 
 69 | /* Example code */
 70 | 
 71 | type Any(type ) interface {};
 72 | type Eq(type a Eq(a)) interface {
 73 | 	Equal(type )(that a) Bool()
 74 | };
 75 | type Int(type ) interface {
 76 | 	Inc(type )() Int();
 77 | 	Dec(type )() Int();
 78 | 	Add(type )(x Int()) Int();
 79 | 	Gt(type )(x Int()) Bool();
 80 | 	IsNeg(type )() Bool();
 81 | 	IsZero(type )() Bool();
 82 | 	Ieq(type )(x Int()) Bool();
 83 | 	//Equal(type )(that Int) Bool()  // FIXME: panic: Type param Int unknown in context: string:string]
 84 | 	Equal(type )(that Int()) Bool()
 85 | };
 86 | func (this Zero(type )) Equal(type )(that Int()) Bool() {
 87 | 	return this.Ieq()(that)
 88 | };
 89 | func (this Pos(type )) Equal(type )(that Int()) Bool() {
 90 | 	return this.Ieq()(that)
 91 | };
 92 | func (this Neg(type )) Equal(type )(that Int()) Bool() {
 93 | 	return this.Ieq()(that)
 94 | };
 95 | type Pair(type a Any(), b Any()) struct {
 96 | 	left a;
 97 | 	right b
 98 | };
 99 | func (this Pair(type a Eq(a), b Eq(b))) Equal(type )(that Pair(a,b)) Bool() {
100 | 	return this.left.Equal()(that.left).And()(this.right.Equal()(that.right))
101 | };
102 | func main() {
103 | 	/*var i, j Int = 1, 2
104 | 	var p Pair(Int, Int) = Pair(Int, Int){i, j}
105 | 	var _ bool = p.Equal(p) // true*/
106 | 	fmt.Printf("%#v", Pair(Int(), Int()){Ints(){}._1()(), Ints(){}._2()()}.
107 | 			Equal()(Pair(Int(), Int()){Ints(){}._1()(), Ints(){}._2()()}))
108 | }
109 | 
--------------------------------------------------------------------------------
/examples/fgg/oopsla20/fig6/lists.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/oopsla20/fig6/lists.fgg
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | /* Library: Bool, Int */
  8 | 
  9 | type Bool(type ) interface {
 10 | 	Not(type )() Bool();
 11 | 	Equal(type )(that Bool()) Bool();
 12 | 	Cond(type a Any())(br Branches(a)) a
 13 | };
 14 | type Branches(type a Any()) interface {
 15 | 	IfTT(type )() a;
 16 | 	IfFF(type )() a
 17 | };
 18 | type TT(type ) struct {};
 19 | type FF(type ) struct {};
 20 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
 21 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
 22 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
 23 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
 24 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
 25 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
 26 | 
 27 | type Int(type ) interface {
 28 | 	Inc(type )() Int();
 29 | 	Dec(type )() Int();
 30 | 	Add(type )(x Int()) Int();
 31 | 	Gt(type )(x Int()) Bool();
 32 | 	IsNeg(type )() Bool();
 33 | 
 34 | 	Equal(type )(x Int()) Bool();
 35 | 	EqualZero(type )() Bool();
 36 | 	EqualNonZero(type )(x Int()) Bool()
 37 | };
 38 | 
 39 | type Zero(type ) struct {};
 40 | func (x0 Zero(type )) Inc(type )() Int() { return Pos(){x0} };
 41 | func (x0 Zero(type )) Dec(type )() Int() { return Neg(){x0} };
 42 | func (x0 Zero(type )) Add(type )(x Int()) Int() { return x };
 43 | func (x0 Zero(type )) Gt(type )(x Int()) Bool() { return x.IsNeg()() };
 44 | func (x0 Zero(type )) IsNeg(type )() Bool() { return FF(){} };
 45 | 
 46 | type Pos(type ) struct { dec Int() };
 47 | func (x0 Pos(type )) Inc(type )() Int() { return Pos(){x0} };
 48 | func (x0 Pos(type )) Dec(type )() Int() { return x0.dec };
 49 | func (x0 Pos(type )) Add(type )(x Int()) Int() { return x0.dec.Add()(x.Inc()()) };
 50 | func (x0 Pos(type )) Gt(type )(x Int()) Bool() { return x0.dec.Gt()(x.Dec()()) };
 51 | func (x0 Pos(type )) IsNeg(type )() Bool() { return FF(){} };
 52 | 
 53 | type Neg(type ) struct { inc Int() };
 54 | func (x0 Neg(type )) Inc(type )() Int() { return x0.inc };
 55 | func (x0 Neg(type )) Dec(type )() Int() { return Neg(){x0} };
 56 | func (x0 Neg(type )) Add(type )(x Int()) Int() { return x0.inc.Add()(x.Dec()()) };
 57 | func (x0 Neg(type )) Gt(type )(x Int()) Bool() { return x0.inc.Gt()(x.Inc()()) };
 58 | func (x0 Neg(type )) IsNeg(type )() Bool() { return TT(){} };
 59 | 
 60 | type Ints(type ) struct {};
 61 | func (d Ints(type )) _1(type )() Int() { return Pos(){Zero(){}} };
 62 | func (d Ints(type )) _2(type )() Int() { return d._1()().Add()(d._1()()) };
 63 | func (d Ints(type )) _3(type )() Int() { return d._2()().Add()(d._1()()) };
 64 | func (d Ints(type )) _4(type )() Int() { return d._3()().Add()(d._1()()) };
 65 | func (d Ints(type )) _5(type )() Int() { return d._4()().Add()(d._1()()) };
 66 | func (d Ints(type )) _6(type )() Int() { return d._5()().Add()(d._1()()) };
 67 | func (d Ints(type )) __1(type )() Int() { return Neg(){Zero(){}} };
 68 | func (d Ints(type )) __2(type )() Int() { return d.__1()().Add()(d.__1()()) };
 69 | func (d Ints(type )) __3(type )() Int() { return d.__2()().Add()(d.__1()()) };
 70 | func (d Ints(type )) __4(type )() Int() { return d.__3()().Add()(d.__1()()) };
 71 | func (d Ints(type )) __5(type )() Int() { return d.__4()().Add()(d.__1()()) };
 72 | 
 73 | 
 74 | /* Prev. example */
 75 | 
 76 | type Any(type ) interface {};
 77 | type Function(type a Any(), b Any()) interface {
 78 | 	Apply(type )(x a) b
 79 | };
 80 | type incr(type ) struct { n Int() };
 81 | func (this incr(type )) Apply(type )(x Int()) Int() {
 82 | 	return x.Add()(this.n)
 83 | };
 84 | type pos(type ) struct {};
 85 | func (this pos(type )) Apply(type )(x Int()) Bool() {
 86 | 	return x.Gt()(Zero(){})
 87 | };
 88 | 
 89 | 
 90 | /* Example code */
 91 | 
 92 | type Eq(type a Eq(a)) interface {
 93 | 	Equal(type )(that a) Bool()
 94 | };
 95 | /*func (this int) Equal(that int) bool {
 96 | 	return this == that
 97 | };
 98 | func (this bool) Equal(that bool) bool {
 99 | 	return this == that
100 | };*/
101 | func (x0 Zero(type )) Equal(type )(x Int()) Bool() { return x.EqualZero()() };
102 | func (x0 Zero(type )) EqualZero(type )() Bool() { return TT(){} };
103 | func (x0 Zero(type )) EqualNonZero(type )(x Int()) Bool() { return FF(){} };
104 | func (x0 Pos(type )) Equal(type )(x Int()) Bool() { return x0.EqualNonZero()(x) };
105 | func (x0 Pos(type )) EqualZero(type )() Bool() { return FF(){} };
106 | func (x0 Pos(type )) EqualNonZero(type )(x Int()) Bool() { return x.Equal()(x0.dec) };
107 | func (x0 Neg(type )) Equal(type )(x Int()) Bool() { return x0.EqualNonZero()(x) };
108 | func (x0 Neg(type )) EqualZero(type )() Bool() { return FF(){} };
109 | func (x0 Neg(type )) EqualNonZero(type )(x Int()) Bool() { return x.Equal()(x0.inc) };
110 | 
111 | type List(type a Any()) interface {
112 | 	Map(type b Any())(f Function(a, b)) List(b)
113 | };
114 | type Nil(type a Any()) struct {};
115 | type Cons(type a Any()) struct {
116 | 	head a;
117 | 	tail List(a)
118 | };
119 | func (xs Nil(type a Any())) 
120 | 			/*Map(type b Any())(f Function(a, b)) List(b) {
121 | 	return Nil(b){}*/
122 | 			Map(type c Any())(f Function(a, c)) List(c) {
123 | 	return Nil(c){}
124 | };
125 | func (xs Cons(type a Any())) 
126 | 			Map(type b Any())(f Function(a, b)) List(b) {
127 | 	return Cons(b){f.Apply()(xs.head), xs.tail.Map(b)(f)}
128 | };
129 | 
130 | 
131 | func main() {
132 | 	/*var xs List(int) =
133 | 			Cons(int){3, Cons(int){6, Nil(int){}}}
134 | 	var ys List(int) = xs.Map(int)(incr{-5})
135 | 	var zs List(bool) = ys.Map(bool)(pos{})*/
136 | 	fmt.Printf("%#v", Cons(Int()){Ints(){}._3()(), Cons(Int()){Ints(){}._6()(), Nil(Int()){}}}.  
137 | 				Map(Int())(incr(){Ints(){}.__5()()}).  
138 | 				Map(Bool())(pos(){}))
139 | }
140 | 
--------------------------------------------------------------------------------
/examples/fgg/oopsla20/fig7/graph.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/oopsla20/fig7/graph.fgg
 2 | 
 3 | package main;
 4 | 
 5 | import "fmt";
 6 | 
 7 | /* Prev. examples */
 8 | 
 9 | type Any(type ) interface {};
10 | type Function(type a Any(), b Any()) interface {
11 | 	Apply(type )(x a) b
12 | };
13 | 
14 | type List(type a Any()) interface {
15 | 	Map(type b Any())(f Function(a, b)) List(b)
16 | };
17 | type Nil(type a Any()) struct {};
18 | type Cons(type a Any()) struct {
19 | 	head a;
20 | 	tail List(a)
21 | };
22 | func (xs Nil(type a Any())) 
23 | 			Map(type b Any())(f Function(a, b)) List(b) {
24 | 	return Nil(b){}
25 | };
26 | func (xs Cons(type a Any())) 
27 | 			Map(type b Any())(f Function(a, b)) List(b) {
28 | 	return Cons(b){f.Apply()(xs.head), xs.tail.Map(b)(f)}
29 | };
30 | 
31 | 
32 | /* Example code */
33 | 
34 | type Edge(type e Edge(e, v), v Vertex(e, v)) interface {
35 | 	Source(type )() v;
36 | 	Target(type )() v
37 | };
38 | type Vertex(type e Edge(e, v), v Vertex(e, v)) interface {
39 | 	Edges(type )() List(e)
40 | };
41 | 
42 | type A(type ) struct {};
43 | func main() {
44 | 	fmt.Printf("%#v", A(){})
45 | }
46 | 
--------------------------------------------------------------------------------
/examples/fgg/oopsla20/fig8/expression.fgg:
--------------------------------------------------------------------------------
  1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/oopsla20/fig8/expression.fgg
  2 | 
  3 | package main;
  4 | 
  5 | import "fmt";
  6 | 
  7 | 
  8 | /* Library: Bool, Int */
  9 | 
 10 | type Bool(type ) interface {
 11 | 	Not(type )() Bool();
 12 | 	Equal(type )(that Bool()) Bool();
 13 | 	Cond(type a Any())(br Branches(a)) a
 14 | };
 15 | type Branches(type a Any()) interface {
 16 | 	IfTT(type )() a;
 17 | 	IfFF(type )() a
 18 | };
 19 | type TT(type ) struct {};
 20 | type FF(type ) struct {};
 21 | func (this TT(type )) Not(type )() Bool() { return FF(){} };
 22 | func (this FF(type )) Not(type )() Bool() { return TT(){} };
 23 | func (this TT(type )) Equal(type )(that Bool()) Bool() { return that };
 24 | func (this FF(type )) Equal(type )(that Bool()) Bool() { return that.Not()() };
 25 | func (this TT(type )) Cond(type a Any())(br Branches(a)) a { return br.IfTT()() };
 26 | func (this FF(type )) Cond(type a Any())(br Branches(a)) a { return br.IfFF()() };
 27 | 
 28 | type Int(type ) interface {
 29 | 	Inc(type )() Int();
 30 | 	Dec(type )() Int();
 31 | 	Equal(type )(x Int()) Bool();
 32 | 	EqualZero(type )() Bool();
 33 | 	EqualNonZero(type )(x Int()) Bool();
 34 | 	Add(type )(x Int()) Int();
 35 | 	Gt(type )(x Int()) Bool();
 36 | 	IsNeg(type )() Bool();
 37 | 	String(type )() string  // !!!
 38 | };
 39 | 
 40 | type Zero(type ) struct {};
 41 | func (x0 Zero(type )) Inc(type )() Int() { return Pos(){x0} };
 42 | func (x0 Zero(type )) Dec(type )() Int() { return Neg(){x0} };
 43 | func (x0 Zero(type )) Equal(type )(x Int()) Bool() { return x.EqualZero()() };
 44 | func (x0 Zero(type )) EqualZero(type )() Bool() { return TT(){} };
 45 | func (x0 Zero(type )) EqualNonZero(type )(x Int()) Bool() { return FF(){} };
 46 | func (x0 Zero(type )) Add(type )(x Int()) Int() { return x };
 47 | func (x0 Zero(type )) Gt(type )(x Int()) Bool() { return x.IsNeg()() };
 48 | func (x0 Zero(type )) IsNeg(type )() Bool() { return FF(){} };
 49 | 
 50 | type Pos(type ) struct { dec Int() };
 51 | func (x0 Pos(type )) Inc(type )() Int() { return Pos(){x0} };
 52 | func (x0 Pos(type )) Dec(type )() Int() { return x0.dec };
 53 | func (x0 Pos(type )) Equal(type )(x Int()) Bool() { return x0.EqualNonZero()(x) };
 54 | func (x0 Pos(type )) EqualZero(type )() Bool() { return FF(){} };
 55 | func (x0 Pos(type )) EqualNonZero(type )(x Int()) Bool() { return x.Equal()(x0.dec) };
 56 | func (x0 Pos(type )) Add(type )(x Int()) Int() { return x0.dec.Add()(x.Inc()()) };
 57 | func (x0 Pos(type )) Gt(type )(x Int()) Bool() { return x0.dec.Gt()(x.Dec()()) };
 58 | func (x0 Pos(type )) IsNeg(type )() Bool() { return FF(){} };
 59 | 
 60 | type Neg(type ) struct { inc Int() };
 61 | func (x0 Neg(type )) Inc(type )() Int() { return x0.inc };
 62 | func (x0 Neg(type )) Dec(type )() Int() { return Neg(){x0} };
 63 | func (x0 Neg(type )) Equal(type )(x Int()) Bool() { return x0.EqualNonZero()(x) };
 64 | func (x0 Neg(type )) EqualZero(type )() Bool() { return FF(){} };
 65 | func (x0 Neg(type )) EqualNonZero(type )(x Int()) Bool() { return x.Equal()(x0.inc) };
 66 | func (x0 Neg(type )) Add(type )(x Int()) Int() { return x0.inc.Add()(x.Dec()()) };
 67 | func (x0 Neg(type )) Gt(type )(x Int()) Bool() { return x0.inc.Gt()(x.Inc()()) };
 68 | func (x0 Neg(type )) IsNeg(type )() Bool() { return TT(){} };
 69 | 
 70 | type Ints(type ) struct {};
 71 | func (d Ints(type )) _1(type )() Int() { return Pos(){Zero(){}} };
 72 | func (d Ints(type )) _2(type )() Int() { return d._1()().Add()(d._1()()) };
 73 | func (d Ints(type )) _3(type )() Int() { return d._2()().Add()(d._1()()) };
 74 | func (d Ints(type )) _4(type )() Int() { return d._3()().Add()(d._1()()) };
 75 | func (d Ints(type )) _5(type )() Int() { return d._4()().Add()(d._1()()) };
 76 | func (d Ints(type )) _6(type )() Int() { return d._5()().Add()(d._1()()) };
 77 | func (d Ints(type )) __1(type )() Int() { return Neg(){Zero(){}} };
 78 | func (d Ints(type )) __2(type )() Int() { return d.__1()().Add()(d.__1()()) };
 79 | func (d Ints(type )) __3(type )() Int() { return d.__2()().Add()(d.__1()()) };
 80 | func (d Ints(type )) __4(type )() Int() { return d.__3()().Add()(d.__1()()) };
 81 | func (d Ints(type )) __5(type )() Int() { return d.__4()().Add()(d.__1()()) };
 82 | 
 83 | 
 84 | /* Assumption */
 85 | 
 86 | // N.B. monomorphises to "String<>", not "String" -- see Num().String below
 87 | func (x0 Zero(type )) String(type )() string { return fmt.Sprintf("%v", x0) };
 88 | func (x0 Pos(type )) String(type )() string { return fmt.Sprintf("%v", x0) };
 89 | func (x0 Neg(type )) String(type )() string { return fmt.Sprintf("%v", x0) };
 90 |   /* N.B. incompatible with test-monom-against-go textual output check,
 91 |   	 because %v in Go just prints "{}", while F(G)G StructLit String()
 92 |   	 prints the type name.  Similarly for "%#v", Go prints the struct name,
 93 |   	 but F(G)G this includes the StructLit struct itself. */
 94 | 
 95 | 
 96 | /* Prev. example */
 97 | 
 98 | type Any(type ) interface {};
 99 | 
100 | 
101 | /* Example code */
102 | 
103 | type Evaler(type ) interface {
104 |   Eval(type )() Int()
105 | };
106 | 
107 | type Num(type ) struct {
108 |   value Int()
109 | };
110 | 
111 | func (e Num(type )) Eval(type )() Int() {
112 |   return e.value
113 | };
114 | 
115 | type Plus(type a Any()) struct {
116 |   left a;
117 |   right a
118 | };
119 | 
120 | func (e Plus(type a Evaler())) Eval(type )() Int() {
121 |   return e.left.Eval()().Add()(e.right.Eval()())
122 | };
123 | 
124 | 
125 | type Stringer(type ) interface {
126 |   String(type )() string
127 | };
128 | 
129 | func (e Num(type )) String(type )() string {
130 |   return 
131 |   	  //fmt.Sprintf("%d", e.value)
132 |   	  fmt.Sprintf("%v", e.value.String()())  // N.B. Monormorphises to String<>(), not just String() -- cf. above
133 |   /* N.B. similar issue to above, %#v here prints the StringLit in F(G)G vs.
134 |    * the actual string in Go */
135 | };
136 | 
137 | func (e Plus(type a Stringer())) String(type )() string {
138 |   return fmt.Sprintf("(%s+%s)",
139 |   		e.left.String()(), e.right.String()())
140 | };
141 | 
142 | type Expr(type ) interface {
143 |   Evaler();
144 |   Stringer()
145 | };
146 | 
147 | 
148 | func main() {
149 |   /*var e Expr = Plus(Expr){Num{1}, {Num{2}}
150 | 	var v Int = e.Eval() // 3
151 | 	var s string = e.String() //"(1+2)"*/
152 |   //_ = Plus(Expr()){Num(){Ints(){}._1()()}, Num(){Ints(){}._2()()}}.Eval()()
153 |   fmt.Printf("%#v", Plus(Expr()){Num(){Ints(){}._1()()}, Num(){Ints(){}._2()()}}.String()())
154 | }
155 | 
156 | 
--------------------------------------------------------------------------------
/examples/fgg/stupidcast/stupidcast.fgg:
--------------------------------------------------------------------------------
 1 | //$ go run github.com/rhu1/fgg -fgg -eval=-1 -v fgg/examples/stupidcast/stupidcast.fgg
 2 | 
 3 | package main;
 4 | type Any(type ) interface {};
 5 | type ToAny(type ) struct { any Any() };
 6 | type IA(type ) interface { m1(type a IA())() IA() };
 7 | type A(type ) struct {};
 8 | func (x0 A(type )) m1(type a IA())() IA() { return x0 };
 9 | type B(type a IA()) struct {};
10 | func (x0 B(type a IA())) m2(type )(x1 a) Any() { return x1 };
11 | func main() { _ = ToAny(){B(A()){}}.any.(ToAny()) }
12 | 
--------------------------------------------------------------------------------
/examples/fgr/oblit/booleans/booleans.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type Eq interface { HasRep; Equal(that HasRep) HasRep };
 5 | type Bool interface { HasRep; Not() HasRep; Equal(that HasRep) HasRep; Cond(a Rep, br HasRep) HasRep };
 6 | type Branches interface { HasRep; IfTT() HasRep; IfFF() HasRep };
 7 | type TT struct { };
 8 | func (x0 TT) getRep() Rep { return TT[[]] };
 9 | type FF struct { };
10 | func (x0 FF) getRep() Rep { return FF[[]] };
11 | func (this TT) Not() HasRep { return FF{} };
12 | func (this FF) Not() HasRep { return TT{} };
13 | func (this TT) Equal(that HasRep) HasRep { return that.(Bool) };
14 | func (this FF) Equal(that HasRep) HasRep { return that.(Bool).Not().(Bool) };
15 | func (this TT) Cond(a Rep, br HasRep) HasRep { return br.(Branches).IfTT().(Any) };
16 | func (this FF) Cond(a Rep, br HasRep) HasRep { return br.(Branches).IfFF().(Any) };
17 | type exampleBr struct { x t; y t };
18 | func (x0 exampleBr) getRep() Rep { return exampleBr[[]] };
19 | func (this exampleBr) IfTT() HasRep { return this.x.m(this.y).(t) };
20 | func (this exampleBr) IfFF() HasRep { return this.x };
21 | type t struct { };
22 | func (x0 t) getRep() Rep { return t[[]] };
23 | func (x0 t) m(x1 HasRep) HasRep { return x1.(t) };
24 | type Ex struct { };
25 | func (x0 Ex) getRep() Rep { return Ex[[]] };
26 | func (d Ex) example(b HasRep, x HasRep, y HasRep) HasRep { return b.(Bool).Cond(t[[]], exampleBr{x.(t), y.(t)}).(t).m(t{}).(t) };
27 | func main() { _ = Ex{}.example(TT{}, t{}, t{}).(t) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/box/box.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type Box struct { a Rep; f Any };
 5 | func (x0 Box) getRep() Rep { return Box[[x0.a]] };
 6 | type D struct { };
 7 | func (x0 D) getRep() Rep { return D[[]] };
 8 | func (x0 D) bad(a Rep, x1 HasRep) HasRep { return D{}.bad(Box[[a]], Box{a, x1.(Any)}).(Any) };
 9 | type A struct { };
10 | func (x0 A) getRep() Rep { return A[[]] };
11 | func main() { _ = D{}.bad(A[[]], A{}).(Any) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/box/box2.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type Box struct { a Rep; f Any };
 5 | func (x0 Box) getRep() Rep { return Box[[x0.a]] };
 6 | type D struct { };
 7 | func (x0 D) getRep() Rep { return D[[]] };
 8 | func (x0 D) bad(a Rep, x1 HasRep) HasRep { return D{}.bad(a, x1.(Any)).(Any) };
 9 | type A struct { };
10 | func (x0 A) getRep() Rep { return A[[]] };
11 | func main() { _ = D{}.bad(A[[]], A{}).(Any) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/compose/compose.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type ToAny struct { any Any };
 5 | func (x0 ToAny) getRep() Rep { return ToAny[[]] };
 6 | type Eq interface { HasRep; Equal(that HasRep) HasRep };
 7 | type Bool interface { HasRep; Not() HasRep; Equal(that HasRep) HasRep; Cond(a Rep, br HasRep) HasRep };
 8 | type Branches interface { HasRep; IfTT() HasRep; IfFF() HasRep };
 9 | type TT struct { };
10 | func (x0 TT) getRep() Rep { return TT[[]] };
11 | type FF struct { };
12 | func (x0 FF) getRep() Rep { return FF[[]] };
13 | func (this TT) Not() HasRep { return FF{} };
14 | func (this FF) Not() HasRep { return TT{} };
15 | func (this TT) Equal(that HasRep) HasRep { return that.(Bool) };
16 | func (this FF) Equal(that HasRep) HasRep { return that.(Bool).Not().(Bool) };
17 | func (this TT) Cond(a Rep, br HasRep) HasRep { return br.(Branches).IfTT().(Any) };
18 | func (this FF) Cond(a Rep, br HasRep) HasRep { return br.(Branches).IfFF().(Any) };
19 | type Nat interface { HasRep; Add(n HasRep) HasRep; Equal(n HasRep) HasRep; equalZero() HasRep; equalSucc(m HasRep) HasRep };
20 | type Zero struct { };
21 | func (x0 Zero) getRep() Rep { return Zero[[]] };
22 | type Succ struct { pred Nat };
23 | func (x0 Succ) getRep() Rep { return Succ[[]] };
24 | func (m Zero) Add(n HasRep) HasRep { return n.(Nat) };
25 | func (m Succ) Add(n HasRep) HasRep { return Succ{m.pred.(Nat).Add(n.(Nat)).(Nat)} };
26 | func (m Zero) Equal(n HasRep) HasRep { return n.(Nat).equalZero().(Bool) };
27 | func (m Succ) Equal(n HasRep) HasRep { return n.(Nat).equalSucc(m.pred.(Nat)).(Bool) };
28 | func (n Zero) equalZero() HasRep { return TT{} };
29 | func (n Succ) equalZero() HasRep { return FF{} };
30 | func (n Zero) equalSucc(m HasRep) HasRep { return FF{} };
31 | func (n Succ) equalSucc(m HasRep) HasRep { return m.(Nat).Equal(n.pred.(Nat)).(Bool) };
32 | type Func interface { HasRep; Apply(x HasRep) HasRep };
33 | type incr struct { n Nat };
34 | func (x0 incr) getRep() Rep { return incr[[]] };
35 | func (this incr) Apply(x HasRep) HasRep { return x.(Nat).Add(this.n.(Nat)).(Nat) };
36 | type not struct { };
37 | func (x0 not) getRep() Rep { return not[[]] };
38 | func (this not) Apply(x HasRep) HasRep { return x.(Bool).Not().(Bool) };
39 | type compose struct { a Rep; b Rep; c Rep; f Func; g Func };
40 | func (x0 compose) getRep() Rep { return compose[[x0.a, x0.b, x0.c]] };
41 | func (this compose) Apply(x HasRep) HasRep { return this.g.(Func).Apply(this.f.(Func).Apply(x.(Any)).(Any)).(Any) };
42 | type List interface { HasRep; Map(b Rep, f HasRep) HasRep; Member(x HasRep) HasRep };
43 | type Nil struct { a Rep };
44 | func (x0 Nil) getRep() Rep { return Nil[[x0.a]] };
45 | type Cons struct { a Rep; head Eq; tail List };
46 | func (x0 Cons) getRep() Rep { return Cons[[x0.a]] };
47 | func (xs Nil) Map(b Rep, f HasRep) HasRep { return Nil{b} };
48 | func (xs Cons) Map(b Rep, f HasRep) HasRep { return Cons{b, f.(Func).Apply(xs.head.(Eq)).(Eq), xs.tail.(List).Map(b, f.(Func)).(List)} };
49 | type memberBr struct { b Rep; xs List; x Eq };
50 | func (x0 memberBr) getRep() Rep { return memberBr[[x0.b]] };
51 | func (this memberBr) IfTT() HasRep { return TT{} };
52 | func (this memberBr) IfFF() HasRep { return this.xs.(List).Member(this.x.(Eq)).(Bool) };
53 | func (xs Nil) Member(x HasRep) HasRep { return FF{} };
54 | func (xs Cons) Member(x HasRep) HasRep { return x.(Eq).Equal(xs.head.(Eq)).(Bool).Cond(Bool[[]], memberBr{xs.a, xs, x.(Eq)}).(Bool) };
55 | type D struct { };
56 | func (x0 D) getRep() Rep { return D[[]] };
57 | func (d D) _1() HasRep { return Succ{Zero{}} };
58 | func (d D) _2() HasRep { return D{}._1().(Nat).Add(D{}._1().(Nat)).(Nat) };
59 | func (d D) _3() HasRep { return D{}._2().(Nat).Add(D{}._1().(Nat)).(Nat) };
60 | func main() { _ = compose{Nat[[]], Nat[[]], Nat[[]], incr{D{}._1().(Nat)}, incr{D{}._2().(Nat)}}.Apply(D{}._3().(Nat)).(Nat).Add(Zero{}).(Nat) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/graph/graph.fgr:
--------------------------------------------------------------------------------
1 | package main;
2 | type HasRep interface { getRep() Rep };
3 | type Any interface { HasRep };
4 | type Edge interface { HasRep; Source() HasRep; Target() HasRep };
5 | type Vertex interface { HasRep; Edges() HasRep };
6 | type A struct { };
7 | func (x0 A) getRep() Rep { return A[[]] };
8 | func main() { _ = A{} }
--------------------------------------------------------------------------------
/examples/fgr/oblit/irregular/irregular.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type Bool interface { HasRep; Not() HasRep };
 5 | type TT struct { };
 6 | func (x0 TT) getRep() Rep { return TT[[]] };
 7 | type FF struct { };
 8 | func (x0 FF) getRep() Rep { return FF[[]] };
 9 | func (this TT) Not() HasRep { return FF{} };
10 | func (this FF) Not() HasRep { return TT{} };
11 | type Nat interface { HasRep; Add(n HasRep) HasRep };
12 | type Zero struct { };
13 | func (x0 Zero) getRep() Rep { return Zero[[]] };
14 | type Succ struct { pred Nat };
15 | func (x0 Succ) getRep() Rep { return Succ[[]] };
16 | func (m Zero) Add(n HasRep) HasRep { return n.(Nat) };
17 | func (m Succ) Add(n HasRep) HasRep { return Succ{m.pred.(Nat).Add(n.(Nat)).(Nat)} };
18 | type Func interface { HasRep; Apply(x HasRep) HasRep };
19 | type incr struct { n Nat };
20 | func (x0 incr) getRep() Rep { return incr[[]] };
21 | func (this incr) Apply(x HasRep) HasRep { return x.(Nat).Add(this.n.(Nat)).(Nat) };
22 | type not struct { };
23 | func (x0 not) getRep() Rep { return not[[]] };
24 | func (this not) Apply(x HasRep) HasRep { return x.(Bool).Not().(Bool) };
25 | type Pair struct { a Rep; fst Any; snd Any };
26 | func (x0 Pair) getRep() Rep { return Pair[[x0.a]] };
27 | type pairMap struct { a Rep; f Func };
28 | func (x0 pairMap) getRep() Rep { return pairMap[[x0.a]] };
29 | func (p pairMap) Apply(x HasRep) HasRep { return Pair{p.a, p.f.(Func).Apply(x.(Pair).fst.(Any)).(Any), p.f.(Func).Apply(x.(Pair).snd.(Any)).(Any)} };
30 | type Balanced interface { HasRep; BalancedMap(f HasRep) HasRep };
31 | type Leaf struct { a Rep };
32 | func (x0 Leaf) getRep() Rep { return Leaf[[x0.a]] };
33 | type Node struct { a Rep; label Any; children Balanced };
34 | func (x0 Node) getRep() Rep { return Node[[x0.a]] };
35 | func (leaf Leaf) BalancedMap(f HasRep) HasRep { return Leaf{leaf.a} };
36 | func (node Node) BalancedMap(f HasRep) HasRep { return Node{node.a, f.(Func).Apply(node.label.(Any)).(Any), node.children.(Balanced).BalancedMap(pairMap{node.a, f.(Func)}).(Balanced)} };
37 | type D struct { };
38 | func (x0 D) getRep() Rep { return D[[]] };
39 | func (d D) _0() HasRep { return Zero{} };
40 | func (d D) _1() HasRep { return Succ{D{}._0().(Nat)} };
41 | func (d D) _2() HasRep { return Succ{D{}._1().(Nat)} };
42 | func (d D) _3() HasRep { return Succ{D{}._2().(Nat)} };
43 | func (d D) _4() HasRep { return Succ{D{}._3().(Nat)} };
44 | func (d D) _5() HasRep { return Succ{D{}._4().(Nat)} };
45 | func (d D) _6() HasRep { return Succ{D{}._5().(Nat)} };
46 | func (d D) _7() HasRep { return Succ{D{}._6().(Nat)} };
47 | func main() { _ = Node{Nat[[]], D{}._1().(Nat), Node{Pair[[Nat[[]]]], Pair{Nat[[]], D{}._2().(Nat), D{}._3().(Nat)}, Node{Pair[[Pair[[Nat[[]]]]]], Pair{Pair[[Nat[[]]]], Pair{Nat[[]], D{}._4().(Nat), D{}._5().(Nat)}, Pair{Nat[[]], D{}._6().(Nat), D{}._7().(Nat)}}, Leaf{Pair[[Pair[[Pair[[Nat[[]]]]]]]]}}}}.BalancedMap(incr{D{}._1().(Nat)}).(Balanced) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/map/map.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type ToAny struct { any Any };
 5 | func (x0 ToAny) getRep() Rep { return ToAny[[]] };
 6 | type Eq interface { HasRep; Equal(that HasRep) HasRep };
 7 | type Bool interface { HasRep; Not() HasRep; Equal(that HasRep) HasRep; Cond(a Rep, br HasRep) HasRep };
 8 | type Branches interface { HasRep; IfTT() HasRep; IfFF() HasRep };
 9 | type TT struct { };
10 | func (x0 TT) getRep() Rep { return TT[[]] };
11 | type FF struct { };
12 | func (x0 FF) getRep() Rep { return FF[[]] };
13 | func (this TT) Not() HasRep { return FF{} };
14 | func (this FF) Not() HasRep { return TT{} };
15 | func (this TT) Equal(that HasRep) HasRep { return that.(Bool) };
16 | func (this FF) Equal(that HasRep) HasRep { return that.(Bool).Not().(Bool) };
17 | func (this TT) Cond(a Rep, br HasRep) HasRep { return br.(Branches).IfTT().(Any) };
18 | func (this FF) Cond(a Rep, br HasRep) HasRep { return br.(Branches).IfFF().(Any) };
19 | type Func interface { HasRep; Apply(x HasRep) HasRep };
20 | type not struct { };
21 | func (x0 not) getRep() Rep { return not[[]] };
22 | func (this not) Apply(x HasRep) HasRep { return x.(Bool).Not().(Bool) };
23 | type compose struct { a Rep; b Rep; c Rep; f Func; g Func };
24 | func (x0 compose) getRep() Rep { return compose[[x0.a, x0.b, x0.c]] };
25 | func (this compose) Apply(x HasRep) HasRep { return this.g.(Func).Apply(this.f.(Func).Apply(x.(Any)).(Any)).(Any) };
26 | type List interface { HasRep; Map(b Rep, f HasRep) HasRep; Member(x HasRep) HasRep };
27 | type Nil struct { a Rep };
28 | func (x0 Nil) getRep() Rep { return Nil[[x0.a]] };
29 | type Cons struct { a Rep; head Eq; tail List };
30 | func (x0 Cons) getRep() Rep { return Cons[[x0.a]] };
31 | func (xs Nil) Map(b Rep, f HasRep) HasRep { return Nil{b} };
32 | func (xs Cons) Map(b Rep, f HasRep) HasRep { return Cons{b, f.(Func).Apply(xs.head.(Eq)).(Eq), xs.tail.(List).Map(b, f.(Func)).(List)} };
33 | type memberBr struct { b Rep; xs List; x Eq };
34 | func (x0 memberBr) getRep() Rep { return memberBr[[x0.b]] };
35 | func (this memberBr) IfTT() HasRep { return TT{} };
36 | func (this memberBr) IfFF() HasRep { return this.xs.(List).Member(this.x.(Eq)).(Bool) };
37 | func (xs Nil) Member(x HasRep) HasRep { return FF{} };
38 | func (xs Cons) Member(x HasRep) HasRep { return x.(Eq).Equal(xs.head.(Eq)).(Bool).Cond(Bool[[]], memberBr{xs.a, xs, x.(Eq)}).(Bool) };
39 | func main() { _ = (if Cons{Bool[[]], TT{}, Cons{Bool[[]], FF{}, Nil{Bool[[]]}}}.Map(Bool[[]], not{}).(List).getRep() << Cons[[Bool[[]]]] then Cons{Bool[[]], TT{}, Cons{Bool[[]], FF{}, Nil{Bool[[]]}}}.Map(Bool[[]], not{}).(List).(Cons) else panic).head.(Bool).Not().(Bool) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/misc/ifacebox-nomethparam.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type Func interface { HasRep; apply(a HasRep) HasRep };
 5 | type Box interface { HasRep; Make() HasRep };
 6 | type ABox struct { A Rep };
 7 | func (x0 ABox) getRep() Rep { return ABox[[x0.A]] };
 8 | func (a ABox) Make() HasRep { return ABox{a.A} };
 9 | type BBox struct { A Rep };
10 | func (x0 BBox) getRep() Rep { return BBox[[x0.A]] };
11 | func (a BBox) Make() HasRep { return BBox{a.A} };
12 | type E struct { val D };
13 | func (x0 E) getRep() Rep { return E[[]] };
14 | type D struct { val E };
15 | func (x0 D) getRep() Rep { return D[[]] };
16 | type Dummy struct { };
17 | func (x0 Dummy) getRep() Rep { return Dummy[[]] };
18 | func (x Dummy) doSomething(y HasRep) HasRep { return y.(Box).Make().(Box) };
19 | func (x Dummy) makeBox(A Rep) HasRep { return ABox{A} };
20 | func main() { _ = Dummy{}.doSomething(Dummy{}.makeBox(E[[]]).(Box)).(Box) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/misc/ifacebox.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type Func interface { HasRep; apply(a HasRep) HasRep };
 5 | type Box interface { HasRep; Map(B Rep, f HasRep) HasRep };
 6 | type ABox struct { A Rep; value Any };
 7 | func (x0 ABox) getRep() Rep { return ABox[[x0.A]] };
 8 | func (a ABox) Map(B Rep, f HasRep) HasRep { return ABox{B, f.(Func).apply(a.value.(Any)).(Any)} };
 9 | type Dummy struct { };
10 | func (x0 Dummy) getRep() Rep { return Dummy[[]] };
11 | type D struct { };
12 | func (x0 D) getRep() Rep { return D[[]] };
13 | type E struct { };
14 | func (x0 E) getRep() Rep { return E[[]] };
15 | type DtoE struct { };
16 | func (x0 DtoE) getRep() Rep { return DtoE[[]] };
17 | func (x0 DtoE) apply(d HasRep) HasRep { return E{} };
18 | func (x Dummy) takeBox(b HasRep) HasRep { return b.(Box).Map(E[[]], DtoE{}).(Box) };
19 | func main() { _ = Dummy{}.takeBox(ABox{D[[]], D{}}).(Any) }
--------------------------------------------------------------------------------
/examples/fgr/oblit/monomorph/monomorph.fgr:
--------------------------------------------------------------------------------
 1 | package main;
 2 | type HasRep interface { getRep() Rep };
 3 | type Any interface { HasRep };
 4 | type Bool interface { HasRep; Not() HasRep };
 5 | type TT struct { };
 6 | func (x0 TT) getRep() Rep { return TT[[]] };
 7 | type FF struct { };
 8 | func (x0 FF) getRep() Rep { return FF[[]] };
 9 | func (this TT) Not() HasRep { return FF{} };
10 | func (this FF) Not() HasRep { return TT{} };
11 | type Nat interface { HasRep; Add(n HasRep) HasRep };
12 | type Zero struct { };
13 | func (x0 Zero) getRep() Rep { return Zero[[]] };
14 | type Succ struct { pred Nat };
15 | func (x0 Succ) getRep() Rep { return Succ[[]] };
16 | func (m Zero) Add(n HasRep) HasRep { return n.(Nat) };
17 | func (m Succ) Add(n HasRep) HasRep { return Succ{m.pred.(Nat).Add(n.(Nat)).(Nat)} };
18 | type Func interface { HasRep; Apply(x HasRep) HasRep };
19 | type incr struct { n Nat };
20 | func (x0 incr) getRep() Rep { return incr[[]] };
21 | func (this incr) Apply(x HasRep) HasRep { return x.(Nat).Add(this.n.(Nat)).(Nat) };
22 | type not struct { };
23 | func (x0 not) getRep() Rep { return not[[]] };
24 | func (this not) Apply(x HasRep) HasRep { return x.(Bool).Not().(Bool) };
25 | type List interface { HasRep; Map(b Rep, f HasRep) HasRep };
26 | type Nil struct { a Rep };
27 | func (x0 Nil) getRep() Rep { return Nil[[x0.a]] };
28 | type Cons struct { a Rep; head Any; tail List };
29 | func (x0 Cons) getRep() Rep { return Cons[[x0.a]] };
30 | func (xs Nil) Map(b Rep, f HasRep) HasRep { return Nil{b} };
31 | func (xs Cons) Map(b Rep, f HasRep) HasRep { return Cons{b, f.(Func).Apply(xs.head.(Any)).(Any), xs.tail.(List).Map(b, f.(Func)).(List)} };
32 | type Pair struct { a Rep; b Rep; Fst Any; Snd Any };
33 | func (x0 Pair) getRep() Rep { return Pair[[x0.a, x0.b]] };
34 | type D struct { };
35 | func (x0 D) getRep() Rep { return D[[]] };
36 | func (d D) _1() HasRep { return Succ{Zero{}} };
37 | func (d D) _2() HasRep { return Succ{D{}._1().(Nat)} };
38 | func (d D) _3() HasRep { return Succ{D{}._2().(Nat)} };
39 | func main() { _ = Pair{List[[Bool[[]]]], List[[Nat[[]]]], Cons{Bool[[]], TT{}, Cons{Bool[[]], FF{}, Nil{Bool[[]]}}}.Map(Bool[[]], not{}).(List), Cons{Nat[[]], D{}._1().(Nat), Cons{Nat[[]], D{}._2().(Nat), Cons{Nat[[]], D{}._3().(Nat), Nil{Nat[[]]}}}}.Map(Nat[[]], incr{D{}._1().(Nat)}).(List)} }
--------------------------------------------------------------------------------
/internal/base/base.go:
--------------------------------------------------------------------------------
 1 | package base
 2 | 
 3 | /* Name */
 4 | 
 5 | type Name = string // Type alias (cf. type def)
 6 | 
 7 | /* AST Nodes */
 8 | 
 9 | type AstNode interface {
10 | 	String() string
11 | }
12 | 
13 | // Top-level decls -- not Field/ParamDecl
14 | type Decl interface {
15 | 	AstNode
16 | 	GetName() Name
17 | 	Ok(ds []Decl)
18 | }
19 | 
20 | type Program interface {
21 | 	AstNode
22 | 	GetDecls() []Decl
23 | 	GetMain() Expr
24 | 	Ok(allowStupid bool) Type // Set false for source check
25 | 	Eval() (Program, string)  // Eval one step; string is the name of the (innermost) applied rule
26 | }
27 | 
28 | type Expr interface {
29 | 	AstNode
30 | 	IsValue() bool
31 | 	CanEval(ds []Decl) bool      // More like, canReduce -- basically, bad assert returns false, cf. IsValue()
32 | 	ToGoString(ds []Decl) string // Basically, type T printed as main.T  // TODO (cf. %#v, Go-syntax value representation)
33 | }
34 | 
35 | /* Types */
36 | 
37 | type Type interface {
38 | 	Impls(ds []Decl, t Type) bool
39 | 	Equals(t Type) bool
40 | 	String() string
41 | }
42 | 
43 | /* ANTLR (parsing) */
44 | 
45 | type Adaptor interface {
46 | 	Parse(strictParse bool, input string) Program
47 | }
48 | 
--------------------------------------------------------------------------------
/internal/base/testutils/testutil.go:
--------------------------------------------------------------------------------
 1 | package testutils
 2 | 
 3 | import (
 4 | 	"fmt"
 5 | 	"strings"
 6 | 	"testing"
 7 | 
 8 | 	"github.com/rhu1/fgg/internal/base"
 9 | )
10 | 
11 | const PARSER_PANIC_PREFIX = "[Parser] "
12 | 
13 | /* Test harness functions */
14 | 
15 | func parseAndCheckOk(a base.Adaptor, src string) base.Program {
16 | 	ast := a.Parse(true, src)
17 | 	allowStupid := false
18 | 	ast.Ok(allowStupid)
19 | 	return ast
20 | }
21 | 
22 | func ParseAndOkGood(t *testing.T, a base.Adaptor, src string) base.Program {
23 | 	defer func() {
24 | 		if r := recover(); r != nil {
25 | 			t.Errorf("Unexpected panic: " + fmt.Sprintf("%v", r) + "\n" +
26 | 				src)
27 | 		}
28 | 	}()
29 | 	return parseAndCheckOk(a, src)
30 | }
31 | 
32 | // N.B. do not use to check for bad *syntax* -- see the PARSER_PANIC_PREFIX panic check
33 | func ParseAndOkBad(t *testing.T, msg string, a base.Adaptor, src string) base.Program {
34 | 	defer func() {
35 | 		if r := recover(); r == nil {
36 | 			t.Errorf("Expected panic, but none occurred: " + msg + "\n" +
37 | 				src)
38 | 		} else {
39 | 			rec := fmt.Sprintf("%v", r)
40 | 			if strings.HasPrefix(rec, PARSER_PANIC_PREFIX) {
41 | 				t.Errorf("Unexpected panic: " + rec + "\n" + src)
42 | 			}
43 | 			// TODO: check panic more specifically
44 | 		}
45 | 	}()
46 | 	return parseAndCheckOk(a, src)
47 | }
48 | 
49 | // Pre: parseAndOkGood
50 | func EvalAndOkGood(t *testing.T, p base.Program, steps int) base.Program {
51 | 	defer func() {
52 | 		if r := recover(); r != nil {
53 | 			t.Errorf("Unexpected panic: " + fmt.Sprintf("%v", r) + "\n" +
54 | 				p.String())
55 | 		}
56 | 	}()
57 | 	allowStupid := true
58 | 	for i := 0; i < steps; i++ {
59 | 		p, _ = p.Eval() // CHECKME: check rule names as part of test?
60 | 		p.Ok(allowStupid)
61 | 	}
62 | 	return p
63 | }
64 | 
65 | // Pre: parseAndOkGood
66 | func EvalAndOkBad(t *testing.T, p base.Program, msg string, steps int) base.Program {
67 | 	defer func() {
68 | 		if r := recover(); r == nil {
69 | 			t.Errorf("Expected panic, but none occurred: " + msg + "\n" +
70 | 				p.String())
71 | 		} else {
72 | 			// PARSER_PANIC_PREFIX panic should be already checked by parseAndOkGood
73 | 			// TODO: check panic more specifically
74 | 		}
75 | 	}()
76 | 	allowStupid := true
77 | 	for i := 0; i < steps; i++ {
78 | 		p, _ = p.Eval()
79 | 		p.Ok(allowStupid)
80 | 	}
81 | 	return p
82 | }
83 | 
--------------------------------------------------------------------------------
/internal/fg/fg.go:
--------------------------------------------------------------------------------
  1 | package fg
  2 | 
  3 | import "reflect"
  4 | 
  5 | import "github.com/rhu1/fgg/internal/base"
  6 | 
  7 | /* Aliases from base */
  8 | 
  9 | type Name = base.Name
 10 | type FGNode = base.AstNode
 11 | type Decl = base.Decl
 12 | 
 13 | /* Constants */
 14 | 
 15 | var STRING_TYPE = Type("string")
 16 | var PRIMITIVE_TYPES = make(map[Type]Type)
 17 | 
 18 | func init() {
 19 | 	PRIMITIVE_TYPES[STRING_TYPE] = STRING_TYPE
 20 | }
 21 | 
 22 | /* Name, Context, Type */
 23 | 
 24 | // Name: see Aliases (at top)
 25 | 
 26 | type Gamma map[Name]Type // Variable? though is an Expr
 27 | 
 28 | type Type Name // Type definition (cf. alias)
 29 | 
 30 | var _ base.Type = Type("")
 31 | var _ Spec = Type("")
 32 | 
 33 | // Pre: t0, t are known types
 34 | // t0 <: t
 35 | func (t0 Type) Impls(ds []Decl, t base.Type) bool {
 36 | 	if _, ok := PRIMITIVE_TYPES[t0]; ok {
 37 | 		if _, ok := t.(Type); ok {
 38 | 			return t0.Equals(t)
 39 | 		}
 40 | 	}
 41 | 
 42 | 	if _, ok := t.(Type); !ok {
 43 | 		panic("Expected FGR type, not " + reflect.TypeOf(t).String() +
 44 | 			":\n\t" + t.String())
 45 | 	}
 46 | 	t_fg := t.(Type)
 47 | 	if isStructType(ds, t_fg) {
 48 | 		return isStructType(ds, t0) && t0 == t_fg
 49 | 	}
 50 | 
 51 | 	gs := methods(ds, t_fg) // t is a t_I
 52 | 	gs0 := methods(ds, t0)  // t0 may be any
 53 | 	for k, g := range gs {
 54 | 		g0, ok := gs0[k]
 55 | 		if !ok || !g.EqExceptVars(g0) {
 56 | 			return false
 57 | 		}
 58 | 	}
 59 | 	return true
 60 | }
 61 | 
 62 | // t_I is a Spec, but not t_S -- this aspect is currently "dynamically typed"
 63 | // From Spec
 64 | func (t Type) GetSigs(ds []Decl) []Sig {
 65 | 	if !isInterfaceType(ds, t) { // isStructType would be more efficient
 66 | 		panic("Cannot use non-interface type as a Spec: " + t.String())
 67 | 	}
 68 | 	td := getTDecl(ds, t).(ITypeLit)
 69 | 	var res []Sig
 70 | 	for _, s := range td.specs {
 71 | 		res = append(res, s.GetSigs(ds)...)
 72 | 	}
 73 | 	return res
 74 | }
 75 | 
 76 | func (t0 Type) Equals(t base.Type) bool {
 77 | 	if _, ok := t.(Type); !ok {
 78 | 		panic("Expected FGR type, not " + reflect.TypeOf(t).String() +
 79 | 			":\n\t" + t.String())
 80 | 	}
 81 | 	return t0 == t.(Type)
 82 | }
 83 | 
 84 | func (t Type) String() string {
 85 | 	return string(t)
 86 | }
 87 | 
 88 | /* AST base intefaces: FGNode, Decl, TDecl, Spec, Expr */
 89 | 
 90 | // FGNode, Decl: see Aliases (at top)
 91 | 
 92 | type TDecl interface { // Rename TypeDecl
 93 | 	Decl
 94 | 	GetType() Type // In FG, GetType() == Type(GetName())
 95 | }
 96 | 
 97 | // A Sig or a Type (specifically a t_I -- bad t_S usage raises a run-time error, cf. Type.GetSigs)
 98 | type Spec interface {
 99 | 	FGNode
100 | 	GetSigs(ds []Decl) []Sig
101 | }
102 | 
103 | type FGExpr interface {
104 | 	base.Expr
105 | 	Subs(subs map[Variable]FGExpr) FGExpr
106 | 
107 | 	// N.B. gamma should be treated immutably (and ds, of course)
108 | 	// (No typing rule modifies gamma, except the T-Func bootstrap)
109 | 	Typing(ds []Decl, gamma Gamma, allowStupid bool) Type
110 | 
111 | 	// string is the type name of the "actually evaluated" expr (within the eval context)
112 | 	// CHECKME: resulting Exprs are not "parsed" from source, OK?
113 | 	Eval(ds []Decl) (FGExpr, string)
114 | 
115 | 	//IsPanic() bool  // TODO "explicit" FG panic -- cf. underlying runtime panic
116 | }
117 | 
118 | /* Helpers */
119 | 
120 | func isStructType(ds []Decl, t Type) bool {
121 | 	for _, v := range ds {
122 | 		if d, ok := v.(STypeLit); ok && d.t_S == t {
123 | 			return true
124 | 		}
125 | 	}
126 | 	return false
127 | }
128 | 
129 | func isInterfaceType(ds []Decl, t Type) bool {
130 | 	for _, v := range ds {
131 | 		d, ok := v.(ITypeLit)
132 | 		if ok && d.t_I == t {
133 | 			return true
134 | 		}
135 | 	}
136 | 	return false
137 | }
138 | 
--------------------------------------------------------------------------------
/internal/fg/fg_aux.go:
--------------------------------------------------------------------------------
 1 | package fg
 2 | 
 3 | import "fmt"
 4 | 
 5 | var _ = fmt.Errorf
 6 | 
 7 | /* fields(t_S), methods(t), body(t_S, m) */
 8 | 
 9 | // Pre: t_S is a struct type
10 | func fields(ds []Decl, t_S Type) []FieldDecl {
11 | 	s, ok := getTDecl(ds, t_S).(STypeLit)
12 | 	if !ok {
13 | 		panic("Not a struct type: " + t_S.String())
14 | 	}
15 | 	return s.fDecls
16 | }
17 | 
18 | // Go has no overloading, meth names are a unique key
19 | func methods(ds []Decl, t Type) map[Name]Sig {
20 | 	res := make(map[Name]Sig)
21 | 	if isStructType(ds, t) {
22 | 		for _, v := range ds { // Factor out getMDecl?
23 | 			md, ok := v.(MethDecl)
24 | 			if ok && md.recv.t == t {
25 | 				res[md.name] = md.ToSig()
26 | 			}
27 | 		}
28 | 	} else if isInterfaceType(ds, t) {
29 | 		td := getTDecl(ds, t).(ITypeLit)
30 | 		for _, s := range td.specs {
31 | 			for _, v := range s.GetSigs(ds) { // cycles? (cf. submission version, recursive "methods")
32 | 				res[v.meth] = v
33 | 			}
34 | 		}
35 | 	} else { // Perhaps redundant if all TDecl OK checked first
36 | 		panic("Unknown type: " + t.String())
37 | 	}
38 | 	return res
39 | }
40 | 
41 | // Pre: t_S is a struct type
42 | func body(ds []Decl, t_S Type, m Name) (Name, []Name, FGExpr) {
43 | 	for _, v := range ds {
44 | 		md, ok := v.(MethDecl)
45 | 		if ok && md.recv.t == t_S && md.name == m {
46 | 			xs := make([]Name, len(md.pDecls))
47 | 			for i := 0; i < len(md.pDecls); i++ {
48 | 				xs[i] = md.pDecls[i].name
49 | 			}
50 | 			return md.recv.name, xs, md.e_body
51 | 		}
52 | 	}
53 | 	panic("Method not found: " + t_S.String() + "." + m)
54 | }
55 | 
56 | /* Additional */
57 | 
58 | func getTDecl(ds []Decl, t Type) TDecl {
59 | 	for _, v := range ds {
60 | 		td, ok := v.(TDecl)
61 | 		if ok && td.GetType() == t {
62 | 			return td
63 | 		}
64 | 	}
65 | 	panic("Type not found: " + t)
66 | }
67 | 
--------------------------------------------------------------------------------
/internal/fg/fg_decls_test.go:
--------------------------------------------------------------------------------
 1 | package fg
 2 | 
 3 | /*
 4 | import (
 5 | 	"testing"
 6 | 
 7 | 	"github.com/rhu1/fgg/internal/parser"  // TODO: internal package not visible from here?
 8 | )
 9 | 
10 | func TestDistinctDecl(t *testing.T) {
11 | 	prog := MakeFgProgram(
12 | 		"type A struct{}", // [0] not ok, clash with [6]
13 | 		"type X struct{}",
14 | 		"func (x X) m1() X { return x }", // [2] not ok, clash with [4]
15 | 		"func (x X) m2() X { return x }", // ok
16 | 		"func (z X) m1() X { return z }", // [4] not OK, clash with [2]
17 | 		"type B struct{}",
18 | 		"type A interface{}", // [6] not ok, clash with [0]
19 | 		"A{}",
20 | 	)
21 | 	expectDistinct := []bool{false, true, false, true, false, true, false}
22 | 
23 | 	var a parser.FGAdaptor
24 | 	ast := a.Parse(true, prog)
25 | 	if want, got := len(expectDistinct), len(ast.GetDecls()); want != got {
26 | 		t.Fatalf("expected %d decls but got %d", want, got)
27 | 	}
28 | 	decls := ast.GetDecls()
29 | 	for i := range expectDistinct {
30 | 		t.Logf("expected unique: %t %s", expectDistinct[i], decls[i])
31 | 		if want, got := expectDistinct[i], isDistinctDecl(decls[i], decls); want != got {
32 | 			t.Fatalf("decl[%d] expected unique decl = %t", i, want)
33 | 		}
34 | 	}
35 | }
36 | */
37 | 
--------------------------------------------------------------------------------
/internal/fg/fg_util.go:
--------------------------------------------------------------------------------
 1 | package fg
 2 | 
 3 | import (
 4 | 	"strings"
 5 | )
 6 | 
 7 | // Pre: len(elems) > 1
 8 | // Pre: elems[:len(elems)-1] -- type/meth decls; elems[len(elems)-1] -- "main" func body expression
 9 | func MakeFgProgram(elems ...string) string {
10 | 	if len(elems) == 0 {
11 | 		panic("Bad empty args: must supply at least body expression for \"main\"")
12 | 	}
13 | 	var b strings.Builder
14 | 	b.WriteString("package main;\n")
15 | 	for _, v := range elems[:len(elems)-1] {
16 | 		b.WriteString(v)
17 | 		b.WriteString(";\n")
18 | 	}
19 | 	b.WriteString("func main() { _ = " + elems[len(elems)-1] + " }")
20 | 	return b.String()
21 | }
22 | 
--------------------------------------------------------------------------------
/internal/fgg/fgg_aux.go:
--------------------------------------------------------------------------------
  1 | package fgg
  2 | 
  3 | import (
  4 | 	"fmt"
  5 | 	"reflect"
  6 | )
  7 | 
  8 | var _ = fmt.Errorf
  9 | 
 10 | /* Export */
 11 | 
 12 | func Bounds(delta Delta, u Type) Type          { return bounds(delta, u) }
 13 | func Fields(ds []Decl, u_S TNamed) []FieldDecl { return fields(ds, u_S) }
 14 | func Methods(ds []Decl, u Type) map[Name]Sig   { return methods(ds, u) }
 15 | func GetTDecl(ds []Decl, t Name) TypeDecl      { return getTDecl(ds, t) }
 16 | 
 17 | /* bounds(delta, u), fields(u_S), methods(u), body(u_S, m) */
 18 | 
 19 | // return type TName?
 20 | func bounds(delta Delta, u Type) Type {
 21 | 	if a, ok := u.(TParam); ok {
 22 | 		if res, ok := delta[a]; ok {
 23 | 			return res
 24 | 		}
 25 | 	}
 26 | 	return u // CHECKME: submission version, includes when TParam 'a' not in delta, correct?
 27 | }
 28 | 
 29 | // Pre: len(s.psi.as) == len (u_S.typs), where s is the STypeLit decl for u_S.t
 30 | func fields(ds []Decl, u_S TNamed) []FieldDecl {
 31 | 	s, ok := getTDecl(ds, u_S.t_name).(STypeLit)
 32 | 	if !ok {
 33 | 		panic("Not a struct type: " + u_S.String())
 34 | 	}
 35 | 	subs := make(map[TParam]Type) // Cf. MakeEta
 36 | 	for i := 0; i < len(s.Psi.tFormals); i++ {
 37 | 		subs[s.Psi.tFormals[i].name] = u_S.u_args[i]
 38 | 	}
 39 | 	fds := make([]FieldDecl, len(s.fDecls))
 40 | 	for i := 0; i < len(s.fDecls); i++ {
 41 | 		fds[i] = s.fDecls[i].Subs(subs)
 42 | 	}
 43 | 	return fds
 44 | }
 45 | 
 46 | // Go has no overloading, meth names are a unique key
 47 | func methods(ds []Decl, u Type) map[Name]Sig { // CHECKME: deprecate?
 48 | 	return methodsDelta(ds, make(Delta), u)
 49 | }
 50 | 
 51 | // TODO FIXME refactor
 52 | func MethodsDelta1(ds []Decl, delta Delta, u Type) map[Name]Sig {
 53 | 	return methodsDelta(ds, delta, u)
 54 | }
 55 | 
 56 | func methodsDelta(ds []Decl, delta Delta, u Type) map[Name]Sig {
 57 | 	res := make(map[Name]Sig)
 58 | 	if IsStructType(ds, u) {
 59 | 		for _, v := range ds {
 60 | 			md, ok := v.(MethDecl)
 61 | 			if ok && isStructName(ds, md.t_recv) {
 62 | 				//sd := md.recv.u.(TName)
 63 | 				u_S := u.(TNamed)
 64 | 				if md.t_recv == u_S.t_name {
 65 | 					/*subs := make(map[TParam]Type)                    // Cf. MakeEta
 66 | 					for i := 0; i < len(md.Psi_recv.tFormals); i++ { // TODO: md.Psi_recv.ToDelta
 67 | 						subs[md.Psi_recv.tFormals[i].name] = u_S.u_args[i]
 68 | 					}
 69 | 					//for i := 0; i < len(md.psi.tfs); i++ { // CHECKME: because TParam.TSubs will panic o/w -- refactor?
 70 | 					//	subs[md.psi.tfs[i].a] = md.psi.tfs[i].a
 71 | 					//}
 72 | 					res[md.name] = md.ToSig().TSubs(subs)*/
 73 | 					if ok, eta := MakeEtaDelta(ds, delta, md.Psi_recv, u_S.u_args); ok {
 74 | 						res[md.name] = md.ToSig().TSubs(eta)
 75 | 					}
 76 | 				}
 77 | 			}
 78 | 		}
 79 | 	} else if IsNamedIfaceType(ds, u) { // N.B. u is a TName, \tau_I (not a TParam)
 80 | 		u_I := u.(TNamed)
 81 | 		td := getTDecl(ds, u_I.t_name).(ITypeLit)
 82 | 		subs := make(map[TParam]Type) // Cf. MakeEta
 83 | 		for i := 0; i < len(td.Psi.tFormals); i++ {
 84 | 			subs[td.Psi.tFormals[i].name] = u_I.u_args[i]
 85 | 		}
 86 | 		for _, s := range td.specs {
 87 | 			/*for _, v := range s.GetSigs(ds) {
 88 | 				res[v.m] = v
 89 | 			}*/
 90 | 			switch s1 := s.(type) {
 91 | 			case Sig:
 92 | 				res[s1.meth] = s1.TSubs(subs)
 93 | 			case TNamed: // Embedded u_I
 94 | 				for k, v := range methods(ds, s1.TSubs(subs)) { // cycles? (cf. submission version)
 95 | 					res[k] = v
 96 | 				}
 97 | 			default:
 98 | 				panic("Unknown Spec kind: " + reflect.TypeOf(s).String())
 99 | 			}
100 | 		}
101 | 	} else if cast, ok := u.(TParam); ok {
102 | 		upper, ok := delta[cast]
103 | 		if !ok {
104 | 			panic("Unknown type: " + u.String())
105 | 		}
106 | 		//return methodsDelta(ds, delta, bounds(delta, cast)) // !!! delegate to bounds
107 | 		return methodsDelta(ds, delta, upper)
108 | 	} else {
109 | 		panic("Unknown type: " + u.String()) // Perhaps redundant if all TDecl OK checked first
110 | 	}
111 | 	return res
112 | }
113 | 
114 | // Pre: t_S is a struct type
115 | // Submission version, m(~\rho) informal notation
116 | //func body(ds []Decl, u_S TNamed, m Name, targs []Type) (Name, []Name, FGGExpr) {
117 | func body(ds []Decl, u_S TNamed, m Name, targs []Type) (ParamDecl, []ParamDecl, FGGExpr) {
118 | 	for _, v := range ds {
119 | 		md, ok := v.(MethDecl)
120 | 		if ok && md.t_recv == u_S.t_name && md.name == m {
121 | 			subs := make(map[TParam]Type) // Cf. MakeEta
122 | 			for i := 0; i < len(md.Psi_recv.tFormals); i++ {
123 | 				subs[md.Psi_recv.tFormals[i].name] = u_S.u_args[i]
124 | 			}
125 | 			for i := 0; i < len(md.Psi_meth.tFormals); i++ {
126 | 				subs[md.Psi_meth.tFormals[i].name] = targs[i]
127 | 			}
128 | 			recv := ParamDecl{md.x_recv, u_S}
129 | 			pds := make([]ParamDecl, len(md.pDecls))
130 | 			for i := 0; i < len(md.pDecls); i++ {
131 | 				tmp := md.pDecls[i]
132 | 				pds[i] = ParamDecl{tmp.name, tmp.u.TSubs(subs)}
133 | 			}
134 | 			//return md.x_recv, xs, md.e_body.TSubs(subs)
135 | 			return recv, pds, md.e_body.TSubs(subs)
136 | 		}
137 | 	}
138 | 	panic("Method not found: " + u_S.String() + "." + m)
139 | }
140 | 
141 | /* Additional */
142 | 
143 | func getTDecl(ds []Decl, t Name) TypeDecl {
144 | 	for _, v := range ds {
145 | 		td, ok := v.(TypeDecl)
146 | 		if ok && td.GetName() == t {
147 | 			return td
148 | 		}
149 | 	}
150 | 	panic("Type not found: " + t)
151 | }
152 | 
--------------------------------------------------------------------------------
/internal/fgg/fgg_conv.go:
--------------------------------------------------------------------------------
  1 | package fgg
  2 | 
  3 | import (
  4 | 	"fmt"
  5 | 
  6 | 	"github.com/rhu1/fgg/internal/base"
  7 | 	"github.com/rhu1/fgg/internal/fg"
  8 | )
  9 | 
 10 | type fg2fgg struct {
 11 | 	fgProg  fg.FGProgram
 12 | 	fggProg FGGProgram
 13 | }
 14 | 
 15 | // FromFG converts a FG program prog into a FGG program
 16 | // with empty type parameters
 17 | func FromFG(prog fg.FGProgram) (FGGProgram, error) {
 18 | 	c := &fg2fgg{fgProg: prog}
 19 | 	if err := c.convert(); err != nil {
 20 | 		return FGGProgram{}, err
 21 | 	}
 22 | 	return c.fggProg, nil
 23 | }
 24 | 
 25 | func (c *fg2fgg) convert() error {
 26 | 	// convert toplevel declarations
 27 | 	for _, decl := range c.fgProg.GetDecls() {
 28 | 		switch decl := decl.(type) {
 29 | 		case fg.STypeLit:
 30 | 			sTypeLit, err := c.convertSTypeLit(decl)
 31 | 			if err != nil {
 32 | 				return err
 33 | 			}
 34 | 			c.fggProg.decls = append(c.fggProg.decls, sTypeLit)
 35 | 
 36 | 		case fg.ITypeLit:
 37 | 			iTypeLit, err := c.convertITypeLit(decl)
 38 | 			if err != nil {
 39 | 				return err
 40 | 			}
 41 | 			c.fggProg.decls = append(c.fggProg.decls, iTypeLit)
 42 | 
 43 | 		case fg.MethDecl:
 44 | 			mDecl, err := c.convertMDecl(decl)
 45 | 			if err != nil {
 46 | 				return err
 47 | 			}
 48 | 			c.fggProg.decls = append(c.fggProg.decls, mDecl)
 49 | 
 50 | 		default:
 51 | 			return fmt.Errorf("unknown declaration type: %T", decl)
 52 | 		}
 53 | 	}
 54 | 
 55 | 	expr, err := c.convertExpr(c.fgProg.GetMain())
 56 | 	if err != nil {
 57 | 		return err
 58 | 	}
 59 | 	c.fggProg.e_main = expr
 60 | 
 61 | 	return nil
 62 | }
 63 | 
 64 | // convertType converts a plain type to a parameterised type
 65 | func (c *fg2fgg) convertType(t fg.Type) (Name, BigPsi) {
 66 | 	return Name(t.String()), BigPsi{tFormals: nil} // 0 formal parameters
 67 | }
 68 | 
 69 | func (c *fg2fgg) convertSTypeLit(s fg.STypeLit) (STypeLit, error) {
 70 | 	typeName, typeFormals := c.convertType(s.GetType())
 71 | 
 72 | 	var fieldDecls []FieldDecl
 73 | 	for _, f := range s.GetFieldDecls() {
 74 | 		fd, err := c.convertFieldDecl(f)
 75 | 		if err != nil {
 76 | 			return STypeLit{}, err
 77 | 		}
 78 | 		fieldDecls = append(fieldDecls, fd)
 79 | 	}
 80 | 
 81 | 	return STypeLit{t_name: typeName, Psi: typeFormals, fDecls: fieldDecls}, nil
 82 | }
 83 | 
 84 | func (c *fg2fgg) convertITypeLit(i fg.ITypeLit) (ITypeLit, error) {
 85 | 	typeName, typeFormals := c.convertType(i.GetType())
 86 | 
 87 | 	var specs []Spec
 88 | 	for _, s := range i.GetSpecs() {
 89 | 		sig := s.(fg.Sig)
 90 | 		var paramDecls []ParamDecl
 91 | 		for _, p := range sig.GetParamDecls() {
 92 | 			pd, err := c.convertParamDecl(p)
 93 | 			if err != nil {
 94 | 				return ITypeLit{}, nil
 95 | 			}
 96 | 			paramDecls = append(paramDecls, pd)
 97 | 		}
 98 | 		retTypeName, _ := c.convertType(sig.GetReturn())
 99 | 
100 | 		specs = append(specs, Sig{
101 | 			meth:   Name(sig.GetMethod()),
102 | 			Psi:    BigPsi{tFormals: nil},
103 | 			pDecls: paramDecls,
104 | 			u_ret:  TNamed{t_name: retTypeName},
105 | 		})
106 | 	}
107 | 
108 | 	return ITypeLit{t_I: typeName, Psi: typeFormals, specs: specs}, nil
109 | }
110 | 
111 | func (c *fg2fgg) convertFieldDecl(fd fg.FieldDecl) (FieldDecl, error) {
112 | 	typeName, _ := c.convertType(fd.GetType())
113 | 	return FieldDecl{field: fd.GetName(), u: TNamed{t_name: typeName}}, nil
114 | }
115 | 
116 | func (c *fg2fgg) convertParamDecl(pd fg.ParamDecl) (ParamDecl, error) {
117 | 	typeName, _ := c.convertType(pd.GetType())
118 | 	return ParamDecl{name: pd.GetName(), u: TNamed{t_name: typeName}}, nil
119 | }
120 | 
121 | func (c *fg2fgg) convertMDecl(md fg.MethDecl) (MethDecl, error) {
122 | 	recvTypeName, recvTypeFormals := c.convertType(md.GetReceiver().GetType())
123 | 
124 | 	var paramDecls []ParamDecl
125 | 	for _, p := range md.GetParamDecls() {
126 | 		pd, err := c.convertParamDecl(p)
127 | 		if err != nil {
128 | 			return MethDecl{}, err
129 | 		}
130 | 		paramDecls = append(paramDecls, pd)
131 | 	}
132 | 
133 | 	retTypeName, _ := c.convertType(md.GetReturn())
134 | 	methImpl, err := c.convertExpr(md.GetBody())
135 | 	if err != nil {
136 | 		return MethDecl{}, err
137 | 	}
138 | 
139 | 	return MethDecl{
140 | 		x_recv:   md.GetReceiver().GetName(),
141 | 		t_recv:   recvTypeName,
142 | 		Psi_recv: recvTypeFormals,
143 | 		name:     Name(md.GetName()),
144 | 		Psi_meth: BigPsi{}, // empty parameter
145 | 		pDecls:   paramDecls,
146 | 		u_ret:    TNamed{t_name: retTypeName},
147 | 		e_body:   methImpl,
148 | 	}, nil
149 | }
150 | 
151 | func (c *fg2fgg) convertExpr(expr base.Expr) (FGGExpr, error) {
152 | 	switch expr := expr.(type) {
153 | 	case fg.Variable:
154 | 		return Variable{name: expr.String()}, nil
155 | 
156 | 	case fg.StructLit:
157 | 		sLitExpr, err := c.convertStructLit(expr)
158 | 		if err != nil {
159 | 			return nil, err
160 | 		}
161 | 		return sLitExpr, nil
162 | 
163 | 	case fg.Call:
164 | 		callExpr, err := c.convertCall(expr)
165 | 		if err != nil {
166 | 			return nil, err
167 | 		}
168 | 		return callExpr, nil
169 | 
170 | 	case fg.Select:
171 | 		selExpr, err := c.convertExpr(expr.GetExpr())
172 | 		if err != nil {
173 | 			return nil, err
174 | 		}
175 | 		return Select{e_S: selExpr, field: Name(expr.GetField())}, nil
176 | 
177 | 	case fg.Assert:
178 | 		assertExpr, err := c.convertExpr(expr.GetExpr())
179 | 		if err != nil {
180 | 			return nil, err
181 | 		}
182 | 		assType, _ := c.convertType(expr.GetType())
183 | 		return Assert{e_I: assertExpr, u_cast: TNamed{t_name: assType}}, nil
184 | 	}
185 | 
186 | 	return nil, fmt.Errorf("unknown expression type: %T", expr)
187 | }
188 | 
189 | func (c *fg2fgg) convertStructLit(sLit fg.StructLit) (StructLit, error) {
190 | 	structType, _ := c.convertType(sLit.GetType())
191 | 
192 | 	var es []FGGExpr
193 | 	for _, expr := range sLit.GetElems() {
194 | 		fieldExpr, err := c.convertExpr(expr)
195 | 		if err != nil {
196 | 			return StructLit{}, err
197 | 		}
198 | 		es = append(es, fieldExpr)
199 | 	}
200 | 
201 | 	return StructLit{u_S: TNamed{t_name: structType}, elems: es}, nil
202 | }
203 | 
204 | func (c *fg2fgg) convertCall(call fg.Call) (Call, error) {
205 | 	e, err := c.convertExpr(call.GetReceiver())
206 | 	if err != nil {
207 | 		return Call{}, err
208 | 	}
209 | 
210 | 	var args []FGGExpr
211 | 	for _, arg := range call.GetArgs() {
212 | 		argExpr, err := c.convertExpr(arg)
213 | 		if err != nil {
214 | 			return Call{}, err
215 | 		}
216 | 		args = append(args, argExpr)
217 | 	}
218 | 
219 | 	return Call{e_recv: e, meth: Name(call.GetMethod()), args: args}, nil
220 | }
221 | 
--------------------------------------------------------------------------------
/internal/fgg/fgg_util.go:
--------------------------------------------------------------------------------
 1 | package fgg
 2 | 
 3 | import (
 4 | 	"fmt"
 5 | 	"strings"
 6 | )
 7 | 
 8 | var _ = fmt.Errorf
 9 | 
10 | // Pre: len(elems) > 1
11 | // Pre: elems[:len(elems)-1] -- type/meth decls; elems[len(elems)-1] -- "main" func body expression
12 | func MakeFggProgram(elems ...string) string {
13 | 	if len(elems) == 0 {
14 | 		panic("Bad empty args: must supply at least body expression for \"main\"")
15 | 	}
16 | 	var b strings.Builder
17 | 	b.WriteString("package main;\n")
18 | 	for _, v := range elems[:len(elems)-1] {
19 | 		b.WriteString(v)
20 | 		b.WriteString(";\n")
21 | 	}
22 | 	b.WriteString("func main() { _ = " + elems[len(elems)-1] + " }")
23 | 	return b.String()
24 | }
25 | 
--------------------------------------------------------------------------------
/internal/fgr/fgr.go:
--------------------------------------------------------------------------------
  1 | package fgr
  2 | 
  3 | import (
  4 | 	"reflect"
  5 | 
  6 | 	"github.com/rhu1/fgg/internal/base"
  7 | )
  8 | 
  9 | //import "github.com/rhu1/fgg/fgg"
 10 | 
 11 | /* Aliases from base */
 12 | 
 13 | type Name = base.Name
 14 | type FGRNode = base.AstNode
 15 | type Decl = base.Decl
 16 | 
 17 | /* Name, Context, Type */
 18 | 
 19 | // Name: see Aliases (at top)
 20 | 
 21 | type Gamma map[Name]Type // TODO: should be Variable rather than Name -- though Variable is an Expr
 22 | 
 23 | // Same as FG
 24 | type Type Name // should be based on fgg.Type -- no: Rep now not parameterised
 25 | 
 26 | var _ base.Type = Type("")
 27 | var _ Spec = Type("")
 28 | 
 29 | // Pre: t0, t are known types
 30 | // t0 <: t
 31 | func (t0 Type) Impls(ds []Decl, u base.Type) bool {
 32 | 	if _, ok := u.(Type); !ok {
 33 | 		panic("Expected FGR type, not " + reflect.TypeOf(u).String() +
 34 | 			":\n\t" + u.String())
 35 | 	}
 36 | 	t_fgr := u.(Type)
 37 | 	if isStructType(ds, t_fgr) {
 38 | 		return isStructType(ds, t0) && t0 == t_fgr
 39 | 	}
 40 | 
 41 | 	gs := methods(ds, t_fgr) // t is a t_I
 42 | 	gs0 := methods(ds, t0)   // t0 may be any
 43 | 	for k, g := range gs {
 44 | 		g0, ok := gs0[k]
 45 | 		if !ok || !g.EqExceptVars(g0) {
 46 | 			return false
 47 | 		}
 48 | 	}
 49 | 	return true
 50 | }
 51 | 
 52 | // t_I is a Spec, but not t_S -- this aspect is currently "dynamically typed"
 53 | func (t Type) GetSigs(ds []Decl) []Sig {
 54 | 	if !isInterfaceType(ds, t) { // isStructType would be more efficient
 55 | 		panic("Cannot use non-interface type as a Spec: " + t.String() +
 56 | 			" is a " + reflect.TypeOf(t).String())
 57 | 	}
 58 | 	td := getTDecl(ds, t).(ITypeLit)
 59 | 	var res []Sig
 60 | 	for _, s := range td.specs {
 61 | 		res = append(res, s.GetSigs(ds)...)
 62 | 	}
 63 | 	return res
 64 | }
 65 | 
 66 | func (t0 Type) Equals(u base.Type) bool {
 67 | 	if _, ok := u.(Type); !ok {
 68 | 		panic("Expected FGR type, not " + reflect.TypeOf(u).String() +
 69 | 			":\n\t" + u.String())
 70 | 	}
 71 | 	return t0 == u.(Type)
 72 | }
 73 | 
 74 | func (t Type) String() string {
 75 | 	return string(t)
 76 | }
 77 | 
 78 | /* The Rep type -- the type of all type rep values (TReps) */
 79 | 
 80 | //const FggType = Type("FggType")
 81 | const RepType = Type("Rep")
 82 | 
 83 | /* AST base intefaces: FGRNode, Decl, TDecl, Spec, Expr */
 84 | 
 85 | // FGRNode, Decl: see Aliases (at top)
 86 | 
 87 | type TDecl interface {
 88 | 	Decl
 89 | 	GetType() Type // In FGR, GetType() == Type(GetName())
 90 | }
 91 | 
 92 | // A Sig or a Type (specifically a t_I -- bad t_S usage raises a run-time error, cf. Type.GetSigs)
 93 | type Spec interface {
 94 | 	FGRNode
 95 | 	GetSigs(ds []Decl) []Sig
 96 | }
 97 | 
 98 | type FGRExpr interface {
 99 | 	base.Expr // Using the same name "Expr", maybe rename this type to FGRExpr
100 | 	Subs(subs map[Variable]FGRExpr) FGRExpr
101 | 
102 | 	// N.B. gamma should be effectively immutable (and ds, of course)
103 | 	// (No typing rule modifies gamma, except the T-Func bootstrap)
104 | 	Typing(ds []Decl, gamma Gamma, allowStupid bool) Type
105 | 
106 | 	// string is the type name of the "actually evaluated" expr (within the eval context)
107 | 	// CHECKME: resulting Exprs are not "parsed" from source, OK?
108 | 	Eval(ds []Decl) (FGRExpr, string)
109 | 
110 | 	//IsPanic() bool  // TODO "explicit" FGR panic -- cf. underlying runtime panic
111 | 
112 | 	// General "nested" subexpr dropping for fgr sim -- also Select-TRep (not only SynthAsserts)
113 | 	DropSynthAsserts(ds []Decl) FGRExpr
114 | }
115 | 
116 | /* Helpers */
117 | 
118 | func isStructType(ds []Decl, t Type) bool {
119 | 	for _, v := range ds {
120 | 		d, ok := v.(STypeLit)
121 | 		if ok && d.t_S == t {
122 | 			return true
123 | 		}
124 | 	}
125 | 	return false
126 | }
127 | 
128 | func isInterfaceType(ds []Decl, t Type) bool {
129 | 	for _, v := range ds {
130 | 		d, ok := v.(ITypeLit)
131 | 		if ok && d.t_I == t {
132 | 			return true
133 | 		}
134 | 	}
135 | 	return false
136 | }
137 | 
138 | /* Old */
139 | 
140 | /*type Rep struct {
141 | 	u fgg.Type // FIXME: Rep doesn't carry u any more
142 | }
143 | 
144 | //var _ Type = Rep{}  // FIXME -- no: this "Rep" is not a String/Type
145 | 
146 | func (r Rep) String() string {
147 | 	return "Rep(" + r.u.String() + ")"
148 | }*/
149 | 
--------------------------------------------------------------------------------
/internal/fgr/fgr_aux.go:
--------------------------------------------------------------------------------
 1 | package fgr
 2 | 
 3 | import "fmt"
 4 | 
 5 | var _ = fmt.Errorf
 6 | 
 7 | /* fields(t_S), methods(t), body(t_S, m) */
 8 | 
 9 | // Pre: t_S is a struct type
10 | func fields(ds []Decl, t_S Type) []FieldDecl {
11 | 	s, ok := getTDecl(ds, t_S).(STypeLit)
12 | 	if !ok {
13 | 		panic("Not a struct type: " + t_S.String())
14 | 	}
15 | 	return s.fDecls
16 | }
17 | 
18 | // Go has no overloading, meth names are a unique key
19 | func methods(ds []Decl, t Type) map[Name]Sig {
20 | 	res := make(map[Name]Sig)
21 | 	if isStructType(ds, t) {
22 | 		for _, v := range ds { // Factor out getMDecl?
23 | 			md, ok := v.(MDecl)
24 | 			if ok && md.recv.t == t {
25 | 				res[md.name] = md.ToSig()
26 | 			}
27 | 		}
28 | 	} else if isInterfaceType(ds, t) {
29 | 		td := getTDecl(ds, t).(ITypeLit)
30 | 		for _, s := range td.specs {
31 | 			for _, v := range s.GetSigs(ds) { // CHECKME: can this cycle indefinitely? (cf. submission version, recursive "methods")
32 | 				res[v.meth] = v
33 | 			}
34 | 		}
35 | 	} else if t != RepType { // !!! Rep // Perhaps redundant if all TDecl OK checked first
36 | 		panic("Unknown type: " + t.String())
37 | 	}
38 | 	return res
39 | }
40 | 
41 | // Pre: t_S is a struct type
42 | func body(ds []Decl, t_S Type, m Name) (Name, []Name, FGRExpr) {
43 | 	for _, v := range ds {
44 | 		md, ok := v.(MDecl)
45 | 		if ok && md.recv.t == t_S && md.name == m {
46 | 			xs := make([]Name, len(md.pDecls))
47 | 			for i := 0; i < len(md.pDecls); i++ {
48 | 				xs[i] = md.pDecls[i].name
49 | 			}
50 | 			return md.recv.name, xs, md.e_body
51 | 		}
52 | 	}
53 | 	panic("Method not found: " + t_S.String() + "." + m)
54 | }
55 | 
56 | /* Additional */
57 | 
58 | func getTDecl(ds []Decl, t Type) TDecl {
59 | 	for _, v := range ds {
60 | 		td, ok := v.(TDecl)
61 | 		if ok && td.GetType() == t {
62 | 			return td
63 | 		}
64 | 	}
65 | 	panic("Type not found: " + t)
66 | }
67 | 
--------------------------------------------------------------------------------
/internal/fgr/fgr_test.go:
--------------------------------------------------------------------------------
 1 | //rhu@HZHL4 MINGW64 ~/code/go/src/github.com/rhu1/fgg
 2 | //$ go test github.com/rhu1/fgg/fg
 3 | //$ go test github.com/rhu1/fgg/fg -run Test001
 4 | 
 5 | package fgr_test // Separate package, can test "API"
 6 | 
 7 | /*import (
 8 | 	"fmt"
 9 | 	"testing"
10 | 
11 | 	"github.com/rhu1/fgg/base"
12 | 	"github.com/rhu1/fgg/base/testutils"
13 | 	"github.com/rhu1/fgg/fgr"
14 | )*/
15 | 
16 | /* Harness funcs * /
17 | 
18 | func parseAndOkGood(t *testing.T, elems ...string) base.Program {
19 | 	var adptr fg.FGAdaptor
20 | 	return testutils.ParseAndOkGood(t, &adptr, fg.MakeFgProgram(elems...))
21 | }
22 | 
23 | // N.B. do not use to check for bad *syntax* -- see the "[Parser]" panic check in base.ParseAndOkBad
24 | func parseAndOkBad(t *testing.T, msg string, elems ...string) base.Program {
25 | 	var adptr fg.FGAdaptor
26 | 	return testutils.ParseAndOkBad(t, msg, &adptr, fg.MakeFgProgram(elems...))
27 | }
28 | //*/
29 | 
30 | /* Syntax and typing */
31 | 
32 | // TOOD: make translation to FGG and compare results to -fgg
33 | 
34 | /*func Test001(t *testing.T) {
35 | 	A := "type A struct {}"
36 | 	Am1 := "func (x0 A) m1() A { return x0 }"
37 | 	Am2 := "func (x0 A) m2(x1 A) A { return x1 }"
38 | 	Am3 := "func (x0 A) m3(x1 A, x2 A) A { return x2 }"
39 | 	B := "type B struct { f A }"
40 | 	e := "B{A{}}"
41 | 	parseAndOkGood(t, A, Am1, Am2, Am3, B, e)
42 | }*/
43 | 
44 | /* Eval */
45 | 
46 | /*func TestEval001(t *testing.T) {
47 | 	A := "type A struct {}"
48 | 	B := "type B struct { f A }"
49 | 	e := "B{A{}}.f"
50 | 	prog := parseAndOkGood(t, A, B, e)
51 | 	testutils.EvalAndOkGood(t, prog, 1)
52 | }*/
53 | 
--------------------------------------------------------------------------------
/internal/frontend/fggi.go:
--------------------------------------------------------------------------------
 1 | package frontend
 2 | 
 3 | func FGGmain(verbose bool, src string, strictParse bool, evalSteps int,
 4 | 	printf bool, monom bool, monomc string, oblitc string) {
 5 | 	intrp_fgg := NewFGGInterp(verbose, src, strictParse)
 6 | 	if evalSteps > NO_EVAL {
 7 | 		intrp_fgg.Eval(evalSteps)
 8 | 		PrintResult(printf, intrp_fgg.GetProgram())
 9 | 	}
10 | 
11 | 	// TODO: refactor (cf. Frontend, Interp)
12 | 	intrp_fgg.Monom(monom, monomc)
13 | 	intrp_fgg.Oblit(oblitc)
14 | 	////doWrappers(prog, wrapperc)
15 | }
16 | 
--------------------------------------------------------------------------------
/internal/frontend/fgi.go:
--------------------------------------------------------------------------------
 1 | package frontend
 2 | 
 3 | func FGmain(verbose bool, src string, strictParse bool, evalSteps int,
 4 | 	printf bool) {
 5 | 	intrp_fg := NewFGInterp(verbose, src, strictParse)
 6 | 	if evalSteps > NO_EVAL {
 7 | 		intrp_fg.Eval(evalSteps)
 8 | 		PrintResult(printf, intrp_fg.GetProgram())
 9 | 	}
10 | }
11 | 
--------------------------------------------------------------------------------
/internal/parser/util/util.go:
--------------------------------------------------------------------------------
 1 | package util
 2 | 
 3 | import (
 4 | 	"errors"
 5 | 	"fmt"
 6 | 	"os"
 7 | 	"strconv"
 8 | 
 9 | 	"github.com/antlr/antlr4/runtime/Go/antlr"
10 | )
11 | 
12 | /* For "strict" parsing, *parser* errors -- cf. F(G)GBailLexer */
13 | 
14 | // Cf. https://stackoverflow.com/questions/51683104/how-to-catch-minor-errors
15 | type StrictErrorStrategy struct {
16 | 	antlr.DefaultErrorStrategy
17 | }
18 | 
19 | var _ antlr.ErrorStrategy = &StrictErrorStrategy{}
20 | 
21 | func (s *StrictErrorStrategy) Recover(recognizer antlr.Parser, e antlr.RecognitionException) {
22 | 	token := recognizer.GetCurrentToken()
23 | 	message := "[Parser] error at line " + strconv.Itoa(token.GetLine()) +
24 | 		", position " + strconv.Itoa(token.GetColumn()) + " right before " +
25 | 		s.GetTokenErrorDisplay(token)
26 | 	//panic(message) // + " " + e.GetMessage())
27 | 	fmt.Println(errors.New(message))
28 | 	os.Exit(1)
29 | }
30 | 
31 | //ErrorStrategy.RecoverInline(Parser) Token
32 | func (s *StrictErrorStrategy) RecoverInline(recognizer antlr.Parser) antlr.Token {
33 | 	token := recognizer.GetCurrentToken()
34 | 	message := "[Parser] error at line " + strconv.Itoa(token.GetLine()) +
35 | 		", position " + strconv.Itoa(token.GetColumn()) + " right before " +
36 | 		s.GetTokenErrorDisplay(token)
37 | 	//panic(message) // + fmt.Sprintf("%v", antlr.NewInputMisMatchException(recognizer)))
38 | 	fmt.Println(errors.New(message))
39 | 	os.Exit(1)
40 | 	return nil
41 | }
42 | 
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
  1 | /* See README.md for install and run examples.
  2 |  * See copyright.txt for copyright.
  3 |  */
  4 | 
  5 | //go:generate antlr4 -Dlanguage=Go -o parser/fg parser/FG.g4
  6 | //go:generate antlr4 -Dlanguage=Go -o parser/fgg parser/FGG.g4
  7 | 
  8 | package main
  9 | 
 10 | import (
 11 | 	"flag"
 12 | 	"fmt"
 13 | 	"io/ioutil"
 14 | 	"os"
 15 | 	"reflect"
 16 | 	"strconv"
 17 | 
 18 | 	"github.com/rhu1/fgg/internal/fg"
 19 | 	"github.com/rhu1/fgg/internal/frontend"
 20 | )
 21 | 
 22 | var _ = reflect.Append
 23 | var _ = strconv.AppendBool
 24 | 
 25 | // Command line parameters/flags
 26 | var (
 27 | 	interpFG  bool // parse FG
 28 | 	interpFGG bool // parse FGG
 29 | 
 30 | 	monom  bool   // parse FGG and monomorphise FGG source -- paper notation (angle bracks)
 31 | 	monomc string // output filename of monomorphised FGG; "--" for stdout -- Go output (no angle bracks)
 32 | 	// TODO: fix naming between "monomc", "compile" and "oblitc"
 33 | 
 34 | 	oblitc         string // output filename of FGR compilation via oblit; "--" for stdout
 35 | 	oblitEvalSteps int    // TODO: A concrete FGR syntax, for oblitc to output
 36 | 
 37 | 	monomtest bool
 38 | 	oblittest bool
 39 | 
 40 | 	useInternalSrc bool   // use internal source
 41 | 	inlineSrc      string // use content of this as source
 42 | 	strictParse    bool   // use strict parsing mode
 43 | 
 44 | 	evalSteps int  // number of steps to evaluate
 45 | 	verbose   bool // verbose mode
 46 | 	printf    bool // use ToGoString for output (e.g., "main." type prefix)
 47 | )
 48 | 
 49 | func init() {
 50 | 	// FG or FGG
 51 | 	flag.BoolVar(&interpFG, "fg", false,
 52 | 		"interpret input as FG (defaults to true if neither -fg/-fgg set)")
 53 | 	flag.BoolVar(&interpFGG, "fgg", false,
 54 | 		"interpret input as FGG")
 55 | 
 56 | 	// Erasure by monomorphisation -- implicitly disabled if not -fgg
 57 | 	flag.BoolVar(&monom, "monom", false,
 58 | 		"monomorphise FGG source using paper notation, i.e., angle bracks (ignored if -fgg not set)")
 59 | 	flag.StringVar(&monomc, "monomc", "", // Empty string for "false"
 60 | 		"monomorphise FGG source to (Go-compatible) FG, i.e., no angle bracks (ignored if -fgg not set)\n"+
 61 | 			"specify '--' to print to stdout")
 62 | 
 63 | 	// Erasure(?) by translation based on type reps -- FGG vs. FGR?
 64 | 	flag.StringVar(&oblitc, "oblitc", "", // Empty string for "false"
 65 | 		"[WIP] compile FGG source to FGR (ignored if -fgg not set)\n"+
 66 | 			"specify '--' to print to stdout")
 67 | 	flag.IntVar(&oblitEvalSteps, "oblit-eval", frontend.NO_EVAL,
 68 | 		" N ⇒ evaluate N (≥ 0) steps; or\n-1 ⇒ evaluate to value (or panic)")
 69 | 
 70 | 	flag.BoolVar(&monomtest, "test-monom", false, `Test monom correctness`)
 71 | 	flag.BoolVar(&oblittest, "test-oblit", false, `[WIP] Test oblit correctness`)
 72 | 
 73 | 	// Parsing options
 74 | 	flag.BoolVar(&useInternalSrc, "internal", false,
 75 | 		`use "internal" input as source`)
 76 | 	flag.StringVar(&inlineSrc, "inline", "",
 77 | 		`-inline="[FG/FGG src]", use inline input as source`)
 78 | 	flag.BoolVar(&strictParse, "strict", true,
 79 | 		"strict parsing (default true, means don't attempt recovery on parsing errors)")
 80 | 
 81 | 	flag.IntVar(&evalSteps, "eval", frontend.NO_EVAL,
 82 | 		" N ⇒ evaluate N (≥ 0) steps; or\n-1 ⇒ evaluate to value (or panic)")
 83 | 	flag.BoolVar(&verbose, "v", false,
 84 | 		"enable verbose printing")
 85 | 	frontend.Verbose = verbose
 86 | 	flag.BoolVar(&printf, "printf", false,
 87 | 		"use Go style output type name prefixes")
 88 | }
 89 | 
 90 | var usage = func() {
 91 | 	fmt.Fprintf(os.Stderr, `Usage:
 92 | 
 93 | 	fgg [options] -fg  path/to/file.fg
 94 | 	fgg [options] -fgg path/to/file.fgg
 95 | 	fgg [options] -internal
 96 | 	fgg [options] -inline "package main; type ...; func main() { ... }"
 97 | 
 98 | Options:
 99 | 
100 | `)
101 | 	flag.PrintDefaults()
102 | 	os.Exit(1)
103 | }
104 | 
105 | func main() {
106 | 	flag.Usage = usage
107 | 	flag.Parse()
108 | 	frontend.OblitEvalSteps = oblitEvalSteps
109 | 
110 | 	// Determine (default) mode
111 | 	if interpFG {
112 | 		if interpFGG { // -fg "overrules" -fgg
113 | 			interpFGG = false
114 | 		}
115 | 	} else if !interpFGG {
116 | 		interpFG = true // -fg default
117 | 	}
118 | 
119 | 	// Determine source
120 | 	var src string
121 | 	switch {
122 | 	case useInternalSrc: // First priority
123 | 		src = internalSrc() // FIXME: hardcoded to FG
124 | 	case inlineSrc != "": // Second priority, i.e., -inline overrules src file
125 | 		src = inlineSrc
126 | 	default:
127 | 		if flag.NArg() < 1 {
128 | 			fmt.Fprintln(os.Stderr, "Input error: need a source .go file (or an -inline program)")
129 | 			flag.Usage()
130 | 		}
131 | 		b, err := ioutil.ReadFile(flag.Arg(0))
132 | 		if err != nil {
133 | 			frontend.CheckErr(err)
134 | 		}
135 | 		src = string(b)
136 | 	}
137 | 
138 | 	// Currently hacked
139 | 	if monomtest {
140 | 		frontend.TestMonom(printf, verbose, src, evalSteps)
141 | 		//testMonom(printf bool, verbose bool, src string, steps int) {
142 | 		return // FIXME
143 | 	} else if oblittest {
144 | 		frontend.TestOblit(verbose, src, evalSteps)
145 | 		//testOblit(verbose, src, evalSteps)  // TODO: "weak" oblit simulation
146 | 		return
147 | 	}
148 | 
149 | 	switch { // Pre: !(interpFG && interpFGG)
150 | 	case interpFG:
151 | 		frontend.FGmain(verbose, src, strictParse, evalSteps, printf)
152 | 		// monom implicitly disabled
153 | 	case interpFGG:
154 | 		frontend.FGGmain(verbose, src, strictParse, evalSteps, printf, monom, monomc, oblitc)
155 | 	}
156 | }
157 | 
158 | // For convenient quick testing -- via flag "-internal"
159 | func internalSrc() string {
160 | 	Any := "type Any interface {}"
161 | 	ToAny := "type ToAny struct { any Any }"
162 | 	e := "ToAny{1}"                        // CHECKME: `1` skipped by parser?
163 | 	return fg.MakeFgProgram(Any, ToAny, e) // FIXME: hardcoded FG
164 | }
165 | 
--------------------------------------------------------------------------------
/parser/FG.g4:
--------------------------------------------------------------------------------
 1 | //$ antlr4 -Dlanguage=Go -o parser/fg parser/FG.g4
 2 | 
 3 | 
 4 | // FG.g4
 5 | grammar FG;
 6 | 
 7 | 
 8 | /* Keywords */
 9 | 
10 | FUNC      : 'func' ;
11 | INTERFACE : 'interface' ;
12 | MAIN      : 'main' ;
13 | PACKAGE   : 'package' ;
14 | RETURN    : 'return' ;
15 | STRUCT    : 'struct' ;
16 | TYPE      : 'type' ;
17 | 
18 | IMPORT    : 'import' ;
19 | FMT       : 'fmt' ;
20 | PRINTF    : 'Printf' ;
21 | SPRINTF   : 'Sprintf' ;
22 | 
23 | 
24 | /* Tokens */
25 | 
26 | fragment LETTER : ('a' .. 'z') | ('A' .. 'Z') | '\u03b1' | '\u03b2' ;
27 | fragment DIGIT  : ('0' .. '9') ;
28 | //fragment HACK   : 'ᐸ' | 'ᐳ' ;  // Doesn't seem to work?
29 | fragment MONOM_HACK   : '\u1438' | '\u1433' | '\u1428' ;  // Hack for monom output
30 | NAME            : (LETTER | '_' | MONOM_HACK) (LETTER | '_' | DIGIT | MONOM_HACK)* ;
31 | WHITESPACE      : [ \r\n\t]+ -> skip ;
32 | COMMENT         : '/*' .*? '*/' -> channel(HIDDEN) ;
33 | LINE_COMMENT    : '//' ~[\r\n]* -> channel(HIDDEN) ;
34 | STRING          : '"' (LETTER | DIGIT | ' ' | '.' | ',' | '_' | '%' | '#' | '(' | ')' | '+' | '-')* '"' ;
35 | 
36 | 
37 | /* Rules */
38 | 
39 | // Conventions:
40 | // "tag=" to distinguish repeat productions within a rule: comes out in
41 | // field/getter names.
42 | // "#tag" for cases within a rule: comes out as Context names (i.e., types).
43 | // "plurals", e.g., decls, used for sequences: comes out as "helper" Contexts,
44 | // nodes that group up actual children underneath -- makes "adapting" easier.
45 | 
46 | program    : PACKAGE MAIN ';'
47 |              (IMPORT STRING ';')?
48 |              decls? FUNC MAIN '(' ')' '{'
49 |              ('_' '=' expr | FMT '.' PRINTF '(' '"%#v"' ',' expr ')')
50 |              '}' EOF ;
51 | decls      : ((typeDecl | methDecl) ';')+ ;
52 | typeDecl   : TYPE NAME typeLit ;  // TODO: tag id=NAME, better for adapting (vs., index constants)
53 | methDecl   : FUNC '(' paramDecl ')' sig '{' RETURN expr '}' ;
54 | typeLit    : STRUCT '{' fieldDecls? '}'             # StructTypeLit
55 |            | INTERFACE '{' specs? '}'               # InterfaceTypeLit ;
56 | fieldDecls : fieldDecl (';' fieldDecl)* ;
57 | fieldDecl  : field=NAME typ=NAME ;
58 | specs      : spec (';' spec)* ;
59 | spec       : sig                                    # SigSpec
60 |            | NAME                                   # InterfaceSpec
61 |            ;
62 | sig        : meth=NAME '(' params? ')' ret=NAME ;
63 | params     : paramDecl (',' paramDecl)* ;
64 | paramDecl  : vari=NAME typ=NAME ;
65 | expr       : NAME                                   # Variable
66 |            | NAME '{' exprs? '}'                    # StructLit
67 |            | expr '.' NAME                          # Select
68 |            | recv=expr '.' NAME '(' args=exprs? ')' # Call
69 |            | expr '.' '(' NAME ')'                  # Assert
70 |            | FMT '.' SPRINTF '(' (STRING | '"%#v"') (',' | expr)* ')'  # Sprintf
71 |            ;
72 | exprs      : expr (',' expr)* ;
73 | 
74 | 
--------------------------------------------------------------------------------
/parser/FGG.g4:
--------------------------------------------------------------------------------
 1 | 
 2 | grammar FGG;
 3 | 
 4 | /* Keywords */
 5 | 
 6 | FUNC: 'func';
 7 | INTERFACE: 'interface';
 8 | MAIN: 'main';
 9 | PACKAGE: 'package';
10 | RETURN: 'return';
11 | STRUCT: 'struct';
12 | TYPE: 'type';
13 | 
14 | IMPORT: 'import';
15 | FMT: 'fmt';
16 | PRINTF: 'Printf';
17 | SPRINTF: 'Sprintf';
18 | 
19 | /* Tokens */
20 | 
21 | fragment LETTER: ('a' .. 'z')
22 | 	| ('A' .. 'Z')
23 | 	| 'α' // For FGR deserialization
24 | 	| 'β';
25 | fragment DIGIT: ('0' .. '9');
26 | NAME: (LETTER | '_') (LETTER | '_' | DIGIT)*;
27 | WHITESPACE: [ \r\n\t]+ -> skip;
28 | COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
29 | LINE_COMMENT: '//' ~[\r\n]* -> channel(HIDDEN);
30 | STRING:
31 | 	'"' (
32 | 		LETTER
33 | 		| DIGIT
34 | 		| ' '
35 | 		| '.'
36 | 		| ','
37 | 		| '_'
38 | 		| '%'
39 | 		| '#'
40 | 		| '('
41 | 		| ')'
42 | 		| '+'
43 | 		| '-'
44 | 	)* '"';
45 | 
46 | /* Rules */
47 | 
48 | // Conventions: "tag=" to distinguish repeat productions within a rule: comes out in field/getter
49 | // names. "#tag" for cases within a rule: comes out as Context names (i.e., types). "plurals", e.g.,
50 | // decls, used for sequences: comes out as "helper" Contexts, nodes that group up actual children
51 | // underneath -- makes "adapting" easier.
52 | 
53 | typ: NAME # TypeParam | NAME '(' typs? ')' # TypeName;
54 | typs: typ (',' typ)*;
55 | typeFormals:
56 | 	'(' TYPE typeFDecls? ')'; // Refactored "(...)" into here
57 | typeFDecls: typeFDecl (',' typeFDecl)*;
58 | typeFDecl: NAME typ; // CHECKME: #TypeName ?
59 | program:
60 | 	PACKAGE MAIN ';' (IMPORT STRING ';')? decls? FUNC MAIN '(' ')' '{' (
61 | 		'_' '=' expr
62 | 		| FMT '.' PRINTF '(' '"%#v"' ',' expr ')'
63 | 	) '}' EOF;
64 | decls: ((typeDecl | methDecl) ';')+;
65 | typeDecl:
66 | 	TYPE NAME typeFormals typeLit; // TODO: tag id=NAME, better for adapting (vs., index constants)
67 | methDecl:
68 | 	FUNC '(' recv = NAME typn = NAME typeFormals ')' sig '{' RETURN expr '}';
69 | typeLit:
70 | 	STRUCT '{' fieldDecls? '}'	# StructTypeLit
71 | 	| INTERFACE '{' specs? '}'	# InterfaceTypeLit;
72 | fieldDecls: fieldDecl (';' fieldDecl)*;
73 | fieldDecl: field = NAME typ;
74 | specs: spec (';' spec)*;
75 | spec:
76 | 	sig		# SigSpec
77 | 	| typ	# InterfaceSpec; // Must be a #TypeName, \tau_I -- refactor?
78 | sig: meth = NAME typeFormals '(' params? ')' typ;
79 | params: paramDecl (',' paramDecl)*;
80 | paramDecl: vari = NAME typ;
81 | expr:
82 | 	NAME																# Variable
83 | 	| typ '{' exprs? '}' /* typ is #TypeName, \tau_S */					# StructLit
84 | 	| expr '.' NAME														# Select
85 | 	| recv = expr '.' NAME '(' targs = typs? ')' '(' args = exprs? ')'	# Call
86 | 	| expr '.' '(' typ ')'												# Assert
87 | 	| FMT '.' SPRINTF '(' (STRING | '"%#v"') (',' | expr)* ')'			# Sprintf;
88 | exprs: expr (',' expr)*;
89 | 
90 | 
--------------------------------------------------------------------------------
/parser/pregen/fg/parser/FG.interp:
--------------------------------------------------------------------------------
 1 | token literal names:
 2 | null
 3 | ';'
 4 | '('
 5 | ')'
 6 | '{'
 7 | '_'
 8 | '='
 9 | '.'
10 | '"%#v"'
11 | ','
12 | '}'
13 | 'func'
14 | 'interface'
15 | 'main'
16 | 'package'
17 | 'return'
18 | 'struct'
19 | 'type'
20 | 'import'
21 | 'fmt'
22 | 'Printf'
23 | 'Sprintf'
24 | null
25 | null
26 | null
27 | null
28 | null
29 | 
30 | token symbolic names:
31 | null
32 | null
33 | null
34 | null
35 | null
36 | null
37 | null
38 | null
39 | null
40 | null
41 | null
42 | FUNC
43 | INTERFACE
44 | MAIN
45 | PACKAGE
46 | RETURN
47 | STRUCT
48 | TYPE
49 | IMPORT
50 | FMT
51 | PRINTF
52 | SPRINTF
53 | NAME
54 | WHITESPACE
55 | COMMENT
56 | LINE_COMMENT
57 | STRING
58 | 
59 | rule names:
60 | program
61 | decls
62 | typeDecl
63 | methDecl
64 | typeLit
65 | fieldDecls
66 | fieldDecl
67 | specs
68 | spec
69 | sig
70 | params
71 | paramDecl
72 | expr
73 | exprs
74 | 
75 | 
76 | atn:
77 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 3, 28, 196, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 37, 10, 2, 3, 2, 5, 2, 40, 10, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 5, 2, 59, 10, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 3, 5, 3, 66, 10, 3, 3, 3, 3, 3, 6, 3, 70, 10, 3, 13, 3, 14, 3, 71, 3, 4, 3, 4, 3, 4, 3, 4, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 5, 3, 6, 3, 6, 3, 6, 5, 6, 91, 10, 6, 3, 6, 3, 6, 3, 6, 3, 6, 5, 6, 97, 10, 6, 3, 6, 5, 6, 100, 10, 6, 3, 7, 3, 7, 3, 7, 7, 7, 105, 10, 7, 12, 7, 14, 7, 108, 11, 7, 3, 8, 3, 8, 3, 8, 3, 9, 3, 9, 3, 9, 7, 9, 116, 10, 9, 12, 9, 14, 9, 119, 11, 9, 3, 10, 3, 10, 5, 10, 123, 10, 10, 3, 11, 3, 11, 3, 11, 5, 11, 128, 10, 11, 3, 11, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 7, 12, 136, 10, 12, 12, 12, 14, 12, 139, 11, 12, 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 5, 14, 149, 10, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 7, 14, 159, 10, 14, 12, 14, 14, 14, 162, 11, 14, 3, 14, 5, 14, 165, 10, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 5, 14, 175, 10, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 7, 14, 183, 10, 14, 12, 14, 14, 14, 186, 11, 14, 3, 15, 3, 15, 3, 15, 7, 15, 191, 10, 15, 12, 15, 14, 15, 194, 11, 15, 3, 15, 2, 3, 26, 16, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 2, 3, 4, 2, 10, 10, 28, 28, 2, 204, 2, 30, 3, 2, 2, 2, 4, 69, 3, 2, 2, 2, 6, 73, 3, 2, 2, 2, 8, 77, 3, 2, 2, 2, 10, 99, 3, 2, 2, 2, 12, 101, 3, 2, 2, 2, 14, 109, 3, 2, 2, 2, 16, 112, 3, 2, 2, 2, 18, 122, 3, 2, 2, 2, 20, 124, 3, 2, 2, 2, 22, 132, 3, 2, 2, 2, 24, 140, 3, 2, 2, 2, 26, 164, 3, 2, 2, 2, 28, 187, 3, 2, 2, 2, 30, 31, 7, 16, 2, 2, 31, 32, 7, 15, 2, 2, 32, 36, 7, 3, 2, 2, 33, 34, 7, 20, 2, 2, 34, 35, 7, 28, 2, 2, 35, 37, 7, 3, 2, 2, 36, 33, 3, 2, 2, 2, 36, 37, 3, 2, 2, 2, 37, 39, 3, 2, 2, 2, 38, 40, 5, 4, 3, 2, 39, 38, 3, 2, 2, 2, 39, 40, 3, 2, 2, 2, 40, 41, 3, 2, 2, 2, 41, 42, 7, 13, 2, 2, 42, 43, 7, 15, 2, 2, 43, 44, 7, 4, 2, 2, 44, 45, 7, 5, 2, 2, 45, 58, 7, 6, 2, 2, 46, 47, 7, 7, 2, 2, 47, 48, 7, 8, 2, 2, 48, 59, 5, 26, 14, 2, 49, 50, 7, 21, 2, 2, 50, 51, 7, 9, 2, 2, 51, 52, 7, 22, 2, 2, 52, 53, 7, 4, 2, 2, 53, 54, 7, 10, 2, 2, 54, 55, 7, 11, 2, 2, 55, 56, 5, 26, 14, 2, 56, 57, 7, 5, 2, 2, 57, 59, 3, 2, 2, 2, 58, 46, 3, 2, 2, 2, 58, 49, 3, 2, 2, 2, 59, 60, 3, 2, 2, 2, 60, 61, 7, 12, 2, 2, 61, 62, 7, 2, 2, 3, 62, 3, 3, 2, 2, 2, 63, 66, 5, 6, 4, 2, 64, 66, 5, 8, 5, 2, 65, 63, 3, 2, 2, 2, 65, 64, 3, 2, 2, 2, 66, 67, 3, 2, 2, 2, 67, 68, 7, 3, 2, 2, 68, 70, 3, 2, 2, 2, 69, 65, 3, 2, 2, 2, 70, 71, 3, 2, 2, 2, 71, 69, 3, 2, 2, 2, 71, 72, 3, 2, 2, 2, 72, 5, 3, 2, 2, 2, 73, 74, 7, 19, 2, 2, 74, 75, 7, 24, 2, 2, 75, 76, 5, 10, 6, 2, 76, 7, 3, 2, 2, 2, 77, 78, 7, 13, 2, 2, 78, 79, 7, 4, 2, 2, 79, 80, 5, 24, 13, 2, 80, 81, 7, 5, 2, 2, 81, 82, 5, 20, 11, 2, 82, 83, 7, 6, 2, 2, 83, 84, 7, 17, 2, 2, 84, 85, 5, 26, 14, 2, 85, 86, 7, 12, 2, 2, 86, 9, 3, 2, 2, 2, 87, 88, 7, 18, 2, 2, 88, 90, 7, 6, 2, 2, 89, 91, 5, 12, 7, 2, 90, 89, 3, 2, 2, 2, 90, 91, 3, 2, 2, 2, 91, 92, 3, 2, 2, 2, 92, 100, 7, 12, 2, 2, 93, 94, 7, 14, 2, 2, 94, 96, 7, 6, 2, 2, 95, 97, 5, 16, 9, 2, 96, 95, 3, 2, 2, 2, 96, 97, 3, 2, 2, 2, 97, 98, 3, 2, 2, 2, 98, 100, 7, 12, 2, 2, 99, 87, 3, 2, 2, 2, 99, 93, 3, 2, 2, 2, 100, 11, 3, 2, 2, 2, 101, 106, 5, 14, 8, 2, 102, 103, 7, 3, 2, 2, 103, 105, 5, 14, 8, 2, 104, 102, 3, 2, 2, 2, 105, 108, 3, 2, 2, 2, 106, 104, 3, 2, 2, 2, 106, 107, 3, 2, 2, 2, 107, 13, 3, 2, 2, 2, 108, 106, 3, 2, 2, 2, 109, 110, 7, 24, 2, 2, 110, 111, 7, 24, 2, 2, 111, 15, 3, 2, 2, 2, 112, 117, 5, 18, 10, 2, 113, 114, 7, 3, 2, 2, 114, 116, 5, 18, 10, 2, 115, 113, 3, 2, 2, 2, 116, 119, 3, 2, 2, 2, 117, 115, 3, 2, 2, 2, 117, 118, 3, 2, 2, 2, 118, 17, 3, 2, 2, 2, 119, 117, 3, 2, 2, 2, 120, 123, 5, 20, 11, 2, 121, 123, 7, 24, 2, 2, 122, 120, 3, 2, 2, 2, 122, 121, 3, 2, 2, 2, 123, 19, 3, 2, 2, 2, 124, 125, 7, 24, 2, 2, 125, 127, 7, 4, 2, 2, 126, 128, 5, 22, 12, 2, 127, 126, 3, 2, 2, 2, 127, 128, 3, 2, 2, 2, 128, 129, 3, 2, 2, 2, 129, 130, 7, 5, 2, 2, 130, 131, 7, 24, 2, 2, 131, 21, 3, 2, 2, 2, 132, 137, 5, 24, 13, 2, 133, 134, 7, 11, 2, 2, 134, 136, 5, 24, 13, 2, 135, 133, 3, 2, 2, 2, 136, 139, 3, 2, 2, 2, 137, 135, 3, 2, 2, 2, 137, 138, 3, 2, 2, 2, 138, 23, 3, 2, 2, 2, 139, 137, 3, 2, 2, 2, 140, 141, 7, 24, 2, 2, 141, 142, 7, 24, 2, 2, 142, 25, 3, 2, 2, 2, 143, 144, 8, 14, 1, 2, 144, 165, 7, 24, 2, 2, 145, 146, 7, 24, 2, 2, 146, 148, 7, 6, 2, 2, 147, 149, 5, 28, 15, 2, 148, 147, 3, 2, 2, 2, 148, 149, 3, 2, 2, 2, 149, 150, 3, 2, 2, 2, 150, 165, 7, 12, 2, 2, 151, 152, 7, 21, 2, 2, 152, 153, 7, 9, 2, 2, 153, 154, 7, 23, 2, 2, 154, 155, 7, 4, 2, 2, 155, 160, 9, 2, 2, 2, 156, 159, 7, 11, 2, 2, 157, 159, 5, 26, 14, 2, 158, 156, 3, 2, 2, 2, 158, 157, 3, 2, 2, 2, 159, 162, 3, 2, 2, 2, 160, 158, 3, 2, 2, 2, 160, 161, 3, 2, 2, 2, 161, 163, 3, 2, 2, 2, 162, 160, 3, 2, 2, 2, 163, 165, 7, 5, 2, 2, 164, 143, 3, 2, 2, 2, 164, 145, 3, 2, 2, 2, 164, 151, 3, 2, 2, 2, 165, 184, 3, 2, 2, 2, 166, 167, 12, 6, 2, 2, 167, 168, 7, 9, 2, 2, 168, 183, 7, 24, 2, 2, 169, 170, 12, 5, 2, 2, 170, 171, 7, 9, 2, 2, 171, 172, 7, 24, 2, 2, 172, 174, 7, 4, 2, 2, 173, 175, 5, 28, 15, 2, 174, 173, 3, 2, 2, 2, 174, 175, 3, 2, 2, 2, 175, 176, 3, 2, 2, 2, 176, 183, 7, 5, 2, 2, 177, 178, 12, 4, 2, 2, 178, 179, 7, 9, 2, 2, 179, 180, 7, 4, 2, 2, 180, 181, 7, 24, 2, 2, 181, 183, 7, 5, 2, 2, 182, 166, 3, 2, 2, 2, 182, 169, 3, 2, 2, 2, 182, 177, 3, 2, 2, 2, 183, 186, 3, 2, 2, 2, 184, 182, 3, 2, 2, 2, 184, 185, 3, 2, 2, 2, 185, 27, 3, 2, 2, 2, 186, 184, 3, 2, 2, 2, 187, 192, 5, 26, 14, 2, 188, 189, 7, 11, 2, 2, 189, 191, 5, 26, 14, 2, 190, 188, 3, 2, 2, 2, 191, 194, 3, 2, 2, 2, 192, 190, 3, 2, 2, 2, 192, 193, 3, 2, 2, 2, 193, 29, 3, 2, 2, 2, 194, 192, 3, 2, 2, 2, 23, 36, 39, 58, 65, 71, 90, 96, 99, 106, 117, 122, 127, 137, 148, 158, 160, 164, 174, 182, 184, 192]
--------------------------------------------------------------------------------
/parser/pregen/fg/parser/FG.tokens:
--------------------------------------------------------------------------------
 1 | T__0=1
 2 | T__1=2
 3 | T__2=3
 4 | T__3=4
 5 | T__4=5
 6 | T__5=6
 7 | T__6=7
 8 | T__7=8
 9 | T__8=9
10 | T__9=10
11 | FUNC=11
12 | INTERFACE=12
13 | MAIN=13
14 | PACKAGE=14
15 | RETURN=15
16 | STRUCT=16
17 | TYPE=17
18 | IMPORT=18
19 | FMT=19
20 | PRINTF=20
21 | SPRINTF=21
22 | NAME=22
23 | WHITESPACE=23
24 | COMMENT=24
25 | LINE_COMMENT=25
26 | STRING=26
27 | ';'=1
28 | '('=2
29 | ')'=3
30 | '{'=4
31 | '_'=5
32 | '='=6
33 | '.'=7
34 | '"%#v"'=8
35 | ','=9
36 | '}'=10
37 | 'func'=11
38 | 'interface'=12
39 | 'main'=13
40 | 'package'=14
41 | 'return'=15
42 | 'struct'=16
43 | 'type'=17
44 | 'import'=18
45 | 'fmt'=19
46 | 'Printf'=20
47 | 'Sprintf'=21
48 | 
--------------------------------------------------------------------------------
/parser/pregen/fg/parser/FGLexer.tokens:
--------------------------------------------------------------------------------
 1 | T__0=1
 2 | T__1=2
 3 | T__2=3
 4 | T__3=4
 5 | T__4=5
 6 | T__5=6
 7 | T__6=7
 8 | T__7=8
 9 | T__8=9
10 | T__9=10
11 | FUNC=11
12 | INTERFACE=12
13 | MAIN=13
14 | PACKAGE=14
15 | RETURN=15
16 | STRUCT=16
17 | TYPE=17
18 | IMPORT=18
19 | FMT=19
20 | PRINTF=20
21 | SPRINTF=21
22 | NAME=22
23 | WHITESPACE=23
24 | COMMENT=24
25 | LINE_COMMENT=25
26 | STRING=26
27 | ';'=1
28 | '('=2
29 | ')'=3
30 | '{'=4
31 | '_'=5
32 | '='=6
33 | '.'=7
34 | '"%#v"'=8
35 | ','=9
36 | '}'=10
37 | 'func'=11
38 | 'interface'=12
39 | 'main'=13
40 | 'package'=14
41 | 'return'=15
42 | 'struct'=16
43 | 'type'=17
44 | 'import'=18
45 | 'fmt'=19
46 | 'Printf'=20
47 | 'Sprintf'=21
48 | 
--------------------------------------------------------------------------------
/parser/pregen/fg/parser/fg_base_listener.go:
--------------------------------------------------------------------------------
  1 | // Code generated from parser/FG.g4 by ANTLR 4.7.2. DO NOT EDIT.
  2 | 
  3 | package parser // FG
  4 | 
  5 | import "github.com/antlr/antlr4/runtime/Go/antlr"
  6 | 
  7 | // BaseFGListener is a complete listener for a parse tree produced by FGParser.
  8 | type BaseFGListener struct{}
  9 | 
 10 | var _ FGListener = &BaseFGListener{}
 11 | 
 12 | // VisitTerminal is called when a terminal node is visited.
 13 | func (s *BaseFGListener) VisitTerminal(node antlr.TerminalNode) {}
 14 | 
 15 | // VisitErrorNode is called when an error node is visited.
 16 | func (s *BaseFGListener) VisitErrorNode(node antlr.ErrorNode) {}
 17 | 
 18 | // EnterEveryRule is called when any rule is entered.
 19 | func (s *BaseFGListener) EnterEveryRule(ctx antlr.ParserRuleContext) {}
 20 | 
 21 | // ExitEveryRule is called when any rule is exited.
 22 | func (s *BaseFGListener) ExitEveryRule(ctx antlr.ParserRuleContext) {}
 23 | 
 24 | // EnterProgram is called when production program is entered.
 25 | func (s *BaseFGListener) EnterProgram(ctx *ProgramContext) {}
 26 | 
 27 | // ExitProgram is called when production program is exited.
 28 | func (s *BaseFGListener) ExitProgram(ctx *ProgramContext) {}
 29 | 
 30 | // EnterDecls is called when production decls is entered.
 31 | func (s *BaseFGListener) EnterDecls(ctx *DeclsContext) {}
 32 | 
 33 | // ExitDecls is called when production decls is exited.
 34 | func (s *BaseFGListener) ExitDecls(ctx *DeclsContext) {}
 35 | 
 36 | // EnterTypeDecl is called when production typeDecl is entered.
 37 | func (s *BaseFGListener) EnterTypeDecl(ctx *TypeDeclContext) {}
 38 | 
 39 | // ExitTypeDecl is called when production typeDecl is exited.
 40 | func (s *BaseFGListener) ExitTypeDecl(ctx *TypeDeclContext) {}
 41 | 
 42 | // EnterMethDecl is called when production methDecl is entered.
 43 | func (s *BaseFGListener) EnterMethDecl(ctx *MethDeclContext) {}
 44 | 
 45 | // ExitMethDecl is called when production methDecl is exited.
 46 | func (s *BaseFGListener) ExitMethDecl(ctx *MethDeclContext) {}
 47 | 
 48 | // EnterStructTypeLit is called when production StructTypeLit is entered.
 49 | func (s *BaseFGListener) EnterStructTypeLit(ctx *StructTypeLitContext) {}
 50 | 
 51 | // ExitStructTypeLit is called when production StructTypeLit is exited.
 52 | func (s *BaseFGListener) ExitStructTypeLit(ctx *StructTypeLitContext) {}
 53 | 
 54 | // EnterInterfaceTypeLit is called when production InterfaceTypeLit is entered.
 55 | func (s *BaseFGListener) EnterInterfaceTypeLit(ctx *InterfaceTypeLitContext) {}
 56 | 
 57 | // ExitInterfaceTypeLit is called when production InterfaceTypeLit is exited.
 58 | func (s *BaseFGListener) ExitInterfaceTypeLit(ctx *InterfaceTypeLitContext) {}
 59 | 
 60 | // EnterFieldDecls is called when production fieldDecls is entered.
 61 | func (s *BaseFGListener) EnterFieldDecls(ctx *FieldDeclsContext) {}
 62 | 
 63 | // ExitFieldDecls is called when production fieldDecls is exited.
 64 | func (s *BaseFGListener) ExitFieldDecls(ctx *FieldDeclsContext) {}
 65 | 
 66 | // EnterFieldDecl is called when production fieldDecl is entered.
 67 | func (s *BaseFGListener) EnterFieldDecl(ctx *FieldDeclContext) {}
 68 | 
 69 | // ExitFieldDecl is called when production fieldDecl is exited.
 70 | func (s *BaseFGListener) ExitFieldDecl(ctx *FieldDeclContext) {}
 71 | 
 72 | // EnterSpecs is called when production specs is entered.
 73 | func (s *BaseFGListener) EnterSpecs(ctx *SpecsContext) {}
 74 | 
 75 | // ExitSpecs is called when production specs is exited.
 76 | func (s *BaseFGListener) ExitSpecs(ctx *SpecsContext) {}
 77 | 
 78 | // EnterSigSpec is called when production SigSpec is entered.
 79 | func (s *BaseFGListener) EnterSigSpec(ctx *SigSpecContext) {}
 80 | 
 81 | // ExitSigSpec is called when production SigSpec is exited.
 82 | func (s *BaseFGListener) ExitSigSpec(ctx *SigSpecContext) {}
 83 | 
 84 | // EnterInterfaceSpec is called when production InterfaceSpec is entered.
 85 | func (s *BaseFGListener) EnterInterfaceSpec(ctx *InterfaceSpecContext) {}
 86 | 
 87 | // ExitInterfaceSpec is called when production InterfaceSpec is exited.
 88 | func (s *BaseFGListener) ExitInterfaceSpec(ctx *InterfaceSpecContext) {}
 89 | 
 90 | // EnterSig is called when production sig is entered.
 91 | func (s *BaseFGListener) EnterSig(ctx *SigContext) {}
 92 | 
 93 | // ExitSig is called when production sig is exited.
 94 | func (s *BaseFGListener) ExitSig(ctx *SigContext) {}
 95 | 
 96 | // EnterParams is called when production params is entered.
 97 | func (s *BaseFGListener) EnterParams(ctx *ParamsContext) {}
 98 | 
 99 | // ExitParams is called when production params is exited.
100 | func (s *BaseFGListener) ExitParams(ctx *ParamsContext) {}
101 | 
102 | // EnterParamDecl is called when production paramDecl is entered.
103 | func (s *BaseFGListener) EnterParamDecl(ctx *ParamDeclContext) {}
104 | 
105 | // ExitParamDecl is called when production paramDecl is exited.
106 | func (s *BaseFGListener) ExitParamDecl(ctx *ParamDeclContext) {}
107 | 
108 | // EnterCall is called when production Call is entered.
109 | func (s *BaseFGListener) EnterCall(ctx *CallContext) {}
110 | 
111 | // ExitCall is called when production Call is exited.
112 | func (s *BaseFGListener) ExitCall(ctx *CallContext) {}
113 | 
114 | // EnterVariable is called when production Variable is entered.
115 | func (s *BaseFGListener) EnterVariable(ctx *VariableContext) {}
116 | 
117 | // ExitVariable is called when production Variable is exited.
118 | func (s *BaseFGListener) ExitVariable(ctx *VariableContext) {}
119 | 
120 | // EnterAssert is called when production Assert is entered.
121 | func (s *BaseFGListener) EnterAssert(ctx *AssertContext) {}
122 | 
123 | // ExitAssert is called when production Assert is exited.
124 | func (s *BaseFGListener) ExitAssert(ctx *AssertContext) {}
125 | 
126 | // EnterSprintf is called when production Sprintf is entered.
127 | func (s *BaseFGListener) EnterSprintf(ctx *SprintfContext) {}
128 | 
129 | // ExitSprintf is called when production Sprintf is exited.
130 | func (s *BaseFGListener) ExitSprintf(ctx *SprintfContext) {}
131 | 
132 | // EnterSelect is called when production Select is entered.
133 | func (s *BaseFGListener) EnterSelect(ctx *SelectContext) {}
134 | 
135 | // ExitSelect is called when production Select is exited.
136 | func (s *BaseFGListener) ExitSelect(ctx *SelectContext) {}
137 | 
138 | // EnterStructLit is called when production StructLit is entered.
139 | func (s *BaseFGListener) EnterStructLit(ctx *StructLitContext) {}
140 | 
141 | // ExitStructLit is called when production StructLit is exited.
142 | func (s *BaseFGListener) ExitStructLit(ctx *StructLitContext) {}
143 | 
144 | // EnterExprs is called when production exprs is entered.
145 | func (s *BaseFGListener) EnterExprs(ctx *ExprsContext) {}
146 | 
147 | // ExitExprs is called when production exprs is exited.
148 | func (s *BaseFGListener) ExitExprs(ctx *ExprsContext) {}
149 | 
--------------------------------------------------------------------------------
/parser/pregen/fg/parser/fg_listener.go:
--------------------------------------------------------------------------------
  1 | // Code generated from parser/FG.g4 by ANTLR 4.7.2. DO NOT EDIT.
  2 | 
  3 | package parser // FG
  4 | 
  5 | import "github.com/antlr/antlr4/runtime/Go/antlr"
  6 | 
  7 | // FGListener is a complete listener for a parse tree produced by FGParser.
  8 | type FGListener interface {
  9 | 	antlr.ParseTreeListener
 10 | 
 11 | 	// EnterProgram is called when entering the program production.
 12 | 	EnterProgram(c *ProgramContext)
 13 | 
 14 | 	// EnterDecls is called when entering the decls production.
 15 | 	EnterDecls(c *DeclsContext)
 16 | 
 17 | 	// EnterTypeDecl is called when entering the typeDecl production.
 18 | 	EnterTypeDecl(c *TypeDeclContext)
 19 | 
 20 | 	// EnterMethDecl is called when entering the methDecl production.
 21 | 	EnterMethDecl(c *MethDeclContext)
 22 | 
 23 | 	// EnterStructTypeLit is called when entering the StructTypeLit production.
 24 | 	EnterStructTypeLit(c *StructTypeLitContext)
 25 | 
 26 | 	// EnterInterfaceTypeLit is called when entering the InterfaceTypeLit production.
 27 | 	EnterInterfaceTypeLit(c *InterfaceTypeLitContext)
 28 | 
 29 | 	// EnterFieldDecls is called when entering the fieldDecls production.
 30 | 	EnterFieldDecls(c *FieldDeclsContext)
 31 | 
 32 | 	// EnterFieldDecl is called when entering the fieldDecl production.
 33 | 	EnterFieldDecl(c *FieldDeclContext)
 34 | 
 35 | 	// EnterSpecs is called when entering the specs production.
 36 | 	EnterSpecs(c *SpecsContext)
 37 | 
 38 | 	// EnterSigSpec is called when entering the SigSpec production.
 39 | 	EnterSigSpec(c *SigSpecContext)
 40 | 
 41 | 	// EnterInterfaceSpec is called when entering the InterfaceSpec production.
 42 | 	EnterInterfaceSpec(c *InterfaceSpecContext)
 43 | 
 44 | 	// EnterSig is called when entering the sig production.
 45 | 	EnterSig(c *SigContext)
 46 | 
 47 | 	// EnterParams is called when entering the params production.
 48 | 	EnterParams(c *ParamsContext)
 49 | 
 50 | 	// EnterParamDecl is called when entering the paramDecl production.
 51 | 	EnterParamDecl(c *ParamDeclContext)
 52 | 
 53 | 	// EnterCall is called when entering the Call production.
 54 | 	EnterCall(c *CallContext)
 55 | 
 56 | 	// EnterVariable is called when entering the Variable production.
 57 | 	EnterVariable(c *VariableContext)
 58 | 
 59 | 	// EnterAssert is called when entering the Assert production.
 60 | 	EnterAssert(c *AssertContext)
 61 | 
 62 | 	// EnterSprintf is called when entering the Sprintf production.
 63 | 	EnterSprintf(c *SprintfContext)
 64 | 
 65 | 	// EnterSelect is called when entering the Select production.
 66 | 	EnterSelect(c *SelectContext)
 67 | 
 68 | 	// EnterStructLit is called when entering the StructLit production.
 69 | 	EnterStructLit(c *StructLitContext)
 70 | 
 71 | 	// EnterExprs is called when entering the exprs production.
 72 | 	EnterExprs(c *ExprsContext)
 73 | 
 74 | 	// ExitProgram is called when exiting the program production.
 75 | 	ExitProgram(c *ProgramContext)
 76 | 
 77 | 	// ExitDecls is called when exiting the decls production.
 78 | 	ExitDecls(c *DeclsContext)
 79 | 
 80 | 	// ExitTypeDecl is called when exiting the typeDecl production.
 81 | 	ExitTypeDecl(c *TypeDeclContext)
 82 | 
 83 | 	// ExitMethDecl is called when exiting the methDecl production.
 84 | 	ExitMethDecl(c *MethDeclContext)
 85 | 
 86 | 	// ExitStructTypeLit is called when exiting the StructTypeLit production.
 87 | 	ExitStructTypeLit(c *StructTypeLitContext)
 88 | 
 89 | 	// ExitInterfaceTypeLit is called when exiting the InterfaceTypeLit production.
 90 | 	ExitInterfaceTypeLit(c *InterfaceTypeLitContext)
 91 | 
 92 | 	// ExitFieldDecls is called when exiting the fieldDecls production.
 93 | 	ExitFieldDecls(c *FieldDeclsContext)
 94 | 
 95 | 	// ExitFieldDecl is called when exiting the fieldDecl production.
 96 | 	ExitFieldDecl(c *FieldDeclContext)
 97 | 
 98 | 	// ExitSpecs is called when exiting the specs production.
 99 | 	ExitSpecs(c *SpecsContext)
100 | 
101 | 	// ExitSigSpec is called when exiting the SigSpec production.
102 | 	ExitSigSpec(c *SigSpecContext)
103 | 
104 | 	// ExitInterfaceSpec is called when exiting the InterfaceSpec production.
105 | 	ExitInterfaceSpec(c *InterfaceSpecContext)
106 | 
107 | 	// ExitSig is called when exiting the sig production.
108 | 	ExitSig(c *SigContext)
109 | 
110 | 	// ExitParams is called when exiting the params production.
111 | 	ExitParams(c *ParamsContext)
112 | 
113 | 	// ExitParamDecl is called when exiting the paramDecl production.
114 | 	ExitParamDecl(c *ParamDeclContext)
115 | 
116 | 	// ExitCall is called when exiting the Call production.
117 | 	ExitCall(c *CallContext)
118 | 
119 | 	// ExitVariable is called when exiting the Variable production.
120 | 	ExitVariable(c *VariableContext)
121 | 
122 | 	// ExitAssert is called when exiting the Assert production.
123 | 	ExitAssert(c *AssertContext)
124 | 
125 | 	// ExitSprintf is called when exiting the Sprintf production.
126 | 	ExitSprintf(c *SprintfContext)
127 | 
128 | 	// ExitSelect is called when exiting the Select production.
129 | 	ExitSelect(c *SelectContext)
130 | 
131 | 	// ExitStructLit is called when exiting the StructLit production.
132 | 	ExitStructLit(c *StructLitContext)
133 | 
134 | 	// ExitExprs is called when exiting the exprs production.
135 | 	ExitExprs(c *ExprsContext)
136 | }
137 | 
--------------------------------------------------------------------------------
/parser/pregen/fgg/parser/FGG.tokens:
--------------------------------------------------------------------------------
 1 | T__0=1
 2 | T__1=2
 3 | T__2=3
 4 | T__3=4
 5 | T__4=5
 6 | T__5=6
 7 | T__6=7
 8 | T__7=8
 9 | T__8=9
10 | T__9=10
11 | FUNC=11
12 | INTERFACE=12
13 | MAIN=13
14 | PACKAGE=14
15 | RETURN=15
16 | STRUCT=16
17 | TYPE=17
18 | IMPORT=18
19 | FMT=19
20 | PRINTF=20
21 | SPRINTF=21
22 | NAME=22
23 | WHITESPACE=23
24 | COMMENT=24
25 | LINE_COMMENT=25
26 | STRING=26
27 | '('=1
28 | ')'=2
29 | ','=3
30 | ';'=4
31 | '{'=5
32 | '_'=6
33 | '='=7
34 | '.'=8
35 | '"%#v"'=9
36 | '}'=10
37 | 'func'=11
38 | 'interface'=12
39 | 'main'=13
40 | 'package'=14
41 | 'return'=15
42 | 'struct'=16
43 | 'type'=17
44 | 'import'=18
45 | 'fmt'=19
46 | 'Printf'=20
47 | 'Sprintf'=21
48 | 
--------------------------------------------------------------------------------
/parser/pregen/fgg/parser/FGGLexer.interp:
--------------------------------------------------------------------------------
 1 | token literal names:
 2 | null
 3 | '('
 4 | ')'
 5 | ','
 6 | ';'
 7 | '{'
 8 | '_'
 9 | '='
10 | '.'
11 | '"%#v"'
12 | '}'
13 | 'func'
14 | 'interface'
15 | 'main'
16 | 'package'
17 | 'return'
18 | 'struct'
19 | 'type'
20 | 'import'
21 | 'fmt'
22 | 'Printf'
23 | 'Sprintf'
24 | null
25 | null
26 | null
27 | null
28 | null
29 | 
30 | token symbolic names:
31 | null
32 | null
33 | null
34 | null
35 | null
36 | null
37 | null
38 | null
39 | null
40 | null
41 | null
42 | FUNC
43 | INTERFACE
44 | MAIN
45 | PACKAGE
46 | RETURN
47 | STRUCT
48 | TYPE
49 | IMPORT
50 | FMT
51 | PRINTF
52 | SPRINTF
53 | NAME
54 | WHITESPACE
55 | COMMENT
56 | LINE_COMMENT
57 | STRING
58 | 
59 | rule names:
60 | T__0
61 | T__1
62 | T__2
63 | T__3
64 | T__4
65 | T__5
66 | T__6
67 | T__7
68 | T__8
69 | T__9
70 | FUNC
71 | INTERFACE
72 | MAIN
73 | PACKAGE
74 | RETURN
75 | STRUCT
76 | TYPE
77 | IMPORT
78 | FMT
79 | PRINTF
80 | SPRINTF
81 | LETTER
82 | DIGIT
83 | NAME
84 | WHITESPACE
85 | COMMENT
86 | LINE_COMMENT
87 | STRING
88 | 
89 | channel names:
90 | DEFAULT_TOKEN_CHANNEL
91 | HIDDEN
92 | 
93 | mode names:
94 | DEFAULT_MODE
95 | 
96 | atn:
97 | [3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 28, 216, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 4, 12, 9, 12, 4, 13, 9, 13, 4, 14, 9, 14, 4, 15, 9, 15, 4, 16, 9, 16, 4, 17, 9, 17, 4, 18, 9, 18, 4, 19, 9, 19, 4, 20, 9, 20, 4, 21, 9, 21, 4, 22, 9, 22, 4, 23, 9, 23, 4, 24, 9, 24, 4, 25, 9, 25, 4, 26, 9, 26, 4, 27, 9, 27, 4, 28, 9, 28, 4, 29, 9, 29, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 10, 3, 11, 3, 11, 3, 12, 3, 12, 3, 12, 3, 12, 3, 12, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 13, 3, 14, 3, 14, 3, 14, 3, 14, 3, 14, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 15, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 16, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 17, 3, 18, 3, 18, 3, 18, 3, 18, 3, 18, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 19, 3, 20, 3, 20, 3, 20, 3, 20, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 21, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 22, 3, 23, 5, 23, 158, 10, 23, 3, 24, 3, 24, 3, 25, 3, 25, 5, 25, 164, 10, 25, 3, 25, 3, 25, 3, 25, 7, 25, 169, 10, 25, 12, 25, 14, 25, 172, 11, 25, 3, 26, 6, 26, 175, 10, 26, 13, 26, 14, 26, 176, 3, 26, 3, 26, 3, 27, 3, 27, 3, 27, 3, 27, 7, 27, 185, 10, 27, 12, 27, 14, 27, 188, 11, 27, 3, 27, 3, 27, 3, 27, 3, 27, 3, 27, 3, 28, 3, 28, 3, 28, 3, 28, 7, 28, 199, 10, 28, 12, 28, 14, 28, 202, 11, 28, 3, 28, 3, 28, 3, 29, 3, 29, 3, 29, 3, 29, 7, 29, 210, 10, 29, 12, 29, 14, 29, 213, 11, 29, 3, 29, 3, 29, 3, 186, 2, 30, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 23, 13, 25, 14, 27, 15, 29, 16, 31, 17, 33, 18, 35, 19, 37, 20, 39, 21, 41, 22, 43, 23, 45, 2, 47, 2, 49, 24, 51, 25, 53, 26, 55, 27, 57, 28, 3, 2, 6, 5, 2, 67, 92, 99, 124, 947, 948, 5, 2, 11, 12, 15, 15, 34, 34, 4, 2, 12, 12, 15, 15, 8, 2, 34, 34, 37, 37, 39, 39, 42, 43, 45, 48, 97, 97, 2, 223, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 2, 23, 3, 2, 2, 2, 2, 25, 3, 2, 2, 2, 2, 27, 3, 2, 2, 2, 2, 29, 3, 2, 2, 2, 2, 31, 3, 2, 2, 2, 2, 33, 3, 2, 2, 2, 2, 35, 3, 2, 2, 2, 2, 37, 3, 2, 2, 2, 2, 39, 3, 2, 2, 2, 2, 41, 3, 2, 2, 2, 2, 43, 3, 2, 2, 2, 2, 49, 3, 2, 2, 2, 2, 51, 3, 2, 2, 2, 2, 53, 3, 2, 2, 2, 2, 55, 3, 2, 2, 2, 2, 57, 3, 2, 2, 2, 3, 59, 3, 2, 2, 2, 5, 61, 3, 2, 2, 2, 7, 63, 3, 2, 2, 2, 9, 65, 3, 2, 2, 2, 11, 67, 3, 2, 2, 2, 13, 69, 3, 2, 2, 2, 15, 71, 3, 2, 2, 2, 17, 73, 3, 2, 2, 2, 19, 75, 3, 2, 2, 2, 21, 81, 3, 2, 2, 2, 23, 83, 3, 2, 2, 2, 25, 88, 3, 2, 2, 2, 27, 98, 3, 2, 2, 2, 29, 103, 3, 2, 2, 2, 31, 111, 3, 2, 2, 2, 33, 118, 3, 2, 2, 2, 35, 125, 3, 2, 2, 2, 37, 130, 3, 2, 2, 2, 39, 137, 3, 2, 2, 2, 41, 141, 3, 2, 2, 2, 43, 148, 3, 2, 2, 2, 45, 157, 3, 2, 2, 2, 47, 159, 3, 2, 2, 2, 49, 163, 3, 2, 2, 2, 51, 174, 3, 2, 2, 2, 53, 180, 3, 2, 2, 2, 55, 194, 3, 2, 2, 2, 57, 205, 3, 2, 2, 2, 59, 60, 7, 42, 2, 2, 60, 4, 3, 2, 2, 2, 61, 62, 7, 43, 2, 2, 62, 6, 3, 2, 2, 2, 63, 64, 7, 46, 2, 2, 64, 8, 3, 2, 2, 2, 65, 66, 7, 61, 2, 2, 66, 10, 3, 2, 2, 2, 67, 68, 7, 125, 2, 2, 68, 12, 3, 2, 2, 2, 69, 70, 7, 97, 2, 2, 70, 14, 3, 2, 2, 2, 71, 72, 7, 63, 2, 2, 72, 16, 3, 2, 2, 2, 73, 74, 7, 48, 2, 2, 74, 18, 3, 2, 2, 2, 75, 76, 7, 36, 2, 2, 76, 77, 7, 39, 2, 2, 77, 78, 7, 37, 2, 2, 78, 79, 7, 120, 2, 2, 79, 80, 7, 36, 2, 2, 80, 20, 3, 2, 2, 2, 81, 82, 7, 127, 2, 2, 82, 22, 3, 2, 2, 2, 83, 84, 7, 104, 2, 2, 84, 85, 7, 119, 2, 2, 85, 86, 7, 112, 2, 2, 86, 87, 7, 101, 2, 2, 87, 24, 3, 2, 2, 2, 88, 89, 7, 107, 2, 2, 89, 90, 7, 112, 2, 2, 90, 91, 7, 118, 2, 2, 91, 92, 7, 103, 2, 2, 92, 93, 7, 116, 2, 2, 93, 94, 7, 104, 2, 2, 94, 95, 7, 99, 2, 2, 95, 96, 7, 101, 2, 2, 96, 97, 7, 103, 2, 2, 97, 26, 3, 2, 2, 2, 98, 99, 7, 111, 2, 2, 99, 100, 7, 99, 2, 2, 100, 101, 7, 107, 2, 2, 101, 102, 7, 112, 2, 2, 102, 28, 3, 2, 2, 2, 103, 104, 7, 114, 2, 2, 104, 105, 7, 99, 2, 2, 105, 106, 7, 101, 2, 2, 106, 107, 7, 109, 2, 2, 107, 108, 7, 99, 2, 2, 108, 109, 7, 105, 2, 2, 109, 110, 7, 103, 2, 2, 110, 30, 3, 2, 2, 2, 111, 112, 7, 116, 2, 2, 112, 113, 7, 103, 2, 2, 113, 114, 7, 118, 2, 2, 114, 115, 7, 119, 2, 2, 115, 116, 7, 116, 2, 2, 116, 117, 7, 112, 2, 2, 117, 32, 3, 2, 2, 2, 118, 119, 7, 117, 2, 2, 119, 120, 7, 118, 2, 2, 120, 121, 7, 116, 2, 2, 121, 122, 7, 119, 2, 2, 122, 123, 7, 101, 2, 2, 123, 124, 7, 118, 2, 2, 124, 34, 3, 2, 2, 2, 125, 126, 7, 118, 2, 2, 126, 127, 7, 123, 2, 2, 127, 128, 7, 114, 2, 2, 128, 129, 7, 103, 2, 2, 129, 36, 3, 2, 2, 2, 130, 131, 7, 107, 2, 2, 131, 132, 7, 111, 2, 2, 132, 133, 7, 114, 2, 2, 133, 134, 7, 113, 2, 2, 134, 135, 7, 116, 2, 2, 135, 136, 7, 118, 2, 2, 136, 38, 3, 2, 2, 2, 137, 138, 7, 104, 2, 2, 138, 139, 7, 111, 2, 2, 139, 140, 7, 118, 2, 2, 140, 40, 3, 2, 2, 2, 141, 142, 7, 82, 2, 2, 142, 143, 7, 116, 2, 2, 143, 144, 7, 107, 2, 2, 144, 145, 7, 112, 2, 2, 145, 146, 7, 118, 2, 2, 146, 147, 7, 104, 2, 2, 147, 42, 3, 2, 2, 2, 148, 149, 7, 85, 2, 2, 149, 150, 7, 114, 2, 2, 150, 151, 7, 116, 2, 2, 151, 152, 7, 107, 2, 2, 152, 153, 7, 112, 2, 2, 153, 154, 7, 118, 2, 2, 154, 155, 7, 104, 2, 2, 155, 44, 3, 2, 2, 2, 156, 158, 9, 2, 2, 2, 157, 156, 3, 2, 2, 2, 158, 46, 3, 2, 2, 2, 159, 160, 4, 50, 59, 2, 160, 48, 3, 2, 2, 2, 161, 164, 5, 45, 23, 2, 162, 164, 7, 97, 2, 2, 163, 161, 3, 2, 2, 2, 163, 162, 3, 2, 2, 2, 164, 170, 3, 2, 2, 2, 165, 169, 5, 45, 23, 2, 166, 169, 7, 97, 2, 2, 167, 169, 5, 47, 24, 2, 168, 165, 3, 2, 2, 2, 168, 166, 3, 2, 2, 2, 168, 167, 3, 2, 2, 2, 169, 172, 3, 2, 2, 2, 170, 168, 3, 2, 2, 2, 170, 171, 3, 2, 2, 2, 171, 50, 3, 2, 2, 2, 172, 170, 3, 2, 2, 2, 173, 175, 9, 3, 2, 2, 174, 173, 3, 2, 2, 2, 175, 176, 3, 2, 2, 2, 176, 174, 3, 2, 2, 2, 176, 177, 3, 2, 2, 2, 177, 178, 3, 2, 2, 2, 178, 179, 8, 26, 2, 2, 179, 52, 3, 2, 2, 2, 180, 181, 7, 49, 2, 2, 181, 182, 7, 44, 2, 2, 182, 186, 3, 2, 2, 2, 183, 185, 11, 2, 2, 2, 184, 183, 3, 2, 2, 2, 185, 188, 3, 2, 2, 2, 186, 187, 3, 2, 2, 2, 186, 184, 3, 2, 2, 2, 187, 189, 3, 2, 2, 2, 188, 186, 3, 2, 2, 2, 189, 190, 7, 44, 2, 2, 190, 191, 7, 49, 2, 2, 191, 192, 3, 2, 2, 2, 192, 193, 8, 27, 3, 2, 193, 54, 3, 2, 2, 2, 194, 195, 7, 49, 2, 2, 195, 196, 7, 49, 2, 2, 196, 200, 3, 2, 2, 2, 197, 199, 10, 4, 2, 2, 198, 197, 3, 2, 2, 2, 199, 202, 3, 2, 2, 2, 200, 198, 3, 2, 2, 2, 200, 201, 3, 2, 2, 2, 201, 203, 3, 2, 2, 2, 202, 200, 3, 2, 2, 2, 203, 204, 8, 28, 3, 2, 204, 56, 3, 2, 2, 2, 205, 211, 7, 36, 2, 2, 206, 210, 5, 45, 23, 2, 207, 210, 5, 47, 24, 2, 208, 210, 9, 5, 2, 2, 209, 206, 3, 2, 2, 2, 209, 207, 3, 2, 2, 2, 209, 208, 3, 2, 2, 2, 210, 213, 3, 2, 2, 2, 211, 209, 3, 2, 2, 2, 211, 212, 3, 2, 2, 2, 212, 214, 3, 2, 2, 2, 213, 211, 3, 2, 2, 2, 214, 215, 7, 36, 2, 2, 215, 58, 3, 2, 2, 2, 12, 2, 157, 163, 168, 170, 176, 186, 200, 209, 211, 4, 8, 2, 2, 2, 3, 2]
--------------------------------------------------------------------------------
/parser/pregen/fgg/parser/FGGLexer.tokens:
--------------------------------------------------------------------------------
 1 | T__0=1
 2 | T__1=2
 3 | T__2=3
 4 | T__3=4
 5 | T__4=5
 6 | T__5=6
 7 | T__6=7
 8 | T__7=8
 9 | T__8=9
10 | T__9=10
11 | FUNC=11
12 | INTERFACE=12
13 | MAIN=13
14 | PACKAGE=14
15 | RETURN=15
16 | STRUCT=16
17 | TYPE=17
18 | IMPORT=18
19 | FMT=19
20 | PRINTF=20
21 | SPRINTF=21
22 | NAME=22
23 | WHITESPACE=23
24 | COMMENT=24
25 | LINE_COMMENT=25
26 | STRING=26
27 | '('=1
28 | ')'=2
29 | ','=3
30 | ';'=4
31 | '{'=5
32 | '_'=6
33 | '='=7
34 | '.'=8
35 | '"%#v"'=9
36 | '}'=10
37 | 'func'=11
38 | 'interface'=12
39 | 'main'=13
40 | 'package'=14
41 | 'return'=15
42 | 'struct'=16
43 | 'type'=17
44 | 'import'=18
45 | 'fmt'=19
46 | 'Printf'=20
47 | 'Sprintf'=21
48 | 
--------------------------------------------------------------------------------
/parser/pregen/fgg/parser/fgg_listener.go:
--------------------------------------------------------------------------------
  1 | // Code generated from parser/FGG.g4 by ANTLR 4.7.2. DO NOT EDIT.
  2 | 
  3 | package parser // FGG
  4 | 
  5 | import "github.com/antlr/antlr4/runtime/Go/antlr"
  6 | 
  7 | // FGGListener is a complete listener for a parse tree produced by FGGParser.
  8 | type FGGListener interface {
  9 | 	antlr.ParseTreeListener
 10 | 
 11 | 	// EnterTypeParam is called when entering the TypeParam production.
 12 | 	EnterTypeParam(c *TypeParamContext)
 13 | 
 14 | 	// EnterTypeName is called when entering the TypeName production.
 15 | 	EnterTypeName(c *TypeNameContext)
 16 | 
 17 | 	// EnterTyps is called when entering the typs production.
 18 | 	EnterTyps(c *TypsContext)
 19 | 
 20 | 	// EnterTypeFormals is called when entering the typeFormals production.
 21 | 	EnterTypeFormals(c *TypeFormalsContext)
 22 | 
 23 | 	// EnterTypeFDecls is called when entering the typeFDecls production.
 24 | 	EnterTypeFDecls(c *TypeFDeclsContext)
 25 | 
 26 | 	// EnterTypeFDecl is called when entering the typeFDecl production.
 27 | 	EnterTypeFDecl(c *TypeFDeclContext)
 28 | 
 29 | 	// EnterProgram is called when entering the program production.
 30 | 	EnterProgram(c *ProgramContext)
 31 | 
 32 | 	// EnterDecls is called when entering the decls production.
 33 | 	EnterDecls(c *DeclsContext)
 34 | 
 35 | 	// EnterTypeDecl is called when entering the typeDecl production.
 36 | 	EnterTypeDecl(c *TypeDeclContext)
 37 | 
 38 | 	// EnterMethDecl is called when entering the methDecl production.
 39 | 	EnterMethDecl(c *MethDeclContext)
 40 | 
 41 | 	// EnterStructTypeLit is called when entering the StructTypeLit production.
 42 | 	EnterStructTypeLit(c *StructTypeLitContext)
 43 | 
 44 | 	// EnterInterfaceTypeLit is called when entering the InterfaceTypeLit production.
 45 | 	EnterInterfaceTypeLit(c *InterfaceTypeLitContext)
 46 | 
 47 | 	// EnterFieldDecls is called when entering the fieldDecls production.
 48 | 	EnterFieldDecls(c *FieldDeclsContext)
 49 | 
 50 | 	// EnterFieldDecl is called when entering the fieldDecl production.
 51 | 	EnterFieldDecl(c *FieldDeclContext)
 52 | 
 53 | 	// EnterSpecs is called when entering the specs production.
 54 | 	EnterSpecs(c *SpecsContext)
 55 | 
 56 | 	// EnterSigSpec is called when entering the SigSpec production.
 57 | 	EnterSigSpec(c *SigSpecContext)
 58 | 
 59 | 	// EnterInterfaceSpec is called when entering the InterfaceSpec production.
 60 | 	EnterInterfaceSpec(c *InterfaceSpecContext)
 61 | 
 62 | 	// EnterSig is called when entering the sig production.
 63 | 	EnterSig(c *SigContext)
 64 | 
 65 | 	// EnterParams is called when entering the params production.
 66 | 	EnterParams(c *ParamsContext)
 67 | 
 68 | 	// EnterParamDecl is called when entering the paramDecl production.
 69 | 	EnterParamDecl(c *ParamDeclContext)
 70 | 
 71 | 	// EnterCall is called when entering the Call production.
 72 | 	EnterCall(c *CallContext)
 73 | 
 74 | 	// EnterVariable is called when entering the Variable production.
 75 | 	EnterVariable(c *VariableContext)
 76 | 
 77 | 	// EnterAssert is called when entering the Assert production.
 78 | 	EnterAssert(c *AssertContext)
 79 | 
 80 | 	// EnterSprintf is called when entering the Sprintf production.
 81 | 	EnterSprintf(c *SprintfContext)
 82 | 
 83 | 	// EnterSelect is called when entering the Select production.
 84 | 	EnterSelect(c *SelectContext)
 85 | 
 86 | 	// EnterStructLit is called when entering the StructLit production.
 87 | 	EnterStructLit(c *StructLitContext)
 88 | 
 89 | 	// EnterExprs is called when entering the exprs production.
 90 | 	EnterExprs(c *ExprsContext)
 91 | 
 92 | 	// ExitTypeParam is called when exiting the TypeParam production.
 93 | 	ExitTypeParam(c *TypeParamContext)
 94 | 
 95 | 	// ExitTypeName is called when exiting the TypeName production.
 96 | 	ExitTypeName(c *TypeNameContext)
 97 | 
 98 | 	// ExitTyps is called when exiting the typs production.
 99 | 	ExitTyps(c *TypsContext)
100 | 
101 | 	// ExitTypeFormals is called when exiting the typeFormals production.
102 | 	ExitTypeFormals(c *TypeFormalsContext)
103 | 
104 | 	// ExitTypeFDecls is called when exiting the typeFDecls production.
105 | 	ExitTypeFDecls(c *TypeFDeclsContext)
106 | 
107 | 	// ExitTypeFDecl is called when exiting the typeFDecl production.
108 | 	ExitTypeFDecl(c *TypeFDeclContext)
109 | 
110 | 	// ExitProgram is called when exiting the program production.
111 | 	ExitProgram(c *ProgramContext)
112 | 
113 | 	// ExitDecls is called when exiting the decls production.
114 | 	ExitDecls(c *DeclsContext)
115 | 
116 | 	// ExitTypeDecl is called when exiting the typeDecl production.
117 | 	ExitTypeDecl(c *TypeDeclContext)
118 | 
119 | 	// ExitMethDecl is called when exiting the methDecl production.
120 | 	ExitMethDecl(c *MethDeclContext)
121 | 
122 | 	// ExitStructTypeLit is called when exiting the StructTypeLit production.
123 | 	ExitStructTypeLit(c *StructTypeLitContext)
124 | 
125 | 	// ExitInterfaceTypeLit is called when exiting the InterfaceTypeLit production.
126 | 	ExitInterfaceTypeLit(c *InterfaceTypeLitContext)
127 | 
128 | 	// ExitFieldDecls is called when exiting the fieldDecls production.
129 | 	ExitFieldDecls(c *FieldDeclsContext)
130 | 
131 | 	// ExitFieldDecl is called when exiting the fieldDecl production.
132 | 	ExitFieldDecl(c *FieldDeclContext)
133 | 
134 | 	// ExitSpecs is called when exiting the specs production.
135 | 	ExitSpecs(c *SpecsContext)
136 | 
137 | 	// ExitSigSpec is called when exiting the SigSpec production.
138 | 	ExitSigSpec(c *SigSpecContext)
139 | 
140 | 	// ExitInterfaceSpec is called when exiting the InterfaceSpec production.
141 | 	ExitInterfaceSpec(c *InterfaceSpecContext)
142 | 
143 | 	// ExitSig is called when exiting the sig production.
144 | 	ExitSig(c *SigContext)
145 | 
146 | 	// ExitParams is called when exiting the params production.
147 | 	ExitParams(c *ParamsContext)
148 | 
149 | 	// ExitParamDecl is called when exiting the paramDecl production.
150 | 	ExitParamDecl(c *ParamDeclContext)
151 | 
152 | 	// ExitCall is called when exiting the Call production.
153 | 	ExitCall(c *CallContext)
154 | 
155 | 	// ExitVariable is called when exiting the Variable production.
156 | 	ExitVariable(c *VariableContext)
157 | 
158 | 	// ExitAssert is called when exiting the Assert production.
159 | 	ExitAssert(c *AssertContext)
160 | 
161 | 	// ExitSprintf is called when exiting the Sprintf production.
162 | 	ExitSprintf(c *SprintfContext)
163 | 
164 | 	// ExitSelect is called when exiting the Select production.
165 | 	ExitSelect(c *SelectContext)
166 | 
167 | 	// ExitStructLit is called when exiting the StructLit production.
168 | 	ExitStructLit(c *StructLitContext)
169 | 
170 | 	// ExitExprs is called when exiting the exprs production.
171 | 	ExitExprs(c *ExprsContext)
172 | }
173 | 
--------------------------------------------------------------------------------