ads to_s to ast for better readability

This commit is contained in:
Torsten Ruger 2014-05-13 10:49:26 +03:00
parent 140d33b167
commit dd05b30230
4 changed files with 19 additions and 3 deletions

View File

@ -10,6 +10,9 @@ module Ast
def inspect def inspect
self.class.name + ".new(" + value.to_s+ ")" self.class.name + ".new(" + value.to_s+ ")"
end end
def to_s
value.to_s
end
def compile context def compile context
Vm::Signed.new value Vm::Signed.new value
end end
@ -31,6 +34,9 @@ module Ast
def inspect def inspect
self.class.name + '.new("' + name + '")' self.class.name + '.new("' + name + '")'
end end
def to_s
name
end
def attributes def attributes
[:name] [:name]
end end

View File

@ -13,7 +13,11 @@ module Ast
block.collect{|m| m.inspect }.join( ",") +"] )" block.collect{|m| m.inspect }.join( ",") +"] )"
end end
def to_s
"def #{name}( " + params.join(",") + ") \n" + block.join("\n") + "end\n"
end
def compile context def compile context
raise self.to_s
parent_locals = context.locals parent_locals = context.locals
context.locals = {} context.locals = {}
args = [] args = []

View File

@ -7,7 +7,6 @@ module Ast
def initialize name, args def initialize name, args
@name , @args = name , args @name , @args = name , args
end end
def compile context def compile context
fun = Vm::FunctionCall.new( name , args.collect{ |a| a.compile(context) } ) fun = Vm::FunctionCall.new( name , args.collect{ |a| a.compile(context) } )
fun.assign_function context fun.assign_function context
@ -19,7 +18,9 @@ module Ast
self.class.name + ".new(" + name.inspect + ", ["+ self.class.name + ".new(" + name.inspect + ", ["+
args.collect{|m| m.inspect }.join( ",") +"] )" args.collect{|m| m.inspect }.join( ",") +"] )"
end end
def to_s
"#{name}(" + args.join(",") + ")"
end
def attributes def attributes
[:name , :args] [:name , :args]
end end
@ -37,7 +38,9 @@ module Ast
def inspect def inspect
self.class.name + ".new(" + operator.inspect + ", " + left.inspect + "," + right.inspect + ")" self.class.name + ".new(" + operator.inspect + ", " + left.inspect + "," + right.inspect + ")"
end end
def to_s
"#{left} #{operator} #{right}"
end
def compile context def compile context
parent_locals = context.locals parent_locals = context.locals
context.locals = {} context.locals = {}

View File

@ -7,6 +7,9 @@ module Ast
def inspect def inspect
self.class.name + ".new(" + condition.inspect + ", " + body.inspect + " )" self.class.name + ".new(" + condition.inspect + ", " + body.inspect + " )"
end end
def to_s
"while(#{condition}) do\n" + body.join("\n") + "\nend\n"
end
def attributes def attributes
[:condition, :body] [:condition, :body]
end end