ads to_s to ast for better readability
This commit is contained in:
parent
140d33b167
commit
dd05b30230
@ -10,6 +10,9 @@ module Ast
|
||||
def inspect
|
||||
self.class.name + ".new(" + value.to_s+ ")"
|
||||
end
|
||||
def to_s
|
||||
value.to_s
|
||||
end
|
||||
def compile context
|
||||
Vm::Signed.new value
|
||||
end
|
||||
@ -31,6 +34,9 @@ module Ast
|
||||
def inspect
|
||||
self.class.name + '.new("' + name + '")'
|
||||
end
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
def attributes
|
||||
[:name]
|
||||
end
|
||||
|
@ -13,7 +13,11 @@ module Ast
|
||||
block.collect{|m| m.inspect }.join( ",") +"] )"
|
||||
end
|
||||
|
||||
def to_s
|
||||
"def #{name}( " + params.join(",") + ") \n" + block.join("\n") + "end\n"
|
||||
end
|
||||
def compile context
|
||||
raise self.to_s
|
||||
parent_locals = context.locals
|
||||
context.locals = {}
|
||||
args = []
|
||||
|
@ -7,7 +7,6 @@ module Ast
|
||||
def initialize name, args
|
||||
@name , @args = name , args
|
||||
end
|
||||
|
||||
def compile context
|
||||
fun = Vm::FunctionCall.new( name , args.collect{ |a| a.compile(context) } )
|
||||
fun.assign_function context
|
||||
@ -19,7 +18,9 @@ module Ast
|
||||
self.class.name + ".new(" + name.inspect + ", ["+
|
||||
args.collect{|m| m.inspect }.join( ",") +"] )"
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{name}(" + args.join(",") + ")"
|
||||
end
|
||||
def attributes
|
||||
[:name , :args]
|
||||
end
|
||||
@ -37,7 +38,9 @@ module Ast
|
||||
def inspect
|
||||
self.class.name + ".new(" + operator.inspect + ", " + left.inspect + "," + right.inspect + ")"
|
||||
end
|
||||
|
||||
def to_s
|
||||
"#{left} #{operator} #{right}"
|
||||
end
|
||||
def compile context
|
||||
parent_locals = context.locals
|
||||
context.locals = {}
|
||||
|
@ -7,6 +7,9 @@ module Ast
|
||||
def inspect
|
||||
self.class.name + ".new(" + condition.inspect + ", " + body.inspect + " )"
|
||||
end
|
||||
def to_s
|
||||
"while(#{condition}) do\n" + body.join("\n") + "\nend\n"
|
||||
end
|
||||
def attributes
|
||||
[:condition, :body]
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user