add scope and kwbegin
scope is just a list of statements
This commit is contained in:
parent
27e4e9f501
commit
539ab692a3
@ -13,8 +13,10 @@ require_relative "vool/method_statement"
|
||||
require_relative "vool/while_statement"
|
||||
require_relative "vool/if_statement"
|
||||
require_relative "vool/return_statement"
|
||||
require_relative "vool/return_statement"
|
||||
require_relative "vool/statements"
|
||||
require_relative "vool/send_statement"
|
||||
require_relative "vool/operator_expression"
|
||||
require_relative "vool/variables"
|
||||
|
||||
require_relative "vool/compiler"
|
||||
|
@ -8,7 +8,7 @@ module Vool
|
||||
|
||||
# default to error, so non implemented stuff shows early
|
||||
def handler_missing(node)
|
||||
raise "Not implemented #{node.type}"
|
||||
raise "Not implemented #{node.type} #{node}"
|
||||
end
|
||||
|
||||
def on_class( statement )
|
||||
@ -69,6 +69,9 @@ module Vool
|
||||
def on_dsym
|
||||
raise "Not implemented dynamix symbols (with interpolation)"
|
||||
end
|
||||
def on_kwbegin expression
|
||||
ScopeStatement.new process_all( expression.children )
|
||||
end
|
||||
|
||||
# Array + Hashes
|
||||
def on_array expression
|
||||
@ -86,6 +89,7 @@ module Vool
|
||||
|
||||
#Variables
|
||||
def on_lvasgn expression
|
||||
puts "EXP #{expression}"
|
||||
name = expression.children[0]
|
||||
value = process(expression.children[1])
|
||||
LocalAssignment.new(name,value)
|
||||
@ -144,6 +148,7 @@ module Vool
|
||||
end
|
||||
|
||||
def on_send statement
|
||||
puts "SEND #{statement}"
|
||||
kids = statement.children.dup
|
||||
receiver = kids.shift
|
||||
name = kids.shift
|
||||
|
@ -1,5 +1,11 @@
|
||||
module Vool
|
||||
class Statements < Statement
|
||||
attr_accessor :statements
|
||||
def initialize(statements)
|
||||
@statements = statements
|
||||
end
|
||||
end
|
||||
|
||||
class ScopeStatement < Statements
|
||||
end
|
||||
end
|
||||
|
12
lib/vool/variables.rb
Normal file
12
lib/vool/variables.rb
Normal 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
|
@ -36,5 +36,14 @@ module Vool
|
||||
Compiler.compile( '"dstr#{self}"')
|
||||
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
|
||||
|
@ -36,6 +36,5 @@ module Vool
|
||||
lst = Compiler.compile( "bar(1)")
|
||||
assert_equal 1 , lst.arguments.first.value
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
14
test/vool/test_variables.rb
Normal file
14
test/vool/test_variables.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user