Package org.armedbear.lisp
Class ArgumentListProcessor
- java.lang.Object
-
- org.armedbear.lisp.ArgumentListProcessor
-
- All Implemented Interfaces:
java.io.Serializable
public class ArgumentListProcessor extends java.lang.Object implements java.io.Serializable
A class to parse a lambda list and match function call arguments with it. The lambda list may either be of type ORDINARY or MACRO lambda list. All other lambda lists are parsed elsewhere in our code base.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ArgumentListProcessor.KeywordParam
Class used to represent optional parameters and their initformsstatic class
ArgumentListProcessor.LambdaListType
static class
ArgumentListProcessor.OptionalParam
Class used to match optional parameters, or, if not provided, evaluate the initform.static class
ArgumentListProcessor.Param
Abstract parent of the classes used to represent the different argument types: - EnvironmentParam - RequiredParam - OptionalParam - RestParam - KeywordParam - AuxParamstatic class
ArgumentListProcessor.RequiredParam
Class used to match required parameters
-
Constructor Summary
Constructors Constructor Description ArgumentListProcessor(Operator fun, int requiredCount, ArgumentListProcessor.OptionalParam[] optional, ArgumentListProcessor.KeywordParam[] keyword, boolean key, boolean moreKeys, Symbol rest)
Constructor to be used from compiled code The compiler hands in pre-parsed lambda lists.ArgumentListProcessor(Operator fun, LispObject lambdaList, LispObject specials, ArgumentListProcessor.LambdaListType type)
Instantiates an ArgumentListProcessor by parsing the lambda list specified in 'lambdaList'.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
bindVars(LispObject[] values, Environment env, LispThread thread)
Binds the variable values returned from 'match' to their corresponding variables in the environment 'env', with specials bound in thread 'thread'.Symbol[]
freeSpecials(LispObject specials)
int
getArity()
int
getMaxArgs()
int
getMinArgs()
Symbol[]
getVariables()
LispObject[]
match(LispObject[] args, Environment _environment, Environment env, LispThread thread)
Matches the function call arguments 'args' with the lambda list, returning an array with variable values to be used.void
setFunction(Operator fun)
-
-
-
Constructor Detail
-
ArgumentListProcessor
public ArgumentListProcessor(Operator fun, int requiredCount, ArgumentListProcessor.OptionalParam[] optional, ArgumentListProcessor.KeywordParam[] keyword, boolean key, boolean moreKeys, Symbol rest)
Constructor to be used from compiled code The compiler hands in pre-parsed lambda lists. The process of matching function call arguments with lambda lists which are constructed this way don't support non-constant initforms for &optional, &key and &aux parameters. As a result, there's no need to create an evaluation environment which in turn eliminates the need to know which variables are special.- Parameters:
fun
- The function to report function call argument matching errors onrequired
- The list of required argumentsoptional
- The list of optional argumentskeyword
- The list of keyword parameterskey
- Indicates whether &key was specified (optionally without naming keys)moreKeys
- Indicates whether &allow-other-keys was specifiedrest
- Specifies the &rest variable name, if one was specified, or 'null' if none
-
ArgumentListProcessor
public ArgumentListProcessor(Operator fun, LispObject lambdaList, LispObject specials, ArgumentListProcessor.LambdaListType type)
Instantiates an ArgumentListProcessor by parsing the lambda list specified in 'lambdaList'. This constructor sets up the object to support evaluation of non-constant initforms.- Parameters:
fun
- Function to use when reporting errorslambdaList
- Lambda list to parse and use for function callspecials
- A list of symbols specifying which variables to bind as specials during initform evaluation
-
-
Method Detail
-
setFunction
public void setFunction(Operator fun)
-
match
public LispObject[] match(LispObject[] args, Environment _environment, Environment env, LispThread thread)
Matches the function call arguments 'args' with the lambda list, returning an array with variable values to be used. The array is sorted the same way as the variables returned by the 'extractVariables' function.- Parameters:
args
- Funcion call arguments to be matched_environment
- Environment to be used for the &environment variableenv
- Environment to evaluate initforms inthread
- Thread to be used for binding special variables -- must be LispThread.currentThread()- Returns:
- An array of LispObjects corresponding to the values to be bound to the variables in the lambda list
-
bindVars
public void bindVars(LispObject[] values, Environment env, LispThread thread)
Binds the variable values returned from 'match' to their corresponding variables in the environment 'env', with specials bound in thread 'thread'.- Parameters:
values
- Values to be boundenv
-thread
-
-
freeSpecials
public Symbol[] freeSpecials(LispObject specials)
-
getArity
public int getArity()
-
getMinArgs
public int getMinArgs()
-
getMaxArgs
public int getMaxArgs()
-
getVariables
public Symbol[] getVariables()
-
-