-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[master] add support for move-only types to map (#43)
- Loading branch information
Showing
3 changed files
with
126 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/perl | ||
|
||
use warnings; | ||
use strict; | ||
$ENV{"DALE_TEST_ARGS"} ||= ""; | ||
my $test_dir = $ENV{"DALE_TEST_DIR"} || "."; | ||
$ENV{PATH} .= ":."; | ||
|
||
use Data::Dumper; | ||
use Test::More tests => 3; | ||
|
||
my @res = `dalec $ENV{"DALE_TEST_ARGS"} -lm $test_dir/t/src/map-rv.dt -o map-rv `; | ||
is_deeply(\@res, [], 'No compilation errors'); | ||
@res = `./map-rv`; | ||
is($?, 0, 'Program executed successfully'); | ||
|
||
chomp for @res; | ||
|
||
is_deeply(\@res, [ | ||
'2 2', | ||
'3 3', | ||
'4 4', | ||
], | ||
'Got correct results'); | ||
|
||
`rm map-rv`; | ||
|
||
1; |
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,66 @@ | ||
(import cstdio) | ||
(import unistd) | ||
(import macros) | ||
(import unique-ptr) | ||
(import map) | ||
(import derivations) | ||
(import algorithms) | ||
|
||
(std.concepts.instantiate UniquePtr int) | ||
|
||
(def = (fn intern bool ((a (const (p int))) (b (const (p int)))) | ||
(= (@ a) (@ b)))) | ||
(def < (fn intern bool ((a (const (p int))) (b (const (p int)))) | ||
(< (@ a) (@ b)))) | ||
(def = (fn extern bool ((a (ref (const (UniquePtr int)))) | ||
(b (ref (const (UniquePtr int))))) | ||
(= (core-@:@ a pointer) (core-@:@ b pointer)))) | ||
(def < (fn extern bool ((a (ref (const (UniquePtr int)))) | ||
(b (ref (const (UniquePtr int))))) | ||
(< (core-@:@ a pointer) (core-@:@ b pointer)))) | ||
|
||
(std.concepts.instantiate relations (UniquePtr int)) | ||
(std.concepts.instantiate swap (UniquePtr int)) | ||
(std.concepts.implement Swappable (UniquePtr int)) | ||
(std.concepts.implement EqualityComparable (UniquePtr int)) | ||
(std.concepts.implement LessThanComparable (UniquePtr int)) | ||
|
||
(std.concepts.instantiate Map int (UniquePtr int)) | ||
|
||
(def main | ||
(fn extern-c int (void) | ||
(let ((map (Map int (UniquePtr int))) | ||
(myint1 \ (malloc' 1 int)) | ||
(myptr1 (UniquePtr int)) | ||
(myint2 \ (malloc' 1 int)) | ||
(myptr2 (UniquePtr int)) | ||
(myint3 \ (malloc' 1 int)) | ||
(myptr3 (UniquePtr int)) | ||
(myint4 \ (malloc' 1 int)) | ||
(myptr4 (UniquePtr int))) | ||
(setf myint1 1) | ||
(init myptr1 myint1) | ||
(setf myint2 2) | ||
(init myptr2 myint2) | ||
(setf myint3 3) | ||
(init myptr3 myint3) | ||
(setf myint4 4) | ||
(init myptr4 myint4) | ||
|
||
; (2, 2). | ||
(insert map 2 (move myptr2)) | ||
; (2, 2), (3, 3). | ||
(insert map 3 (move myptr3)) | ||
; (1, 1), (2, 2), (3, 3). | ||
(insert map 1 (move myptr1)) | ||
; (2, 2), (3, 3). | ||
(erase (begin map)) | ||
; (2, 2), (3, 3), (4, 4). | ||
(insert map 4 (move myptr4)) | ||
|
||
(while (not (empty map)) | ||
(let ((b1 \ (@ (get (@:@ (source (begin map)) second)))) | ||
(b2 \ (@:@ (source (begin map)) first))) | ||
(erase (begin map)) | ||
(printf "%d %d\n" b2 b1))) | ||
0))) |