Skip to content

Commit

Permalink
Remove the call_fun and use just the trampoline
Browse files Browse the repository at this point in the history
  • Loading branch information
fikovnik committed Sep 9, 2024
1 parent f375196 commit dc6bb5a
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 37 deletions.
2 changes: 1 addition & 1 deletion client/rsh/src/bc2c/runtime_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SEXP do_relop_dflt(SEXP call, SEXP op, SEXP x, SEXP y);
SEXP do_math1(SEXP call, SEXP op, SEXP args, SEXP env);
SEXP R_unary(SEXP call, SEXP op, SEXP s1);
SEXP do_logic(SEXP call, SEXP op, SEXP args, SEXP env);
int tryDispatch(char *generic, SEXP call, SEXP x, SEXP rho, SEXP *pv);
int tryDispatch(const char *generic, SEXP call, SEXP x, SEXP rho, SEXP *pv);
SEXP R_subset3_dflt(SEXP x, SEXP input, SEXP call);
SEXP CreateTag(SEXP x);

Expand Down
28 changes: 1 addition & 27 deletions client/rsh/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ void jit_fun_destructor(SEXP fun_ptr) {

namespace rsh {

SEXP CALL_FUN = nullptr;

SEXP RSH_JIT_FUN_PTR = Rf_install("RSH_JIT_FUN_PTR");

static CompileResponse compile_closure(SEXP closure, CompilerOptions options) {
Expand Down Expand Up @@ -90,7 +88,7 @@ static SEXP create_wrapper_body(SEXP closure, SEXP c_cp) {
// store the original AST (consequently it will not correspond to the AST)
SET_VECTOR_ELT(cp, i++, BODY(closure));
SET_VECTOR_ELT(cp, i++, Rf_install(".External2"));
SET_VECTOR_ELT(cp, i++, CALL_FUN);
SET_VECTOR_ELT(cp, i++, BC2C_CALL_TRAMPOLINE_SXP);
SET_VECTOR_ELT(cp, i++, closure);
SET_VECTOR_ELT(cp, i++, c_cp);
SET_VECTOR_ELT(cp, i++, expr_index);
Expand Down Expand Up @@ -197,29 +195,6 @@ SEXP compile(SEXP closure, SEXP options) {
return closure;
}

SEXP call_fun(SEXP call, SEXP op, SEXP args, SEXP env) {
SEXP closure = CADR(args);
if (TYPEOF(closure) != CLOSXP) {
Rf_error("Expected a closure");
}

SEXP body = BODY(closure);
if (TYPEOF(body) != BCODESXP) {
Rf_error("Expected a compiled closure");
}

SEXP cp = BCODE_CONSTS(body);
if (XLENGTH(cp) != 6) {
Rf_error("Expected a constant pool with 6 elements");
}

SEXP c_cp = VECTOR_ELT(cp, LENGTH(cp) - 2);
auto fun = (JitFun)R_ExternalPtrAddr(VECTOR_ELT(c_cp, 0));
SEXP res = fun(env, VECTOR_ELT(c_cp, 1));

return res;
}

SEXP is_compiled(SEXP closure) {
if (TYPEOF(closure) != CLOSXP) {
Rf_error("Expected a closure");
Expand Down Expand Up @@ -257,7 +232,6 @@ SEXP is_compiled(SEXP closure) {
SEXP initialize() {
Rsh_initialize_runtime();

CALL_FUN = load_symbol_checked("rsh", "C_call_fun");
BC2C_CALL_TRAMPOLINE_SXP = load_symbol_checked("rsh", "C_call_trampoline");

return R_NilValue;
Expand Down
1 change: 0 additions & 1 deletion client/rsh/src/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct CompilerOptions {

SEXP initialize();
SEXP compile(SEXP closure, SEXP options);
SEXP call_fun(SEXP call, SEXP op, SEXP args, SEXP env);
SEXP is_compiled(SEXP closure);

using JitFun = SEXP (*)(SEXP env, SEXP cp);
Expand Down
4 changes: 1 addition & 3 deletions client/rsh/src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ static const R_CallMethodDef callMethods[] = {
{NULL, NULL, 0}};

static const R_ExternalMethodDef externalMethods[] = {
{"call_fun", (DL_FUNC)&rsh::call_fun, -1},
{"call_trampoline", (DL_FUNC)&Rsh_call_trampoline, -1},
{NULL, NULL, 0}};
{"call_trampoline", (DL_FUNC)&Rsh_call_trampoline, -1}, {NULL, NULL, 0}};

void R_init_rsh(DllInfo *dll) {
R_registerRoutines(dll, NULL, callMethods, NULL, externalMethods);
Expand Down
4 changes: 0 additions & 4 deletions client/rsh/src/rsh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace rsh {

using Bytes = std::vector<u8>;

// This should point to the R ExternalRoutine/NativeSymbolInfo structure
// that represents the exported C function registered in r_init_rsh
extern SEXP CALL_FUN;

// A tag to attach to the external pointer
extern SEXP RSH_JIT_FUN_PTR;

Expand Down
2 changes: 1 addition & 1 deletion external/R
Submodule R updated 1 files
+1 −1 src/main/eval.c
1 change: 1 addition & 0 deletions external/R-debug
Submodule R-debug added at 687361

0 comments on commit dc6bb5a

Please sign in to comment.