Skip to content

Commit

Permalink
Export new r_arg_match() lazy interface
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed May 24, 2022
1 parent 5f9df77 commit a7f277a
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 12 deletions.
10 changes: 9 additions & 1 deletion src/internal/arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,19 @@ int arg_match1(r_obj* arg,
}
}

r_obj* ffi_error_call = r_lazy_eval(error_call);
if (ffi_error_call == r_missing_arg) {
// Replace `error_call` by environment on the stack because
// `r_eval_with_` evaluates in an out-of-stack mask
ffi_error_call = r_peek_frame();
}
KEEP(ffi_error_call);

r_eval_with_wxyz(stop_arg_match_call,
KEEP(wrap_chr(arg)),
values,
KEEP(lazy_wrap_chr(error_arg)),
KEEP(r_lazy_eval(error_call)),
KEEP(ffi_error_call),
rlang_ns_env);
r_stop_unreachable();
}
Expand Down
5 changes: 3 additions & 2 deletions src/internal/decl/dots-decl.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
static r_obj* auto_name_call;
static r_obj* dots_homonyms_arg;
static r_obj* dots_homonyms_values;
static r_obj* dots_ignore_empty_arg;
static r_obj* dots_ignore_empty_values;
static r_obj* empty_spliced_arg;
static r_obj* glue_unquote_fn;
static r_obj* quosures_attrib;
static r_obj* splice_box_attrib;
static r_obj* abort_dots_homonyms_ns_sym;

static struct r_lazy dots_homonyms_arg;
static struct r_lazy dots_ignore_empty_arg;

r_obj* rlang_ns_get(const char* name);

static
Expand Down
19 changes: 13 additions & 6 deletions src/internal/dots.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,10 @@ r_obj* dots_unquote(r_obj* dots, struct dots_capture_info* capture_info) {

static
enum dots_ignore_empty arg_match_ignore_empty(r_obj* ignore_empty) {
return r_arg_match(ignore_empty, dots_ignore_empty_values, dots_ignore_empty_arg, r_missing_arg);
return r_arg_match(ignore_empty,
dots_ignore_empty_values,
dots_ignore_empty_arg,
r_lazy_missing_arg);
}

static
Expand All @@ -547,7 +550,10 @@ const char* dots_homonyms_c_values[DOTS_HOMONYMS_SIZE] = {

static
enum dots_homonyms arg_match_homonyms(r_obj* homonyms) {
return r_arg_match(homonyms, dots_homonyms_values, dots_homonyms_arg, r_missing_arg);
return r_arg_match(homonyms,
dots_homonyms_values,
dots_homonyms_arg,
r_lazy_missing_arg);
}

static
Expand Down Expand Up @@ -1093,17 +1099,18 @@ void rlang_init_dots(r_obj* ns) {
dots_homonyms_values = r_chr_n(dots_homonyms_c_values, DOTS_HOMONYMS_SIZE);
r_preserve_global(dots_homonyms_values);

dots_ignore_empty_arg = r_sym(".ignore_empty");
dots_homonyms_arg = r_sym(".homonyms");
dots_ignore_empty_arg = (struct r_lazy) { .x = r_sym(".ignore_empty"), .env = r_null };
dots_homonyms_arg = (struct r_lazy) { .x = r_sym(".homonyms"), .env = r_null };
}

static r_obj* auto_name_call = NULL;
static r_obj* empty_spliced_arg = NULL;
static r_obj* glue_unquote_fn = NULL;
static r_obj* dots_homonyms_arg = NULL;
static r_obj* dots_homonyms_values = NULL;
static r_obj* dots_ignore_empty_arg = NULL;
static r_obj* dots_ignore_empty_values = NULL;
static r_obj* quosures_attrib = NULL;
static r_obj* splice_box_attrib = NULL;
static r_obj* abort_dots_homonyms_ns_sym = NULL;

static struct r_lazy dots_homonyms_arg = { 0 };
static struct r_lazy dots_ignore_empty_arg = { 0 };
8 changes: 6 additions & 2 deletions src/rlang/arg.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "rlang.h"

int (*r_arg_match)(r_obj* arg, r_obj* values, r_obj* error_arg, r_obj* error_call);
int (*r_arg_match)(r_obj* arg,
r_obj* values,
struct r_lazy error_arg,
struct r_lazy error_call);

void r_init_library_arg() {
r_arg_match = (int (*)(r_obj*, r_obj*, r_obj*, r_obj*)) r_peek_c_callable("rlang", "rlang_arg_match");
r_arg_match = (int (*)(r_obj*, r_obj*, struct r_lazy, struct r_lazy))
r_peek_c_callable("rlang", "rlang_arg_match_2");
}
5 changes: 4 additions & 1 deletion src/rlang/arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#define RLANG_ARG_H


extern int (*r_arg_match)(r_obj* arg, r_obj* values, r_obj* error_arg, r_obj* error_call);
extern int (*r_arg_match)(r_obj* arg,
r_obj* values,
struct r_lazy error_arg,
struct r_lazy error_call);


#endif
7 changes: 7 additions & 0 deletions src/rlang/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,10 @@ r_obj* r_exec_mask_n_call_poke(r_obj* fn_sym,
FREE(1);
return call;
}


void r_init_library_eval() {
r_lazy_missing_arg = (struct r_lazy) { .x = r_missing_arg, .env = r_null };
}

struct r_lazy r_lazy_missing_arg = { 0 };
3 changes: 3 additions & 0 deletions src/rlang/eval.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ r_obj* r_lazy_eval(struct r_lazy lazy) {
static
struct r_lazy r_lazy_null = { 0 };

extern
struct r_lazy r_lazy_missing_arg;

static inline
r_obj* r_lazy_eval_protect(struct r_lazy lazy) {
r_obj* out = KEEP(r_lazy_eval(lazy));
Expand Down
1 change: 1 addition & 0 deletions src/rlang/rlang.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ r_obj* r_init_library(r_obj* ns) {
r_init_library_cnd();
r_init_library_dyn_array();
r_init_library_env();
r_init_library_eval();
r_init_library_fn();
r_init_library_quo();
r_init_library_session();
Expand Down

0 comments on commit a7f277a

Please sign in to comment.