Skip to content

Commit 5fa9c98

Browse files
committedNov 13, 2013
Cleanup literal nodes in compiler
1 parent edc7592 commit 5fa9c98

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed
 

‎lib/opal/nodes/literal.rb

+17-20
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,56 @@ class ValueNode < Base
66
handle :true, :false, :self, :nil
77

88
def compile
9-
# :self, :true, :false, :nil
109
push type.to_s
1110
end
1211
end
1312

14-
class LiteralNode < Base
15-
children :value
16-
end
17-
18-
class NumericNode < LiteralNode
13+
class NumericNode < Base
1914
handle :int, :float
2015

16+
children :value
17+
2118
def compile
2219
push value.to_s
2320
wrap '(', ')' if recv?
2421
end
2522
end
2623

27-
class StringNode < LiteralNode
24+
class StringNode < Base
2825
handle :str
2926

27+
children :value
28+
3029
def compile
3130
push value.inspect
3231
end
3332
end
3433

35-
class SymbolNode < LiteralNode
34+
class SymbolNode < Base
3635
handle :sym
3736

37+
children :value
38+
3839
def compile
3940
push value.to_s.inspect
4041
end
4142
end
4243

43-
class RegexpNode < LiteralNode
44+
class RegexpNode < Base
4445
handle :regexp
4546

47+
children :value
48+
4649
def compile
4750
push((value == // ? /^/ : value).inspect)
4851
end
4952
end
5053

51-
class XStringNode < LiteralNode
54+
class XStringNode < Base
5255
handle :xstr
5356

57+
children :value
58+
5459
def needs_semicolon?
5560
stmt? and !value.to_s.include?(';')
5661
end
@@ -166,11 +171,7 @@ class ExclusiveRangeNode < Base
166171
def compile
167172
helper :range
168173

169-
push "$range("
170-
push expr(start)
171-
push ", "
172-
push expr(finish)
173-
push ", false)"
174+
push '$range(', expr(start), ', ', expr(finish), ', false)'
174175
end
175176
end
176177

@@ -182,11 +183,7 @@ class InclusiveRangeNode < Base
182183
def compile
183184
helper :range
184185

185-
push "$range("
186-
push expr(start)
187-
push ", "
188-
push expr(finish)
189-
push ", true)"
186+
push '$range(', expr(start), ', ', expr(finish), ', true)'
190187
end
191188
end
192189
end

0 commit comments

Comments
 (0)
Please sign in to comment.