mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
compiler: allow to declare global variables in multiple files
Traverse and count globals across all used files. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
babd84ec10
commit
7009417325
6 changed files with 36 additions and 8 deletions
|
@ -28,20 +28,18 @@ func (c *codegen) newGlobal(name string) {
|
|||
|
||||
// traverseGlobals visits and initializes global variables.
|
||||
// and returns number of variables initialized.
|
||||
func (c *codegen) traverseGlobals(fs ...*ast.File) int {
|
||||
func (c *codegen) traverseGlobals() int {
|
||||
var n int
|
||||
for _, f := range fs {
|
||||
c.ForEachFile(func(f *ast.File) {
|
||||
n += countGlobals(f)
|
||||
}
|
||||
})
|
||||
if n != 0 {
|
||||
if n > 255 {
|
||||
c.prog.BinWriter.Err = errors.New("too many global variables")
|
||||
return 0
|
||||
}
|
||||
emit.Instruction(c.prog.BinWriter, opcode.INITSSLOT, []byte{byte(n)})
|
||||
for _, f := range fs {
|
||||
c.convertGlobals(f)
|
||||
}
|
||||
c.ForEachFile(c.convertGlobals)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue