Class RuntimeFunctionLiteral

java.lang.Object
io.github.protasm.jvmud.compiler.runtime.RuntimeFunctionLiteral
All Implemented Interfaces:
RuntimeCallable

public final class RuntimeFunctionLiteral extends Object implements RuntimeCallable
Runtime representation for an LPC function literal.

The compiler can currently parse, type-check, and pass these values through normal LPC value paths. Executable values either call a generated inline-closure helper or invoke a named method on the object that created the reference.

  • Constructor Details

    • RuntimeFunctionLiteral

      public RuntimeFunctionLiteral(String signature)
    • RuntimeFunctionLiteral

      public RuntimeFunctionLiteral(String signature, int arity)
    • RuntimeFunctionLiteral

      public RuntimeFunctionLiteral(String signature, int arity, Object target, String methodName)
    • RuntimeFunctionLiteral

      public RuntimeFunctionLiteral(String signature, int arity, Object target, String methodName, Object[] captures)
      Creates an executable inline callable bound to a generated helper method and captured local values from the lexical point where the LPC closure literal was evaluated.
      Parameters:
      signature - display signature for diagnostics
      arity - number of LPC callback arguments expected by the closure body
      target - generated object that owns the helper method
      methodName - generated helper method name
      captures - boxed outer-local values captured by the closure literal
    • RuntimeFunctionLiteral

      public RuntimeFunctionLiteral(String signature, int arity, Object target, String methodName, Object[] captures, Class<?> helperOwner)
      Creates an executable inline callable whose helper lives on a specific generated class.

      Inherited LPC methods still run with this bound to the most-derived object. Binding the helper lookup to the class that emitted the method keeps synthetic helper names from colliding with helpers generated by descendants or flattened parents.

      Parameters:
      signature - display signature for diagnostics
      arity - number of LPC callback arguments expected by the closure body
      target - generated object that owns the runtime receiver
      methodName - generated helper method name
      captures - boxed outer-local values captured by the closure literal
      helperOwner - generated class that declared methodName
  • Method Details

    • namedFunction

      public static RuntimeFunctionLiteral namedFunction(String methodName, Object target)
      Creates a callable for a quoted LPC function symbol such as #'helper.

      The callable is bound to the generated object that produced it and accepts whatever arguments the consuming efun passes at runtime.

      Parameters:
      methodName - LPC method name to invoke
      target - generated object that owns the method
      Returns:
      executable named-method callable
    • signature

      public String signature()
    • arity

      public int arity()
    • executable

      public boolean executable()
    • call

      public Object call(RuntimeContext runtime, Object... args)
      Description copied from interface: RuntimeCallable
      Invokes the callable in an LPC runtime context.
      Specified by:
      call in interface RuntimeCallable
      Parameters:
      runtime - active runtime context for callbacks that need object/session state
      args - LPC callback arguments
      Returns:
      callback result as a JVMud runtime value
    • toString

      public String toString()
      Overrides:
      toString in class Object