Package net.hydromatic.morel.compile
Class Environment
- java.lang.Object
-
- net.hydromatic.morel.compile.Environment
-
- Direct Known Subclasses:
Environments.EmptyEnvironment,Environments.SubEnvironment
public abstract class Environment extends java.lang.ObjectEnvironment for validation/compilation.Every environment is immutable; when you call
bind(java.lang.String, net.hydromatic.morel.type.Type, 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:
TypeResolver.TypeEnv,EvalEnv
-
-
Constructor Summary
Constructors Constructor Description Environment()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Environmentbind(java.lang.String name, Type type, java.lang.Object value)Creates an environment that is the same as a given environment, plus one more variable.private Environmentbind(Binding binding)EnvironmentbindAll(java.lang.Iterable<Binding> bindings)Creates an environment that is the same as this, plus the given bindings.voidforEachType(java.util.function.BiConsumer<java.lang.String,Type> consumer)Calls a consumer for each variable and its type.voidforEachValue(java.util.function.BiConsumer<java.lang.String,java.lang.Object> consumer)Calls a consumer for each variable and its value.Bindingget(java.lang.String name)Returns the binding ofname; throws if not.abstract BindinggetOpt(java.lang.String name)Returns the binding ofnameif bound, null if not.java.util.Map<java.lang.String,Binding>getValueMap()Returns a map of the values and bindings.java.lang.StringtoString()(package private) abstract voidvisit(java.util.function.Consumer<Binding> consumer)Visits every variable binding in this environment.
-
-
-
Method Detail
-
visit
abstract void visit(java.util.function.Consumer<Binding> consumer)
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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getOpt
public abstract Binding getOpt(java.lang.String name)
Returns the binding ofnameif bound, null if not.
-
get
public Binding get(java.lang.String name)
Returns the binding ofname; throws if not.
-
bind
public Environment bind(java.lang.String name, Type type, java.lang.Object value)
Creates an environment that is the same as a given environment, plus one more variable.
-
bind
private Environment bind(Binding binding)
-
forEachType
public void forEachType(java.util.function.BiConsumer<java.lang.String,Type> consumer)
Calls a consumer for each variable and its type. Does not visit obscured bindings.
-
forEachValue
public void forEachValue(java.util.function.BiConsumer<java.lang.String,java.lang.Object> consumer)
Calls a consumer for each variable and its value. Does not visit obscured bindings, or bindings toUnit.INSTANCE.
-
getValueMap
public final java.util.Map<java.lang.String,Binding> getValueMap()
Returns a map of the values and bindings.
-
bindAll
public final Environment bindAll(java.lang.Iterable<Binding> bindings)
Creates an environment that is the same as this, plus the given bindings.
-
-