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 的虚拟指令的更多相关文章

  1. lua 1.0 源码分析 -- 总结

    读完 lua1.0 的源码感触:1. 把复杂的代码写简单2. pack 的内存回收3. hash 实现简单,但是应该可以改进,看高版本的代码怎么实现4. lua 初始化环境做了什么,就是一组全局变量初 ...

  2. lua 1.0 源码分析 -- 2 内存回收

    说这个,先要说下 lua 的环境,正常说创建一个 lua 的虚拟环境,就是创建一组全局变量, lua1.0 里创建的主要是以下几个: extern Symbol *lua_table; /* 符号数组 ...

  3. AFNetWorking3.0源码分析

    分析: AFNetWorking(3.0)源码分析(一)——基本框架 AFNetworking源码解析 AFNetworking2.0源码解析<一> end

  4. Solr5.0源码分析-SolrDispatchFilter

    年初,公司开发法律行业的搜索引擎.当时,我作为整个系统的核心成员,选择solr,并在solr根据我们的要求做了相应的二次开发.但是,对solr的还没有进行认真仔细的研究.最近,事情比较清闲,翻翻sol ...

  5. Solr4.8.0源码分析(25)之SolrCloud的Split流程

    Solr4.8.0源码分析(25)之SolrCloud的Split流程(一) 题记:昨天有位网友问我SolrCloud的split的机制是如何的,这个还真不知道,所以今天抽空去看了Split的原理,大 ...

  6. Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五)

    Solr4.8.0源码分析(24)之SolrCloud的Recovery策略(五) 题记:关于SolrCloud的Recovery策略已经写了四篇了,这篇应该是系统介绍Recovery策略的最后一篇了 ...

  7. Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四)

    Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四) 题记:本来计划的SolrCloud的Recovery策略的文章是3篇的,但是没想到Recovery的内容蛮多的,前面 ...

  8. Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三)

    Solr4.8.0源码分析(22)之SolrCloud的Recovery策略(三) 本文是SolrCloud的Recovery策略系列的第三篇文章,前面两篇主要介绍了Recovery的总体流程,以及P ...

  9. Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二)

    Solr4.8.0源码分析(21)之SolrCloud的Recovery策略(二) 题记:  前文<Solr4.8.0源码分析(20)之SolrCloud的Recovery策略(一)>中提 ...

随机推荐

  1. 小程序开发-微信小程序开发入门

    分享一个微信小程序开发的基本流程,仅供参考. 第一步:注册微信小程序公众号,注册成功后,登录微信公众号管理后台,等待下一步操作. 第二步:进入微信小程序的后台后,下载微信内置的微信小程序开发者工具,以 ...

  2. [java]将多个文件压缩成一个zip文件

    此文进阶请见:https://www.cnblogs.com/xiandedanteng/p/12155957.html 方法: package zip; import java.io.Buffere ...

  3. linux 安装ifconfig

    一:使用yum命令下载安装wget 查看镜像中ifconfig安装包 yum search ifconfig yum install net-tools.x86_64 -y 下面按照提示一步步安装即可 ...

  4. TP6.0 一对一模型关联 belongsTo 相对关联(反向关联)

    1. 创建数据表 一对一反向关联使用率很高 附表关联主表称为反向关联,又称为相对关联(tp官方手册这样叫) -- 分类表 CREATE TABLE `category` ( `id` int(10) ...

  5. 在express中使用ES7装饰器构建路由

    在Java的Spring框架中,我们经常会看到类似于@Controller这样的注解,这类代码能够极大的提高我们代码的可读性和复用性.而在Javascript的ES7提案中,有一种新的语法叫做deco ...

  6. 看图学习 ArrayBuffers 和 SharedArrayBuffers

    原文地址:A cartoon intro to ArrayBuffers and SharedArrayBuffers 原文作者:Lin Clark 译者:黑黑 校对者:Bob 在上一篇文章中,老司机 ...

  7. sqli-labs 1-10关

    学习sql注入的必做靶场我终于来尝试一下下了. 第一关 ?id=1'时出现 在测试?id=1' and '1'='1,页面正常 ?id=1' and '1'='2  页面错误 判断存在单引号字符型注入 ...

  8. 什么是 Catalan 数列以及其应用

    引言 在开始论述之前,我想请大家先看下这几个问题: 有 \(2n\) 个人排成一行进入剧场.入场费 5 元.其中只有 \(n\) 个人有一张 5 元钞票,另外 \(n\) 人只有 10 元钞票,剧院无 ...

  9. 2020华为杯数学建模B题-RON建模 赛后总结与分析

    好久好久没有写博客了...挺累的,从二月份开始找暑期实习,接着在进行暑期实习,然后马不停蹄地进行秋招,现在总算结束实习,前两天又参加了华为杯数学建模竞赛,感觉接下来就会很轻松了,希望能好好休息休息.这 ...

  10. GitLab集成kubernetes

    创建GitLab源码项目并上传示例代码 1. 创建GitLab源码项目 本示例中创建的GitLab源码项目地址为:https://gitee.com/SunHarvey/helloworld_java ...