compiler: allow to use exported variables

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2020-07-28 19:35:41 +03:00
parent b8d7e93459
commit 6df019913d
5 changed files with 124 additions and 23 deletions

View file

@ -21,10 +21,19 @@ var (
)
// newGlobal creates new global variable.
func (c *codegen) newGlobal(name string) {
func (c *codegen) newGlobal(pkg string, name string) {
name = c.getIdentName(pkg, name)
c.globals[name] = len(c.globals)
}
// getIdentName returns fully-qualified name for a variable.
func (c *codegen) getIdentName(pkg string, name string) string {
if fullName, ok := c.importMap[pkg]; ok {
pkg = fullName
}
return pkg + "." + name
}
// traverseGlobals visits and initializes global variables.
// and returns number of variables initialized.
func (c *codegen) traverseGlobals() int {