diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index 69e6d085..624697d6 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -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 diff --git a/lib/ast/function_expression.rb b/lib/ast/function_expression.rb index 144b9a66..4b57e5d8 100644 --- a/lib/ast/function_expression.rb +++ b/lib/ast/function_expression.rb @@ -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 = [] diff --git a/lib/ast/operator_expressions.rb b/lib/ast/operator_expressions.rb index 21a7e16d..1793a365 100644 --- a/lib/ast/operator_expressions.rb +++ b/lib/ast/operator_expressions.rb @@ -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 = {} diff --git a/lib/ast/while_expression.rb b/lib/ast/while_expression.rb index c78953f1..e20e4def 100644 --- a/lib/ast/while_expression.rb +++ b/lib/ast/while_expression.rb @@ -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