fix true false and nil constant
going from mom to parfait basics in place, more ripples to fix
This commit is contained in:
parent
9e9b5c7f37
commit
cb9f6973d9
@ -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
|
||||
|
@ -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
|
||||
|
@ -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|
|
||||
|
@ -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 } ,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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}"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user