introduce ruby variable and remove ct_type
cleaner oo
This commit is contained in:
parent
9548440949
commit
6022aa4dab
@ -9,7 +9,7 @@ module Ruby
|
|||||||
def to_vool()
|
def to_vool()
|
||||||
raise "not named left #{name.class}" unless name.is_a?(Symbol)
|
raise "not named left #{name.class}" unless name.is_a?(Symbol)
|
||||||
case value
|
case value
|
||||||
when Named , Constant
|
when Variable , Constant
|
||||||
return self.vool_brother.new(name,@value.to_vool)
|
return self.vool_brother.new(name,@value.to_vool)
|
||||||
when SendStatement
|
when SendStatement
|
||||||
return normalize_send
|
return normalize_send
|
||||||
|
@ -14,9 +14,6 @@ module Ruby
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
class IntegerConstant < ValueConstant
|
class IntegerConstant < ValueConstant
|
||||||
def ct_type
|
|
||||||
Parfait.object_space.get_type_by_class_name(:Integer)
|
|
||||||
end
|
|
||||||
def to_s
|
def to_s
|
||||||
value.to_s
|
value.to_s
|
||||||
end
|
end
|
||||||
@ -26,30 +23,18 @@ module Ruby
|
|||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
def ct_type
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
class TrueConstant < Constant
|
class TrueConstant < Constant
|
||||||
def ct_type
|
|
||||||
Parfait.object_space.get_type_by_class_name(:True)
|
|
||||||
end
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"true"
|
"true"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class FalseConstant < Constant
|
class FalseConstant < Constant
|
||||||
def ct_type
|
|
||||||
Parfait.object_space.get_type_by_class_name(:False)
|
|
||||||
end
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"false"
|
"false"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class NilConstant < Constant
|
class NilConstant < Constant
|
||||||
def ct_type
|
|
||||||
Parfait.object_space.get_type_by_class_name(:Nil)
|
|
||||||
end
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"nil"
|
"nil"
|
||||||
end
|
end
|
||||||
@ -72,16 +57,10 @@ module Ruby
|
|||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
def ct_type
|
|
||||||
Parfait.object_space.get_type_by_class_name(:Word)
|
|
||||||
end
|
|
||||||
def to_s(depth = 0)
|
def to_s(depth = 0)
|
||||||
"'#{@value}'"
|
"'#{@value}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class SymbolConstant < StringConstant
|
class SymbolConstant < StringConstant
|
||||||
def ct_type
|
|
||||||
Parfait.object_space.get_type_by_class_name(:Word)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -12,7 +12,7 @@ module Ruby
|
|||||||
if( condition.is_a?(ScopeStatement) and condition.single?)
|
if( condition.is_a?(ScopeStatement) and condition.single?)
|
||||||
condition = condition.first
|
condition = condition.first
|
||||||
end
|
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
|
local = "tmp_#{object_id}".to_sym
|
||||||
assign = LocalAssignment.new( local , condition)
|
assign = LocalAssignment.new( local , condition)
|
||||||
[LocalVariable.new(local) , assign]
|
[LocalVariable.new(local) , assign]
|
||||||
|
@ -23,7 +23,7 @@ module Ruby
|
|||||||
end
|
end
|
||||||
|
|
||||||
def normalize_arg(arg , arguments , statements)
|
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
|
arguments << arg.to_vool
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
module Ruby
|
module Ruby
|
||||||
module Named
|
class Variable < Statement
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
def initialize name
|
def initialize name
|
||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
def each(&block)
|
|
||||||
end
|
|
||||||
def to_vool
|
def to_vool
|
||||||
vool_brother.new(@name)
|
vool_brother.new(@name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class LocalVariable < Statement
|
class LocalVariable < Variable
|
||||||
include Named
|
|
||||||
def to_s
|
def to_s
|
||||||
name.to_s
|
name.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class InstanceVariable < Statement
|
class InstanceVariable < Variable
|
||||||
include Named
|
|
||||||
# used to collect type information
|
# used to collect type information
|
||||||
def add_ivar( array )
|
def add_ivar( array )
|
||||||
array << @name
|
array << @name
|
||||||
@ -29,11 +28,9 @@ module Ruby
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ClassVariable < Statement
|
class ClassVariable < Variable
|
||||||
include Named
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class ModuleName < Statement
|
class ModuleName < Variable
|
||||||
include Named
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -53,28 +53,27 @@ module Ruby
|
|||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
end
|
end
|
||||||
def compile_ct( input )
|
def compile_const( input )
|
||||||
lst = compile( input )
|
lst = compile( input )
|
||||||
lst.ct_type.class_name
|
lst.class
|
||||||
end
|
end
|
||||||
def test_integer
|
def test_integer
|
||||||
assert_equal :Integer , compile_ct( "123")
|
assert_equal IntegerConstant , compile_const( "123")
|
||||||
end
|
end
|
||||||
def test_string
|
def test_string
|
||||||
assert_equal :Word , compile_ct( "'string'")
|
assert_equal StringConstant , compile_const( "'string'")
|
||||||
end
|
end
|
||||||
def test_sym
|
def test_sym
|
||||||
assert_equal :Word , compile_ct( ":symbol")
|
assert_equal SymbolConstant , compile_const( ":symbol")
|
||||||
end
|
end
|
||||||
# classes fot these are not implemented in parfait yet
|
def test_nil
|
||||||
def pest_nil
|
assert_equal NilConstant , compile_const( "nil")
|
||||||
assert_equal :Nil , compile_ct( "nil")
|
|
||||||
end
|
end
|
||||||
def pest_false
|
def test_false
|
||||||
assert_equal :False , compile_ct( "false")
|
assert_equal FalseConstant , compile_const( "false")
|
||||||
end
|
end
|
||||||
def pest_true
|
def test_true
|
||||||
assert_equal :True , compile_ct( "true")
|
assert_equal TrueConstant , compile_const( "true")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user