Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clean-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
13
Issues
13
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
clean-and-itasks
clean-platform
Commits
c47d3e73
Verified
Commit
c47d3e73
authored
Sep 22, 2018
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make System._PointerWithFinalizer more general; move to System._Finalized
parent
a2cde102
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
30 deletions
+66
-30
src/libraries/OS-Independent/System/_Finalized.dcl
src/libraries/OS-Independent/System/_Finalized.dcl
+40
-0
src/libraries/OS-Independent/System/_Finalized.icl
src/libraries/OS-Independent/System/_Finalized.icl
+25
-0
src/libraries/OS-Independent/System/_PointerWithFinalizer.dcl
...libraries/OS-Independent/System/_PointerWithFinalizer.dcl
+0
-30
tests/linux64/test.icl
tests/linux64/test.icl
+1
-0
No files found.
src/libraries/OS-Independent/System/_Finalized.dcl
0 → 100644
View file @
c47d3e73
definition
module
System
.
_Finalized
/**
* This module provides support for 'finalized' values. These are values that
* have a finalizer attached to them: a C function pointer and an integer
* argument for that function. When the value is discarded by the garbage
* collector, the C function will be called with that argument. Because garbage
* collection runs periodically, this may not be directly after all references
* to the value are lost (and may not happen at all, depending on the heap
* usage of the application).
*/
from
System
.
_Pointer
import
::
Pointer
::
Finalized
a
=
Finalized
!
a
!
Finalizer
::
Finalizer
=
{
finalizer_implementation
::
!
FinalizerT
}
::
FinalizerT
=
DummyFinalizer
!
Int
!
Int
!
Int
/**
* Attach a finalizer to a value.
*
* @param The value
* @param A pointer to the finalizer C function
* @param An integer argument for the C function
* @result The value with a finalizer attached
*/
finalize
::
a
!
Pointer
!
Int
->
Finalized
a
/**
* Perfoms an operation on a finalized value.
* All operations on a finalized value must use this function in order for the
* system to work (otherwise, a reference to the value may still exist while
* all references to the {{`Finalizer`}} are lost).
*
* @param The operation to perform
* @param The finalized value
* @result The operation's result
*/
withFinalizedValue
::
!(
a
->
b
)
!(
Finalized
a
)
->
(!
b
,
!
Finalized
a
)
src/libraries/OS-Independent/System/_
PointerWithFinalizer
.icl
→
src/libraries/OS-Independent/System/_
Finalized
.icl
View file @
c47d3e73
implementation
module
System
.
_PointerWithFinalizer
import
StdEnv
import
Data
.
Func
import
System
.
_Pointer
::
PointerWithFinalizer
=
PointerWithFinalizer
!
Pointer
!
Finalizer
pointerWithFinalizer
::
!
Pointer
!
Pointer
->
PointerWithFinalizer
pointerWithFinalizer
ptr
finalPtr
=
PointerWithFinalizer
ptr
$
make_finalizer
finalPtr
ptr
withPointer
::
!(
Pointer
->
a
)
!
PointerWithFinalizer
->
(!
a
,
!
PointerWithFinalizer
)
withPointer
func
fptr
=:(
PointerWithFinalizer
ptr
_)
=
(
func
ptr
,
fptr
)
::
Finalizer
=
{
finalizer_implementation
::
!
FinalizerT
}
::
FinalizerT
=
DummyFinalizer
!
Int
!
Int
!
Int
make_finalizer
::
!
Pointer
!
Pointer
->
Finalizer
make_finalizer
f
v
=
{
finalizer_implementation
=
fst
$
make_finalizer_c
f
v
}
where
make_finalizer_c
::
!
Int
!
Int
->
(!
FinalizerT
,
!
Int
)
make_finalizer_c
f
v
=
code {
push_finalizers
push_a_b
0
pop_a
1
build_r
e__system_kFinalizer
0
3
0
0
pop_b
3
set_finalizers
pushI
0
}
implementation
module
System
.
_Finalized
import
StdEnv
import
Data
.
Func
import
System
.
_Pointer
finalize
::
a
!
Pointer
!
Int
->
Finalized
a
finalize
val
ptr
arg
=
Finalized
val
$
make_finalizer
ptr
arg
withFinalizedValue
::
!(
a
->
b
)
!(
Finalized
a
)
->
(!
b
,
!
Finalized
a
)
withFinalizedValue
func
fin
=:(
Finalized
x
_)
=
(
func
x
,
fin
)
make_finalizer
::
!
Pointer
!
Int
->
Finalizer
make_finalizer
f
v
=
{
finalizer_implementation
=
fst
$
make_finalizer_c
f
v
}
where
make_finalizer_c
::
!
Int
!
Int
->
(!
FinalizerT
,
!
Int
)
make_finalizer_c
f
v
=
code {
push_finalizers
push_a_b
0
pop_a
1
build_r
e__system_kFinalizer
0
3
0
0
pop_b
3
set_finalizers
pushI
0
}
src/libraries/OS-Independent/System/_PointerWithFinalizer.dcl
deleted
100644 → 0
View file @
a2cde102
definition
module
System
.
_PointerWithFinalizer
/**
* This module provides pointer to which finalizers are attached,
* which are called if no reference to the pointer is left.
*/
from
System
.
_Pointer
import
::
Pointer
::
PointerWithFinalizer
/**
* Creates a pointer with a finalizer which is called if no reference to the pointer is left.
*
* @param A pointer
* @param A pointer to the finalizer C function, which gets the pointer as argument
* @result The pointer with a finalizer attached
*/
pointerWithFinalizer
::
!
Pointer
!
Pointer
->
PointerWithFinalizer
/**
* Perfoms an operation on the pointer.
* All operations on the pointer have to be evaluated within the function
* to make sure that no operations are performed on the pointer after the finalizer is called.
*
* @param The operation to perform
* @param The pointer with finalizer
* @result The operation's result
*/
withPointer
::
!(
Pointer
->
a
)
!
PointerWithFinalizer
->
(!
a
,
!
PointerWithFinalizer
)
tests/linux64/test.icl
View file @
c47d3e73
...
...
@@ -145,6 +145,7 @@ import qualified System.TTS
import
qualified
System
.
Time
import
qualified
System
.
_Directory
import
qualified
System
.
_FilePath
import
qualified
System
.
_Finalized
import
qualified
System
.
_Platform
import
qualified
System
.
_Pointer
import
qualified
System
.
_Posix
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment