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
|
||||||
end
|
end
|
||||||
class TrueConstant < Constant
|
class TrueConstant < Constant
|
||||||
|
def to_parfait(compiler)
|
||||||
|
Parfait.object_space.true_object
|
||||||
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:TrueClass).instance_type
|
Parfait.object_space.get_class_by_name(:TrueClass).instance_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class FalseConstant < Constant
|
class FalseConstant < Constant
|
||||||
|
def to_parfait(compiler)
|
||||||
|
Parfait.object_space.false_object
|
||||||
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:FalseClass).instance_type
|
Parfait.object_space.get_class_by_name(:FalseClass).instance_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class NilConstant < Constant
|
class NilConstant < Constant
|
||||||
|
def to_parfait(compiler)
|
||||||
|
Parfait.object_space.nil_object
|
||||||
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:NilClass).instance_type
|
Parfait.object_space.get_class_by_name(:NilClass).instance_type
|
||||||
end
|
end
|
||||||
@ -48,6 +57,11 @@ module Mom
|
|||||||
def initialize(value)
|
def initialize(value)
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
|
def to_parfait(compiler)
|
||||||
|
value = Parfait.new_word(@value)
|
||||||
|
compiler.add_constant(value)
|
||||||
|
value
|
||||||
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
Parfait.object_space.get_class_by_name(:Word).instance_type
|
Parfait.object_space.get_class_by_name(:Word).instance_type
|
||||||
end
|
end
|
||||||
|
@ -29,10 +29,19 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
# adding other base classes in here for now:
|
# adding other base classes in here for now:
|
||||||
class FalseClass
|
class FalseClass < Data2
|
||||||
end
|
#FIXME: this is "just" for compilation
|
||||||
class TrusClass
|
def initialize
|
||||||
end
|
end
|
||||||
class NilClass
|
end
|
||||||
|
class TrueClass < Data2
|
||||||
|
#FIXME: this is "just" for compilation
|
||||||
|
def initialize
|
||||||
|
end
|
||||||
|
end
|
||||||
|
class NilClass < Data2
|
||||||
|
#FIXME: this is "just" for compilation
|
||||||
|
def initialize
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -44,9 +44,13 @@ module Parfait
|
|||||||
@classes.each do |name , cl|
|
@classes.each do |name , cl|
|
||||||
add_type(cl.instance_type)
|
add_type(cl.instance_type)
|
||||||
end
|
end
|
||||||
|
@true_object = Parfait::TrueClass.new
|
||||||
|
@false_object = Parfait::FalseClass.new
|
||||||
|
@nil_object = Parfait::NilClass.new
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :classes , :first_message
|
attr_reader :classes , :first_message , :first_integer
|
||||||
|
attr_reader :true_object , :false_object , :nil_object
|
||||||
|
|
||||||
def each_type
|
def each_type
|
||||||
@types.values.each do |type|
|
@types.values.each do |type|
|
||||||
|
@ -140,8 +140,9 @@ module Risc
|
|||||||
Kernel: {}, #fix, kernel is a class, but should be a module
|
Kernel: {}, #fix, kernel is a class, but should be a module
|
||||||
BinaryCode: {next: :BinaryCode} ,
|
BinaryCode: {next: :BinaryCode} ,
|
||||||
Space: {classes: :Dictionary , types: :Dictionary ,
|
Space: {classes: :Dictionary , types: :Dictionary ,
|
||||||
first_message: :Message , single_true: :TrueClass,
|
first_message: :Message , first_integer: :Integer ,
|
||||||
single_false: :FalseClass , single_nil: :NilClass},
|
true_object: :TrueClass,
|
||||||
|
false_object: :FalseClass , nil_object: :NilClass},
|
||||||
NamedList: {},
|
NamedList: {},
|
||||||
Type: {names: :List , types: :List ,
|
Type: {names: :List , types: :List ,
|
||||||
object_class: :Class, methods: :List } ,
|
object_class: :Class, methods: :List } ,
|
||||||
|
@ -19,7 +19,7 @@ module Risc
|
|||||||
|
|
||||||
def test_false_load
|
def test_false_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Mom::FalseConstant , produced.next(2).constant.class
|
assert_equal Parfait::FalseClass , produced.next(2).constant.class
|
||||||
end
|
end
|
||||||
def test_false_check
|
def test_false_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
@ -27,7 +27,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_nil_load
|
def test_nil_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Mom::NilConstant , produced.next(5).constant.class
|
assert_equal Parfait::NilClass , produced.next(5).constant.class
|
||||||
end
|
end
|
||||||
def test_nil_check
|
def test_nil_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
|
@ -18,7 +18,7 @@ module Risc
|
|||||||
|
|
||||||
def test_false_load
|
def test_false_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Mom::FalseConstant , produced.next(2).constant.class
|
assert_equal Parfait::FalseClass , produced.next(2).constant.class
|
||||||
end
|
end
|
||||||
def test_isnotzero
|
def test_isnotzero
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
@ -35,7 +35,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_nil_load
|
def test_nil_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Mom::NilConstant , produced.next(5).constant.class
|
assert_equal Parfait::NilClass , produced.next(5).constant.class
|
||||||
end
|
end
|
||||||
def test_nil_check
|
def test_nil_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
|
@ -25,7 +25,7 @@ module Risc
|
|||||||
def test_load_arg_const
|
def test_load_arg_const
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal LoadConstant , produced.next(19).class
|
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
|
assert_equal 1 , produced.next(19).constant.value
|
||||||
end
|
end
|
||||||
def test_load_next_m
|
def test_load_next_m
|
||||||
|
@ -18,7 +18,7 @@ module Risc
|
|||||||
|
|
||||||
def test_false_load
|
def test_false_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Mom::FalseConstant , produced.next(3).constant.class
|
assert_equal Parfait::FalseClass , produced.next(3).constant.class
|
||||||
end
|
end
|
||||||
def test_false_check
|
def test_false_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
@ -26,7 +26,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_nil_load
|
def test_nil_load
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
assert_equal Mom::NilConstant , produced.next(6).constant.class
|
assert_equal Parfait::NilClass , produced.next(6).constant.class
|
||||||
end
|
end
|
||||||
def test_nil_check
|
def test_nil_check
|
||||||
produced = produce_body
|
produced = produce_body
|
||||||
|
@ -14,7 +14,14 @@ class TestSpace < MiniTest::Test
|
|||||||
def test_booted
|
def test_booted
|
||||||
assert_equal true , @machine.booted
|
assert_equal true , @machine.booted
|
||||||
end
|
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
|
def test_methods_booted
|
||||||
word = @space.get_class_by_name(:Word).instance_type
|
word = @space.get_class_by_name(:Word).instance_type
|
||||||
assert_equal 4 , word.method_names.get_length
|
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}"
|
assert_equal 0 , type.methods.get_length , "name #{type.name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def ttest_no_methods_in_classes
|
def test_no_methods_in_classes
|
||||||
test_remove_methods
|
test_remove_methods
|
||||||
@space.classes.each do |name , cl|
|
@space.classes.each do |name , cl|
|
||||||
assert_equal 0 , cl.instance_type.methods.get_length , "name #{cl.name}"
|
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
|
assert_equal Parfait::Space , space.class
|
||||||
type = space.get_type
|
type = space.get_type
|
||||||
assert_equal Parfait::Type , type.class
|
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.class , Parfait::Class
|
||||||
assert_equal type.object_class.name , :Space
|
assert_equal type.object_class.name , :Space
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user