4、Ruby代码编译:从AST到YARV指令的深入解析

Ruby代码编译:从AST到YARV指令的深入解析

1. YARV指令优化

在编译过程中,Ruby会对YARV(Yet Another Ruby Virtual Machine)指令进行优化。例如,对于 puts 2+2 这样的代码,最初生成的YARV指令如下:

NODE_SCOPE
putself
putobject
putobject
send
send
NODE_FCALL
2
2
<callinfo!mid:+, argc:1, ...
<callinfo!mid:puts, argc:1, ...
YARV instructions
table: [ none ]
args: [ none ]
method id:
puts

在优化步骤中,Ruby会用专门的指令替换一些YARV指令。像 send <callinfo!mid:+... 会被 opt_plus 替换,第二个 send 会被 opt_send_simple 替换,优化后的指令如下:

NODE_SCOPE
putself
putobject
putobject
opt_plus
opt_send_simple
NODE_FCALL
2
2
<callinfo!mid:puts,
argc:1...
YARV instructions
table: [ none ]
ar
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值