Skip to content

Commit 58ed215

Browse files
Remove bits/bytes and force using bits/bytesBE/LE
1 parent 1fd6dd3 commit 58ed215

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

examples/stdlib/binstream.effekt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ def main() = {
1313
test("int back-and-forth (17), explicit LE"){ assert(x"${17.LE}", 17 * 256 * 256 * 256) }
1414
test("byte 00101010"){
1515
with on[MissingValue].default{ assert(true, false) }
16-
assert(first[Byte]{groupBytes{ bit"00101010${()}" }}.toInt, 42)
17-
}
18-
test("to bits and back"){
19-
with on[MissingValue].default{ assert(true, false) }
20-
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v =>
21-
assert(first[Byte]{ groupBytes{ bits(v) } }, v)
22-
}
16+
assert(first[Byte]{groupBytesBE{ bit"00101010${()}" }}.toInt, 42)
2317
}
2418
test("to bits and back LE bitorder"){
2519
with on[MissingValue].default{ assert(true, false) }
@@ -36,7 +30,7 @@ def main() = {
3630
test("append 0 means *2"){
3731
with on[MissingValue].default{ assert(true, false) }
3832
[42.toByte, 12.toByte, 127.toByte].foreach{ v =>
39-
assert(nth[Byte](1){ groupBytes{ repeat(7){ do emit(B0()) }; bits(v); do emit(B0()) } }, (v.toInt * 2).toByte)
33+
assert(nth[Byte](1){ groupBytesBE{ repeat(7){ do emit(B0()) }; bitsBE(v); do emit(B0()) } }, (v.toInt * 2).toByte)
4034
}
4135
}
4236
test("pow agrees with double one"){

libraries/common/binstream.effekt

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ def bytesBE(n: Int, width: Int): Unit / emit[Byte] = {
6868
/// emit bytes of the given int as a 4 bytes in big-endian byte order
6969
def bytesBE(n: Int): Unit / emit[Byte] = bytesBE(n, 4)
7070

71-
/// emit bytes of the given int as a 4 bytes in big-endian byte order
72-
def bytes(n: Int): Unit / emit[Byte] = bytesBE(n)
73-
7471
/// emit bytes of the given int as width bytes (in 2s-complement) in little-endian byte order
7572
def signedBytesLE(int: Int, width: Int): Unit / emit[Byte] =
7673
if (int < 0) {
@@ -178,9 +175,6 @@ def bitsBE(byte: Byte): Unit / emit[Bit] = {
178175
}
179176
}
180177

181-
/// emit bits of the given Byte as 8 Bits in big-endian bit order
182-
def bits(byte: Byte): Unit / emit[Bit] = bitsBE(byte)
183-
184178
/// emit bits of the given Byte as width Bits in little-endian bit order
185179
def bitsLE(v: Int, width: Int): Unit / emit[Bit] = {
186180
var mask = 1
@@ -222,8 +216,8 @@ def collectBitsBE{ body: => Unit / emit[Bit] }: Int = {
222216
}
223217

224218
/// split emitted bytes and emit the individual bits in big-endian bit order
225-
def ungroupBytes{ body: => Unit / emit[Byte] }: Unit / emit[Bit] =
226-
for[Byte]{body}{ b => bits(b) }
219+
def ungroupBytesBE{ body: => Unit / emit[Byte] }: Unit / emit[Bit] =
220+
for[Byte]{body}{ b => bitsBE(b) }
227221

228222
/// streaming negation in 2s-complement for little-endian bitstreams
229223
def twoscomplementLE{ body: => Unit / emit[Bit] }: Unit / emit[Bit] = {
@@ -273,11 +267,6 @@ def groupBytesLE{ body: => Unit / emit[Bit] }: Unit / emit[Byte] = {
273267
}
274268
}
275269

276-
/// group 8 bits into a byte each, big-endian bit order.
277-
/// NOTE: The remainder is dropped.
278-
def groupBytes{ body: => Unit / emit[Bit] }: Unit / emit[Byte] =
279-
groupBytesBE{body}
280-
281270
// Literals/splices
282271
// ----------------
283272
/// Splices allowed in bit stream literals
@@ -293,7 +282,7 @@ effect BitSplices = {
293282
/// Ignores whitespace
294283
def bit{ body: => Unit / { literal, BitSplices } }: Unit / emit[Bit] = {
295284
try {
296-
ungroupBytes{
285+
ungroupBytesBE{
297286
try {
298287
body()
299288
}
@@ -317,7 +306,7 @@ def bit{ body: => Unit / { literal, BitSplices } }: Unit / emit[Bit] = {
317306
}
318307
with splice[Unit] { _ => resume(()) }
319308
with splice[Bit] { b => do emit(b); resume(()) }
320-
with splice[Byte] { b => bits(b); resume(()) }
309+
with splice[Byte] { b => bitsBE(b); resume(()) }
321310
with splice[OfWidth[LE[Int]]] { i =>
322311
bitsLE(i.raw.raw, i.width)
323312
resume(())

0 commit comments

Comments
 (0)