Skip to content

Commit

Permalink
Merge pull request #2229 from zephir-lang/development
Browse files Browse the repository at this point in the history
0.13.3
  • Loading branch information
Jeckerson authored Apr 25, 2021
2 parents c23c2ab + 8b9c914 commit f18f285
Show file tree
Hide file tree
Showing 100 changed files with 3,424 additions and 1,074 deletions.
12 changes: 12 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: [phalcon]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: ['https://opencollective.com/phalcon']
2 changes: 1 addition & 1 deletion .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, fileinfo, gmp, sqlite, pdo_sqlite, psr, zip
extensions: mbstring, fileinfo, gmp, sqlite, pdo_sqlite, psr, zip, mysqli
coverage: none
# variables_order: https://github.com/zephir-lang/zephir/pull/1537
# enable_dl: https://github.com/zephir-lang/zephir/pull/1654
Expand Down
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org).
## [Unreleased]


## [0.13.3] - 2021-04-25
### Fixed
- Fixed nullable array [#1094](https://github.com/zephir-lang/zephir/issues/1094)
- Fixed default value detection with Reflection (only PHP 8.0) [#1134](https://github.com/zephir-lang/zephir/issues/1134)
- Updated supported list of class entries for PHP date extension [#2226](https://github.com/zephir-lang/zephir/issues/2226)
- Fixed unset from class property [#1259](https://github.com/zephir-lang/zephir/issues/1259)

### Added
- Added support syntax assign-bitwise operators [#1103](https://github.com/zephir-lang/zephir/issues/1103)

## [0.13.2] - 2021-04-10
### Fixed
- Fixed default value of nullable string parameter [#2180](https://github.com/zephir-lang/zephir/issues/2180)
Expand Down Expand Up @@ -455,8 +465,9 @@ and this project adheres to [Semantic Versioning](http://semver.org).
- Fixed casting resource to int (only ZendEngine 3)
[#1524](https://github.com/zephir-lang/zephir/issues/1524)

[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.13.2...HEAD
[0.13.2]: https://github.com/zephir-lang/zephir/compare/0.13.0...0.13.2
[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.13.3...HEAD
[0.13.3]: https://github.com/zephir-lang/zephir/compare/0.13.2...0.13.3
[0.13.2]: https://github.com/zephir-lang/zephir/compare/0.13.1...0.13.2
[0.13.1]: https://github.com/zephir-lang/zephir/compare/0.13.0...0.13.1
[0.13.0]: https://github.com/zephir-lang/zephir/compare/0.12.21...0.13.0
[0.12.21]: https://github.com/zephir-lang/zephir/compare/0.12.20...0.12.21
Expand Down
63 changes: 53 additions & 10 deletions Library/ArgInfoDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ArgInfoDefinition
/**
* @var ClassMethodParameters|null
*/
private ?ClassMethodParameters $parameters = null;
private ?ClassMethodParameters $parameters;

/**
* @var CodePrinter
Expand Down Expand Up @@ -228,14 +228,38 @@ private function renderEnd(): void
switch ("{$flag}:".$parameter['data-type']) {
case '0:array':
case '1:array':
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_ARRAY_INFO(%d, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter)
)
);
if (!isset($parameter['default'])) {
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_ARRAY_INFO(%d, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter)
)
);
} else {
$this->codePrinter->output('#if PHP_VERSION_ID >= 80000');
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(%d, %s, IS_ARRAY, %d, %s)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter),
$this->defaultArrayValue($parameter),
)
);
$this->codePrinter->output('#else');
// `ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE` does not exist in PHP 7.4
$this->codePrinter->output(
sprintf(
"\tZEND_ARG_ARRAY_INFO(%d, %s, %d)",
$this->passByReference($parameter),
$parameter['name'],
(int) $this->allowNull($parameter)
)
);
$this->codePrinter->output('#endif');
}
break;
case '0:variable':
case '1:variable':
Expand Down Expand Up @@ -333,6 +357,25 @@ private function hasParameters(): bool
return null !== $this->parameters && \count($this->parameters->getParameters()) > 0;
}

private function defaultArrayValue(array $parameter): string
{
if ($parameter['default']['type'] === 'empty-array') {
return '"[]"';
}

// TODO: Come back later
/**
* It seems that it is impossible to pass default array with some data inside.
* Only empty array, even if manually specify not empty array - it will be ignored,
* for example:
*
* `ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, someDefaultData, IS_ARRAY, 0, "[\"key\" => \"value\"]")`
*
* Output of default value will be `[]` during method call.
*/
return '"[]"';
}

private function allowNull(array $parameter): bool
{
if (!isset($parameter['default']) || !\is_array($parameter['default'])) {
Expand All @@ -348,7 +391,7 @@ private function allowNull(array $parameter): bool

private function passByReference(array $parameter)
{
return isset($parameter['reference']) ? $parameter['reference'] : 0;
return $parameter['reference'] ?? 0;
}

private function getReturnType(): string
Expand Down
4 changes: 2 additions & 2 deletions Library/Backends/ZendEngine2/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,12 @@ public function arrayUnset(Variable $variable, $exprIndex, $flags, CompilationCo
break;

default:
throw new CompilerException('Variable type: '.$variableIndex->getType().' cannot be used as array index without cast', $expression['right']);
throw new CompilerException('Variable type: '.$variableIndex->getType().' cannot be used as array index without cast');
}
break;

default:
throw new CompilerException('Cannot use expression: '.$exprIndex->getType().' as array index without cast', $expression['right']);
throw new CompilerException('Cannot use expression: '.$exprIndex->getType().' as array index without cast');
}
}

Expand Down
17 changes: 9 additions & 8 deletions Library/Backends/ZendEngine3/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,6 @@ public function forStatement(Variable $exprVariable, $keyVariable, $variable, $d
$codePrinter->output('if (Z_TYPE_P('.$this->getVariableCode($exprVariable).') == IS_ARRAY) {');
$codePrinter->increaseLevel();

$macro = null;
$reverse = $statement['reverse'] ? 'REVERSE_' : '';

if (isset($keyVariable)) {
Expand Down Expand Up @@ -1074,7 +1073,7 @@ public function forStatement(Variable $exprVariable, $keyVariable, $variable, $d
$codePrinter->decreaseLevel();
}

/*
/**
* Compile statements in the 'for' block
*/
if (isset($statement['statements'])) {
Expand Down Expand Up @@ -1177,29 +1176,31 @@ public function fetchClassEntry($str)
* {@inheritdoc}
*
* @param string $type
* @param CompilationContext $context
* @param CompilationContext $compilationContext
* @param bool $isLocal
*
* @return Variable
*/
public function getScalarTempVariable(
string $type,
CompilationContext $context,
CompilationContext $compilationContext,
$isLocal = true
): Variable {
return $context->symbolTable->getTempNonTrackedVariable($type, $context);
return $compilationContext->symbolTable->getTempNonTrackedVariable($type, $compilationContext);
}

/**
* {@inheritdoc}
* Initialize array
*
* Init empty array or specific size array.
*
* @param Variable $variable
* @param CompilationContext $context
* @param int $size
* @param int|null $size
*
* @return void
*/
public function initArray(Variable $variable, CompilationContext $context, int $size = null)
public function initArray(Variable $variable, CompilationContext $context, ?int $size = null): void
{
$code = $this->getVariableCode($variable);

Expand Down
2 changes: 1 addition & 1 deletion Library/Backends/ZendEngine3/StringsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function genConcatCode()
void zephir_concat_function(zval *result, zval *op1, zval *op2)
{
zval tmp;
SEPARATE_ZVAL_IF_NOT_REF(result);
SEPARATE_ZVAL_NOREF(result);
/*
res == op1 == op2: won't leak
Expand Down
23 changes: 23 additions & 0 deletions Library/ClassDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -1912,16 +1912,39 @@ public function getClassEntryByClassName(
$classEntry = 'php_pdo_get_exception()';
break;

/**
* PHP Ext Date
*/
case 'datetimeinterface':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_interface_ce()';
break;

case 'datetime':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_date_ce()';
break;

case 'datetimeimmutable':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_immutable_ce()';
break;

case 'datetimezone':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_timezone_ce()';
break;

case 'dateinterval':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_interval_ce()';
break;

case 'dateperiod':
$compilationContext->headersManager->add('ext/date/php_date');
$classEntry = 'php_date_get_period_ce()';
break;

/**
* PHP Ext session
*/
Expand Down
1 change: 0 additions & 1 deletion Library/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,6 @@ public function assignDefaultValue(array $parameter, CompilationContext $compila
switch ($parameter['default']['type']) {
case 'null':
$compilationContext->backend->initVar($paramVariable, $compilationContext);
$compilationContext->backend->initArray($paramVariable, $compilationContext, null);
break;

case 'empty-array':
Expand Down
2 changes: 1 addition & 1 deletion Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public function generate(bool $fromGenerate = false): bool
}

krsort($rankedFiles);
foreach ($rankedFiles as $rank => $rankFiles) {
foreach ($rankedFiles as $rankFiles) {
$files = array_merge($files, $rankFiles);
}
$this->files = $files;
Expand Down
17 changes: 8 additions & 9 deletions Library/CompilerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public function compile(Compiler $compiler, StringsManager $stringsManager)
throw new CompilerException('Unable to locate the intermediate representation of the compiled file');
}

/*
/**
* External classes should not be compiled as part of the extension
*/
if ($this->external) {
Expand All @@ -804,26 +804,25 @@ public function compile(Compiler $compiler, StringsManager $stringsManager)
*/
$compilationContext = new CompilationContext();

/*
/**
* Set global compiler in the compilation context
*/
$compilationContext->compiler = $compiler;

/*
/**
* Set global config in the compilation context
*/
$compilationContext->config = $this->config;

/*
/**
* Set global logger in the compilation context
*/
$compilationContext->logger = $this->logger;

/*
/**
* Set global strings manager
*/
$compilationContext->stringsManager = $stringsManager;

$compilationContext->backend = $compiler->backend;

/**
Expand All @@ -838,7 +837,7 @@ public function compile(Compiler $compiler, StringsManager $stringsManager)
$codePrinter = new CodePrinter();
$compilationContext->codePrinter = $codePrinter;

/*
/**
* Alias manager
*/
$compilationContext->aliasManager = $this->aliasManager;
Expand Down Expand Up @@ -900,7 +899,7 @@ public function compile(Compiler $compiler, StringsManager $stringsManager)
}

if ($codePrinter) {
/*
/**
* If the file does not exists we create it for the first time
*/
if (!file_exists($filePath)) {
Expand Down Expand Up @@ -929,7 +928,7 @@ public function compile(Compiler $compiler, StringsManager $stringsManager)
}
}

/*
/**
* Add to file compiled
*/
$this->compiledFile = $path.'.c';
Expand Down
4 changes: 4 additions & 0 deletions Library/Console/Command/CleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->filesystem->isInitialized()) {
$this->filesystem->initialize();
}

$this->filesystem->clean();
$io = new SymfonyStyle($input, $output);

Expand Down
2 changes: 1 addition & 1 deletion Library/Console/Command/FullCleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$io = new SymfonyStyle($input, $output);

/*
/**
* TODO: Do we need a batch file for Windows like "clean" as used below?
* TODO: The 'clean' file contains duplicated commands
*/
Expand Down
2 changes: 0 additions & 2 deletions Library/DependencyInjection/ZephirKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Zephir\DependencyInjection;

use Exception;
use Oneup\FlysystemBundle\OneupFlysystemBundle;
use RuntimeException;
use Symfony\Bundle\MonologBundle\MonologBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
Expand Down Expand Up @@ -57,7 +56,6 @@ public function registerBundles(): array
{
return [
new MonologBundle(),
new OneupFlysystemBundle(),
];
}

Expand Down
Loading

0 comments on commit f18f285

Please sign in to comment.