adds a mom version of basic values
This commit is contained in:
55
lib/mom/basic_values.rb
Normal file
55
lib/mom/basic_values.rb
Normal file
@ -0,0 +1,55 @@
|
||||
module Mom
|
||||
# just name scoping the same stuff to mom
|
||||
# so we know we are on the way down, keeping our layers seperated
|
||||
# and we can put constant adding into the to_risc methods (instead of on vool classes)
|
||||
class Constant
|
||||
end
|
||||
|
||||
class IntegerConstant < Constant
|
||||
attr_reader :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||
end
|
||||
end
|
||||
class FloatConstant < Constant
|
||||
attr_reader :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def ct_type
|
||||
true
|
||||
end
|
||||
end
|
||||
class TrueConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:True).instance_type
|
||||
end
|
||||
end
|
||||
class FalseConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:False).instance_type
|
||||
end
|
||||
end
|
||||
class NilConstant < Constant
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
||||
end
|
||||
end
|
||||
class StringConstant < Constant
|
||||
attr_reader :value
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
end
|
||||
end
|
||||
class SymbolConstant < String
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
end
|
||||
end
|
||||
end
|
@ -19,6 +19,7 @@ module Mom
|
||||
end
|
||||
end
|
||||
|
||||
require_relative "basic_values"
|
||||
require_relative "simple_call"
|
||||
require_relative "dynamic_call"
|
||||
require_relative "truth_check"
|
||||
|
@ -30,7 +30,8 @@ module Mom
|
||||
def initialize(left , right)
|
||||
left = SlotDefinition.new(left.shift , left) if left.is_a? Array
|
||||
@left , @right = left , right
|
||||
raise "right not SlotDefinition, #{left}" unless left.is_a? SlotDefinition
|
||||
raise "left not SlotDefinition, #{left}" unless left.is_a? SlotDefinition
|
||||
# raise "right not Mom, #{right.to_rxf}" unless right.class.name.include?("Mom")
|
||||
end
|
||||
end
|
||||
|
||||
@ -44,7 +45,7 @@ module Mom
|
||||
|
||||
def initialize(left , right)
|
||||
super
|
||||
raise "right not constant, #{right}" unless right.is_a? Vool::ConstantStatement
|
||||
raise "right not constant, #{right}" unless right.is_a? Mom::Constant
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,11 +1,10 @@
|
||||
|
||||
# Integer class for representing maths on Integers
|
||||
# Integers are Values (not Objects),
|
||||
# Integers are Objects, spcifically DataObjects
|
||||
# - they have fixed value
|
||||
# - they are immutable
|
||||
# you can *not* assign instance variables or methods
|
||||
|
||||
# TODO how this idea works with Numeric ?
|
||||
# (both by implementation, not design.
|
||||
# Ie it would be possible to change the value, we just don't support that)
|
||||
|
||||
module Parfait
|
||||
class Integer
|
||||
|
@ -15,6 +15,9 @@ module Vool
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def to_mom(method)
|
||||
return Mom::IntegerConstant.new(@value)
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||
end
|
||||
@ -45,10 +48,12 @@ module Vool
|
||||
end
|
||||
class SelfStatement < Statement
|
||||
attr_reader :clazz
|
||||
|
||||
def set_class(clazz)
|
||||
@clazz = clazz
|
||||
end
|
||||
def to_mom(in_method)
|
||||
Mom::SlotDefinition.new(:message , [:self])
|
||||
end
|
||||
def ct_type
|
||||
@clazz.instance_type
|
||||
end
|
||||
@ -60,6 +65,9 @@ module Vool
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def to_mom(method)
|
||||
return Mom::StringConstant.new(@value)
|
||||
end
|
||||
def ct_type
|
||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ module Vool
|
||||
end
|
||||
|
||||
def to_mom( method )
|
||||
@value.slot_class.new([:message , :self , @name] , @value)
|
||||
@value.slot_class.new([:message , :self , @name] , @value.to_mom(method))
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -12,7 +12,7 @@ module Vool
|
||||
else
|
||||
type = :frame
|
||||
end
|
||||
@value.slot_class.new(Mom::SlotDefinition.new(:message , [type , @name]) , @value)
|
||||
@value.slot_class.new(Mom::SlotDefinition.new(:message , [type , @name]) , @value.to_mom(method))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -11,11 +11,11 @@ module Vool
|
||||
super
|
||||
end
|
||||
|
||||
# To return form a method in mom instructions we need to do three things:
|
||||
# To return form a method in mom instructions we need to do two things:
|
||||
# - store the given return value, this is a SlotMove / SlotConstant
|
||||
# - activate return sequence (reinstantiate old message and jump to return address)
|
||||
def to_mom( method )
|
||||
move = @return_value.slot_class.new( [:message , :return_value] , @return_value)
|
||||
move = @return_value.slot_class.new( [:message , :return_value] , @return_value.to_mom(method))
|
||||
Mom::Statements.new [move , Mom::ReturnSequence.new]
|
||||
end
|
||||
|
||||
|
@ -43,11 +43,11 @@ module Vool
|
||||
|
||||
def message_setup(in_method)
|
||||
setup = [Mom::MessageSetup.new(in_method)]
|
||||
receiver = @receiver.slot_class.new([:message , :next_message , :receiver] , @receiver)
|
||||
receiver = @receiver.slot_class.new([:message , :next_message , :receiver] , @receiver.to_mom(in_method))
|
||||
arg_target = [:message , :next_message , :arguments]
|
||||
args = []
|
||||
@arguments.each_with_index do |arg , index|
|
||||
args << arg.slot_class.new( arg_target + [index] , arg)
|
||||
args << arg.slot_class.new( arg_target + [index] , arg.to_mom(in_method))
|
||||
end
|
||||
setup << Mom::ArgumentTransfer.new( receiver , args )
|
||||
end
|
||||
|
@ -9,8 +9,8 @@ module Vool
|
||||
statements
|
||||
end
|
||||
def self.ruby_to_mom(source)
|
||||
statements = elf.ruby_to_vool(source)
|
||||
statements.to_mom
|
||||
statements = self.ruby_to_vool(source)
|
||||
statements.to_mom(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user