2828#include " xinput.hpp"
2929#include " xinspect.hpp"
3030#include " xmagics/os.hpp"
31+ #include " xmime_internal.hpp"
3132#include " xparser.hpp"
3233#include " xsystem.hpp"
3334
@@ -128,7 +129,7 @@ __get_cxx_version ()
128129
129130 void interpreter::execute_request_impl (
130131 send_reply_callback cb,
131- int /* execution_count */ ,
132+ int execution_counter ,
132133 const std::string& code,
133134 xeus::execute_request_config config,
134135 nl::json /* user_expressions*/
@@ -153,7 +154,9 @@ __get_cxx_version ()
153154 auto errorlevel = 0 ;
154155 std::string ename;
155156 std::string evalue;
156- bool compilation_result = false ;
157+ // bool compilation_result = false;
158+ intptr_t output_value;
159+ bool hadError = false ;
157160
158161 // If silent is set to true, temporarily dismiss all std::cerr and
159162 // std::cout outputs resulting from `process_code`.
@@ -174,7 +177,7 @@ __get_cxx_version ()
174177 try
175178 {
176179 StreamRedirectRAII R (err);
177- compilation_result = Cpp::Process (code.c_str ());
180+ output_value = Cpp::Evaluate (code.c_str (), &hadError );
178181 }
179182 catch (std::exception& e)
180183 {
@@ -188,7 +191,7 @@ __get_cxx_version ()
188191 ename = " Error: " ;
189192 }
190193
191- if (compilation_result )
194+ if (hadError )
192195 {
193196 errorlevel = 1 ;
194197 ename = " Error: " ;
@@ -233,15 +236,12 @@ __get_cxx_version ()
233236 }
234237 else
235238 {
236- /*
237- // Publish a mime bundle for the last return value if
238- // the semicolon was omitted.
239- if (!config.silent && output.hasValue() && trim(code).back() != ';')
240- {
241- nl::json pub_data = mime_repr(output);
242- publish_execution_result(execution_counter, std::move(pub_data), nl::json::object());
243- }
244- */
239+ // Publish a mime bundle for the last return value if
240+ // the semicolon was omitted.
241+ if (!config.silent && !hadError && trim (code).back () != ' ;' ) {
242+ nl::json pub_data = mime_repr (output_value);
243+ publish_execution_result (execution_counter, std::move (pub_data), nl::json::object ());
244+ }
245245 // Compose execute_reply message.
246246 kernel_res[" status" ] = " ok" ;
247247 kernel_res[" payload" ] = nl::json::array ();
0 commit comments