collapsed slot classes into one

different slot operation have different right sides
mom assignment tests work again
157 others don’t
This commit is contained in:
Torsten Ruger
2018-03-15 20:33:38 +05:30
parent 3247c2036c
commit 79bf416e58
23 changed files with 140 additions and 233 deletions

View File

@ -10,23 +10,32 @@ module Vool
raise "not named left #{name.class}" unless @name.is_a?(Symbol)
raise "unsupported right #{value}" unless @value.is_a?(Named) or
@value.is_a?(SendStatement) or @value.is_a?(Constant)
self
end
def collect(arr)
@value.collect(arr)
super
def chain_assign(assign , method)
return assign unless @value.is_a?(SendStatement)
first = @value.to_mom(method)
first.next = assign
return first
end
def each(&block)
block.call(self)
@value.each(&block)
end
end
class IvarAssignment < Assignment
# used to collect type information
def add_ivar( array )
array << @name
def normalize()
super()
return IvarAssignment.new(@name , @value)
end
def to_mom( method )
@value.slot_class.new([:message , :receiver , @name] , @value.to_mom(method))
to = Mom::SlotDefinition.new(:message ,[ :receiver , @name])
from = @value.slot_definition(method)
return chain_assign( Mom::SlotLoad.new(to,from) , method)
end
end

View File

@ -1,13 +1,6 @@
module Vool
class Statement
def slot_class
Mom::SlotMove
end
end
class Constant < Expression
def slot_class
Mom::SlotConstant
end
end
class IntegerConstant < Constant
@ -15,12 +8,15 @@ module Vool
def initialize(value)
@value = value
end
def to_mom(method)
def slot_definition(method)
return Mom::IntegerConstant.new(@value)
end
def ct_type
Parfait.object_space.get_class_by_name(:Integer).instance_type
end
#gobble it up
def each(&block)
end
end
class FloatConstant < Constant
attr_reader :value
@ -63,7 +59,7 @@ module Vool
def initialize(value)
@value = value
end
def to_mom(method)
def slot_definition(method)
return Mom::StringConstant.new(@value)
end
def ct_type

View File

@ -5,7 +5,6 @@ module Vool
def initialize( name , supe , body)
@name , @super_class_name , @body = name , supe , body
@body = ScopeStatement.new([]) unless body
end
def normalize

View File

@ -30,6 +30,26 @@ module Vool
check
end
def flatten(options = {})
true_label = Label.new( "true_label_#{object_id}")
false_label = Label.new( "false_label_#{object_id}")
merge_label = Label.new( "merge_label_#{object_id}")
first = condition.flatten( true_label: true_label , false_label: false_label)
if hoisted
head = hoisted.flatten
head.append first
else
head = first
end
head.append true_label
head.append if_true.flatten( merge_label: merge_label)
if( if_false)
head.append false_label
head.append if_false.flatten( merge_label: merge_label)
end
head.append merge_label
head
end
def collect(arr)
@if_true.collect(arr)

View File

@ -1,9 +1,10 @@
module Vool
class LocalAssignment < Assignment
# used to collect frame information
def add_local( array )
array << @name
def normalize
super
return LocalAssignment.new(@name , @value)
end
def to_mom( method )
@ -12,9 +13,9 @@ module Vool
else
type = :frame
end
statements = @value.to_mom(method)
statements << @value.slot_class.new([:message , type , @name] , @value.slot_definition)
return statements
to = Mom::SlotDefinition.new(:message ,[ type , @name])
from = @value.slot_definition(method)
return chain_assign( Mom::SlotLoad.new(to,from) , method)
end
end

View File

@ -4,7 +4,7 @@ module Vool
def initialize( name , args , body , clazz = nil)
@name , @args , @body = name , args , body
@body = ScopeStatement.new([]) unless body
raise "no bod" unless body
@clazz = clazz
end
@ -34,7 +34,7 @@ module Vool
@clazz.add_method( method )
typed_method = method.create_parfait_method(clazz.instance_type)
compiler = Risc::MethodCompiler.new( typed_method ).init_method
head = @body.to_mom( method ).flatten
head = @body.to_mom( method )
compiler.add_mom(head)
end

View File

@ -4,8 +4,12 @@ module Vool
# create machine instructions
def to_mom( method )
all = @statements.collect { |statement| statement.to_mom( method ) }
Mom::Statements.new(all)
raise "Empty list ? #{statements.length}" unless @statements[0]
flat = @statements.shift.to_mom(method)
while( nekst = @statements.shift )
flat.append nekst.to_mom(method)
end
flat
end
def create_objects

View File

@ -4,11 +4,13 @@ module Vool
def initialize name
@name = name
end
def each(&block)
end
end
class LocalVariable < Expression
include Named
def to_mom(method)
def slot_definition(method)
if method.args_type.variable_index(@name)
type = :arguments
else
@ -20,7 +22,7 @@ module Vool
class InstanceVariable < Expression
include Named
def to_mom(method)
def slot_definition(method)
Mom::SlotDefinition.new(:message , [ :receiver , @name] )
end
# used to collect type information

View File

@ -27,6 +27,16 @@ module Vool
check
end
def flatten(options = {})
merge_label = Label.new( "merge_label_#{object_id}")
cond_label = Label.new( "cond_label_#{object_id}")
@nekst = cond_label
@nekst.append(hoisted.flatten) if hoisted
@nekst.append condition.flatten( true_label: cond_label , false_label: merge_label)
@nekst.append merge_label
@nekst
end
def simplify_condition
return unless @condition.is_a?(ScopeStatement)
@condition = @condition.first if @condition.single?