Skip to content

Commit

Permalink
feat: debug for arrayview (moonbitlang#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
qazxcdswe123 authored Jul 9, 2024
1 parent 2ea4919 commit b2c713e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/builtin.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl Array {

type ArrayView
impl ArrayView {
debug_write[X : Debug](Self[X], Buffer) -> Unit
length[T](Self[T]) -> Int
op_as_view[T](Self[T], ~start : Int, ~end : Int) -> Self[T]
op_get[T](Self[T], Int) -> T
Expand Down
11 changes: 11 additions & 0 deletions builtin/debug.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ pub fn debug_write[X : Debug](self : Array[X], buf : Buffer) -> Unit {
buf.write_char(']')
}

pub fn debug_write[X : Debug](self : ArrayView[X], buf : Buffer) -> Unit {
buf.write_char('[')
for i = 0; i < self.length(); i = i + 1 {
if i > 0 {
buf.write_string(", ")
}
self[i].debug_write(buf)
}
buf.write_char(']')
}

pub fn debug_write(self : String, buf : Buffer) -> Unit {
buf.write_char('"')
let mut segment_start = 0
Expand Down

0 comments on commit b2c713e

Please sign in to comment.