@@ -29,89 +29,69 @@ using Args = std::vector<const char*>;
29
29
30
30
void * createInterpreter (const Args& ExtraArgs = {})
31
31
{
32
- Args ClangArgs = {/* "-xc++"*/ " -v" };
33
- if (std::find_if (
34
- ExtraArgs.begin (),
35
- ExtraArgs.end (),
36
- [](const std::string& s)
37
- {
38
- return s == " -resource-dir" ;
39
- }
40
- )
41
- == ExtraArgs.end ())
42
- {
32
+ Args ClangArgs = {/* "-xc++"*/ " -v" };
33
+ if (std::find_if (ExtraArgs.begin (), ExtraArgs.end (), [](const std::string& s) {
34
+ return s == " -resource-dir" ;}) == ExtraArgs.end ()) {
43
35
std::string resource_dir = Cpp::DetectResourceDir ();
44
- if (!resource_dir.empty ())
45
- {
36
+ if (!resource_dir.empty ()) {
46
37
ClangArgs.push_back (" -resource-dir" );
47
38
ClangArgs.push_back (resource_dir.c_str ());
48
- }
49
- else
50
- {
39
+ } else {
51
40
std::cerr << " Failed to detect the resource-dir\n " ;
52
41
}
53
42
}
54
43
std::vector<std::string> CxxSystemIncludes;
55
44
Cpp::DetectSystemCompilerIncludePaths (CxxSystemIncludes);
56
- for (const std::string& CxxInclude : CxxSystemIncludes)
57
- {
45
+ for (const std::string& CxxInclude : CxxSystemIncludes) {
58
46
ClangArgs.push_back (" -isystem" );
59
47
ClangArgs.push_back (CxxInclude.c_str ());
60
48
}
61
49
ClangArgs.insert (ClangArgs.end (), ExtraArgs.begin (), ExtraArgs.end ());
62
50
63
51
// FIXME: We should process the kernel input options and conditionally pass
64
52
// the gpu args here.
65
- if (std::find_if (
66
- ExtraArgs.begin (),
67
- ExtraArgs.end (),
68
- [](const std::string& s)
69
- {
70
- return s == " -gdwarf-4" ;
71
- }
72
- )
73
- == ExtraArgs.end ())
74
- {
53
+ if (std::find_if (ExtraArgs.begin (), ExtraArgs.end (), [](const std::string& s) {
54
+ return s == " -gdwarf-4" ;}) == ExtraArgs.end ()) {
75
55
// If no debugger option, then use the non-OOP JIT execution.
76
56
return Cpp::CreateInterpreter (ClangArgs /* , {"-cuda"}*/ );
77
57
}
78
58
79
- // If debugger option is set, then use the OOP JIT execution.
59
+ #ifdef XEUS_CPP_USE_DEBUGGER
60
+ // If debugger option is set, then use the OOP JIT execution.
80
61
return Cpp::CreateInterpreter (ClangArgs, {}, true );
62
+ #else
63
+ return Cpp::CreateInterpreter (ClangArgs);
64
+ #endif
81
65
}
82
66
83
67
using namespace std ::placeholders;
84
68
85
69
namespace xcpp
86
70
{
87
- struct StreamRedirectRAII
88
- {
89
- std::string &out, &err;
90
-
91
- StreamRedirectRAII (std::string& o, std::string& e)
92
- : out(o)
93
- , err(e)
94
- {
95
- Cpp::BeginStdStreamCapture (Cpp::kStdErr );
96
- Cpp::BeginStdStreamCapture (Cpp::kStdOut );
97
- }
98
-
99
- ~StreamRedirectRAII ()
100
- {
101
- out = Cpp::EndStdStreamCapture ();
102
- err = Cpp::EndStdStreamCapture ();
103
- }
71
+ struct StreamRedirectRAII {
72
+ std::string &err;
73
+ StreamRedirectRAII (std::string &e) : err(e) {
74
+ Cpp::BeginStdStreamCapture (Cpp::kStdErr );
75
+ Cpp::BeginStdStreamCapture (Cpp::kStdOut );
76
+ }
77
+ ~StreamRedirectRAII () {
78
+ std::string out = Cpp::EndStdStreamCapture ();
79
+ err = Cpp::EndStdStreamCapture ();
80
+ std::cout << out;
81
+ }
104
82
};
105
83
106
84
void interpreter::configure_impl ()
107
85
{
108
86
xeus::register_interpreter (this );
109
87
}
110
88
89
+ #ifdef XEUS_CPP_USE_DEBUGGER
111
90
pid_t interpreter::get_current_pid ()
112
91
{
113
92
return Cpp::GetExecutorPID ();
114
93
}
94
+ #endif
115
95
116
96
static std::string get_stdopt ()
117
97
{
@@ -140,8 +120,8 @@ __get_cxx_version ()
140
120
return std::to_string (cxx_version);
141
121
}
142
122
143
- interpreter::interpreter (int argc, const char * const * argv)
144
- : xmagics()
123
+ interpreter::interpreter (int argc, const char * const * argv):
124
+ xmagics ()
145
125
, p_cout_strbuf(nullptr )
146
126
, p_cerr_strbuf(nullptr )
147
127
, m_cout_buffer(std::bind(&interpreter::publish_stdout, this , _1))
@@ -202,12 +182,12 @@ __get_cxx_version ()
202
182
std::cerr.rdbuf (&null);
203
183
}
204
184
205
- std::string out, err;
185
+ std::string err;
206
186
207
187
// Attempt normal evaluation
208
188
try
209
189
{
210
- StreamRedirectRAII R (out, err);
190
+ StreamRedirectRAII R (err);
211
191
compilation_result = Cpp::Process (code.c_str ());
212
192
}
213
193
catch (std::exception& e)
@@ -229,10 +209,6 @@ __get_cxx_version ()
229
209
evalue = " Compilation error! " + err;
230
210
std::cerr << err;
231
211
}
232
- else
233
- {
234
- std::cout << out;
235
- }
236
212
237
213
// Flush streams
238
214
std::cout << std::flush;
@@ -254,8 +230,7 @@ __get_cxx_version ()
254
230
//
255
231
// JupyterLab displays the "{ename}: {evalue}" if the traceback is
256
232
// empty.
257
- if (evalue.size () < 4 )
258
- {
233
+ if (evalue.size () < 4 ) {
259
234
ename = " " ;
260
235
}
261
236
std::vector<std::string> traceback ({ename + evalue});
@@ -301,8 +276,7 @@ __get_cxx_version ()
301
276
302
277
Cpp::CodeComplete (results, code.c_str (), 1 , _cursor_pos + 1 );
303
278
304
- return xeus::create_complete_reply (
305
- results /* matches*/ ,
279
+ return xeus::create_complete_reply (results /* matches*/ ,
306
280
cursor_pos - to_complete.length () /* cursor_start*/ ,
307
281
cursor_pos /* cursor_end*/
308
282
);
@@ -514,11 +488,11 @@ __get_cxx_version ()
514
488
515
489
void interpreter::init_preamble ()
516
490
{
517
- // NOLINTBEGIN(cppcoreguidelines-owning-memory)
491
+ // NOLINTBEGIN(cppcoreguidelines-owning-memory)
518
492
preamble_manager.register_preamble (" introspection" , std::make_unique<xintrospection>());
519
493
preamble_manager.register_preamble (" magics" , std::make_unique<xmagics_manager>());
520
494
preamble_manager.register_preamble (" shell" , std::make_unique<xsystem>());
521
- // NOLINTEND(cppcoreguidelines-owning-memory)
495
+ // NOLINTEND(cppcoreguidelines-owning-memory)
522
496
}
523
497
524
498
void interpreter::init_magic ()
0 commit comments