diff --git a/lib/ruby.rb b/lib/ruby.rb index 34b45b7e..12abf071 100644 --- a/lib/ruby.rb +++ b/lib/ruby.rb @@ -9,12 +9,12 @@ end require_relative "ruby/statement" require_relative "ruby/statements" +require_relative "ruby/assignment_statement" require_relative "ruby/array_statement" require_relative "ruby/block_statement" require_relative "ruby/if_statement" require_relative "ruby/normalizer" require_relative "ruby/send_statement" -require_relative "ruby/assign_statement" require_relative "ruby/class_statement" require_relative "ruby/logical_statement" require_relative "ruby/return_statement" @@ -24,5 +24,6 @@ require_relative "ruby/hash_statement" require_relative "ruby/method_statement" require_relative "ruby/ruby_compiler" require_relative "ruby/yield_statement" +require_relative "ruby/variables" require_relative "ruby/ruby_compiler" diff --git a/lib/ruby/assign_statement.rb b/lib/ruby/assignment_statement.rb similarity index 81% rename from lib/ruby/assign_statement.rb rename to lib/ruby/assignment_statement.rb index b03784e5..2aa01e2b 100644 --- a/lib/ruby/assign_statement.rb +++ b/lib/ruby/assignment_statement.rb @@ -6,7 +6,7 @@ module Ruby @name , @value = name , value end - def normalize() + def to_vool() raise "not named left #{name.class}" unless name.is_a?(Symbol) case value when Named , Constant @@ -23,7 +23,7 @@ module Ruby self.class.new(name,value) end - def normalize_send + def to_vool_send statements = value.normalize() return copy( statements ) if statements.is_a?(SendStatement) assign = statements.statements.pop @@ -31,11 +31,6 @@ module Ruby statements end - def chain_assign(assign , compiler) - return assign unless @value.is_a?(SendStatement) - @value.to_mom(compiler) << assign - end - def to_s(depth = 0) at_depth(depth , "#{@name} = #{@value}") end @@ -44,10 +39,14 @@ module Ruby class IvarAssignment < Assignment - def normalize() + def to_vool() super() return IvarAssignment.new(@name , @value) end + end + + class LocalAssignment < Assignment end + end diff --git a/lib/ruby/block_statement.rb b/lib/ruby/block_statement.rb index c73e1382..373622ee 100644 --- a/lib/ruby/block_statement.rb +++ b/lib/ruby/block_statement.rb @@ -9,7 +9,7 @@ module Vool @clazz = clazz end - def normalize + def to_vool BlockStatement.new( @args , @body.normalize) end diff --git a/lib/ruby/class_statement.rb b/lib/ruby/class_statement.rb index aada50ac..b602e0a1 100644 --- a/lib/ruby/class_statement.rb +++ b/lib/ruby/class_statement.rb @@ -16,7 +16,7 @@ module Ruby end end - def normalize + def to_vool meths = body.statements.collect{|meth| meth.normalize} ClassStatement.new(@name , @super_class_name, Statements.new(meths) ) end diff --git a/lib/ruby/if_statement.rb b/lib/ruby/if_statement.rb index 5ede89f1..0f2dd776 100644 --- a/lib/ruby/if_statement.rb +++ b/lib/ruby/if_statement.rb @@ -12,7 +12,7 @@ module Ruby @if_false = if_false end - def normalize + def to_vool cond , rest = *normalize_name(@condition) fals = @if_false ? @if_false.normalize : nil me = IfStatement.new(cond , @if_true.normalize, fals) diff --git a/lib/ruby/method_statement.rb b/lib/ruby/method_statement.rb index 234b9d0b..1c6e2ed1 100644 --- a/lib/ruby/method_statement.rb +++ b/lib/ruby/method_statement.rb @@ -9,7 +9,7 @@ module Ruby end - def normalize + def to_vool MethodStatement.new( @name , @args , @body.normalize) end diff --git a/lib/ruby/normalizer.rb b/lib/ruby/normalizer.rb index 5476d70f..bf148c0f 100644 --- a/lib/ruby/normalizer.rb +++ b/lib/ruby/normalizer.rb @@ -8,7 +8,7 @@ module Ruby # but if(tmp_123) is with tmp_123 = @var % 5 hoisted above the if # # also constants count, though they may not be so useful in ifs, but returns - def normalize_name( condition ) + def to_vool_name( condition ) if( condition.is_a?(ScopeStatement) and condition.single?) condition = condition.first end diff --git a/lib/ruby/return_statement.rb b/lib/ruby/return_statement.rb index 9cf7de8d..138246f2 100644 --- a/lib/ruby/return_statement.rb +++ b/lib/ruby/return_statement.rb @@ -8,7 +8,7 @@ module Ruby @return_value = value end - def normalize + def to_vool val , rest = *normalize_name(@return_value) me = ReturnStatement.new(val) return me unless rest diff --git a/lib/ruby/send_statement.rb b/lib/ruby/send_statement.rb index b97ae46e..3b851e1c 100644 --- a/lib/ruby/send_statement.rb +++ b/lib/ruby/send_statement.rb @@ -8,7 +8,7 @@ module Ruby @arguments ||= [] end - def normalize + def to_vool statements = Statements.new([]) arguments = [] @arguments.each_with_index do |arg , index | @@ -22,7 +22,7 @@ module Ruby end end - def normalize_arg(arg , arguments , statements) + def to_vool_arg(arg , arguments , statements) if arg.respond_to?(:slot_definition) and !arg.is_a?(SendStatement) arguments << arg return diff --git a/lib/ruby/statement.rb b/lib/ruby/statement.rb index de21ccbc..330e8738 100644 --- a/lib/ruby/statement.rb +++ b/lib/ruby/statement.rb @@ -16,7 +16,7 @@ module Ruby class Expression - def normalize + def to_vool raise "should not be normalized #{self}" end diff --git a/lib/ruby/variables.rb b/lib/ruby/variables.rb new file mode 100644 index 00000000..c2145985 --- /dev/null +++ b/lib/ruby/variables.rb @@ -0,0 +1,36 @@ +module Ruby + module Named + attr_reader :name + def initialize name + @name = name + end + def each(&block) + end + end + + class LocalVariable < Expression + include Named + def to_s + name.to_s + end + end + + class InstanceVariable < Expression + include Named + # used to collect type information + def add_ivar( array ) + array << @name + end + def to_s + "@#{name}" + end + end + + class ClassVariable < Expression + include Named + end + + class ModuleName < Expression + include Named + end +end diff --git a/lib/ruby/while_statement.rb b/lib/ruby/while_statement.rb index 31f75b36..842fe3fd 100644 --- a/lib/ruby/while_statement.rb +++ b/lib/ruby/while_statement.rb @@ -11,7 +11,7 @@ module Ruby @body = body end - def normalize + def to_vool cond , rest = *normalize_name(@condition) WhileStatement.new(cond , @body.normalize , rest) end diff --git a/lib/ruby/yield_statement.rb b/lib/ruby/yield_statement.rb index d8b44e6f..27817860 100644 --- a/lib/ruby/yield_statement.rb +++ b/lib/ruby/yield_statement.rb @@ -8,7 +8,7 @@ module Ruby @arguments ||= [] end - def normalize + def to_vool statements = Statements.new([]) arguments = [] @arguments.each_with_index do |arg , index | @@ -22,7 +22,7 @@ module Ruby end end - def normalize_arg(arg , arguments , statements) + def to_vool_arg(arg , arguments , statements) if arg.respond_to?(:slot_definition) and !arg.is_a?(YieldStatement) arguments << arg return diff --git a/test/ruby/test_yield_statement.rb b/test/ruby/test_yield_statement.rb index 3b45d8e1..abd4fff1 100644 --- a/test/ruby/test_yield_statement.rb +++ b/test/ruby/test_yield_statement.rb @@ -20,9 +20,5 @@ module Ruby def test_method_yield? assert_equal true , @lst.has_yield? end - def test_method_args - Parfait.boot! - assert_equal 2 , @lst.make_arg_type.get_length - end end end