Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Finish string support, also fix a few issues with void functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ircmaxell committed Oct 1, 2014
1 parent 9d2dae7 commit e5fed55
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/ReckiCT/Compiler/PECL/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function generateCFile($moduleName, array $funcs) {

foreach ($funcs as $func) {
$code .= "PHP_FUNCTION({$func->name});\n";
$code .= 'static ' . $this->generateInternalFuncSignature($func) . ";\n";
}

foreach ($funcs as $func) {
Expand Down Expand Up @@ -250,6 +251,7 @@ protected function buildFunction(array $func, $obj) {
$prefix = '';
switch ($func[$i][0]) {
case 'var':
if ($func[$i][2] === 'void') break;
$scope[$func[$i][1]] = $this->convertToCLabel($func[$i][1]);
$vars[$scope[$func[$i][1]]] = $this->convertToCType($func[$i][2]);

Expand Down Expand Up @@ -294,7 +296,10 @@ protected function buildFunction(array $func, $obj) {
$code .= $scope[$func[$i][count($func[$i]) - 1]] . ' = ' . $scope[$func[$i][2]] . '.length;';
break;
}
$code .= $scope[$func[$i][count($func[$i]) - 1]] . ' = recki_if_' . strtolower($func[$i][1]) . '(';
if (isset($scope[$func[$i][count($func[$i]) - 1]])) {
$code .= $scope[$func[$i][count($func[$i]) - 1]] . ' = ';
}
$code .= 'recki_if_' . strtolower($func[$i][1]) . '(';
for ($j = 2; $j < count($func[$i]) - 1; $j++) {
$code .= $scope[$func[$i][$j]] . ', ';
}
Expand Down Expand Up @@ -364,7 +369,7 @@ protected function printConstant(array $const) {
return (int) $const[3];
case 'string':
$val = base64_decode($const[3]);
return '{"' . addslashes($val) . '", ' . strlen($val) . '}';
return '((reckistring){"' . addslashes($val) . '", ' . strlen($val) . '})';
}
throw new \RuntimeException("Unknown constant type {$const[2]} with value {$const[3]}");
}
Expand Down

0 comments on commit e5fed55

Please sign in to comment.