set up ivar_assignment correctly
for statement tests and write mom tests also implement to_mom and fix local (self) bug
This commit is contained in:
parent
87133722b3
commit
be10e8c6af
@ -129,7 +129,7 @@ module Vool
|
||||
def on_ivasgn expression
|
||||
name = expression.children[0]
|
||||
value = process(expression.children[1])
|
||||
InstanceAssignment.new(instance_name(name),value)
|
||||
IvarAssignment.new(instance_name(name),value)
|
||||
end
|
||||
|
||||
def on_return statement
|
||||
|
@ -51,11 +51,11 @@ end
|
||||
|
||||
|
||||
require_relative "statements/array_statement"
|
||||
require_relative "statements/assignment_statement"
|
||||
require_relative "statements/basic_values"
|
||||
require_relative "statements/class_statement"
|
||||
require_relative "statements/hash_statement"
|
||||
require_relative "statements/if_statement"
|
||||
require_relative "statements/ivar_statement"
|
||||
require_relative "statements/logical_statement"
|
||||
require_relative "statements/local_statement"
|
||||
require_relative "statements/method_statement"
|
||||
|
@ -1,4 +1,5 @@
|
||||
module Vool
|
||||
|
||||
class Assignment < Statement
|
||||
attr_reader :name , :value
|
||||
def initialize(name , value )
|
||||
@ -10,10 +11,15 @@ module Vool
|
||||
end
|
||||
end
|
||||
|
||||
class InstanceAssignment < Assignment
|
||||
class IvarAssignment < Assignment
|
||||
# used to collect type information
|
||||
def add_ivar( array )
|
||||
array << @name
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
Mom::SlotConstant.new([:message , :self , @name] , @value)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -7,7 +7,7 @@ module Vool
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
Mom::SlotConstant.new([:message , :self , @name] , @value)
|
||||
Mom::SlotConstant.new([:message , :frame , @name] , @value)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
require_relative "test_array_statement"
|
||||
require_relative "test_assignment_statement"
|
||||
require_relative "test_basic_values"
|
||||
require_relative "test_class_statement"
|
||||
require_relative "test_hash_statement"
|
||||
require_relative "test_if_statement"
|
||||
require_relative "test_ivar"
|
||||
require_relative "test_logical_statement"
|
||||
require_relative "test_method_statement"
|
||||
require_relative "test_return_statement"
|
||||
|
@ -14,7 +14,7 @@ module Vool
|
||||
|
||||
def test_instance
|
||||
lst = RubyCompiler.compile( "@foo = bar")
|
||||
assert_equal InstanceAssignment , lst.class
|
||||
assert_equal IvarAssignment , lst.class
|
||||
end
|
||||
def test_instance_name
|
||||
lst = RubyCompiler.compile( "@foo = bar")
|
@ -1 +1,14 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module MomCompile
|
||||
include CompilerHelper
|
||||
|
||||
def compile_first_method input
|
||||
lst = Vool::VoolCompiler.compile as_main( input )
|
||||
assert_equal Parfait::Class , lst.clazz.class , input
|
||||
method = lst.clazz.get_method(:main)
|
||||
assert method
|
||||
lst.to_mom( nil ).first
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,3 +1,3 @@
|
||||
require_relative "helper"
|
||||
require_relative "test_local"
|
||||
require_relative "test_ivar_assignment"
|
||||
require_relative "test_ivar"
|
||||
|
34
test/vool/to_mom/test_ivar.rb
Normal file
34
test/vool/to_mom/test_ivar.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestIvarMom < MiniTest::Test
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@method = compile_first_method( "@a = 5")
|
||||
end
|
||||
|
||||
def test_class_compiles
|
||||
assert_equal Mom::SlotConstant , @method.first.class , @method
|
||||
end
|
||||
def test_slot_is_set
|
||||
assert @method.first.left
|
||||
end
|
||||
def test_slot_starts_at_message
|
||||
assert_equal :message , @method.first.left[0]
|
||||
end
|
||||
def test_slot_gets_self
|
||||
assert_equal :self , @method.first.left[1]
|
||||
end
|
||||
def test_slot_assigns_to_local
|
||||
assert_equal :a , @method.first.left[-1]
|
||||
end
|
||||
def test_slot_assigns_something
|
||||
assert @method.first.right
|
||||
end
|
||||
def test_slot_assigns_int
|
||||
assert_equal IntegerStatement , @method.first.right.class
|
||||
end
|
||||
end
|
||||
end
|
@ -2,21 +2,13 @@ require_relative "helper"
|
||||
|
||||
module Vool
|
||||
class TestLocalMom < MiniTest::Test
|
||||
include CompilerHelper
|
||||
include MomCompile
|
||||
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@method = compile_first_method( "a = 5")
|
||||
end
|
||||
|
||||
def compile_first_method input
|
||||
lst = VoolCompiler.compile as_main( input )
|
||||
assert_equal Parfait::Class , lst.clazz.class , input
|
||||
method = lst.clazz.get_method(:main)
|
||||
assert method
|
||||
lst.to_mom( nil ).first
|
||||
end
|
||||
|
||||
def test_class_compiles
|
||||
assert_equal Mom::SlotConstant , @method.first.class , @method
|
||||
end
|
||||
@ -27,7 +19,7 @@ module Vool
|
||||
assert_equal :message , @method.first.left[0]
|
||||
end
|
||||
def test_slot_gets_self
|
||||
assert_equal :self , @method.first.left[1]
|
||||
assert_equal :frame , @method.first.left[1]
|
||||
end
|
||||
def test_slot_assigns_to_local
|
||||
assert_equal :a , @method.first.left[-1]
|
||||
|
Loading…
Reference in New Issue
Block a user