work in progress: 'sink' and 'lent' types

This commit is contained in:
Araq
2018-01-07 10:17:19 +01:00
parent 06e68feadb
commit e316665b7b
5 changed files with 16 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 =

View File

@@ -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()

View File

@@ -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