aboutsummaryrefslogtreecommitdiff
path: root/src/compiler/builtins.zc
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/builtins.zc')
-rw-r--r--src/compiler/builtins.zc8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/compiler/builtins.zc b/src/compiler/builtins.zc
index be8c3b4..f40e223 100644
--- a/src/compiler/builtins.zc
+++ b/src/compiler/builtins.zc
@@ -736,7 +736,7 @@ int array_push(word t) {
effect_note_mask(effect_value, EF_WRITE); af_mutate(xaf, tpack()); nogrow(t);
if (t[0] == TY_DYN && isagg(t[4])) serr("push takes scalar or reference elements; use resize for aggregates");
c = expr(); rval(); if (t[0] == TY_DYN) fcoerce(t[4]);
- if (isptr(xty) || xty == tword) effect_note_mask(effect_mask(c), EF_RETAIN); argcheck(c, 2);
+ if (isptr(xty) || xty == tword) effect_note_mask(effect_mask(c), EF_RETAIN); arg_site = 1; argcheck(c, 2); arg_site = 0;
if (t[0] == TY_DYN && !compat(t[4], xty)) tcerr("push", t[4], xty);
if (o3on && t[0] == TY_DYN && hasptr(t[4])) { lit(t[4]); callname(s_fatten); }
expect(s_rp);
@@ -1119,6 +1119,7 @@ int kw_extern() {
}
}
expect(s_rp);
+ int borrowed = borrows_clause(0, np, 1);
if (accept(s_eq)) {
if (tk != T_STR) { die("expected the c name as a string"); return 0; }
cname = tv;
@@ -1194,7 +1195,10 @@ int kw_extern() {
ebn10(i);
i++;
}
- ebs(") { let b = "); ebn10(a); ebs(";");
+ ebs(")");
+ // the stub keeps the declaration's borrows clause, so calls see it in the signature
+ if (borrowed) { ebs(" borrows "); i = 0; g = 0; while (i < np) { if ((borrowed >> i) & 1) { if (g) ebs(", "); ebs("p"); ebn10(i); g = 1; } i++; } }
+ ebs(" { let b = "); ebn10(a); ebs(";");
// the native descriptor borrows an integer address, not ownership of r.
// clear that scratch address after the call so it cannot keep the result rooted.
if (sret) { ebs(" "); ebs(rn); ebs("* r = rt.new("); ebs(rn); ebs("); b[3] = core.addr_b(r) >> 3;"); }