fix use of slot_constant vs slot_move
wip
This commit is contained in:
parent
a523af14f1
commit
66901eeb5b
@ -39,6 +39,12 @@ module Mom
|
|||||||
# @left: See SlotLoad, and array of symbols
|
# @left: See SlotLoad, and array of symbols
|
||||||
# @right: A Constant from parse, ie an instance of classes in basc_value, like TrueStatement
|
# @right: A Constant from parse, ie an instance of classes in basc_value, like TrueStatement
|
||||||
class SlotConstant < SlotLoad
|
class SlotConstant < SlotLoad
|
||||||
|
|
||||||
|
def initialize(left , right)
|
||||||
|
super
|
||||||
|
raise "right not constant, #{right}" unless right.is_a? Vool::ConstantStatement
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class SlotMove < SlotLoad
|
class SlotMove < SlotLoad
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
module Vool
|
module Vool
|
||||||
class IntegerStatement < Statement
|
class Statement
|
||||||
|
def slot_class
|
||||||
|
Mom::SlotMove
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class ConstantStatement < Statement
|
||||||
|
def slot_class
|
||||||
|
Mom::SlotConstant
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class IntegerStatement < ConstantStatement
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
@ -8,7 +19,7 @@ module Vool
|
|||||||
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
Parfait.object_space.get_class_by_name(:Integer).instance_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class FloatStatement < Statement
|
class FloatStatement < ConstantStatement
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
@ -17,17 +28,17 @@ module Vool
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TrueStatement < Statement
|
class TrueStatement < ConstantStatement
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:True).instance_type
|
Parfait.object_space.get_class_by_name(:True).instance_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class FalseStatement < Statement
|
class FalseStatement < ConstantStatement
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:False).instance_type
|
Parfait.object_space.get_class_by_name(:False).instance_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class NilStatement < Statement
|
class NilStatement < ConstantStatement
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
Parfait.object_space.get_class_by_name(:Nil).instance_type
|
||||||
end
|
end
|
||||||
@ -44,7 +55,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
class SuperStatement < Statement
|
class SuperStatement < Statement
|
||||||
end
|
end
|
||||||
class StringStatement < Statement
|
class StringStatement < ConstantStatement
|
||||||
attr_reader :value
|
attr_reader :value
|
||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
|
@ -15,8 +15,8 @@ module Vool
|
|||||||
# - store the given return value, this is a SlotMove / SlotConstant
|
# - store the given return value, this is a SlotMove / SlotConstant
|
||||||
# - activate return sequence (reinstantiate old message and jump to return address)
|
# - activate return sequence (reinstantiate old message and jump to return address)
|
||||||
def to_mom( method )
|
def to_mom( method )
|
||||||
Mom::Statements.new [Mom::SlotConstant.new([:message , :return_value] , @return_value) ,
|
move = @return_value.slot_class.new( [:message , :return_value] , @return_value)
|
||||||
Mom::ReturnSequence.new]
|
Mom::Statements.new [move , Mom::ReturnSequence.new]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ module Mom
|
|||||||
assert_equal 9 , @stats.length
|
assert_equal 9 , @stats.length
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [SlotConstant,TruthCheck,Label,SimpleCall,SlotConstant,Label,SimpleCall,SlotConstant,Label] , @stats
|
check_array [SlotMove,TruthCheck,Label,SimpleCall,SlotMove,Label,SimpleCall,SlotMove,Label] , @stats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ module Mom
|
|||||||
assert_equal 4 , @stats.length
|
assert_equal 4 , @stats.length
|
||||||
end
|
end
|
||||||
def test_array
|
def test_array
|
||||||
check_array [Label,SlotConstant,TruthCheck,Label] , @stats
|
check_array [Label,SlotMove,TruthCheck,Label] , @stats
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -39,10 +39,12 @@ module MomCompile
|
|||||||
index = 0
|
index = 0
|
||||||
test = is
|
test = is
|
||||||
while(test)
|
while(test)
|
||||||
assert_equal should[index] , test.class , "Wrong class for #{index+1}, #{dump(is)}"
|
# if we assert here, we get output pointing here. Without stack, not useful
|
||||||
|
raise "Wrong class for #{index+1}, #{dump(is)}" if should[index] != test.class
|
||||||
index += 1
|
index += 1
|
||||||
test = test.next
|
test = test.next
|
||||||
end
|
end
|
||||||
|
assert 1 #just to get an assertion in the output.
|
||||||
end
|
end
|
||||||
def dump(is)
|
def dump(is)
|
||||||
res =[]
|
res =[]
|
||||||
|
@ -10,7 +10,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotConstant , @stats.first.class , @stats
|
assert_equal Mom::SlotMove , @stats.first.class , @stats
|
||||||
end
|
end
|
||||||
def test_slot_is_set
|
def test_slot_is_set
|
||||||
assert @stats.first.left
|
assert @stats.first.left
|
||||||
@ -19,7 +19,7 @@ module Vool
|
|||||||
assert_equal 3 , @stats.length
|
assert_equal 3 , @stats.length
|
||||||
end
|
end
|
||||||
def test_receiver_move_class
|
def test_receiver_move_class
|
||||||
assert_equal Mom::SlotConstant, @stats.first.class
|
assert_equal Mom::SlotMove, @stats.first.class
|
||||||
end
|
end
|
||||||
def test_receiver_move
|
def test_receiver_move
|
||||||
assert_equal :receiver, @stats.first.left[2]
|
assert_equal :receiver, @stats.first.left[2]
|
||||||
|
@ -13,7 +13,7 @@ module Vool
|
|||||||
assert Array != @stats.class , @stats
|
assert Array != @stats.class , @stats
|
||||||
end
|
end
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotConstant , @stats.first.class , @stats
|
assert_equal Mom::SlotMove , @stats.first.class , @stats
|
||||||
end
|
end
|
||||||
def test_slot_is_set
|
def test_slot_is_set
|
||||||
assert @stats.first.left
|
assert @stats.first.left
|
||||||
@ -22,7 +22,7 @@ module Vool
|
|||||||
assert_equal 2 , @stats.length
|
assert_equal 2 , @stats.length
|
||||||
end
|
end
|
||||||
def test_receiver_move_class
|
def test_receiver_move_class
|
||||||
assert_equal Mom::SlotConstant, @stats.first.class
|
assert_equal Mom::SlotMove, @stats.first.class
|
||||||
end
|
end
|
||||||
def test_receiver_move
|
def test_receiver_move
|
||||||
assert_equal :receiver, @stats.first.left[2]
|
assert_equal :receiver, @stats.first.left[2]
|
||||||
|
@ -13,13 +13,13 @@ module Vool
|
|||||||
assert_equal Mom::Statements , @stats.class
|
assert_equal Mom::Statements , @stats.class
|
||||||
end
|
end
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotConstant , @stats.first.class , @stats
|
assert_equal Mom::SlotMove , @stats.first.class , @stats
|
||||||
end
|
end
|
||||||
def test_four_instructions_are_returned
|
def test_four_instructions_are_returned
|
||||||
assert_equal 4 , @stats.length
|
assert_equal 4 , @stats.length
|
||||||
end
|
end
|
||||||
def test_receiver_move
|
def test_receiver_move
|
||||||
assert_equal Mom::SlotConstant, @stats[0].class
|
assert_equal Mom::SlotMove, @stats[0].class
|
||||||
assert_equal :receiver, @stats[0].left[2]
|
assert_equal :receiver, @stats[0].left[2]
|
||||||
end
|
end
|
||||||
def test_receiver
|
def test_receiver
|
||||||
|
@ -13,13 +13,13 @@ module Vool
|
|||||||
assert Array != @stats.class , @stats
|
assert Array != @stats.class , @stats
|
||||||
end
|
end
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotConstant , @stats.first.class , @stats
|
assert_equal Mom::SlotMove , @stats.first.class , @stats
|
||||||
end
|
end
|
||||||
def test_four_instructions_are_returned
|
def test_four_instructions_are_returned
|
||||||
assert_equal 3 , @stats.length
|
assert_equal 3 , @stats.length
|
||||||
end
|
end
|
||||||
def test_receiver_move
|
def test_receiver_move
|
||||||
assert_equal Mom::SlotConstant, @stats.first.class
|
assert_equal Mom::SlotMove, @stats.first.class
|
||||||
assert_equal :receiver, @stats[0].left[2]
|
assert_equal :receiver, @stats[0].left[2]
|
||||||
end
|
end
|
||||||
def test_receiver
|
def test_receiver
|
||||||
|
@ -11,7 +11,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotConstant , @first.class , @stats
|
assert_equal Mom::SlotMove , @first.class , @stats
|
||||||
end
|
end
|
||||||
def test_slot_is_set
|
def test_slot_is_set
|
||||||
assert @first.left
|
assert @first.left
|
||||||
@ -44,7 +44,7 @@ module Vool
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotConstant , @first.class , @stats
|
assert_equal Mom::SlotMove , @first.class , @stats
|
||||||
end
|
end
|
||||||
def test_slot_is_set
|
def test_slot_is_set
|
||||||
assert @first.left
|
assert @first.left
|
||||||
|
@ -21,7 +21,7 @@ module Vool
|
|||||||
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
|
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
|
||||||
end
|
end
|
||||||
def test_hoisetd
|
def test_hoisetd
|
||||||
assert_equal Mom::SlotConstant , @first.hoisted.class
|
assert_equal Mom::SlotMove , @first.hoisted.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ module Vool
|
|||||||
assert Array != @stats.class , @stats
|
assert Array != @stats.class , @stats
|
||||||
end
|
end
|
||||||
def test_class_compiles
|
def test_class_compiles
|
||||||
assert_equal Mom::SlotConstant , @first.class , @stats
|
assert_equal Mom::SlotMove , @first.class , @stats
|
||||||
end
|
end
|
||||||
def test_slot_is_set
|
def test_slot_is_set
|
||||||
assert @first.left
|
assert @first.left
|
||||||
|
@ -21,7 +21,7 @@ module Vool
|
|||||||
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
|
assert_equal Mom::SlotDefinition , @first.condition.condition.class , @stats
|
||||||
end
|
end
|
||||||
def test_hoisetd
|
def test_hoisetd
|
||||||
assert_equal Mom::SlotConstant , @first.hoisted.class
|
assert_equal Mom::SlotMove , @first.hoisted.class
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user