generate signature for foreign symbols

This commit is contained in:
Folkert 2020-11-06 23:46:31 +01:00
parent 4b8392696e
commit a6e39e66f1
8 changed files with 75 additions and 31 deletions

View file

@ -374,13 +374,13 @@ impl<'a> BorrowInfState<'a> {
self.own_args_using_bools(args, ps);
}
ForeignCall(_, args) => {
ForeignCall { arguments, .. } => {
// very unsure what demand ForeignCall should place upon its arguments
self.own_var(z);
let ps = foreign_borrow_signature(self.arena, args.len());
let ps = foreign_borrow_signature(self.arena, arguments.len());
self.own_args_using_bools(args, ps);
self.own_args_using_bools(arguments, ps);
}
Literal(_) | FunctionPointer(_, _) | RuntimeErrorFunction(_) => {}

View file

@ -125,8 +125,8 @@ pub fn occuring_variables_expr(expr: &Expr<'_>, result: &mut MutSet<Symbol>) {
RunLowLevel(_, args) => {
result.extend(args.iter());
}
ForeignCall(_, args) => {
result.extend(args.iter());
ForeignCall { arguments, .. } => {
result.extend(arguments.iter());
}
EmptyArray | RuntimeErrorFunction(_) | Literal(_) => {}
@ -466,9 +466,9 @@ impl<'a> Context<'a> {
self.arena.alloc(Stmt::Let(z, v, l, b))
}
ForeignCall(_, args) => {
let ps = crate::borrow::foreign_borrow_signature(self.arena, args.len());
let b = self.add_dec_after_lowlevel(args, ps, b, b_live_vars);
ForeignCall { arguments, .. } => {
let ps = crate::borrow::foreign_borrow_signature(self.arena, arguments.len());
let b = self.add_dec_after_lowlevel(arguments, ps, b, b_live_vars);
self.arena.alloc(Stmt::Let(z, v, l, b))
}

View file

@ -829,7 +829,11 @@ pub enum Expr<'a> {
args: &'a [Symbol],
},
RunLowLevel(LowLevel, &'a [Symbol]),
ForeignCall(ForeignSymbol, &'a [Symbol]),
ForeignCall {
foreign_symbol: ForeignSymbol,
arguments: &'a [Symbol],
ret_layout: Layout<'a>,
},
Tag {
tag_layout: Layout<'a>,
@ -944,11 +948,15 @@ impl<'a> Expr<'a> {
.text(format!("lowlevel {:?} ", lowlevel))
.append(alloc.intersperse(it, " "))
}
ForeignCall(symbol, args) => {
let it = args.iter().map(|s| symbol_to_doc(alloc, *s));
ForeignCall {
foreign_symbol,
arguments,
..
} => {
let it = arguments.iter().map(|s| symbol_to_doc(alloc, *s));
alloc
.text(format!("foreign {:?} ", symbol.as_str()))
.text(format!("foreign {:?} ", foreign_symbol.as_str()))
.append(alloc.intersperse(it, " "))
}
Tag {
@ -3191,7 +3199,11 @@ pub fn with_hole<'a>(
let result = Stmt::Let(
assigned,
Expr::ForeignCall(foreign_symbol.clone(), arg_symbols),
Expr::ForeignCall {
foreign_symbol: foreign_symbol.clone(),
arguments: arg_symbols,
ret_layout: layout.clone(),
},
layout,
hole,
);
@ -4035,10 +4047,14 @@ fn substitute_in_expr<'a>(
None
}
}
ForeignCall(symbol, args) => {
ForeignCall {
foreign_symbol,
arguments,
ret_layout,
} => {
let mut did_change = false;
let new_args = Vec::from_iter_in(
args.iter().map(|s| match substitute(subs, *s) {
arguments.iter().map(|s| match substitute(subs, *s) {
None => *s,
Some(s) => {
did_change = true;
@ -4051,7 +4067,11 @@ fn substitute_in_expr<'a>(
if did_change {
let args = new_args.into_bump_slice();
Some(ForeignCall(symbol.clone(), args))
Some(ForeignCall {
foreign_symbol: foreign_symbol.clone(),
arguments: args,
ret_layout: ret_layout.clone(),
})
} else {
None
}