forked from jrh13/hol-light
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcomms_wrapper.cc
53 lines (46 loc) · 1.11 KB
/
comms_wrapper.cc
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
#include "subprocess.h"
#include "caml/alloc.h"
#include "caml/fail.h"
#include "caml/memory.h"
#include "caml/mlvalues.h"
extern "C" {
using hol_light::Subprocess;
CAMLprim value RecvString(value unit) {
CAMLparam1(unit);
try {
std::string s = Subprocess::child_comms().ReceiveString();
CAMLlocal1(ml_s);
ml_s = caml_copy_string(s.c_str());
CAMLreturn(ml_s);
} catch (std::exception& e) {
caml_failwith(e.what());
}
}
CAMLprim value RecvInt(value unit) {
CAMLparam1(unit);
try {
int64_t v = Subprocess::child_comms().ReceiveInt();
CAMLreturn(Val_long(v));
} catch (std::exception& e) {
caml_failwith(e.what());
}
}
CAMLprim value SendString(value ml_s) {
// Note: This assumes the string has no embedded null characters.
std::string s(String_val(ml_s));
try {
Subprocess::child_comms().SendString(s);
} catch (std::exception& e) {
caml_failwith(e.what());
}
return Val_unit;
}
CAMLprim value SendInt(value v) {
try {
Subprocess::child_comms().SendInt(Long_val(v));
} catch (std::exception& e) {
caml_failwith(e.what());
}
return Val_unit;
}
}