adds basic to_mom machinery for class and method statement

This commit is contained in:
Torsten Ruger 2017-04-12 11:52:23 +03:00
parent a4b0666c8c
commit 1deca34c23
5 changed files with 39 additions and 1 deletions

View File

@ -24,6 +24,12 @@ module Vool
def collect(arr) def collect(arr)
arr << self arr << self
end end
def to_mom( _ )
# temporary warning to find unimplemented kids
raise "Not implemented for #{self}"
end
# create corresponding parfait objects, ie classes, types, methods # create corresponding parfait objects, ie classes, types, methods
# mainly implemented by class/method statement # mainly implemented by class/method statement
def create_objects def create_objects

View File

@ -11,6 +11,16 @@ module Vool
end end
end end
# compilation to the next layer, mom
# context coming in for class is nil, also for methods, henceafter a method is passed down
def to_mom( _ )
methods = []
@body.statements.each do |meth|
methods << meth.to_mom( nil )
end
methods
end
def collect(arr) def collect(arr)
@body.collect(arr) @body.collect(arr)
super super

View File

@ -3,7 +3,20 @@ module Vool
attr_reader :name, :args , :body , :clazz attr_reader :name, :args , :body , :clazz
def initialize( name , args , body) def initialize( name , args , body)
@name , @args , @body = name , args , (body || []) @name , @args , @body = name , args , body
unless( body.is_a?(ScopeStatement))
@body = ScopeStatement.new([])
@body.statements << body if body
end
end
# compile to mom instructions. methods themselves do no result in instructions (yet)
# instead the resulting instruction tree is saved into the method object that
# represents the method
def to_mom( _ )
method = @clazz.get_method( @name )
@body.to_mom(method)
end end
def collect(arr) def collect(arr)

View File

@ -4,6 +4,14 @@ module Vool
def initialize(statements) def initialize(statements)
@statements = statements @statements = statements
end end
# create machine instructions
def to_mom( method )
@statements.collect do |statement|
statement.to_mom( method )
end
end
def empty? def empty?
@statements.empty? @statements.empty?
end end

View File

@ -0,0 +1 @@
require_relative "../helper"