X-Git-Url: http://nitlanguage.org diff --git a/lib/core/kernel.nit b/lib/core/kernel.nit index a8ec1c5..fe45072 100644 --- a/lib/core/kernel.nit +++ b/lib/core/kernel.nit @@ -644,12 +644,17 @@ universal Byte # `i` bits shift fo the left # # assert 5u8 << 1 == 10u8 - fun <<(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 `{ 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 `{ return (uint32_t)self; `} redef fun to_i is intern redef fun to_f is intern @@ -694,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. @@ -738,12 +746,12 @@ universal Int # `i` bits shift fo the left # # assert 5 << 1 == 10 - fun <<(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 `{ 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 @@ -802,7 +810,7 @@ universal Int # assert 65.code_point == 'A' # assert 10.code_point == '\n' # assert 0x220B.code_point == '∋' - fun code_point: 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) # @@ -862,9 +870,9 @@ universal Int do assert self >= 0 and self <= 36 # TODO plan for this if self < 10 then - return (self + '0'.ascii).ascii + return (self + '0'.code_point).code_point else - return (self + ('a'.ascii - 10)).ascii + return (self - 10 + 'a'.code_point).code_point end end @@ -873,15 +881,7 @@ universal Int # assert (-10).abs == 10 # assert 10.abs == 10 # assert 0.abs == 0 - fun abs: Int - do - if self >= 0 - then - return self - else - return -1 * self - end - end + fun abs: Int do return if self >= 0 then self else -self end # Native characters. @@ -906,7 +906,7 @@ universal Char printf("%c", self); } `} - redef fun hash do return ascii + redef fun hash do return code_point redef fun ==(o) is intern redef fun !=(o) is intern @@ -920,7 +920,7 @@ universal Char redef fun distance(c) do - var d = self.ascii - c.ascii + var d = self.code_point - c.code_point if d >= 0 then return d else @@ -937,9 +937,9 @@ universal Char if self == '-' then return -1 else if is_digit then - return self.ascii - '0'.ascii + return self.code_point - '0'.code_point else - return self.to_lower.ascii - 'a'.ascii + 10 + return self.to_lower.code_point - 'a'.code_point + 10 end end @@ -956,7 +956,7 @@ universal Char # assert 'A'.code_point == 65 # assert '\n'.code_point == 10 # assert '∋'.code_point == 0x220B - fun code_point: Int `{ return (long)self; `} + fun code_point: Int is intern `{ return (long)self; `} # Is `self` an ASCII character ? # @@ -973,7 +973,7 @@ universal Char fun to_lower: Char do if is_upper then - return (ascii + ('a'.distance('A'))).ascii + return (code_point + ('a'.distance('A'))).code_point else return self end @@ -988,7 +988,7 @@ universal Char fun to_upper: Char do if is_lower then - return (ascii - ('a'.distance('A'))).ascii + return (code_point - ('a'.distance('A'))).code_point else return self end @@ -1049,7 +1049,7 @@ universal Char # assert '\t'.is_whitespace == true fun is_whitespace: Bool do - var i = ascii + var i = code_point return i <= 0x20 or i == 0x7F end end @@ -1062,3 +1062,14 @@ extern class Pointer # Free the memory pointed by this pointer fun free `{ free(self); `} end + +# Task with a `main` method to be implemented by subclasses +# +# This class is provided for compatibility between different parallelization systems. +# It can be used to run a fragment of code on a different thread and +# to register a reaction to UI events. +interface Task + + # Main method of this task + fun main do end +end