core: fix typos in union_find
[nit.git] / lib / core / kernel.nit
index 125e95f..6a07060 100644 (file)
@@ -644,23 +644,17 @@ universal Byte
        # `i` bits shift fo the left
        #
        #     assert 5u8 << 1    == 10u8
-       fun <<(i: Int): Byte is intern do return lsh(i)
-
-       private fun lsh(i: Int): Byte `{ return self << i; `}
+       fun <<(i: Int): Byte is intern `{ return self << i; `}
 
        # `i` bits shift fo the right
        #
        #     assert 5u8 >> 1    == 2u8
-       fun >>(i: Int): Byte is intern do return rsh(i)
-
-       private fun rsh(i: Int): Byte `{ return self >> i; `}
+       fun >>(i: Int): Byte is intern `{ return self >> i; `}
 
        # Returns the character equivalent of `self`
        #
        # REQUIRE: `self <= 127u8`
-       fun ascii: Char is intern do return ffi_ascii
-
-       private fun ffi_ascii: Char `{ return (uint32_t)self; `}
+       fun ascii: Char is intern `{ return (uint32_t)self; `}
 
        redef fun to_i is intern
        redef fun to_f is intern
@@ -705,6 +699,9 @@ universal Byte
                        return self
                end
        end
+
+       # Is `self` an ASCII whitespace ?
+       fun is_whitespace: Bool do return self == 0x7Fu8 or self <= 0x20u8
 end
 
 # Native integer numbers.
@@ -749,16 +746,12 @@ universal Int
        # `i` bits shift fo the left
        #
        #     assert 5 << 1    == 10
-       fun <<(i: Int): Int is intern do return lsh(i)
-
-       private fun lsh(i: Int): Int `{ return self << i; `}
+       fun <<(i: Int): Int is intern `{ return self << i; `}
 
        # `i` bits shift fo the right
        #
        #     assert 5 >> 1    == 2
-       fun >>(i: Int): Int is intern do return rsh(i)
-
-       private fun rsh(i: Int): Int `{ return self >> i; `}
+       fun >>(i: Int): Int is intern `{ return self >> i; `}
 
        redef fun to_i do return self
        redef fun to_f is intern
@@ -817,9 +810,7 @@ universal Int
        #     assert 65.code_point == 'A'
        #     assert 10.code_point == '\n'
        #     assert 0x220B.code_point == '∋'
-       fun code_point: Char is intern do return cp
-
-       private fun cp: Char `{ return (uint32_t)self; `}
+       fun code_point: Char is intern `{ return (uint32_t)self; `}
 
        # Number of digits of an integer in base `b` (plus one if negative)
        #
@@ -965,9 +956,7 @@ universal Char
        #     assert 'A'.code_point == 65
        #     assert '\n'.code_point == 10
        #     assert '∋'.code_point == 0x220B
-       fun code_point: Int is intern do return cp
-
-       private fun cp: Int `{ return (long)self; `}
+       fun code_point: Int is intern `{ return (long)self; `}
 
        # Is `self` an ASCII character ?
        #
@@ -1056,22 +1045,33 @@ universal Char
        #
        #     assert 'A'.is_whitespace  == false
        #     assert ','.is_whitespace  == false
-       #     assert ' '.is_whitespace  == true
+       #     assert ' '.is_whitespace  == true # space
+       #     assert ' '.is_whitespace  == true # non-breaking space
        #     assert '\t'.is_whitespace == true
        fun is_whitespace: Bool
        do
                var i = code_point
-               return i <= 0x20 or i == 0x7F
+               return i <= 0x20 or i == 0x7F or i == 0xA0
        end
 end
 
 # Pointer classes are used to manipulate extern C structures.
 extern class Pointer
+       # C `NULL` pointer
+       new nul `{ return NULL; `}
+
        # Is the address behind this Object at NULL?
        fun address_is_null: Bool `{ return self == NULL; `}
 
        # Free the memory pointed by this pointer
        fun free `{ free(self); `}
+
+       # Use the address value
+       redef fun hash `{ return (long)(intptr_t)self; `}
+
+       # Is equal to any instance pointing to the same address
+       redef fun ==(o) do return o isa Pointer and native_equals(o)
+       private fun native_equals(o: Pointer): Bool `{ return self == o; `}
 end
 
 # Task with a `main` method to be implemented by subclasses
@@ -1084,3 +1084,12 @@ interface Task
        # Main method of this task
        fun main do end
 end
+
+# Is this program currently running in a Windows OS?
+fun is_windows: Bool `{
+#ifdef _WIN32
+       return 1;
+#else
+       return 0;
+#endif
+`}