add assignment and self

This commit is contained in:
Torsten Ruger 2017-04-02 12:59:07 +03:00
parent d62e996f7c
commit 27e4e9f501
6 changed files with 26 additions and 8 deletions

View File

@ -1,13 +1,11 @@
module Vool
class Assignment < Statement
attr_accessor :name , :value
def initialize(n = nil , v = nil )
@name , @value = n , v
def initialize(name , value )
@name , @value = name , value
end
end
class FieldDef < Statement
attr_accessor :name , :type , :value
class LocalAssignment < Assignment
end
end

View File

@ -17,6 +17,8 @@ module Vool
end
class NilStatement < Statement
end
class SelfStatement < Statement
end
class StringStatement < Statement
attr_accessor :value
def initialize(value)

View File

@ -86,7 +86,6 @@ module Vool
#Variables
def on_lvasgn expression
puts "EXP #{expression}"
name = expression.children[0]
value = process(expression.children[1])
LocalAssignment.new(name,value)

View File

@ -1,5 +1,5 @@
module Vool
class CallSite < Statement
class SendStatement < Statement
attr_accessor :name , :receiver , :arguments
end
end

View File

@ -0,0 +1,16 @@
require_relative "../helper"
module Vool
class TestAssignment < MiniTest::Test
def test_local
lst = Compiler.compile( "foo = bar")
assert_equal LocalAssignment , lst.class
end
def test_local_name
lst = Compiler.compile( "foo = bar")
assert_equal :foo , lst.name
end
end
end

View File

@ -1,6 +1,9 @@
require_relative "helper"
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_method_statement"
require_relative "test_send_statement"
require_relative "test_variables"