Module: FastRuby::NonLocalTranslator

Defined in:
lib/fastruby/translator/modules/nonlocal.rb

Instance Method Summary collapse

Instance Method Details

#to_c_break(tree) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 34

def to_c_break(tree)
    inline_block(
     "

     VALUE value = #{tree[1] ? to_c(tree[1]) : "Qnil"};

     typeof(pframe) target_frame_;
     target_frame_ = (void*)FIX2LONG(plocals->call_frame);

     if (target_frame_ == 0) {
        #{_raise("rb_eLocalJumpError","illegal break")};
     }

     plocals->call_frame = LONG2FIX(0);

     target_frame_->return_value = value;
     target_frame_->targetted = 1;
     pframe->thread_data->exception = Qnil;
     longjmp(pframe->jmp,FASTRUBY_TAG_BREAK);"
    )
end

#to_c_next(tree) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 82

def to_c_next(tree)
  if @on_block
   inline_block "
    pframe->thread_data->accumulator = #{tree[1] ? to_c(tree[1]) : "Qnil"};
    longjmp(pframe->jmp,FASTRUBY_TAG_NEXT);
    return Qnil;
    "
  else
    _raise("rb_eLocalJumpError","illegal next");
  end
end

#to_c_redo(tree) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 71

def to_c_redo(tree)
  if @on_block
     inline_block "
      longjmp(pframe->jmp,FASTRUBY_TAG_REDO);
      return Qnil;
      "
  else
      _raise("rb_eLocalJumpError","illegal redo");
  end
end

#to_c_retry(tree) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 56

def to_c_retry(tree)
    inline_block(
     "
     typeof(pframe) target_frame_;
     target_frame_ = (void*)FIX2LONG(plocals->call_frame);

     if (target_frame_ == 0) {
        #{_raise("rb_eLocalJumpError","illegal retry")};
     }

     target_frame_->targetted = 1;
     longjmp(pframe->jmp,FASTRUBY_TAG_RETRY);"
    )
end

#to_c_return(tree) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 25

def to_c_return(tree)
  inline_block "
    plocals->return_value = #{to_c(tree[1])};
    plocals->targetted = 1;
    longjmp(pframe->jmp, FASTRUBY_TAG_RETURN);
    return Qnil;
    "
end