예제 #1
0
 public function setProperty($name, Zval $value)
 {
     if (isset($this->properties[$name])) {
         $this->properties[$name]->assignZval($value->getZval());
     } else {
         $this->properties[$name] = Zval::ptrFactory($value->getZval());
     }
 }
예제 #2
0
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $key = $this->op2->getValue();
     if ($this->op1->isArray()) {
         $array =& $this->op1->getArray();
         if (!isset($array[$key])) {
             if ($this->write) {
                 $array[$key] = Zval::ptrFactory();
                 $this->result->setValue($array[$key]);
             } else {
                 $this->result->setValue(Zval::ptrFactory());
             }
         } else {
             $this->result->setValue($array[$key]);
         }
     } elseif ($this->op1->isString()) {
         $value = $this->op1->getValue();
         if (isset($value[$key])) {
             $this->result->setValue($value[$key]);
         } else {
             $this->result->setValue('');
         }
     } elseif ($this->write && $this->op1->isNull()) {
         $value = Zval::ptrFactory();
         $this->op1->setValue(array($key => $value));
         $this->result->setValue($value);
     } else {
         throw new \RuntimeException('Cannot use a scalar value as an array');
     }
     if ($this->write) {
         $this->result->getZval()->makeRef();
     }
     $data->nextOp();
 }
예제 #3
0
 protected function registerCoreConstants(ConstantStore $constants)
 {
     $coreConstants = array('null' => null, 'true' => true, 'false' => false);
     foreach ($coreConstants as $name => $value) {
         $constants->register($name, Zval::factory($value), false);
     }
 }
예제 #4
0
파일: Buffer.php 프로젝트: asgrim/PHPPHP
 protected function callCallback($data, $mode)
 {
     if ($this->callback) {
         $this->buffer = '';
         $current = $this->executor->getOutput();
         $ro = new ReadOnly($this->executor);
         $this->executor->setOutput($ro);
         try {
             $ret = Zval::ptrFactory();
             $args = array(Zval::ptrFactory($data), Zval::ptrFactory($mode));
             $cb = $this->callback;
             $cb($this->executor, $args, $ret);
         } catch (\PHPPHP\Engine\ErrorOccurredException $e) {
             // Restore error handler first!
             $this->executor->setOutput($current);
             throw $e;
         }
         $this->executor->setOutput($current);
         if ($ret->isBool() || $ret->toBool() == false) {
             return $data;
         } else {
             return $ret->toString();
         }
     }
     return $data;
 }
예제 #5
0
파일: AssignDim.php 프로젝트: asgrim/PHPPHP
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $this->op1->separateIfNotRef();
     if (!$this->op1->isArray()) {
         if ($this->op1->isNull()) {
             $this->op1->setValue(array());
         } else {
             throw new \RuntimeException('Cannot use a scalar value as an array');
         }
     }
     $array =& $this->op1->getArray();
     if ($this->dim) {
         $key = $this->dim->toString();
         if (isset($array[$key])) {
             $array[$key]->forceValue($this->op2->getZval());
         } else {
             $array[$key] = Zval::ptrFactory($this->op2->getZval());
         }
     } else {
         $array[] = Zval::ptrFactory($this->op2->getZval());
     }
     if ($this->result) {
         $this->result->setValue($this->op2->getZval());
     }
     $data->nextOp();
 }
예제 #6
0
파일: Variable.php 프로젝트: asgrim/PHPPHP
 protected function fetch()
 {
     $varName = $this->name->toString();
     if ($this->class) {
         if ($this->class->isString()) {
             $ci = $this->executor->getClassStore()->get($this->class->getValue());
         } else {
             if ($this->class->isObject()) {
                 $ci = $this->class->getValue()->getClassEntry();
             } else {
                 throw new \RuntimeException('Class name must be a valid object or a string');
             }
         }
         $this->zval = $ci->fetchStaticVariable($varName);
     } else {
         if (self::SCOPE_GLOBAL === $this->scope) {
             $symbolTable = $this->executor->executorGlobals->symbolTable;
             if (!isset($symbolTable[$varName])) {
                 $this->zval = Zval::ptrFactory();
             } else {
                 $this->zval = $symbolTable[$varName];
             }
         } else {
             if ($varName == 'this') {
                 $this->zval = Zval::lockedPtrFactory($this->executor->getCurrent()->ci);
             } else {
                 $this->zval = $this->executor->getCurrent()->fetchVariable($varName);
             }
         }
     }
 }
예제 #7
0
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $varName = $this->op1->toString();
     if (!isset($data->executor->executorGlobals->symbolTable[$varName])) {
         $data->executor->executorGlobals->symbolTable[$varName] = Zval::ptrFactory();
     }
     $data->symbolTable[$varName] = $data->executor->executorGlobals->symbolTable[$varName];
     $data->nextOp();
 }
예제 #8
0
파일: RecvInit.php 프로젝트: asgrim/PHPPHP
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $args =& $data->arguments;
     $n = $this->op1->toLong();
     if (!isset($args[$n])) {
         $args[$n] = Zval::ptrFactory($this->op2->getZval());
     }
     parent::execute($data);
 }
예제 #9
0
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $name = $this->op1->toString();
     $functionData = $this->op2;
     $ce = $data->executor->getClassStore()->get('Closure');
     $ci = $ce->instantiate($data, array('functionData' => Zval::ptrFactory($functionData)));
     if ($this->result) {
         $this->result->setValue($ci);
     }
     $data->nextOp();
 }
예제 #10
0
 public function compileReturn($value)
 {
     if (is_array($value)) {
         $result = array();
         foreach ($value as $key => $item) {
             $result[$key] = $this->compileReturn($item);
         }
         return Engine\Zval::factory($result);
     } else {
         return Engine\Zval::factory($value);
     }
 }
예제 #11
0
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $key = $this->op1->toString();
     $array = $this->result->toArray();
     $var = Zval::ptrFactory($this->op2->getZval())->separateIfRef();
     if ($key) {
         $array[$key] = $var;
     } else {
         $array[] = $var;
     }
     $this->result->setValue($array);
     $data->nextOp();
 }
예제 #12
0
파일: Extension.php 프로젝트: asgrim/PHPPHP
 protected function registerConstants(\PHPPHP\Engine\Executor $executor)
 {
     $store = $executor->getConstantStore();
     foreach (get_defined_constants(true) as $group => $set) {
         if ($group == 'user') {
             continue;
         }
         foreach ($set as $name => $value) {
             if (!$store->exists($name)) {
                 $store->register($name, Zval::factory($value));
             }
         }
     }
 }
예제 #13
0
파일: Base.php 프로젝트: asgrim/PHPPHP
 public function register(\PHPPHP\Engine\Executor $executor)
 {
     $functionStore = $executor->getFunctionStore();
     foreach ($this->getFunctions() as $name => $functionData) {
         $functionStore->register($name, $functionData);
     }
     $constantStore = $executor->getConstantStore();
     foreach ($this->getConstants() as $name => $value) {
         $constantStore->register($name, Engine\Zval::factory($value));
     }
     $classStore = $executor->getClassStore();
     foreach ($this->getClasses() as $ce) {
         $classStore->register($ce);
     }
 }
예제 #14
0
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $functionCall = $data->executor->executorGlobals->call;
     $args = array();
     $stack = $data->executor->getStack();
     for ($i = $stack->count() - 1; $i >= 0; $i--) {
         $args[] = $stack->pop();
     }
     $args = array_reverse($args);
     if (!$this->result) {
         $this->result = Zval::ptrFactory();
     }
     $functionCall->execute($args, $this->result);
     $data->executor->executorGlobals->call = null;
     $data->nextOp();
 }
예제 #15
0
파일: NewOp.php 프로젝트: asgrim/PHPPHP
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     self::$instanceNumber++;
     $className = $this->op1->toString();
     $classEntry = $data->executor->getClassStore()->get($className);
     $instance = $classEntry->instantiate($data, array());
     $instance->setInstanceNumber(self::$instanceNumber);
     $constructor = $classEntry->getConstructor();
     if ($constructor) {
         $data->executor->executorGlobals->call = new Engine\FunctionCall($data->executor, $constructor, $instance);
     }
     $this->result->setValue(Zval::factory($instance));
     if (!$constructor) {
         $data->jump($this->noConstructorJumpOffset);
     } else {
         $data->nextOp();
     }
 }
예제 #16
0
파일: Send.php 프로젝트: asgrim/PHPPHP
 public function execute(\PHPPHP\Engine\ExecuteData $data)
 {
     $ptr = null;
     if ($data->executor->executorGlobals->call->getFunction()->isArgByRef($this->op2->getValue())) {
         if ($this->op1->isVariable() || $this->op1->isRef() || $this->op1->isObject()) {
             $op = $this->op1->getPtr();
             $op->makeRef();
             $op->addRef();
             $ptr = Zval::ptrFactory($op->getZval());
         } else {
             throw new \RuntimeException("Can't pass parameter {" . $this->op2->getValue() . "} by reference");
         }
     } else {
         $ptr = Zval::ptrFactory($this->op1->getValue());
     }
     $data->executor->getStack()->push($ptr);
     $data->nextOp();
 }
예제 #17
0
 protected function setValue($value)
 {
     $zval = Zval::factory($value);
     if ($this->property) {
         $this->op1->getValue()->setProperty($this->property->toString(), $zval);
     } else {
         if ($this->dim) {
             $array =& $this->op1->getArray();
             $key = $this->dim->toString();
             if (isset($array[$key])) {
                 $array[$key]->setValue($zval);
             } else {
                 $array[$key] = Zval::ptrFactory($zval);
             }
         } else {
             $this->op1->setValue($zval);
         }
     }
     if ($this->result) {
         $this->result->setValue($zval);
     }
 }
예제 #18
0
파일: Base.php 프로젝트: asgrim/PHPPHP
 protected function checkParams(\PHPPHP\Engine\Executor $executor, array &$args, $checkTooMany = false)
 {
     $argNo = 0;
     $required = 0;
     $hasOptional = false;
     $has = count($args);
     $varargs = false;
     while ($param = $this->getParam($argNo)) {
         if ($param->type) {
             $error = "";
             if ($param->type == 'array') {
                 if (!isset($args[$argNo]) && !$param->isOptional) {
                     $error = "array";
                 } elseif (!isset($args[$argNo])) {
                     // Blank intentional
                 } elseif (!$args[$argNo]->isArray() && !($args[$argNo]->isNull() && $param->isOptional)) {
                     $error = "array";
                 }
             } elseif ($param->type == 'callable') {
                 //bypass the callable check for now...
             } else {
                 if (!isset($args[$argNo]) && !$param->isOptional) {
                     $error = "instance of {$param->type}";
                 } elseif (!isset($args[$argNo])) {
                     // Blank intentional
                 } elseif (!$args[$argNo]->isObject() && !($args[$argNo]->isNull() && $param->isOptional)) {
                     $error = "instance of {$param->type}";
                 } elseif (!$args[$argNo]->isObject()) {
                     // Blank intentional
                 } elseif (!$args[$argNo]->getValue()->getClassEntry()->isInstanceOf($param->type)) {
                     $error = "instance of {$param->type}";
                 }
             }
             if ($error) {
                 $type = "none";
                 if (isset($args[$argNo])) {
                     $type = $args[$argNo]->getType();
                     if ($type == 'object') {
                         $type = 'instance of ' . $args[$argNo]->getValue()->getClassEntry()->getName();
                     }
                 }
                 $extra = '';
                 if ($this->getFileName()) {
                     $extra = ' and defined in ' . $this->getFileName() . ' on line ' . $param->lineno;
                 }
                 $message = "Argument " . ($argNo + 1) . " passed to {$this->name}() must be an {$error}, {$type} given, called";
                 $executor->raiseError(E_RECOVERABLE_ERROR, $message, $extra, false);
             }
         }
         if (!$param->isOptional) {
             $required++;
             if (!isset($args[$argNo])) {
                 $args[$argNo] = Engine\Zval::ptrFactory();
             }
         } else {
             $hasOptional = true;
         }
         if ($param->name == '...') {
             $varargs = true;
         }
         $argNo++;
     }
     if ($required > $has) {
         $message = $this->name;
         $message .= "() expects ";
         $message .= $hasOptional ? "at least" : "exactly";
         $message .= " {$required} " . ($required == 1 ? "parameter" : "parameters");
         $message .= ", {$has} given";
         $executor->raiseError(E_WARNING, $message, '', false);
         return false;
     } elseif ($checkTooMany && !$varargs && $has > $argNo) {
         $message = $this->name;
         $message .= "() expects ";
         $message .= $hasOptional ? "at most" : "exactly";
         $message .= " {$argNo} " . ($argNo == 1 ? "parameter" : "parameters");
         $message .= ", {$has} given";
         $executor->raiseError(E_WARNING, $message, '', false);
         return false;
     }
     return true;
 }
예제 #19
0
파일: Compiler.php 프로젝트: asgrim/PHPPHP
 protected function makeZvalFromNode(\PHPParser_Node $node)
 {
     if ($node instanceof \PHPParser_Node_Scalar_LNumber || $node instanceof \PHPParser_Node_Scalar_DNumber || $node instanceof \PHPParser_Node_Scalar_String) {
         return Zval::factory($node->value);
     } elseif ($node instanceof \PHPParser_Node_Expr_Array) {
         $array = array();
         foreach ($node->items as $item) {
             if ($item->byRef) {
                 return null;
             }
             $array[$this->makeZvalFromNode($item->key)] = $this->makeZvalFromNode($item->value);
         }
         return $array;
     } elseif ($node instanceof \PHPParser_Node_Scalar_FileConst) {
         /* TODO */
         return null;
     } else {
         return null;
     }
 }
예제 #20
0
 public function callMethod(ExecuteData $data, ClassInstance $ci = null, $name = '', array $args = array(), Ptr $result = null)
 {
     $method = $this->findMethod($name);
     if (!$result) {
         $result = Zval::ptrFactory();
     }
     $method->execute($data->executor, $args, $result, $ci);
 }
예제 #21
0
파일: Value.php 프로젝트: asgrim/PHPPHP
 public function isIdenticalTo(Zval $other)
 {
     $type = $this->getType();
     $otherType = $other->getType();
     if ('array' === $type && 'array' === $otherType) {
         return 0 === $this->compareArrays($this->getValue(), $other->getValue(), function ($a, $b) {
             return $a->isIdenticalTo($b);
         }, true);
     } elseif ($type == $otherType) {
         return $this->getValue() === $other->getValue();
     }
     return false;
 }