From 6022aa4dabb5ea79d2229538ebb6213de45f13a2 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 20 Jul 2018 20:53:35 +0300 Subject: [PATCH] introduce ruby variable and remove ct_type cleaner oo --- lib/ruby/assignment.rb | 2 +- lib/ruby/basic_values.rb | 21 --------------------- lib/ruby/normalizer.rb | 2 +- lib/ruby/send_statement.rb | 2 +- lib/ruby/variables.rb | 19 ++++++++----------- test/ruby/test_basic_values.rb | 23 +++++++++++------------ 6 files changed, 22 insertions(+), 47 deletions(-) diff --git a/lib/ruby/assignment.rb b/lib/ruby/assignment.rb index df338f1b..a44bc2c5 100644 --- a/lib/ruby/assignment.rb +++ b/lib/ruby/assignment.rb @@ -9,7 +9,7 @@ module Ruby def to_vool() raise "not named left #{name.class}" unless name.is_a?(Symbol) case value - when Named , Constant + when Variable , Constant return self.vool_brother.new(name,@value.to_vool) when SendStatement return normalize_send diff --git a/lib/ruby/basic_values.rb b/lib/ruby/basic_values.rb index d0a3c332..2bce4f32 100644 --- a/lib/ruby/basic_values.rb +++ b/lib/ruby/basic_values.rb @@ -14,9 +14,6 @@ module Ruby end end class IntegerConstant < ValueConstant - def ct_type - Parfait.object_space.get_type_by_class_name(:Integer) - end def to_s value.to_s end @@ -26,30 +23,18 @@ module Ruby def initialize(value) @value = value end - def ct_type - true - end end class TrueConstant < Constant - def ct_type - Parfait.object_space.get_type_by_class_name(:True) - end def to_s(depth = 0) "true" end end class FalseConstant < Constant - def ct_type - Parfait.object_space.get_type_by_class_name(:False) - end def to_s(depth = 0) "false" end end class NilConstant < Constant - def ct_type - Parfait.object_space.get_type_by_class_name(:Nil) - end def to_s(depth = 0) "nil" end @@ -72,16 +57,10 @@ module Ruby def initialize(value) @value = value end - def ct_type - Parfait.object_space.get_type_by_class_name(:Word) - end def to_s(depth = 0) "'#{@value}'" end end class SymbolConstant < StringConstant - def ct_type - Parfait.object_space.get_type_by_class_name(:Word) - end end end diff --git a/lib/ruby/normalizer.rb b/lib/ruby/normalizer.rb index fe29e858..ff9ab151 100644 --- a/lib/ruby/normalizer.rb +++ b/lib/ruby/normalizer.rb @@ -12,7 +12,7 @@ module Ruby if( condition.is_a?(ScopeStatement) and condition.single?) condition = condition.first end - return [condition] if condition.is_a?(Named) or condition.is_a?(Constant) + return [condition] if condition.is_a?(Variable) or condition.is_a?(Constant) local = "tmp_#{object_id}".to_sym assign = LocalAssignment.new( local , condition) [LocalVariable.new(local) , assign] diff --git a/lib/ruby/send_statement.rb b/lib/ruby/send_statement.rb index cd80b8fb..671d23c7 100644 --- a/lib/ruby/send_statement.rb +++ b/lib/ruby/send_statement.rb @@ -23,7 +23,7 @@ module Ruby end def normalize_arg(arg , arguments , statements) - if arg.respond_to?(:ct_type) and !arg.is_a?(SendStatement) + if arg.is_a?(Constant) and !arg.is_a?(SendStatement) arguments << arg.to_vool return end diff --git a/lib/ruby/variables.rb b/lib/ruby/variables.rb index 2ef81960..77e5fb6f 100644 --- a/lib/ruby/variables.rb +++ b/lib/ruby/variables.rb @@ -1,25 +1,24 @@ module Ruby - module Named + class Variable < Statement attr_reader :name + def initialize name @name = name end - def each(&block) - end + def to_vool vool_brother.new(@name) end end - class LocalVariable < Statement - include Named + class LocalVariable < Variable def to_s name.to_s end end - class InstanceVariable < Statement - include Named + class InstanceVariable < Variable + # used to collect type information def add_ivar( array ) array << @name @@ -29,11 +28,9 @@ module Ruby end end - class ClassVariable < Statement - include Named + class ClassVariable < Variable end - class ModuleName < Statement - include Named + class ModuleName < Variable end end diff --git a/test/ruby/test_basic_values.rb b/test/ruby/test_basic_values.rb index 8fed5d59..b08c5609 100644 --- a/test/ruby/test_basic_values.rb +++ b/test/ruby/test_basic_values.rb @@ -53,28 +53,27 @@ module Ruby def setup Parfait.boot! end - def compile_ct( input ) + def compile_const( input ) lst = compile( input ) - lst.ct_type.class_name + lst.class end def test_integer - assert_equal :Integer , compile_ct( "123") + assert_equal IntegerConstant , compile_const( "123") end def test_string - assert_equal :Word , compile_ct( "'string'") + assert_equal StringConstant , compile_const( "'string'") end def test_sym - assert_equal :Word , compile_ct( ":symbol") + assert_equal SymbolConstant , compile_const( ":symbol") end - # classes fot these are not implemented in parfait yet - def pest_nil - assert_equal :Nil , compile_ct( "nil") + def test_nil + assert_equal NilConstant , compile_const( "nil") end - def pest_false - assert_equal :False , compile_ct( "false") + def test_false + assert_equal FalseConstant , compile_const( "false") end - def pest_true - assert_equal :True , compile_ct( "true") + def test_true + assert_equal TrueConstant , compile_const( "true") end end end