diff --git a/lib/vool/statement.rb b/lib/vool/statement.rb index 243e6ae5..c64fb807 100644 --- a/lib/vool/statement.rb +++ b/lib/vool/statement.rb @@ -24,6 +24,12 @@ module Vool def collect(arr) arr << self end + + def to_mom( _ ) + # temporary warning to find unimplemented kids + raise "Not implemented for #{self}" + end + # create corresponding parfait objects, ie classes, types, methods # mainly implemented by class/method statement def create_objects diff --git a/lib/vool/statements/class_statement.rb b/lib/vool/statements/class_statement.rb index e6e0e4fe..6a0e177f 100644 --- a/lib/vool/statements/class_statement.rb +++ b/lib/vool/statements/class_statement.rb @@ -11,6 +11,16 @@ module Vool 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) @body.collect(arr) super diff --git a/lib/vool/statements/method_statement.rb b/lib/vool/statements/method_statement.rb index 8c1591b7..01917237 100644 --- a/lib/vool/statements/method_statement.rb +++ b/lib/vool/statements/method_statement.rb @@ -3,7 +3,20 @@ module Vool attr_reader :name, :args , :body , :clazz 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 def collect(arr) diff --git a/lib/vool/statements/statements.rb b/lib/vool/statements/statements.rb index 864c5b2a..a9d2388f 100644 --- a/lib/vool/statements/statements.rb +++ b/lib/vool/statements/statements.rb @@ -4,6 +4,14 @@ module Vool def initialize(statements) @statements = statements end + + # create machine instructions + def to_mom( method ) + @statements.collect do |statement| + statement.to_mom( method ) + end + end + def empty? @statements.empty? end diff --git a/test/vool/to_mom/helper.rb b/test/vool/to_mom/helper.rb new file mode 100644 index 00000000..26258082 --- /dev/null +++ b/test/vool/to_mom/helper.rb @@ -0,0 +1 @@ +require_relative "../helper"