Skip to content

Commit

Permalink
[master] unique-ptr retval test (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Mar 24, 2016
1 parent 1d48489 commit e5d74d1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
28 changes: 28 additions & 0 deletions t/015up/005up-move-fn-ret.t
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"} $test_dir/t/src/up-move-fn-ret.dt -o up-move-fn-ret `;
is_deeply(\@res, [], 'No compilation errors');
@res = `./up-move-fn-ret`;
is($?, 0, 'Program executed successfully');

chomp for @res;

is_deeply(\@res, [
'0 100 0',
'100',
'0 0 100',
],
'Got correct results');

`rm up-move-fn-ret`;

1;
30 changes: 30 additions & 0 deletions t/src/up-move-fn-ret.dt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(import cstdio)
(import macros)
(import unique-ptr)

(std.concepts.instantiate UniquePtr int)

(def otherfn
(fn extern (retval (UniquePtr int)) ((myptr (rv-ref (UniquePtr int))))
(def myptr2 (var auto (UniquePtr int) (move (@ myptr))))
(printf "%d\n" (@ myptr2))
(setf retval (move myptr2))
(return)))

(def main
(fn extern-c int (void)
(let ((myptr (UniquePtr int))
(myptr2 (UniquePtr int))
(myptr3 (UniquePtr int))
(myint \ (malloc' 1 int)))
(setf myint 100)
(init myptr myint)
(setv myptr2 (move myptr))
(printf "%d %d %d\n" (cast (get myptr) intptr)
(@ myptr2)
(cast (get myptr3) intptr))
(setv myptr3 (otherfn (move myptr2)))
(printf "%d %d %d\n" (cast (get myptr) intptr)
(cast (get myptr2) intptr)
(@ myptr3))
0)))

0 comments on commit e5d74d1

Please sign in to comment.