fastruby 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. data/CHANGELOG +17 -1
  2. data/Rakefile +1 -1
  3. data/ext/fastruby_base/fastruby_base.inl +81 -3
  4. data/lib/fastruby/fastruby_sexp.rb +21 -0
  5. data/lib/fastruby/getlocals.rb +2 -1
  6. data/lib/fastruby/object.rb +1 -1
  7. data/lib/fastruby/sexp_extension.rb +189 -0
  8. data/lib/fastruby/sexp_extension_edges.rb +210 -0
  9. data/lib/fastruby/translator/modules/block.rb +29 -22
  10. data/lib/fastruby/translator/modules/call.rb +211 -34
  11. data/lib/fastruby/translator/modules/defn.rb +64 -29
  12. data/lib/fastruby/translator/modules/exceptions.rb +1 -1
  13. data/lib/fastruby/translator/modules/flow.rb +93 -31
  14. data/lib/fastruby/translator/modules/iter.rb +277 -340
  15. data/lib/fastruby/translator/modules/literal.rb +97 -20
  16. data/lib/fastruby/translator/modules/logical.rb +40 -5
  17. data/lib/fastruby/translator/modules/method_group.rb +41 -19
  18. data/lib/fastruby/translator/modules/nonlocal.rb +74 -29
  19. data/lib/fastruby/translator/modules/variable.rb +151 -42
  20. data/lib/fastruby/translator/scope_mode_helper.rb +161 -0
  21. data/lib/fastruby/translator/translator.rb +389 -302
  22. data/lib/fastruby.rb +1 -1
  23. data/lib/fastruby.rb~ +36 -0
  24. data/spec/edges_helper.rb +91 -0
  25. data/spec/graph/base_spec.rb +35 -0
  26. data/spec/graph/path_spec.rb +48 -0
  27. data/spec/graph/vertex_spec.rb +58 -0
  28. data/spec/ruby/block/proc_as_block_spec.rb +214 -0
  29. data/spec/ruby/block/redo_spec.rb +133 -0
  30. data/spec/ruby/defn/single_function_spec.rb +50 -0
  31. data/spec/scope_mode/base_spec.rb +55 -0
  32. data/spec/scope_mode/block_spec.rb +105 -0
  33. data/spec/scope_mode/call_spec.rb +24 -0
  34. data/spec/scope_mode/exception_spec.rb +34 -0
  35. data/spec/scope_mode/flow_spec.rb +99 -0
  36. data/spec/scope_mode/optimization_spec.rb +130 -0
  37. data/spec/sexp2graph/base_spec.rb +36 -0
  38. data/spec/sexp2graph/exception_spec.rb +172 -0
  39. data/spec/sexp2graph/flow_spec.rb +67 -0
  40. data/spec/sexp2graph/logical_spec.rb +21 -0
  41. data/spec/sexp2graph/variable_spec.rb +26 -0
  42. metadata +110 -120
  43. data/lib/fastruby/self +0 -82
  44. data/lib/len +0 -280
  45. data/spec/block/proc_as_block_spec.rb +0 -111
  46. data/spec/block/redo_spec.rb +0 -67
  47. /data/spec/{base_spec.rb → ruby/base_spec.rb} +0 -0
  48. /data/spec/{block → ruby/block}/arguments_spec.rb +0 -0
  49. /data/spec/{block → ruby/block}/block_as_proc_spec.rb +0 -0
  50. /data/spec/{block → ruby/block}/break_spec.rb +0 -0
  51. /data/spec/{block → ruby/block}/callcc_spec.rb +0 -0
  52. /data/spec/{block → ruby/block}/lambda_spec.rb +0 -0
  53. /data/spec/{block → ruby/block}/next_spec.rb +0 -0
  54. /data/spec/{block → ruby/block}/proc_spec.rb +0 -0
  55. /data/spec/{block → ruby/block}/retry_spec.rb +0 -0
  56. /data/spec/{block_spec.rb → ruby/block_spec.rb} +0 -0
  57. /data/spec/{call → ruby/call}/base_call_spec.rb +0 -0
  58. /data/spec/{call → ruby/call}/multiple_args_spec.rb +0 -0
  59. /data/spec/{control_spec.rb → ruby/control_spec.rb} +0 -0
  60. /data/spec/{defn → ruby/defn}/default_args_spec.rb +0 -0
  61. /data/spec/{defn → ruby/defn}/multiple_args_spec.rb +0 -0
  62. /data/spec/{defn → ruby/defn}/replacement_spec.rb +0 -0
  63. /data/spec/{exception → ruby/exception}/base_spec.rb +0 -0
  64. /data/spec/{exception → ruby/exception}/ensure_spec.rb +0 -0
  65. /data/spec/{exception → ruby/exception}/exc_trap_spec.rb +0 -0
  66. /data/spec/{exception → ruby/exception}/internal_ex_spec.rb +0 -0
  67. /data/spec/{exception → ruby/exception}/syntaxis_spec.rb +0 -0
  68. /data/spec/{expression_spec.rb → ruby/expression_spec.rb} +0 -0
  69. /data/spec/{flow_control → ruby/flow_control}/case_spec.rb +0 -0
  70. /data/spec/{flow_control → ruby/flow_control}/for_spec.rb +0 -0
  71. /data/spec/{integrity_spec.rb → ruby/integrity_spec.rb} +0 -0
  72. /data/spec/{jump → ruby/jump}/next_spec.rb +0 -0
  73. /data/spec/{literal_spec.rb → ruby/literal_spec.rb} +0 -0
  74. /data/spec/{module_spec.rb → ruby/module_spec.rb} +0 -0
  75. /data/spec/{return_spec.rb → ruby/return_spec.rb} +0 -0
  76. /data/spec/{singleton_spec.rb → ruby/singleton_spec.rb} +0 -0
  77. /data/spec/{sugar_spec.rb → ruby/sugar_spec.rb} +0 -0
  78. /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
- if (RTEST(#{to_c_call(calltree, tmpvarname)})) {
38
- return #{to_c(subtree[2])};
39
- }
40
-
39
+ if (RTEST(#{to_c_call(calltree)})) {
40
+ #{to_c(subtree[2],outputvar)};
41
+ }
41
42
  "
42
- }.join("\n")
43
-
44
- }.join("\n")
45
-
46
- inline_block "
47
-
48
- VALUE #{tmpvarname} = #{to_c tree[1]};
49
-
50
- #{code};
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
- inline_block "
62
- if (RTEST(#{to_c condition_tree})) {
63
- last_expression = #{to_c impl_tree};
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
- last_expression = #{to_c else_tree};
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
- inline_block("
84
- while (#{to_c tree[1]}) {
85
- #{to_c tree[2]};
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
- return Qnil;
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