Home  >  Article  >  Backend Development  >  Does php have a virtual machine?

Does php have a virtual machine?

(*-*)浩
(*-*)浩Original
2019-10-15 14:45:223549browse

Does php have a virtual machine?

PHP Virtual Machine

Virtual machines are also computers. Referring to the design of a physical machine, when designing a virtual machine, you should first consider three elements: Instructions, data storage, function stack frames;

Instructions (Recommended learning: PHP video tutorial)

Instructions are composed of opcodes and operands ;The opcode specifies the operation type of this instruction, and the operand specifies the operand itself or the address of the operand;

Data storage

PHP virtual machine supports multiple data types : Integer, floating point, string, array, object, etc.;

Function stack frame

PHP virtual machine implements a function stack frame similar to that of a physical machine Structure;

Use _zend_vm_stack to represent the stack structure; use the prev field between multiple stacks to form a one-way linked list; top and end point to the low and top of the stack, respectively, and are pointers of zval type;

Summary

The PHP virtual machine is also a computer. There are three points that we need to focus on: instruction set (including instruction processing functions), data storage (zval), and function stack frame ;

At this time, the virtual machine can accept instructions and execute the instruction code;

However, the PHP virtual machine is dedicated to executing PHP code. How can the PHP code be converted into a PHP virtual machine? What about the instructions that can be recognized - compilation;

The PHP virtual machine also provides a compiler, which can convert the PHP code into a set of instructions that can be recognized;

Theory You can customize any language. As long as you implement a compiler that can convert your own language into instruction codes that PHP can recognize, it can be executed by the PHP virtual machine;

The above is the detailed content of Does php have a virtual machine?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn