First step towards allowing variadic functions #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this PR, we introduce a new
ParameterList
struct. This will ultimately house both a list of normal parameters as well as a single trailing variadic parameter, but for now will only be used for the former. Doing so takes a first step towards fully supporting variadic functions. The following additional changes were made:lambda
case forExpression
s andResolvedExpression
s now has an optionalParameterList
as an associated value instead of an optional list ofToken
sparseParameters()
now constructs and returns aParameterList
. It should be noted thatparseFunction()
will still initialize alambda
case with a nil value forParameterList
to preserve support for computed propertieshandleLambda()
continues to declare and define variables, but this time by iterating over the parameter tokens inside theParameterList
instance it receivesLoxCallable
now has as part of its contract a computed property,parameterList
, instead ofarity
. The three conforming objects,NativeFunction
,UserDefinedFunction
, andLoxClass
, have been updated accordingly, but most notably,NativeFunction
synthesizesToken
instances with line number values set to0
in order to return aParameterList
object.ParameterList
instance passed in instead of[Token]
, but it is inhandleCallExpression()
where the arity check is made significantly differently by callingParameterList.checkArity(argCount:)
, which will throw if the checkk fails. For the time beingParameterList.checkArity(argCount:)
only examines normal parameters.