# Most minimal classes and methods.
# This module is the root of the standard module hierarchy.
-package kernel
+module kernel
import end # Mark this module is a top level one. (must be only one)
# Return the global sys object, the only instance of the `Sys` class.
protected fun sys: Sys is intern
+
+ # The hash code of the object.
+ # Assuming that a == b -> a.hash == b.hash
+ ##
+ # Without redefinition, it is based on the `object_id` of the instance.
+ fun hash: Int do return object_id / 8
end
# The main class of the program.
redef fun ==(b) is intern
redef fun !=(b) is intern
redef fun output is intern
+ redef fun hash
+ do
+ if self then
+ return 1
+ else
+ return 0
+ end
+ end
end
# Native floating point numbers.
redef type OTHER: Int
redef fun object_id is intern
+ redef fun hash do return self
redef fun ==(i) is intern
redef fun !=(i) is intern
redef fun output is intern
end
end
- # Execute 'each' for each integer in [self..last]
- fun enumerate_to(last: Int)
- !each(i: Int)
- do
- var cur = self
- while cur <= last do
- each(cur)
- cur += 1
- end
- end
-
- # Execute 'each' for each integer in [self..after[
- fun enumerate_before(after: Int)
- !each(i: Int)
- do
- var cur = self
- while cur < after do
- each(cur)
- cur += 1
- end
- end
-
# The absolute value of self
#
# assert (-10).abs == 10
redef type OTHER: Char
redef fun object_id is intern
+ redef fun hash do return ascii
redef fun ==(o) is intern
redef fun !=(o) is intern
redef fun output is intern
# Pointer classes are used to manipulate extern C structures.
extern Pointer
+ # Is the address behind this Object at NULL?
+ fun address_is_null: Bool `{ return recv == NULL; `}
end