Skip to content

Commit dfaa06b

Browse files
Start adding doc comments
1 parent c501ec0 commit dfaa06b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

libraries/common/binstream.effekt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ import bytearray
1111

1212
// Wrappers
1313
// --------
14+
/// A with explicit big-endian order
1415
record BE[A](raw: A)
16+
/// A with explicit little-endian order
1517
record LE[A](raw: A)
18+
/// A with explicit width in current unit
19+
/// (bits for bitstreams, bytes for bytestreams)
1620
record OfWidth[A](raw: A, width: Int)
21+
/// explicitly signed A
1722
record Signed[A](raw: A)
1823

1924
/// Bits
2025
type Bit { B0(); B1() }
2126

22-
/// Effect alias
27+
/// Splices allowed in hex/byte stream literals
2328
effect HexSplices = {
2429
splice[Char], splice[String],
2530
splice[Unit],
@@ -33,39 +38,57 @@ effect HexSplices = {
3338

3439
// Splitting
3540
// ---------
41+
42+
/// emit bytes of the given int as a w bytes in little-endian byte order
3643
def bytesLE(int: Int, w: Int): Unit / emit[Byte] = {
3744
var c = int
3845
repeat(w){
3946
do emit(mod(c, 256).toByte)
4047
c = c / 256
4148
}
4249
}
50+
51+
/// emit bytes of the given int as a 4 bytes in little-endian byte order
4352
def bytesLE(int: Int): Unit / emit[Byte] = bytesLE(int, 4)
53+
54+
/// emit bytes of the given int as a w bytes in big-endian byte order
4455
def bytesBE(n: Int, width: Int): Unit / emit[Byte] = {
4556
var pos = pow(256, width - 1)
4657
repeat(width){
4758
do emit((bitwiseAnd(n, pos * 255) / pos).toByte)
4859
pos = pos / 256
4960
}
5061
}
62+
63+
/// emit bytes of the given int as a 4 bytes in big-endian byte order
5164
def bytesBE(n: Int): Unit / emit[Byte] = bytesBE(n, 4)
65+
66+
/// emit bytes of the given int as a 4 bytes in big-endian byte order
5267
def bytes(n: Int): Unit / emit[Byte] = bytesBE(n)
68+
69+
/// emit bytes of the given int as width bytes (in 2s-complement) in little-endian byte order
5370
def signedBytesLE(int: Int, width: Int): Unit / emit[Byte] = {
5471
if (int < 0) {
5572
bytesLE(bitwiseNot(neg(int)) + 1, width)
5673
} else {
5774
bytesLE(int, width)
5875
}
5976
}
77+
/// emit bytes of the given int as width bytes (in 2s-complement) in big-endian byte order
6078
def signedBytesBE(int: Int, width: Int): Unit / emit[Byte] = {
6179
if (int < 0) {
6280
bytesBE(bitwiseNot(neg(int)) + 1, width)
6381
} else {
6482
bytesBE(int, width)
6583
}
6684
}
85+
86+
/// emit bytes of the given int as 4 bytes (in 2s-complement) in little-endian byte order
6787
def signedBytesLE(int: Int): Unit / emit[Byte] = signedBytesLE(int, 4)
88+
89+
/// emit bytes of the given int as 4 bytes (in 2s-complement) in big-endian byte order
6890
def signedBytesBE(int: Int): Unit / emit[Byte] = signedBytesBE(int, 4)
91+
6992
def bitsBE(int: Int): Unit / emit[Bit] = bitsBE(int, 32)
7093
def collectBitsBE{ body: => Unit / emit[Bit] }: Int = {
7194
var res = 0

0 commit comments

Comments
 (0)