introduce ruby variable and remove ct_type

cleaner oo
This commit is contained in:
Torsten Ruger 2018-07-20 20:53:35 +03:00
parent 9548440949
commit 6022aa4dab
6 changed files with 22 additions and 47 deletions

View File

@ -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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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