Package org.kink_lang.kink.hostfun.graph

Provides the Execution Graph DSL, which is a convenient way to invoke Kink funs from Java actions or handlers.

Without the DSL, it can easily become cumbersome to invoke a Kink fun using results of other invocations. For exmaple, tail-calling of (X + Y) * (Z + W) from a Java make is written as:

  Val x = ,,, y = ,,, z = ,,, w  = ,,,
  int add = vm.sym.getHandle("op_add");
  int mul = vm.sym.getHandle("op_mul");
  return c.call(x, add).args(y).on((cc, xy) -> {
      return cc.call(z, add).args(w).on((c3, zw) -> {
          return c3.call(xy, mul).args(zw);
      });
  });
 

Using the Execution Graph DSL, you can write the equivalent Java code without nesting lambdas and multiple call contexts:

  Val x = ,,, y = ,,, z = ,,, w  = ,,,
  int add = vm.sym.getHandle("op_add");
  int mul = vm.sym.getHandle("op_mul");
  GraphNode xPlusY = vm.graph.call(vm.graph.of(x), add).args(vm.graph.of(y));
  GraphNode zPlusW = vm.graph.call(vm.graph.of(z), add).args(vm.graph.of(w));
  GraphNode result = vm.graph.call(xPlusY, mul).args(zPlusW);
  return c.call(result);
 

There are also shorthands for several idioms such as raise(Template.format(,,,)) or Val.repr.

  return c.call(vm.graph.raiseFormat(
      "expected a str, but got {}",
      vm.graph.repr(arg)));
 
See Also:
Vm.graph