Package gnu.expr

Class PrimProcedure

All Implemented Interfaces:
Named

public class PrimProcedure extends MethodProc
A primitive Procedure implemented by a plain Java method.
  • Field Details

    • explicitArrayAsVarArgsAllowed

      public static boolean explicitArrayAsVarArgsAllowed
      Support passing an explicit array to a varargs function. This is a kludge inherited from Java to support backwards compatibility after various methods were converte to take varargs. If Java5-style VARARGS we allow both a variable-length argument list, or if the last argument already is an array we can use it as is. The tricky part is we sometimes have to distinguish these cases at run-time - see the logic for createVarargsArrayIfNeeded in compileArgs. FIXME This is needless and unreliable complexity. We should by default create a varargs array - even if the actual argument is an array. People should now use splices instead.
    • applyToConsumer

      public static final MethodHandle applyToConsumer
  • Constructor Details

    • PrimProcedure

      public PrimProcedure(String className, String methodName, int numArgs)
    • PrimProcedure

      public PrimProcedure(Method method, Language language)
    • PrimProcedure

      public PrimProcedure(Method method)
    • PrimProcedure

      public PrimProcedure(Method method, Type retType, Type[] argTypes)
    • PrimProcedure

      public PrimProcedure(Method method, Language language)
    • PrimProcedure

      public PrimProcedure(Method method, char mode, Language language, ParameterizedType parameterizedType)
    • PrimProcedure

      public PrimProcedure(Method method, LambdaExp source)
    • PrimProcedure

      public PrimProcedure(int opcode, Type retType, Type[] argTypes)
    • PrimProcedure

      public PrimProcedure(int op_code, ClassType classtype, String name, Type retType, Type[] argTypes)
  • Method Details

    • opcode

      public final int opcode()
    • getReturnType

      public Type getReturnType()
    • setReturnType

      public void setReturnType(Type retType)
    • isSpecial

      public boolean isSpecial()
    • getReturnType

      public Type getReturnType(Expression[] args)
      Description copied from class: Procedure
      Semi-deprecated - instead should be set at Inline time. FIXME
      Overrides:
      getReturnType in class Procedure
    • getDeclaringClass

      public ClassType getDeclaringClass()
    • getMethod

      public Method getMethod()
    • setMethodForInvoke

      public void setMethodForInvoke(Method m)
    • isSideEffectFree

      public boolean isSideEffectFree()
      Description copied from class: Procedure
      True if this Procedure (definitely) has no side-effects. Note side-effect-free does not imply idempotent if this allocates an object with "identity".
      Overrides:
      isSideEffectFree in class Procedure
    • setSideEffectFree

      public void setSideEffectFree()
    • takesVarArgs

      public boolean takesVarArgs()
      Return true iff the last parameter is a "rest" argument.
    • takesVarArgs

      public static boolean takesVarArgs(Method method)
    • takesContext

      public boolean takesContext()
    • takesContext

      public static boolean takesContext(Method method)
    • isApplicable

      public int isApplicable(Type[] argTypes, Type restType)
      Description copied from class: MethodProc
      Test if method is applicable to an invocation with given arguments.
      Overrides:
      isApplicable in class MethodProc
      Parameters:
      argTypes - array of known "single" arguments.
      restType - If null, the arguments are fully specified by argTypes. If non-null, there may be an unknown number of extra arguments of the given restType. This is used for splices, where we usually don't know at compile-time how many argument values we have.
      Returns:
      -1 if no; 1 if yes; 0 if need to check at run-time.
    • isAbstract

      public boolean isAbstract()
    • isConstructor

      public final boolean isConstructor()
    • takesTarget

      public boolean takesTarget()
      Whether we are passed an argument for the 'target' / 'receiver' / 'this'. Normally this is false for static methods and true for non-static methods. However, we may need to be able to call a static method using object.name(args...) (Java syntax) or (invoke object 'name args...) (Scheme syntax). This includes when the object is implied. In this case we need to ignore the first argument's value.
    • numArgs

      public int numArgs()
      The (minimum, number) of arguments. Doesn't not count implicit CallContext argument. Does count 'this' argument for non-static methods. Does count an implicit staticLink argument for constructor.
      Overrides:
      numArgs in class Procedure
    • applyToConsumer

      public static Object applyToConsumer(Procedure proc, CallContext ctx) throws Throwable
      Throws:
      Throwable
    • applyToConsumerX

      public Object applyToConsumerX(CallContext ctx) throws Throwable
      Throws:
      Throwable
    • decodeType

      public static Type decodeType(Type javaType, String[] annotTypes, int annotIndex, ParameterizedType parameterizedType, Language lang)
    • makeBuiltinUnary

      public static PrimProcedure makeBuiltinUnary(int opcode, Type type)
    • makeBuiltinBinary

      public static PrimProcedure makeBuiltinBinary(int opcode, Type type)
    • getStaticFlag

      public final boolean getStaticFlag()
      True if there is no 'this' parameter.
    • getParameterTypes

      public final Type[] getParameterTypes()
    • compileRestArg

      public static final void compileRestArg(Type arg_type, ApplyExp exp, int startArg, int i, Compilation comp)
    • canCompile

      public boolean canCompile(ApplyExp exp)
    • compile

      public boolean compile(ApplyExp exp, Compilation comp, Target target)
    • compileInvoke

      public static void compileInvoke(Compilation comp, Method method, Target target, boolean isTailCall, int op_code, Type returnType, boolean doFixUnsigned)
      Emit the actual invoke operation, after arguments have been pushed. Does whatever magic is needed to pass the result to target, including passing CallContext or special handling of ConsumerTarget.
    • compileReachedUnexpected

      public static void compileReachedUnexpected(CodeAttr code)
    • getParameterType

      public Type getParameterType(int index)
      Overrides:
      getParameterType in class MethodProc
    • mostSpecific

      public static int mostSpecific(PrimProcedure[] procs, int length)
      Return the index of the most specific method. An approximation of the algorithm in JLS3 15.12.2.5 "Choosing the Most Specific Method."
    • getMethodFor

      public static PrimProcedure getMethodFor(Procedure pproc, Expression[] args)
    • getMethodFor

      public static PrimProcedure getMethodFor(Procedure pproc, Declaration decl, Expression[] args, Language language)
      Search for a matching static method in a procedure's class.
      Returns:
      a PrimProcedure that is suitable, or null.
    • getMethodFor

      public static PrimProcedure getMethodFor(Procedure pproc, Declaration decl, Type[] atypes, Language language)
    • disassemble$X

      public static void disassemble$X(Procedure pproc, CallContext ctx) throws Exception
      Throws:
      Exception
    • disassemble

      public static void disassemble(Procedure proc, Writer out) throws Exception
      Throws:
      Exception
    • disassemble

      public static void disassemble(Procedure proc, ClassTypeWriter cwriter) throws Exception
      Throws:
      Exception
    • getProcedureClass

      public static Class getProcedureClass(Object pproc)
    • getMethodFor

      public static PrimProcedure getMethodFor(Class procClass, String name, Declaration decl, Expression[] args, Language language)
      Get PrimProcedure for matching method in given class.
    • getMethodFor

      public static PrimProcedure getMethodFor(ClassType procClass, String name, Declaration decl, Expression[] args, Language language)
    • getMethodFor

      public static PrimProcedure getMethodFor(ClassType procClass, String name, Declaration decl, Type[] atypes, Language language)
    • getName

      public String getName()
      Specified by:
      getName in interface Named
      Overrides:
      getName in class PropertySet
    • getVerboseName

      public String getVerboseName()
    • toString

      public String toString()
      Overrides:
      toString in class Procedure
    • print

      public void print(PrintWriter ps)