/** * Gets emitter * * @return xp.compiler.emit.Emitter */ protected static function emitter() { if (null === self::$emitter) { self::$emitter = Emitter::newInstance(); } return self::$emitter; }
/** * Compiles a class if necessary * * @param string $class * @return string * @throws lang.ClassLoadingException */ public function loadClass0($class) { if (isset(\xp::$cl[$class])) { return literal($class); } // Locate sourcecode if (null === ($source = $this->locateSource($class))) { throw new ClassNotFoundException($class); } if (null === $this->emitter) { $this->emitter = Emitter::newInstance(); } // Parse, then emit source $this->debug && fputs(STDERR, "COMPILE " . $source->toString() . "\n"); $scope = new TaskScope(new CompilationTask($source, new NullDiagnosticListener(), $this->files, $this->emitter)); $this->emitter->clearMessages(); try { $r = $this->emitter->emit($source->getSyntax()->parse($source->getInputStream()), $scope); } catch (ParseException $e) { $this->debug && $e->printStackTrace(); throw new ClassFormatException('Cannot compile ' . $source->getURI() . ': ' . $e->formattedErrors(''), $e); } catch (FormatException $e) { $this->debug && $e->printStackTrace(); throw new JitCompilationError($class, [$this], $this->emitter->messages(), $e); } // Clean up unset($this->source[$class]); // Define type $this->debug && fputs(STDERR, $r->type()->toString() . "\n"); $r->executeWith([]); \xp::$cl[$class] = nameof($this) . '://' . $this->instanceId(); return $r->type()->literal(); }