diff --git a/src/twopass.rs b/src/twopass.rs index cb146be..9975875 100644 --- a/src/twopass.rs +++ b/src/twopass.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; -use crate::ast; +use crate::{ast, types}; #[derive(Debug, Clone)] pub struct OpenFunction(Function); @@ -240,3 +240,21 @@ fn build_function(parent: &BuildContext<'_>, code: &ast::Function) -> Function { pub fn build(code: &ast::Function) -> OpenFunction { 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!(), + } + } +}