-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add move semantics for heap specifier (#609)
- Loading branch information
1 parent
c56e451
commit 2561ef2
Showing
24 changed files
with
253 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,65 @@ | ||
import "std/data/map"; | ||
import "std/data/binary-tree"; | ||
|
||
f<int> main() { | ||
Map<int, string> map; | ||
assert map.getSize() == 0l; | ||
assert map.isEmpty(); | ||
map.insert(1, "Hello"); | ||
assert map.getSize() == 1l; | ||
assert !map.isEmpty(); | ||
map.insert(2, "World"); | ||
assert map.getSize() == 2l; | ||
map.insert(3, "Foo"); | ||
assert map.getSize() == 3l; | ||
map.insert(4, "Bar"); | ||
assert map.getSize() == 4l; | ||
assert map.contains(1); | ||
assert map.contains(2); | ||
assert map.contains(3); | ||
assert map.contains(4); | ||
assert map.get(1) == "Hello"; | ||
assert map.get(2) == "World"; | ||
assert map.get(3) == "Foo"; | ||
assert map.get(4) == "Bar"; | ||
map.remove(2); | ||
assert map.getSize() == 3l; | ||
assert !map.contains(2); | ||
assert !map.isEmpty(); | ||
map.remove(1); | ||
assert map.getSize() == 2l; | ||
assert !map.contains(1); | ||
assert !map.isEmpty(); | ||
string& foo = map.get(3); | ||
assert foo == "Foo"; | ||
foo = "Baz"; | ||
assert map.get(3) == "Baz"; | ||
Result<string> bar = map.getSafe(4); | ||
assert bar.isOk(); | ||
assert bar.unwrap() == "Bar"; | ||
Result<string> baz = map.getSafe(5); | ||
assert baz.isErr(); | ||
map.remove(3); | ||
assert map.getSize() == 1l; | ||
assert !map.contains(3); | ||
assert !map.isEmpty(); | ||
map.remove(4); | ||
assert map.getSize() == 0l; | ||
assert !map.contains(4); | ||
assert map.isEmpty(); | ||
BinaryTree<int> tree; | ||
tree.insert(5); | ||
tree.insert(3); | ||
tree.insert(7); | ||
tree.insert(2); | ||
assert tree.contains(5); | ||
assert tree.contains(3); | ||
assert tree.contains(7); | ||
assert tree.contains(2); | ||
assert !tree.contains(1); | ||
assert !tree.contains(4); | ||
assert !tree.contains(6); | ||
assert !tree.contains(8); | ||
tree.delete(3); | ||
assert tree.contains(5); | ||
assert !tree.contains(3); | ||
assert tree.contains(7); | ||
assert tree.contains(2); | ||
assert !tree.contains(1); | ||
assert !tree.contains(4); | ||
assert !tree.contains(6); | ||
assert !tree.contains(8); | ||
tree.delete(5); | ||
assert !tree.contains(5); | ||
assert !tree.contains(3); | ||
assert tree.contains(7); | ||
assert tree.contains(2); | ||
assert !tree.contains(1); | ||
assert !tree.contains(4); | ||
assert !tree.contains(6); | ||
assert !tree.contains(8); | ||
tree.delete(7); | ||
assert !tree.contains(5); | ||
assert !tree.contains(3); | ||
assert !tree.contains(7); | ||
assert tree.contains(2); | ||
assert !tree.contains(1); | ||
assert !tree.contains(4); | ||
assert !tree.contains(6); | ||
assert !tree.contains(8); | ||
tree.delete(2); | ||
assert !tree.contains(5); | ||
assert !tree.contains(3); | ||
assert !tree.contains(7); | ||
assert !tree.contains(2); | ||
assert !tree.contains(1); | ||
assert !tree.contains(4); | ||
assert !tree.contains(6); | ||
assert !tree.contains(8); | ||
|
||
printf("All assertions passed!\n"); | ||
} | ||
|
||
/*import "std/os/env"; | ||
import "std/io/filepath"; | ||
import "bootstrap/ast/ast-nodes"; | ||
import "bootstrap/lexer/lexer"; | ||
import "bootstrap/parser/parser"; | ||
/*p foo(heap int* ptr) { | ||
*ptr = 3; | ||
} | ||
|
||
f<int> main() { | ||
String filePathString = getEnv("SPICE_STD_DIR") + "/../test/test-files/bootstrap-compiler/standalone-parser-test/test-file.spice"; | ||
FilePath filePath = FilePath(filePathString); | ||
Lexer lexer = Lexer(filePath); | ||
Parser parser = Parser(lexer); | ||
ASTEntryNode* ast = parser.parse(); | ||
assert ast != nil<ASTEntryNode*>; | ||
printf("All assertions passed!\n"); | ||
heap int* ptr = sNew<int>(); | ||
*ptr = 5; | ||
foo(ptr); | ||
}*/ |
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
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
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
Oops, something went wrong.