Skip to content

Commit 65fb7d6

Browse files
committed
Fix procedures bytevector-copy and bytevector-copy!.
1 parent 1cc85b8 commit 65fb7d6

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

Sources/LispKit/Primitives/BytevectorLibrary.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,20 @@ public final class BytevectorLibrary: NativeLibrary {
126126

127127
func bytevectorCopy(_ bvec: Expr, args: Arguments) throws -> Expr {
128128
let bvector = try bvec.asByteVector()
129-
guard let (s, e) = args.optional(Expr.makeNumber(bvector.value.count),
130-
Expr.makeNumber(0)) else {
129+
guard let (s, e) = args.optional(Expr.makeNumber(0),
130+
Expr.makeNumber(bvector.value.count)) else {
131131
throw RuntimeError.argumentCount(of: "bytevector-copy",
132-
min: 2,
133-
max: 2,
132+
min: 1,
133+
max: 3,
134134
args: .pair(bvec, .makeList(args)))
135135
}
136136
let (start, end) = (try s.asInt(), try e.asInt())
137-
guard start >= 0 && start < bvector.value.count else {
137+
guard start >= 0 && start <= bvector.value.count else {
138138
throw RuntimeError.range(parameter: 2,
139139
of: "bytevector-copy",
140140
s,
141141
min: 0,
142-
max: Int64(bvector.value.count - 1))
142+
max: Int64(bvector.value.count))
143143
}
144144
guard end >= start && end <= bvector.value.count else {
145145
throw RuntimeError.range(parameter: 3,
@@ -163,18 +163,18 @@ public final class BytevectorLibrary: NativeLibrary {
163163
of: "bytevector-copy!",
164164
at,
165165
min: 0,
166-
max: Int64(toVec.value.count - 1))
166+
max: Int64(toVec.value.count))
167167
}
168168
let fromVec = try from.asByteVector()
169-
guard let (s, e) = args.optional(Expr.makeNumber(fromVec.value.count),
170-
Expr.makeNumber(0)) else {
169+
guard let (s, e) = args.optional(Expr.makeNumber(0),
170+
Expr.makeNumber(fromVec.value.count)) else {
171171
throw RuntimeError.argumentCount(of: "bytevector-copy!",
172172
min: 3,
173173
max: 5,
174174
args: .pair(to, .pair(at, .pair(from, .makeList(args)))))
175175
}
176176
let (start, end) = (try s.asInt(), try e.asInt())
177-
guard start >= 0 && start < fromVec.value.count else {
177+
guard start >= 0 && start <= fromVec.value.count else {
178178
throw RuntimeError.range(parameter: 4,
179179
of: "bytevector-copy!",
180180
s,

Sources/LispKit/Resources/Tests/R7RS.scm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,20 +1550,20 @@
15501550
(test #u8(0 255 2)
15511551
(let ((bv (bytevector 0 1 2))) (bytevector-u8-set! bv 1 255) bv))
15521552

1553-
#;(test #u8() (bytevector-copy #u8())) ;; TODO
1554-
#;(test #u8(0 1 2) (bytevector-copy #u8(0 1 2))) ;; TODO
1555-
#;(test #u8(1 2) (bytevector-copy #u8(0 1 2) 1)) ;; TODO
1556-
#;(test #u8(1) (bytevector-copy #u8(0 1 2) 1 2)) ;; TODO
1553+
(test #u8() (bytevector-copy #u8()))
1554+
(test #u8(0 1 2) (bytevector-copy #u8(0 1 2)))
1555+
(test #u8(1 2) (bytevector-copy #u8(0 1 2) 1))
1556+
(test #u8(1) (bytevector-copy #u8(0 1 2) 1 2))
15571557

1558-
#;(test #u8(1 6 7 4 5)
1558+
(test #u8(1 6 7 4 5)
15591559
(let ((bv (bytevector 1 2 3 4 5)))
15601560
(bytevector-copy! bv 1 #u8(6 7 8 9 10) 0 2)
15611561
bv)) ;; TODO
1562-
#;(test #u8(6 7 8 9 10)
1562+
(test #u8(6 7 8 9 10)
15631563
(let ((bv (bytevector 1 2 3 4 5)))
15641564
(bytevector-copy! bv 0 #u8(6 7 8 9 10))
15651565
bv)) ;; TODO
1566-
#;(test #u8(8 9 10 4 5)
1566+
(test #u8(8 9 10 4 5)
15671567
(let ((bv (bytevector 1 2 3 4 5)))
15681568
(bytevector-copy! bv 0 #u8(6 7 8 9 10) 2)
15691569
bv)) ;; TODO

0 commit comments

Comments
 (0)