Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAII #659

Closed
wants to merge 89 commits into from
Closed

RAII #659

Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
e248051
<ignore> added test artifacts to .ignore
hiemstar May 17, 2024
0e2cdb0
<feature> added __init metamethod to initialize managed types in raii.
hiemstar May 17, 2024
683526d
<feature> added __dtor metamethod to destruct managed variables in raii.
hiemstar May 17, 2024
5ba46c8
<feature> added __copy metamethod which enables specialized copy-assi…
hiemstar May 17, 2024
d867d28
<tests> added simple testing of raii metamethods __init, __dtor, __co…
hiemstar May 17, 2024
52ae95d
<terralib> revert commented out code to make things work on my local …
hiemstar May 17, 2024
31482a8
<bugfix> now calling __dtor before a new copy-assignment
hiemstar May 17, 2024
a685745
<bugfix> fixed dispatch of __copy. calling __copy is limited to rhs b…
hiemstar May 21, 2024
d677352
<refactor> added hasmetamethod(v, method). changed copy assignment be…
hiemstar May 21, 2024
b77f477
forgot to uncomment SDKROOT code on macos
renehiemstra May 22, 2024
8ba635e
<bugfix> fixed small bug in copyconstruction where the type is passed…
hiemstar May 22, 2024
1ff7038
<test> tests/raii-copyctr-cast.t, which combines __cast and __copy me…
hiemstar May 22, 2024
1d03783
Merge branch 'raii' of github.com:renehiemstra/terra into raii
hiemstar May 22, 2024
31a006b
<test> raii-shared_ptr.t which tests some functionality for a shared …
hiemstar May 22, 2024
ac0c68a
<bugfix> enabled copy assignments for rhs 'select' variables and rhs …
hiemstar May 23, 2024
8aee8b1
<test> raii-offset_ptr.t: example with a type that has some sematics …
hiemstar May 23, 2024
94caf67
<feature> added lib/terralibext.t that is being called from terralib …
hiemstar May 26, 2024
8cbc4b0
<refactor> changed __init, __copy, __dtor from metamethods to regular…
hiemstar May 26, 2024
509816d
<refactor> cleaned up terralibext.t
hiemstar May 27, 2024
0090b2e
<refactor> updated tests to incorporate changes in 'terralibext.t'
hiemstar May 27, 2024
9bf3f79
<test> raii-compose.t: testing composable use of managed structs.
hiemstar May 27, 2024
e1d9cf0
<feature> first implementation of raii composable managed datastructures
hiemstar May 27, 2024
49170c6
<refactor> updated tests/raii-shared_ptr.t
hiemstar May 27, 2024
2e3dcf3
<bugfix> fixed assignment__copy assignment. removed __dtor in custom …
hiemstar May 27, 2024
4e6bfc3
<refactor> reorganized raii tests.
hiemstar May 27, 2024
95a7e84
<test> raii-tuple-default-copy.t and fails/raii-tuple-custom-copy.t
hiemstar May 27, 2024
f4caa8b
<bugfix> fixed throwing error in createassignment in case of a tuple …
hiemstar May 27, 2024
25cb501
<bugfix> proper error exception for tuple assignment of managed varia…
hiemstar May 27, 2024
dd7754f
<uncomment> system code macos in terralib.lua
hiemstar May 27, 2024
5415fe2
<docs> lib/raii.md - discussing implementation and use of RAII concepts.
hiemstar May 29, 2024
ced17ed
<ignore> added test artifacts to .ignore
hiemstar May 17, 2024
8877111
<feature> added __init metamethod to initialize managed types in raii.
hiemstar May 17, 2024
b760837
<feature> added __dtor metamethod to destruct managed variables in raii.
hiemstar May 17, 2024
c503201
<feature> added __copy metamethod which enables specialized copy-assi…
hiemstar May 17, 2024
59d0945
<tests> added simple testing of raii metamethods __init, __dtor, __co…
hiemstar May 17, 2024
69b96e0
<terralib> revert commented out code to make things work on my local …
hiemstar May 17, 2024
5510a1d
<bugfix> now calling __dtor before a new copy-assignment
hiemstar May 17, 2024
010da09
<bugfix> fixed dispatch of __copy. calling __copy is limited to rhs b…
hiemstar May 21, 2024
4e363b0
<refactor> added hasmetamethod(v, method). changed copy assignment be…
hiemstar May 21, 2024
3dbede1
<bugfix> fixed small bug in copyconstruction where the type is passed…
hiemstar May 22, 2024
2c83bf9
<test> tests/raii-copyctr-cast.t, which combines __cast and __copy me…
hiemstar May 22, 2024
5e55ed5
forgot to uncomment SDKROOT code on macos
renehiemstra May 22, 2024
2c24f11
<test> raii-shared_ptr.t which tests some functionality for a shared …
hiemstar May 22, 2024
543bac5
<bugfix> enabled copy assignments for rhs 'select' variables and rhs …
hiemstar May 23, 2024
1b56cf1
<test> raii-offset_ptr.t: example with a type that has some sematics …
hiemstar May 23, 2024
9762db8
<feature> added lib/terralibext.t that is being called from terralib …
hiemstar May 26, 2024
44fa7ad
<refactor> changed __init, __copy, __dtor from metamethods to regular…
hiemstar May 26, 2024
a2671e3
<refactor> cleaned up terralibext.t
hiemstar May 27, 2024
0d21b6d
<refactor> updated tests to incorporate changes in 'terralibext.t'
hiemstar May 27, 2024
84dfe04
<test> raii-compose.t: testing composable use of managed structs.
hiemstar May 27, 2024
433c5b7
<feature> first implementation of raii composable managed datastructures
hiemstar May 27, 2024
93114ff
<refactor> updated tests/raii-shared_ptr.t
hiemstar May 27, 2024
880342e
<bugfix> fixed assignment__copy assignment. removed __dtor in custom …
hiemstar May 27, 2024
d2d2ce8
<refactor> reorganized raii tests.
hiemstar May 27, 2024
2c3a4e0
<test> raii-tuple-default-copy.t and fails/raii-tuple-custom-copy.t
hiemstar May 27, 2024
2aeb433
<bugfix> fixed throwing error in createassignment in case of a tuple …
hiemstar May 27, 2024
5fcd780
<bugfix> proper error exception for tuple assignment of managed varia…
hiemstar May 27, 2024
ee3b76d
<uncomment> system code macos in terralib.lua
hiemstar May 27, 2024
dd5efb3
<docs> lib/raii.md - discussing implementation and use of RAII concepts.
hiemstar May 29, 2024
19d2f39
<merge> rebased changes on top of upstream/master
hiemstar May 29, 2024
50abd4a
<refactor> addmissing<dtor,copy,init> generates a missing method only…
hiemstar May 29, 2024
ae58678
<refactor> prohibiting assignments of managed objects consisting of m…
hiemstar May 29, 2024
5c31ea5
<systemcode> forgot to uncomment system code for macos.
hiemstar May 29, 2024
ec311ad
<docs> updated /lib/raii.md
hiemstar May 29, 2024
35040c6
<docs> updated /lib/raii.md
hiemstar May 29, 2024
12f6128
Update terralib.lua
renehiemstra May 31, 2024
296ba5c
<docs> updated /lib/raii.md
hiemstar Jun 5, 2024
e020696
<BUILD> added terralibext.t to list of terra files that are to be ins…
hiemstar Jun 27, 2024
df66d4c
Merge remote-tracking branch 'upstream/master' into raii
hiemstar Jun 27, 2024
84ebde2
Merge branch 'terralang:master' into raii
renehiemstra Aug 13, 2024
eaff090
<bugfix> fixed issue with assignment of managed variables where a tem…
hiemstar Aug 27, 2024
487cf69
<refactor> removed the print statements in terralibext.t in the gener…
hiemstar Aug 27, 2024
8109b94
Merge branch 'raii' of github.com:renehiemstra/terra into raii
hiemstar Aug 27, 2024
477ba23
<bugfix> fixed pasted-copy bug in __addmissingcopy - where hasdtor sh…
hiemstar Sep 7, 2024
86a3873
<feature> added __move, __forward to terralibext.t
hiemstar Sep 30, 2024
829ff63
<bugfix> passing by value in __generate_move in lib/terralibext.t
hiemstar Oct 17, 2024
7e30579
Merge remote-tracking branch 'upstream/master' into raii
hiemstar Oct 17, 2024
099ae98
<bugfix> direct initialization with managed members now works as expe…
hiemstar Nov 22, 2024
bed8cf0
fixed test to conform to added code of previous bugfix. one should be…
hiemstar Nov 22, 2024
2642290
<tests> added raii-copyctr.t that tests direct initialization and cop…
hiemstar Nov 22, 2024
779c01f
<test> added tests for returning managed vars from function
hiemstar Nov 25, 2024
952b904
<test> testing return managed variables from functions.
hiemstar Nov 25, 2024
e75ff3d
<bugfix> structcast now working correctly, also when returning multip…
hiemstar Nov 25, 2024
3f9d92f
forgot to uncomment macos specific code.
hiemstar Nov 25, 2024
b65e647
fixed typo 'environment' in README; added some test arctifacts and .d…
hiemstar Nov 25, 2024
4d4cf13
fixed typo in README
hiemstar Nov 25, 2024
c409fce
Merge branch 'master' into raii
renehiemstra Nov 26, 2024
440965d
<ignore> removed ducplicate 'cmake-build-debug' from .ignore file.
renehiemstra Nov 27, 2024
14234ca
<doc> added raii.md to documentation folder. updated content.
renehiemstra Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
<refactor> reorganized raii tests.
  • Loading branch information
hiemstar committed May 29, 2024
commit d2d2ce83612f4525d73081bc8ff3ac952ba45561
28 changes: 13 additions & 15 deletions tests/raii-copyctr-cast.t
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
--load 'terralibext' to enable raii
require "terralibext"
require "terralibext" --load 'terralibext' to enable raii
--[[
We need that direct initialization
var a : A = b
yields the same result as
var a : A
a = b
If 'b' is a variable or a literal (something with a value) and the user has
implemented the right copy-assignment 'A.metamethods.__copy' then the copy
should be perform using this metamethod.
If the metamethod is not implemented for the exact types then a (user-defined)
implemented the right copy-assignment 'A.methods.__copy' then the copy
should be performed using this method.
If the method is not implemented for the exact types then a (user-defined)
implicit cast should be attempted.
--]]

local test = require("test")
local std = {}
std.io = terralib.includec("stdio.h")
local std = {
io = terralib.includec("stdio.h")
}

struct A{
data : int
@@ -49,9 +49,9 @@ end

--[[
The integer '2' will first be cast to a temporary of type A using
the user defined A.metamethods.__cast method. Then the metamethod
A.metamethods.__init(self : &A) is called to initialize the variable
and then the copy-constructor A.metamethods.__copy(from : &A, to : &A)
the user defined A.metamethods.__cast method. Then the method
A.methods.__init(self : &A) is called to initialize the variable
and then the copy-constructor A.methods.__copy(from : &A, to : &A)
will be called to finalize the copy-construction.
--]]
terra testwithcast()
@@ -75,16 +75,14 @@ A.methods.__copy:adddefinition(terra(from : int, to : &A)
to.data = to.data + from + 11
end)


--[[
The metamethod A.metamethods.__init(self : &A) is called to initialize
the variable and then the copy-constructor A.metamethods.__copy(from : int, to : &A)
will be called to finalize the copy-construction.
The method A.methods.__init(self : &A) is called to initialize the variable
and then the copy-constructor A.methods.__copy(from : int, to : &A) will be
called to finalize the copy-construction.
--]]
terra testwithoutcast()
var a : A = 2
return a.data
end

-- to.data + from.data + 10 = 1 + 2 + 11 = 14
test.eq(testwithoutcast(), 14)
8 changes: 4 additions & 4 deletions tests/raii-offset_ptr.t
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--load 'terralibext' to enable raii
require "terralibext"
require "terralibext" --load 'terralibext' to enable raii
local test = require("test")

local std = {}
std.io = terralib.includec("stdio.h")
local std = {
io = terralib.includec("stdio.h")
}

struct offset_ptr{
offset : int
24 changes: 12 additions & 12 deletions tests/raii-unique_ptr.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
--load 'terralibext' to enable raii
require "terralibext"
local std = {}
std.io = terralib.includec("stdio.h")
std.lib = terralib.includec("stdlib.h")
require "terralibext" --load 'terralibext' to enable raii

local std = {
io = terralib.includec("stdio.h"),
lib = terralib.includec("stdlib.h")
}

local function printtestheader(s)
print()
@@ -67,12 +68,17 @@ terra A.methods.allocate(self : &A)
self.heap = true
end


local test = require "test"

printtestheader("raii-unique_ptr.t: test return ptr value from function before resource is deleted")
terra testdereference()
var ptr : A
ptr:allocate()
ptr:setvalue(3)
return ptr:getvalue()
end
test.eq(testdereference(), 3)

terra returnheapresource()
var ptr : A
@@ -81,17 +87,11 @@ terra returnheapresource()
return ptr
end

printtestheader("raii-unique_ptr.t: test return heap resource from function")
terra testgetptr()
var ptr = returnheapresource()
return ptr:getvalue()
end

local test = require "test"

printtestheader("raii-unique_ptr.t: test return ptr value from function before resource is deleted")
test.eq(testdereference(), 3)

printtestheader("raii-unique_ptr.t: test return heap resource from function")
test.eq(testgetptr(), 3)