fix ruby variables
This commit is contained in:
parent
f4402ba30f
commit
98788b52d3
@ -6,6 +6,9 @@ module Ruby
|
||||
end
|
||||
def each(&block)
|
||||
end
|
||||
def to_vool
|
||||
vool_brother.new(@name)
|
||||
end
|
||||
end
|
||||
|
||||
class LocalVariable < Statement
|
||||
|
@ -16,14 +16,4 @@ module Vool
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class IvarAssignment < Assignment
|
||||
|
||||
def to_mom( compiler )
|
||||
to = Mom::SlotDefinition.new(:message ,[ :receiver , @name])
|
||||
from = @value.slot_definition(compiler)
|
||||
return chain_assign( Mom::SlotLoad.new(to,from) , compiler)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
12
lib/vool/ivar_assignment.rb
Normal file
12
lib/vool/ivar_assignment.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module Vool
|
||||
|
||||
class IvarAssignment < Assignment
|
||||
|
||||
def to_mom( compiler )
|
||||
to = Mom::SlotDefinition.new(:message ,[ :receiver , @name])
|
||||
from = @value.slot_definition(compiler)
|
||||
return chain_assign( Mom::SlotLoad.new(to,from) , compiler)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -61,7 +61,7 @@ module Vool
|
||||
end
|
||||
|
||||
|
||||
require_relative "assign_statement"
|
||||
require_relative "assignment"
|
||||
require_relative "array_statement"
|
||||
require_relative "basic_values"
|
||||
require_relative "block_statement"
|
||||
@ -69,6 +69,7 @@ require_relative "class_statement"
|
||||
require_relative "hash_statement"
|
||||
require_relative "if_statement"
|
||||
require_relative "logical_statement"
|
||||
require_relative "ivar_assignment"
|
||||
require_relative "local_assignment"
|
||||
require_relative "method_statement"
|
||||
require_relative "return_statement"
|
||||
|
@ -55,4 +55,40 @@ module Ruby
|
||||
assert_raises {compile( "M::Module" ) }
|
||||
end
|
||||
end
|
||||
class TestVariablesVool < MiniTest::Test
|
||||
include RubyTests
|
||||
def test_local_basic
|
||||
lst = compile( "foo = 1 ; foo").to_vool
|
||||
assert_equal Vool::LocalVariable , lst.statements[1].class
|
||||
end
|
||||
|
||||
def test_instance_basic
|
||||
lst = compile( "@var" ).to_vool
|
||||
assert_equal Vool::InstanceVariable , lst.class
|
||||
assert_equal :var , lst.name
|
||||
end
|
||||
|
||||
def test_instance_return
|
||||
lst = compile( "return @var" ).to_vool
|
||||
assert_equal InstanceVariable , lst.return_value.class
|
||||
end
|
||||
|
||||
def test_class_basic
|
||||
lst = compile( "@@var" ).to_vool
|
||||
assert_equal Vool::ClassVariable , lst.class
|
||||
assert_equal :var , lst.name
|
||||
end
|
||||
|
||||
def test_class_return
|
||||
lst = compile( "return @@var" ).to_vool
|
||||
assert_equal ClassVariable , lst.return_value.class
|
||||
end
|
||||
|
||||
def test_module_basic
|
||||
lst = compile( "Module" ).to_vool
|
||||
assert_equal Vool::ModuleName , lst.class
|
||||
assert_equal :Module , lst.name
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user