-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<refactor> prohibiting assignments of managed objects consisting of m…
…ore that 1 assignment.
- Loading branch information
Showing
3 changed files
with
59 additions
and
60 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,38 @@ | ||
if not require("fail") then return end | ||
require "terralibext" --load 'terralibext' to enable raii | ||
local test = require "test" | ||
|
||
local std = {} | ||
std.io = terralib.includec("stdio.h") | ||
|
||
local function printtestheader(s) | ||
print() | ||
print("===========================") | ||
print(s) | ||
print("===========================") | ||
end | ||
|
||
struct A{ | ||
data : int | ||
} | ||
|
||
A.methods.__init = terra(self : &A) | ||
std.io.printf("__init: calling initializer.\n") | ||
self.data = 1 | ||
end | ||
|
||
A.methods.__dtor = terra(self : &A) | ||
std.io.printf("__dtor: calling destructor.\n") | ||
self.data = -1 | ||
end | ||
|
||
terra test0() | ||
var a = A{1} | ||
var b = A{2} | ||
a, b = b, a --bitcopies don't work in a swap | ||
--tuple assignments are prohibited because proper | ||
--resource management cannot be guaranteed | ||
--(at least not yet) | ||
return a.data, b.data | ||
end | ||
test0() |
This file was deleted.
Oops, something went wrong.