diff --git a/compiler/renderer.nim b/compiler/renderer.nim index f6fb0f8c0b..c8fe70e028 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -557,7 +557,7 @@ proc longMode(n: PNode, start: int = 0, theEnd: int = - 1): bool = proc gstmts(g: var TSrcGen, n: PNode, c: TContext) = if n.kind == nkEmpty: return - if (n.kind == nkStmtList) or (n.kind == nkStmtListExpr): + if n.kind in {nkStmtList, nkStmtListExpr, nkStmtListType}: indentNL(g) for i in countup(0, sonsLen(n) - 1): optNL(g) @@ -1069,7 +1069,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = put(g, tkSpaces, Space) putWithSpace(g, tkEquals, "=") gsub(g, n.sons[1]) - of nkStmtList, nkStmtListExpr: gstmts(g, n, emptyContext) + of nkStmtList, nkStmtListExpr, nkStmtListType: gstmts(g, n, emptyContext) of nkIfStmt: putWithSpace(g, tkIf, "if") gif(g, n) @@ -1246,8 +1246,12 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = put(g, tkBracketLe, "[") gcomma(g, n) put(g, tkBracketRi, "]") + of nkMetaNode: + put(g, tkParLe, "(META|") + gsub(g, n.sons[0]) + put(g, tkParRi, ")") else: - #nkNone, nkMetaNode, nkExplicitTypeListCall: + #nkNone, nkExplicitTypeListCall: InternalError(n.info, "rnimsyn.gsub(" & $n.kind & ')') proc renderTree(n: PNode, renderFlags: TRenderFlags = {}): string = diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index a5f763519c..aab4c82f53 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -51,7 +51,9 @@ proc semTypeTraits(c: PContext, n: PNode): PNode = checkMinSonsLen(n, 2) let t = n.sons[1].typ internalAssert t != nil - if not containsGenericType(t): + if t.kind == tyTypeDesc and t.len == 0: + result = n + elif not containsGenericType(t): result = evalTypeTrait(n[0], t, GetCurrOwner()) else: # a typedesc variable, pass unmodified to evals diff --git a/compiler/vm.nim b/compiler/vm.nim index 984cc4bb81..ef83860f75 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1027,6 +1027,9 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode = if c.code[pc].opcode in {opcWrGlobal, opcWrGlobalRef} and c.code[pc].regBx == rb: break + of opcGlobalAlias: + let rb = instr.regBx - wordExcess - 1 + regs[ra] = c.globals.sons[rb] inc pc proc fixType(result, n: PNode) {.inline.} = @@ -1135,11 +1138,14 @@ proc evalMacroCall*(module: PSym, n, nOrig: PNode, sym: PSym): PNode = # setup arguments: var L = n.safeLen if L == 0: L = 1 - InternalAssert tos.slots.len >= L + # This is wrong for tests/reject/tind1.nim where the passed 'else' part + # doesn't end up in the parameter: + #InternalAssert tos.slots.len >= L # return value: tos.slots[0] = newNodeIT(nkNilLit, n.info, sym.typ.sons[0]) # setup parameters: - for i in 1 .. < L: tos.slots[i] = setupMacroParam(n.sons[i]) + for i in 1 .. < min(tos.slots.len, L): + tos.slots[i] = setupMacroParam(n.sons[i]) # temporary storage: for i in L .. = slotSomeTemp: c.slots[r].inUse = false @@ -929,7 +944,7 @@ proc cannotEval(n: PNode) {.noinline.} = n.renderTree) proc genGlobalInit(c: PCtx; n: PNode; s: PSym) = - c.globals.add(emptyNode) + c.globals.add(emptyNode.copyNode) s.position = c.globals.len # This is rather hard to support, due to the laziness of the VM code # generator. See tests/compile/tmacro2 for why this is necesary: @@ -946,11 +961,14 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest) = discard else: cannotEval(n) - if dest < 0: dest = c.getTemp(s.typ) if s.position == 0: if sfImportc in s.flags: c.importcSym(n.info, s) else: genGlobalInit(c, n, s) - c.gABx(n, opcLdGlobal, dest, s.position) + if dest < 0: + dest = c.getGlobalSlot(n, s) + #c.gABx(n, opcAliasGlobal, dest, s.position) + else: + c.gABx(n, opcLdGlobal, dest, s.position) else: if s.position > 0 or (s.position == 0 and s.kind in {skParam, skResult}): if dest < 0: diff --git a/tests/compile/tmacro2.nim b/tests/compile/tmacro2.nim index e7bc648dbe..39324e497d 100644 --- a/tests/compile/tmacro2.nim +++ b/tests/compile/tmacro2.nim @@ -26,7 +26,7 @@ macro importImpl_forward(name, returns): stmt {.immediate.} = p2.add newIdentNode("errors") p2.add newNimNode(nnkVarTy) p2.add newNimNode(nnkEmpty) - p2[1].add newNimNOde(nnkBracketExpr) + p2[1].add newNimNode(nnkBracketExpr) p2[1][0].add newIdentNode("seq") p2[1][0].add newIdentNode("string") res[3].add p2 diff --git a/tests/reject/twrongiter.nim b/tests/reject/twrongiter.nim index 2d2502a6a9..33394219ba 100644 --- a/tests/reject/twrongiter.nim +++ b/tests/reject/twrongiter.nim @@ -1,5 +1,5 @@ discard """ -line: 14 +line: 12 errormsg: "type mismatch" """