- All Known Subinterfaces:
CallContext
public interface HostContext
Context of an action of a host fun.
The context is valid during invocation of the lambda of
HostFunBuilder.action(ThrowingFunction1)
or CallFlowToOn.on(HostFunReaction)
.
See org.kink_lang.kink.hostfun
for usage.
-
Method Summary
Modifier and TypeMethodDescriptionReturns a call flow to call a fun in the specified mod with no args.Returns a call flow to call the fun, with nada as the recv and no args.Returns a call flow to evaluate the graph.Returns a call flow to call a method ofownerRecv
with no args.Returns a HostResult to raise an exception.Returns a HostResult to raise an exception made from the Java throwable.traces()
Returns the traces to the current execution stack.
-
Method Details
-
traces
Returns the traces to the current execution stack.The traces are ordered from the bottom to the top, unlike stack trace in Java.
- Returns:
- the traces to the current execution stack.
-
raise
Returns a HostResult to raise an exception.- Parameters:
msg
- the message of the exception.- Returns:
- a HostResult to raise an exception.
-
raise
Returns a HostResult to raise an exception made from the Java throwable.- Parameters:
throwable
- the throwable of which a kink exception is made.- Returns:
- a HostResult to raise an exception.
-
call
Returns a call flow to call the fun, with nada as the recv and no args.Example:
FunVal curry2 = vm.fun.make("curry2($fun)").take(1).action(c -> { Val funArg = c.getArg(0); if (! (funArg instanceof FunVal)) { return c.call(vm.graph.raiseFormat("curry2($fun): required a fun, but got {}", vm.graph.repr(funArg))); } FunVal fun = (FunVal) funArg; FunVal curried = vm.fun.make().take(1).action(cc -> { Val a0 = cc.getArg(0); return vm.fun.make().take(1).action(c3 -> { Val a1 = c3.getArg(0); return c3.call(fun).args(a0, a1); }); }); });
- Parameters:
fun
- the fun.- Returns:
- a call flow to call the fun.
-
call
Returns a call flow to call a method ofownerRecv
with no args.The ownerRecv is also set as the recv of the call.
Example:
int opAddHandle = vm.sym.getHandle("op_add"); FunVal increment = vm.fun.make().take(1).action(c -> { Val n = c.getArg(0); // call “n + 1” return c.call(n, opAddHandle).args(vm.num.of(1)); });
If the specified var is empty, or the target of the var is not a fun, call() method returns a call flow which raises an exception.
- Parameters:
ownerRecv
- the owner and the recv of the method.symHandle
- the sym handle of the method.- Returns:
- a call flow with the fun.
-
call
Returns a call flow to call a fun in the specified mod with no args.nada is set as the recv of the call.
Example:
int exit = vm.sym.getHandle("exit"); FunVal abort = vm.fun.make().take(0).action( c -> c.call("kink/PROCESS", exit).args(vm.num.of(1)));
If the specified fun is empty, or the target of the var is not a fun, call() method returns a call flow which raises an exception.
- Parameters:
modName
- the name of the mod containing the fun.symHandle
- the sym handle of the fun.- Returns:
- a call flow.
-
call
Returns a call flow to evaluate the graph.Example:
FunVal abs = vm.fun.make().take(0).action(c -> { Val num = c.getArg(0); if (! (num instanceof NumVal)) { return c.call(vm.graph.raiseFormat("unknown val {}", vm.graph.repr(num))); } BigDecimal dec = ((NumVal) num).getBigDecimal(); return vm.num.of(dec.abs()); });
- Parameters:
graph
- the graph to evaluate.- Returns:
- a call flow to evaluate the graph.
-