Skip to content

Commit 1049b21

Browse files
committed
Include emitters in xp compile output
1 parent ba9783e commit 1049b21

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ $ xp compile -o dist.xar src/main/php/
5959
# Compile src/main/php, do not write output
6060
$ xp compile -n src/main/php/
6161

62-
# Target PHP 7.0 (default target is current PHP version)
63-
$ xp compile -t PHP.7.0 HelloWorld.php HelloWorld.class.php
62+
# Target PHP 7.4 (default target is current PHP version)
63+
$ xp compile -t PHP.7.4 HelloWorld.php HelloWorld.class.php
6464
```
6565

6666
The -o and -n options accept multiple input sources following them.
@@ -81,7 +81,12 @@ $ xp compile
8181
Usage: xp compile <in> [<out>]
8282

8383
@FileSystemCL<./vendor/xp-framework/compiler/src/main/php>
84-
lang.ast.syntax.php.Using
84+
lang.ast.emit.PHP70
85+
lang.ast.emit.PHP71
86+
lang.ast.emit.PHP72
87+
lang.ast.emit.PHP74
88+
lang.ast.emit.PHP80 [*]
89+
lang.ast.syntax.php.Using [*]
8590

8691
@FileSystemCL<./vendor/xp-lang/php-is-operator/src/main/php>
8792
lang.ast.syntax.php.IsOperator

src/main/php/xp/compiler/CompileRunner.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
* ```sh
3131
* $ xp compile -n src/main/php/
3232
* ```
33-
* - Target PHP 7.0 (default target is current PHP version)
33+
* - Target PHP 7.4 (default target is current PHP version)
3434
* ```sh
35-
* $ xp compile -t PHP.7.0 HelloWorld.php HelloWorld.class.php
35+
* $ xp compile -t PHP.7.4 HelloWorld.php HelloWorld.class.php
3636
* ```
3737
*
3838
* The *-o* and *-n* options accept multiple input sources following them.

src/main/php/xp/compiler/Usage.class.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace xp\compiler;
22

3-
use lang\ast\Language;
3+
use lang\ast\{Language, Emitter};
4+
use lang\reflect\Package;
45
use util\cmd\Console;
56

67
class Usage {
@@ -9,24 +10,31 @@ class Usage {
910
public static function main(array $args) {
1011
Console::$err->writeLine('Usage: xp compile <in> [<out>]');
1112

12-
// Show syntax implementations sorted by class loader
13-
$loaders= $sorted= [];
14-
foreach (Language::named('PHP')->extensions() as $extension) {
15-
$t= typeof($extension);
16-
$l= $t->getClassLoader();
17-
$hash= $l->hashCode();
18-
if (isset($sorted[$hash])) {
19-
$sorted[$hash][]= $t;
20-
} else {
21-
$loaders[$hash]= $l;
22-
$sorted[$hash]= [$t];
13+
$impl= new class() {
14+
public $byLoader= [];
15+
16+
public function add($t, $active= false) {
17+
$this->byLoader[$t->getClassLoader()->toString()][$t->getName()]= $active;
18+
}
19+
};
20+
21+
$default= Emitter::forRuntime('PHP.'.PHP_VERSION);
22+
foreach (Package::forName('lang.ast.emit')->getClasses() as $class) {
23+
if ($class->isSubclassOf(Emitter::class) && !(MODIFIER_ABSTRACT & $class->getModifiers())) {
24+
$impl->add($class, $class->equals($default));
2325
}
2426
}
25-
foreach ($sorted as $hash => $list) {
27+
28+
foreach (Language::named('PHP')->extensions() as $extension) {
29+
$impl->add(typeof($extension), true);
30+
}
31+
32+
// Show implementations sorted by class loader
33+
foreach ($impl->byLoader as $loader => $list) {
2634
Console::$err->writeLine();
27-
Console::$err->writeLine("\033[33m@", $loaders[$hash], "\033[0m");
28-
foreach ($list as $syntax) {
29-
Console::$err->writeLine($syntax->getName());
35+
Console::$err->writeLine("\033[33m@", $loader, "\033[0m");
36+
foreach ($list as $impl => $active) {
37+
Console::$err->writeLine($impl, $active ? " [\033[36m*\033[0m]" : '');
3038
}
3139
}
3240
return 2;

0 commit comments

Comments
 (0)