-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvalExitCallback.cpp
59 lines (48 loc) · 1.65 KB
/
EvalExitCallback.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "EvalExitCallback.hpp"
#include "Application.hpp"
#include "Context.hpp"
#include "utilities.h"
namespace instrumentr {
typedef void (*callback_t)(ContextSPtr context,
ApplicationSPtr application,
SEXP r_expression,
SEXP r_rho,
SEXP r_result);
SEXP EvalExitCallback::class_ = nullptr;
void EvalExitCallback::initialize() {
class_ = Callback::create_class("instrumentr_eval_exit_callback");
R_PreserveObject(class_);
}
void EvalExitCallback::finalize() {
R_ReleaseObject(class_);
class_ = NULL;
}
SEXP EvalExitCallback::get_class() {
return class_;
}
/* TODO: wrap expression and result */
void EvalExitCallback::invoke(SEXP r_context,
SEXP r_application,
SEXP r_expression,
SEXP r_rho,
SEXP r_result) {
ContextSPtr context = from_sexp<Context>(r_context);
if (is_c_callback()) {
ApplicationSPtr application = from_sexp<Application>(r_application);
callback_t callback = get_function<callback_t>();
callback(context, application, r_expression, r_rho, r_result);
}
/**/
else {
SEXP r_function_name = get_function_name();
SEXP r_environment = context->get_environment();
Rf_eval(Rf_lang6(r_function_name,
r_context,
r_application,
r_expression,
r_rho,
r_result),
r_environment);
}
}
} // namespace instrumentr