Evaluates a code snippet.
172{
173#ifdef MAYAFLUX_PLATFORM_MACOS
174 __block EvalResult result;
175#else
176 EvalResult result;
177#endif
178
179 if (!
m_impl->interpreter) {
180 result.error = "Interpreter not initialized";
181 LILA_ERROR(Emitter::INTERPRETER, result.error);
182 return result;
183 }
184
185 LILA_DEBUG(Emitter::INTERPRETER,
"Evaluating code...");
186
187#ifdef MAYAFLUX_PLATFORM_MACOS
188 dispatch_sync(dispatch_get_main_queue(), ^{
189 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
190
191 if (!eval_result) {
192 result.success = true;
193 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
194 } else {
195 result.success = false;
196 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
197 LILA_ERROR(Emitter::INTERPRETER, result.error);
198 }
199 });
200#else
201 auto eval_result =
m_impl->interpreter->ParseAndExecute(code);
202
203 if (!eval_result) {
204 result.success = true;
205 LILA_DEBUG(Emitter::INTERPRETER,
"Code evaluation succeeded");
206 } else {
207 result.success = false;
208 result.error = "Execution failed: " + llvm::toString(std::move(eval_result));
209 LILA_ERROR(Emitter::INTERPRETER, result.error);
210 }
211#endif
212
214 return result;
215}
std::unique_ptr< Impl > m_impl
Internal implementation details.