diff --git a/lib/builtins/main.hyd b/lib/builtins/main.hyd index 2050b8a..b406e60 100644 --- a/lib/builtins/main.hyd +++ b/lib/builtins/main.hyd @@ -4,5 +4,5 @@ comb reduce_or ( a: Logic ) -> Logic<1> { - + reduce_or(a) } diff --git a/src/frontend.rs b/src/frontend.rs index 29436b3..07d0ce5 100644 --- a/src/frontend.rs +++ b/src/frontend.rs @@ -196,6 +196,13 @@ impl Context { .map(|expr| self.type_expression(expr)) .collect::, _>>()?; let called = self.try_get_callable(call.name.fragment())?; + let called_callable = self.callables.get(called); + if args_resolved.len() != called_callable.argcount() { + return Err(CompileError::new(CompileErrorKind::BadArgCount { + received: args_resolved.len(), + expected: called_callable.argcount(), + })); + } typed_ir::Expr { id, kind: typed_ir::ExprKind::Call { diff --git a/src/frontend/callable.rs b/src/frontend/callable.rs index 5025419..68be24f 100644 --- a/src/frontend/callable.rs +++ b/src/frontend/callable.rs @@ -1,5 +1,4 @@ -use super::types::{Type, TypingContext}; -use std::collections::HashMap; +use super::types::{GenericArg, Type, TypingContext}; #[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Eq, Ord)] pub struct CallableId(pub usize); @@ -38,6 +37,7 @@ impl CallableContext { bitnot: CallableId(1), reduce_or: CallableId(2), }; + let logic1 = typectx.make_logic_size(1); Self { callables: vec![ Callable { @@ -52,8 +52,8 @@ impl CallableContext { }, Callable { name: "builtin::reduce_or".to_string(), - args: vec![], - ret_type: Some(typectx.primitives.logic), + args: vec![(Some("a".to_string()), typectx.primitives.logic)], + ret_type: Some(logic1), }, ], builtins, diff --git a/src/frontend/types.rs b/src/frontend/types.rs index cef1dc3..367e031 100644 --- a/src/frontend/types.rs +++ b/src/frontend/types.rs @@ -125,6 +125,12 @@ impl TypingContext { } } + pub fn make_logic_size(&mut self, width: u32) -> Type { + let widthnum = self.make_elabnum_u32(width); + self.parameterize(self.primitives.logic, &[GenericArg::Elab(widthnum)]) + .unwrap() + } + pub fn parameterize(&mut self, typ: Type, params: &[GenericArg]) -> Option { // TODO: return proper error type here match &self.get(typ).kind {