change the ruby block to be like the ruby block

ie modelled like the ast outputs it
This commit is contained in:
Torsten Ruger 2018-07-19 16:22:44 +03:00
parent 61225c2f20
commit f728725b1a
3 changed files with 15 additions and 19 deletions

View File

@ -1,12 +1,11 @@
module Vool module Ruby
class BlockStatement < Statement class BlockStatement < Statement
attr_reader :args , :body , :clazz attr_reader :send , :args , :body
def initialize( args , body , something_really_else) def initialize( send , args , body )
@args , @body = args , body @send , @args , @body = send , args , body
raise "no bod" unless @body raise "no bod" unless @body
@clazz = clazz
end end
def to_vool def to_vool

View File

@ -41,8 +41,7 @@ module Ruby
sendd = process(block_node.children[0]) sendd = process(block_node.children[0])
args = process(block_node.children[1]) args = process(block_node.children[1])
body = process(block_node.children[2]) body = process(block_node.children[2])
sendd.add_block BlockStatement.new(args , body) BlockStatement.new(sendd , args , body)
sendd
end end
def on_yield(node) def on_yield(node)
@ -177,7 +176,7 @@ module Ruby
IfStatement.new( process(condition) , if_true , if_false ) IfStatement.new( process(condition) , if_true , if_false )
end end
def on_send statement def on_send( statement )
kids = statement.children.dup kids = statement.children.dup
receiver = process(kids.shift) || SelfExpression.new receiver = process(kids.shift) || SelfExpression.new
name = kids.shift name = kids.shift

View File

@ -1,30 +1,28 @@
require_relative "helper" require_relative "helper"
module Ruby module Ruby
class TestBlockStatementX < MiniTest::Test class TestBlockStatement < MiniTest::Test
include RubyTests include RubyTests
def setup() def setup()
input = "plus_one{|arg1| arg1 + 1 } " input = "plus_one{|arg1| arg1 + 1 } "
@lst = compile( input ) @lst = compile( input )
end end
def test_method
assert_equal SendStatement , @lst.class
end
def test_block def test_block
assert_equal BlockStatement , @lst.block.class assert_equal BlockStatement , @lst.class
end
def test_send
assert_equal SendStatement , @lst.send.class
end end
def test_method_name def test_method_name
assert_equal :plus_one , @lst.name assert_equal :plus_one , @lst.send.name
end end
def test_block_args def test_block_args
assert_equal [:arg1] , @lst.block.args assert_equal [:arg1] , @lst.args
end end
def test_block_body def test_block_body
assert_equal SendStatement , @lst.block.body.class assert_equal SendStatement , @lst.body.class
assert_equal 1 , @lst.block.body.arguments.length assert_equal 1 , @lst.body.arguments.length
end end
end end
end end