lua 1.0 源码分析 -- 1 lua 的虚拟指令
lua的解释器拿到 lua 编写的源码,首先进行解析,就是进行词法分析和语法分析,将源码转换成 lua 的指令集,然后执行这个指令集。
lua 源码:
function f(val)
return val;
end function main()
local i = 1;
local j = 2;
local b = i + f(2);
--local b = i + j; print("retval = "..b); return b;
end
调用 main 的指令集分析:
in while opcode = [CALLFUNC]. -- main
in while opcode = [NOP].
in while opcode = [SETFUNCTION].
in while opcode = [ADJUST].
in while opcode = [NOP].
in while opcode = [SETLINE].
in while opcode = [PUSH1]. -- i
in while opcode = [SETLINE].
in while opcode = [PUSH2]. -- j
in while opcode = [SETLINE]. -- local b = i + f(2)
in while opcode = [PUSHLOCAL0]. -- i
in while opcode = [PUSHGLOBAL]. -- f
in while opcode = [PUSHMARK].
in while opcode = [PUSH2]. -- val
in while opcode = [CALLFUNC]. -- f()
in while opcode = [NOP].
in while opcode = [SETFUNCTION].
in while opcode = [ADJUST].
in while opcode = [NOP].
in while opcode = [SETLINE].
in while opcode = [PUSHLOCAL0]. -- val
in while opcode = [RESET].
in while opcode = [RETCODE].
in while opcode = [SETLINE].
in while opcode = [ADJUST].
in while opcode = [ADDOP]. -- local b = i + f(2)
in while opcode = [SETLINE].
in while opcode = [NOP].
in while opcode = [PUSHGLOBAL]. -- print
in while opcode = [PUSHMARK].
in while opcode = [PUSHSTRING]. -- retval =
in while opcode = [PUSHLOCAL2]. -- b
in while opcode = [CONCOP].
in while opcode = [CALLFUNC]. -- print()
retval = 3
in while opcode = [ADJUST].
in while opcode = [SETLINE].
in while opcode = [PUSHLOCAL2].
in while opcode = [RESET].
in while opcode = [RETCODE].
in while opcode = [HALT].
PS:
函数就是一个入口地址,入口是通向将要执行的指令集。想下 汇编 中的 call,ret。lua 中的虚拟指令类似,只不过入口中的指令集是 lua 自己的虚拟指令,不是像 c 那样的机器指令。
lua 1.0 源码分析 -- 1 lua 的虚拟指令的更多相关文章
- lua 1.0 源码分析 -- 总结
读完 lua1.0 的源码感触:1. 把复杂的代码写简单2. pack 的内存回收3. hash 实现简单,但是应该可以改进,看高版本的代码怎么实现4. lua 初始化环境做了什么,就是一组全局变量初 ...
- lua 1.0 源码分析 -- 2 内存回收
说这个,先要说下 lua 的环境,正常说创建一个 lua 的虚拟环境,就是创建一组全局变量, lua1.0 里创建的主要是以下几个: extern Symbol *lua_table; /* 符号数组 ...
- AFNetWorking3.0源码分析
分析: AFNetWorking(3.0)源码分析(一)——基本框架 AFNetworking源码解析 AFNetworking2.0源码解析<一> end
- Solr5.0源码分析-SolrDispatchFilter
年初,公司开发法律行业的搜索引擎.当时,我作为整个系统的核心成员,选择solr,并在solr根据我们的要求做了相应的二次开发.但是,对solr的还没有进行认真仔细的研究.最近,事情比较清闲,翻翻sol ...
- Solr4.8.0源码分析(25)之SolrCloud的Split流程
Solr4.8.0源码分析(25)之SolrCloud的Split流程(一) 题记:昨天有位网友问我SolrCloud的split的机制是如何的,这个还真不知道,所以今天抽空去看了Split的原理,大 ...
- Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五)
Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五) 题记:关于SolrCloud的Recovery策略已经写了四篇了,这篇应该是系统介绍Recovery策略的最后一篇了 ...
- Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四)
Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四) 题记:本来计划的SolrCloud的Recovery策略的文章是3篇的,但是没想到Recovery的内容蛮多的,前面 ...
- Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三)
Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三) 本文是SolrCloud的Recovery策略系列的第三篇文章,前面两篇主要介绍了Recovery的总体流程,以及P ...
- Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二)
Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二) 题记: 前文<Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一)>中提 ...
随机推荐
- Mysql业务设计(物理设计)
物理设计 根据所选择的关系型数据库的特点对逻辑模型进行存储结构的设计 物理设计: 定义数据库.表及字段的命名规范 选择合适的存储引擎 为表中的字段选择合适的数据类型 建立数据库结构 定义数据库.表及字 ...
- javascript面试题(二)
24. function foo() { } var oldName = foo.name; foo.name = "bar"; [oldName, foo.name] // [f ...
- Docker启动失败
报错信息: Job for docker.service failed because the control process exited with error code. See "sy ...
- 20190919-02安装Xshell和CRT远程工具 000 008
Linux远程登录及相关工具介绍 Linux一般作为服务器使用,而服务器一般放在机房,你不可能在机房操作你的Linux服务器.这时我们就需要远程登录到Linux服务器来管理维护系统. Linux系统中 ...
- Prmise.all的简单实现
注意点 入参一般是个由Promise实例组成的数组,但是也可以不是数组,但必须具有 Iterator 接口,且返回的每个成员都是 Promise 实例.若参数如果不是 Promise 实例,就会先调用 ...
- tcp、http 学习小结
tcp.http 学习小结 前言 最近因为cdn的一个问题,困扰了自己好久.因为需要统计网站访问的成功数,而且要求比较精确.目前的实现不能满足要求,因为没有区别访问成功与否,也没有对超时做处理.期间解 ...
- [Leetcode]Sql系列3
题目1 产品数据表: Products +---------------+---------+ | Column Name | Type | +---------------+---------+ | ...
- MySQL的事务机制和锁(InnoDB引擎、MVCC多版本并发控制技术)
一.事务(数据库的事务都通用的定义) 1.1 事务定义 事务是由一步或几步数据库操作序列组成逻辑执行单元,这系列操作要么全部执行,要么全部放弃执行.事务通常以 BEGIN TRANSACTION 开始 ...
- Linux磁盘管理及LVM讲解(1)
硬盘接口 从整体的角度上,硬盘接口分为IDE.SATA.SCSI和SAS四种,IDE接口硬盘多用于家用产品中,也部分应用于服务器,SCSI接口的硬盘则主要应用于服务器市场,而SAS只在高端服务器上,价 ...
- nginx异步访问mysql
nginx中有一个模块有这个功能,(以前的文章中扩展,这里叫模块,以后统一叫模块,模块可能准确点,因为扩展是单独的文件,而模块是嵌入到主文件中的),这个模块叫drizzle-nginx-module, ...