Get started on calling erased functions

This commit is contained in:
Ayaz Hafiz 2023-06-25 17:27:10 -05:00
parent 6312d75ee0
commit a6bb3ab03c
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 44 additions and 3 deletions

View file

@ -43,6 +43,7 @@ use pattern::{from_can_pattern, store_pattern, Pattern};
pub use literal::{ListLiteralElement, Literal};
mod decision_tree;
mod erased;
mod literal;
mod pattern;
@ -1682,6 +1683,13 @@ impl<'a> Call<'a> {
alloc.text("CallByName ").append(alloc.intersperse(it, " "))
}
CallType::ByPointer { pointer, .. } => {
let it = std::iter::once(pointer)
.chain(arguments.iter().copied())
.map(|s| symbol_to_doc(alloc, s, pretty));
alloc.text("CallByPtr ").append(alloc.intersperse(it, " "))
}
LowLevel { op: lowlevel, .. } => {
let it = arguments.iter().map(|s| symbol_to_doc(alloc, *s, pretty));
@ -1759,6 +1767,11 @@ pub enum CallType<'a> {
arg_layouts: &'a [InLayout<'a>],
specialization_id: CallSpecId,
},
ByPointer {
pointer: Symbol,
ret_layout: InLayout<'a>,
arg_layouts: &'a [InLayout<'a>],
},
Foreign {
foreign_symbol: ForeignSymbol,
ret_layout: InLayout<'a>,
@ -5439,7 +5452,26 @@ pub fn with_hole<'a>(
env.arena.alloc(result),
);
}
RawFunctionLayout::ErasedFunction(..) => todo_lambda_erasure!(),
RawFunctionLayout::ErasedFunction(..) => {
// What we want here is
// f = compile(loc_expr)
// joinpoint join result:
// <hole>
// if (f.value) {
// f = cast(f, (..params, void*) -> ret);
// result = f ..args
// jump join result
// } else {
// f = cast(f, (..params) -> ret);
// result = f ..args
// jump join result
// }
todo_lambda_erasure!(
"{:?} :: {:?}",
loc_expr.value,
full_layout
)
}
RawFunctionLayout::ZeroArgumentThunk(_) => {
unreachable!(
"{:?} cannot be called in the source language",
@ -7520,6 +7552,15 @@ fn substitute_in_call<'a>(
ret_layout: *ret_layout,
specialization_id: *specialization_id,
}),
CallType::ByPointer {
pointer,
arg_layouts,
ret_layout,
} => substitute(subs, *pointer).map(|new| CallType::ByPointer {
pointer: new,
arg_layouts,
ret_layout: *ret_layout,
}),
CallType::Foreign { .. } => None,
CallType::LowLevel { .. } => None,
CallType::HigherOrder { .. } => None,

View file

@ -690,8 +690,8 @@ pub enum LayoutRepr<'a> {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct FunctionPointer<'a> {
args: &'a [InLayout<'a>],
ret: InLayout<'a>,
pub args: &'a [InLayout<'a>],
pub ret: InLayout<'a>,
}
impl<'a> FunctionPointer<'a> {