- java.lang.Object
-
- org.kink_lang.kink.Vm
-
public class Vm extends Object
A Kink vm.
-
-
Field Summary
Fields Modifier and Type Field Description BinHelper
bin
The helper for bin vals.BindingHelper
binding
The helper for env vals.BoolHelper
bool
The helper for bool vals.ComponentRegistry
component
The component registry.FunHelper
fun
The helper of funs.GraphFacade
graph
The facade for the Execution Graph DSL.JavaHelper
java
The helper for java vals.LocHelper
loc
The helper for loc vals.Val
nada
The nada val.NumHelper
num
The helper for num vals.StrHelper
str
The helper for str vals.SymRegistry
sym
The registry of syms.TraceHelper
trace
The helper for trace vals.VarMappingFactory
varMapping
The factory of VarMapping.VarrefHelper
varref
The helper for varref vals.VecHelper
vec
The helper for vec vals.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Val
newVal()
Returns a new val.Val
newVal(VarMapping initialVarMapping)
Returns a new val with the initial var mapping.static Vm
newVm()
Returns a new vm.<T> T
run(ThrowingFunction1<? super HostContext,HostResult> bootstrapAction, Function<Val,T> onReturned, BiFunction<String,List<TraceVal>,T> onRaised)
Runs a new execution stack which starts from the bootstrap action.
-
-
-
Field Detail
-
nada
public final Val nada
The nada val.
-
bool
public final BoolHelper bool
The helper for bool vals.
-
binding
public final BindingHelper binding
The helper for env vals.
-
num
public final NumHelper num
The helper for num vals.
-
str
public final StrHelper str
The helper for str vals.
-
bin
public final BinHelper bin
The helper for bin vals.
-
fun
public final FunHelper fun
The helper of funs.
-
varref
public final VarrefHelper varref
The helper for varref vals.
-
vec
public final VecHelper vec
The helper for vec vals.
-
trace
public final TraceHelper trace
The helper for trace vals.
-
loc
public final LocHelper loc
The helper for loc vals.
-
java
public final JavaHelper java
The helper for java vals.
-
sym
public final SymRegistry sym
The registry of syms.
-
graph
public final GraphFacade graph
The facade for the Execution Graph DSL.
-
varMapping
public final VarMappingFactory varMapping
The factory of VarMapping.
-
component
public final ComponentRegistry component
The component registry.
-
-
Method Detail
-
newVm
public static Vm newVm()
Returns a new vm.- Returns:
- a new vm.
-
newVal
public final Val newVal()
Returns a new val.- Returns:
- a new val.
-
newVal
public final Val newVal(VarMapping initialVarMapping)
Returns a new val with the initial var mapping.The contents of the
initialVarMapping
override the common ones.- Parameters:
initialVarMapping
- the initial var mapping for the new val.- Returns:
- a new val.
-
run
public <T> T run(ThrowingFunction1<? super HostContext,HostResult> bootstrapAction, Function<Val,T> onReturned, BiFunction<String,List<TraceVal>,T> onRaised)
Runs a new execution stack which starts from the bootstrap action.The execution starts from
bootstrapAction
.If the execution succeeds with a result, the method invokes
onReturned
with the result val. If the execution fails, the method invokesonRaised
with the exception message and the traces.Example:
FunVal fun = ...; boolean isSuccess = vm.run( c -> c.call(fun).args(x, y), result -> { System.out.printf("OK!: %s%n", result); return true; }, (msg, traces) -> { System.out.printf("Bad: %s %s", msg, traces); return false; } );
- Type Parameters:
T
- the result type ofonReturned
andonRaised
.- Parameters:
bootstrapAction
- the action which is called to start the execution.onReturned
- called when the execution succeeds with a result.onRaised
- called when the execution fails with an exception.- Returns:
- the result of
onReturned
oronRaised
.
-
-