Class Environment
- Direct Known Subclasses:
Environments.EmptyEnvironment,Environments.MapEnvironment,Environments.SubEnvironment
Every environment is immutable; when you call bind(net.hydromatic.morel.ast.Core.IdPat, java.lang.Object), a new
environment is created that inherits from the previous environment. The new
environment may obscure bindings in the old environment, but neither the new
nor the old will ever change.
To create an empty environment, call Environments.empty().
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasString()Converts this environment to a string.bind(Core.IdPat id, Object value) Creates an environment that is the same as a given environment, plus one more variable.protected Environmentfinal EnvironmentCreates an environment that is the same as this, plus the given bindings.(package private) abstract intdistance(int soFar, Core.NamedPat id) voidforEachType(TypeSystem typeSystem, BiConsumer<String, Type> consumer) Calls a consumer for each variable and its type.voidforEachValue(BiConsumer<String, Object> consumer) Calls a consumer for each variable and its value.abstract @Nullable BindingReturns the binding ofnameif bound, null if not.abstract @Nullable BindinggetOpt(Core.NamedPat id) Returns the binding ofidif bound, null if not.Returns a map of the values and bindings.(package private) abstract EnvironmentIf this environment only defines bindings in the given set, returns its parent.plus(Environment env) Returns this environment plus the bindings in the given environment.renumber()Creates an environment where all variables have ordinal 0.(package private) abstract voidVisits every variable binding in this environment.
-
Constructor Details
-
Environment
public Environment()
-
-
Method Details
-
visit
Visits every variable binding in this environment.Bindings that are obscured by more recent bindings of the same name are visited, but after the more obscuring bindings.
-
asString
Converts this environment to a string.This method does not override the
Object.toString()method; if we did, debuggers would invoke it automatically, burning lots of CPU and memory. -
getOpt
Returns the binding ofnameif bound, null if not. -
getOpt
Returns the binding ofidif bound, null if not. -
bind
Creates an environment that is the same as a given environment, plus one more variable. -
bind
-
forEachType
Calls a consumer for each variable and its type. Does not visit obscured bindings. -
forEachValue
Calls a consumer for each variable and its value. Does not visit obscured bindings, or bindings toUnit.INSTANCE. -
getValueMap
Returns a map of the values and bindings. -
bindAll
Creates an environment that is the same as this, plus the given bindings. -
nearestAncestorNotObscuredBy
If this environment only defines bindings in the given set, returns its parent. Never returns null. The empty environment returns itself. -
distance
-
plus
Returns this environment plus the bindings in the given environment. -
renumber
Creates an environment where all variables have ordinal 0.A rather crude hack that papers over some problems when we evaluate fragments of Morel code in Calcite. The conversion to code currently produces variables with names like "wordCount_1", and the code is run in an environment not exactly the same as that in which it was compiled.
-