Skip to content

Commit

Permalink
Merge pull request #2286 from zephir-lang/development
Browse files Browse the repository at this point in the history
0.14.0
  • Loading branch information
Jeckerson authored Sep 18, 2021
2 parents 0be9ad5 + e1b0dd1 commit a7d7a61
Show file tree
Hide file tree
Showing 40 changed files with 970 additions and 595 deletions.
37 changes: 0 additions & 37 deletions .ci/install-zephir-parser.sh

This file was deleted.

1 change: 0 additions & 1 deletion .ci/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set -eu
php \
-d extension=ext/modules/stub.so \
vendor/bin/phpunit \
--colors=always \
--bootstrap tests/ext-bootstrap.php \
--testsuite Extension

Expand Down
10 changes: 4 additions & 6 deletions .ci/win-ci-tools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ function InstallZephirParser {
Download and install Zephir parser PHP extension
#>

$BaseUri = "https://github.com/phalcon/php-zephir-parser/releases/download"
$LocalPart = "zephir_parser_${env:PHP_ARCH}_vc${env:VC_VERSION}_php${env:PHP_MINOR}"
$BaseUri = "https://github.com/zephir-lang/php-zephir-parser/releases/download"
$LocalPart = "zephir-parser-php-${env:PHP_MINOR}-${env:BUILD_TYPE}-win32-vc${env:VC_VERSION}-${env:PHP_ARCH}.zip"

$TS = Get-ThreadSafety

$RemoteUrl = "${BaseUri}/v${env:PARSER_VERSION}/${LocalPart}${TS}_${env:PARSER_VERSION}-${env:PARSER_RELEASE}.zip"
$DestinationPath = "C:\Downloads\${LocalPart}${TS}_${env:PARSER_VERSION}-${env:PARSER_RELEASE}.zip"
$RemoteUrl = "${BaseUri}/v${env:PARSER_VERSION}/${LocalPart}"
$DestinationPath = "C:\Downloads\${LocalPart}"

if (-not (Test-Path "${env:PHPROOT}\ext\php_zephir_parser.dll")) {
if (-not [System.IO.File]::Exists($DestinationPath)) {
Expand Down
22 changes: 5 additions & 17 deletions .github/workflows/build-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- development

env:
ZEPHIR_PARSER_VERSION: v1.3.6
ZEPHIR_PARSER_VERSION: 1.4.1

jobs:
linux:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: gmp, pdo_sqlite, psr, zip
extensions: gmp, pdo_sqlite, psr, zip, zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}
tools: phpize, php-config
coverage: xdebug
# variables_order: https://github.com/zephir-lang/zephir/pull/1537
Expand All @@ -62,6 +62,8 @@ jobs:
memory_limit=1G,
date.timezone=UTC,
xdebug.max_nesting_level=256
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout Code
uses: actions/checkout@v2
Expand Down Expand Up @@ -98,20 +100,6 @@ jobs:
sudo apt-get update --quiet --yes 1>/dev/null
sudo apt-get install --no-install-recommends -q -y re2c
- name: Get Zephir Parser Cache Key
id: pcache
run: echo ::set-output name=key::$(echo -n ${ZEPHIR_PARSER_VERSION}_${CPUHASH})

- name: Cache Zephir Parser
uses: actions/cache@v1
with:
path: ~/php-zephir-parser
key: ${{ runner.os }}-${{ matrix.php }}-zephir-parser-${{ steps.pcache.outputs.key }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-zephir-parser-

- name: Install Zephir Parser
run: .ci/install-zephir-parser.sh

- name: Get Composer Cache Directory
id: composer-cache
run: echo ::set-output name=dir::$(composer config cache-files-dir)
Expand All @@ -125,7 +113,7 @@ jobs:
${{ runner.os }}-composer-
- name: Install Project Dependencies for PHP
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress --no-suggest
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress

- name: Prepare Zephir Executable
run: sudo ln -s "$(pwd)/zephir" /usr/local/bin/zephir
Expand Down
17 changes: 5 additions & 12 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- development

env:
PARSER_VERSION: 1.3.6
PARSER_VERSION: 1.4.1
PARSER_RELEASE: 559
PHP_SDK_VERSION: 2.2.0
PHP_DEVPACK: C:\tools\php-devpack
Expand Down Expand Up @@ -67,6 +67,7 @@ jobs:
xdebug.max_nesting_level=256
env:
PHPTS: ${{ matrix.build_type }}
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set Environment Variables
run: |
Expand Down Expand Up @@ -119,10 +120,10 @@ jobs:
InstallZephirParser
- name: Enable Zephir Parser
run: Enable-PhpExtension -Extension 'Zephir Parser' -Path "${env:PHPROOT}"
run: Enable-PhpExtension -Extension zephir_parser -Path "${env:PHPROOT}"

- name: Minimal Zephir Parser Load Test
run: php --ri 'Zephir Parser'
run: php --ri zephir_parser

- name: "Setup Visual Studio Command Line for PHP SDK ${{ matrix.arch }}"
run: .ci\vsenv.bat -arch=${{ matrix.arch }} -host_arch=${{ matrix.arch }}
Expand All @@ -148,16 +149,8 @@ jobs:
restore-keys: |
${{ runner.os }}-composer-
- name: Setup GitHub Token
shell: bash
run: |
# To increase the GitHub rate limit we're use GitHub authentication
if [ ! -z '${{ secrets.COMPOSER_TOKEN }}' ]; then
composer config github-oauth.github.com ${{ secrets.COMPOSER_TOKEN }}
fi
- name: Install Project Dependencies
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress --no-suggest
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress

- name: Initialize Release Variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
${{ runner.os }}-composer-
- name: Install Project Dependencies
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress --no-suggest
run: composer install --prefer-dist --no-interaction --no-ansi --no-progress

- name: Install Box
run: |
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org).

## [Unreleased]

## [0.14.0] - 2021-09-18
### Added
- Added support for `require_once` [#2253](https://github.com/zephir-lang/zephir/issues/2253)

### Changed
- Bumped minimal version of Zephir Parser to `1.4.1`. [#2284](https://github.com/zephir-lang/zephir/issues/2284)

## [0.14.0-beta.3] - 2021-08-06
### Fixed
- Fixed class entry generation of external class [#2261](https://github.com/zephir-lang/zephir/issues/2261)
Expand Down Expand Up @@ -534,7 +541,8 @@ and this project adheres to [Semantic Versioning](http://semver.org).
[#1524](https://github.com/zephir-lang/zephir/issues/1524)


[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.3...HEAD
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.14.0...HEAD
[0.14.0]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.3...0.14.0
[0.14.0-beta.3]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.2...0.14.0-beta.3
[0.14.0-beta.2]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.1...0.14.0-beta.2
[0.14.0-beta.1]: https://github.com/zephir-lang/zephir/compare/0.13.5...0.14.0-beta.1
Expand Down
2 changes: 2 additions & 0 deletions Library/Detectors/WriteDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public function passExpression(array $expression)
case 'empty':
case 'instanceof':
case 'require':
case 'require_once':
case 'clone':
case 'likely':
case 'unlikely':
Expand Down Expand Up @@ -432,6 +433,7 @@ public function passStatementBlock(array $statements)
case 'scall':
case 'fcall':
case 'require':
case 'require_once':
$this->passCall($statement['expr']);
break;

Expand Down
8 changes: 5 additions & 3 deletions Library/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
use Zephir\Operators\Other\NewInstanceTypeOperator;
use Zephir\Operators\Other\RangeExclusiveOperator;
use Zephir\Operators\Other\RangeInclusiveOperator;
use Zephir\Operators\Other\RequireOnceOperator;
use Zephir\Operators\Other\RequireOperator;
use Zephir\Operators\Other\ShortTernaryOperator;
use Zephir\Operators\Other\TernaryOperator;
Expand Down Expand Up @@ -575,6 +576,10 @@ public function compile(CompilationContext $compilationContext): CompiledExpress
$compilableExpression = new RequireOperator();
break;

case 'require_once':
$compilableExpression = new RequireOnceOperator();
break;

case 'closure':
$compilableExpression = new Closure();
break;
Expand All @@ -591,9 +596,6 @@ public function compile(CompilationContext $compilationContext): CompiledExpress
throw new CompilerException('Unknown expression: '.$type, $expression);
}

if (!$compilableExpression) {
throw new CompilerException('Unknown expression passed as compilableExpression', $expression);
}
$compilableExpression->setReadOnly($this->isReadOnly());
$compilableExpression->setExpectReturn($this->expecting, $this->expectingVariable);

Expand Down
3 changes: 3 additions & 0 deletions Library/Expression/Builder/Operators/UnaryOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class UnaryOperator extends AbstractOperator
// y = require a
const OPERATOR_REQUIRE = 'require';

// y = require_once a
const OPERATOR_REQUIRE_ONCE = 'require_once';

// y = clone a
const OPERATOR_CLONE = 'clone';

Expand Down
86 changes: 86 additions & 0 deletions Library/Operators/Other/RequireOnceOperator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* This file is part of the Zephir.
*
* (c) Phalcon Team <team@zephir-lang.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir\Operators\Other;

use Zephir\CompilationContext;
use Zephir\CompiledExpression;
use Zephir\Exception;
use Zephir\Expression;
use Zephir\Operators\BaseOperator;

/**
* Require once.
*
* Includes once a plain PHP file
*/
class RequireOnceOperator extends BaseOperator
{
/**
* @param array $expression
* @param CompilationContext $compilationContext
*
* @return CompiledExpression
* @throws Exception
*/
public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression
{
$expr = new Expression($expression['left']);
$expr->setReadOnly(true);
$expr->setExpectReturn(true);

$exprPath = $expr->compile($compilationContext);
if ('variable' === $exprPath->getType()) {
$exprVariable = $compilationContext->symbolTable->getVariableForRead($exprPath->getCode(), $compilationContext, $expression);
$exprVar = $compilationContext->backend->getVariableCode($exprVariable);
if ('variable' === $exprVariable->getType()) {
if ($exprVariable->hasDifferentDynamicType(['undefined', 'string'])) {
$compilationContext->logger->warning(
'Possible attempt to use invalid type as path in "require_once" operator',
['non-valid-require-once', $expression]
);
}
}
} else {
$exprVar = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
$compilationContext->backend->assignString($exprVar, $exprPath->getCode(), $compilationContext);
$exprVar = $compilationContext->backend->getVariableCode($exprVar);
}

$symbolVariable = false;
if ($this->isExpecting()) {
$symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext);
}

$compilationContext->headersManager->add('kernel/memory');
$compilationContext->headersManager->add('kernel/require');

$codePrinter = $compilationContext->codePrinter;

if ($symbolVariable) {
$codePrinter->output('ZEPHIR_OBSERVE_OR_NULLIFY_PPZV(&'.$symbolVariable->getName().');');
$symbol = $compilationContext->backend->getVariableCodePointer($symbolVariable);
$codePrinter->output('if (zephir_require_once_zval_ret('.$symbol.', '.$exprVar.') == FAILURE) {');
} else {
$codePrinter->output('if (zephir_require_once_zval('.$exprVar.') == FAILURE) {');
}
$codePrinter->output("\t".'RETURN_MM_NULL();');
$codePrinter->output('}');

if ($symbolVariable) {
return new CompiledExpression('variable', $symbolVariable->getName(), $expression);
}

return new CompiledExpression('null', null, $expression);
}
}
Loading

0 comments on commit a7d7a61

Please sign in to comment.