Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 46 additions & 39 deletions docs/bootstrap-inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Regenerate: `php script/bootstrap-inventory.php`

| Metric | Count |
|--------|------:|
| PHP files on vm.php path | 240 |
| PHP files on vm.php path | 241 |
| Source constructs flagged (blockers) | 10 |
| Source constructs flagged (warnings) | 629 |
| Source constructs flagged (warnings) | 631 |

## Compiler CFG gaps (`lib/Compiler.php`)

Expand Down Expand Up @@ -59,7 +59,7 @@ These `LogicException` messages indicate CFG ops or expressions not yet lowered:
| `ext/standard/JitStripTags.php` | 0 | 1 |
| `ext/standard/JitStrpos.php` | 0 | 1 |
| `ext/standard/JitUrlencode.php` | 0 | 1 |
| `ext/standard/Module.php` | 0 | 110 |
| `ext/standard/Module.php` | 0 | 111 |
| `ext/standard/VmDate.php` | 0 | 1 |
| `ext/standard/VmExit.php` | 0 | 2 |
| `ext/standard/VmFs.php` | 0 | 3 |
Expand All @@ -75,6 +75,7 @@ These `LogicException` messages indicate CFG ops or expressions not yet lowered:
| `ext/standard/array_keys.php` | 0 | 1 |
| `ext/standard/array_merge.php` | 0 | 1 |
| `ext/standard/array_pop.php` | 0 | 1 |
| `ext/standard/array_product.php` | 0 | 1 |
| `ext/standard/array_push.php` | 0 | 2 |
| `ext/standard/array_reverse.php` | 0 | 1 |
| `ext/standard/array_search.php` | 0 | 1 |
Expand Down Expand Up @@ -480,41 +481,42 @@ These `LogicException` messages indicate CFG ops or expressions not yet lowered:
- new array_reverse (line 93)
- new array_search (line 94)
- new array_sum (line 95)
- new array_flip (line 96)
- new array_unique (line 97)
- new array_fill (line 98)
- new array_combine (line 99)
- new range (line 100)
- new bin2hex (line 101)
- new hex2bin (line 102)
- new random_bytes (line 103)
- new str_pad (line 104)
- new str_split (line 105)
- new htmlspecialchars (line 106)
- new strip_tags (line 107)
- new header_ (line 108)
- new header_remove (line 109)
- new header_list (line 110)
- new getallheaders_ (line 111)
- new http_response_code (line 112)
- new urlencode (line 113)
- new rawurlencode (line 114)
- new urldecode (line 115)
- new rawurldecode (line 116)
- new parse_url (line 117)
- new dirname (line 118)
- new basename (line 119)
- new realpath (line 120)
- new file_get_contents (line 121)
- new getenv_ (line 122)
- new putenv_ (line 123)
- new extract_ (line 124)
- new compact_ (line 125)
- new scandir (line 126)
- new glob_ (line 127)
- new time (line 128)
- new date (line 129)
- new gmdate (line 130)
- new array_product (line 96)
- new array_flip (line 97)
- new array_unique (line 98)
- new array_fill (line 99)
- new array_combine (line 100)
- new range (line 101)
- new bin2hex (line 102)
- new hex2bin (line 103)
- new random_bytes (line 104)
- new str_pad (line 105)
- new str_split (line 106)
- new htmlspecialchars (line 107)
- new strip_tags (line 108)
- new header_ (line 109)
- new header_remove (line 110)
- new header_list (line 111)
- new getallheaders_ (line 112)
- new http_response_code (line 113)
- new urlencode (line 114)
- new rawurlencode (line 115)
- new urldecode (line 116)
- new rawurldecode (line 117)
- new parse_url (line 118)
- new dirname (line 119)
- new basename (line 120)
- new realpath (line 121)
- new file_get_contents (line 122)
- new getenv_ (line 123)
- new putenv_ (line 124)
- new extract_ (line 125)
- new compact_ (line 126)
- new scandir (line 127)
- new glob_ (line 128)
- new time (line 129)
- new date (line 130)
- new gmdate (line 131)
- 2 class method(s) — PHPCfg Op\Stmt\ClassMethod not lowered in Compiler

### `ext/standard/VmDate.php`
Expand Down Expand Up @@ -606,6 +608,11 @@ These `LogicException` messages indicate CFG ops or expressions not yet lowered:
**Warnings** (review for bootstrap subset):
- 2 class method(s) — PHPCfg Op\Stmt\ClassMethod not lowered in Compiler

### `ext/standard/array_product.php`

**Warnings** (review for bootstrap subset):
- 2 class method(s) — PHPCfg Op\Stmt\ClassMethod not lowered in Compiler

### `ext/standard/array_push.php`

**Warnings** (review for bootstrap subset):
Expand Down Expand Up @@ -1329,7 +1336,7 @@ These `LogicException` messages indicate CFG ops or expressions not yet lowered:
- new Variable (line 655)
- new Variable (line 1071)
- new Variable (line 1079)
- 33 class method(s) — PHPCfg Op\Stmt\ClassMethod not lowered in Compiler
- 37 class method(s) — PHPCfg Op\Stmt\ClassMethod not lowered in Compiler

### `lib/JIT/BasicBlockHelper.php`

Expand Down
1 change: 1 addition & 0 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Auto-generated by `script/capability-matrix.php`. Do not edit by hand.
| `array_keys` | yes | yes | yes | standard | doc: VM only |
| `array_merge` | yes | yes | yes | standard | doc: VM only |
| `array_pop` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_product` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_push` | yes | yes | yes | standard | doc: VM only; JIT PHPT |
| `array_reverse` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_search` | yes | no | no | standard | doc: VM only; not implemented for JIT in this compiler build |
Expand Down
1 change: 1 addition & 0 deletions ext/standard/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function getFunctions(): array
new array_reverse(),
new array_search(),
new array_sum(),
new array_product(),
new array_flip(),
new array_unique(),
new array_fill(),
Expand Down
86 changes: 86 additions & 0 deletions ext/standard/array_product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

/**
* This file is part of PHP-Compiler, a PHP CFG Compiler for PHP code
*
* @copyright 2015 Anthony Ferrara. All rights reserved
* @license MIT See LICENSE at the root of the project for more info
*/

namespace PHPCompiler\ext\standard;

use PHPCompiler\Frame;
use PHPCompiler\Func\Internal;
use PHPCompiler\JIT\ArrayBuiltinHelper;
use PHPCompiler\JIT\Context;
use PHPCompiler\JIT\Variable as JITVariable;
use PHPCompiler\VM\Variable;
use PHPLLVM\Value;

/**
* array_product() for arrays of integers and floats (subset of PHP; native LLVM in JIT).
*/
final class array_product extends Internal
{
public function execute(Frame $frame): void
{
if (1 !== \count($frame->calledArgs)) {
throw new \LogicException('array_product() requires exactly one argument');
}
$array = $frame->calledArgs[0]->resolveIndirect();
if (null === $frame->returnVar) {
return;
}
if (Variable::TYPE_ARRAY !== $array->type) {
throw new \LogicException('array_product() argument must be an array in this compiler build');
}
$prodInt = 1;
$prodFloat = 1.0;
$useFloat = false;
foreach ($array->toArray()->iterate(true) as $value) {
$v = $value->resolveIndirect();
if (Variable::TYPE_INTEGER === $v->type) {
if ($useFloat) {
$prodFloat *= (float) $v->toInt();
} else {
$prodInt *= $v->toInt();
}
continue;
}
if (Variable::TYPE_FLOAT === $v->type) {
if (!$useFloat) {
$useFloat = true;
$prodFloat = (float) $prodInt * $v->toFloat();
} else {
$prodFloat *= $v->toFloat();
}
continue;
}
throw new \LogicException('array_product() only supports integer and float elements in this compiler build');
}
if ($useFloat) {
$frame->returnVar->float($prodFloat);
} else {
$frame->returnVar->int($prodInt);
}
}

public Context $context;

public function call(Context $context, JITVariable ...$args): Value
{
if (1 !== \count($args)) {
throw new \LogicException('array_product() requires exactly one argument');
}
if ($args[0]->type & JITVariable::IS_NATIVE_ARRAY) {
return ArrayBuiltinHelper::arrayProduct($context, $args[0]);
}
if (JITVariable::TYPE_HASHTABLE === $args[0]->type) {
return ArrayBuiltinHelper::arrayProduct($context, $args[0]);
}

throw new \LogicException('array_product() only supports arrays in this compiler build');
}
}
Loading
Loading