implements inspect for copy paste into tests
This commit is contained in:
parent
051b0ea7dc
commit
20128627c7
@ -7,11 +7,14 @@ module Ast
|
||||
def initialize val
|
||||
@value = val
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(" + value.to_s+ ")"
|
||||
end
|
||||
def compile context
|
||||
Vm::Signed.new value
|
||||
end
|
||||
def == other
|
||||
compare other , [:value]
|
||||
def attributes
|
||||
[:value]
|
||||
end
|
||||
end
|
||||
|
||||
@ -20,8 +23,11 @@ module Ast
|
||||
def initialize name
|
||||
@name = name
|
||||
end
|
||||
def == other
|
||||
compare other , [:name]
|
||||
def inspect
|
||||
self.class.name + ".new(" + name + ")"
|
||||
end
|
||||
def attributes
|
||||
[:name]
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,14 +36,17 @@ module Ast
|
||||
def initialize str
|
||||
@string = str
|
||||
end
|
||||
def inspectt
|
||||
"#{string}"
|
||||
end
|
||||
|
||||
def compile context
|
||||
value = Vm::StringLiteral.new(string)
|
||||
context.program.add_object value
|
||||
value
|
||||
end
|
||||
def == other
|
||||
compare other , [:string]
|
||||
def attributes
|
||||
[:string]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,8 +4,9 @@ module Ast
|
||||
def initialize cond, if_true, if_false
|
||||
@cond, @if_true, @if_false = cond, if_true, if_false
|
||||
end
|
||||
def == other
|
||||
compare other , [:cond, :if_true, :if_false]
|
||||
|
||||
def attributes
|
||||
[:cond, :if_true, :if_false]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -15,7 +15,13 @@ module Ast
|
||||
def compile context
|
||||
raise "abstract #{self}"
|
||||
end
|
||||
def compare other , attributes
|
||||
def inspectt
|
||||
self.class.name + ".new(" + self.attributes.collect{|m| self.send(m).inspect }.join( ",") +")"
|
||||
end
|
||||
def attributes
|
||||
raise "abstract #{self}"
|
||||
end
|
||||
def == other
|
||||
return false unless other.class == self.class
|
||||
attributes.each do |a|
|
||||
left = send(a)
|
||||
|
@ -4,8 +4,13 @@ module Ast
|
||||
def initialize name, params, block
|
||||
@name, @params, @block = name, params, block
|
||||
end
|
||||
def == other
|
||||
compare other , [:name, :params, :block]
|
||||
def attributes
|
||||
[:name, :params, :block]
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(" + name.inspect + ", ["+
|
||||
params.collect{|m| m.inspect }.join( ",") +"] , [" +
|
||||
block.collect{|m| m.inspect }.join( ",") +"] )"
|
||||
end
|
||||
|
||||
def compile context
|
||||
|
@ -15,9 +15,13 @@ module Ast
|
||||
fun.do_call
|
||||
fun
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(" + name.inspect + ", ["+
|
||||
args.collect{|m| m.inspect }.join( ",") +"] )"
|
||||
end
|
||||
|
||||
def == other
|
||||
compare other , [:name , :args]
|
||||
def attributes
|
||||
[:name , :args]
|
||||
end
|
||||
end
|
||||
|
||||
@ -26,14 +30,17 @@ module Ast
|
||||
def initialize assignee, assigned
|
||||
@assignee, @assigned = assignee, assigned
|
||||
end
|
||||
def inspect
|
||||
self.class.name + ".new(" + assignee + ", " + assigned.inspect+ ")"
|
||||
end
|
||||
|
||||
def compile context
|
||||
var = @assigned.compile(context)
|
||||
context.locals[@assignee] = var
|
||||
end
|
||||
|
||||
def == other
|
||||
compare other , [:assignee, :assigned]
|
||||
def attributes
|
||||
[:assignee, :assigned]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user