File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def rewrite_lambda(exp)
29
29
end
30
30
end
31
31
end
32
-
32
+
33
33
34
34
# Re-write string constants outside %s() to
35
35
# %s(call __get_string [original string constant])
@@ -78,6 +78,20 @@ def rewrite_fixnumconst(exp)
78
78
end
79
79
80
80
81
+ # Rewrite operators that should be treated as method calls
82
+ # so that e.g. (+ 1 2) is turned into (callm 1 + 2)
83
+ #
84
+ def rewrite_operators ( exp )
85
+ exp . depth_first do |e |
86
+ next :skip if e [ 0 ] == :sexp
87
+
88
+ if OPER_METHOD . member? ( e [ 0 ] . to_s )
89
+ e [ 3 ] = e [ 2 ]
90
+ e [ 2 ] = e [ 0 ]
91
+ e [ 0 ] = :callm
92
+ end
93
+ end
94
+ end
81
95
82
96
# 1. If I see an assign node, the variable on the left hand is defined
83
97
# for the remainder of this scope and on any sub-scope.
@@ -199,6 +213,7 @@ def rewrite_let_env(exp)
199
213
def preprocess exp
200
214
rewrite_strconst ( exp )
201
215
rewrite_fixnumconst ( exp )
216
+ rewrite_operators ( exp )
202
217
rewrite_let_env ( exp )
203
218
rewrite_lambda ( exp )
204
219
end
You can’t perform that action at this time.
0 commit comments