Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nikita: The Ruby Secret Agent

brixen
January 29, 2012

Nikita: The Ruby Secret Agent

Talk presented at RubyConf 2011.

brixen

January 29, 2012
Tweet

More Decks by brixen

Other Decks in Technology

Transcript

  1. VALUE rb_to_float(VALUE val) { if (TYPE(val) == T_FLOAT) return val;

    if (!rb_obj_is_kind_of(val, rb_cNumeric)) { rb_raise(rb_eTypeError, "can't convert %s into Float", NIL_P(val) ? "nil" : val == Qtrue ? "true" : val == Qfalse ? "false" : rb_obj_classname(val)); } return rb_convert_type(val, T_FLOAT, "Float", "to_f"); }
  2. -w

  3. OOM

  4. $ rbx irb(main):001:0> ast = "a = 1".to_ast => #<Rubinius::AST::LocalVariableAssignment:0xf30

    @value=#<Rubinius::AST::FixnumLiteral:0xf34 @value=1 @line=1> @line=1 @name=:a @variable=nil> irb(main):002:0> ast.class => Rubinius::AST::LocalVariableAssignment
  5. $ irb(main):003:0> ast.ascii_graph LocalVariableAssignment @line: 1 @name: :a @variable: nil

    @value: \ FixnumLiteral @value: 1 @line: 1 => [["@value", #<Rubinius::AST::FixnumLiteral:0xf34 @value=1 @line=1>]]
  6. $ rbx irb(main):001:0> def m(a, b) irb(main):002:1> a + b

    irb(main):003:1> end => #<Rubinius::CompiledMethod m file=(irb)>
  7. $ rbx compile -e 'puts 1' -B ============= :__script__ ==============

    Arguments: 0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 2 Lines to IP: 1: 0..8 0000: push_self 0001: meta_push_1 0002: allow_private 0003: send_stack :puts, 1 0006: pop 0007: push_true 0008: ret ----------------------------------------
  8. $ rbx compile -e 'class A; def m; end; end'

    -B -N __script__ ============= :__script__ ============== Arguments: 0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 6 Lines to IP: 1: 0..28 0000: push_rubinius 0001: push_literal :A 0003: push_nil 0004: push_scope 0005: send_stack :open_class, 3 0008: dup_top 0009: push_rubinius 0010: swap_stack 0011: push_literal :__class_init__ 0013: swap_stack 0014: push_literal #<Rubinius::CompiledMethod A file=(snippet)> 0016: swap_stack 0017: push_scope 0018: swap_stack 0019: send_stack :attach_method, 4 0022: pop 0023: send_stack :__class_init__, 0 0026: pop 0027: push_true 0028: ret ----------------------------------------
  9. $ rbx compile -e 'class A; def m; end; end'

    -B -N A ================== :A ================== Arguments: 0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 5 Lines to IP: 1: 2..15 0000: push_self 0001: add_scope 0002: push_rubinius 0003: push_literal :m 0005: push_literal #<Rubinius::CompiledMethod m file=(snippet)> 0007: push_scope 0008: push_variables 0009: send_stack :method_visibility, 0 0012: send_stack :add_defn_method, 4 0015: ret ----------------------------------------
  10. $ rbx irb(main):001:0> class F irb(main):002:1> dynamic_method :m do |g|

    irb(main):003:2* g.push :self irb(main):004:2> g.push_literal g.name irb(main):005:2> g.send :p, 1, true irb(main):006:2> g.ret irb(main):007:2> end irb(main):008:1> end => #<Rubinius::CompiledMethod m file=dynamic> irb(main):009:0> F.new.m :m => nil