start on class compiler
idea is to get cleaner layer seperation reduce machine and rework builtin boot
This commit is contained in:
10
lib/mom/class_compiler.rb
Normal file
10
lib/mom/class_compiler.rb
Normal file
@ -0,0 +1,10 @@
|
||||
module Mom
|
||||
class ClassCompiler
|
||||
attr_reader :clazz , :methods
|
||||
|
||||
def initialize(clazz , methods)
|
||||
@clazz = clazz
|
||||
@methods = methods
|
||||
end
|
||||
end
|
||||
end
|
@ -15,3 +15,4 @@ module Mom
|
||||
end
|
||||
|
||||
require_relative "instruction/instruction.rb"
|
||||
require_relative "class_compiler"
|
||||
|
@ -20,6 +20,7 @@ module Parfait
|
||||
raise "args_type must be type" unless args_type.is_a?(Parfait::Type)
|
||||
raise "frame_type must be type" unless frame_type.is_a?(Parfait::Type)
|
||||
raise "source must be vool" unless source.is_a?(Vool::Statement)
|
||||
raise "Empty bod" if(source.is_a?(Vool::Statements) and source.empty?)
|
||||
end
|
||||
|
||||
def create_typed_method( type )
|
||||
@ -27,6 +28,11 @@ module Parfait
|
||||
type.create_method( @name , @args_type , @frame_type)
|
||||
end
|
||||
|
||||
def compile_to_mom(for_type)
|
||||
typed_method = create_typed_method(for_type)
|
||||
source.to_mom( typed_method )
|
||||
end
|
||||
|
||||
def compile_to_risc(for_type)
|
||||
typed_method = create_typed_method(for_type)
|
||||
head = source.to_mom( typed_method )
|
||||
|
@ -24,12 +24,12 @@ module Vool
|
||||
|
||||
def to_mom( _ )
|
||||
create_class_object
|
||||
mom = []
|
||||
methods = []
|
||||
body.statements.each do |node|
|
||||
raise "Only methods for now #{node}" unless node.is_a?(MethodStatement)
|
||||
mom << node.to_mom(@clazz)
|
||||
methods << node.to_mom(@clazz)
|
||||
end
|
||||
mom
|
||||
Mom::ClassCompiler.new(@clazz , methods)
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
|
@ -31,8 +31,9 @@ module Vool
|
||||
# create mom instructions
|
||||
def to_mom( method )
|
||||
raise "Empty list ? #{statements.length}" if empty?
|
||||
flat = @statements.shift.to_mom(method)
|
||||
while( nekst = @statements.shift )
|
||||
stats = @statements.dup
|
||||
flat = stats.shift.to_mom(method)
|
||||
while( nekst = stats.shift )
|
||||
flat.append nekst.to_mom(method)
|
||||
end
|
||||
flat
|
||||
|
Reference in New Issue
Block a user