projects
/
onyx.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
536b2ab
)
added: sensible overloads for `delete`
author
Brendan Hansen
<brendan.f.hansen@gmail.com>
Thu, 9 Mar 2023 22:32:27 +0000
(16:32 -0600)
committer
Brendan Hansen
<brendan.f.hansen@gmail.com>
Thu, 9 Mar 2023 22:32:27 +0000
(16:32 -0600)
core/builtin.onyx
patch
|
blob
|
history
diff --git
a/core/builtin.onyx
b/core/builtin.onyx
index aa5402c85bc845c7ef06f1882d8a250c8cc17815..332ac85b109568f91c881677ce97a5d46375b092 100644
(file)
--- a/
core/builtin.onyx
+++ b/
core/builtin.onyx
@@
-349,6
+349,30
@@
cfree :: (ptr: rawptr) => raw_free(context.allocator, ptr);
__make_overload :: #match {}
delete :: #match {}
+
+ #local
+ Destroyable :: interface (t: $T) {
+ { T.destroy(&t) } -> void;
+ }
+
+ #overload #order 1000
+ delete :: macro (x: &$T/Destroyable) {
+ x_ := x;
+ T.destroy(x_);
+ cfree(x_);
+ }
+
+ #local
+ IsNotDoublePointer :: interface (t: $T) {
+ #not **t;
+ }
+
+ #overload #order 1001
+ delete :: macro (x: &$T/core.intrinsics.types.type_is_simple)
+ where IsNotDoublePointer(&T)
+ {
+ cfree(x);
+ }
}