Skip to content

Commit

Permalink
cleanup imports
Browse files Browse the repository at this point in the history
  • Loading branch information
thatstoasty committed Jul 9, 2024
1 parent 3efe9b7 commit b82b06d
Show file tree
Hide file tree
Showing 56 changed files with 5,079 additions and 3,637 deletions.
2 changes: 1 addition & 1 deletion external/gojo/bufio/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .bufio import Reader, Writer, ReadWriter
from .bufio import Reader, Writer, ReadWriter, new_writer, new_reader, new_read_writer
from .scan import Scanner, scan_words, scan_bytes, scan_lines
452 changes: 240 additions & 212 deletions external/gojo/bufio/bufio.mojo

Large diffs are not rendered by default.

239 changes: 110 additions & 129 deletions external/gojo/bufio/scan.mojo

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions external/gojo/builtins/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from .bytes import Byte, index_byte, has_suffix, has_prefix, to_string
from .list import equals
from .attributes import cap, copy
from .bytes import index_byte, has_suffix, has_prefix, to_string
from .attributes import copy
from .errors import exit, panic

alias Rune = Int32
124 changes: 120 additions & 4 deletions external/gojo/builtins/attributes.mojo
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from collections import InlineList


fn copy[T: CollectionElement](inout target: List[T], source: List[T], start: Int = 0) -> Int:
"""Copies the contents of source into target at the same index. Returns the number of bytes copied.
Added a start parameter to specify the index to start copying into.
Expand All @@ -22,10 +25,123 @@ fn copy[T: CollectionElement](inout target: List[T], source: List[T], start: Int
return count


fn cap[T: CollectionElement](iterable: List[T]) -> Int:
"""Returns the capacity of the List.
# fn copy[T: CollectionElement](inout target_span: Span[T], source_span: Span[T], start: Int = 0) -> Int:
# """Copies the contents of source into target at the same index. Returns the number of bytes copied.
# Added a start parameter to specify the index to start copying into.

# Args:
# target_span: The buffer to copy into.
# source_span: The buffer to copy from.
# start: The index to start copying into.

# Returns:
# The number of bytes copied.
# """
# var count = 0

# for i in range(len(source_span)):
# target_span[i + start] = source_span[i]
# count += 1

# target_span._len += count
# return count


# fn copy[T: CollectionElementNew](inout target_span: Span[T], source: InlineList[T], start: Int = 0) -> Int:
# """Copies the contents of source into target at the same index. Returns the number of bytes copied.
# Added a start parameter to specify the index to start copying into.

# Args:
# target_span: The buffer to copy into.
# source: The buffer to copy from.
# start: The index to start copying into.

# Returns:
# The number of bytes copied.
# """
# var count = 0

# for i in range(len(source)):
# target_span[i + start] = source[i]
# count += 1

# target_span._len += count
# return count


# fn copy[T: CollectionElementNew, T2: CollectionElement](inout list: InlineList[T], source: Span[T2], start: Int = 0) -> Int:
# """Copies the contents of source into target at the same index. Returns the number of bytes copied.
# Added a start parameter to specify the index to start copying into.

# Args:
# list: The buffer to copy into.
# source: The buffer to copy from.
# start: The index to start copying into.

# Returns:
# The number of bytes copied.
# """
# var count = 0

# for i in range(len(source)):
# if i + start > len(list):
# list[i + start] = source[i]
# else:
# list.append(source[i])
# count += 1

# return count


fn copy(target: UnsafePointer[UInt8], source: UnsafePointer[UInt8], source_length: Int, start: Int = 0) -> Int:
"""Copies the contents of source into target at the same index. Returns the number of bytes copied.
Added a start parameter to specify the index to start copying into.
Args:
target: The buffer to copy into.
source: The buffer to copy from.
source_length: The length of the source buffer.
start: The index to start copying into.
Returns:
The number of bytes copied.
"""
var count = 0

for i in range(source_length):
target[i + start] = source[i]
count += 1

return count


fn copy(
inout target: List[UInt8],
source: DTypePointer[DType.uint8],
source_start: Int,
source_end: Int,
target_start: Int = 0,
) -> Int:
"""Copies the contents of source into target at the same index. Returns the number of bytes copied.
Added a start parameter to specify the index to start copying into.
Args:
iterable: The List to get the capacity of.
target: The buffer to copy into.
source: The buffer to copy from.
source_start: The index to start copying from.
source_end: The index to stop copying at.
target_start: The index to start copying into.
Returns:
The number of bytes copied.
"""
return iterable.capacity
var count = 0

for i in range(source_start, source_end):
if i + target_start > len(target):
target[i + target_start] = source[i]
else:
target.append(source[i])
count += 1

return count
46 changes: 43 additions & 3 deletions external/gojo/builtins/bytes.mojo
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from .list import equals
alias Byte = UInt8


alias Byte = Int8
fn equals(left: List[UInt8], right: List[UInt8]) -> Bool:
if len(left) != len(right):
return False
for i in range(len(left)):
if left[i] != right[i]:
return False
return True


fn has_prefix(bytes: List[Byte], prefix: List[Byte]) -> Bool:
Expand Down Expand Up @@ -44,7 +50,41 @@ fn index_byte(bytes: List[Byte], delim: Byte) -> Int:
Returns:
The index of the first occurrence of the byte delim.
"""
var i = 0
for i in range(len(bytes)):
if bytes[i] == delim:
return i

return -1


fn index_byte(bytes: DTypePointer[DType.uint8], size: Int, delim: Byte) -> Int:
"""Return the index of the first occurrence of the byte delim.
Args:
bytes: The DTypePointer[DType.int8] struct to search.
size: The size of the bytes pointer.
delim: The byte to search for.
Returns:
The index of the first occurrence of the byte delim.
"""
for i in range(size):
if UInt8(bytes[i]) == delim:
return i

return -1


fn index_byte(bytes: Span[UInt8], delim: Byte) -> Int:
"""Return the index of the first occurrence of the byte delim.
Args:
bytes: The Span to search.
delim: The byte to search for.
Returns:
The index of the first occurrence of the byte delim.
"""
for i in range(len(bytes)):
if bytes[i] == delim:
return i
Expand Down
2 changes: 1 addition & 1 deletion external/gojo/builtins/errors.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ fn panic[T: Stringable](message: T, code: Int = 1):
message: The message to panic with.
code: The exit code to panic with.
"""
print("panic:", message)
print("panic:", str(message))
exit(code)
133 changes: 0 additions & 133 deletions external/gojo/builtins/list.mojo

This file was deleted.

Loading

0 comments on commit b82b06d

Please sign in to comment.