From cb46a0593522dcd10636a603c1c5b3eab95330bf Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 3 Feb 2016 21:02:08 -0500 Subject: [PATCH] lib/core: use intern && ffi since it is now allowed by `c_src` Signed-off-by: Jean Privat --- lib/core/kernel.nit | 28 +++++++--------------------- lib/core/math.nit | 12 +++--------- lib/core/text/native.nit | 8 ++------ 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/lib/core/kernel.nit b/lib/core/kernel.nit index 125e95f..399487a 100644 --- a/lib/core/kernel.nit +++ b/lib/core/kernel.nit @@ -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 @@ -749,16 +743,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 +807,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 +953,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 ? # diff --git a/lib/core/math.nit b/lib/core/math.nit index 537271c..62cd544 100644 --- a/lib/core/math.nit +++ b/lib/core/math.nit @@ -67,16 +67,12 @@ redef class Int # Returns the result of a binary AND operation on `self` and `i` # # assert 0x10 & 0x01 == 0 - fun &(i: Int): Int is intern do return band(i) - - private fun band(i: Int): Int `{ return self & i; `} + fun &(i: Int): Int is intern `{ return self & i; `} # Returns the result of a binary OR operation on `self` and `i` # # assert 0x10 | 0x01 == 0x11 - fun |(i: Int): Int is intern do return bor(i) - - private fun bor(i: Int): Int `{ return self | i; `} + fun |(i: Int): Int is intern `{ return self | i; `} # Returns the result of a binary XOR operation on `self` and `i` # @@ -179,9 +175,7 @@ redef class Byte # Returns the result of a binary AND operation on `self` and `i` # # assert 0x10u8 & 0x01u8 == 0u8 - fun &(i: Byte): Byte is intern do return band(i) - - private fun band(i: Byte): Byte `{ return self & i; `} + fun &(i: Byte): Byte is intern `{ return self & i; `} # Returns the result of a binary OR operation on `self` and `i` # diff --git a/lib/core/text/native.nit b/lib/core/text/native.nit index 051cefb..30ec0af 100644 --- a/lib/core/text/native.nit +++ b/lib/core/text/native.nit @@ -274,12 +274,8 @@ extern class NativeString `{ char* `} end # Fetch 4 chars in `self` at `pos` - fun fetch_4_chars(pos: Int): Int is intern do return fetch_4_ffi(pos) + fun fetch_4_chars(pos: Int): Int is intern `{ return (long)*((uint32_t*)(self+pos)); `} # Fetch 4 chars in `self` at `pos` - fun fetch_4_hchars(pos: Int): Int is intern do return fetch_4h_ffi(pos) - - # FIXME: To remove when bootstrap supports PR #1898 - private fun fetch_4_ffi(pos: Int): Int `{ return (long)*((uint32_t*)(self+pos)); `} - private fun fetch_4h_ffi(pos: Int): Int `{ return (long)be32toh(*((uint32_t*)(self+pos))); `} + fun fetch_4_hchars(pos: Int): Int is intern `{ return (long)be32toh(*((uint32_t*)(self+pos))); `} end -- 1.7.9.5