summary refs log tree commit diff stats
path: root/lib/core/refs.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-01-04 14:16:33 +0100
committerAndreas Rumpf <rumpf_a@web.de>2018-01-04 14:16:33 +0100
commit80fef7c8182f8b1427697ef923266094bb49abb2 (patch)
tree6c25dc7f0db6302cd2766f18e413b7a3892bfa4d /lib/core/refs.nim
parent64d583d6caadb6c6e1f21bbc9385e2a53b81fe5b (diff)
downloadNim-80fef7c8182f8b1427697ef923266094bb49abb2.tar.gz
allocators.nim: minor typo
Diffstat (limited to 'lib/core/refs.nim')
-rw-r--r--lib/core/refs.nim55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/core/refs.nim b/lib/core/refs.nim
new file mode 100644
index 000000000..71c999a74
--- /dev/null
+++ b/lib/core/refs.nim
@@ -0,0 +1,55 @@
+#
+#
+#            Nim's Runtime Library
+#        (c) Copyright 2017 Nim contributors
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+## Default ref implementation used by Nim's core.
+
+import allocators
+
+type
+  TracingGc = ptr object of Allocator
+
+  GcHeader = object
+    t: ptr TypeLayout
+
+  GcFrame {.core.} = object
+    prev: ptr GcFrame
+    marker: proc (self: GcFrame; a: Allocator)
+
+proc `=trace`[T](a: ref T) =
+  if not marked(a):
+    mark(a)
+    `=trace`(a[])
+
+proc linkGcFrame(f: ptr GcFrame) {.core.}
+proc unlinkGcFrame() {.core.}
+
+proc setGcFrame(f: ptr GcFrame) {.core.}
+
+proc registerGlobal(p: pointer; t: ptr TypeLayout) {.core.}
+proc unregisterGlobal(p: pointer; t: ptr TypeLayout) {.core.}
+
+proc registerThreadvar(p: pointer; t: ptr TypeLayout) {.core.}
+proc unregisterThreadvar(p: pointer; t: ptr TypeLayout) {.core.}
+
+proc newImpl(t: ptr TypeLayout): pointer =
+  let a = getCurrentAllocator()
+  let r = cast[ptr GcHeader](a.alloc(a, t.size + sizeof(GcHeader), t.alignment))
+  r.typ = t
+  result = r +! sizeof(GcHeader)
+
+template new*[T](x: var ref T) =
+  x = newImpl(getTypeLayout(x))
+
+
+when false:
+  # implement these if your GC requires them:
+  proc writeBarrierLocal() {.core.}
+  proc writeBarrierGlobal() {.core.}
+
+  proc writeBarrierGeneric() {.core.}