Package gnu.expr

Class PrimProcedure

  • All Implemented Interfaces:
    Named

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

      • 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 Detail

      • 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,
                             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 Detail

      • opcode

        public final int opcode()
      • getReturnType

        public Type getReturnType()
      • setReturnType

        public void setReturnType​(Type retType)
      • isSpecial

        public boolean isSpecial()
      • 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
      • 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)
      • 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)
      • 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."
      • getProcedureClass

        public static Class getProcedureClass​(Object pproc)
      • getVerboseName

        public String getVerboseName()