lang: funcs: vars: Include system package variables in the scope

This commit is contained in:
James Shubin
2024-08-07 17:29:50 -04:00
parent a93c98402a
commit 8e9c3b6c1e
2 changed files with 12 additions and 4 deletions

View File

@@ -3433,10 +3433,13 @@ func (obj *StmtProg) importSystemScope(name string) (*interfaces.Scope, error) {
// TODO: do we want to run Interpolate or SetScope?
}
// TODO: pass `data` into ast.VarPrefixToVariablesScope ?
variables := VarPrefixToVariablesScope(name) // strips prefix!
// initial scope, built from core golang code
scope := &interfaces.Scope{
// TODO: we could use the core API for variables somehow...
//Variables: make(map[string]interfaces.Expr),
Variables: variables,
Functions: functions, // map[string]interfaces.Expr
// TODO: we could add a core API for classes too!
//Classes: make(map[string]interfaces.Stmt),

View File

@@ -46,6 +46,11 @@ const (
ResourceNamespace = "res"
)
// Value is a shortcut to using this type.
// XXX: Eventually we might get rid of this entirely and use types.Value instead
// of interfaces.Var which seems to be unnecessary at the moment.
type Value = interfaces.Var
// registeredVars is a global map of all possible vars which can be used. You
// should never touch this map directly. Use methods like Register instead.
var registeredVars = make(map[string]func() interfaces.Var) // must initialize
@@ -63,9 +68,9 @@ func Register(name string, fn func() interfaces.Var) {
// ModuleRegister is exactly like Register, except that it registers within a
// named module. This is a helper function.
//func ModuleRegister(module, name string, v func() interfaces.Var) {
// Register(module+interfaces.ModuleSep+name, v)
//}
func ModuleRegister(module, name string, v func() interfaces.Var) {
Register(module+interfaces.ModuleSep+name, v)
}
// resourceConstHelper is a helper function to manage the const topology.
func resourceConstHelper(kind, param, field string) string {