Skip to content

Commit be99275

Browse files
committed
Don't quote symbolic arguments by default
Instead caller can do it if needed with `expr_protect()`
1 parent 85cd7e6 commit be99275

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

crates/harp/src/call.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77

88
use libr::*;
99

10+
use crate::exec::RFunction;
11+
use crate::exec::RFunctionExt;
1012
use crate::object::RObject;
11-
use crate::protect::RProtect;
1213
use crate::r_symbol;
1314
use crate::utils::r_typeof;
1415

@@ -39,42 +40,32 @@ impl RCall {
3940

4041
pub fn build(&self) -> RObject {
4142
unsafe {
42-
let mut protect = RProtect::new();
43-
44-
// Now, build the actual call to be evaluated
45-
let size = (1 + self.arguments.len()) as R_xlen_t;
46-
let call = protect.add(Rf_allocVector(LANGSXP, size));
47-
SET_TAG(call, R_NilValue);
48-
SETCAR(call, self.function.sexp);
43+
let call = RObject::new(Rf_lcons(self.function.sexp, R_NilValue));
44+
let mut tail = call.sexp;
4945

5046
// Append arguments to the call
51-
let mut slot = CDR(call);
5247
for argument in self.arguments.iter() {
53-
// Quote language objects by default
54-
// FIXME: Shouldn't this be done by the caller?
55-
let mut sexp = argument.value.sexp;
56-
if matches!(r_typeof(sexp), LANGSXP | SYMSXP | EXPRSXP) {
57-
let quote = protect.add(Rf_lang3(
58-
r_symbol!("::"),
59-
r_symbol!("base"),
60-
r_symbol!("quote"),
61-
));
62-
sexp = protect.add(Rf_lang2(quote, sexp));
63-
}
48+
SETCDR(tail, Rf_cons(argument.value.sexp, R_NilValue));
6449

65-
SETCAR(slot, sexp);
50+
tail = CDR(tail);
6651
if !argument.name.is_empty() {
67-
SET_TAG(slot, r_symbol!(argument.name));
52+
SET_TAG(tail, r_symbol!(argument.name));
6853
}
69-
70-
slot = CDR(slot);
7154
}
7255

73-
RObject::new(call)
56+
call
7457
}
7558
}
7659
}
7760

61+
pub fn r_expr_quote(x: impl Into<SEXP>) -> RObject {
62+
let x = x.into();
63+
match r_typeof(x) {
64+
SYMSXP | LANGSXP => return RFunction::new("base", "quote").add(x).call.build(),
65+
_ => return x.into(),
66+
}
67+
}
68+
7869
pub struct RArgument {
7970
pub name: String,
8071
pub value: RObject,

0 commit comments

Comments
 (0)