more typechecking af callables
This commit is contained in:
parent
cf1a5c1c3b
commit
270713b3f9
|
@ -4,5 +4,5 @@ comb reduce_or (
|
||||||
a: Logic
|
a: Logic
|
||||||
)
|
)
|
||||||
-> Logic<1> {
|
-> Logic<1> {
|
||||||
|
reduce_or(a)
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,6 +196,13 @@ impl Context {
|
||||||
.map(|expr| self.type_expression(expr))
|
.map(|expr| self.type_expression(expr))
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
let called = self.try_get_callable(call.name.fragment())?;
|
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 {
|
typed_ir::Expr {
|
||||||
id,
|
id,
|
||||||
kind: typed_ir::ExprKind::Call {
|
kind: typed_ir::ExprKind::Call {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use super::types::{Type, TypingContext};
|
use super::types::{GenericArg, Type, TypingContext};
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Eq, Ord)]
|
#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Eq, Ord)]
|
||||||
pub struct CallableId(pub usize);
|
pub struct CallableId(pub usize);
|
||||||
|
@ -38,6 +37,7 @@ impl CallableContext {
|
||||||
bitnot: CallableId(1),
|
bitnot: CallableId(1),
|
||||||
reduce_or: CallableId(2),
|
reduce_or: CallableId(2),
|
||||||
};
|
};
|
||||||
|
let logic1 = typectx.make_logic_size(1);
|
||||||
Self {
|
Self {
|
||||||
callables: vec![
|
callables: vec![
|
||||||
Callable {
|
Callable {
|
||||||
|
@ -52,8 +52,8 @@ impl CallableContext {
|
||||||
},
|
},
|
||||||
Callable {
|
Callable {
|
||||||
name: "builtin::reduce_or".to_string(),
|
name: "builtin::reduce_or".to_string(),
|
||||||
args: vec![],
|
args: vec![(Some("a".to_string()), typectx.primitives.logic)],
|
||||||
ret_type: Some(typectx.primitives.logic),
|
ret_type: Some(logic1),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
builtins,
|
builtins,
|
||||||
|
|
|
@ -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> {
|
pub fn parameterize(&mut self, typ: Type, params: &[GenericArg]) -> Option<Type> {
|
||||||
// TODO: return proper error type here
|
// TODO: return proper error type here
|
||||||
match &self.get(typ).kind {
|
match &self.get(typ).kind {
|
||||||
|
|
Loading…
Reference in New Issue