mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
*: support _initialize
method in contracts
Invoke `_initialize` method on every call if present. In NEO3 there is no entrypoint and methods are invoked by offset, thus `Main` function is no longer required. We still have special `Main` method in tests to simplify them.
This commit is contained in:
parent
466af55dea
commit
685d44dbc1
9 changed files with 156 additions and 40 deletions
|
@ -27,16 +27,23 @@ func (c *codegen) newGlobal(name string) {
|
|||
}
|
||||
|
||||
// traverseGlobals visits and initializes global variables.
|
||||
func (c *codegen) traverseGlobals(f ast.Node) {
|
||||
n := countGlobals(f)
|
||||
// and returns number of variables initialized.
|
||||
func (c *codegen) traverseGlobals(fs ...*ast.File) int {
|
||||
var n int
|
||||
for _, f := range fs {
|
||||
n += countGlobals(f)
|
||||
}
|
||||
if n != 0 {
|
||||
if n > 255 {
|
||||
c.prog.BinWriter.Err = errors.New("too many global variables")
|
||||
return
|
||||
return 0
|
||||
}
|
||||
emit.Instruction(c.prog.BinWriter, opcode.INITSSLOT, []byte{byte(n)})
|
||||
for _, f := range fs {
|
||||
c.convertGlobals(f)
|
||||
}
|
||||
}
|
||||
c.convertGlobals(f)
|
||||
return n
|
||||
}
|
||||
|
||||
// countGlobals counts the global variables in the program to add
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue