Package net.hydromatic.morel.compile
Class Environment
java.lang.Object
net.hydromatic.morel.compile.Environment
- Direct Known Subclasses:
Environments.EmptyEnvironment,Environments.MapEnvironment,Environments.SubEnvironment
Environment for validation/compilation.
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.(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.
-