fastruby 0.0.16 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +17 -1
- data/Rakefile +1 -1
- data/ext/fastruby_base/fastruby_base.inl +81 -3
- data/lib/fastruby/fastruby_sexp.rb +21 -0
- data/lib/fastruby/getlocals.rb +2 -1
- data/lib/fastruby/object.rb +1 -1
- data/lib/fastruby/sexp_extension.rb +189 -0
- data/lib/fastruby/sexp_extension_edges.rb +210 -0
- data/lib/fastruby/translator/modules/block.rb +29 -22
- data/lib/fastruby/translator/modules/call.rb +211 -34
- data/lib/fastruby/translator/modules/defn.rb +64 -29
- data/lib/fastruby/translator/modules/exceptions.rb +1 -1
- data/lib/fastruby/translator/modules/flow.rb +93 -31
- data/lib/fastruby/translator/modules/iter.rb +277 -340
- data/lib/fastruby/translator/modules/literal.rb +97 -20
- data/lib/fastruby/translator/modules/logical.rb +40 -5
- data/lib/fastruby/translator/modules/method_group.rb +41 -19
- data/lib/fastruby/translator/modules/nonlocal.rb +74 -29
- data/lib/fastruby/translator/modules/variable.rb +151 -42
- data/lib/fastruby/translator/scope_mode_helper.rb +161 -0
- data/lib/fastruby/translator/translator.rb +389 -302
- data/lib/fastruby.rb +1 -1
- data/lib/fastruby.rb~ +36 -0
- data/spec/edges_helper.rb +91 -0
- data/spec/graph/base_spec.rb +35 -0
- data/spec/graph/path_spec.rb +48 -0
- data/spec/graph/vertex_spec.rb +58 -0
- data/spec/ruby/block/proc_as_block_spec.rb +214 -0
- data/spec/ruby/block/redo_spec.rb +133 -0
- data/spec/ruby/defn/single_function_spec.rb +50 -0
- data/spec/scope_mode/base_spec.rb +55 -0
- data/spec/scope_mode/block_spec.rb +105 -0
- data/spec/scope_mode/call_spec.rb +24 -0
- data/spec/scope_mode/exception_spec.rb +34 -0
- data/spec/scope_mode/flow_spec.rb +99 -0
- data/spec/scope_mode/optimization_spec.rb +130 -0
- data/spec/sexp2graph/base_spec.rb +36 -0
- data/spec/sexp2graph/exception_spec.rb +172 -0
- data/spec/sexp2graph/flow_spec.rb +67 -0
- data/spec/sexp2graph/logical_spec.rb +21 -0
- data/spec/sexp2graph/variable_spec.rb +26 -0
- metadata +110 -120
- data/lib/fastruby/self +0 -82
- data/lib/len +0 -280
- data/spec/block/proc_as_block_spec.rb +0 -111
- data/spec/block/redo_spec.rb +0 -67
- /data/spec/{base_spec.rb → ruby/base_spec.rb} +0 -0
- /data/spec/{block → ruby/block}/arguments_spec.rb +0 -0
- /data/spec/{block → ruby/block}/block_as_proc_spec.rb +0 -0
- /data/spec/{block → ruby/block}/break_spec.rb +0 -0
- /data/spec/{block → ruby/block}/callcc_spec.rb +0 -0
- /data/spec/{block → ruby/block}/lambda_spec.rb +0 -0
- /data/spec/{block → ruby/block}/next_spec.rb +0 -0
- /data/spec/{block → ruby/block}/proc_spec.rb +0 -0
- /data/spec/{block → ruby/block}/retry_spec.rb +0 -0
- /data/spec/{block_spec.rb → ruby/block_spec.rb} +0 -0
- /data/spec/{call → ruby/call}/base_call_spec.rb +0 -0
- /data/spec/{call → ruby/call}/multiple_args_spec.rb +0 -0
- /data/spec/{control_spec.rb → ruby/control_spec.rb} +0 -0
- /data/spec/{defn → ruby/defn}/default_args_spec.rb +0 -0
- /data/spec/{defn → ruby/defn}/multiple_args_spec.rb +0 -0
- /data/spec/{defn → ruby/defn}/replacement_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/base_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/ensure_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/exc_trap_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/internal_ex_spec.rb +0 -0
- /data/spec/{exception → ruby/exception}/syntaxis_spec.rb +0 -0
- /data/spec/{expression_spec.rb → ruby/expression_spec.rb} +0 -0
- /data/spec/{flow_control → ruby/flow_control}/case_spec.rb +0 -0
- /data/spec/{flow_control → ruby/flow_control}/for_spec.rb +0 -0
- /data/spec/{integrity_spec.rb → ruby/integrity_spec.rb} +0 -0
- /data/spec/{jump → ruby/jump}/next_spec.rb +0 -0
- /data/spec/{literal_spec.rb → ruby/literal_spec.rb} +0 -0
- /data/spec/{module_spec.rb → ruby/module_spec.rb} +0 -0
- /data/spec/{return_spec.rb → ruby/return_spec.rb} +0 -0
- /data/spec/{singleton_spec.rb → ruby/singleton_spec.rb} +0 -0
- /data/spec/{sugar_spec.rb → ruby/sugar_spec.rb} +0 -0
- /data/spec/{variable_spec.rb → ruby/variable_spec.rb} +0 -0
@@ -23,10 +23,12 @@ module FastRuby
|
|
23
23
|
|
24
24
|
register_translator_module self
|
25
25
|
|
26
|
-
def to_c_case(tree)
|
26
|
+
def to_c_case(tree, result_var = nil)
|
27
27
|
|
28
28
|
tmpvarname = "tmp" + rand(1000000).to_s;
|
29
|
-
|
29
|
+
@repass_var = tmpvarname
|
30
|
+
outputvar = result_var || ("tmp_" + rand(1000000).to_s);
|
31
|
+
|
30
32
|
code = tree[2..-2].map{|subtree|
|
31
33
|
|
32
34
|
# this subtree is a when
|
@@ -34,42 +36,76 @@ module FastRuby
|
|
34
36
|
c_calltree = s(:call, nil, :inline_c, s(:arglist, s(:str, tmpvarname), s(:false)))
|
35
37
|
calltree = s(:call, subsubtree, :===, s(:arglist, c_calltree))
|
36
38
|
"
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
if (RTEST(#{to_c_call(calltree)})) {
|
40
|
+
#{to_c(subtree[2],outputvar)};
|
41
|
+
}
|
41
42
|
"
|
42
|
-
}.join("
|
43
|
-
|
44
|
-
}.join("
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
return #{to_c tree[-1]};
|
43
|
+
}.join(" else ")
|
44
|
+
|
45
|
+
}.join(" else ") + "else {
|
46
|
+
#{
|
47
|
+
if tree[-1]
|
48
|
+
to_c tree[-1],outputvar
|
49
|
+
end
|
50
|
+
};
|
51
|
+
}
|
53
52
|
"
|
53
|
+
|
54
|
+
ret_code = "
|
55
|
+
{
|
56
|
+
#{
|
57
|
+
unless result_var
|
58
|
+
VALUE #{outputvar} = Qnil;
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE #{tmpvarname} = Qnil;
|
63
|
+
#{to_c tree[1], tmpvarname};
|
64
|
+
|
65
|
+
// case
|
66
|
+
#{code}
|
67
|
+
#{
|
68
|
+
unless result_var
|
69
|
+
"return #{outputvar};"
|
70
|
+
end
|
71
|
+
}
|
72
|
+
}
|
73
|
+
"
|
74
|
+
|
75
|
+
if result_var
|
76
|
+
ret_code
|
77
|
+
else
|
78
|
+
inline_block ret_code
|
79
|
+
end
|
54
80
|
end
|
55
81
|
|
56
|
-
def to_c_if(tree)
|
82
|
+
def to_c_if(tree, result_variable_ = nil)
|
57
83
|
condition_tree = tree[1]
|
58
84
|
impl_tree = tree[2]
|
59
85
|
else_tree = tree[3]
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
86
|
+
|
87
|
+
result_variable = result_variable_ || "last_expression"
|
88
|
+
|
89
|
+
code = "
|
90
|
+
{
|
91
|
+
VALUE condition_result;
|
92
|
+
#{to_c condition_tree, "condition_result"};
|
93
|
+
if (RTEST(condition_result)) {
|
94
|
+
#{to_c impl_tree, result_variable};
|
64
95
|
}#{else_tree ?
|
65
96
|
" else {
|
66
|
-
|
97
|
+
#{to_c else_tree, result_variable};
|
67
98
|
}
|
68
99
|
" : ""
|
69
100
|
}
|
70
|
-
|
71
|
-
return last_expression;
|
101
|
+
}
|
72
102
|
"
|
103
|
+
|
104
|
+
if result_variable_
|
105
|
+
code
|
106
|
+
else
|
107
|
+
inline_block code + "; return last_expression;"
|
108
|
+
end
|
73
109
|
end
|
74
110
|
|
75
111
|
def to_c_for(tree)
|
@@ -79,13 +115,39 @@ module FastRuby
|
|
79
115
|
to_c alter_tree
|
80
116
|
end
|
81
117
|
|
82
|
-
def to_c_while(tree)
|
83
|
-
|
84
|
-
|
85
|
-
|
118
|
+
def to_c_while(tree, result_var = nil)
|
119
|
+
|
120
|
+
begin_while = "begin_while_"+rand(10000000).to_s
|
121
|
+
end_while = "end_while_"+rand(10000000).to_s
|
122
|
+
aux_varname = "_aux_" + rand(10000000).to_s
|
123
|
+
code = "
|
124
|
+
{
|
125
|
+
VALUE while_condition;
|
126
|
+
VALUE #{aux_varname};
|
127
|
+
|
128
|
+
#{begin_while}:
|
129
|
+
#{to_c tree[1], "while_condition"};
|
130
|
+
if (!RTEST(while_condition)) goto #{end_while};
|
131
|
+
#{to_c tree[2], aux_varname};
|
132
|
+
goto #{begin_while};
|
133
|
+
#{end_while}:
|
134
|
+
|
135
|
+
#{
|
136
|
+
if result_var
|
137
|
+
"#{result_var} = Qnil;"
|
138
|
+
else
|
139
|
+
"return Qnil;"
|
140
|
+
end
|
86
141
|
}
|
87
|
-
|
88
|
-
"
|
142
|
+
}
|
143
|
+
"
|
144
|
+
|
145
|
+
if result_var
|
146
|
+
code
|
147
|
+
else
|
148
|
+
inline_block code
|
149
|
+
end
|
150
|
+
|
89
151
|
end
|
90
152
|
end
|
91
153
|
end
|