-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
Memory::relocate_memory
(#784)
* Add first draft inefficient implementation * Add new test cases * Clean leftover segments + add tests * Add temporal fix + TODO * Add test programs * Simplify code * Simplify code * Remove intermediate storange vec * Reserve memory for relocated values * Remove impossible-case code * Add tests * Clippy * Remove temp_data trim * Simplify code + add test case * Remove comments + add cairo progran * Use remove instead of swap for relocated temporary memory * Rely on insertion errors + add tests * Add newline at eof * Add comment * Change method name + add tests * Update CHANGELOG.md Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com> * Update src/vm/vm_memory/memory.rs Co-authored-by: Juan Rigada <62958725+Jrigada@users.noreply.github.com> * Update src/vm/vm_memory/memory.rs Co-authored-by: Juan Rigada <62958725+Jrigada@users.noreply.github.com> --------- Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com> Co-authored-by: Juan Rigada <62958725+Jrigada@users.noreply.github.com>
- Loading branch information
1 parent
b91f4ac
commit 4a642c7
Showing
6 changed files
with
440 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.segments import relocate_segment | ||
|
||
func main() { | ||
alloc_locals; | ||
// Create temporary_array in a temporary segment | ||
local temporary_array: felt*; | ||
%{ | ||
ids.temporary_array = segments.add_temp_segment() | ||
%} | ||
|
||
// Insert values into temporary_array | ||
assert temporary_array[0] = 4; | ||
assert temporary_array[1] = 5; | ||
assert temporary_array[2] = 6; | ||
|
||
// Create array | ||
let (array: felt*) = alloc(); | ||
assert array[0] = 1; | ||
assert array[1] = 2; | ||
assert array[2] = 3; | ||
|
||
// Realocate temporary_array into the array segment | ||
relocate_segment(src_ptr=temporary_array, dest_ptr=array + 3); | ||
|
||
return (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.segments import relocate_segment | ||
|
||
func main() { | ||
alloc_locals; | ||
// Create temporary_array in a temporary segment | ||
local temporary_array: felt*; | ||
%{ | ||
ids.temporary_array = segments.add_temp_segment() | ||
%} | ||
|
||
// Insert values into temporary_array | ||
assert temporary_array[0] = 1; | ||
assert temporary_array[1] = 2; | ||
assert temporary_array[2] = 3; | ||
|
||
// Create array | ||
let (array: felt*) = alloc(); | ||
|
||
// Realocate temporary_array into the array segment | ||
relocate_segment(src_ptr=temporary_array, dest_ptr=array); | ||
|
||
return (); | ||
} |
Oops, something went wrong.