adds collect for the statements
This commit is contained in:
parent
0fe5685ad4
commit
8942f42310
@ -4,6 +4,10 @@ module Vool
|
|||||||
def initialize(name , value )
|
def initialize(name , value )
|
||||||
@name , @value = name , value
|
@name , @value = name , value
|
||||||
end
|
end
|
||||||
|
def collect(arr)
|
||||||
|
@value.collect(arr)
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
class LocalAssignment < Assignment
|
class LocalAssignment < Assignment
|
||||||
end
|
end
|
||||||
|
@ -9,6 +9,12 @@ module Vool
|
|||||||
simplify_condition
|
simplify_condition
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect(arr)
|
||||||
|
@if_true.collect(arr)
|
||||||
|
@if_false.collect(arr)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
def simplify_condition
|
def simplify_condition
|
||||||
return unless @condition.is_a?(ScopeStatement)
|
return unless @condition.is_a?(ScopeStatement)
|
||||||
@condition = @condition.first if @condition.single?
|
@condition = @condition.first if @condition.single?
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
module Vool
|
module Vool
|
||||||
# Logical Statements are guaranteed to return boolean
|
# Logical Statements are guaranteed to return boolean
|
||||||
# either :and or :or, which may be written as && and ||
|
# either :and or :or, which may be written as && and ||
|
||||||
class LogicalStatement < Statement
|
class LogicalStatement < Statement
|
||||||
attr_reader :name , :left , :right
|
attr_reader :name , :left , :right
|
||||||
|
|
||||||
def initialize(name , left , right)
|
def initialize(name , left , right)
|
||||||
@name , @left , @right = name , left , right
|
@name , @left , @right = name , left , right
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect(arr)
|
||||||
|
@receiver.collect(arr)
|
||||||
|
@arguments.collect(arr)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,5 +6,11 @@ module Vool
|
|||||||
@name , @args , @body = name , args , (body || [])
|
@name , @args , @body = name , args , (body || [])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect(arr)
|
||||||
|
@args.collect(arr)
|
||||||
|
@body.collect(arr)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,5 +5,10 @@ module Vool
|
|||||||
def initialize(value)
|
def initialize(value)
|
||||||
@return_value = value
|
@return_value = value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect(arr)
|
||||||
|
@return_value.collect(arr)
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,5 +5,12 @@ module Vool
|
|||||||
def initialize(name , receiver , arguments = [])
|
def initialize(name , receiver , arguments = [])
|
||||||
@name , @receiver , @arguments = name , receiver , arguments
|
@name , @receiver , @arguments = name , receiver , arguments
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect(arr)
|
||||||
|
@receiver.collect(arr)
|
||||||
|
@arguments.collect(arr)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,11 @@ module Vool
|
|||||||
def length
|
def length
|
||||||
@statements.length
|
@statements.length
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect(arr)
|
||||||
|
@statements.each { |s| s.collect(arr) }
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ScopeStatement < Statements
|
class ScopeStatement < Statements
|
||||||
|
@ -13,5 +13,11 @@ module Vool
|
|||||||
@condition = @condition.first if @condition.single?
|
@condition = @condition.first if @condition.single?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def collect(arr)
|
||||||
|
@condition.collect(arr)
|
||||||
|
@statements.collect(arr)
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
38
test/vool/test_vool_compiler.rb
Normal file
38
test/vool/test_vool_compiler.rb
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
require_relative "helper"
|
||||||
|
|
||||||
|
module Vool
|
||||||
|
class TestVoolCompiler < MiniTest::Test
|
||||||
|
include CompilerHelper
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Risc.machine.boot
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_method
|
||||||
|
VoolCompiler.compile in_Test("def meth; @ivar ;end")
|
||||||
|
test = Parfait.object_space.get_class_by_name(:Test)
|
||||||
|
test.get_method(:meth)
|
||||||
|
end
|
||||||
|
|
||||||
|
def pest_creates_method_in_class
|
||||||
|
method = create_method
|
||||||
|
assert method , "No method created"
|
||||||
|
end
|
||||||
|
|
||||||
|
def pest_method_has_source
|
||||||
|
method = create_method
|
||||||
|
assert_equal "(ivar :@ivar)", method.source.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def pest_method_has_no_args
|
||||||
|
method = create_method
|
||||||
|
assert_equal 1 , method.args_type.instance_length
|
||||||
|
end
|
||||||
|
|
||||||
|
def pest_method_has_no_locals
|
||||||
|
method = create_method
|
||||||
|
assert_equal 1 , method.locals_type.instance_length
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user