summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-01-07 10:17:19 +0100
committerAraq <rumpf_a@web.de>2018-01-07 10:17:19 +0100
commite316665b7b25b3e45a66766260bfa645c92beb97 (patch)
treebde3eaaf190e9701cecdbc4445dbeb7485303968
parent06e68feadb4becb653e5e55fd2ef85e1eafd9ba4 (diff)
downloadNim-e316665b7b25b3e45a66766260bfa645c92beb97.tar.gz
work in progress: 'sink' and 'lent' types
-rw-r--r--compiler/ast.nim4
-rw-r--r--compiler/semstmts.nim4
-rw-r--r--compiler/semtypes.nim5
-rw-r--r--compiler/types.nim4
-rw-r--r--lib/system.nim4
5 files changed, 16 insertions, 5 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 27a44c6c2..f5114feb0 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -354,7 +354,7 @@ type
     tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers
     tyFloat, tyFloat32, tyFloat64, tyFloat128,
     tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
-    tyOptAsRef, tyUnused1, tyUnused2,
+    tyOptAsRef, tySink, tyLent,
     tyVarargs,
     tyUnused,
     tyProxy # used as errornous type (for idetools)
@@ -640,7 +640,7 @@ type
     mNHint, mNWarning, mNError,
     mInstantiationInfo, mGetTypeInfo, mNGenSym,
     mNimvm, mIntDefine, mStrDefine, mRunnableExamples,
-    mException
+    mException, mBultinType
 
 # things that we can evaluate safely at compile time, even if not asked for it:
 const
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index dcaa0263b..d8754a931 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -739,7 +739,9 @@ proc semRaise(c: PContext, n: PNode): PNode =
       if base.sym.magic == mException:
         break
       if base.lastSon == nil:
-        localError(n.info, "raised object of type $1 does not inherit from Exception", [typ.sym.name.s])
+        localError(n.info,
+          "raised object of type $1 does not inherit from Exception",
+          [typeToString(typ)])
         return
       base = base.lastSon
 
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index cb66685b2..b0171fcbe 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1618,6 +1618,11 @@ proc processMagicType(c: PContext, m: PSym) =
   of mPNimrodNode:
     incl m.typ.flags, tfTriggersCompileTime
   of mException: discard
+  of mBuiltinType:
+    case m.name.s
+    of "lent": setMagicType(m, tyLent, ptrSize)
+    of "sink": setMagicType(m, tySink, 0)
+    else: localError(m.info, errTypeExpected)
   else: localError(m.info, errTypeExpected)
 
 proc semGenericConstraints(c: PContext, x: PType): PType =
diff --git a/compiler/types.nim b/compiler/types.nim
index 495a1977d..0d3a25980 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -988,11 +988,11 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
     result = sameTypeOrNilAux(a.sons[0], b.sons[0], c) and
         sameValue(a.n.sons[0], b.n.sons[0]) and
         sameValue(a.n.sons[1], b.n.sons[1])
-  of tyGenericInst, tyAlias, tyInferred:
+  of tyGenericInst, tyAlias, tyInferred, tyLent, tySink:
     cycleCheck()
     result = sameTypeAux(a.lastSon, b.lastSon, c)
   of tyNone: result = false
-  of tyUnused, tyOptAsRef, tyUnused1, tyUnused2: internalError("sameFlags")
+  of tyUnused, tyOptAsRef: internalError("sameFlags")
 
 proc sameBackendType*(x, y: PType): bool =
   var c = initSameTypeClosure()
diff --git a/lib/system.nim b/lib/system.nim
index 4d8610737..de91c4dda 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -249,6 +249,10 @@ type
 when defined(nimHasOpt):
   type opt*{.magic: "Opt".}[T]
 
+when defined(nimHasSink):
+  type sink*{.magic: "BuiltinType".}[T]
+  type lent*{.magic: "BuiltinType".}[T]
+
 proc high*[T: Ordinal](x: T): T {.magic: "High", noSideEffect.}
   ## returns the highest possible index of an array, a sequence, a string or
   ## the highest possible value of an ordinal value `x`. As a special