diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgexprs.nim | 34 | ||||
-rw-r--r-- | compiler/cgen.nim | 3 | ||||
-rw-r--r-- | compiler/cgendata.nim | 10 | ||||
-rw-r--r-- | compiler/pragmas.nim | 8 | ||||
-rw-r--r-- | compiler/semexprs.nim | 4 | ||||
-rw-r--r-- | compiler/semtempl.nim | 10 | ||||
-rw-r--r-- | compiler/trees.nim | 19 | ||||
-rw-r--r-- | compiler/vmdeps.nim | 22 | ||||
-rw-r--r-- | compiler/vmgen.nim | 3 |
9 files changed, 68 insertions, 45 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 75a7cb3bb..a86409e50 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1151,7 +1151,25 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) = genTypeInfo(p.module, seqtype), a.rdLoc])) gcUsage(e) +proc genConstExpr(p: BProc, n: PNode): Rope +proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool = + if d.k == locNone and n.len > ord(n.kind == nkObjConstr) and n.isDeepConstExpr: + var t = getUniqueType(n.typ) + discard getTypeDesc(p.module, t) # so that any fields are initialized + let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels) + fillLoc(d, locData, t, p.module.tmpBase & rope(id), OnStatic) + if id == p.module.labels: + # expression not found in the cache: + inc(p.module.labels) + addf(p.module.s[cfsData], "NIM_CONST $1 $2 = $3;$n", + [getTypeDesc(p.module, t), d.r, genConstExpr(p, n)]) + result = true + else: + result = false + proc genObjConstr(p: BProc, e: PNode, d: var TLoc) = + if handleConstExpr(p, e, d): return + #echo rendertree e, " ", e.isDeepConstExpr var tmp: TLoc var t = e.typ.skipTypes(abstractInst) getTemp(p, t, tmp) @@ -1769,22 +1787,6 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mDotDot, mEqCString: genCall(p, e, d) else: internalError(e.info, "genMagicExpr: " & $op) -proc genConstExpr(p: BProc, n: PNode): Rope -proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool = - if nfAllConst in n.flags and d.k == locNone and n.len > 0 and n.isDeepConstExpr: - var t = getUniqueType(n.typ) - discard getTypeDesc(p.module, t) # so that any fields are initialized - let id = nodeTableTestOrSet(p.module.dataCache, n, p.module.labels) - fillLoc(d, locData, t, p.module.tmpBase & rope(id), OnStatic) - if id == p.module.labels: - # expression not found in the cache: - inc(p.module.labels) - addf(p.module.s[cfsData], "NIM_CONST $1 $2 = $3;$n", - [getTypeDesc(p.module, t), d.r, genConstExpr(p, n)]) - result = true - else: - result = false - proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = # example: { a..b, c, d, e, f..g } # we have to emit an expression of the form: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 4dbe8572e..9851ab0e2 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -328,7 +328,8 @@ proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) = proc getTemp(p: BProc, t: PType, result: var TLoc; needsInit=false) = inc(p.labels) result.r = "LOC" & rope(p.labels) - linefmt(p, cpsLocals, "$1 $2;$n", getTypeDesc(p.module, t), result.r) + addf(p.blocks[0].sections[cpsLocals], + "$1 $2;$n", [getTypeDesc(p.module, t), result.r]) result.k = locTemp #result.a = - 1 result.t = t diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index c027bb451..a94950029 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -15,7 +15,7 @@ import from msgs import TLineInfo type - TLabel* = Rope # for the C generator a label is just a rope + TLabel* = Rope # for the C generator a label is just a rope TCFileSection* = enum # the sections a generated C file consists of cfsMergeInfo, # section containing merge information cfsHeaders, # section for C include file headers @@ -89,7 +89,7 @@ type # requires 'T x = T()' to become 'T x; x = T()' # (yes, C++ is weird like that) gcFrameId*: Natural # for the GC stack marking - gcFrameType*: Rope # the struct {} we put the GC markers into + gcFrameType*: Rope # the struct {} we put the GC markers into TTypeSeq* = seq[PType] @@ -111,10 +111,10 @@ type tmpBase*: Rope # base for temp identifier generation typeCache*: TIdTable # cache the generated types forwTypeCache*: TIdTable # cache for forward declarations of types - declaredThings*: IntSet # things we have declared in this .c file - declaredProtos*: IntSet # prototypes we have declared in this .c file + declaredThings*: IntSet # things we have declared in this .c file + declaredProtos*: IntSet # prototypes we have declared in this .c file headerFiles*: TLinkedList # needed headers to include - typeInfoMarker*: IntSet # needed for generating type information + typeInfoMarker*: IntSet # needed for generating type information initProc*: BProc # code for init procedure postInitProc*: BProc # code to be executed after the init proc preInitProc*: BProc # code executed before the init proc diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 781aab687..354e5bdc6 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -400,8 +400,12 @@ proc relativeFile(c: PContext; n: PNode; ext=""): string = s = addFileExt(s, ext) result = parentDir(n.info.toFullPath) / s if not fileExists(result): - if isAbsolute(s): result = s - else: result = findFile(s) + if isAbsolute(s): + result = s + else: + result = findFile(s) + if result.len == 0: + result = s proc processCompile(c: PContext, n: PNode) = let found = relativeFile(c, n) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index fd18dc3d7..fc31829ba 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2216,7 +2216,9 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = if nfSem in n.flags: return case n.kind of nkIdent, nkAccQuoted: - var s = lookUp(c, n) + let checks = if efNoEvaluateGeneric in flags: {checkUndeclared} + else: {checkUndeclared, checkModule, checkAmbiguity} + var s = qualifiedLookUp(c, n, checks) if c.inTypeClass == 0: semCaptureSym(s, c.p.owner) result = semSym(c, n, s, flags) if s.kind in {skProc, skMethod, skConverter, skIterator}: diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 4d3b6d038..20b5071ac 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -51,9 +51,10 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode = var i = 0 a = initOverloadIter(o, c, n) while a != nil: + if a.kind != skModule: + inc(i) + if i > 1: break a = nextOverloadIter(o, c, n) - inc(i) - if i > 1: break if i <= 1 and r != scForceOpen: # XXX this makes more sense but breaks bootstrapping for now: # (s.kind notin routineKinds or s.magic != mNone): @@ -68,8 +69,9 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode = result = newNodeIT(kind, n.info, newTypeS(tyNone, c)) a = initOverloadIter(o, c, n) while a != nil: - incl(a.flags, sfUsed) - addSon(result, newSymNode(a, n.info)) + if a.kind != skModule: + incl(a.flags, sfUsed) + addSon(result, newSymNode(a, n.info)) a = nextOverloadIter(o, c, n) proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode = diff --git a/compiler/trees.nim b/compiler/trees.nim index 659df334b..fdd88c348 100644 --- a/compiler/trees.nim +++ b/compiler/trees.nim @@ -103,14 +103,16 @@ proc getMagic*(op: PNode): TMagic = else: result = mNone else: result = mNone -proc treeToSym*(t: PNode): PSym = - result = t.sym - proc isConstExpr*(n: PNode): bool = result = (n.kind in {nkCharLit..nkInt64Lit, nkStrLit..nkTripleStrLit, nkFloatLit..nkFloat64Lit, nkNilLit}) or (nfAllConst in n.flags) +proc isCaseObj*(n: PNode): bool = + if n.kind == nkRecCase: return true + for i in 0..<safeLen(n): + if n[i].isCaseObj: return true + proc isDeepConstExpr*(n: PNode): bool = case n.kind of nkCharLit..nkInt64Lit, nkStrLit..nkTripleStrLit, @@ -119,11 +121,14 @@ proc isDeepConstExpr*(n: PNode): bool = of nkExprEqExpr, nkExprColonExpr, nkHiddenStdConv, nkHiddenSubConv: result = isDeepConstExpr(n.sons[1]) of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure: - for i in 0 .. <n.len: + for i in ord(n.kind == nkObjConstr) .. <n.len: if not isDeepConstExpr(n.sons[i]): return false - # XXX once constant objects are supported by the codegen this needs to be - # weakened: - result = n.typ.isNil or n.typ.skipTypes({tyGenericInst, tyDistinct}).kind != tyObject + if n.typ.isNil: result = true + else: + let t = n.typ.skipTypes({tyGenericInst, tyDistinct}) + if t.kind in {tyRef, tyPtr}: return false + if t.kind != tyObject or not isCaseObj(t.n): + result = true else: discard proc flattenTreeAux(d, a: PNode, op: TMagic) = diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index 18c5ae832..7dbf6f801 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -85,6 +85,17 @@ proc mapTypeToBracketX(name: string; m: TMagic; t: PType; info: TLineInfo; else: result.add mapTypeToAstX(t.sons[i], info, inst) +proc objectNode(n: PNode): PNode = + if n.kind == nkSym: + result = newNodeI(nkIdentDefs, n.info) + result.add n # name + result.add mapTypeToAstX(n.sym.typ, n.info, true, false) # type + result.add ast.emptyNode # no assigned value + else: + result = copyNode(n) + for i in 0 ..< n.safeLen: + result.add objectNode(n[i]) + proc mapTypeToAstX(t: PType; info: TLineInfo; inst=false; allowRecursionX=false): PNode = var allowRecursion = allowRecursionX @@ -167,7 +178,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo; result = newNodeX(nkDistinctTy) result.add mapTypeToAst(t.sons[0], info) else: - if allowRecursion or t.sym==nil: + if allowRecursion or t.sym == nil: result = mapTypeToBracket("distinct", mDistinct, t, info) else: result = atomicType(t.sym.name.s, t.sym.magic) @@ -177,16 +188,13 @@ proc mapTypeToAstX(t: PType; info: TLineInfo; if inst: result = newNodeX(nkObjectTy) result.add ast.emptyNode # pragmas not reconstructed yet - if t.sons[0]==nil: result.add ast.emptyNode # handle parent object + if t.sons[0] == nil: result.add ast.emptyNode # handle parent object else: var nn = newNodeX(nkOfInherit) nn.add mapTypeToAst(t.sons[0], info) result.add nn - if t.n.sons.len>0: - var rl = copyNode(t.n) # handle nkRecList - for s in t.n.sons: - rl.add newIdentDefs(s) - result.add rl + if t.n.len > 0: + result.add objectNode(t.n) else: result.add ast.emptyNode else: diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 366662258..61ab65360 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -664,8 +664,7 @@ proc genNarrowU(c: PCtx; n: PNode; dest: TDest) = let t = skipTypes(n.typ, abstractVar-{tyTypeDesc}) # uint is uint64 in the VM, we we only need to mask the result for # other unsigned types: - if t.kind in {tyUInt8..tyUInt32, tyInt8..tyInt32} or - (t.kind == tyInt and t.size == 4): + if t.kind in {tyUInt8..tyUInt32, tyInt8..tyInt32}: c.gABC(n, opcNarrowU, dest, TRegister(t.size*8)) proc genBinaryABCnarrow(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) = |