some little bugfixes
This commit is contained in:
parent
45f8d31c47
commit
dc669155e3
12 changed files with 91 additions and 69 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
Comex
|
Comex
|
||||||
|
Eric Doughty-Papassideris
|
||||||
Philippe Lhoste
|
Philippe Lhoste
|
||||||
Mario Ray Mahardhika
|
Mario Ray Mahardhika
|
||||||
Dominik Picheta
|
Dominik Picheta
|
||||||
|
|
|
||||||
|
|
@ -2163,7 +2163,7 @@ Example:
|
||||||
|
|
||||||
proc newNode[T](data: T): PBinaryTree[T] = # constructor for a node
|
proc newNode[T](data: T): PBinaryTree[T] = # constructor for a node
|
||||||
new(result)
|
new(result)
|
||||||
result.dat = data
|
result.data = data
|
||||||
|
|
||||||
proc add[T](root: var PBinaryTree[T], n: PBinaryTree[T]) =
|
proc add[T](root: var PBinaryTree[T], n: PBinaryTree[T]) =
|
||||||
if root == nil:
|
if root == nil:
|
||||||
|
|
@ -2172,7 +2172,7 @@ Example:
|
||||||
var it = root
|
var it = root
|
||||||
while it != nil:
|
while it != nil:
|
||||||
var c = cmp(it.data, n.data) # compare the data items; uses
|
var c = cmp(it.data, n.data) # compare the data items; uses
|
||||||
# the generic ``cmd`` proc that works for
|
# the generic ``cmp`` proc that works for
|
||||||
# any type that has a ``==`` and ``<``
|
# any type that has a ``==`` and ``<``
|
||||||
# operator
|
# operator
|
||||||
if c < 0:
|
if c < 0:
|
||||||
|
|
|
||||||
|
|
@ -699,7 +699,10 @@ when defined(windows):
|
||||||
discard FreeEnvironmentStringsA(env)
|
discard FreeEnvironmentStringsA(env)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
when defined(macosx):
|
const
|
||||||
|
useNSGetEnviron = defined(macosx) and
|
||||||
|
(defined(createNimRtl) or defined(useNimRtl))
|
||||||
|
when useNSGetEnviron:
|
||||||
# From the manual:
|
# From the manual:
|
||||||
# Shared libraries and bundles don't have direct access to environ,
|
# Shared libraries and bundles don't have direct access to environ,
|
||||||
# which is only available to the loader ld(1) when a complete program
|
# which is only available to the loader ld(1) when a complete program
|
||||||
|
|
@ -716,7 +719,7 @@ else:
|
||||||
proc getEnvVarsC() =
|
proc getEnvVarsC() =
|
||||||
# retrieves the variables of char** env of C's main proc
|
# retrieves the variables of char** env of C's main proc
|
||||||
if not envComputed:
|
if not envComputed:
|
||||||
when defined(macosx):
|
when useNSGetEnviron:
|
||||||
var gEnv = NSGetEnviron()^
|
var gEnv = NSGetEnviron()^
|
||||||
var i = 0
|
var i = 0
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
|
|
@ -751,7 +751,7 @@ proc match*(s: string, pattern: TPeg, matches: var openarray[string],
|
||||||
## returned.
|
## returned.
|
||||||
var c: TCaptures
|
var c: TCaptures
|
||||||
c.origStart = start
|
c.origStart = start
|
||||||
result = rawMatch(s, pattern, start, c) == len(s) -start
|
result = rawMatch(s, pattern, start, c) == len(s) - start
|
||||||
if result:
|
if result:
|
||||||
for i in 0..c.ml-1:
|
for i in 0..c.ml-1:
|
||||||
matches[i] = copy(s, c.matches[i][0], c.matches[i][1])
|
matches[i] = copy(s, c.matches[i][0], c.matches[i][1])
|
||||||
|
|
|
||||||
19
rod/cgen.nim
19
rod/cgen.nim
|
|
@ -267,7 +267,7 @@ proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: TLoc,
|
||||||
of frHeader:
|
of frHeader:
|
||||||
var r = rdLoc(a)
|
var r = rdLoc(a)
|
||||||
if not takeAddr: r = ropef("(*$1)", [r])
|
if not takeAddr: r = ropef("(*$1)", [r])
|
||||||
var s = t
|
var s = skipTypes(t, abstractInst)
|
||||||
while (s.kind == tyObject) and (s.sons[0] != nil):
|
while (s.kind == tyObject) and (s.sons[0] != nil):
|
||||||
app(r, ".Sup")
|
app(r, ".Sup")
|
||||||
s = skipTypes(s.sons[0], abstractInst)
|
s = skipTypes(s.sons[0], abstractInst)
|
||||||
|
|
@ -373,7 +373,7 @@ proc cstringLit(m: BModule, r: var PRope, s: string): PRope =
|
||||||
|
|
||||||
proc allocParam(p: BProc, s: PSym) =
|
proc allocParam(p: BProc, s: PSym) =
|
||||||
assert(s.kind == skParam)
|
assert(s.kind == skParam)
|
||||||
if not (lfParamCopy in s.loc.flags):
|
if lfParamCopy notin s.loc.flags:
|
||||||
inc(p.labels)
|
inc(p.labels)
|
||||||
var tmp = con("%LOC", toRope(p.labels))
|
var tmp = con("%LOC", toRope(p.labels))
|
||||||
incl(s.loc.flags, lfParamCopy)
|
incl(s.loc.flags, lfParamCopy)
|
||||||
|
|
@ -383,7 +383,6 @@ proc allocParam(p: BProc, s: PSym) =
|
||||||
s.loc.r = tmp
|
s.loc.r = tmp
|
||||||
|
|
||||||
proc localDebugInfo(p: BProc, s: PSym) =
|
proc localDebugInfo(p: BProc, s: PSym) =
|
||||||
var name, a: PRope
|
|
||||||
if {optStackTrace, optEndb} * p.options != {optStackTrace, optEndb}: return
|
if {optStackTrace, optEndb} * p.options != {optStackTrace, optEndb}: return
|
||||||
# XXX work around a bug: No type information for open arrays possible:
|
# XXX work around a bug: No type information for open arrays possible:
|
||||||
if skipTypes(s.typ, abstractVar).kind == tyOpenArray: return
|
if skipTypes(s.typ, abstractVar).kind == tyOpenArray: return
|
||||||
|
|
@ -391,7 +390,7 @@ proc localDebugInfo(p: BProc, s: PSym) =
|
||||||
# "address" is the 0th field
|
# "address" is the 0th field
|
||||||
# "typ" is the 1rst field
|
# "typ" is the 1rst field
|
||||||
# "name" is the 2nd field
|
# "name" is the 2nd field
|
||||||
name = cstringLit(p, p.s[cpsInit], normalize(s.name.s))
|
var name = cstringLit(p, p.s[cpsInit], normalize(s.name.s))
|
||||||
if (s.kind == skParam) and not ccgIntroducedPtr(s): allocParam(p, s)
|
if (s.kind == skParam) and not ccgIntroducedPtr(s): allocParam(p, s)
|
||||||
inc(p.labels, 3)
|
inc(p.labels, 3)
|
||||||
appf(p.s[cpsInit], "%LOC$6 = getelementptr %TF* %F, %NI 0, $1, %NI 0$n" &
|
appf(p.s[cpsInit], "%LOC$6 = getelementptr %TF* %F, %NI 0, $1, %NI 0$n" &
|
||||||
|
|
@ -404,12 +403,12 @@ proc localDebugInfo(p: BProc, s: PSym) =
|
||||||
toRope(p.labels), toRope(p.labels - 1),
|
toRope(p.labels), toRope(p.labels - 1),
|
||||||
toRope(p.labels - 2)])
|
toRope(p.labels - 2)])
|
||||||
else:
|
else:
|
||||||
a = con("&", s.loc.r)
|
var a = con("&", s.loc.r)
|
||||||
if (s.kind == skParam) and ccgIntroducedPtr(s): a = s.loc.r
|
if (s.kind == skParam) and ccgIntroducedPtr(s): a = s.loc.r
|
||||||
appf(p.s[cpsInit],
|
appf(p.s[cpsInit],
|
||||||
"F.s[$1].address = (void*)$3; F.s[$1].typ = $4; F.s[$1].name = $2;$n", [
|
"F.s[$1].address = (void*)$3; F.s[$1].typ = $4; F.s[$1].name = $2;$n",
|
||||||
toRope(p.frameLen), makeCString(normalize(s.name.s)), a,
|
[toRope(p.frameLen), makeCString(normalize(s.name.s)), a,
|
||||||
genTypeInfo(p.module, s.loc.t)])
|
genTypeInfo(p.module, s.loc.t)])
|
||||||
inc(p.frameLen)
|
inc(p.frameLen)
|
||||||
|
|
||||||
proc assignLocalVar(p: BProc, s: PSym) =
|
proc assignLocalVar(p: BProc, s: PSym) =
|
||||||
|
|
@ -461,7 +460,7 @@ proc iff(cond: bool, the, els: PRope): PRope =
|
||||||
|
|
||||||
proc assignParam(p: BProc, s: PSym) =
|
proc assignParam(p: BProc, s: PSym) =
|
||||||
assert(s.loc.r != nil)
|
assert(s.loc.r != nil)
|
||||||
if (sfAddrTaken in s.flags) and (gCmd == cmdCompileToLLVM): allocParam(p, s)
|
if sfAddrTaken in s.flags and gCmd == cmdCompileToLLVM: allocParam(p, s)
|
||||||
localDebugInfo(p, s)
|
localDebugInfo(p, s)
|
||||||
|
|
||||||
proc fillProcLoc(sym: PSym) =
|
proc fillProcLoc(sym: PSym) =
|
||||||
|
|
@ -574,7 +573,7 @@ proc generateHeaders(m: BModule) =
|
||||||
app(m.s[cfsHeaders], "#include \"nimbase.h\"" & tnl & tnl)
|
app(m.s[cfsHeaders], "#include \"nimbase.h\"" & tnl & tnl)
|
||||||
var it = PStrEntry(m.headerFiles.head)
|
var it = PStrEntry(m.headerFiles.head)
|
||||||
while it != nil:
|
while it != nil:
|
||||||
if not (it.data[0] in {'\"', '<'}):
|
if it.data[0] notin {'\"', '<'}:
|
||||||
appf(m.s[cfsHeaders], "#include \"$1\"$n", [toRope(it.data)])
|
appf(m.s[cfsHeaders], "#include \"$1\"$n", [toRope(it.data)])
|
||||||
else:
|
else:
|
||||||
appf(m.s[cfsHeaders], "#include $1$n", [toRope(it.data)])
|
appf(m.s[cfsHeaders], "#include $1$n", [toRope(it.data)])
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ proc getCurrentLine(L: TBaseLexer, marker: bool = true): string =
|
||||||
while not (L.buf[i] in {CR, LF, EndOfFile}):
|
while not (L.buf[i] in {CR, LF, EndOfFile}):
|
||||||
add(result, L.buf[i])
|
add(result, L.buf[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
result = result & "\n"
|
result.add("\n")
|
||||||
if marker:
|
if marker:
|
||||||
result = result & RepeatChar(getColNumber(L, L.bufpos)) & '^' & "\n"
|
result.add(RepeatChar(getColNumber(L, L.bufpos)) & '^' & "\n")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -472,11 +472,7 @@ proc addGenericParamListToScope(c: PContext, n: PNode) =
|
||||||
if a.kind != nkSym: internalError(a.info, "addGenericParamListToScope")
|
if a.kind != nkSym: internalError(a.info, "addGenericParamListToScope")
|
||||||
addDecl(c, a.sym)
|
addDecl(c, a.sym)
|
||||||
|
|
||||||
proc SemTypeSection(c: PContext, n: PNode): PNode =
|
proc typeSectionLeftSidePass(c: PContext, n: PNode) =
|
||||||
var
|
|
||||||
s: PSym
|
|
||||||
t, body: PType
|
|
||||||
result = n
|
|
||||||
# process the symbols on the left side for the whole type section, before
|
# process the symbols on the left side for the whole type section, before
|
||||||
# we even look at the type definitions on the right
|
# we even look at the type definitions on the right
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
|
@ -485,7 +481,8 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
if a.kind != nkTypeDef: IllFormedAst(a)
|
if a.kind != nkTypeDef: IllFormedAst(a)
|
||||||
checkSonsLen(a, 3)
|
checkSonsLen(a, 3)
|
||||||
if (c.p.owner.kind == skModule):
|
var s: PSym
|
||||||
|
if c.p.owner.kind == skModule:
|
||||||
s = semIdentWithPragma(c, skType, a.sons[0], {sfStar, sfMinus})
|
s = semIdentWithPragma(c, skType, a.sons[0], {sfStar, sfMinus})
|
||||||
incl(s.flags, sfGlobal)
|
incl(s.flags, sfGlobal)
|
||||||
else:
|
else:
|
||||||
|
|
@ -498,13 +495,15 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
|
||||||
# add it here, so that recursive types are possible:
|
# add it here, so that recursive types are possible:
|
||||||
addInterfaceDecl(c, s)
|
addInterfaceDecl(c, s)
|
||||||
a.sons[0] = newSymNode(s)
|
a.sons[0] = newSymNode(s)
|
||||||
|
|
||||||
|
proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
if (a.kind != nkTypeDef): IllFormedAst(a)
|
if (a.kind != nkTypeDef): IllFormedAst(a)
|
||||||
checkSonsLen(a, 3)
|
checkSonsLen(a, 3)
|
||||||
if (a.sons[0].kind != nkSym): IllFormedAst(a)
|
if (a.sons[0].kind != nkSym): IllFormedAst(a)
|
||||||
s = a.sons[0].sym
|
var s = a.sons[0].sym
|
||||||
if (s.magic == mNone) and (a.sons[2].kind == nkEmpty):
|
if (s.magic == mNone) and (a.sons[2].kind == nkEmpty):
|
||||||
GlobalError(a.info, errImplOfXexpected, s.name.s)
|
GlobalError(a.info, errImplOfXexpected, s.name.s)
|
||||||
if s.magic != mNone: processMagicType(c, s)
|
if s.magic != mNone: processMagicType(c, s)
|
||||||
|
|
@ -518,13 +517,12 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
|
||||||
InternalError(a.info, "semTypeSection: containerID")
|
InternalError(a.info, "semTypeSection: containerID")
|
||||||
s.typ.containerID = getID()
|
s.typ.containerID = getID()
|
||||||
a.sons[1] = semGenericParamList(c, a.sons[1], s.typ)
|
a.sons[1] = semGenericParamList(c, a.sons[1], s.typ)
|
||||||
|
|
||||||
# we fill it out later. For magic generics like 'seq', it won't be filled
|
# we fill it out later. For magic generics like 'seq', it won't be filled
|
||||||
# so we use tyEmpty instead of nil to not crash for strange conversions
|
# so we use tyEmpty instead of nil to not crash for strange conversions
|
||||||
# like: mydata.seq
|
# like: mydata.seq
|
||||||
addSon(s.typ, newTypeS(tyEmpty, c))
|
addSon(s.typ, newTypeS(tyEmpty, c))
|
||||||
s.ast = a
|
s.ast = a
|
||||||
body = semTypeNode(c, a.sons[2], nil)
|
var body = semTypeNode(c, a.sons[2], nil)
|
||||||
if body != nil: body.sym = s
|
if body != nil: body.sym = s
|
||||||
s.typ.sons[sonsLen(s.typ) - 1] = body
|
s.typ.sons[sonsLen(s.typ) - 1] = body
|
||||||
popOwner()
|
popOwner()
|
||||||
|
|
@ -532,28 +530,39 @@ proc SemTypeSection(c: PContext, n: PNode): PNode =
|
||||||
elif a.sons[2].kind != nkEmpty:
|
elif a.sons[2].kind != nkEmpty:
|
||||||
# process the type's body:
|
# process the type's body:
|
||||||
pushOwner(s)
|
pushOwner(s)
|
||||||
t = semTypeNode(c, a.sons[2], s.typ)
|
var t = semTypeNode(c, a.sons[2], s.typ)
|
||||||
if (t != s.typ) and (s.typ != nil):
|
if s.typ == nil:
|
||||||
internalError(a.info, "semTypeSection()")
|
s.typ = t
|
||||||
s.typ = t
|
elif t != s.typ:
|
||||||
|
# this can happen for e.g. tcan_alias_specialised_generic:
|
||||||
|
assignType(s.typ, t)
|
||||||
|
#debug s.typ
|
||||||
s.ast = a
|
s.ast = a
|
||||||
popOwner()
|
popOwner()
|
||||||
|
|
||||||
|
proc typeSectionFinalPass(c: PContext, n: PNode) =
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
if a.kind == nkCommentStmt: continue
|
if a.kind == nkCommentStmt: continue
|
||||||
if (a.sons[0].kind != nkSym): IllFormedAst(a)
|
if (a.sons[0].kind != nkSym): IllFormedAst(a)
|
||||||
s = a.sons[0].sym
|
var s = a.sons[0].sym
|
||||||
# compute the type's size and check for illegal recursions:
|
# compute the type's size and check for illegal recursions:
|
||||||
if a.sons[1].kind == nkEmpty:
|
if a.sons[1].kind == nkEmpty:
|
||||||
if (a.sons[2].kind in {nkSym, nkIdent, nkAccQuoted}):
|
if a.sons[2].kind in {nkSym, nkIdent, nkAccQuoted}:
|
||||||
# type aliases are hard:
|
# type aliases are hard:
|
||||||
#MessageOut('for type ' + typeToString(s.typ));
|
#MessageOut('for type ' + typeToString(s.typ));
|
||||||
t = semTypeNode(c, a.sons[2], nil)
|
var t = semTypeNode(c, a.sons[2], nil)
|
||||||
if t.kind in {tyObject, tyEnum}:
|
if t.kind in {tyObject, tyEnum}:
|
||||||
assignType(s.typ, t)
|
assignType(s.typ, t)
|
||||||
s.typ.id = t.id # same id
|
s.typ.id = t.id # same id
|
||||||
checkConstructedType(s.info, s.typ)
|
checkConstructedType(s.info, s.typ)
|
||||||
|
|
||||||
|
proc SemTypeSection(c: PContext, n: PNode): PNode =
|
||||||
|
typeSectionLeftSidePass(c, n)
|
||||||
|
typeSectionRightSidePass(c, n)
|
||||||
|
typeSectionFinalPass(c, n)
|
||||||
|
result = n
|
||||||
|
|
||||||
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) =
|
proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) =
|
||||||
s.typ = semProcTypeNode(c, n, genericParams, nil)
|
s.typ = semProcTypeNode(c, n, genericParams, nil)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -421,27 +421,34 @@ proc addInheritedFields(c: PContext, check: var TIntSet, pos: var int,
|
||||||
addInheritedFields(c, check, pos, obj.sons[0])
|
addInheritedFields(c, check, pos, obj.sons[0])
|
||||||
addInheritedFieldsAux(c, check, pos, obj.n)
|
addInheritedFieldsAux(c, check, pos, obj.n)
|
||||||
|
|
||||||
|
proc skipGenericInvokation(t: PType): PType {.inline.} =
|
||||||
|
result = t
|
||||||
|
if result.kind == tyGenericInvokation:
|
||||||
|
result = result.sons[0]
|
||||||
|
if result.kind == tyGenericBody:
|
||||||
|
result = lastSon(result)
|
||||||
|
|
||||||
proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
|
proc semObjectNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
var
|
var check: TIntSet
|
||||||
check: TIntSet
|
|
||||||
base: PType
|
|
||||||
pos: int
|
|
||||||
IntSetInit(check)
|
IntSetInit(check)
|
||||||
pos = 0 # n.sons[0] contains the pragmas (if any). We process these later...
|
var pos = 0
|
||||||
|
var base: PType = nil
|
||||||
|
# n.sons[0] contains the pragmas (if any). We process these later...
|
||||||
checkSonsLen(n, 3)
|
checkSonsLen(n, 3)
|
||||||
if n.sons[1].kind != nkEmpty:
|
if n.sons[1].kind != nkEmpty:
|
||||||
base = semTypeNode(c, n.sons[1].sons[0], nil)
|
base = semTypeNode(c, n.sons[1].sons[0], nil)
|
||||||
if base.kind == tyObject: addInheritedFields(c, check, pos, base)
|
var concreteBase = skipGenericInvokation(skipTypes(base, skipPtrs))
|
||||||
else: localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects)
|
if concreteBase.kind == tyObject and tfFinal notin concreteBase.flags:
|
||||||
else:
|
addInheritedFields(c, check, pos, concreteBase)
|
||||||
base = nil
|
else:
|
||||||
|
debug base
|
||||||
|
debug concreteBase
|
||||||
|
localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects)
|
||||||
if n.kind != nkObjectTy: InternalError(n.info, "semObjectNode")
|
if n.kind != nkObjectTy: InternalError(n.info, "semObjectNode")
|
||||||
result = newOrPrevType(tyObject, prev, c)
|
result = newOrPrevType(tyObject, prev, c)
|
||||||
addSon(result, base)
|
addSon(result, base)
|
||||||
result.n = newNodeI(nkRecList, n.info)
|
result.n = newNodeI(nkRecList, n.info)
|
||||||
semRecordNodeAux(c, n.sons[2], check, pos, result.n, result.sym)
|
semRecordNodeAux(c, n.sons[2], check, pos, result.n, result.sym)
|
||||||
if (base != nil) and (tfFinal in base.flags):
|
|
||||||
localError(n.sons[1].info, errInheritanceOnlyWithNonFinalObjects)
|
|
||||||
|
|
||||||
proc addTypeVarsOfGenericBody(c: PContext, t: PType, genericParams: PNode,
|
proc addTypeVarsOfGenericBody(c: PContext, t: PType, genericParams: PNode,
|
||||||
cl: var TIntSet): PType =
|
cl: var TIntSet): PType =
|
||||||
|
|
@ -559,9 +566,6 @@ proc semBlockType(c: PContext, n: PNode, prev: PType): PType =
|
||||||
Dec(c.p.nestedBlockCounter)
|
Dec(c.p.nestedBlockCounter)
|
||||||
|
|
||||||
proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
var
|
|
||||||
s: PSym
|
|
||||||
t: PType
|
|
||||||
result = nil
|
result = nil
|
||||||
if gCmd == cmdIdeTools: suggestExpr(c, n)
|
if gCmd == cmdIdeTools: suggestExpr(c, n)
|
||||||
case n.kind
|
case n.kind
|
||||||
|
|
@ -576,7 +580,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
else: GlobalError(n.info, errTypeExpected)
|
else: GlobalError(n.info, errTypeExpected)
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
checkMinSonsLen(n, 2)
|
checkMinSonsLen(n, 2)
|
||||||
s = semTypeIdent(c, n.sons[0])
|
var s = semTypeIdent(c, n.sons[0])
|
||||||
case s.magic
|
case s.magic
|
||||||
of mArray: result = semArray(c, n, prev)
|
of mArray: result = semArray(c, n, prev)
|
||||||
of mOpenArray: result = semContainer(c, n, tyOpenArray, "openarray", prev)
|
of mOpenArray: result = semContainer(c, n, tyOpenArray, "openarray", prev)
|
||||||
|
|
@ -586,7 +590,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
of mSeq: result = semContainer(c, n, tySequence, "seq", prev)
|
of mSeq: result = semContainer(c, n, tySequence, "seq", prev)
|
||||||
else: result = semGeneric(c, n, s, prev)
|
else: result = semGeneric(c, n, s, prev)
|
||||||
of nkIdent, nkDotExpr, nkAccQuoted:
|
of nkIdent, nkDotExpr, nkAccQuoted:
|
||||||
s = semTypeIdent(c, n)
|
var s = semTypeIdent(c, n)
|
||||||
if s.typ == nil: GlobalError(n.info, errTypeExpected)
|
if s.typ == nil: GlobalError(n.info, errTypeExpected)
|
||||||
if prev == nil:
|
if prev == nil:
|
||||||
result = s.typ
|
result = s.typ
|
||||||
|
|
@ -596,7 +600,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = prev
|
result = prev
|
||||||
of nkSym:
|
of nkSym:
|
||||||
if (n.sym.kind == skType) and (n.sym.typ != nil):
|
if (n.sym.kind == skType) and (n.sym.typ != nil):
|
||||||
t = n.sym.typ
|
var t = n.sym.typ
|
||||||
if prev == nil:
|
if prev == nil:
|
||||||
result = t
|
result = t
|
||||||
else:
|
else:
|
||||||
|
|
@ -615,20 +619,15 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
result = semProcTypeNode(c, n.sons[0], nil, prev)
|
result = semProcTypeNode(c, n.sons[0], nil, prev)
|
||||||
# dummy symbol for `pragma`:
|
# dummy symbol for `pragma`:
|
||||||
s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c)
|
var s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c)
|
||||||
s.typ = result
|
s.typ = result
|
||||||
pragma(c, s, n.sons[1], procTypePragmas)
|
pragma(c, s, n.sons[1], procTypePragmas)
|
||||||
of nkEnumTy:
|
of nkEnumTy: result = semEnum(c, n, prev)
|
||||||
result = semEnum(c, n, prev)
|
of nkType: result = n.typ
|
||||||
of nkType:
|
of nkStmtListType: result = semStmtListType(c, n, prev)
|
||||||
result = n.typ
|
of nkBlockType: result = semBlockType(c, n, prev)
|
||||||
of nkStmtListType:
|
else: GlobalError(n.info, errTypeExpected)
|
||||||
result = semStmtListType(c, n, prev)
|
#internalError(n.info, 'semTypeNode(' +{&} nodeKindToStr[n.kind] +{&} ')');
|
||||||
of nkBlockType:
|
|
||||||
result = semBlockType(c, n, prev)
|
|
||||||
else:
|
|
||||||
GlobalError(n.info, errTypeExpected)
|
|
||||||
#internalError(n.info, 'semTypeNode(' +{&} nodeKindToStr[n.kind] +{&} ')');
|
|
||||||
|
|
||||||
proc setMagicType(m: PSym, kind: TTypeKind, size: int) =
|
proc setMagicType(m: PSym, kind: TTypeKind, size: int) =
|
||||||
m.typ.kind = kind
|
m.typ.kind = kind
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,16 @@
|
||||||
import ast, astalgo, msgs, types, semdata
|
import ast, astalgo, msgs, types, semdata
|
||||||
|
|
||||||
proc checkConstructedType*(info: TLineInfo, t: PType) =
|
proc checkConstructedType*(info: TLineInfo, t: PType) =
|
||||||
if (tfAcyclic in t.flags) and (skipTypes(t, abstractInst).kind != tyObject):
|
if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
|
||||||
LocalError(info, errInvalidPragmaX, "acyclic")
|
LocalError(info, errInvalidPragmaX, "acyclic")
|
||||||
elif computeSize(t) < 0:
|
elif computeSize(t) < 0:
|
||||||
LocalError(info, errIllegalRecursionInTypeX, typeToString(t))
|
LocalError(info, errIllegalRecursionInTypeX, typeToString(t))
|
||||||
elif (t.kind == tyVar) and (t.sons[0].kind == tyVar):
|
elif t.kind == tyVar and t.sons[0].kind == tyVar:
|
||||||
LocalError(info, errVarVarTypeNotAllowed)
|
LocalError(info, errVarVarTypeNotAllowed)
|
||||||
|
when false:
|
||||||
|
if t.kind == tyObject and t.sons[0] != nil:
|
||||||
|
if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags:
|
||||||
|
localError(info, errInheritanceOnlyWithNonFinalObjects)
|
||||||
|
|
||||||
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
||||||
result = t.kind in GenericTypes
|
result = t.kind in GenericTypes
|
||||||
|
|
|
||||||
|
|
@ -669,7 +669,7 @@ proc transform(c: PTransf, n: PNode): PTransNode =
|
||||||
result = transformFor(c, n)
|
result = transformFor(c, n)
|
||||||
of nkCaseStmt:
|
of nkCaseStmt:
|
||||||
result = transformCase(c, n)
|
result = transformCase(c, n)
|
||||||
of nkProcDef, nkMethodDef, nkIteratorDef, nkMacroDef:
|
of nkProcDef, nkMethodDef, nkIteratorDef, nkMacroDef, nkConverterDef:
|
||||||
if n.sons[genericParamsPos].kind == nkEmpty:
|
if n.sons[genericParamsPos].kind == nkEmpty:
|
||||||
n.sons[codePos] = PNode(transform(c, n.sons[codePos]))
|
n.sons[codePos] = PNode(transform(c, n.sons[codePos]))
|
||||||
if n.kind == nkMethodDef: methodDef(n.sons[namePos].sym)
|
if n.kind == nkMethodDef: methodDef(n.sons[namePos].sym)
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,12 @@
|
||||||
|
|
||||||
type
|
type
|
||||||
TGen[T] = object
|
TGen[T] = object
|
||||||
|
x, y: T
|
||||||
|
|
||||||
TSpef[T] = object of TGen[T]
|
TSpef[T] = object of TGen[T]
|
||||||
|
|
||||||
|
|
||||||
|
var s: TSpef[float]
|
||||||
|
s.x = 0.4
|
||||||
|
s.y = 0.6
|
||||||
|
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -34,7 +34,7 @@ Bugs
|
||||||
To implement
|
To implement
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* hash tables and sets
|
* hash tables and sets; count tables; ordered dicts
|
||||||
* distinct types for array/seq indexes
|
* distinct types for array/seq indexes
|
||||||
* constant sequences
|
* constant sequences
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue