Skip to content

Commit

Permalink
std/lib/collections: make List support the []= operator (#831)
Browse files Browse the repository at this point in the history
* std/lib/collections: make List support the []= operator

Signed-off-by: Pierre Curto <[email protected]>

* std/lib/io: rename receiver to self

Signed-off-by: Pierre Curto <[email protected]>

---------

Signed-off-by: Pierre Curto <[email protected]>
  • Loading branch information
pierrec authored Jul 7, 2023
1 parent 79e2d68 commit 7dc1eab
Show file tree
Hide file tree
Showing 11 changed files with 418 additions and 406 deletions.
5 changes: 5 additions & 0 deletions lib/std/collections/list.c3
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ fn Type* List.get_ref(&self, usz index) @operator(&[]) @inline
return &self.entries[index];
}

fn void List.set(&self, usz index, Type value) @operator([]=)
{
self.entries[index] = value;
}

fn void List.ensure_capacity(&self, usz added = 1) @inline @private
{
usz new_size = self.size + added;
Expand Down
16 changes: 8 additions & 8 deletions lib/std/io/io_file.c3
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ fn File from_libc(CFile file)
}

/**
* @require file.file != null
* @require self.file != null
**/
fn void! File.reopen(File* file, String filename, String mode)
fn void! File.reopen(&self, String filename, String mode)
{
file.file = os::native_freopen(file.file, filename, mode)!;
self.file = os::native_freopen(self.file, filename, mode)!;
}

/**
* @require file.file != null
* @require self.file != null
**/
fn usz! File.seek(File file, isz offset, Seek seek_mode = Seek.SET)
fn usz! File.seek(self, isz offset, Seek seek_mode = Seek.SET)
{
os::native_fseek(file.file, offset, seek_mode)!;
return os::native_ftell(file.file);
os::native_fseek(self.file, offset, seek_mode)!;
return os::native_ftell(self.file);
}


/*
Implement later
/**
* @require file.file == null
* @require self.file == null
**/
fn void! File.memopen(File* file, char[] data, String mode)
{
Expand Down
Loading

0 comments on commit 7dc1eab

Please sign in to comment.