diff --git a/lib/mom/instruction/basic_values.rb b/lib/mom/instruction/basic_values.rb index 91565faf..6afcba71 100644 --- a/lib/mom/instruction/basic_values.rb +++ b/lib/mom/instruction/basic_values.rb @@ -29,16 +29,25 @@ module Mom end end class TrueConstant < Constant + def to_parfait(compiler) + Parfait.object_space.true_object + end def ct_type Parfait.object_space.get_class_by_name(:TrueClass).instance_type end end class FalseConstant < Constant + def to_parfait(compiler) + Parfait.object_space.false_object + end def ct_type Parfait.object_space.get_class_by_name(:FalseClass).instance_type end end class NilConstant < Constant + def to_parfait(compiler) + Parfait.object_space.nil_object + end def ct_type Parfait.object_space.get_class_by_name(:NilClass).instance_type end @@ -48,6 +57,11 @@ module Mom def initialize(value) @value = value end + def to_parfait(compiler) + value = Parfait.new_word(@value) + compiler.add_constant(value) + value + end def ct_type Parfait.object_space.get_class_by_name(:Word).instance_type end diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index 5618a14f..6d9382d6 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -29,10 +29,19 @@ module Parfait end # adding other base classes in here for now: - class FalseClass + class FalseClass < Data2 + #FIXME: this is "just" for compilation + def initialize + end end - class TrusClass + class TrueClass < Data2 + #FIXME: this is "just" for compilation + def initialize + end end - class NilClass + class NilClass < Data2 + #FIXME: this is "just" for compilation + def initialize + end end end diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 1611c707..6c881823 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -44,9 +44,13 @@ module Parfait @classes.each do |name , cl| add_type(cl.instance_type) end + @true_object = Parfait::TrueClass.new + @false_object = Parfait::FalseClass.new + @nil_object = Parfait::NilClass.new end - attr_reader :classes , :first_message + attr_reader :classes , :first_message , :first_integer + attr_reader :true_object , :false_object , :nil_object def each_type @types.values.each do |type| diff --git a/lib/risc/boot.rb b/lib/risc/boot.rb index ae67f2f6..a5bb0195 100644 --- a/lib/risc/boot.rb +++ b/lib/risc/boot.rb @@ -140,8 +140,9 @@ module Risc Kernel: {}, #fix, kernel is a class, but should be a module BinaryCode: {next: :BinaryCode} , Space: {classes: :Dictionary , types: :Dictionary , - first_message: :Message , single_true: :TrueClass, - single_false: :FalseClass , single_nil: :NilClass}, + first_message: :Message , first_integer: :Integer , + true_object: :TrueClass, + false_object: :FalseClass , nil_object: :NilClass}, NamedList: {}, Type: {names: :List , types: :List , object_class: :Class, methods: :List } , diff --git a/test/mom/test_if_else.rb b/test/mom/test_if_else.rb index 17bcf91f..856a067e 100644 --- a/test/mom/test_if_else.rb +++ b/test/mom/test_if_else.rb @@ -19,7 +19,7 @@ module Risc def test_false_load produced = produce_body - assert_equal Mom::FalseConstant , produced.next(2).constant.class + assert_equal Parfait::FalseClass , produced.next(2).constant.class end def test_false_check produced = produce_body @@ -27,7 +27,7 @@ module Risc end def test_nil_load produced = produce_body - assert_equal Mom::NilConstant , produced.next(5).constant.class + assert_equal Parfait::NilClass , produced.next(5).constant.class end def test_nil_check produced = produce_body diff --git a/test/mom/test_if_no_else.rb b/test/mom/test_if_no_else.rb index 5f53aedb..1a665e6e 100644 --- a/test/mom/test_if_no_else.rb +++ b/test/mom/test_if_no_else.rb @@ -18,7 +18,7 @@ module Risc def test_false_load produced = produce_body - assert_equal Mom::FalseConstant , produced.next(2).constant.class + assert_equal Parfait::FalseClass , produced.next(2).constant.class end def test_isnotzero produced = produce_body @@ -35,7 +35,7 @@ module Risc end def test_nil_load produced = produce_body - assert_equal Mom::NilConstant , produced.next(5).constant.class + assert_equal Parfait::NilClass , produced.next(5).constant.class end def test_nil_check produced = produce_body diff --git a/test/mom/test_send_simple_args.rb b/test/mom/test_send_simple_args.rb index d43d5764..dfb21278 100644 --- a/test/mom/test_send_simple_args.rb +++ b/test/mom/test_send_simple_args.rb @@ -25,7 +25,7 @@ module Risc def test_load_arg_const produced = produce_body assert_equal LoadConstant , produced.next(19).class - assert_equal Mom::IntegerConstant , produced.next(19).constant.class + assert_equal Parfait::Integer , produced.next(19).constant.class assert_equal 1 , produced.next(19).constant.value end def test_load_next_m diff --git a/test/mom/test_while.rb b/test/mom/test_while.rb index 821143cd..ca6515f2 100644 --- a/test/mom/test_while.rb +++ b/test/mom/test_while.rb @@ -18,7 +18,7 @@ module Risc def test_false_load produced = produce_body - assert_equal Mom::FalseConstant , produced.next(3).constant.class + assert_equal Parfait::FalseClass , produced.next(3).constant.class end def test_false_check produced = produce_body @@ -26,7 +26,7 @@ module Risc end def test_nil_load produced = produce_body - assert_equal Mom::NilConstant , produced.next(6).constant.class + assert_equal Parfait::NilClass , produced.next(6).constant.class end def test_nil_check produced = produce_body diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 1f96eb3e..45c63ea6 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -14,7 +14,14 @@ class TestSpace < MiniTest::Test def test_booted assert_equal true , @machine.booted end - + def test_space_length + assert_equal 8 , @space.get_type.instance_length , @space.get_type.inspect + end + def test_singletons + assert @space.true_object , "No truth" + assert @space.false_object , "No lies" + assert @space.nil_object , "No nothing" + end def test_methods_booted word = @space.get_class_by_name(:Word).instance_type assert_equal 4 , word.method_names.get_length @@ -145,7 +152,7 @@ class TestSpace < MiniTest::Test assert_equal 0 , type.methods.get_length , "name #{type.name}" end end - def ttest_no_methods_in_classes + def test_no_methods_in_classes test_remove_methods @space.classes.each do |name , cl| assert_equal 0 , cl.instance_type.methods.get_length , "name #{cl.name}" diff --git a/test/parfait/type/test_type_api.rb b/test/parfait/type/test_type_api.rb index fbe043b7..d6f81900 100644 --- a/test/parfait/type/test_type_api.rb +++ b/test/parfait/type/test_type_api.rb @@ -27,7 +27,7 @@ class TypeApi < MiniTest::Test assert_equal Parfait::Space , space.class type = space.get_type assert_equal Parfait::Type , type.class - assert_equal 7 , type.names.get_length + assert_equal 8 , type.names.get_length assert_equal type.object_class.class , Parfait::Class assert_equal type.object_class.name , :Space end