Evaluates a code snippet.
200{
201#ifdef MAYAFLUX_PLATFORM_MACOS
202 __block EvalResult result;
203#else
204 EvalResult result;
205#endif
206
207 if (!
m_impl->interpreter) {
208 result.error = "Interpreter not initialized";
209 LILA_ERROR(Emitter::INTERPRETER, result.error);
210 return result;
211 }
212
213 LILA_DEBUG(Emitter::INTERPRETER,
"Evaluating code...");
214
215#ifdef MAYAFLUX_PLATFORM_MACOS
216 dispatch_sync(dispatch_get_main_queue(), ^{
217 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
218
219 if (!eval_result) {
220 result.success = true;
221 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
222 } else {
223 result.success = false;
224 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
225 LILA_ERROR(Emitter::INTERPRETER, result.error);
226 }
227 });
228
229#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
230 auto completed = std::make_shared<std::atomic<bool>>(false);
231
232 auto* task = new std::function<void()>([&, completed]() {
233 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
234
235 if (!eval_result) {
236 result.success = true;
237 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
238 } else {
239 result.success = false;
240 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
241 LILA_ERROR(Emitter::INTERPRETER, result.error);
242 }
243
244 completed->store(true, std::memory_order_release);
245 });
246
247 PostThreadMessage(MayaFlux::Parallel::g_MainThreadId, MAYAFLUX_WM_DISPATCH, 0, (LPARAM)task);
248
249 while (!completed->load(std::memory_order_acquire)) {
250 std::this_thread::sleep_for(std::chrono::microseconds(100));
251 }
252
253#else
254 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
255
256 if (!eval_result) {
257 result.success = true;
258 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
259 } else {
260 result.success = false;
261 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
262 LILA_ERROR(Emitter::INTERPRETER, result.error);
263 }
264#endif
265
267 return result;
268}
std::unique_ptr< Impl > m_impl
Internal implementation details.