Some more inline codegen
This commit is contained in:
parent
ddef708178
commit
5616dfb1bc
@ -16,6 +16,12 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/big"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
blockadt "github.com/filecoin-project/specs-actors/actors/util/adt"
|
blockadt "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
|
|
||||||
|
/* inline-gen template
|
||||||
|
{{range .actorVersions}}
|
||||||
|
exported{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/exported"{{end}}
|
||||||
|
|
||||||
|
inline-gen start */
|
||||||
|
|
||||||
exported0 "github.com/filecoin-project/specs-actors/actors/builtin/exported"
|
exported0 "github.com/filecoin-project/specs-actors/actors/builtin/exported"
|
||||||
exported2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/exported"
|
exported2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/exported"
|
||||||
exported3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/exported"
|
exported3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/exported"
|
||||||
@ -23,6 +29,8 @@ import (
|
|||||||
exported5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/exported"
|
exported5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/exported"
|
||||||
exported6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/exported"
|
exported6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/exported"
|
||||||
|
|
||||||
|
//inline-gen end
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
@ -39,6 +47,11 @@ func NewActorRegistry() *vm.ActorRegistry {
|
|||||||
inv := vm.NewActorRegistry()
|
inv := vm.NewActorRegistry()
|
||||||
|
|
||||||
// TODO: define all these properties on the actors themselves, in specs-actors.
|
// TODO: define all these properties on the actors themselves, in specs-actors.
|
||||||
|
/* inline-gen template
|
||||||
|
{{range .actorVersions}}
|
||||||
|
inv.Register(vm.ActorsVersionPredicate(actors.Version{{.}}), exported{{.}}.BuiltinActors()...){{end}}
|
||||||
|
|
||||||
|
inline-gen start */
|
||||||
|
|
||||||
inv.Register(vm.ActorsVersionPredicate(actors.Version0), exported0.BuiltinActors()...)
|
inv.Register(vm.ActorsVersionPredicate(actors.Version0), exported0.BuiltinActors()...)
|
||||||
inv.Register(vm.ActorsVersionPredicate(actors.Version2), exported2.BuiltinActors()...)
|
inv.Register(vm.ActorsVersionPredicate(actors.Version2), exported2.BuiltinActors()...)
|
||||||
@ -47,6 +60,8 @@ func NewActorRegistry() *vm.ActorRegistry {
|
|||||||
inv.Register(vm.ActorsVersionPredicate(actors.Version5), exported5.BuiltinActors()...)
|
inv.Register(vm.ActorsVersionPredicate(actors.Version5), exported5.BuiltinActors()...)
|
||||||
inv.Register(vm.ActorsVersionPredicate(actors.Version6), exported6.BuiltinActors()...)
|
inv.Register(vm.ActorsVersionPredicate(actors.Version6), exported6.BuiltinActors()...)
|
||||||
|
|
||||||
|
//inline-gen end
|
||||||
|
|
||||||
return inv
|
return inv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,12 @@ import (
|
|||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
|
|
||||||
|
/* inline-gen template
|
||||||
|
{{range .actorVersions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"{{end}}
|
||||||
|
|
||||||
|
inline-gen start */
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
@ -21,6 +27,8 @@ import (
|
|||||||
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
|
||||||
|
|
||||||
|
//inline-gen end
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
@ -104,6 +112,12 @@ func newAccountActor(ver actors.Version) *types.Actor {
|
|||||||
// TODO: ActorsUpgrade use a global actor registry?
|
// TODO: ActorsUpgrade use a global actor registry?
|
||||||
var code cid.Cid
|
var code cid.Cid
|
||||||
switch ver {
|
switch ver {
|
||||||
|
/* inline-gen template
|
||||||
|
{{range .actorVersions}}
|
||||||
|
case actors.Version{{.}}:
|
||||||
|
code = builtin{{.}}.AccountActorCodeID{{end}}
|
||||||
|
inline-gen start */
|
||||||
|
|
||||||
case actors.Version0:
|
case actors.Version0:
|
||||||
code = builtin0.AccountActorCodeID
|
code = builtin0.AccountActorCodeID
|
||||||
case actors.Version2:
|
case actors.Version2:
|
||||||
@ -116,6 +130,7 @@ func newAccountActor(ver actors.Version) *types.Actor {
|
|||||||
code = builtin5.AccountActorCodeID
|
code = builtin5.AccountActorCodeID
|
||||||
case actors.Version6:
|
case actors.Version6:
|
||||||
code = builtin6.AccountActorCodeID
|
code = builtin6.AccountActorCodeID
|
||||||
|
//inline-gen end
|
||||||
default:
|
default:
|
||||||
panic("unsupported actors version")
|
panic("unsupported actors version")
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,10 @@
|
|||||||
- [ ] Update `chain/actors/policy/policy.go`
|
- [ ] Update `chain/actors/policy/policy.go`
|
||||||
- [ ] Update `chain/actors/version.go`
|
- [ ] Update `chain/actors/version.go`
|
||||||
- [ ] Register in `chain/vm/invoker.go`
|
- [ ] Register in `chain/vm/invoker.go`
|
||||||
- [ ] Register in `chain/vm/mkactor.go`
|
|
||||||
- [ ] Update `chain/types/state.go`
|
- [ ] Update `chain/types/state.go`
|
||||||
- [ ] Update `chain/state/statetree.go` (New / Load)
|
- [ ] Update `chain/state/statetree.go` (New / Load)
|
||||||
- [ ] Update `chain/stmgr/forks.go`
|
- [ ] Update `chain/stmgr/forks.go`
|
||||||
- [ ] Schedule
|
- [ ] Schedule
|
||||||
- [ ] Migration
|
- [ ] Migration
|
||||||
- [ ] Update upgrade schedule in `api/test/test.go` and `chain/sync_test.go`
|
- [ ] Update upgrade schedule in `api/test/test.go` and `chain/sync_test.go`
|
||||||
- [ ] Update `NewestNetworkVersion` in `build/params_shared_vals.go`
|
|
||||||
- [ ] Register in init in `chain/stmgr/utils.go`
|
- [ ] Register in init in `chain/stmgr/utils.go`
|
||||||
|
@ -47,46 +47,68 @@ func main() {
|
|||||||
|
|
||||||
state := stateGlobal
|
state := stateGlobal
|
||||||
|
|
||||||
|
rewrite := false
|
||||||
|
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
ln := i+1
|
ln := i + 1
|
||||||
switch state {
|
switch state {
|
||||||
case stateGlobal:
|
case stateGlobal:
|
||||||
outLines = append(outLines, line)
|
outLines = append(outLines, line)
|
||||||
if line == `/* inline-gen template` {
|
if strings.TrimSpace(line) == `/* inline-gen template` {
|
||||||
state = stateTemplate
|
state = stateTemplate
|
||||||
fmt.Printf("template section start %s:%d\n", path, ln)
|
fmt.Printf("template section start %s:%d\n", path, ln)
|
||||||
}
|
}
|
||||||
case stateTemplate:
|
case stateTemplate:
|
||||||
outLines = append(outLines, line) // output all template lines
|
outLines = append(outLines, line) // output all template lines
|
||||||
|
|
||||||
if line == `inline-gen start */` {
|
if strings.TrimSpace(line) == `inline-gen start */` {
|
||||||
state = stateGen
|
state = stateGen
|
||||||
fmt.Printf("generated section start %s:%d\n", path, ln)
|
fmt.Printf("generated section start %s:%d\n", path, ln)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
templateLines = append(templateLines, line)
|
templateLines = append(templateLines, line)
|
||||||
case stateGen:
|
case stateGen:
|
||||||
if line != `//inline-gen end` {
|
if strings.TrimSpace(line) != `//inline-gen end` {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
state = stateGlobal
|
fmt.Printf("generated section end %s:%d\n", path, ln)
|
||||||
fmt.Printf("inline gen:\n")
|
|
||||||
fmt.Println(strings.Join(templateLines, "\n"))
|
|
||||||
|
|
||||||
tpl, err := template.New("").Parse(strings.Join(templateLines, "\n"))
|
state = stateGlobal
|
||||||
|
rewrite = true
|
||||||
|
|
||||||
|
tpl, err := template.New("").Funcs(template.FuncMap{
|
||||||
|
"import": func(v float64) string {
|
||||||
|
if v == 0 {
|
||||||
|
return "/"
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("/v%d/", int(v))
|
||||||
|
},
|
||||||
|
}).Parse(strings.Join(templateLines, "\n"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("%s:%d: parsing template: %s\n", path, ln, err)
|
fmt.Printf("%s:%d: parsing template: %s\n", path, ln, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
err = tpl.Execute(&b, data)
|
err = tpl.Execute(&b, data)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s:%d: executing template: %s\n", path, ln, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
outLines = append(outLines, strings.Split(b.String(), "\n")...)
|
outLines = append(outLines, strings.Split(b.String(), "\n")...)
|
||||||
fmt.Println("inline gen-ed:\n", b.String())
|
|
||||||
|
|
||||||
outLines = append(outLines, line)
|
outLines = append(outLines, line)
|
||||||
|
templateLines = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rewrite {
|
||||||
|
fmt.Printf("write %s\n", path)
|
||||||
|
if err := ioutil.WriteFile(path, []byte(strings.Join(outLines, "\n")), 0664); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user