work in progress: 'sink' and 'lent' types
This commit is contained in:
parent
06e68feadb
commit
e316665b7b
5 changed files with 16 additions and 5 deletions
|
|
@ -354,7 +354,7 @@ type
|
||||||
tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers
|
tyInt, tyInt8, tyInt16, tyInt32, tyInt64, # signed integers
|
||||||
tyFloat, tyFloat32, tyFloat64, tyFloat128,
|
tyFloat, tyFloat32, tyFloat64, tyFloat128,
|
||||||
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
|
tyUInt, tyUInt8, tyUInt16, tyUInt32, tyUInt64,
|
||||||
tyOptAsRef, tyUnused1, tyUnused2,
|
tyOptAsRef, tySink, tyLent,
|
||||||
tyVarargs,
|
tyVarargs,
|
||||||
tyUnused,
|
tyUnused,
|
||||||
tyProxy # used as errornous type (for idetools)
|
tyProxy # used as errornous type (for idetools)
|
||||||
|
|
@ -640,7 +640,7 @@ type
|
||||||
mNHint, mNWarning, mNError,
|
mNHint, mNWarning, mNError,
|
||||||
mInstantiationInfo, mGetTypeInfo, mNGenSym,
|
mInstantiationInfo, mGetTypeInfo, mNGenSym,
|
||||||
mNimvm, mIntDefine, mStrDefine, mRunnableExamples,
|
mNimvm, mIntDefine, mStrDefine, mRunnableExamples,
|
||||||
mException
|
mException, mBultinType
|
||||||
|
|
||||||
# things that we can evaluate safely at compile time, even if not asked for it:
|
# things that we can evaluate safely at compile time, even if not asked for it:
|
||||||
const
|
const
|
||||||
|
|
|
||||||
|
|
@ -739,7 +739,9 @@ proc semRaise(c: PContext, n: PNode): PNode =
|
||||||
if base.sym.magic == mException:
|
if base.sym.magic == mException:
|
||||||
break
|
break
|
||||||
if base.lastSon == nil:
|
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
|
return
|
||||||
base = base.lastSon
|
base = base.lastSon
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1618,6 +1618,11 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||||
of mPNimrodNode:
|
of mPNimrodNode:
|
||||||
incl m.typ.flags, tfTriggersCompileTime
|
incl m.typ.flags, tfTriggersCompileTime
|
||||||
of mException: discard
|
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)
|
else: localError(m.info, errTypeExpected)
|
||||||
|
|
||||||
proc semGenericConstraints(c: PContext, x: PType): PType =
|
proc semGenericConstraints(c: PContext, x: PType): PType =
|
||||||
|
|
|
||||||
|
|
@ -988,11 +988,11 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||||
result = sameTypeOrNilAux(a.sons[0], b.sons[0], c) and
|
result = sameTypeOrNilAux(a.sons[0], b.sons[0], c) and
|
||||||
sameValue(a.n.sons[0], b.n.sons[0]) and
|
sameValue(a.n.sons[0], b.n.sons[0]) and
|
||||||
sameValue(a.n.sons[1], b.n.sons[1])
|
sameValue(a.n.sons[1], b.n.sons[1])
|
||||||
of tyGenericInst, tyAlias, tyInferred:
|
of tyGenericInst, tyAlias, tyInferred, tyLent, tySink:
|
||||||
cycleCheck()
|
cycleCheck()
|
||||||
result = sameTypeAux(a.lastSon, b.lastSon, c)
|
result = sameTypeAux(a.lastSon, b.lastSon, c)
|
||||||
of tyNone: result = false
|
of tyNone: result = false
|
||||||
of tyUnused, tyOptAsRef, tyUnused1, tyUnused2: internalError("sameFlags")
|
of tyUnused, tyOptAsRef: internalError("sameFlags")
|
||||||
|
|
||||||
proc sameBackendType*(x, y: PType): bool =
|
proc sameBackendType*(x, y: PType): bool =
|
||||||
var c = initSameTypeClosure()
|
var c = initSameTypeClosure()
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,10 @@ type
|
||||||
when defined(nimHasOpt):
|
when defined(nimHasOpt):
|
||||||
type opt*{.magic: "Opt".}[T]
|
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.}
|
proc high*[T: Ordinal](x: T): T {.magic: "High", noSideEffect.}
|
||||||
## returns the highest possible index of an array, a sequence, a string or
|
## 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
|
## the highest possible value of an ordinal value `x`. As a special
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue