Class Vm


  • public class Vm
    extends Object
    A Kink vm.
    • Field Detail

      • nada

        public final Val nada
        The nada val.
      • bool

        public final BoolHelper bool
        The helper for bool vals.
      • env

        public final EnvHelper env
        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.
    • 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 invokes onRaised 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 of onReturned and onRaised.
        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 or onRaised.