|
| 1 | +# What is the JVM language of PHP syntax? |
| 2 | +PHPJava is able to become a JVM language with PHP syntax. |
| 3 | +This feature analyze to AST using `nikic/php-parser`, And PHPJava assemble a intermediately code with assembler in PHPJava, and you can run it as a JVM language with `java` command. |
| 4 | +This feature is a experimental implementation more than any other. |
| 5 | + |
| 6 | +# DEMO |
| 7 | + |
| 8 | + |
| 9 | +# Get started |
| 10 | +1. Create a `HelloWorld.php` |
| 11 | +```php |
| 12 | +<?php |
| 13 | +class HelloWorld |
| 14 | +{ |
| 15 | + public static function main(array $strings) |
| 16 | + { |
| 17 | + echo "Hello World!"; |
| 18 | + } |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +2. Run `PackageAssembler`, and coordinate an intermediately code. |
| 23 | + |
| 24 | +```php |
| 25 | +<?php |
| 26 | +use PHPJava\Compiler\Lang\PackageAssembler; |
| 27 | +use PHPJava\Compiler\Lang\Stream\FileStream; |
| 28 | + |
| 29 | +(new PackageAssembler( |
| 30 | + (new FileStream(__DIR__ . '/HelloWorld.php')) |
| 31 | + // Specify output directory after compile is finished. |
| 32 | + ->setDistributeDirectory(__DIR__ . '/dist') |
| 33 | +))->assemble(); |
| 34 | + |
| 35 | +``` |
| 36 | + |
| 37 | +3. To run generated `HelloWorld.class` in `dist` directory. |
| 38 | + |
| 39 | +``` |
| 40 | +$ cd dist |
| 41 | +$ java HelloWorld |
| 42 | +``` |
| 43 | + |
| 44 | +You'll get `Hello World!`. |
| 45 | + |
| 46 | +# About compile |
| 47 | +## Compatibility |
| 48 | +This feature compile as the JDK 8. |
| 49 | + |
| 50 | +## About types |
| 51 | +PHPJava will try to convert to a string when passed literal or object is not a string. |
| 52 | +For example, The number literal `1` will convert as below roughly on Java. |
| 53 | + |
| 54 | +```java |
| 55 | +int number = 1; |
| 56 | +(new java.lang.Integer(number)).toString() |
| 57 | +``` |
| 58 | + |
| 59 | +PHPJava will assemble operation code as follows: |
| 60 | + |
| 61 | +``` |
| 62 | + 0: iconst_1 |
| 63 | + 1: istore_1 |
| 64 | + 2: getstatic #21 // Field java/lang/System.out:Ljava/io/PrintStream; |
| 65 | + 5: new #9 // class java/lang/Integer |
| 66 | + 8: dup |
| 67 | + 9: iload_1 |
| 68 | +10: invokespecial #7 // Method java/lang/Integer."<init>":(I)V |
| 69 | +13: invokevirtual #13 // Method java/lang/Integer.toString:()Ljava/lang/String; |
| 70 | +16: invokevirtual #25 // Method java/io/PrintStream.print:(Ljava/lang/String;)V |
| 71 | +``` |
| 72 | + |
| 73 | +## PHPRuntime.PHPStandard |
| 74 | +`PHPStandard` is a namespace for runtime classes of PHP. |
| 75 | + |
| 76 | +### PHPRuntime.PHPStandard.Constants (旧: PHPStandardClass) |
| 77 | +TBD |
| 78 | + |
| 79 | +### PHPRuntime.PHPStandard.Classes |
| 80 | +TBD |
| 81 | + |
| 82 | +### PHPRuntime.PHPStandard.Functions |
| 83 | +TBD |
| 84 | + |
| 85 | +### PHPRuntime.GlobalStore |
| 86 | +TBD |
| 87 | + |
| 88 | +## PHPRuntime.EntryPoint |
| 89 | +TBD |
0 commit comments