adding to_s to code for debugging
This commit is contained in:
parent
6c9bd7e476
commit
1b8d6149dd
@ -5,6 +5,11 @@ module Typed
|
||||
class Statement < Code ; end
|
||||
class Expression < Code ; end
|
||||
|
||||
module ValuePrinter
|
||||
def to_s
|
||||
@value.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
require_relative "tree/while_statement"
|
||||
|
@ -1,30 +1,43 @@
|
||||
module Typed
|
||||
module Tree
|
||||
class IntegerExpression < Expression
|
||||
include ValuePrinter
|
||||
attr_accessor :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
end
|
||||
class FloatExpression < Expression
|
||||
include ValuePrinter
|
||||
attr_accessor :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
end
|
||||
class TrueExpression < Expression
|
||||
def to_s
|
||||
"true"
|
||||
end
|
||||
end
|
||||
class FalseExpression < Expression
|
||||
def to_s
|
||||
false
|
||||
end
|
||||
end
|
||||
class NilExpression < Expression
|
||||
def to_s
|
||||
"nil"
|
||||
end
|
||||
end
|
||||
class StringExpression < Expression
|
||||
include ValuePrinter
|
||||
attr_accessor :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
end
|
||||
class NameExpression < Expression
|
||||
include ValuePrinter
|
||||
attr_accessor :value
|
||||
alias :name :value
|
||||
def initialize(value)
|
||||
@ -32,6 +45,7 @@ module Typed
|
||||
end
|
||||
end
|
||||
class ClassExpression < Expression
|
||||
include ValuePrinter
|
||||
attr_accessor :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
|
@ -2,6 +2,11 @@ module Typed
|
||||
module Tree
|
||||
class CallSite < Expression
|
||||
attr_accessor :name , :receiver , :arguments
|
||||
|
||||
def to_s
|
||||
str = receiver ? "#{receiver}.#{name}" : name.to_s
|
||||
str + arguments.collect{|a| a.to_s }.join(",")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,9 @@ module Typed
|
||||
module Tree
|
||||
class FieldAccess < Expression
|
||||
attr_accessor :receiver , :field
|
||||
def to_s
|
||||
"#{receiver}.#{field}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,11 @@ module Typed
|
||||
module Tree
|
||||
class IfStatement < Statement
|
||||
attr_accessor :branch_type , :condition , :if_true , :if_false
|
||||
def to_s
|
||||
str = "if_#{branch_type}(#{condition}) \n #{if_true}\n"
|
||||
str += "else\n #{if_false}\n" if if_false
|
||||
str + "end\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,9 @@ module Typed
|
||||
module Tree
|
||||
class OperatorExpression < Expression
|
||||
attr_accessor :operator , :left_expression , :right_expression
|
||||
def to_s
|
||||
"#{left_expression} #{operator} #{right_expression}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,10 @@ module Typed
|
||||
module Tree
|
||||
class ReturnStatement < Statement
|
||||
attr_accessor :return_value
|
||||
|
||||
def to_s
|
||||
"return #{return_value}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,6 +2,10 @@ module Typed
|
||||
module Tree
|
||||
class WhileStatement < Statement
|
||||
attr_accessor :branch_type , :condition , :statements
|
||||
def to_s
|
||||
str = "while_#{branch_type}(#{condition}) do\n"
|
||||
str + statements.join(" ") + "\nend\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user