more typechecking af callables

main
NotAFile 2022-02-18 12:59:53 +01:00
parent cf1a5c1c3b
commit 270713b3f9
4 changed files with 18 additions and 5 deletions

View File

@ -4,5 +4,5 @@ comb reduce_or (
a: Logic
)
-> Logic<1> {
reduce_or(a)
}

View File

@ -196,6 +196,13 @@ impl Context {
.map(|expr| self.type_expression(expr))
.collect::<Result<Vec<_>, _>>()?;
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 {

View File

@ -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,

View File

@ -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<Type> {
// TODO: return proper error type here
match &self.get(typ).kind {