Expr::FunctionPointer

This commit is contained in:
Ayaz Hafiz 2023-06-25 18:46:08 -05:00
parent 55fa8098d3
commit cf30f02e01
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
11 changed files with 176 additions and 5 deletions

View file

@ -70,6 +70,9 @@ pub enum ProblemKind<'a> {
proc_layout: ProcLayout<'a>,
similar: Vec<ProcLayout<'a>>,
},
PtrToUndefinedProc {
symbol: Symbol,
},
DuplicateCallSpecId {
old_call_line: usize,
},
@ -464,6 +467,49 @@ impl<'a, 'r> Ctx<'a, 'r> {
// TODO don't know what the element layout is
None
}
&Expr::ExprBox { symbol } => self.with_sym_layout(symbol, |ctx, _def_line, layout| {
let inner = layout;
Some(
ctx.interner
.insert_direct_no_semantic(LayoutRepr::Boxed(inner)),
)
}),
&Expr::ExprUnbox { symbol } => self.with_sym_layout(symbol, |ctx, def_line, layout| {
let layout = ctx.resolve(layout);
match ctx.interner.get_repr(layout) {
LayoutRepr::Boxed(inner) => Some(inner),
_ => {
ctx.problem(ProblemKind::UnboxNotABox { symbol, def_line });
None
}
}
}),
&Expr::FunctionPointer { lambda_name } => {
let lambda_symbol = lambda_name.name();
if !self.procs.iter().any(|((name, proc), _)| {
*name == lambda_symbol && proc.niche == lambda_name.niche()
}) {
self.problem(ProblemKind::PtrToUndefinedProc {
symbol: lambda_symbol,
});
}
Some(Layout::OPAQUE_PTR)
}
&Expr::Reuse {
symbol,
update_tag_id: _,
update_mode: _,
tag_layout,
tag_id: _,
arguments: _,
} => {
let union = self
.interner
.insert_direct_no_semantic(LayoutRepr::Union(tag_layout));
self.check_sym_layout(symbol, union, UseKind::TagReuse);
// TODO also check update arguments
Some(union)
}
&Expr::Reset {
symbol,
update_mode: _,

View file

@ -265,6 +265,15 @@ where
};
stack(f, [no_spec_doc, similar_doc])
}
ProblemKind::PtrToUndefinedProc { symbol } => {
title = "PROC SPECIALIZATION NOT DEFINED";
docs_before = vec![];
f.concat([
f.reflow("The proc "),
format_symbol(f, interns, symbol),
f.reflow(" is not defined"),
])
}
ProblemKind::DuplicateCallSpecId { old_call_line } => {
title = "DUPLICATE CALL SPEC ID";
docs_before = vec![(old_call_line, f.reflow("This call has a specialization ID"))];