Skip to content

Commit 35d93b0

Browse files
committed
Transform (concat a b c) into chain of method calls
1 parent c7b4b54 commit 35d93b0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

transform.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,24 @@ def rewrite_let_env(exp)
210210
end
211211
end
212212

213+
def create_concat(sub)
214+
right = sub.pop
215+
right = E[:callm,right,:to_s] if !right.is_a?(Array)
216+
return right if sub.size == 0
217+
E[:callm, create_concat(sub), :concat, [right]]
218+
end
219+
220+
def rewrite_concat(exp)
221+
exp.depth_first do |e|
222+
if e[0] == :concat
223+
e.replace(create_concat(e[1..-1]))
224+
end
225+
:next
226+
end
227+
end
228+
213229
def preprocess exp
230+
rewrite_concat(exp)
214231
rewrite_strconst(exp)
215232
rewrite_fixnumconst(exp)
216233
rewrite_operators(exp)

0 commit comments

Comments
 (0)