Unverified Commit 07d051e5 authored by Rod Vagg's avatar Rod Vagg

betterer codegen invocation

parent 035ab815
// +build ignore
package main package main
// based on https://github.com/ipld/go-ipld-prime-proto/blob/master/gen/main.go // based on https://github.com/ipld/go-ipld-prime-proto/blob/master/gen/main.go
import ( import (
"os/exec" "fmt"
"os"
"github.com/ipld/go-ipld-prime/schema" "github.com/ipld/go-ipld-prime/schema"
gengo "github.com/ipld/go-ipld-prime/schema/gen/go" gengo "github.com/ipld/go-ipld-prime/schema/gen/go"
) )
func main() { func main() {
ts := schema.TypeSystem{} ts := schema.TypeSystem{}
ts.Init() ts.Init()
adjCfg := &gengo.AdjunctCfg{} adjCfg := &gengo.AdjunctCfg{}
...@@ -55,8 +57,12 @@ func main() { ...@@ -55,8 +57,12 @@ func main() {
schema.SpawnStructRepresentationMap(nil), schema.SpawnStructRepresentationMap(nil),
)) ))
// note in scope: ts.Accumulate(schema.SpawnBytes("RawNode")) if errs := ts.ValidateGraph(); errs != nil {
for _, err := range errs {
fmt.Printf("- %s\n", err)
}
os.Exit(1)
}
gengo.Generate("./", pkgName, ts, adjCfg) gengo.Generate(".", pkgName, ts, adjCfg)
exec.Command("go", "fmt").Run()
} }
...@@ -10,14 +10,14 @@ import ( ...@@ -10,14 +10,14 @@ import (
) )
const ( const (
midvalue = schema.Maybe(4) midvalue = schema.Maybe(4)
allowNull = schema.Maybe(5) allowNull = schema.Maybe(5)
) )
type maState uint8 type maState uint8
const ( const (
maState_initial maState = iota maState_initial maState = iota
maState_midKey maState_midKey
maState_expectValue maState_expectValue
maState_midValue maState_midValue
...@@ -27,25 +27,24 @@ const ( ...@@ -27,25 +27,24 @@ const (
type laState uint8 type laState uint8
const ( const (
laState_initial laState = iota laState_initial laState = iota
laState_midValue laState_midValue
laState_finished laState_finished
) )
type _ErrorThunkAssembler struct { type _ErrorThunkAssembler struct {
e error e error
} }
func (ea _ErrorThunkAssembler) BeginMap(_ int) (ipld.MapAssembler, error) { return nil, ea.e } func (ea _ErrorThunkAssembler) BeginMap(_ int) (ipld.MapAssembler, error) { return nil, ea.e }
func (ea _ErrorThunkAssembler) BeginList(_ int) (ipld.ListAssembler, error) { return nil, ea.e } func (ea _ErrorThunkAssembler) BeginList(_ int) (ipld.ListAssembler, error) { return nil, ea.e }
func (ea _ErrorThunkAssembler) AssignNull() error { return ea.e } func (ea _ErrorThunkAssembler) AssignNull() error { return ea.e }
func (ea _ErrorThunkAssembler) AssignBool(bool) error { return ea.e } func (ea _ErrorThunkAssembler) AssignBool(bool) error { return ea.e }
func (ea _ErrorThunkAssembler) AssignInt(int) error { return ea.e } func (ea _ErrorThunkAssembler) AssignInt(int) error { return ea.e }
func (ea _ErrorThunkAssembler) AssignFloat(float64) error { return ea.e } func (ea _ErrorThunkAssembler) AssignFloat(float64) error { return ea.e }
func (ea _ErrorThunkAssembler) AssignString(string) error { return ea.e } func (ea _ErrorThunkAssembler) AssignString(string) error { return ea.e }
func (ea _ErrorThunkAssembler) AssignBytes([]byte) error { return ea.e } func (ea _ErrorThunkAssembler) AssignBytes([]byte) error { return ea.e }
func (ea _ErrorThunkAssembler) AssignLink(ipld.Link) error { return ea.e } func (ea _ErrorThunkAssembler) AssignLink(ipld.Link) error { return ea.e }
func (ea _ErrorThunkAssembler) AssignNode(ipld.Node) error { return ea.e } func (ea _ErrorThunkAssembler) AssignNode(ipld.Node) error { return ea.e }
func (ea _ErrorThunkAssembler) Prototype() ipld.NodePrototype { func (ea _ErrorThunkAssembler) Prototype() ipld.NodePrototype {
panic(fmt.Errorf("cannot get prototype from error-carrying assembler: already derailed with error: %w", ea.e)) panic(fmt.Errorf("cannot get prototype from error-carrying assembler: already derailed with error: %w", ea.e))
} }
This diff is collapsed.
...@@ -5,7 +5,6 @@ package dagpb ...@@ -5,7 +5,6 @@ package dagpb
import ( import (
ipld "github.com/ipld/go-ipld-prime" ipld "github.com/ipld/go-ipld-prime"
) )
var _ ipld.Node = nil // suppress errors when this dependency is not referenced var _ ipld.Node = nil // suppress errors when this dependency is not referenced
// Type is a struct embeding a NodePrototype/Type for every Node implementation in this package. // Type is a struct embeding a NodePrototype/Type for every Node implementation in this package.
// One of its major uses is to start the construction of a value. // One of its major uses is to start the construction of a value.
...@@ -20,20 +19,20 @@ var _ ipld.Node = nil // suppress errors when this dependency is not referenced ...@@ -20,20 +19,20 @@ var _ ipld.Node = nil // suppress errors when this dependency is not referenced
var Type typeSlab var Type typeSlab
type typeSlab struct { type typeSlab struct {
Bytes _Bytes__Prototype Bytes _Bytes__Prototype
Bytes__Repr _Bytes__ReprPrototype Bytes__Repr _Bytes__ReprPrototype
Int _Int__Prototype Int _Int__Prototype
Int__Repr _Int__ReprPrototype Int__Repr _Int__ReprPrototype
Link _Link__Prototype Link _Link__Prototype
Link__Repr _Link__ReprPrototype Link__Repr _Link__ReprPrototype
PBLink _PBLink__Prototype PBLink _PBLink__Prototype
PBLink__Repr _PBLink__ReprPrototype PBLink__Repr _PBLink__ReprPrototype
PBLinks _PBLinks__Prototype PBLinks _PBLinks__Prototype
PBLinks__Repr _PBLinks__ReprPrototype PBLinks__Repr _PBLinks__ReprPrototype
PBNode _PBNode__Prototype PBNode _PBNode__Prototype
PBNode__Repr _PBNode__ReprPrototype PBNode__Repr _PBNode__ReprPrototype
String _String__Prototype String _String__Prototype
String__Repr _String__ReprPrototype String__Repr _String__ReprPrototype
} }
// --- type definitions follow --- // --- type definitions follow ---
...@@ -53,8 +52,8 @@ type _Link struct{ x ipld.Link } ...@@ -53,8 +52,8 @@ type _Link struct{ x ipld.Link }
// PBLink matches the IPLD Schema type "PBLink". It has Struct type-kind, and may be interrogated like map kind. // PBLink matches the IPLD Schema type "PBLink". It has Struct type-kind, and may be interrogated like map kind.
type PBLink = *_PBLink type PBLink = *_PBLink
type _PBLink struct { type _PBLink struct {
Hash _Link Hash _Link
Name _String__Maybe Name _String__Maybe
Tsize _Int__Maybe Tsize _Int__Maybe
} }
...@@ -68,9 +67,10 @@ type _PBLinks struct { ...@@ -68,9 +67,10 @@ type _PBLinks struct {
type PBNode = *_PBNode type PBNode = *_PBNode
type _PBNode struct { type _PBNode struct {
Links _PBLinks Links _PBLinks
Data _Bytes__Maybe Data _Bytes__Maybe
} }
// String matches the IPLD Schema type "String". It has string kind. // String matches the IPLD Schema type "String". It has string kind.
type String = *_String type String = *_String
type _String struct{ x string } type _String struct{ x string }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment