add scope and kwbegin

scope is just a list of statements
This commit is contained in:
Torsten Ruger 2017-04-02 13:24:09 +03:00
parent 27e4e9f501
commit 539ab692a3
7 changed files with 50 additions and 3 deletions

View File

@ -13,8 +13,10 @@ require_relative "vool/method_statement"
require_relative "vool/while_statement" 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/return_statement"
require_relative "vool/statements" require_relative "vool/statements"
require_relative "vool/send_statement" require_relative "vool/send_statement"
require_relative "vool/operator_expression" require_relative "vool/operator_expression"
require_relative "vool/variables"
require_relative "vool/compiler" require_relative "vool/compiler"

View File

@ -8,7 +8,7 @@ module Vool
# default to error, so non implemented stuff shows early # default to error, so non implemented stuff shows early
def handler_missing(node) def handler_missing(node)
raise "Not implemented #{node.type}" raise "Not implemented #{node.type} #{node}"
end end
def on_class( statement ) def on_class( statement )
@ -69,6 +69,9 @@ module Vool
def on_dsym def on_dsym
raise "Not implemented dynamix symbols (with interpolation)" raise "Not implemented dynamix symbols (with interpolation)"
end end
def on_kwbegin expression
ScopeStatement.new process_all( expression.children )
end
# Array + Hashes # Array + Hashes
def on_array expression def on_array expression
@ -86,6 +89,7 @@ module Vool
#Variables #Variables
def on_lvasgn expression def on_lvasgn expression
puts "EXP #{expression}"
name = expression.children[0] name = expression.children[0]
value = process(expression.children[1]) value = process(expression.children[1])
LocalAssignment.new(name,value) LocalAssignment.new(name,value)
@ -144,6 +148,7 @@ module Vool
end end
def on_send statement def on_send statement
puts "SEND #{statement}"
kids = statement.children.dup kids = statement.children.dup
receiver = kids.shift receiver = kids.shift
name = kids.shift name = kids.shift

View File

@ -1,5 +1,11 @@
module Vool module Vool
class Statements < Statement class Statements < Statement
attr_accessor :statements attr_accessor :statements
def initialize(statements)
@statements = statements
end
end
class ScopeStatement < Statements
end end
end end

12
lib/vool/variables.rb Normal file
View File

@ -0,0 +1,12 @@
module Vool
module Named
attr_accessor :name
def initialize name
@name = name
end
end
class LocalVariable < Statement
include Named
end
end

View File

@ -5,7 +5,7 @@ module Vool
def test_self def test_self
lst = Compiler.compile( "self") lst = Compiler.compile( "self")
assert_equal SelfStatement , lst.class assert_equal SelfStatement , lst.class
end end
def test_nil def test_nil
lst = Compiler.compile( "nil") lst = Compiler.compile( "nil")
@ -36,5 +36,14 @@ module Vool
Compiler.compile( '"dstr#{self}"') Compiler.compile( '"dstr#{self}"')
end end
end end
def test_scope
lst = Compiler.compile( "begin ; 1 ; end")
assert_equal ScopeStatement , lst.class , lst.inspect
end
def test_scope_contents
lst = Compiler.compile( "begin ; 1 ; end")
assert_equal 1 , lst.statements.first.value
end
end end
end end

View File

@ -36,6 +36,5 @@ module Vool
lst = Compiler.compile( "bar(1)") lst = Compiler.compile( "bar(1)")
assert_equal 1 , lst.arguments.first.value assert_equal 1 , lst.arguments.first.value
end end
end end
end end

View File

@ -0,0 +1,14 @@
require_relative "../helper"
module Vool
class TestVariables < MiniTest::Test
# "free standing" local can not be tested as it will result in send
# in other words ther is no way of knowing if a name is variable or method
def ptest_send_to_local
lst = Compiler.compile( "foo = 1 ; foo.bar")
assert_equal LocalVariable , lst.receiver
end
end
end