fix ruby send statement

remove ruby expression
This commit is contained in:
Torsten Ruger
2018-07-20 10:05:11 +03:00
parent 8cd9818f64
commit 7b02feae7a
6 changed files with 144 additions and 74 deletions

View File

@ -1,28 +1,27 @@
module Ruby
class Constant < Expression
#gobble it up
def each(&block)
class Constant < Statement
def to_vool
vool_brother.new
end
end
class IntegerConstant < Constant
class ValueConstant < Constant
attr_reader :value
def initialize(value)
@value = value
end
def slot_definition(compiler)
return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , [])
def to_vool
vool_brother.new(@value)
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
def each(&block)
end
end
class FloatConstant < Constant
class FloatConstant < ValueConstant
attr_reader :value
def initialize(value)
@value = value
@ -35,9 +34,6 @@ module Ruby
def ct_type
Parfait.object_space.get_type_by_class_name(:True)
end
def slot_definition(compiler)
return Mom::SlotDefinition.new(Parfait.object_space.true_object , [])
end
def to_s(depth = 0)
"true"
end
@ -46,9 +42,6 @@ module Ruby
def ct_type
Parfait.object_space.get_type_by_class_name(:False)
end
def slot_definition(compiler)
return Mom::SlotDefinition.new(Parfait.object_space.false_object , [])
end
def to_s(depth = 0)
"false"
end
@ -57,25 +50,11 @@ module Ruby
def ct_type
Parfait.object_space.get_type_by_class_name(:Nil)
end
def slot_definition(compiler)
return Mom::SlotDefinition.new(Parfait.object_space.nil_object , [])
end
def to_s(depth = 0)
"nil"
end
end
class SelfExpression < Expression
attr_reader :my_type
def initialize(type = nil)
@my_type = type
end
def slot_definition(compiler)
@my_type = compiler.receiver_type
Mom::SlotDefinition.new(:message , [:receiver])
end
def ct_type
@my_type
end
class SelfExpression < Constant
def to_s(depth = 0)
"self"
end
@ -84,15 +63,15 @@ module Ruby
def to_s(depth = 0)
"super"
end
def to_vool
vool_brother.new
end
end
class StringConstant < Constant
class StringConstant < ValueConstant
attr_reader :value
def initialize(value)
@value = value
end
def slot_definition(compiler)
return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[])
end
def ct_type
Parfait.object_space.get_type_by_class_name(:Word)
end

View File

@ -9,27 +9,27 @@ module Ruby
end
def to_vool
statements = Statements.new([])
statements = Vool::Statements.new([])
arguments = []
@arguments.each_with_index do |arg , index |
normalize_arg(arg , arguments , statements)
end
if statements.empty?
return SendStatement.new(@name, @receiver , @arguments)
return Vool::SendStatement.new(@name, @receiver.to_vool , @arguments)
else
statements << SendStatement.new(@name, @receiver , arguments)
statements << Vool::SendStatement.new(@name, @receiver.to_vool , arguments)
return statements
end
end
def to_vool_arg(arg , arguments , statements)
def normalize_arg(arg , arguments , statements)
if arg.respond_to?(:slot_definition) and !arg.is_a?(SendStatement)
arguments << arg
return
end
assign = LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg)
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg)
statements << assign
arguments << LocalVariable.new(assign.name)
arguments << Vool::LocalVariable.new(assign.name)
end
def to_s

View File

@ -20,12 +20,4 @@ module Ruby
end
end
class Expression
def to_vool
raise "should not be normalized #{self}"
end
end
end

View File

@ -8,14 +8,14 @@ module Ruby
end
end
class LocalVariable < Expression
class LocalVariable < Statement
include Named
def to_s
name.to_s
end
end
class InstanceVariable < Expression
class InstanceVariable < Statement
include Named
# used to collect type information
def add_ivar( array )
@ -26,11 +26,11 @@ module Ruby
end
end
class ClassVariable < Expression
class ClassVariable < Statement
include Named
end
class ModuleName < Expression
class ModuleName < Statement
include Named
end
end