add send statement
This commit is contained in:
parent
93f9d16209
commit
d62e996f7c
@ -4,6 +4,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
require_relative "vool/array_statement"
|
require_relative "vool/array_statement"
|
||||||
|
require_relative "vool/assignment_statement"
|
||||||
require_relative "vool/basic_values"
|
require_relative "vool/basic_values"
|
||||||
require_relative "vool/class_statement"
|
require_relative "vool/class_statement"
|
||||||
require_relative "vool/hash_statement"
|
require_relative "vool/hash_statement"
|
||||||
@ -13,8 +14,7 @@ require_relative "vool/while_statement"
|
|||||||
require_relative "vool/if_statement"
|
require_relative "vool/if_statement"
|
||||||
require_relative "vool/return_statement"
|
require_relative "vool/return_statement"
|
||||||
require_relative "vool/statements"
|
require_relative "vool/statements"
|
||||||
|
require_relative "vool/send_statement"
|
||||||
require_relative "vool/operator_expression"
|
require_relative "vool/operator_expression"
|
||||||
require_relative "vool/call_site_statement"
|
|
||||||
require_relative "vool/assignment_statement"
|
|
||||||
|
|
||||||
require_relative "vool/compiler"
|
require_relative "vool/compiler"
|
||||||
|
@ -27,6 +27,14 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
#basic Values
|
#basic Values
|
||||||
|
def on_self exp
|
||||||
|
SelfStatement.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_nil expression
|
||||||
|
NilStatement.new
|
||||||
|
end
|
||||||
|
|
||||||
def on_int expression
|
def on_int expression
|
||||||
IntegerStatement.new(expression.children.first)
|
IntegerStatement.new(expression.children.first)
|
||||||
end
|
end
|
||||||
@ -43,10 +51,6 @@ module Vool
|
|||||||
FalseStatement.new
|
FalseStatement.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_nil expression
|
|
||||||
NilStatement.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def on_str expression
|
def on_str expression
|
||||||
StringStatement.new(expression.children.first)
|
StringStatement.new(expression.children.first)
|
||||||
end
|
end
|
||||||
@ -80,6 +84,14 @@ module Vool
|
|||||||
hash
|
hash
|
||||||
end
|
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
|
def on_return statement
|
||||||
w = ReturnStatement.new()
|
w = ReturnStatement.new()
|
||||||
w.return_value = process(statement.children.first)
|
w.return_value = process(statement.children.first)
|
||||||
@ -132,12 +144,15 @@ module Vool
|
|||||||
process expression.children.first
|
process expression.children.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def on_call statement
|
def on_send statement
|
||||||
name_s , arguments , receiver = *statement
|
kids = statement.children.dup
|
||||||
w = CallSite.new()
|
receiver = kids.shift
|
||||||
w.name = name_s.children.first
|
name = kids.shift
|
||||||
|
arguments = kids
|
||||||
|
w = SendStatement.new()
|
||||||
|
w.receiver = process(receiver) || SelfStatement.new
|
||||||
|
w.name = name
|
||||||
w.arguments = process_all(arguments)
|
w.arguments = process_all(arguments)
|
||||||
w.receiver = process(receiver)
|
|
||||||
w
|
w
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -3,6 +3,10 @@ require_relative "../helper"
|
|||||||
module Vool
|
module Vool
|
||||||
class TestBasicValues < MiniTest::Test
|
class TestBasicValues < MiniTest::Test
|
||||||
|
|
||||||
|
def test_self
|
||||||
|
lst = Compiler.compile( "self")
|
||||||
|
assert_equal SelfStatement , lst.class
|
||||||
|
end
|
||||||
def test_nil
|
def test_nil
|
||||||
lst = Compiler.compile( "nil")
|
lst = Compiler.compile( "nil")
|
||||||
assert_equal NilStatement , lst.class
|
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