Module: FastRuby::NonLocalTranslator

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

Instance Method Summary collapse

Instance Method Details

#to_c_break(tree, result_var = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 38

def to_c_break(tree, result_var = nil)
  
    value_tmp_var = "value_" + rand(10000000).to_s
  
    code = "

      {
     VALUE #{value_tmp_var} = Qnil; 
     #{
     if tree[1]
       to_c(tree[1], value_tmp_var)
     end
     };

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

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

     plocals->call_frame = 0;

     target_frame_->return_value = #{value_tmp_var};
     target_frame_->targetted = 1;
     pframe->thread_data->exception = Qnil;
     longjmp(pframe->jmp,FASTRUBY_TAG_BREAK);
     
     }
     "
     
     if result_var
       code
     else
       inline_block code
     end
end

#to_c_next(tree, result_var = nil) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 113

def to_c_next(tree, result_var = nil)
  tmp_varname = "_acc_" + rand(10000000).to_s
  if @on_block
   code = "
    {
      last_expression = Qnil;
      
      #{
      if tree[1]
        to_c(tree[1],"last_expression")
      end
      }
    pframe->thread_data->accumulator = last_expression;
    goto fastruby_local_next;
    }
    "
    if result_var
      code
    else
      inline_block code
    end
  else
    _raise("rb_eLocalJumpError","illegal next");
  end
end

#to_c_redo(tree, result_var = nil) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 97

def to_c_redo(tree, result_var = nil)
  if @on_block
     code = "
        goto fastruby_local_redo;
      "
      
      if result_var
        code
      else
        inline_block code
      end
  else
      _raise("rb_eLocalJumpError","illegal redo");
  end
end

#to_c_retry(tree, result_var = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fastruby/translator/modules/nonlocal.rb', line 76

def to_c_retry(tree, result_var = nil)
    code = "
      {
     typeof(pframe) target_frame_;
     target_frame_ = (void*)plocals->call_frame;

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

     target_frame_->targetted = 1;
     longjmp(pframe->jmp,FASTRUBY_TAG_RETRY);
     }
     "
   if result_var
     code
   else
     inline_block code
   end
end

#to_c_return(tree, return_variable = nil) ⇒ Object



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

def to_c_return(tree, return_variable = nil)
  code = "
    #{to_c(tree[1],"last_expression")};
    goto local_return;
    return Qnil;
    "
  if return_variable
    code
  else
    inline_block code
  end
end