From 443fd1398001f96af8ec28d45faf442b00361ce0 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 2 Apr 2017 18:42:52 +0300 Subject: [PATCH] adds super with and without args current thinking is to fill the name of the method later as we carry no context currently, but this may change --- lib/vool/basic_values.rb | 2 ++ lib/vool/compiler.rb | 16 ++++++++++++++++ lib/vool/send_statement.rb | 1 + test/vool/test_send_statement.rb | 23 +++++++++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/lib/vool/basic_values.rb b/lib/vool/basic_values.rb index 2c36877b..8dd2f9cc 100644 --- a/lib/vool/basic_values.rb +++ b/lib/vool/basic_values.rb @@ -19,6 +19,8 @@ module Vool end class SelfStatement < Statement end + class SuperStatement < Statement + end class StringStatement < Statement attr_accessor :value def initialize(value) diff --git a/lib/vool/compiler.rb b/lib/vool/compiler.rb index 39ede5a1..55a4d445 100644 --- a/lib/vool/compiler.rb +++ b/lib/vool/compiler.rb @@ -161,6 +161,22 @@ module Vool w end + # this is a call to super without args (z = zero arity) + def on_zsuper exp + w = SendStatement.new( nil ) + w.receiver = SuperStatement.new + w + end + + # this is a call to super with args and + # same name as current method, which is set later + def on_super( statement ) + w = SendStatement.new( nil ) + w.receiver = SuperStatement.new + w.arguments = process_all(statement.children) + w + end + # def on_name statement # NameStatement.new(statement.children.first) # end diff --git a/lib/vool/send_statement.rb b/lib/vool/send_statement.rb index e231508d..e733aadb 100644 --- a/lib/vool/send_statement.rb +++ b/lib/vool/send_statement.rb @@ -3,6 +3,7 @@ module Vool attr_accessor :name , :receiver , :arguments def initialize(name) @name = name + @arguments = [] end end end diff --git a/test/vool/test_send_statement.rb b/test/vool/test_send_statement.rb index fc14461b..19937ff4 100644 --- a/test/vool/test_send_statement.rb +++ b/test/vool/test_send_statement.rb @@ -36,5 +36,28 @@ module Vool lst = Compiler.compile( "bar(1)") assert_equal 1 , lst.arguments.first.value end + + def test_super0_receiver + lst = Compiler.compile( "super") + assert_equal SuperStatement , lst.receiver.class + end + def test_super0 + lst = Compiler.compile( "super") + assert_equal SendStatement , lst.class + end + + def test_super_receiver + lst = Compiler.compile( "super(1)") + assert_equal SuperStatement , lst.receiver.class + end + def test_super_args + lst = Compiler.compile( "super(1)") + assert_equal 1 , lst.arguments.first.value + end + def test_super_name #is nil + lst = Compiler.compile( "super(1)") + assert_nil lst.name + end + end end