Skip to content

Commit

Permalink
clean up node/gendemo; generation now has standard triggers.
Browse files Browse the repository at this point in the history
Do regeneratation.  Some diff churn: the codegen doesn't yet jive
smoothly with a recent change made in service to go vet.
We'll want to straighten that out soon, I guess.
  • Loading branch information
warpfork committed Dec 14, 2020
1 parent 5f00926 commit 7849b87
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 93 deletions.
3 changes: 2 additions & 1 deletion node/gendemo/HACKME.md → node/gendemo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ who want to lay eyes on generated code without needing to get up-and-running wit
This package is absolutely _not_ full of general purpose node implementations
that you should use in _any_ application.

The input info for the code generation is at the top of the `hax_test.go` file.
The input info for the code generation is in `gen.go` file.
(This'll be extracted to be its own schema file, etc, later --
but you'll have to imagine that part; at present, it's wired directly in code.)
The code generation is triggered by `go:generate` comments in `gen_trigger.go`.
28 changes: 28 additions & 0 deletions node/gendemo/gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// +build ignore

package main

import (
"github.com/ipld/go-ipld-prime/schema"
gengo "github.com/ipld/go-ipld-prime/schema/gen/go"
)

func main() {
pkgName := "gendemo"
ts := schema.TypeSystem{}
ts.Init()
adjCfg := &gengo.AdjunctCfg{}
ts.Accumulate(schema.SpawnInt("Int"))
ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnStruct("Msg3",
[]schema.StructField{
schema.SpawnStructField("whee", "Int", false, false),
schema.SpawnStructField("woot", "Int", false, false),
schema.SpawnStructField("waga", "Int", false, false),
},
schema.SpawnStructRepresentationMap(nil),
))
ts.Accumulate(schema.SpawnMap("Map__String__Msg3",
"String", "Msg3", false))
gengo.Generate(".", pkgName, ts, adjCfg)
}
4 changes: 4 additions & 0 deletions node/gendemo/gen_trigger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//go:generate go run gen.go
//go:generate gofmt -w .

package gendemo
27 changes: 0 additions & 27 deletions node/gendemo/hax_test.go → node/gendemo/gendemo_test.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
package gendemo

import (
"os/exec"
"testing"

"github.com/ipld/go-ipld-prime/node/tests"
"github.com/ipld/go-ipld-prime/schema"
gengo "github.com/ipld/go-ipld-prime/schema/gen/go"
)

// i am the worst person and this is the worst code
// but it does do codegen when you test this package!
// (it's also legitimately trash tho, because if you get a compile error, you have to manually rm the relevant files, which is not fun.)
func init() {
pkgName := "gendemo"
ts := schema.TypeSystem{}
ts.Init()
adjCfg := &gengo.AdjunctCfg{}
ts.Accumulate(schema.SpawnInt("Int"))
ts.Accumulate(schema.SpawnString("String"))
ts.Accumulate(schema.SpawnStruct("Msg3",
[]schema.StructField{
schema.SpawnStructField("whee", "Int", false, false),
schema.SpawnStructField("woot", "Int", false, false),
schema.SpawnStructField("waga", "Int", false, false),
},
schema.SpawnStructRepresentationMap(nil),
))
ts.Accumulate(schema.SpawnMap("Map__String__Msg3",
"String", "Msg3", false))
gengo.Generate(".", pkgName, ts, adjCfg)
exec.Command("go", "fmt").Run()
}

func BenchmarkMapStrInt_3n_AssembleStandard(b *testing.B) {
tests.SpecBenchmarkMapStrInt_3n_AssembleStandard(b, _Msg3__Prototype{})
}
Expand Down
Loading

0 comments on commit 7849b87

Please sign in to comment.