replace arrays with Statements class

This commit is contained in:
Torsten Ruger 2017-09-06 12:51:24 +03:00
parent 9a1e4a6f27
commit 80c3430536
7 changed files with 16 additions and 9 deletions

View File

@ -15,10 +15,15 @@ module Common
def first def first
@statements.first @statements.first
end end
def last
@statements.last
end
def length def length
@statements.length @statements.length
end end
def [](i)
@statements[i]
end
def collect(arr) def collect(arr)
@statements.each { |s| s.collect(arr) } @statements.each { |s| s.collect(arr) }
super super

View File

@ -9,6 +9,10 @@ module Mom
@if_true = if_true @if_true = if_true
@if_false = if_false @if_false = if_false
end end
def flatten
self
end
end end
end end

View File

@ -18,7 +18,7 @@ module Vool
@body.statements.each do |meth| @body.statements.each do |meth|
methods << meth.to_mom( nil ) methods << meth.to_mom( nil )
end end
methods Mom::Statements.new(methods)
end end
def collect(arr) def collect(arr)

View File

@ -15,7 +15,7 @@ module Vool
# - store the given return value, this is a SlotMove / SlotConstant # - store the given return value, this is a SlotMove / SlotConstant
# - activate return sequence (reinstantiate old message and jump to return address) # - activate return sequence (reinstantiate old message and jump to return address)
def to_mom( method ) def to_mom( method )
[Mom::SlotConstant.new([:message , :return_value] , @return_value) , Mom::Statements.new [Mom::SlotConstant.new([:message , :return_value] , @return_value) ,
Mom::ReturnSequence.new] Mom::ReturnSequence.new]
end end

View File

@ -34,7 +34,7 @@ module Vool
# in a not so distant future, temporary variables will have to be created # in a not so distant future, temporary variables will have to be created
# and complex statements hoisted to assign to them. pps: same as in conditions # and complex statements hoisted to assign to them. pps: same as in conditions
def to_mom( method ) def to_mom( method )
message_setup + call_instruction Mom::Statements.new( message_setup + call_instruction )
end end
def message_setup def message_setup

View File

@ -4,9 +4,7 @@ module Vool
# create machine instructions # create machine instructions
def to_mom( method ) def to_mom( method )
all = @statements.collect do |statement| all = @statements.collect { |statement| statement.to_mom( method ) }
statement.to_mom( method )
end
Mom::Statements.new(all) Mom::Statements.new(all)
end end

View File

@ -10,7 +10,7 @@ module Vool
end end
def test_stats def test_stats
assert_equal Array , @stats.class assert_equal Mom::Statements , @stats.class
end end
def test_class_compiles def test_class_compiles
assert_equal Mom::SlotConstant , @stats.first.class , @stats assert_equal Mom::SlotConstant , @stats.first.class , @stats