Skip to content

Commit

Permalink
Merge pull request #123 from ipld/gendemo-regularization
Browse files Browse the repository at this point in the history
clean up node/gendemo regeneration
  • Loading branch information
warpfork committed Dec 14, 2020
2 parents 5f00926 + acdc7fb commit 8ba7638
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 107 deletions.
15 changes: 0 additions & 15 deletions node/gendemo/HACKME.md

This file was deleted.

19 changes: 19 additions & 0 deletions node/gendemo/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// The gendemo package contains some what codegen output code,
// so that it can demonstrate what schema-based codegen looks and acts like.
//
// The main purpose is to benchmark things,
// and to provide an easy-to-look-at _thing_ for prospective users
// who want to lay eyes on generated code without needing to get up-and-running with the generator themselves.
//
// 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 in `gen.go` file.
// (This is currently wired directly in code; in the future, the same instructions
// will be extracted to an IPLD Schema file and standard tools will be used to process it.)
// The code generation is triggered by `go:generate` comments in the `doc.go` file.

//go:generate go run gen.go
//go:generate gofmt -w .

package gendemo
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)
}
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 8ba7638

Please sign in to comment.