implements argument assignment

This commit is contained in:
Torsten Ruger 2017-04-13 14:14:43 +03:00
parent d2d845266e
commit 9dd4409009
6 changed files with 89 additions and 12 deletions

View File

@ -7,7 +7,12 @@ module Vool
end end
def to_mom( method ) def to_mom( method )
Mom::SlotConstant.new([:message , :frame , @name] , @value) if method.args_type.variable_index(@name)
type = :arguments
else
type = :frame
end
Mom::SlotConstant.new([:message , type , @name] , @value)
end end
end end

View File

@ -12,6 +12,10 @@ module CompilerHelper
def as_main(statements) def as_main(statements)
in_Space("def main ; #{statements}; end") in_Space("def main ; #{statements}; end")
end end
def as_test_main( statements )
in_Test("def main(arg) ; #{statements}; end")
end
end end

View File

@ -4,10 +4,10 @@ module MomCompile
include CompilerHelper include CompilerHelper
def compile_first_method input def compile_first_method input
lst = Vool::VoolCompiler.compile as_main( input ) lst = Vool::VoolCompiler.compile as_test_main( input )
assert_equal Parfait::Class , lst.clazz.class , input assert_equal Parfait::Class , lst.clazz.class , input
method = lst.clazz.get_method(:main) @method = lst.clazz.get_method(:main)
assert method assert @method
lst.to_mom( nil ).first lst.to_mom( nil ).first
end end

View File

@ -1,3 +1,4 @@
require_relative "helper" require_relative "helper"
require_relative "test_local" require_relative "test_local"
require_relative "test_ivar" require_relative "test_ivar"
require_relative "test_args"

View File

@ -0,0 +1,67 @@
require_relative "helper"
module Vool
class TestArgsMom < MiniTest::Test
include MomCompile
def setup
Risc.machine.boot
@stats = compile_first_method( "arg = 5")
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 :arguments , @stats.first.left[1]
end
def test_slot_assigns_to_local
assert_equal :arg , @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
#compiling to an argument should result in different second parameter in the slot array
class TestArgMom < MiniTest::Test
include MomCompile
def setup
Risc.machine.boot
@stats = compile_first_method( "arg = 5")
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 :arguments , @stats.first.left[1]
end
def test_slot_assigns_to_local
assert_equal :arg , @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

View File

@ -6,29 +6,29 @@ module Vool
def setup def setup
Risc.machine.boot Risc.machine.boot
@method = compile_first_method( "a = 5") @stats = compile_first_method( "a = 5")
end end
def test_class_compiles def test_class_compiles
assert_equal Mom::SlotConstant , @method.first.class , @method assert_equal Mom::SlotConstant , @stats.first.class , @stats
end end
def test_slot_is_set def test_slot_is_set
assert @method.first.left assert @stats.first.left
end end
def test_slot_starts_at_message def test_slot_starts_at_message
assert_equal :message , @method.first.left[0] assert_equal :message , @stats.first.left[0]
end end
def test_slot_gets_self def test_slot_gets_self
assert_equal :frame , @method.first.left[1] assert_equal :frame , @stats.first.left[1]
end end
def test_slot_assigns_to_local def test_slot_assigns_to_local
assert_equal :a , @method.first.left[-1] assert_equal :a , @stats.first.left[-1]
end end
def test_slot_assigns_something def test_slot_assigns_something
assert @method.first.right assert @stats.first.right
end end
def test_slot_assigns_int def test_slot_assigns_int
assert_equal IntegerStatement , @method.first.right.class assert_equal IntegerStatement , @stats.first.right.class
end end
end end
end end