SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace Zephir\Optimizers\FunctionCall;
  4.  
  5. use Zephir\Call;
  6. use Zephir\CompilationContext;
  7. use Zephir\CompiledExpression;
  8. use Zephir\Compiler\CompilerException;
  9. use Zephir\Optimizers\OptimizerAbstract;
  10.  
  11. class CalculatePiOptimizer extends OptimizerAbstract
  12. {
  13.     public function optimize(array $expression, Call $call, CompilationContext $context)
  14.     {
  15.         if (!isset($expression['parameters'])) {
  16.             throw new CompilerException("'calculate_pi' requires one parameter", $expression);
  17.         }
  18.  
  19.         if (count($expression['parameters']) > 1) {
  20.             throw new CompilerException("'calculate_pi' requires one parameter", $expression);
  21.         }
  22.  
  23.         /**
  24.          * Process the expected symbol to be returned
  25.          */
  26.         $call->processExpectedReturn($context);
  27.  
  28.         $symbolVariable = $call->getSymbolVariable();
  29.         if (!$symbolVariable->isDouble()) {
  30.             throw new CompilerException("Calculated PI values only can be stored in double variables", $expression);
  31.         }
  32.  
  33.         $resolvedParams = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
  34.  
  35.         return new CompiledExpression('double', 'my_calculate_pi(' . $resolvedParams[0] . ')', $expression);
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top