From: Lucas Bajolet Date: Mon, 14 May 2018 18:56:51 +0000 (-0400) Subject: lib/core: remove uses of Byte for Text X-Git-Url: http://nitlanguage.org lib/core: remove uses of Byte for Text Byte is convenient for automatic modular arithmetic on 8-bit values. However, due to the way our Numeric types are handled, no automatic conversion is done when working on primitive types, and operations like comparison will fail when comparing two values of different type. This is a cause of bugs as the u8 suffix is required for comparing two bytes, and is also the cause for tedious cast operations to go back-and-forth between Byte and Int. We remove the uses of Byte in the Text API, and replace them with Int. This should not have a negative impact on performance. Signed-off-by: Lucas Bajolet --- diff --git a/contrib/brainfuck/brainfuck.nit b/contrib/brainfuck/brainfuck.nit index 4216952..d207496 100644 --- a/contrib/brainfuck/brainfuck.nit +++ b/contrib/brainfuck/brainfuck.nit @@ -18,7 +18,7 @@ module brainfuck # Interpreter for Brainfuck source code. class BFInterpreter # Data cells - var dr = new Array[Byte] + var dr = new Array[Int] # Data pointer var dp = 0 # Instruction pointer @@ -29,7 +29,7 @@ class BFInterpreter # Create an interpreter for `program`. init do - dr.add 0u8 + dr.add 0 end # Create an interpreter for the file located at `path`. @@ -51,35 +51,35 @@ class BFInterpreter # Evaluates the current instruction fun eval do var instr = program[ip] - if instr == '.'.ascii then printn dr[dp].ascii - if instr == '['.ascii then - if dr[dp] == 0u8 then + if instr == u'.' then printn dr[dp].code_point + if instr == u'[' then + if dr[dp] == 0 then ip = find_matching_rbra return end end - if instr == ']'.ascii then - if dr[dp] != 0u8 then + if instr == u']' then + if dr[dp] != 0 then ip = find_matching_lbra return end end - if instr == '>'.ascii then + if instr == u'>' then dp += 1 - if dp >= dr.length then dr.add(0u8) + if dp >= dr.length then dr.add(0) end - if instr == '<'.ascii then + if instr == u'<' then dp -= 1 if dp < 0 then abort end - if instr == '+'.ascii then - dr[dp] = dr[dp] + 1u8 + if instr == u'+' then + dr[dp] = dr[dp] + 1 end - if instr == '-'.ascii then - dr[dp] = dr[dp] - 1u8 + if instr == u'-' then + dr[dp] = dr[dp] - 1 end - if instr == ','.ascii then - dr[dp] = getc.ascii + if instr == u',' then + dr[dp] = getc.code_point end end @@ -89,14 +89,14 @@ class BFInterpreter var lbracnt = 0 loop if pos > program.length then abort - if program[pos] == ']'.ascii then + if program[pos] == u']' then if lbracnt > 0 then lbracnt -= 1 else break end end - if program[pos] == '['.ascii then lbracnt += 1 + if program[pos] == u'[' then lbracnt += 1 pos += 1 end return pos @@ -108,14 +108,14 @@ class BFInterpreter var rbracnt = 0 loop if pos < 0 then abort - if program[pos] == '['.ascii then + if program[pos] == u'[' then if rbracnt > 0 then rbracnt -= 1 else break end end - if program[pos] == ']'.ascii then rbracnt += 1 + if program[pos] == u']' then rbracnt += 1 pos -= 1 end return pos diff --git a/contrib/pep8analysis/src/parser/xss/lexer.xss b/contrib/pep8analysis/src/parser/xss/lexer.xss index 6a4d1d0..802755f 100644 --- a/contrib/pep8analysis/src/parser/xss/lexer.xss +++ b/contrib/pep8analysis/src/parser/xss/lexer.xss @@ -107,7 +107,7 @@ $ end foreach if sp >= string_len then dfa_state = -1 else - var c = string[sp].ascii + var c = string[sp].code_point sp += 1 var cr = _cr diff --git a/examples/leapfrog/leapfrog_curses.nit b/examples/leapfrog/leapfrog_curses.nit index da05bf8..995adde 100644 --- a/examples/leapfrog/leapfrog_curses.nit +++ b/examples/leapfrog/leapfrog_curses.nit @@ -124,7 +124,7 @@ redef class PlayScene while sys.stdin.poll_in do if sys.stdin.eof then return var c = sys.stdin.read_char - if c == 'q'.ascii then + if c == u'q' then self.exists = false return end diff --git a/examples/rosettacode/vignere_cipher.nit b/examples/rosettacode/vignere_cipher.nit index 565c19e..7fea059 100644 --- a/examples/rosettacode/vignere_cipher.nit +++ b/examples/rosettacode/vignere_cipher.nit @@ -19,7 +19,7 @@ fun encrypt(src, key: String): String do continue end - out.add(((c.ascii + key[j].ascii - 2u8 * 'A'.ascii) % 26u8 + 'A'.ascii).ascii) + out.add(((c.code_point + key[j].code_point - 2 * u'A') % 26 + u'A').code_point) j = (j + 1) % key.length end @@ -39,7 +39,7 @@ fun decrypt(src, key: String): String do continue end - out.add(((c.ascii - key[j].ascii + 26u8) % 26u8 + 'A'.ascii).ascii) + out.add(((c.code_point - key[j].code_point + 26) % 26 + u'A').code_point) j = (j + 1) % key.length end diff --git a/lib/actors/examples/mandelbrot/mandelbrot.nit b/lib/actors/examples/mandelbrot/mandelbrot.nit index f756970..8fa7be3 100644 --- a/lib/actors/examples/mandelbrot/mandelbrot.nit +++ b/lib/actors/examples/mandelbrot/mandelbrot.nit @@ -54,8 +54,8 @@ class Worker return res ^-1 end - fun put_line(y: Int, line: Array[Byte]) do - for i in [0..line.length[ do line[i] = get_byte(i * 8, y).to_b + fun put_line(y: Int, line: Array[Int]) do + for i in [0..line.length[ do line[i] = get_byte(i * 8, y) end fun work do @@ -70,7 +70,7 @@ end redef class Sys var n = 0 var inv_n: Float is noautoinit - var data: Array[Array[Byte]] is noautoinit + var data: Array[Array[Int]] is noautoinit var crb: Array[Float] is noautoinit var cib: Array[Float] is noautoinit var atomic = new AtomicInt(0) @@ -89,8 +89,8 @@ for i in [0..n[ do sys.cib[i] = i.to_f * inv_n - 1.0 sys.crb[i] = i.to_f * inv_n - 1.5 end -sys.data = new Array[Array[Byte]].with_capacity(n) -for i in [0..n[ do sys.data[i] = new Array[Byte].filled_with(0.to_b, (n) / 8) +sys.data = new Array[Array[Int]].with_capacity(n) +for i in [0..n[ do sys.data[i] = new Array[Int].filled_with(0, (n) / 8) # Parallel Approach var actors = new Array[Worker] diff --git a/lib/base64/base64.nit b/lib/base64/base64.nit index 26e1207..622bb51 100644 --- a/lib/base64/base64.nit +++ b/lib/base64/base64.nit @@ -21,38 +21,38 @@ redef class Char # Is `self` a valid Base64 character ? fun is_base64_char: Bool do if code_point >= 127 then return false - return ascii.is_base64_char + return code_point.is_base64_char end end -redef class Byte +redef class Int # Is `self` a valid Base64 character ? fun is_base64_char: Bool do - if self == b'+' then return true - if self == b'/' then return true - if self > b'Z' then - if self < b'a' then return false - if self <= b'z' then return true + if self == u'+' then return true + if self == u'/' then return true + if self > u'Z' then + if self < u'a' then return false + if self <= u'z' then return true return false end - if self >= b'A' then return true - if self <= b'9' and self >= b'0' then return true + if self >= u'A' then return true + if self <= u'9' and self >= u'0' then return true return false end # Returns the `base64` equivalent of `self` # # REQUIRE `self`.`is_base64_char` - fun to_base64_char: Byte do - if self == b'+' then return 62u8 - if self == b'/' then return 63u8 - if self > b'Z' then - if self < b'a' then abort - if self <= b'z' then return self - 71u8 + fun to_base64_char: Int do + if self == u'+' then return 62 + if self == u'/' then return 63 + if self > u'Z' then + if self < u'a' then abort + if self <= u'z' then return self - 71 abort end - if self >= b'A' then return self - 0x41u8 - if self <= b'9' and self >= b'0' then return self + 4u8 + if self >= u'A' then return self - 0x41 + if self <= u'9' and self >= u'0' then return self + 4 abort end end @@ -79,26 +79,26 @@ redef class CString var in_off = 0 for s in [0 .. steps[ do - var ind = ((self[in_off] & 0b1111_1100u8) >> 2).to_i + var ind = (self[in_off] & 0b1111_1100) >> 2 result.add base64_bytes[ind] - ind = ((self[in_off] & 0b0000_0011u8) << 4).to_i | ((self[in_off + 1] & 0b1111_0000u8) >> 4).to_i + ind = ((self[in_off] & 0b0000_0011) << 4) | ((self[in_off + 1] & 0b1111_0000) >> 4) result.add base64_bytes[ind] - ind = ((self[in_off + 1] & 0b0000_1111u8) << 2).to_i | ((self[in_off + 2] & 0b1100_0000u8) >> 6).to_i + ind = ((self[in_off + 1] & 0b0000_1111) << 2) | ((self[in_off + 2] & 0b1100_0000) >> 6) result.add base64_bytes[ind] - ind = (self[in_off + 2] & 0b0011_1111u8).to_i + ind = (self[in_off + 2] & 0b0011_1111) result.add base64_bytes[ind] in_off += 3 end if bytes_in_last_step == 1 then - result.add base64_bytes[((self[in_off] & 0b1111_1100u8) >> 2).to_i] - result.add base64_bytes[((self[in_off] & 0b0000_0011u8) << 4).to_i] + result.add base64_bytes[(self[in_off] & 0b1111_1100) >> 2] + result.add base64_bytes[(self[in_off] & 0b0000_0011) << 4] else if bytes_in_last_step == 2 then - result.add base64_bytes[((self[in_off] & 0b1111_1100u8) >> 2).to_i] - result.add base64_bytes[(((self[in_off] & 0b0000_0011u8) << 4) | ((self[in_off + 1] & 0b1111_0000u8) >> 4)).to_i] - result.add base64_bytes[((self[in_off + 1] & 0b0000_1111u8) << 2).to_i] + result.add base64_bytes[(self[in_off] & 0b1111_1100) >> 2] + result.add base64_bytes[((self[in_off] & 0b0000_0011) << 4) | ((self[in_off + 1] & 0b1111_0000) >> 4)] + result.add base64_bytes[(self[in_off + 1] & 0b0000_1111) << 2] end var rempad = if bytes_in_last_step > 0 then 3 - bytes_in_last_step else 0 - for i in [0 .. rempad[ do result.add b'=' + for i in [0 .. rempad[ do result.add u'=' return result end @@ -116,7 +116,7 @@ redef class CString if length == 0 then return new Bytes.empty # Avoids constant unboxing - var pad = b'=' + var pad = '=' var result = new Bytes.with_capacity((length / 4 + 1) * 3) @@ -130,15 +130,15 @@ redef class CString break end # Ignore whitespaces - if b <= 0x20u8 then continue + if b <= 0x20 then continue if not b.is_base64_char then continue curr <<= 6 curr += b.to_base64_char.to_i cnt += 1 if cnt == 4 then - result.add(((curr & 0xFF0000) >> 16).to_b) - result.add(((curr & 0xFF00) >> 8).to_b) - result.add((curr & 0xFF).to_b) + result.add ((curr & 0xFF0000) >> 16) + result.add ((curr & 0xFF00) >> 8) + result.add (curr & 0xFF) curr = 0 cnt = 0 end @@ -147,16 +147,16 @@ redef class CString var pads = 0 for i in [endpos .. length[ do var b = self[i] - if b <= 0x20u8 then continue + if b <= 0x20 then continue pads += 1 end if cnt == 2 then curr >>= 4 - result.add(curr.to_b) + result.add(curr) else if cnt == 3 then curr >>= 2 - result.add(((curr & 0xFF00) >> 8).to_b) - result.add((curr & 0xFF).to_b) + result.add ((curr & 0xFF00) >> 8) + result.add (curr & 0xFF) end end return result @@ -177,19 +177,19 @@ redef class CString var rlen = 0 var opos = length for i in [0 .. length[ do - if self[i] == b'=' then + if self[i] == u'=' then opos = i break end if self[i].is_whitespace then continue - if not self[i].is_base64_char then return new Error("Invalid Base64 character at position {i}: {self[i].ascii}") + if not self[i].is_base64_char then return new Error("Invalid Base64 character at position {i}: {self[i].code_point}") rlen += 1 if rlen > 4 then rlen -= 4 end var pad = 0 for i in [opos .. length[ do if self[i].is_whitespace then continue - if self[i] != b'=' then return new Error("Invalid padding character {self[i].ascii} at position {i}") + if self[i] != u'=' then return new Error("Invalid padding character {self[i].code_point} at position {i}") pad += 1 end if rlen + pad != 4 then return new Error("Invalid padding length") diff --git a/lib/binary/binary.nit b/lib/binary/binary.nit index b8f8b5c..8b39d31 100644 --- a/lib/binary/binary.nit +++ b/lib/binary/binary.nit @@ -18,7 +18,7 @@ # var w = new FileWriter.open("/tmp/data.bin") # w.write "hello" # w.write_int64 123456789 -# w.write_byte 3u8 +# w.write_byte 3 # w.write_float 1.25 # w.write_double 1.234567 # w.write_bits(true, false, true) @@ -70,7 +70,7 @@ redef abstract class Writer super BinaryStream # Write a boolean `value` on a byte, using 0 for `false` and 1 for `true` - fun write_bool(value: Bool) do write_byte if value then 1u8 else 0u8 + fun write_bool(value: Bool) do write_byte if value then 1 else 0 # Write up to 8 `Bool` in a byte # @@ -81,9 +81,9 @@ redef abstract class Writer do assert bits.length <= 8 - var int = 0u8 + var int = 0 for b in bits.length.times do - if bits[b] then int |= 1u8 << (7 - b) + if bits[b] then int |= 1 << (7 - b) end write_byte int @@ -97,7 +97,7 @@ redef abstract class Writer fun write_string(text: Text) do write text - write_byte 0x00u8 + write_byte 0x00 end # Write the length as a 64 bits integer, then the content of `text` @@ -184,7 +184,7 @@ redef abstract class Reader if byte <= 0 then return buf.to_s end - buf.add byte.to_b + buf.add byte end end @@ -341,7 +341,7 @@ end redef class Int # Utility for `BinaryWriter` - private fun int64_byte_at(index: Int, big_endian: Bool): Byte `{ + private fun int64_byte_at(index: Int, big_endian: Bool): Int `{ union { unsigned char bytes[8]; int64_t val; @@ -360,7 +360,7 @@ end redef class Float # Utility for `BinaryWriter` - private fun float_byte_at(index: Int, big_endian: Bool): Byte `{ + private fun float_byte_at(index: Int, big_endian: Bool): Int `{ union { unsigned char bytes[4]; float val; @@ -377,7 +377,7 @@ redef class Float `} # Utility for `BinaryWriter` - private fun double_byte_at(index: Int, big_endian: Bool): Byte `{ + private fun double_byte_at(index: Int, big_endian: Bool): Int `{ union { unsigned char bytes[8]; double val; diff --git a/lib/core/bytes.nit b/lib/core/bytes.nit index 73802a7..f386c47 100644 --- a/lib/core/bytes.nit +++ b/lib/core/bytes.nit @@ -22,83 +22,83 @@ intrude import text::flat # Any kind of entity which can be searched for in a Sequence of Byte interface BytePattern # Return the first occurence of `self` in `b`, or -1 if not found - fun first_index_in(b: SequenceRead[Byte]): Int do return first_index_in_from(b, 0) + fun first_index_in(b: SequenceRead[Int]): Int do return first_index_in_from(b, 0) # Return the first occurence of `self` in `b` starting at `from`, or -1 if not found - fun first_index_in_from(b: SequenceRead[Byte], from: Int): Int is abstract + fun first_index_in_from(b: SequenceRead[Int], from: Int): Int is abstract # Return the last occurence of `self` in `b`, or -1 if not found - fun last_index_in(b: SequenceRead[Byte]): Int do return last_index_in_from(b, b.length - 1) + fun last_index_in(b: SequenceRead[Int]): Int do return last_index_in_from(b, b.length - 1) # Return the last occurence of `self` in `b`, or -1 if not found - fun last_index_in_from(b: SequenceRead[Byte], from: Int): Int is abstract + fun last_index_in_from(b: SequenceRead[Int], from: Int): Int is abstract # Returns the indexes of all the occurences of `self` in `b` - fun search_all_in(b: SequenceRead[Byte]): SequenceRead[Int] is abstract + fun search_all_in(b: SequenceRead[Int]): SequenceRead[Int] is abstract # Length of the pattern fun pattern_length: Int is abstract # Appends `self` to `b` - fun append_to(b: Sequence[Byte]) is abstract + fun append_to(b: Sequence[Int]) is abstract # Is `self` a prefix for `b` ? - fun is_prefix(b: SequenceRead[Byte]): Bool is abstract + fun is_prefix(b: SequenceRead[Int]): Bool is abstract # Is `self` a suffix for `b` ? - fun is_suffix(b: SequenceRead[Byte]): Bool is abstract + fun is_suffix(b: SequenceRead[Int]): Bool is abstract end -redef class Byte +redef class Int super BytePattern # Write self as a string into `ns` at position `pos` private fun add_digest_at(ns: CString, pos: Int) do - var tmp = (0xF0u8 & self) >> 4 - ns[pos] = if tmp >= 0x0Au8 then tmp + 0x37u8 else tmp + 0x30u8 - tmp = 0x0Fu8 & self - ns[pos + 1] = if tmp >= 0x0Au8 then tmp + 0x37u8 else tmp + 0x30u8 + var tmp = (0xF0 & self) >> 4 + ns[pos] = if tmp >= 0x0A then tmp + 0x37 else tmp + 0x30 + tmp = 0x0F & self + ns[pos + 1] = if tmp >= 0x0A then tmp + 0x37 else tmp + 0x30 end # Is `self` a valid hexadecimal digit (in ASCII) # # ~~~nit # intrude import core::bytes - # assert not '/'.ascii.is_valid_hexdigit - # assert '0'.ascii.is_valid_hexdigit - # assert '9'.ascii.is_valid_hexdigit - # assert not ':'.ascii.is_valid_hexdigit - # assert not '@'.ascii.is_valid_hexdigit - # assert 'A'.ascii.is_valid_hexdigit - # assert 'F'.ascii.is_valid_hexdigit - # assert not 'G'.ascii.is_valid_hexdigit - # assert not '`'.ascii.is_valid_hexdigit - # assert 'a'.ascii.is_valid_hexdigit - # assert 'f'.ascii.is_valid_hexdigit - # assert not 'g'.ascii.is_valid_hexdigit + # assert not u'/'.is_valid_hexdigit + # assert u'0'.is_valid_hexdigit + # assert u'9'.is_valid_hexdigit + # assert not u':'.is_valid_hexdigit + # assert not u'@'.is_valid_hexdigit + # assert u'A'.is_valid_hexdigit + # assert u'F'.is_valid_hexdigit + # assert not u'G'.is_valid_hexdigit + # assert not u'`'.is_valid_hexdigit + # assert u'a'.is_valid_hexdigit + # assert u'f'.is_valid_hexdigit + # assert not u'g'.is_valid_hexdigit # ~~~ private fun is_valid_hexdigit: Bool do - return (self >= 0x30u8 and self <= 0x39u8) or - (self >= 0x41u8 and self <= 0x46u8) or - (self >= 0x61u8 and self <= 0x66u8) + return (self >= 0x30 and self <= 0x39) or + (self >= 0x41 and self <= 0x46) or + (self >= 0x61 and self <= 0x66) end # `self` as a hexdigit to its byte value # # ~~~nit # intrude import core::bytes - # assert 0x39u8.hexdigit_to_byteval == 0x09u8 - # assert 0x43u8.hexdigit_to_byteval == 0x0Cu8 + # assert 0x39.hexdigit_to_byteval == 0x09 + # assert 0x43.hexdigit_to_byteval == 0x0C # ~~~ # # REQUIRE: `self.is_valid_hexdigit` - private fun hexdigit_to_byteval: Byte do - if self >= 0x30u8 and self <= 0x39u8 then - return self - 0x30u8 - else if self >= 0x41u8 and self <= 0x46u8 then - return self - 0x37u8 - else if self >= 0x61u8 and self <= 0x66u8 then - return self - 0x57u8 + private fun hexdigit_to_byteval: Int do + if self >= 0x30 and self <= 0x39 then + return self - 0x30 + else if self >= 0x41 and self <= 0x46 then + return self - 0x37 + else if self >= 0x61 and self <= 0x66 then + return self - 0x57 end # Happens only if the requirement is not met. # i.e. this abort is here to please the compiler @@ -130,20 +130,113 @@ redef class Byte redef fun append_to(b) do b.push self - # assert 'b'.ascii.is_suffix("baqsdb".to_bytes) - # assert not 'b'.ascii.is_suffix("baqsd".to_bytes) + # assert u'b'.is_suffix("baqsdb".to_bytes) + # assert not u'b'.is_suffix("baqsd".to_bytes) redef fun is_suffix(b) do return b.length != 0 and b.last == self - # assert 'b'.ascii.is_prefix("baqsdb".to_bytes) - # assert not 'b'.ascii.is_prefix("aqsdb".to_bytes) + # assert u'b'.is_prefix("baqsdb".to_bytes) + # assert not u'b'.is_prefix("aqsdb".to_bytes) redef fun is_prefix(b) do return b.length != 0 and b.first == self + + # A signed big-endian representation of `self` + # + # ~~~ + # assert 1.to_bytes.hexdigest == "01" + # assert 255.to_bytes.hexdigest == "FF" + # assert 256.to_bytes.hexdigest == "0100" + # assert 65535.to_bytes.hexdigest == "FFFF" + # assert 65536.to_bytes.hexdigest == "010000" + # ~~~ + # + # Negative values are converted to their two's complement. + # Be careful as the result can be ambiguous. + # + # ~~~ + # assert (-1).to_bytes.hexdigest == "FF" + # assert (-32).to_bytes.hexdigest == "E0" + # assert (-512).to_bytes.hexdigest == "FE00" + # assert (-65794).to_bytes.hexdigest == "FEFEFE" + # ~~~ + # + # Optionally, set `n_bytes` to the desired number of bytes in the output. + # This setting can disambiguate the result between positive and negative + # integers. Be careful with this parameter as the result may overflow. + # + # ~~~ + # assert 1.to_bytes(2).hexdigest == "0001" + # assert 65535.to_bytes(2).hexdigest == "FFFF" + # assert (-1).to_bytes(2).hexdigest == "FFFF" + # assert (-512).to_bytes(4).hexdigest == "FFFFFE00" + # assert 0x123456.to_bytes(2).hexdigest == "3456" + # ~~~ + # + # For 0, a Bytes object with single nul byte is returned (instead of an empty Bytes object). + # + # ~~~ + # assert 0.to_bytes.hexdigest == "00" + # ~~~ + # + # For positive integers, `Bytes::to_i` can reverse the operation. + # + # ~~~ + # assert 1234.to_bytes.to_i == 1234 + # ~~~ + # + # Require self >= 0 + fun to_bytes(n_bytes: nullable Int): Bytes do + + # If 0, force using at least one byte + if self == 0 and n_bytes == null then n_bytes = 1 + + # Compute the len (log256) + var len = 1 + var max = 256 + var s = self.abs + while s >= max do + len += 1 + max *= 256 + end + + # Two's complement + s = self + if self < 0 then + var ff = 0 + for j in [0..len[ do + ff *= 0x100 + ff += 0xFF + end + + s = ((-self) ^ ff) + 1 + end + + # Cut long values + if n_bytes != null and len > n_bytes then len = n_bytes + + # Allocate the buffer + var cap = n_bytes or else len + var res = new Bytes.with_capacity(cap) + + var filler = if self < 0 then 0xFF else 0 + for i in [0..cap[ do res[i] = filler + + # Fill it starting with the end + var i = cap + var sum = s + while i > cap - len do + i -= 1 + res[i] = sum % 256 + sum /= 256 + end + + return res + end end # A buffer containing Byte-manipulation facilities # # Uses Copy-On-Write when persisted class Bytes - super AbstractArray[Byte] + super AbstractArray[Int] super BytePattern # A CString being a char*, it can be used as underlying representation here. @@ -178,8 +271,8 @@ class Bytes redef fun is_empty do return length == 0 # var b = new Bytes.empty - # b.add 101u8 - # assert b[0] == 101u8 + # b.add 101 + # assert b[0] == 101 redef fun [](i) do assert i >= 0 assert i < length @@ -202,13 +295,13 @@ class Bytes fun trim: Bytes do var st = 0 while st < length do - if self[st] > 0x20u8 then break + if self[st] > 0x20 then break st += 1 end if st >= length then return new Bytes.empty var ed = length - 1 while ed > 0 do - if self[ed] > 0x20u8 then break + if self[ed] > 0x20 then break ed -= 1 end return slice(st, ed - st + 1) @@ -304,8 +397,8 @@ class Bytes var i = 0 var oi = 0 while i < length do - ns[oi] = 0x5Cu8 # b'\\' - ns[oi+1] = 0x78u8 # b'x' + ns[oi] = u'\\' + ns[oi+1] = u'x' self[i].add_digest_at(ns, oi+2) i += 1 oi += 4 @@ -328,12 +421,12 @@ class Bytes var oi = 0 while i < length do var c = self[i] - var b = 128u8 - while b > 0u8 do - if c & b == 0u8 then - ns[oi] = 0x30u8 # b'0' + var b = 128 + while b > 0 do + if c & b == 0 then + ns[oi] = u'0' else - ns[oi] = 0x31u8 # b'1' + ns[oi] = u'1' end oi += 1 b = b >> 1 @@ -394,7 +487,7 @@ class Bytes end # Two's complement is `signed` - if signed == true and not_empty and first > 0x80u8 then + if signed == true and not_empty and first > 0x80 then var ff = 0 for j in [0..length[ do ff *= 0x100 @@ -408,7 +501,7 @@ class Bytes end # var b = new Bytes.with_capacity(1) - # b[0] = 101u8 + # b[0] = 101 # assert b.to_s == "e" redef fun []=(i, v) do if persisted then regen @@ -419,7 +512,7 @@ class Bytes end # var b = new Bytes.empty - # b.add 101u8 + # b.add 101 # assert b.to_s == "e" redef fun add(c) do if persisted then regen @@ -446,7 +539,7 @@ class Bytes end # var b = new Bytes.empty - # b.append([104u8, 101u8, 108u8, 108u8, 111u8]) + # b.append([104, 101, 108, 108, 111]) # assert b.to_s == "hello" redef fun append(arr) do if arr isa Bytes then @@ -457,7 +550,7 @@ class Bytes end # var b = new Bytes.empty - # b.append([0x41u8, 0x41u8, 0x18u8]) + # b.append([0x41, 0x41, 0x18]) # b.pop # assert b.to_s == "AA" redef fun pop do @@ -556,7 +649,7 @@ class Bytes # Splits the content on self when encountering `b` # - # var a = "String is string".to_bytes.split_with('s'.ascii) + # var a = "String is string".to_bytes.split_with(u's') # assert a.length == 3 # assert a[0].hexdigest == "537472696E672069" # assert a[1].hexdigest == "20" @@ -576,7 +669,7 @@ class Bytes # Splits `self` in two parts at the first occurence of `b` # - # var a = "String is string".to_bytes.split_once_on('s'.ascii) + # var a = "String is string".to_bytes.split_once_on(u's') # assert a[0].hexdigest == "537472696E672069" # assert a[1].hexdigest == "20737472696E67" fun split_once_on(b: BytePattern): Array[Bytes] do @@ -590,7 +683,7 @@ class Bytes # Replaces all the occurences of `this` in `self` by `by` # - # var b = "String is string".to_bytes.replace(0x20u8, 0x41u8) + # var b = "String is string".to_bytes.replace(0x20, 0x41) # assert b.hexdigest == "537472696E6741697341737472696E67" fun replace(pattern: BytePattern, bytes: BytePattern): Bytes do if is_empty then return new Bytes.empty @@ -624,20 +717,20 @@ class Bytes var pos = 0 while pos < length do var b = self[pos] - if b != '%'.ascii then + if b != u'%' then tmp.add b pos += 1 continue end if length - pos < 2 then - tmp.add '%'.ascii + tmp.add u'%' pos += 1 continue end var bn = self[pos + 1] var bnn = self[pos + 2] if not bn.is_valid_hexdigit or not bnn.is_valid_hexdigit then - tmp.add '%'.ascii + tmp.add u'%' pos += 1 continue end @@ -673,7 +766,7 @@ class Bytes end private class BytesIterator - super IndexedIterator[Byte] + super IndexedIterator[Int] var tgt: CString @@ -690,107 +783,12 @@ private class BytesIterator redef fun item do return tgt[index] end -redef class Int - # A signed big-endian representation of `self` - # - # ~~~ - # assert 1.to_bytes.hexdigest == "01" - # assert 255.to_bytes.hexdigest == "FF" - # assert 256.to_bytes.hexdigest == "0100" - # assert 65535.to_bytes.hexdigest == "FFFF" - # assert 65536.to_bytes.hexdigest == "010000" - # ~~~ - # - # Negative values are converted to their two's complement. - # Be careful as the result can be ambiguous. - # - # ~~~ - # assert (-1).to_bytes.hexdigest == "FF" - # assert (-32).to_bytes.hexdigest == "E0" - # assert (-512).to_bytes.hexdigest == "FE00" - # assert (-65794).to_bytes.hexdigest == "FEFEFE" - # ~~~ - # - # Optionally, set `n_bytes` to the desired number of bytes in the output. - # This setting can disambiguate the result between positive and negative - # integers. Be careful with this parameter as the result may overflow. - # - # ~~~ - # assert 1.to_bytes(2).hexdigest == "0001" - # assert 65535.to_bytes(2).hexdigest == "FFFF" - # assert (-1).to_bytes(2).hexdigest == "FFFF" - # assert (-512).to_bytes(4).hexdigest == "FFFFFE00" - # assert 0x123456.to_bytes(2).hexdigest == "3456" - # ~~~ - # - # For 0, a Bytes object with single nul byte is returned (instead of an empty Bytes object). - # - # ~~~ - # assert 0.to_bytes.hexdigest == "00" - # ~~~ - # - # For positive integers, `Bytes::to_i` can reverse the operation. - # - # ~~~ - # assert 1234.to_bytes.to_i == 1234 - # ~~~ - # - # Require self >= 0 - fun to_bytes(n_bytes: nullable Int): Bytes do - - # If 0, force using at least one byte - if self == 0 and n_bytes == null then n_bytes = 1 - - # Compute the len (log256) - var len = 1 - var max = 256 - var s = self.abs - while s >= max do - len += 1 - max *= 256 - end - - # Two's complement - s = self - if self < 0 then - var ff = 0 - for j in [0..len[ do - ff *= 0x100 - ff += 0xFF - end - - s = ((-self) ^ ff) + 1 - end - - # Cut long values - if n_bytes != null and len > n_bytes then len = n_bytes - - # Allocate the buffer - var cap = n_bytes or else len - var res = new Bytes.with_capacity(cap) - - var filler = if self < 0 then 0xFFu8 else 0u8 - for i in [0..cap[ do res[i] = filler - - # Fill it starting with the end - var i = cap - var sum = s - while i > cap - len do - i -= 1 - res[i] = (sum % 256).to_b - sum /= 256 - end - - return res - end -end - redef class Text # Returns a mutable copy of `self`'s bytes # # ~~~nit # assert "String".to_bytes isa Bytes - # assert "String".to_bytes == [83u8, 116u8, 114u8, 105u8, 110u8, 103u8] + # assert "String".to_bytes == [83, 116, 114, 105, 110, 103] # ~~~ fun to_bytes: Bytes do var b = new Bytes.with_capacity(byte_length) @@ -817,7 +815,7 @@ redef class Text # Returns a new `Bytes` instance with the digest as content # - # assert "0B1F4D".hexdigest_to_bytes == [0x0Bu8, 0x1Fu8, 0x4Du8] + # assert "0B1F4D".hexdigest_to_bytes == [0x0B, 0x1F, 0x4D] # assert "0B1F4D".hexdigest_to_bytes.hexdigest == "0B1F4D" # # Characters that are not hexadecimal digits are ignored. @@ -852,7 +850,7 @@ redef class Text var ret = new Bytes.with_capacity((dlength+1) / 2) var i = (dlength+1) % 2 # current hex digit (1=high, 0=low) - var byte = 0u8 # current accumulated byte value + var byte = 0 # current accumulated byte value pos = 0 while pos < max do @@ -864,7 +862,7 @@ redef class Text # Last digit known: store and restart ret.add byte i = 1 - byte = 0u8 + byte = 0 end end pos += 1 @@ -922,7 +920,7 @@ redef class Text else if c == 'x' or c == 'X' then var hx = substring(i + 1, 2) if hx.is_hex then - res.add(hx.to_hex.to_b) + res.add hx.to_hex else res.add_char(c) end @@ -975,23 +973,23 @@ redef class Text while pos < max do var c = b[pos] pos += 1 - if c == 0x30u8 or c == 0x31u8 then bitlen += 1 # b'0' or b'1' + if c == u'0' or c == u'1' then bitlen += 1 end # Allocate (and take care of the padding) var ret = new Bytes.with_capacity((bitlen+7) / 8) var i = (bitlen+7) % 8 # current bit (7th=128, 0th=1) - var byte = 0u8 # current accumulated byte value + var byte = 0 # current accumulated byte value pos = 0 while pos < max do var c = b[pos] pos += 1 - if c == 0x30u8 then # b'0' + if c == u'0' then byte = byte << 1 - else if c == 0x31u8 then # b'1' - byte = byte << 1 | 1u8 + else if c == u'1' then + byte = byte << 1 | 1 else continue end @@ -1001,7 +999,7 @@ redef class Text # Last bit known: store and restart ret.add byte i = 7 - byte = 0u8 + byte = 0 end end return ret @@ -1037,7 +1035,7 @@ end # Joins an array of bytes `arr` separated by `sep` # -# assert join_bytes(["String".to_bytes, "is".to_bytes, "string".to_bytes], ' '.ascii).hexdigest == "537472696E6720697320737472696E67" +# assert join_bytes(["String".to_bytes, "is".to_bytes, "string".to_bytes], u' ').hexdigest == "537472696E6720697320737472696E67" fun join_bytes(arr: Array[Bytes], sep: nullable BytePattern): Bytes do if arr.is_empty then return new Bytes.empty sep = sep or else new Bytes.empty diff --git a/lib/core/codecs/iso8859_1.nit b/lib/core/codecs/iso8859_1.nit index 005c569..be52242 100644 --- a/lib/core/codecs/iso8859_1.nit +++ b/lib/core/codecs/iso8859_1.nit @@ -35,7 +35,7 @@ private class ISO88591Codec redef fun add_char_to(c, stream) do var cp = if c.code_point <= 255 then c else '?' - stream[0] = cp.ascii + stream[0] = cp.code_point return 1 end @@ -50,9 +50,9 @@ private class ISO88591Codec for i in s.chars do var cp = i.code_point if cp <= 255 then - b[pos] = cp.to_b + b[pos] = cp else - b[pos] = 0x3Fu8 + b[pos] = 0x3F end pos += 1 end diff --git a/lib/core/codecs/utf8.nit b/lib/core/codecs/utf8.nit index d4d4a38..c37bd35 100644 --- a/lib/core/codecs/utf8.nit +++ b/lib/core/codecs/utf8.nit @@ -54,7 +54,7 @@ private class UTF8Codec redef fun is_valid_char(ns, len) do if len == 0 then return 2 if not ns[0].is_valid_utf8_start then return 2 - for i in [1 .. len[ do if ns[i] & 0b1100_0000u8 != 0b1000_0000u8 then return 2 + for i in [1 .. len[ do if ns[i] & 0b1100_0000 != 0b1000_0000 then return 2 if len != ns[0].u8len then return 1 return 0 end diff --git a/lib/core/file.nit b/lib/core/file.nit index 26f7398..fa50549 100644 --- a/lib/core/file.nit +++ b/lib/core/file.nit @@ -1362,7 +1362,7 @@ redef class FlatString var p = last_byte var c = its[p] var st = _first_byte - while p >= st and c != '.'.ascii do + while p >= st and c != u'.' do p -= 1 c = its[p] end @@ -1379,7 +1379,7 @@ redef class FlatString var l = s.last_byte var its = s._items var min = s._first_byte - var sl = '/'.ascii + var sl = u'/' while l > min and its[l] == sl do l -= 1 if l == min then return "/" var ns = l @@ -1523,7 +1523,7 @@ private extern class NativeFile `{ FILE* `} return (long)res; `} - fun write_byte(value: Byte): Int `{ + fun write_byte(value: Int): Int `{ unsigned char b = (unsigned char)value; return fwrite(&b, 1, 1, self); `} diff --git a/lib/core/kernel.nit b/lib/core/kernel.nit index 72b6fc9..1160e72 100644 --- a/lib/core/kernel.nit +++ b/lib/core/kernel.nit @@ -651,11 +651,6 @@ universal Byte # assert 5u8 >> 1 == 2u8 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 redef fun to_b do return self @@ -812,6 +807,11 @@ universal Int # assert 0x220B.code_point == '∋' fun code_point: Char is intern `{ return (uint32_t)self; `} + # Returns the character equivalent of `self` + # + # REQUIRE: `self <= 127` + fun ascii: Char do return code_point + # Number of digits of an integer in base `b` (plus one if negative) # # assert 123.digit_count(10) == 3 @@ -882,6 +882,9 @@ universal Int # assert 10.abs == 10 # assert 0.abs == 0 fun abs: Int do return if self >= 0 then self else -self + + # Is `self` an ASCII whitespace ? + fun is_whitespace: Bool do return self == 0x7F or self <= 0x20 end # Native characters. @@ -963,11 +966,11 @@ universal Char # The ascii value of `self` # - # assert 'a'.ascii == 97u8 - # assert '\n'.ascii == 10u8 + # assert 'a'.ascii == 97 + # assert '\n'.ascii == 10 # # REQUIRE: `is_ascii` - fun ascii: Byte do return code_point.to_b + fun ascii: Int do return code_point # The unicode code point value of `self` # diff --git a/lib/core/stream.nit b/lib/core/stream.nit index 6d0278a..152c294 100644 --- a/lib/core/stream.nit +++ b/lib/core/stream.nit @@ -122,7 +122,7 @@ abstract class Reader for i in [0 .. max[ do var b = raw_read_byte if b < 0 then break - buf[i] = b.to_b + buf[i] = b rd += 1 end return rd @@ -551,7 +551,7 @@ abstract class Writer fun write(s: Text) is abstract # Write a single byte - fun write_byte(value: Byte) is abstract + fun write_byte(value: Int) is abstract # Write a single char fun write_char(c: Char) do @@ -627,7 +627,7 @@ end # # writer.write "Strings " # writer.write_char '&' -# writer.write_byte 0x20u8 +# writer.write_byte 0x20 # writer.write_bytes "bytes".to_bytes # # assert writer.to_s == "\\x53\\x74\\x72\\x69\\x6E\\x67\\x73\\x20\\x26\\x20\\x62\\x79\\x74\\x65\\x73" @@ -641,12 +641,12 @@ end # writer = new BytesWriter # # # Write just the character first half -# writer.write_byte 0xC2u8 +# writer.write_byte 0xC2 # assert writer.to_s == "\\xC2" # assert writer.bytes.to_s == "�" # # # Complete the character -# writer.write_byte 0xA2u8 +# writer.write_byte 0xA2 # assert writer.to_s == "\\xC2\\xA2" # assert writer.bytes.to_s == "¢" # ~~~ @@ -698,7 +698,7 @@ end # # writer.write "Strings " # writer.write_char '&' -# writer.write_byte 0x20u8 +# writer.write_byte 0x20 # writer.write_bytes "bytes".to_bytes # # assert writer.to_s == "Strings & bytes" diff --git a/lib/core/text/abstract_text.nit b/lib/core/text/abstract_text.nit index 38f3e49..0b2c1ce 100644 --- a/lib/core/text/abstract_text.nit +++ b/lib/core/text/abstract_text.nit @@ -42,9 +42,9 @@ abstract class Text # Gets a view on the bytes of the Text object # # ~~~ - # assert "hello".bytes.to_a == [104u8, 101u8, 108u8, 108u8, 111u8] + # assert "hello".bytes.to_a == [104, 101, 108, 108, 111] # ~~~ - fun bytes: SequenceRead[Byte] is abstract + fun bytes: SequenceRead[Int] is abstract # Number of characters contained in self. # @@ -957,21 +957,21 @@ abstract class Text if c == '%' then if i + 2 >= length then # What follows % has been cut off - buf[l] = '%'.ascii + buf[l] = u'%' else i += 1 var hex_s = substring(i, 2) if hex_s.is_hex then var hex_i = hex_s.to_hex - buf[l] = hex_i.to_b + buf[l] = hex_i i += 1 else # What follows a % is not Hex - buf[l] = '%'.ascii + buf[l] = u'%' i -= 1 end end - else buf[l] = c.ascii + else buf[l] = c.code_point i += 1 l += 1 @@ -1462,7 +1462,7 @@ end # Abstract class for the SequenceRead compatible # views on the bytes of any Text private abstract class StringByteView - super SequenceRead[Byte] + super SequenceRead[Int] type SELFTYPE: Text @@ -1946,7 +1946,7 @@ redef class Byte redef fun to_s do var nslen = byte_to_s_len var ns = new CString(nslen + 1) - ns[nslen] = 0u8 + ns[nslen] = 0 native_byte_to_s(ns, nslen + 1) return ns.to_s_unsafe(nslen, copy=false, clean=false) end @@ -2094,10 +2094,10 @@ redef class Char # Returns a sequence with the UTF-8 bytes of `self` # # ~~~ - # assert 'a'.bytes == [0x61u8] - # assert 'ま'.bytes == [0xE3u8, 0x81u8, 0xBEu8] + # assert 'a'.bytes == [0x61] + # assert 'ま'.bytes == [0xE3, 0x81, 0xBE] # ~~~ - fun bytes: SequenceRead[Byte] do return to_s.bytes + fun bytes: SequenceRead[Int] do return to_s.bytes # Is `self` an UTF-16 surrogate pair ? fun is_surrogate: Bool do diff --git a/lib/core/text/fixed_ints_text.nit b/lib/core/text/fixed_ints_text.nit index 88a21a4..c738f91 100644 --- a/lib/core/text/fixed_ints_text.nit +++ b/lib/core/text/fixed_ints_text.nit @@ -40,7 +40,7 @@ redef class Int8 redef fun to_s do var nslen = to_s_len var ns = new CString(nslen + 1) - ns[nslen] = 0u8 + ns[nslen] = 0 native_to_s(ns, nslen + 1) return ns.to_s_unsafe(nslen, copy=false) end @@ -63,7 +63,7 @@ redef class Int16 redef fun to_s do var nslen = to_s_len var ns = new CString(nslen + 1) - ns[nslen] = 0u8 + ns[nslen] = 0 native_to_s(ns, nslen + 1) return ns.to_s_unsafe(nslen, copy=false) end @@ -87,7 +87,7 @@ redef class UInt16 redef fun to_s do var nslen = to_s_len var ns = new CString(nslen + 1) - ns[nslen] = 0u8 + ns[nslen] = 0 native_to_s(ns, nslen + 1) return ns.to_s_unsafe(nslen, copy=false) end @@ -111,7 +111,7 @@ redef class Int32 redef fun to_s do var nslen = to_s_len var ns = new CString(nslen + 1) - ns[nslen] = 0u8 + ns[nslen] = 0 native_to_s(ns, nslen + 1) return ns.to_s_unsafe(nslen, copy=false) end @@ -135,7 +135,7 @@ redef class UInt32 redef fun to_s do var nslen = to_s_len var ns = new CString(nslen + 1) - ns[nslen] = 0u8 + ns[nslen] = 0 native_to_s(ns, nslen + 1) return ns.to_s_unsafe(nslen, copy=false) end diff --git a/lib/core/text/flat.nit b/lib/core/text/flat.nit index b728e42..cc60978 100644 --- a/lib/core/text/flat.nit +++ b/lib/core/text/flat.nit @@ -55,7 +55,7 @@ redef class FlatText var its = _items if dpos == 1 then - if its[b] & 0x80u8 == 0x00u8 then + if its[b] & 0x80 == 0x00 then b += 1 else b += its.length_of_char_at(b) @@ -113,17 +113,17 @@ redef class FlatText var endlen = 0 while pos <= max do var c = its[pos] - if c == b'<' then + if c == u'<' then endlen += 3 - else if c == b'>' then + else if c == u'>' then endlen += 3 - else if c == b'&' then + else if c == u'&' then endlen += 4 - else if c == b'"' then + else if c == u'"' then endlen += 4 - else if c == b'\'' then + else if c == u'\'' then endlen += 4 - else if c == 0x2Fu8 then + else if c == 0x2F then endlen += 4 end pos += 1 @@ -146,45 +146,45 @@ redef class FlatText # Special codes: # Some HTML characters are used as meta-data, they need # to be replaced by an HTML-Escaped equivalent - if c == b'<' then - nits[outpos] = b'&' - nits[outpos + 1] = b'l' - nits[outpos + 2] = b't' - nits[outpos + 3] = b';' + if c == u'<' then + nits[outpos] = u'&' + nits[outpos + 1] = u'l' + nits[outpos + 2] = u't' + nits[outpos + 3] = u';' outpos += 4 - else if c == b'>' then - nits[outpos] = b'&' - nits[outpos + 1] = b'g' - nits[outpos + 2] = b't' - nits[outpos + 3] = b';' + else if c == u'>' then + nits[outpos] = u'&' + nits[outpos + 1] = u'g' + nits[outpos + 2] = u't' + nits[outpos + 3] = u';' outpos += 4 - else if c == b'&' then - nits[outpos] = b'&' - nits[outpos + 1] = b'a' - nits[outpos + 2] = b'm' - nits[outpos + 3] = b'p' - nits[outpos + 4] = b';' + else if c == u'&' then + nits[outpos] = u'&' + nits[outpos + 1] = u'a' + nits[outpos + 2] = u'm' + nits[outpos + 3] = u'p' + nits[outpos + 4] = u';' outpos += 5 - else if c == b'"' then - nits[outpos] = b'&' - nits[outpos + 1] = b'#' - nits[outpos + 2] = b'3' - nits[outpos + 3] = b'4' - nits[outpos + 4] = b';' + else if c == u'"' then + nits[outpos] = u'&' + nits[outpos + 1] = u'#' + nits[outpos + 2] = u'3' + nits[outpos + 3] = u'4' + nits[outpos + 4] = u';' outpos += 5 - else if c == b'\'' then - nits[outpos] = b'&' - nits[outpos + 1] = b'#' - nits[outpos + 2] = b'3' - nits[outpos + 3] = b'9' - nits[outpos + 4] = b';' + else if c == u'\'' then + nits[outpos] = u'&' + nits[outpos + 1] = u'#' + nits[outpos + 2] = u'3' + nits[outpos + 3] = u'9' + nits[outpos + 4] = u';' outpos += 5 - else if c == 0x2Fu8 then - nits[outpos] = b'&' - nits[outpos + 1] = b'#' - nits[outpos + 2] = b'4' - nits[outpos + 3] = b'7' - nits[outpos + 4] = b';' + else if c == u'/' then + nits[outpos] = u'&' + nits[outpos + 1] = u'#' + nits[outpos + 2] = u'4' + nits[outpos + 3] = u'7' + nits[outpos + 4] = u';' outpos += 5 else nits[outpos] = c @@ -208,33 +208,33 @@ redef class FlatText var req_esc = 0 while pos <= max do var c = its[pos] - if c == b'\n' then + if c == u'\n' then req_esc += 1 - else if c == b'\t' then + else if c == u'\t' then req_esc += 1 - else if c == b'"' then + else if c == u'"' then req_esc += 1 - else if c == b'\'' then + else if c == u'\'' then req_esc += 1 - else if c == b'\\' then + else if c == u'\\' then req_esc += 1 - else if c == 0x3Fu8 then + else if c == u'?' then var j = pos + 1 if j < length then var next = its[j] # We ignore `??'` because it will be escaped as `??\'`. if - next == 0x21u8 or - next == 0x28u8 or - next == 0x29u8 or - next == 0x2Du8 or - next == 0x2Fu8 or - next == 0x3Cu8 or - next == 0x3Du8 or - next == 0x3Eu8 + next == 0x21 or + next == 0x28 or + next == 0x29 or + next == 0x2D or + next == 0x2F or + next == 0x3C or + next == 0x3D or + next == 0x3E then req_esc += 1 end - else if c < 32u8 then + else if c < 32 then req_esc += 3 end pos += 1 @@ -269,52 +269,52 @@ redef class FlatText # * 0x22 => \" # * 0x27 => \' # * 0x5C => \\ - if c == b'\t' then - nns[opos] = b'\\' - nns[opos + 1] = b't' + if c == u'\t' then + nns[opos] = u'\\' + nns[opos + 1] = u't' opos += 2 - else if c == b'\n' then - nns[opos] = b'\\' - nns[opos + 1] = b'n' + else if c == u'\n' then + nns[opos] = u'\\' + nns[opos + 1] = u'n' opos += 2 - else if c == b'"' then - nns[opos] = b'\\' - nns[opos + 1] = b'"' + else if c == u'"' then + nns[opos] = u'\\' + nns[opos + 1] = u'"' opos += 2 - else if c == b'\'' then - nns[opos] = b'\\' - nns[opos + 1] = b'\'' + else if c == u'\'' then + nns[opos] = u'\\' + nns[opos + 1] = u'\'' opos += 2 - else if c == b'\\' then - nns[opos] = b'\\' - nns[opos + 1] = b'\\' + else if c == u'\\' then + nns[opos] = u'\\' + nns[opos + 1] = u'\\' opos += 2 - else if c == 0x3Fu8 then + else if c == u'?' then var j = pos + 1 if j < length then var next = its[j] # We ignore `??'` because it will be escaped as `??\'`. if - next == 0x21u8 or - next == 0x28u8 or - next == 0x29u8 or - next == 0x2Du8 or - next == 0x2Fu8 or - next == 0x3Cu8 or - next == 0x3Du8 or - next == 0x3Eu8 + next == 0x21 or + next == 0x28 or + next == 0x29 or + next == 0x2D or + next == 0x2F or + next == 0x3C or + next == 0x3D or + next == 0x3E then - nns[opos] = 0x5Cu8 + nns[opos] = 0x5C opos += 1 end end - nns[opos] = 0x3Fu8 + nns[opos] = 0x3F opos += 1 - else if c < 32u8 then - nns[opos] = b'\\' - nns[opos + 1] = b'0' - nns[opos + 2] = ((c & 0x38u8) >> 3) + b'0' - nns[opos + 3] = (c & 0x07u8) + b'0' + else if c < 32 then + nns[opos] = u'\\' + nns[opos + 1] = u'0' + nns[opos + 2] = ((c & 0x38) >> 3) + u'0' + nns[opos + 3] = (c & 0x07) + u'0' opos += 4 else nns[opos] = c @@ -339,7 +339,7 @@ redef class FlatText if dpos == 1 and index < len - 1 then var its = _items var c = its[b] - if c & 0x80u8 == 0x00u8 then + if c & 0x80 == 0x00 then # We want the next, and current is easy. # So next is easy to find! b += 1 @@ -351,20 +351,20 @@ redef class FlatText else if dpos == -1 and index > 1 then var its = _items var c = its[b-1] - if c & 0x80u8 == 0x00u8 then + if c & 0x80 == 0x00 then # We want the previous, and it is easy. b -= 1 dpos = 0 _position = index _bytepos = b - return c.ascii + return c.code_point end end if dpos == 0 then # We know what we want (+0 or +1) just get it now! var its = _items var c = its[b] - if c & 0x80u8 == 0x00u8 then return c.ascii + if c & 0x80 == 0x00 then return c.code_point return items.char_at(b) end @@ -379,7 +379,7 @@ redef class FlatText var i = char_to_byte_index(index) var items = _items var b = items[i] - if b & 0x80u8 == 0x00u8 then return b.ascii + if b & 0x80 == 0x00 then return b.code_point return items.char_at(i) end @@ -395,7 +395,7 @@ redef class FlatText var max = pos + ln for i in [pos .. max[ do res <<= 4 - res += its[i].ascii.from_hex + res += its[i].code_point.from_hex end return res end @@ -421,7 +421,7 @@ abstract class FlatString var blen = _byte_length var new_items = new CString(blen + 1) _items.copy_to(new_items, blen, _first_byte, 0) - new_items[blen] = 0u8 + new_items[blen] = 0 return new_items end @@ -624,7 +624,7 @@ abstract class FlatString var its = _items var fb = _first_byte var ns = new CString(new_byte_length + 1) - ns[new_byte_length] = 0u8 + ns[new_byte_length] = 0 var offset = 0 while i > 0 do its.copy_to(ns, mybtlen, fb, offset) @@ -696,7 +696,7 @@ private class ASCIIFlatString redef fun [](idx) do assert idx < _byte_length and idx >= 0 - return _items[idx + _first_byte].ascii + return _items[idx + _first_byte].code_point end redef fun substring(from, count) do @@ -729,7 +729,7 @@ private class ASCIIFlatString return new ASCIIFlatString.full_data(_items, count, from + _first_byte, count) end - redef fun fetch_char_at(i) do return _items[i + _first_byte].ascii + redef fun fetch_char_at(i) do return _items[i + _first_byte].code_point end private class FlatStringCharReverseIterator @@ -784,7 +784,7 @@ private class FlatStringCharView end private class FlatStringByteReverseIterator - super IndexedIterator[Byte] + super IndexedIterator[Int] var target: FlatString @@ -810,7 +810,7 @@ private class FlatStringByteReverseIterator end private class FlatStringByteIterator - super IndexedIterator[Byte] + super IndexedIterator[Int] var target: FlatString @@ -1019,7 +1019,7 @@ class FlatBuffer do var bln = _byte_length var new_native = new CString(bln + 1) - new_native[bln] = 0u8 + new_native[bln] = 0 if _length > 0 then _items.copy_to(new_native, bln, 0, 0) return new_native end @@ -1163,7 +1163,7 @@ class FlatBuffer end private class FlatBufferByteReverseIterator - super IndexedIterator[Byte] + super IndexedIterator[Int] var target: FlatBuffer @@ -1197,7 +1197,7 @@ private class FlatBufferByteView end private class FlatBufferByteIterator - super IndexedIterator[Byte] + super IndexedIterator[Int] var target: FlatBuffer @@ -1331,7 +1331,7 @@ redef class CString if copy and (str == null or str.items == self) then var new_cstr = new CString(byte_length + 1) copy_to(new_cstr, byte_length, 0, 0) - new_cstr[byte_length] = 0u8 + new_cstr[byte_length] = 0 str = new FlatString.full(new_cstr, byte_length, 0, char_length) end @@ -1359,7 +1359,7 @@ redef class CString end if rem == 0 then break var b = self[pos] - if b & 0x80u8 == 0x00u8 then + if b & 0x80 == 0x00 then pos += 1 chr_ln += 1 rem -= 1 @@ -1368,13 +1368,13 @@ redef class CString var nxst = length_of_char_at(pos) var ok_st: Bool if nxst == 1 then - ok_st = b & 0x80u8 == 0u8 + ok_st = b & 0x80 == 0 else if nxst == 2 then - ok_st = b & 0xE0u8 == 0xC0u8 + ok_st = b & 0xE0 == 0xC0 else if nxst == 3 then - ok_st = b & 0xF0u8 == 0xE0u8 + ok_st = b & 0xF0 == 0xE0 else - ok_st = b & 0xF8u8 == 0xF0u8 + ok_st = b & 0xF8 == 0xF0 end if not ok_st then if replacements == null then replacements = new Array[Int] @@ -1425,9 +1425,9 @@ redef class CString var chkln = repl_pos - old_repl copy_to(ret, chkln, old_repl, off) off += chkln - ret[off] = 0xEFu8 - ret[off + 1] = 0xBFu8 - ret[off + 2] = 0xBDu8 + ret[off] = 0xEF + ret[off + 1] = 0xBF + ret[off + 2] = 0xBD old_repl = repl_pos + 1 off += 3 end @@ -1442,22 +1442,22 @@ redef class CString private fun set_char_at(pos: Int, c: Char) do var cp = c.code_point if cp < 128 then - self[pos] = cp.to_b + self[pos] = cp return end var ln = c.u8char_len if ln == 2 then - self[pos] = (0xC0 | ((cp & 0x7C0) >> 6)).to_b - self[pos + 1] = (0x80 | (cp & 0x3F)).to_b + self[pos] = 0xC0 | ((cp & 0x7C0) >> 6) + self[pos + 1] = 0x80 | (cp & 0x3F) else if ln == 3 then - self[pos] = (0xE0 | ((cp & 0xF000) >> 12)).to_b - self[pos + 1] = (0x80 | ((cp & 0xFC0) >> 6)).to_b - self[pos + 2] = (0x80 | (cp & 0x3F)).to_b + self[pos] = 0xE0 | ((cp & 0xF000) >> 12) + self[pos + 1] = 0x80 | ((cp & 0xFC0) >> 6) + self[pos + 2] = 0x80 | (cp & 0x3F) else if ln == 4 then - self[pos] = (0xF0 | ((cp & 0x1C0000) >> 18)).to_b - self[pos + 1] = (0x80 | ((cp & 0x3F000) >> 12)).to_b - self[pos + 2] = (0x80 | ((cp & 0xFC0) >> 6)).to_b - self[pos + 3] = (0x80 | (cp & 0x3F)).to_b + self[pos] = 0xF0 | ((cp & 0x1C0000) >> 18) + self[pos + 1] = 0x80 | ((cp & 0x3F000) >> 12) + self[pos + 2] = 0x80 | ((cp & 0xFC0) >> 6) + self[pos + 3] = 0x80 | (cp & 0x3F) end end end @@ -1474,7 +1474,7 @@ redef class Int var nslen = int_to_s_len var ns = new CString(nslen + 1) - ns[nslen] = 0u8 + ns[nslen] = 0 native_int_to_s(ns, nslen + 1) return new FlatString.full(ns, nslen, 0, nslen) end @@ -1507,7 +1507,7 @@ redef class Array[E] mypos += 1 end var ns = new CString(sl + 1) - ns[sl] = 0u8 + ns[sl] = 0 i = 0 var off = 0 while i < mypos do @@ -1544,7 +1544,7 @@ redef class NativeArray[E] mypos += 1 end var ns = new CString(sl + 1) - ns[sl] = 0u8 + ns[sl] = 0 i = 0 var off = 0 while i < mypos do diff --git a/lib/core/text/native.nit b/lib/core/text/native.nit index 74f5f3f..372ac5a 100644 --- a/lib/core/text/native.nit +++ b/lib/core/text/native.nit @@ -35,16 +35,16 @@ in "C" `{ #include `} -redef class Byte +redef class Int # Gives the length of the UTF-8 char starting with `self` fun u8len: Int do - if self & 0b1000_0000u8 == 0u8 then + if self & 0b1000_0000 == 0 then return 1 - else if self & 0b1110_0000u8 == 0b1100_0000u8 then + else if self & 0b1110_0000 == 0b1100_0000 then return 2 - else if self & 0b1111_0000u8 == 0b1110_0000u8 then + else if self & 0b1111_0000 == 0b1110_0000 then return 3 - else if self & 0b1111_1000u8 == 0b1111_0000u8 then + else if self & 0b1111_1000 == 0b1111_0000 then return 4 else return 1 @@ -54,16 +54,16 @@ redef class Byte # Is `self` a valid UTF-8 sequence start ? # # ~~~nit - # assert 0u8.is_valid_utf8_start - # assert 0xC0u8.is_valid_utf8_start - # assert 0xE0u8.is_valid_utf8_start - # assert 0xF0u8.is_valid_utf8_start + # assert 0.is_valid_utf8_start + # assert 0xC0.is_valid_utf8_start + # assert 0xE0.is_valid_utf8_start + # assert 0xF0.is_valid_utf8_start # ~~~ fun is_valid_utf8_start: Bool do - if self & 0x80u8 == 0u8 then return true - if self & 0b1110_0000u8 == 0b1100_0000u8 then return true - if self & 0b1111_0000u8 == 0b1110_0000u8 then return true - if self & 0b1111_1000u8 == 0b1111_0000u8 then return true + if self & 0x80 == 0 then return true + if self & 0b1110_0000 == 0b1100_0000 then return true + if self & 0b1111_0000 == 0b1110_0000 then return true + if self & 0b1111_1000 == 0b1111_0000 then return true return false end end @@ -104,10 +104,10 @@ extern class CString `{ char* `} fun fast_cstring(index: Int): CString is intern # Get char at `index`. - fun [](index: Int): Byte is intern + fun [](index: Int): Int is intern # Set char `item` at index. - fun []=(index: Int, item: Byte) is intern + fun []=(index: Int, item: Int) is intern # Copy `self` to `dest`. fun copy_to(dest: CString, length: Int, from: Int, to: Int) is intern @@ -120,7 +120,7 @@ extern class CString `{ char* `} fun cstring_length: Int do var l = 0 - while self[l] != 0u8 do l += 1 + while self[l] != 0 do l += 1 return l end @@ -146,7 +146,7 @@ extern class CString `{ char* `} # ~~~ fun char_at(pos: Int): Char do var c = self[pos] - if c & 0x80u8 == 0u8 then return c.ascii + if c & 0x80 == 0 then return c.code_point var b = fetch_4_hchars(pos) var ret = 0u32 if b & 0xC00000u32 != 0x800000u32 then return 0xFFFD.code_point @@ -179,13 +179,13 @@ extern class CString `{ char* `} # Gets the length of the character at position `pos` (1 if invalid sequence) fun length_of_char_at(pos: Int): Int do var c = self[pos] - if c & 0x80u8 == 0x00u8 then + if c & 0x80 == 0x00 then return 1 - else if c & 0xE0u8 == 0xC0u8 and self[pos + 1] & 0xC0u8 == 0x80u8 then + else if c & 0xE0 == 0xC0 and self[pos + 1] & 0xC0 == 0x80 then return 2 - else if c & 0xF0u8 == 0xE0u8 and self[pos + 1] & 0xC0u8 == 0x80u8 and self[pos + 2] & 0xC0u8 == 0x80u8 then + else if c & 0xF0 == 0xE0 and self[pos + 1] & 0xC0 == 0x80 and self[pos + 2] & 0xC0 == 0x80 then return 3 - else if c & 0xF8u8 == 0xF0u8 and self[pos + 1] & 0xC0u8 == 0x80u8 and self[pos + 2] & 0xC0u8 == 0x80u8 and self[pos + 3] & 0xC0u8 == 0x80u8 then + else if c & 0xF8 == 0xF0 and self[pos + 1] & 0xC0 == 0x80 and self[pos + 2] & 0xC0 == 0x80 and self[pos + 3] & 0xC0 == 0x80 then return 4 else return 1 @@ -265,13 +265,13 @@ extern class CString `{ char* `} # ~~~raw # assert "abc".items.find_beginning_of_char_at(2) == 2 # assert "か".items.find_beginning_of_char_at(1) == 0 - # assert [0x41u8, 233u8].to_s.items.find_beginning_of_char_at(1) == 1 + # assert [0x41, 233].to_s.items.find_beginning_of_char_at(1) == 1 # ~~~ fun find_beginning_of_char_at(pos: Int): Int do var endpos = pos var c = self[pos] - if c & 0x80u8 == 0x00u8 then return pos - while c & 0xC0u8 == 0x80u8 do + if c & 0x80 == 0x00 then return pos + while c & 0xC0 == 0x80 do pos -= 1 c = self[pos] end diff --git a/lib/core/text/ropes.nit b/lib/core/text/ropes.nit index ca846fd..ef0016c 100644 --- a/lib/core/text/ropes.nit +++ b/lib/core/text/ropes.nit @@ -91,7 +91,7 @@ private class Concat redef fun to_cstring do var len = _byte_length var ns = new CString(len + 1) - ns[len] = 0u8 + ns[len] = 0 var off = 0 for i in substrings do var ilen = i._byte_length @@ -331,7 +331,7 @@ end # A reverse iterator capable of working with `Rope` objects private class RopeByteReverseIterator - super IndexedIterator[Byte] + super IndexedIterator[Int] # Current CString var ns: CString is noautoinit @@ -372,7 +372,7 @@ end # Forward iterator on the bytes of a `Rope` private class RopeByteIterator - super IndexedIterator[Byte] + super IndexedIterator[Int] # Position in current `String` var pns: Int is noautoinit diff --git a/lib/crapto/xor.nit b/lib/crapto/xor.nit index 8745c1a..6402969 100644 --- a/lib/crapto/xor.nit +++ b/lib/crapto/xor.nit @@ -26,20 +26,20 @@ redef class SingleByteXorCipher # Accumulate best result var max = 0.0 - var best = 0.to_b + var best = 0 # Iterate on possible values for a byte var xor_b = new Bytes.with_capacity(1) for b in [0 .. 255] do # Need `Bytes` to pass to xor - xor_b[0] = b.to_b + xor_b[0] = b # Xor and evaluate result var xored = ciphertext.xorcipher(xor_b) var result = xored.to_s.english_scoring if result > max then max = result - best = b.to_b + best = b end end diff --git a/lib/crypto/basic_ciphers.nit b/lib/crypto/basic_ciphers.nit index 9796bf8..7181928 100644 --- a/lib/crypto/basic_ciphers.nit +++ b/lib/crypto/basic_ciphers.nit @@ -212,12 +212,12 @@ redef class Bytes # assert "this is a test".to_bytes.hamming_distance("wokka wokka!!!".bytes) == 37 # assert "this is a test".to_bytes.hamming_distance("this is a test".bytes) == 0 # - fun hamming_distance(other: SequenceRead[Byte]): Int do + fun hamming_distance(other: SequenceRead[Int]): Int do var diff = 0 for idx in self.length.times do var res_byte = self[idx] ^ other[idx] for bit in [0..8[ do - if res_byte & 1u8 == 1u8 then diff += 1 + if res_byte & 1 == 1 then diff += 1 res_byte = res_byte >> 1 end end diff --git a/lib/crypto/xor_ciphers.nit b/lib/crypto/xor_ciphers.nit index 18de9fb..aaa18d1 100644 --- a/lib/crypto/xor_ciphers.nit +++ b/lib/crypto/xor_ciphers.nit @@ -69,7 +69,7 @@ class SingleByteXorCipher super Cipher # Cryptographic key used in encryption and decryption. - var key: Byte = 0.to_b + var key: Int = 0 redef fun encrypt do var key_bytes = new Bytes.with_capacity(1) diff --git a/lib/gamnit/textures.nit b/lib/gamnit/textures.nit index 4383c2b..4987be2 100644 --- a/lib/gamnit/textures.nit +++ b/lib/gamnit/textures.nit @@ -161,10 +161,10 @@ class CustomTexture # Simple conversion from [0.0..1.0] to [0..255] var bytes = [for c in color do (c*255.0).round.to_i.clamp(0, 255).to_bytes.last] - while bytes.length < 4 do bytes.add 255u8 + while bytes.length < 4 do bytes.add 255 var offset = 4*(x + y*width.to_i) - for i in [0..4[ do cpixels[offset+i] = bytes[i] + for i in [0..4[ do cpixels[offset+i] = bytes[i].to_b loaded = false end @@ -177,12 +177,12 @@ class CustomTexture do # Simple conversion from [0.0..1.0] to [0..255] var bytes = [for c in color do (c*255.0).round.to_i.clamp(0, 255).to_bytes.last] - while bytes.length < 4 do bytes.add 255u8 + while bytes.length < 4 do bytes.add 255 var i = 0 for x in [0..width.to_i[ do for y in [0..height.to_i[ do - for j in [0..4[ do cpixels[i+j] = bytes[j] + for j in [0..4[ do cpixels[i+j] = bytes[j].to_b i += 4 end end diff --git a/lib/json/static.nit b/lib/json/static.nit index 0d25f10..2d42e16 100644 --- a/lib/json/static.nit +++ b/lib/json/static.nit @@ -128,7 +128,7 @@ redef class FlatText redef fun json_need_escape do var its = items for i in [first_byte .. last_byte] do - if its[i] == 0x5Cu8 then return true + if its[i] == 0x5C then return true end return false end diff --git a/lib/libevent/libevent.nit b/lib/libevent/libevent.nit index efd434f..ff10b05 100644 --- a/lib/libevent/libevent.nit +++ b/lib/libevent/libevent.nit @@ -366,7 +366,7 @@ extern class NativeBufferEvent `{ struct bufferevent * `} `} # Write the byte `value` - fun write_byte(value: Byte): Int `{ + fun write_byte(value: Int): Int `{ unsigned char byt = (unsigned char)value; return bufferevent_write(self, &byt, 1); `} diff --git a/lib/msgpack/ext.nit b/lib/msgpack/ext.nit index 327dbff..909b423 100644 --- a/lib/msgpack/ext.nit +++ b/lib/msgpack/ext.nit @@ -22,12 +22,12 @@ class MsgPackExt serialize # Custom type code, in [0..127] - var typ: Byte + var typ: Int # Data bytes var data: Bytes redef fun hash do return typ.hash + data.hash*8 redef fun ==(o) do return o isa MsgPackExt and o.typ == typ and o.data == data - redef fun to_s do return "<{class_name} typ: {typ}, data: {data.chexdigest}>" + redef fun to_s do return "<{class_name} typ: {typ.to_b}, data: {data.chexdigest}>" end diff --git a/lib/msgpack/msgpack.nit b/lib/msgpack/msgpack.nit index 929c330..84f5f79 100644 --- a/lib/msgpack/msgpack.nit +++ b/lib/msgpack/msgpack.nit @@ -107,7 +107,7 @@ # # ~~~ # assert 0x01u8.serialize_msgpack == b"\xD4\x7E\x01" -# assert b"\xD4\x7E\x01".deserialize_msgpack == 0x01u8 +# assert b"\xD4\x7E\x01".deserialize_msgpack == 1 # ~~~ # # ## Full objects diff --git a/lib/msgpack/read.nit b/lib/msgpack/read.nit index 3b8854a..be68898 100644 --- a/lib/msgpack/read.nit +++ b/lib/msgpack/read.nit @@ -45,7 +45,7 @@ redef class Reader else if typ & 0b1000_0000 == 0 or typ & 0b1110_0000 == 0b1110_0000 then # fixint var bytes = new Bytes.with_capacity(1) - bytes.add typ.to_b + bytes.add typ return bytes.to_i(signed=true) else if typ & 0b1111_0000 == 0b1000_0000 then @@ -174,7 +174,7 @@ redef class Reader # var reader = new BytesReader(b"\xC7\x03\x0A\x0B\x0C\x0D") # var ext = reader.read_msgpack # assert ext isa MsgPackExt - # assert ext.typ == 0x0Au8 + # assert ext.typ == 0x0a # assert ext.data == b"\x0B\x0C\x0D" # ~~~ private fun read_msgpack_fixext_data(len: Int): MsgPackExt @@ -182,7 +182,7 @@ redef class Reader var exttyp = read_byte if exttyp < 0 then exttyp = 0 var data = read_bytes(len) - return new MsgPackExt(exttyp.to_b, data) + return new MsgPackExt(exttyp, data) end # Read the content of a dynamic *ext* including the length on `len_len` bytes diff --git a/lib/msgpack/serialization_common.nit b/lib/msgpack/serialization_common.nit index a9e9ddf..edf9210 100644 --- a/lib/msgpack/serialization_common.nit +++ b/lib/msgpack/serialization_common.nit @@ -19,14 +19,14 @@ module serialization_common abstract class MsgPackEngine # *ext type* byte for object definitions, defaults to 0x7Bu8 or '{' - var ext_typ_obj: Byte = 0x7Bu8 is writable + var ext_typ_obj: Int = 0x7B is writable # *ext type* byte for object references, defaults to 0x7Du8 or '}' - var ext_typ_ref: Byte = 0x7Du8 is writable + var ext_typ_ref: Int = 0x7D is writable # *ext type* byte to identify a char, defaults to 0x7Cu8 or '~' - var ext_typ_char: Byte = 0x7Cu8 is writable + var ext_typ_char: Int = 0x7C is writable # *ext type* byte to identify a byte, defaults to 0x7Eu8 or '|' - var ext_typ_byte: Byte = 0x7Eu8 is writable + var ext_typ_byte: Int = 0x7E is writable end diff --git a/lib/msgpack/serialization_write.nit b/lib/msgpack/serialization_write.nit index 0b5b4f9..e1bb2d0 100644 --- a/lib/msgpack/serialization_write.nit +++ b/lib/msgpack/serialization_write.nit @@ -266,7 +266,7 @@ redef class Byte else # Write as ext var bytes = new Bytes.with_capacity(1) - bytes.add self + bytes.add self.to_i v.stream.write_msgpack_ext(v.ext_typ_byte, bytes) end end diff --git a/lib/msgpack/write.nit b/lib/msgpack/write.nit index 15e5985..7d18e32 100644 --- a/lib/msgpack/write.nit +++ b/lib/msgpack/write.nit @@ -20,11 +20,11 @@ import binary redef class Writer # Write `null`, or nil, in MessagePack format - fun write_msgpack_null do write_byte 0xC0u8 + fun write_msgpack_null do write_byte 0xC0 # Write `bool` in MessagePack format fun write_msgpack_bool(bool: Bool) - do write_byte(if bool then 0xC3u8 else 0xC2u8) + do write_byte(if bool then 0xC3 else 0xC2) # --- # Integers @@ -61,7 +61,7 @@ redef class Writer fun write_msgpack_fixint(value: Int) do assert value >= -0x20 and value <= 0x7F - write_byte value.to_b + write_byte value end # Write `value` over one unsigned byte, following 1 metadata byte @@ -69,7 +69,7 @@ redef class Writer # Require: `value >= 0x00 and value <= 0xFF` fun write_msgpack_uint8(value: Int) do - write_byte 0xCCu8 + write_byte 0xCC write_bytes value.to_bytes(n_bytes=1) end @@ -78,7 +78,7 @@ redef class Writer # Require: `value >= 0x00 and value <= 0xFFFF` fun write_msgpack_uint16(value: Int) do - write_byte 0xCDu8 + write_byte 0xCD write_bytes value.to_bytes(n_bytes=2) end @@ -87,7 +87,7 @@ redef class Writer # Require: `value >= 0x00 and value <= 0xFFFF_FFFF` fun write_msgpack_uint32(value: Int) do - write_byte 0xCEu8 + write_byte 0xCE write_bytes value.to_bytes(n_bytes=4) end @@ -96,7 +96,7 @@ redef class Writer # Require: `value >= 0x00 and value <= 0xFFFF_FFFF_FFFF_FFFF` fun write_msgpack_uint64(value: Int) do - write_byte 0xCFu8 + write_byte 0xCF write_bytes value.to_bytes(n_bytes=8) end @@ -105,28 +105,28 @@ redef class Writer # Require: `value >= -128 and value <= 127` fun write_msgpack_int8(value: Int) do - write_byte 0xD0u8 + write_byte 0xD0 write_bytes value.to_bytes(n_bytes=1) end # Write `value` over two signed bytes, following 1 metadata byte fun write_msgpack_int16(value: Int) do - write_byte 0xD1u8 + write_byte 0xD1 write_bytes value.to_bytes(n_bytes=2) end # Write `value` over 4 signed bytes, following 1 metadata byte fun write_msgpack_int32(value: Int) do - write_byte 0xD2u8 + write_byte 0xD2 write_bytes value.to_bytes(n_bytes=4) end # Write `value` over 8 signed bytes, following 1 metadata byte fun write_msgpack_int64(value: Int) do - write_byte 0xD3u8 + write_byte 0xD3 write_int64 value end @@ -136,14 +136,14 @@ redef class Writer # Write `value` as a MessagePack float (losing precision) fun write_msgpack_float(value: Float) do - write_byte 0xCAu8 + write_byte 0xCA write_float value end # Write `value` as a MessagePack double fun write_msgpack_double(value: Float) do - write_byte 0xCBu8 + write_byte 0xCB write_double value end @@ -177,7 +177,7 @@ redef class Writer var len = text.byte_length assert len <= 0x1F - var b = 0b1010_0000u8 | len.to_b + var b = 0b1010_0000 | len write_byte b write text @@ -191,8 +191,8 @@ redef class Writer var len = text.byte_length assert len <= 0xFF - write_byte 0xD9u8 - write_byte len.to_b + write_byte 0xD9 + write_byte len write text end @@ -204,10 +204,10 @@ redef class Writer var len = text.byte_length assert len <= 0xFFFF - write_byte 0xDAu8 + write_byte 0xDA var len_bytes = len.to_bytes write_byte len_bytes[0] - write_byte if len_bytes.length > 1 then len_bytes[1] else 0u8 + write_byte if len_bytes.length > 1 then len_bytes[1] else 0 write text end @@ -219,11 +219,11 @@ redef class Writer var len = text.byte_length assert len <= 0xFFFF_FFFF - write_byte 0xDBu8 + write_byte 0xDB var len_bytes = len.to_bytes write_byte len_bytes[0] for i in [1..4[ do - write_byte if len_bytes.length > i then len_bytes[i] else 0u8 + write_byte if len_bytes.length > i then len_bytes[i] else 0 end write text end @@ -254,8 +254,8 @@ redef class Writer var len = data.length assert len <= 0xFF - write_byte 0xC4u8 - write_byte len.to_b + write_byte 0xC4 + write_byte len write_bytes data end @@ -267,7 +267,7 @@ redef class Writer var len = data.length assert len <= 0xFFFF - write_byte 0xC5u8 + write_byte 0xC5 write_bytes len.to_bytes(n_bytes=2) write_bytes data end @@ -280,7 +280,7 @@ redef class Writer var len = data.length assert len <= 0xFFFF_FFFF - write_byte 0xC6u8 + write_byte 0xC6 write_bytes len.to_bytes(n_bytes=4) write_bytes data end @@ -314,7 +314,7 @@ redef class Writer fun write_msgpack_fixarray(len: Int) do assert len <= 0x0F - write_byte 0b1001_0000u8 | len.to_b + write_byte 0b1001_0000 | len end # Write an array header for `len` items, max of 0xFFFF items @@ -325,7 +325,7 @@ redef class Writer fun write_msgpack_array16(len: Int) do assert len <= 0xFFFF - write_byte 0xDCu8 + write_byte 0xDC write_bytes len.to_bytes(n_bytes=2) end @@ -337,7 +337,7 @@ redef class Writer fun write_msgpack_array32(len: Int) do assert len <= 0xFFFF_FFFF - write_byte 0xDDu8 + write_byte 0xDD write_bytes len.to_bytes(n_bytes=4) end @@ -372,7 +372,7 @@ redef class Writer fun write_msgpack_fixmap(len: Int) do assert len <= 0x0F - write_byte 0b1000_0000u8 | len.to_b + write_byte 0b1000_0000 | len end # Write a map header for `len` key/value pairs, max of 0xFFFF pairs @@ -384,7 +384,7 @@ redef class Writer fun write_msgpack_map16(len: Int) do assert len <= 0xFFFF - write_byte 0xDEu8 + write_byte 0xDE write_bytes len.to_bytes(n_bytes=2) end @@ -397,7 +397,7 @@ redef class Writer fun write_msgpack_map32(len: Int) do assert len <= 0xFFFF_FFFF - write_byte 0xDFu8 + write_byte 0xDF write_bytes len.to_bytes(n_bytes=4) end @@ -410,10 +410,10 @@ redef class Writer # # ~~~ # var writer = new BytesWriter - # writer.write_msgpack_ext(0x0Au8, b"\x0B\x0C\x0D") + # writer.write_msgpack_ext(0x0A, b"\x0B\x0C\x0D") # assert writer.bytes == b"\xC7\x03\x0A\x0B\x0C\x0D" # ~~~ - fun write_msgpack_ext(typ: Byte, bytes: Bytes) + fun write_msgpack_ext(typ: Int, bytes: Bytes) do var len = bytes.length if len == 1 then @@ -448,45 +448,45 @@ redef class Writer # Write the header for an application-specific extension of one data byte # # After writing the header, clients should write the data byte. - fun write_msgpack_fixext1(typ: Byte) + fun write_msgpack_fixext1(typ: Int) do - write_byte 0xD4u8 + write_byte 0xD4 write_byte typ end # Write the header for an application-specific extension of two data bytes # # After writing the header, clients should write the two data bytes. - fun write_msgpack_fixext2(typ: Byte) + fun write_msgpack_fixext2(typ: Int) do - write_byte 0xD5u8 + write_byte 0xD5 write_byte typ end # Write the header for an application-specific extension of 4 data bytes # # After writing the header, clients should write the 4 data bytes. - fun write_msgpack_fixext4(typ: Byte) + fun write_msgpack_fixext4(typ: Int) do - write_byte 0xD6u8 + write_byte 0xD6 write_byte typ end # Write the header for an application-specific extension of 8 data bytes # # After writing the header, clients should write the 8 data bytes. - fun write_msgpack_fixext8(typ: Byte) + fun write_msgpack_fixext8(typ: Int) do - write_byte 0xD7u8 + write_byte 0xD7 write_byte typ end # Write the header for an application-specific extension of 16 data bytes # # After writing the header, clients should write the 16 data bytes. - fun write_msgpack_fixext16(typ: Byte) + fun write_msgpack_fixext16(typ: Int) do - write_byte 0xD8u8 + write_byte 0xD8 write_byte typ end @@ -495,11 +495,11 @@ redef class Writer # After writing the header, clients should write the data bytes. # # Require: `len >= 0 and <= 0xFF` - fun write_msgpack_ext8(typ: Byte, len: Int) + fun write_msgpack_ext8(typ, len: Int) do assert len >= 0 and len <= 0xFF - write_byte 0xC7u8 - write_byte len.to_b + write_byte 0xC7 + write_byte len write_byte typ end @@ -508,10 +508,10 @@ redef class Writer # After writing the header, clients should write the data bytes. # # Require: `len >= 0 and <= 0xFFFF` - fun write_msgpack_ext16(typ: Byte, len: Int) + fun write_msgpack_ext16(typ, len: Int) do assert len >= 0 and len <= 0xFFFF - write_byte 0xC8u8 + write_byte 0xC8 write_bytes len.to_bytes(n_bytes=2) write_byte typ end @@ -521,10 +521,10 @@ redef class Writer # After writing the header, clients should write the data bytes. # # Require: `len >= 0 and <= 0xFFFF_FFFF` - fun write_msgpack_ext32(typ: Byte, len: Int) + fun write_msgpack_ext32(typ, len: Int) do assert len >= 0 and len <= 0xFFFF_FFFF - write_byte 0xC9u8 + write_byte 0xC9 write_bytes len.to_bytes(n_bytes=4) write_byte typ end diff --git a/lib/nitcorn/token.nit b/lib/nitcorn/token.nit index 31aefd6..7e55f69 100644 --- a/lib/nitcorn/token.nit +++ b/lib/nitcorn/token.nit @@ -58,7 +58,7 @@ do # Fallback if bytes == null or bytes.length != bin_length or force_rand == true then bytes = new Bytes.with_capacity(bin_length) - for i in bin_length.times do bytes.add 256.rand.to_b + for i in bin_length.times do bytes.add 256.rand end # Encode in base64 so it is readable diff --git a/lib/sha1/sha1.nit b/lib/sha1/sha1.nit index a80e9f2..6ad30c8 100644 --- a/lib/sha1/sha1.nit +++ b/lib/sha1/sha1.nit @@ -245,7 +245,7 @@ redef class Text # sha1_hexdigest. # # import base64 - # assert "The quick brown fox jumps over the lazy dog".sha1 == [0x2Fu8, 0xD4u8, 0xE1u8, 0xC6u8, 0x7Au8, 0x2Du8, 0x28u8, 0xFCu8, 0xEDu8, 0x84u8, 0x9Eu8, 0xE1u8, 0xBBu8, 0x76u8, 0xE7u8, 0x39u8, 0x1Bu8, 0x93u8, 0xEBu8, 0x12u8] + # assert "The quick brown fox jumps over the lazy dog".sha1 == [0x2F, 0xD4, 0xE1, 0xC6, 0x7A, 0x2D, 0x28, 0xFC, 0xED, 0x84, 0x9E, 0xE1, 0xBB, 0x76, 0xE7, 0x39, 0x1B, 0x93, 0xEB, 0x12] fun sha1: Bytes do return new Bytes(to_cstring.sha1_intern(byte_length), 20, 20) end diff --git a/lib/socket/socket_c.nit b/lib/socket/socket_c.nit index e359b77..13b4049 100644 --- a/lib/socket/socket_c.nit +++ b/lib/socket/socket_c.nit @@ -141,7 +141,7 @@ extern class NativeSocket `{ int* `} `} # Write `value` as a single byte - fun write_byte(value: Byte): Int `{ + fun write_byte(value: Int): Int `{ unsigned char byt = (unsigned char)value; return write(*self, &byt, 1); `} diff --git a/lib/websocket/websocket.nit b/lib/websocket/websocket.nit index c5ea6bb..f1a559a 100644 --- a/lib/websocket/websocket.nit +++ b/lib/websocket/websocket.nit @@ -148,14 +148,14 @@ class WebsocketConnection var ans_buffer = new Bytes.with_capacity(msg.byte_length + 2) # Flag for final frame set to 1 # opcode set to 1 (for text) - ans_buffer.add(129u8) + ans_buffer.add(129) if msg.length < 126 then - ans_buffer.add(msg.length.to_b) + ans_buffer.add(msg.length) end if msg.length >= 126 and msg.length <= 65535 then - ans_buffer.add(126u8) - ans_buffer.add((msg.length >> 8).to_b) - ans_buffer.add(msg.length.to_b) + ans_buffer.add(126) + ans_buffer.add(msg.length >> 8) + ans_buffer.add(msg.length) end msg.append_to_bytes(ans_buffer) return ans_buffer diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index b0cbd03..3fa312d 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1789,7 +1789,7 @@ abstract class AbstractCompilerVisitor var nat = new_var(mtype) var byte_esc = new Buffer.with_cap(len * 4) for i in [0 .. len[ do - byte_esc.append("\\x{ns[i].to_s.substring_from(2)}") + byte_esc.append("\\x{ns[i].to_hex}") end self.add("{nat} = \"{byte_esc}\";") return nat @@ -3809,7 +3809,7 @@ end redef class ACharExpr redef fun expr(v) do - if is_ascii then return v.byte_instance(value.as(not null).ascii) + if is_ascii then return v.int_instance(value.as(not null).ascii) if is_code_point then return v.int_instance(value.as(not null).code_point) return v.char_instance(self.value.as(not null)) end diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index f7b765b..9c7ec34 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -325,7 +325,7 @@ class NaiveInterpreter do var instance = c_string_instance_len(txt.byte_length+1) var val = instance.val - val[txt.byte_length] = 0u8 + val[txt.byte_length] = 0 txt.to_cstring.copy_to(val, txt.byte_length, 0, 0) return instance @@ -1189,10 +1189,10 @@ redef class AMethPropdef var recvval = args.first.val.as(CString) if pname == "[]" then var arg1 = args[1].to_i - return v.byte_instance(recvval[arg1]) + return v.int_instance(recvval[arg1]) else if pname == "[]=" then var arg1 = args[1].to_i - recvval[arg1] = args[2].val.as(Byte) + recvval[arg1] = args[2].val.as(Int) return null else if pname == "copy_to" then # sig= copy_to(dest: CString, length: Int, from: Int, to: Int) @@ -1991,7 +1991,7 @@ end redef class ACharExpr redef fun expr(v) do - if is_ascii then return v.byte_instance(self.value.as(not null).ascii) + if is_ascii then return v.int_instance(self.value.as(not null).ascii) if is_code_point then return v.int_instance(self.value.as(not null).code_point) return v.char_instance(self.value.as(not null)) end diff --git a/tests/sav/error_class_glob.res b/tests/sav/error_class_glob.res index 389e33a..46e2b1a 100644 --- a/tests/sav/error_class_glob.res +++ b/tests/sav/error_class_glob.res @@ -6,8 +6,8 @@ ../lib/core/kernel.nit:431,1--486,3: Error: `kernel$Numeric` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? ../lib/core/kernel.nit:492,1--515,3: Error: `kernel$Bool` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? ../lib/core/kernel.nit:517,1--599,3: Error: `kernel$Float` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:601,1--705,3: Error: `kernel$Byte` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:707,1--885,3: Error: `kernel$Int` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:887,1--1074,3: Error: `kernel$Char` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:1076,1--1093,3: Error: `kernel$Pointer` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? -../lib/core/kernel.nit:1095,1--1104,3: Error: `kernel$Task` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:601,1--700,3: Error: `kernel$Byte` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:702,1--883,3: Error: `kernel$Int` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:885,1--1064,3: Error: `kernel$Char` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:1066,1--1083,3: Error: `kernel$Pointer` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? +../lib/core/kernel.nit:1085,1--1094,3: Error: `kernel$Task` does not specialize `module_0$Object`. Possible duplication of the root class `Object`? diff --git a/tests/sav/nitce/test_new_native.res b/tests/sav/nitce/test_new_native.res index 43e16fd..874965a 100644 --- a/tests/sav/nitce/test_new_native.res +++ b/tests/sav/nitce/test_new_native.res @@ -1,5 +1,5 @@ CString -0x4e +78 Nit NativeArray 3 diff --git a/tests/sav/nitce/test_new_native_alt1.res b/tests/sav/nitce/test_new_native_alt1.res index a653720..7506938 100644 --- a/tests/sav/nitce/test_new_native_alt1.res +++ b/tests/sav/nitce/test_new_native_alt1.res @@ -1,5 +1,5 @@ CString -0x4e +78 Nit NativeArray 3 diff --git a/tests/sav/test_augmented.res b/tests/sav/test_augmented.res index 2afbdc5..c3897e7 100644 --- a/tests/sav/test_augmented.res +++ b/tests/sav/test_augmented.res @@ -22,7 +22,7 @@ s8 isa ASCIIFlatString String66515A s9 isa Regex / -0x47String/ +71String/ true false true diff --git a/tests/sav/test_bytes_hexdigit.res b/tests/sav/test_bytes_hexdigit.res index f00af0c..018a8df 100644 --- a/tests/sav/test_bytes_hexdigit.res +++ b/tests/sav/test_bytes_hexdigit.res @@ -1,3 +1,3 @@ -0x0b -0x1f -0x4d +11 +31 +77 diff --git a/tests/sav/test_new_native.res b/tests/sav/test_new_native.res index 02b60bc..742b701 100644 --- a/tests/sav/test_new_native.res +++ b/tests/sav/test_new_native.res @@ -1,5 +1,5 @@ CString -0x4e +78 Nit NativeArray[Int] 3 diff --git a/tests/sav/test_new_native_alt1.res b/tests/sav/test_new_native_alt1.res index c36446c..1af51e8 100644 --- a/tests/sav/test_new_native_alt1.res +++ b/tests/sav/test_new_native_alt1.res @@ -1,4 +1,4 @@ Runtime error: Cast failed. Expected `E`, got `Bool` (../lib/core/collection/array.nit:991) CString -0x4e +78 Nit diff --git a/tests/sav/test_prefixed_chars.res b/tests/sav/test_prefixed_chars.res index a334f7f..935db22 100644 --- a/tests/sav/test_prefixed_chars.res +++ b/tests/sav/test_prefixed_chars.res @@ -1,2 +1,2 @@ -0x41 +65 66515 diff --git a/tests/sav/test_prefixed_chars_alt1.res b/tests/sav/test_prefixed_chars_alt1.res deleted file mode 100644 index 8c96895..0000000 --- a/tests/sav/test_prefixed_chars_alt1.res +++ /dev/null @@ -1 +0,0 @@ -alt/test_prefixed_chars_alt1.nit:18,17--20: Syntax Error: usage of byte prefix on multibyte character. diff --git a/tests/sav/test_rope_bytes.res b/tests/sav/test_rope_bytes.res index a61d3e4..ac57a1c 100644 --- a/tests/sav/test_rope_bytes.res +++ b/tests/sav/test_rope_bytes.res @@ -1,2 +1,2 @@ à1111111111111111111111111111111111111111éć2222222222222222222222222222222222222222ç -0xc3 0xa0 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0x31 0xc3 0xa9 0xc4 0x87 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0x32 0xc3 0xa7 +195 160 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 195 169 196 135 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 195 167 diff --git a/tests/sav/test_string_bytes.res b/tests/sav/test_string_bytes.res index 8e3a30b..e6f0a3d 100644 --- a/tests/sav/test_string_bytes.res +++ b/tests/sav/test_string_bytes.res @@ -1,8 +1,8 @@ -[0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c] -[0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c,0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c,0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c,0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c] -[0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c,0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c,0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c,0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c] -[0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54] -[0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54,0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54,0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54,0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54] -[0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54,0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54,0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54,0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54] -[0x54,0x68,0x69,0x73,0x20,0x73,0x74,0x72,0x69,0x6e,0x67,0x20,0x69,0x73,0x20,0x63,0x6f,0x6f,0x6c] -[0x6c,0x6f,0x6f,0x63,0x20,0x73,0x69,0x20,0x67,0x6e,0x69,0x72,0x74,0x73,0x20,0x73,0x69,0x68,0x54] +[84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108] +[84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108,84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108,84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108,84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108] +[84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108,84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108,84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108,84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108] +[108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84] +[108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84,108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84,108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84,108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84] +[108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84,108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84,108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84,108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84] +[84,104,105,115,32,115,116,114,105,110,103,32,105,115,32,99,111,111,108] +[108,111,111,99,32,115,105,32,103,110,105,114,116,115,32,115,105,104,84] diff --git a/tests/shootout_mandelbrot.nit b/tests/shootout_mandelbrot.nit index 7970971..e0923ae 100644 --- a/tests/shootout_mandelbrot.nit +++ b/tests/shootout_mandelbrot.nit @@ -32,7 +32,7 @@ end var w = args.first.to_i var h = w -var byte_acc = 0u8 +var byte_acc = 0 var bit_num = 0 print("P4\n{w} {h}") @@ -56,19 +56,19 @@ for y in [0..h[ do if zr*zr+zi*zi > limit*limit then byte_acc = byte_acc << 1 else - byte_acc = (byte_acc << 1) + 1u8 + byte_acc = (byte_acc << 1) + 1 end bit_num = bit_num + 1 if bit_num == 8 then stdout.write_byte(byte_acc) - byte_acc = 0u8 + byte_acc = 0 bit_num = 0 else if x == w - 1 then byte_acc = byte_acc << (8-w%8) stdout.write_byte(byte_acc) - byte_acc = 0u8 + byte_acc = 0 bit_num = 0 end end diff --git a/tests/shootout_nsieve_bytes_alt.nit b/tests/shootout_nsieve_bytes_alt.nit index 6a05c79..73b3ee6 100644 --- a/tests/shootout_nsieve_bytes_alt.nit +++ b/tests/shootout_nsieve_bytes_alt.nit @@ -17,20 +17,20 @@ class Bitarray var narr: Bytes init do - for x in [0 .. narr.length[ do narr[x] = 0xFFu8 + for x in [0 .. narr.length[ do narr[x] = 0xFF end fun [](pos: Int): Bool do pos -= 2 - return (narr[pos / 8] & (1u8 << (7 - pos % 8))) != 0u8 + return (narr[pos / 8] & (1 << (7 - pos % 8))) != 0 end fun []=(pos: Int, val: Bool) do pos -= 2 if val then - narr[pos / 8] |= 1u8 << (7 - pos % 8) + narr[pos / 8] |= 1 << (7 - pos % 8) else - narr[pos / 8] &= 0xFFu8 - (1u8 << (7 - pos % 8)) + narr[pos / 8] &= 0xFF - (1 << (7 - pos % 8)) end end end diff --git a/tests/test_augmented.nit b/tests/test_augmented.nit index a1b5400..3d2a47a 100644 --- a/tests/test_augmented.nit +++ b/tests/test_augmented.nit @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -var c1 = b'G' +var c1 = u'G' var c2 = u'𐏓' var s = b"String\x41\x42" diff --git a/tests/test_binary.nit b/tests/test_binary.nit index 45750de..f4b7a3f 100644 --- a/tests/test_binary.nit +++ b/tests/test_binary.nit @@ -19,7 +19,7 @@ var writer = new FileWriter.open(path) #alt1# writer.big_endian = false #alt3# writer.big_endian = false writer.write "hello" -writer.write_byte 77u8 +writer.write_byte 77 writer.write_float 1.23456789 writer.write_double 1.23456789 writer.write_int64 123456789 diff --git a/tests/test_buffer_unicode.nit b/tests/test_buffer_unicode.nit index c42de6d..5ce1a1f 100644 --- a/tests/test_buffer_unicode.nit +++ b/tests/test_buffer_unicode.nit @@ -34,7 +34,7 @@ end l = 0 for i in fb.bytes do - print "Byte {l} = {i}" + print "Byte {l} = 0x{i.to_hex}" l += 1 end @@ -48,6 +48,6 @@ end l = fb.byte_length - 1 for i in fb.bytes.reverse_iterator do - print "Byte {l} = {i}" + print "Byte {l} = 0x{i.to_hex}" l -= 1 end diff --git a/tests/test_new_native.nit b/tests/test_new_native.nit index e6fee68..39400dc 100644 --- a/tests/test_new_native.nit +++ b/tests/test_new_native.nit @@ -13,10 +13,10 @@ # limitations under the License. var s = new CString(4) -s[0] = 0x4Eu8 -s[2] = 0x74u8 -s[1] = 0x69u8 -s[3] = 0u8 +s[0] = 0x4E +s[2] = 0x74 +s[1] = 0x69 +s[3] = 0 print s.class_name print s[0] print s.to_s diff --git a/tests/test_prefixed_chars.nit b/tests/test_prefixed_chars.nit index 3070060..a963e75 100644 --- a/tests/test_prefixed_chars.nit +++ b/tests/test_prefixed_chars.nit @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -var ascii_char = b'A' +var ascii_char = u'A' var unicode_char = u'𐏓' -#alt1 var bug_ascii = b'𐏓' - print ascii_char print unicode_char