Package tech.ixor.calclox
Class LoxFunction
java.lang.Object
tech.ixor.calclox.LoxFunction
- All Implemented Interfaces:
LoxCallable
Runtime representation of a user-defined CalcLox function.
A function retains the environment in which it was declared, allowing its body to access captured variables when invoked later.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final EnvironmentThe variable scope of the function.protected final Statement.FunctionParsed declaration containing the function name, parameters, and body. -
Constructor Summary
ConstructorsConstructorDescriptionLoxFunction(Statement.Function declaration, Environment closure) Creates a function closure. -
Method Summary
-
Field Details
-
declaration
Parsed declaration containing the function name, parameters, and body. -
closure
The variable scope of the function.
-
-
Constructor Details
-
LoxFunction
Creates a function closure.- Parameters:
declaration- parsed function declarationclosure- declaration-time lexical environment
-
-
Method Details
-
toString
-
arity
public int arity()Description copied from interface:LoxCallableReturns the required argument count.- Specified by:
arityin interfaceLoxCallable- Returns:
- the exact number of arguments accepted by this callable
-
call
Description copied from interface:LoxCallableInvokes the callable with already evaluated arguments.- Specified by:
callin interfaceLoxCallable- Parameters:
interpreter- active interpreterarguments- argument values in source order- Returns:
- the call result, or
nullfor CalcLoxnil
-