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 那样的机器指令。

最新文章

  1. 格式化Double类型
  2. weblogic无需用户名密码启动Server
  3. C#微信json结构接收参数 转载
  4. html 符号大全
  5. HDU题目分类
  6. Scala - 正则表达式匹配例子
  7. AE 线编辑
  8. 使用scrapy制作的小说爬虫
  9. hdu EXCEL排序
  10. sort 使用 tab键 作为 分隔符_人生如梦_百度空间
  11. (简单) POJ 3264 Balanced Lineup,RMQ。
  12. python实现数据结构单链表
  13. 15.scrapy中selenium的应用
  14. jsp (2)
  15. docker部署Javaweb环境数据库连接问题
  16. http://218.245.4.98:20000/phpmyadmin:2018SCTF--easiest web - phpmyadmin
  17. [翻译] 提升树算法的介绍(Introduction to Boosted Trees)
  18. yum 卸载 error: %preun(tengine-2.1.0-1.el6.x86_64) scriptlet failed, exit status 6
  19. Lua官方文档与源码分析
  20. QrenCode : 命令行下生成二维码图片

热门文章

  1. nginx模块化结构
  2. javascript面试题(二)
  3. 与C中printf并列的System.out.printf 用法(转载)
  4. PostgressQL
  5. 字符串split的用法
  6. .NET Core表达式树的梳理
  7. Traveling by Stagecoach(POJ 2686)
  8. [LeetCode]21. 合并两个有序链表(递归)
  9. 对比 Redis 中 RDB 和 AOF 持久化
  10. Scala的递归函数应用