Skip to content

Commit

Permalink
Cleanup literal nodes in compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 13, 2013
1 parent edc7592 commit 5fa9c98
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions lib/opal/nodes/literal.rb
Expand Up @@ -6,51 +6,56 @@ class ValueNode < Base
handle :true, :false, :self, :nil

def compile
# :self, :true, :false, :nil
push type.to_s
end
end

class LiteralNode < Base
children :value
end

class NumericNode < LiteralNode
class NumericNode < Base
handle :int, :float

children :value

def compile
push value.to_s
wrap '(', ')' if recv?
end
end

class StringNode < LiteralNode
class StringNode < Base
handle :str

children :value

def compile
push value.inspect
end
end

class SymbolNode < LiteralNode
class SymbolNode < Base
handle :sym

children :value

def compile
push value.to_s.inspect
end
end

class RegexpNode < LiteralNode
class RegexpNode < Base
handle :regexp

children :value

def compile
push((value == // ? /^/ : value).inspect)
end
end

class XStringNode < LiteralNode
class XStringNode < Base
handle :xstr

children :value

def needs_semicolon?
stmt? and !value.to_s.include?(';')
end
Expand Down Expand Up @@ -166,11 +171,7 @@ class ExclusiveRangeNode < Base
def compile
helper :range

push "$range("
push expr(start)
push ", "
push expr(finish)
push ", false)"
push '$range(', expr(start), ', ', expr(finish), ', false)'
end
end

Expand All @@ -182,11 +183,7 @@ class InclusiveRangeNode < Base
def compile
helper :range

push "$range("
push expr(start)
push ", "
push expr(finish)
push ", true)"
push '$range(', expr(start), ', ', expr(finish), ', true)'
end
end
end
Expand Down

0 comments on commit 5fa9c98

Please sign in to comment.