diff options
author | Araq <rumpf_a@web.de> | 2012-03-16 19:33:24 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-03-16 19:33:24 +0100 |
commit | be1154106a81207dfaf383afc25bfa0e2efb90c7 (patch) | |
tree | 981fc574252d4b7dde5f8884b7376497ccb8fde3 | |
parent | 4da067691eb61554515197fa79392b1509c2e566 (diff) | |
download | Nim-be1154106a81207dfaf383afc25bfa0e2efb90c7.tar.gz |
clean separation of PNimrodNode and tyExpr
-rwxr-xr-x | compiler/sem.nim | 4 | ||||
-rwxr-xr-x | compiler/seminst.nim | 5 | ||||
-rwxr-xr-x | compiler/semstmts.nim | 16 | ||||
-rwxr-xr-x | compiler/semtypes.nim | 18 | ||||
-rwxr-xr-x | lib/core/macros.nim | 4 | ||||
-rwxr-xr-x | lib/system.nim | 5 | ||||
-rwxr-xr-x | todo.txt | 2 |
7 files changed, 32 insertions, 22 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index 1bc2cee09..1c1b4351d 100755 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -31,8 +31,8 @@ proc semLambda(c: PContext, n: PNode): PNode proc semTypeNode(c: PContext, n: PNode, prev: PType): PType proc semStmt(c: PContext, n: PNode): PNode proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) -proc addParams(c: PContext, n: PNode) -proc addResult(c: PContext, t: PType, info: TLineInfo) +proc addParams(c: PContext, n: PNode, kind: TSymKind) +proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) proc addResultNode(c: PContext, n: PNode) proc instGenericContainer(c: PContext, n: PNode, header: PType): PType diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 503b3c7f6..1da6a671f 100755 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -75,7 +75,7 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) = addDecl(c, result) pushProcCon(c, result) if result.kind in {skProc, skMethod, skConverter}: - addResult(c, result.typ.sons[0], n.info) + addResult(c, result.typ.sons[0], n.info, result.kind) addResultNode(c, n) var b = semStmtScope(c, n.sons[bodyPos]) # XXX Bad hack for tests/titer2 and tests/tactiontable @@ -92,7 +92,8 @@ proc fixupInstantiatedSymbols(c: PContext, s: PSym) = openScope(c.tab) var n = oldPrc.ast n.sons[bodyPos] = copyTree(s.getBody) - if n.sons[paramsPos].kind != nkEmpty: addParams(c, oldPrc.typ.n) + if n.sons[paramsPos].kind != nkEmpty: + addParams(c, oldPrc.typ.n, oldPrc.kind) instantiateBody(c, n, oldPrc) closeScope(c.tab) popInfoContext() diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 8b758d9f7..5b4639f26 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -599,12 +599,12 @@ proc SemTypeSection(c: PContext, n: PNode): PNode = result = n proc semParamList(c: PContext, n, genericParams: PNode, s: PSym) = - s.typ = semProcTypeNode(c, n, genericParams, nil) + s.typ = semProcTypeNode(c, n, genericParams, nil, s.kind) -proc addParams(c: PContext, n: PNode) = +proc addParams(c: PContext, n: PNode, kind: TSymKind) = for i in countup(1, sonsLen(n)-1): if (n.sons[i].kind != nkSym): InternalError(n.info, "addParams") - addDecl(c, n.sons[i].sym) + addParamOrResult(c, n.sons[i].sym, kind) proc semBorrow(c: PContext, n: PNode, s: PSym) = # search for the correct alias: @@ -615,13 +615,13 @@ proc semBorrow(c: PContext, n: PNode, s: PSym) = else: LocalError(n.info, errNoSymbolToBorrowFromFound) -proc addResult(c: PContext, t: PType, info: TLineInfo) = +proc addResult(c: PContext, t: PType, info: TLineInfo, owner: TSymKind) = if t != nil: var s = newSym(skResult, getIdent"result", getCurrOwner()) s.info = info s.typ = t incl(s.flags, sfUsed) - addDecl(c, s) + addParamOrResult(c, s, owner) c.p.resultSym = s proc addResultNode(c: PContext, n: PNode) = @@ -653,7 +653,7 @@ proc semLambda(c: PContext, n: PNode): PNode = if sfImportc in s.flags: LocalError(n.sons[bodyPos].info, errImplOfXNotAllowed, s.name.s) pushProcCon(c, s) - addResult(c, s.typ.sons[0], n.info) + addResult(c, s.typ.sons[0], n.info, skProc) n.sons[bodyPos] = semStmtScope(c, n.sons[bodyPos]) addResultNode(c, n) popProcCon(c) @@ -717,7 +717,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, openScope(c.tab) # open scope for old (correct) parameter symbols if proto.ast.sons[genericParamsPos].kind != nkEmpty: addGenericParamListToScope(c, proto.ast.sons[genericParamsPos]) - addParams(c, proto.typ.n) + addParams(c, proto.typ.n, proto.kind) proto.info = s.info # more accurate line information s.typ = proto.typ s = proto @@ -737,7 +737,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, ParamsTypeCheck(c, s.typ) pushProcCon(c, s) if s.typ.sons[0] != nil and kind != skIterator: - addResult(c, s.typ.sons[0], n.info) + addResult(c, s.typ.sons[0], n.info, kind) if sfImportc notin s.flags: # no semantic checking for importc: n.sons[bodyPos] = semStmtScope(c, n.sons[bodyPos]) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 5a1fc004d..cec3a9f7e 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -510,9 +510,18 @@ proc paramType(c: PContext, n, genericParams: PNode, cl: var TIntSet): PType = if genericParams != nil and sonsLen(genericParams) == 0: result = addTypeVarsOfGenericBody(c, result, genericParams, cl) +proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) = + if kind == skMacro and param.typ.kind in {tyTypeDesc, tyExpr, tyStmt}: + let nn = getSysSym"PNimrodNode" + var a = copySym(param) + a.typ = nn.typ + addDecl(c, a) + else: + addDecl(c, param) + proc semProcTypeNode(c: PContext, n, genericParams: PNode, - prev: PType): PType = - var + prev: PType, kind: TSymKind): PType = + var def, res: PNode typ: PType cl: TIntSet @@ -568,7 +577,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s) addSon(result.n, newSymNode(arg)) addSon(result, typ) - addDecl(c, arg) + addParamOrResult(c, arg, kind) if n.sons[0].kind != nkEmpty: var r = paramType(c, n.sons[0], genericParams, cl) @@ -717,7 +726,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of nkProcTy: checkSonsLen(n, 2) openScope(c.tab) - result = semProcTypeNode(c, n.sons[0], nil, prev) + result = semProcTypeNode(c, n.sons[0], nil, prev, skProc) # dummy symbol for `pragma`: var s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c) s.typ = result @@ -769,6 +778,7 @@ proc processMagicType(c: PContext, m: PSym) = of mSet: setMagicType(m, tySet, 0) of mSeq: setMagicType(m, tySequence, 0) of mOrdinal: setMagicType(m, tyOrdinal, 0) + of mPNimrodNode: nil else: GlobalError(m.info, errTypeExpected) proc newConstraint(c: PContext, k: TTypeKind): PType = diff --git a/lib/core/macros.nim b/lib/core/macros.nim index b6b9174cd..1fb012a28 100755 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -87,10 +87,6 @@ type ## represents a Nimrod *symbol* in the compiler; a *symbol* is a looked-up ## *ident*. - TNimrodNode {.final.} = object - PNimrodNode* {.magic: "PNimrodNode".} = ref TNimrodNode - ## represents a Nimrod AST node. Macros operate on this type. - const nnkLiterals* = {nnkCharLit..nnkNilLit} nnkCallKinds* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand, diff --git a/lib/system.nim b/lib/system.nim index c92c86443..2644d6fbb 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -2220,6 +2220,11 @@ proc shallow*(s: var string) {.noSideEffect, inline.} = # const res = e # res +type + TNimrodNode {.final.} = object + PNimrodNode* {.magic: "PNimrodNode".} = ref TNimrodNode + ## represents a Nimrod AST node. Macros operate on this type. + template eval*(blk: stmt): stmt = ## executes a block of code at compile time just as if it was a macro ## optonally, the block can return an AST tree that will replace the diff --git a/todo.txt b/todo.txt index 47c2cf570..a3d1cd2b7 100755 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,6 @@ version 0.9.0 ============= -- clean separation between tyExpr and PNimrodNode - - ``=`` should be overloadable; requires specialization for ``=`` - fix remaining generics bugs - fix remaining closure bugs: |