OpenFunction::call stub

This commit is contained in:
numzero 2025-04-19 13:45:42 +03:00
parent 1325b1cf08
commit f3ae2b8461

View File

@ -1,6 +1,6 @@
use std::cell::RefCell; use std::cell::RefCell;
use crate::ast; use crate::{ast, types};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct OpenFunction(Function); pub struct OpenFunction(Function);
@ -240,3 +240,21 @@ fn build_function(parent: &BuildContext<'_>, code: &ast::Function) -> Function {
pub fn build(code: &ast::Function) -> OpenFunction { pub fn build(code: &ast::Function) -> OpenFunction {
OpenFunction(build_function(&BuildContext::new_toplevel(), &code)) OpenFunction(build_function(&BuildContext::new_toplevel(), &code))
} }
impl Function {
fn call(&self, upvalues: &[types::Value], args: &[types::Value]) -> types::Value {
assert_eq!(upvalues.len(), self.upvalues.len());
assert_eq!(args.len(), self.args.len());
todo!()
}
}
impl OpenFunction {
pub fn call(&self, env: types::Value, args: &[types::Value]) -> types::Value {
match self.0.upvalues.as_slice() {
[] => self.0.call(&[], args),
[up] if up.0 == "_ENV" => self.0.call(&[env], args),
_ => unreachable!(),
}
}
}