YAR指令序列/ SimpleDateFormat到源转换

时间:2013-09-16 14:21:53

标签: ruby metaprogramming

可以在YARVInstructionSequence/SimpleDataFormat中将proc转换为Ruby虚拟机序列,如下所示:

RubyVM::InstructionSequence.of(->x{x + 1}).to_a
# => ["YARVInstructionSequence/SimpleDataFormat", 2, 0, 1,
  {:arg_size=>1, :local_size=>2, :stack_max=>2},
  "block in irb_binding", "(irb)", nil, 2,
  :block, [:x], [1, [], 0, 0, -1, -1, 3],
  [
    [:redo, nil, :label_0, :label_9, :label_0, 0],
    [:next, nil, :label_0, :label_9, :label_9, 0]
  ],
  [
    :label_0, 2, [:trace, 256], [:trace, 1], [:getlocal_OP__WC__0, 2],
    [:putobject_OP_INT2FIX_O_1_C_],
    [:opt_plus, {:mid=>:+, :flag=>256, :orig_argc=>1, :blockptr=>nil}], :label_9,
    [:trace, 512], [:leave]
  ]
]

有没有办法将这种格式转换回来重建字符串中的源表达式,如"->x{x+1}"或接近它的东西?

格式在RDoc中解释如下:

doc1 doc2 doc3 doc4

0 个答案:

没有答案