start implementing return for constant
This commit is contained in:
parent
73b7e2b22f
commit
c885888f4a
@ -10,5 +10,14 @@ module Vool
|
||||
@return_value.collect(arr)
|
||||
super
|
||||
end
|
||||
|
||||
# To return form a method in mom instructions we need to do three things:
|
||||
# - store the given return value, this is a SlotMove / SlotConstant
|
||||
# - restore the previous message
|
||||
# - jump to the return address
|
||||
def to_mom( method )
|
||||
[Mom::SlotConstant.new([:message , :return_value] , @return_value)]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ module Vool
|
||||
def test_slot_starts_at_message
|
||||
assert_equal :message , @stats.first.left[0]
|
||||
end
|
||||
def test_slot_gets_self
|
||||
def test_slot_gets_frame
|
||||
assert_equal :frame , @stats.first.left[1]
|
||||
end
|
||||
def test_slot_assigns_to_local
|
||||
|
31
test/vool/to_mom/test_return.rb
Normal file
31
test/vool/to_mom/test_return.rb
Normal file
@ -0,0 +1,31 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestReturnMom < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@stats = compile_first_method( "return 5").first
|
||||
end
|
||||
|
||||
def test_class_compiles
|
||||
assert_equal Mom::SlotConstant , @stats.first.class , @stats
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @stats.first.left
|
||||
end
|
||||
def test_slot_starts_at_message
|
||||
assert_equal :message , @stats.first.left[0]
|
||||
end
|
||||
def test_slot_gets_self
|
||||
assert_equal :return_value , @stats.first.left[1]
|
||||
end
|
||||
def test_slot_assigns_something
|
||||
assert @stats.first.right
|
||||
end
|
||||
def test_slot_assigns_int
|
||||
assert_equal IntegerStatement , @stats.first.right.class
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user