add send statement
This commit is contained in:
parent
93f9d16209
commit
d62e996f7c
@ -4,6 +4,7 @@ module Vool
|
||||
end
|
||||
|
||||
require_relative "vool/array_statement"
|
||||
require_relative "vool/assignment_statement"
|
||||
require_relative "vool/basic_values"
|
||||
require_relative "vool/class_statement"
|
||||
require_relative "vool/hash_statement"
|
||||
@ -13,8 +14,7 @@ require_relative "vool/while_statement"
|
||||
require_relative "vool/if_statement"
|
||||
require_relative "vool/return_statement"
|
||||
require_relative "vool/statements"
|
||||
require_relative "vool/send_statement"
|
||||
require_relative "vool/operator_expression"
|
||||
require_relative "vool/call_site_statement"
|
||||
require_relative "vool/assignment_statement"
|
||||
|
||||
require_relative "vool/compiler"
|
||||
|
@ -27,6 +27,14 @@ module Vool
|
||||
end
|
||||
|
||||
#basic Values
|
||||
def on_self exp
|
||||
SelfStatement.new
|
||||
end
|
||||
|
||||
def on_nil expression
|
||||
NilStatement.new
|
||||
end
|
||||
|
||||
def on_int expression
|
||||
IntegerStatement.new(expression.children.first)
|
||||
end
|
||||
@ -43,10 +51,6 @@ module Vool
|
||||
FalseStatement.new
|
||||
end
|
||||
|
||||
def on_nil expression
|
||||
NilStatement.new
|
||||
end
|
||||
|
||||
def on_str expression
|
||||
StringStatement.new(expression.children.first)
|
||||
end
|
||||
@ -80,6 +84,14 @@ module Vool
|
||||
hash
|
||||
end
|
||||
|
||||
#Variables
|
||||
def on_lvasgn expression
|
||||
puts "EXP #{expression}"
|
||||
name = expression.children[0]
|
||||
value = process(expression.children[1])
|
||||
LocalAssignment.new(name,value)
|
||||
end
|
||||
|
||||
def on_return statement
|
||||
w = ReturnStatement.new()
|
||||
w.return_value = process(statement.children.first)
|
||||
@ -132,12 +144,15 @@ module Vool
|
||||
process expression.children.first
|
||||
end
|
||||
|
||||
def on_call statement
|
||||
name_s , arguments , receiver = *statement
|
||||
w = CallSite.new()
|
||||
w.name = name_s.children.first
|
||||
def on_send statement
|
||||
kids = statement.children.dup
|
||||
receiver = kids.shift
|
||||
name = kids.shift
|
||||
arguments = kids
|
||||
w = SendStatement.new()
|
||||
w.receiver = process(receiver) || SelfStatement.new
|
||||
w.name = name
|
||||
w.arguments = process_all(arguments)
|
||||
w.receiver = process(receiver)
|
||||
w
|
||||
end
|
||||
|
||||
|
@ -3,6 +3,10 @@ require_relative "../helper"
|
||||
module Vool
|
||||
class TestBasicValues < MiniTest::Test
|
||||
|
||||
def test_self
|
||||
lst = Compiler.compile( "self")
|
||||
assert_equal SelfStatement , lst.class
|
||||
end
|
||||
def test_nil
|
||||
lst = Compiler.compile( "nil")
|
||||
assert_equal NilStatement , lst.class
|
||||
|
41
test/vool/test_send_statement.rb
Normal file
41
test/vool/test_send_statement.rb
Normal file
@ -0,0 +1,41 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Vool
|
||||
class TestSend < MiniTest::Test
|
||||
|
||||
def test_simple
|
||||
lst = Compiler.compile( "foo")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
def test_simple_name
|
||||
lst = Compiler.compile( "foo")
|
||||
assert_equal :foo , lst.name
|
||||
end
|
||||
def test_simple_receiver
|
||||
lst = Compiler.compile( "foo")
|
||||
assert_equal SelfStatement , lst.receiver.class
|
||||
end
|
||||
def test_simple_args
|
||||
lst = Compiler.compile( "foo")
|
||||
assert_equal [] , lst.arguments
|
||||
end
|
||||
|
||||
def test_one_arg
|
||||
lst = Compiler.compile( "bar(1)")
|
||||
assert_equal SendStatement , lst.class
|
||||
end
|
||||
def test_one_arg_name
|
||||
lst = Compiler.compile( "bar(1)")
|
||||
assert_equal :bar , lst.name
|
||||
end
|
||||
def test_one_arg_receiver
|
||||
lst = Compiler.compile( "bar(1)")
|
||||
assert_equal SelfStatement , lst.receiver.class
|
||||
end
|
||||
def test_one_arg_args
|
||||
lst = Compiler.compile( "bar(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user