facebook hiphop php vm 兑现概述(二)
facebook hiphop php vm 实现概述(二)
从上文可知,核心的runtime环境的代码在 src/runtme/eval,本文主要简单概述此处的代码实现,下面的叙述按文件夹分类。
一、runtime:运行时的核心数据结构(符号表)
1、assoc_list.cpp 变量关联表
2、code_coverage.cpp 代码覆盖率工具
3、file_repository.cpp php文件的jit缓存
4、variable_environment.cpp 维护各个函数、变量等所属的环境(如所属的类、作用范围等)
5、variant_stack.cpp 变量栈结构(可以用于记录函数调用关系)
6、eval_state.cpp 最重要的runtime信息都收集在这里面,比如当前有哪objects、每个object有哪些method、全局函数、常量……
7、eval_object_data.h 记录一个class的信息
8、eval_frame_injection.h 函数调用中的一个栈帧
二、ext
此目录封装了往runtime中添加外部函数的方法,
三、parser
解析器,利用YACC实现的parser(EBNF语法文件是hphp.y, hphp.tab.cpp是工具生成的),此parser与compiler目录中的不同,此处主要是为语义解析服务的(可以理解TreeWalker)。对于hiphop php vm来说,语义处理就是想办法将php代码映射为c++代码(需要runtime提供大量的外部函数)。
1、hphp.y概述
文法开始符号:start
文件包含关系、语句添加等的处理在src/runtime/eval/parser/parser.cpp中, 就onXXX()此树遍历器的输出是一个AST,顶层节点是statement
四、debugger 利用socket实现的调试器
最后真正开始处理的是 void DebuggerProxy::processInterrupt(CmdInterrupt &cmd)
五、base
基本数据结构声明
六、ast
针对 parser解析出的AST进行语义处理(即具体的对每一层树节点 将php代码转为c++代码)
每个statement的统一接口是
virtual Statement *optimize(VariableEnvironment &env) { return NULL; } // 优化语句
virtual void eval(VariableEnvironment &env) const = 0; // 处理语句关系
virtual void byteCode(ByteCodeProgram &code) const; //
dump(std::ostream &out) const = 0; // 输出c++的代码
PS:
Eval::Construct 发展出的继承结构写的很漂亮
七、analysis 分析作用域
八、runtime 语义处理即翻译php到c++的主流程
eval.cpp Variant eval(LVariableTable *vars, CObjRef self, CStrRef code_str,bool prepend_php /* = true */)
1、php源代码预处理
2、ParseString() 树遍历
3、s->eval(env); 语义分析(递归往下走)
九、函数调用的实现
函数调用基本思路:根据符号表信息,找到object、method、variable等执行环境信息、每次进入一个函数时建立一个thread的栈帧,将php函数调用转化为外部函数的执行逻辑

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
