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策略(一)>中提 ...
随机推荐
- Resis常用命令及数据类型
1.下载Windows环境redis安装: 2.下载jar包: commons-pool2-2.4.2.jar jedis-2.9.0.jar 3.项目结构: 4.代码说明: package com. ...
- 2020年1月31日 安装Python的BeautifulSoap库记录
C:\Users\ufo>pip install beautifulsoup4 Collecting beautifulsoup4 WARNING: Retrying (Retry(total= ...
- [oracle/sql]写SQL从学生考试成绩三表中选出五门分综合超过720的尖子
任务:有学生,科目,考分三张表,需要从中筛选出五门考分总和超过720的学生. 科目表最简单只有五条记录: CREATE TABLE tb_course ( id NUMBER not null pri ...
- Oracle Sqlplus 三项设置
显示sql执行时间:set timing on 显示sql execute plan:set autotrace trace exp 关闭 set autotrace off 设置行宽:set li ...
- python - 模块调用
基础 调用模块常见的两种方法 import [模块名] from [模块名] import [属性/方法] 进阶用法 调用父级目录下模块 背景介绍 目录new2(b2.py)调用上级目录new1(b1 ...
- PHP实现Restful风格的API(转)
Restful是一种设计风格而不是标准,比如一个接口原本是这样的: http://www1.qixoo.com/user/view/id/1表示获取id为1的用户信息,如果使用Restful风格,可以 ...
- NGINX 负载均衡的理解
前言 NGINX是轻量级,也是当前比较流行的web服务器软件.体积小但是功能强大. 这里我按照自己的理解,记录下对NGINX负载均衡的认识.(加权均衡,最小连接) 这里参考了 [https://blo ...
- [LeetCode]66. 加一(数组)
###题目 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 ...
- js中的选择排序和冒泡排序
var arr = [12,25,8,16,14]; console.log("排序前数组,",arr) //选择排序:第一轮,找出数组中最小的数,将第一项和最小的数互换位置.第二 ...
- openstack (共享服务) 消息队列rabbitmq服务
云计算openstack共享组件——消息队列rabbitmq(3) 一.MQ 全称为 Message Queue, 消息队列( MQ ) 是一种应用程序对应用程序的通信方法.应用程序通过读写出入队 ...