Interpreter - Callables now receive the callee value as an argument
This commit is contained in:
parent
692531ca65
commit
85e9c7db38
4 changed files with 14 additions and 4 deletions
|
@ -11,7 +11,7 @@ pub trait Callable: Debug + ToString {
|
||||||
|
|
||||||
/// Run the callable in the execution environment with the specified
|
/// Run the callable in the execution environment with the specified
|
||||||
/// arguments.
|
/// arguments.
|
||||||
fn call(&self, environment: &mut InterpreterState, arguments: Vec<Value>) -> SloxResult<Value>;
|
fn call(&self, callee: &Value, environment: &mut InterpreterState, arguments: Vec<Value>) -> SloxResult<Value>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A reference to a callable.
|
/// A reference to a callable.
|
||||||
|
|
|
@ -39,7 +39,12 @@ impl Callable for Function {
|
||||||
self.params.len()
|
self.params.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&self, es: &mut InterpreterState, arguments: Vec<Value>) -> SloxResult<Value> {
|
fn call(
|
||||||
|
&self,
|
||||||
|
_callee: &Value,
|
||||||
|
es: &mut InterpreterState,
|
||||||
|
arguments: Vec<Value>,
|
||||||
|
) -> SloxResult<Value> {
|
||||||
assert_eq!(arguments.len(), self.arity());
|
assert_eq!(arguments.len(), self.arity());
|
||||||
let param_env = InterpreterState {
|
let param_env = InterpreterState {
|
||||||
environment: Environment::create_child(&self.env),
|
environment: Environment::create_child(&self.env),
|
||||||
|
|
|
@ -505,7 +505,7 @@ impl ExprNode {
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(callable.call(es, arg_values)?.into())
|
Ok(callable.call(&callee, es, arg_values)?.into())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
error(right_paren, "can only call functions and classes")
|
error(right_paren, "can only call functions and classes")
|
||||||
|
|
|
@ -20,7 +20,12 @@ impl Callable for Clock {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&self, _environment: &mut InterpreterState, _arguments: Vec<Value>) -> SloxResult<Value> {
|
fn call(
|
||||||
|
&self,
|
||||||
|
_callee: &Value,
|
||||||
|
_environment: &mut InterpreterState,
|
||||||
|
_arguments: Vec<Value>,
|
||||||
|
) -> SloxResult<Value> {
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
let since_epoch = now
|
let since_epoch = now
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
|
|
Loading…
Reference in a new issue