starting to_risc descent

just fleshing it for now
This commit is contained in:
Torsten Ruger
2018-03-13 16:16:06 +05:30
parent b297650b78
commit 96800fd8fd
13 changed files with 245 additions and 25 deletions

View File

@ -16,6 +16,9 @@ module Mom
def initialize(name)
@name = name
end
def to_risc(compiler)
Risc::Label.new(self,name)
end
end
end

View File

@ -16,6 +16,11 @@ module Mom
def initialize(method)
@method = method
end
def to_risc(compiler)
Risc::Label.new(self,method.name)
end
end

View File

@ -12,5 +12,9 @@ module Mom
def initialize(left, right)
@left , @right = left , right
end
def to_risc(compiler)
Risc::Label.new(self,"nosense")
end
end
end

View File

@ -33,6 +33,11 @@ module Mom
raise "left not SlotDefinition, #{left}" unless left.is_a? SlotDefinition
# raise "right not Mom, #{right.to_rxf}" unless right.class.name.include?("Mom")
end
def to_risc(compiler)
Risc::Label.new(self,"nosense")
end
end
# A SlotConstant moves a constant into a known Slot.
@ -52,6 +57,9 @@ module Mom
#SlotMove is a SlotLoad where the right side is a slot, just like the left.
class SlotMove < SlotLoad
def to_risc(compiler)
end
end
class SlotDefinition

View File

@ -1,5 +1,6 @@
module Mom
class Statement
include Common::List
# flattening will change the structure from a tree to a linked list (and use
# nekst to do so)
def flatten(options = {})
@ -18,6 +19,12 @@ module Mom
flat
end
def initialize(arr)
super(arr)
arr.each {|s|
raise "Not a Statement #{s}" unless s.is_a?( Statement) or s.is_a?(Instruction)
}
end
end
end

View File

@ -18,5 +18,10 @@ module Mom
def initialize(condition)
@condition = condition
end
def to_risc(compiler)
Risc::Label.new(self,"nosense")
end
end
end

View File

@ -11,13 +11,13 @@ module Mom
end
def flatten(options = {})
cond_label = Label.new( "cond_label_#{object_id}")
head = cond_label
head.append hoisted.flatten
merge_label = Label.new( "merge_label_#{object_id}")
head.append condition.flatten( true_label: cond_label , false_label: merge_label)
head.append merge_label
head
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
end

View File

@ -18,7 +18,7 @@ module Risc
@source = source
@next = nekst
return unless source
raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(Vm::Code)
raise "Source must be string or ast node, not #{source.class}" unless source.is_a?(String) or source.is_a?(Mom::Instruction)
end
attr_reader :source

View File

@ -33,14 +33,10 @@ module Vool
locals_type = make_locals
method = Parfait::VoolMethod.new(name , args_type , locals_type , body )
@clazz.add_method( method )
end
def compile_methods(clazz , methods)
methods.each do |method|
code = Passes::MethodCompiler.new(method).get_code
typed_method = method.create_parfait_method(clazz.instance_type)
Risc::MethodCompiler.new( typed_method ).init_method.process( code )
end
typed_method = method.create_parfait_method(clazz.instance_type)
compiler = Risc::MethodCompiler.new( typed_method ).init_method
head = @body.to_mom( method ).flatten
head.to_risc(compiler)
end
private