fixes the tests after fixing hierarchy

This commit is contained in:
Torsten Ruger
2014-07-15 10:35:29 +03:00
parent 49f73c090d
commit 930740e1db
11 changed files with 79 additions and 25 deletions

View File

@ -3,10 +3,13 @@ module Virtual
class Constant < ::Virtual::Value
end
class TrueValue < Constant
def attributes ; [] ; end
end
class FalseValue < Constant
def attributes ; [] ; end
end
class NilValue < Constant
def attributes ; [] ; end
end
# another abstract "marker" class (so we can check for it)
@ -19,7 +22,7 @@ module Virtual
@integer = int
end
attr_reader :integer
def attributes
def attributes
[:integer]
end
def inspect

View File

@ -30,14 +30,17 @@ module Virtual
#
def compile_get method , name
method.add FrameGet.new(name)
method.get_var(name)
end
def compile_send method , name , with = []
method.add FrameSend.new(name , with )
Return.new( method.return_type )
end
def compile_set method , name , val
method.add FrameSet.new(name , val )
method.get_var(name)
end
end
end

View File

@ -18,9 +18,6 @@ module Virtual
def initialize nex = nil
@next = nex
end
def type
Reference
end
end
# the first instruction we need is to stop. Off course in a real machine this would be a syscall, but that is just

View File

@ -17,7 +17,7 @@ module Virtual
def attributes
[:name , :args , :receiver , :return_type , :start]
end
def initialize name , args , receiver = Virtual::SelfReference.new , return_type = Virtual::Reference , start = MethodEnter.new
def initialize name , args , receiver = Virtual::SelfReference.new , return_type = Virtual::Mystery , start = MethodEnter.new
@name = name.to_sym
@args = args
@locals = []
@ -34,7 +34,6 @@ module Virtual
raise instruction.inspect unless instruction.is_a? Instruction
@current.next = instruction
@current = instruction
instruction.type
end
# determine whether this method has a variable by the given name
@ -46,7 +45,8 @@ module Virtual
var = @tmps.find {|a| a == name } unless var
var
end
alias :get_var :has_var
def get_tmp
name = "__tmp__#{@tmps.length}"
@tmps << name

View File

@ -48,7 +48,9 @@ module Virtual
class Mystery < Type
def initialize
end
def attributes
[]
end
def as type
type.new
end

View File

@ -9,15 +9,65 @@ module Virtual
def == other
other.class == self.class
end
def inspect
self.class.name + ".new()"
end
def type
raise "abstract called"
raise "abstract called for #{self.class}"
end
def attributes
raise "abstract called for #{self.class}"
end
def == other
return false unless other.class == self.class
attributes.each do |a|
left = send(a)
right = other.send(a)
return false unless left.class == right.class
return false unless left == right
end
return true
end
def inspect
self.class.name + ".new(" + attributes.collect{|a| send(a).inspect }.join(",")+ ")"
end
private
def initialize
end
end
class Variable < Value
def initialize name , type
@name = name
@type = type
end
attr_accessor :name , :type
def attributes
[:name , :type]
end
end
# The subclasses are not strictly speaking neccessary at this def point
# i just don't want to destroy the information for later optimizations
#
# All variables are stored in frames and quite possibly in order arg,local,tmp
class Return < Variable
def initialize type
super(:return , type)
end
def attributes
[:type]
end
end
class Self < Variable
def initialize type
super(:self , type)
end
def attributes
[:type]
end
end
class Argument < Variable
end
class Local < Variable
end
class Temp < Variable
end
end