## ------------------------------------------------------------------------- ##
## Object
## ------------------------------------------------------------------------- ##

^Object := ^Class.new({});

# NOTE:
# these three methods need to also live as ^Object instance
# methods too. They would normally be inherited from ^Object
# by ^Class, but becuase they need to exist prior to the 
# creation of ^Object, we have to duplicate them. Better 
# suggestions welcome :)

^Object.add_method('BUILD',      ^Class.get_method('BUILD'));
^Object.add_method('BUILDALL',   ^Class.get_method('BUILDALL'));
^Object.add_method('DESTROYALL', ^Class.get_method('DESTROYALL'));

^Object.add_method('meta',  -> { self`meta(); });
^Object.add_method('id',    -> { self`id();   });

^Object.add_method('isa', -> $class {
    $?CLASS.name`eq($class)`if_else(
        -> { true },
        -> {
            &dispatcher := $?CLASS.dispatcher('descendant');            
            -> {
                &redo     := &?SUB;
                $ancestor := &WALKCLASS`(&dispatcher);                        
                -> {
                    $ancestor.name`eq($class)`if_else(
                        -> { true     },
                        -> { &redo`() }
                    );
                }`do_if($ancestor`not_nil)
            }`();
        }
    );    
});

^Object.add_method('can', -> $label {
    &WALKMETH`($?CLASS.dispatcher('descendant'), $label)`not_nil`if_else(
        -> { true  },
        -> { false }
    );
});
