MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ eval()

ClangInterpreter::EvalResult Lila::ClangInterpreter::eval ( const std::string &  code)

Evaluates a code snippet.

Parameters
codeC++ code to execute
Returns
EvalResult containing success, output, and error info

Definition at line 231 of file ClangInterpreter.cpp.

232{
233#ifdef MAYAFLUX_PLATFORM_MACOS
234 __block EvalResult result;
235#else
236 EvalResult result;
237#endif
238
239 if (!m_impl->interpreter) {
240 result.error = "Interpreter not initialized";
241 LILA_ERROR(Emitter::INTERPRETER, result.error);
242 return result;
243 }
244
245 LILA_DEBUG(Emitter::INTERPRETER, "Evaluating code...");
246
247#ifdef MAYAFLUX_PLATFORM_MACOS
248 dispatch_sync(dispatch_get_main_queue(), ^{
249 auto eval_result = m_impl->interpreter->ParseAndExecute(code);
250
251 if (!eval_result) {
252 result.success = true;
253 LILA_DEBUG(Emitter::INTERPRETER, "Code evaluation succeeded");
254 } else {
255 result.success = false;
256 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
257 LILA_ERROR(Emitter::INTERPRETER, result.error);
258 }
259 });
260
261#elif defined(MAYAFLUX_PLATFORM_WINDOWS)
262 auto completed = std::make_shared<std::atomic<bool>>(false);
263
264 auto* task = static_cast<std::function<void()>*>(
265 HeapAlloc(GetProcessHeap(), 0, sizeof(std::function<void()>)));
266 new (task) std::function<void()>([&, completed]() {
267 auto eval_result = m_impl->interpreter->ParseAndExecute(code);
268
269 if (!eval_result) {
270 result.success = true;
271 LILA_DEBUG(Emitter::INTERPRETER, "Code evaluation succeeded");
272 } else {
273 result.success = false;
274 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
275 LILA_ERROR(Emitter::INTERPRETER, result.error);
276 }
277
278 completed->store(true, std::memory_order_release);
279 });
280
281 PostThreadMessage(MayaFlux::Parallel::g_MainThreadId, MAYAFLUX_WM_DISPATCH, 0, (LPARAM)task);
282
283 while (!completed->load(std::memory_order_acquire)) {
284 std::this_thread::sleep_for(std::chrono::microseconds(100));
285 }
286
287#else
288 auto eval_result = m_impl->interpreter->ParseAndExecute(code);
289
290 if (!eval_result) {
291 result.success = true;
292 LILA_DEBUG(Emitter::INTERPRETER, "Code evaluation succeeded");
293 } else {
294 result.success = false;
295 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
296 LILA_ERROR(Emitter::INTERPRETER, result.error);
297 }
298#endif
299
300 m_impl->eval_counter++;
301 return result;
302}
#define LILA_ERROR(emitter, msg)
#define LILA_DEBUG(emitter, msg)
std::unique_ptr< Impl > m_impl
Internal implementation details.

References Lila::ClangInterpreter::EvalResult::error, LILA_DEBUG, LILA_ERROR, and m_impl.

Referenced by eval_file().

+ Here is the caller graph for this function: