diff options
author | Araq <rumpf_a@web.de> | 2012-07-16 23:00:57 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-07-16 23:00:57 +0200 |
commit | 8d99753d6320489e4de8cf186415b0a7be8260b4 (patch) | |
tree | 2008a25dac1df222efc2c205fdf772ba5a533ecc /compiler | |
parent | 56b4e3ad91a0dda632ba6bab7139665a3da163d3 (diff) | |
download | Nim-8d99753d6320489e4de8cf186415b0a7be8260b4.tar.gz |
preparations for making 'closure' the default calling convention for proc types
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/astalgo.nim | 5 | ||||
-rwxr-xr-x | compiler/lists.nim | 2 | ||||
-rwxr-xr-x | compiler/msgs.nim | 6 | ||||
-rwxr-xr-x | compiler/parser.nim | 2 | ||||
-rwxr-xr-x | compiler/passes.nim | 12 | ||||
-rwxr-xr-x | compiler/semdata.nim | 6 | ||||
-rwxr-xr-x | compiler/semstmts.nim | 2 | ||||
-rwxr-xr-x | compiler/semtypes.nim | 11 | ||||
-rwxr-xr-x | compiler/sigmatch.nim | 4 | ||||
-rwxr-xr-x | compiler/transf.nim | 8 | ||||
-rwxr-xr-x | compiler/types.nim | 6 |
11 files changed, 32 insertions, 32 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim index a8fc9c8f6..2e75c7787 100755 --- a/compiler/astalgo.nim +++ b/compiler/astalgo.nim @@ -35,9 +35,10 @@ proc ObjectSetContainsOrIncl*(t: var TObjectSet, obj: PObject): bool proc TablePut*(t: var TTable, key, val: PObject) proc TableGet*(t: TTable, key: PObject): PObject type - TCmpProc* = proc (key, closure: PObject): bool # should return true if found + TCmpProc* = proc (key, closure: PObject): bool {.nimcall.} # true if found -proc TableSearch*(t: TTable, key, closure: PObject, comparator: TCmpProc): PObject +proc TableSearch*(t: TTable, key, closure: PObject, + comparator: TCmpProc): PObject # return val as soon as comparator returns true; if this never happens, # nil is returned diff --git a/compiler/lists.nim b/compiler/lists.nim index 6a1f6c650..1998581ce 100755 --- a/compiler/lists.nim +++ b/compiler/lists.nim @@ -22,7 +22,7 @@ type head*, tail*: PListEntry Counter*: int - TCompareProc* = proc (entry: PListEntry, closure: Pointer): bool + TCompareProc* = proc (entry: PListEntry, closure: Pointer): bool {.nimcall.} proc InitLinkedList*(list: var TLinkedList) = list.Counter = 0 diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 03ee28df3..a661da0e1 100755 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -102,7 +102,7 @@ type warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel, warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored, warnXisPassedToProcVar, warnAnalysisLoophole, - warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitNarrowing, + warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure, warnUser, hintSuccess, hintSuccessX, hintLineTooLong, hintXDeclaredButNotUsed, hintConvToBaseNotNeeded, @@ -345,7 +345,7 @@ const warnAnalysisLoophole: "thread analysis incomplete due to unkown call '$1' [AnalysisLoophole]", warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]", warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]", - warnImplicitNarrowing: "implicit narrowing conversion: '$1' [ImplicitNarrowing]", + warnImplicitClosure: "implicit closure convention: '$1' [ImplicitClosure]", warnUser: "$1 [User]", hintSuccess: "operation successful [Success]", hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#) [SuccessX]", @@ -370,7 +370,7 @@ const "RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported", "CommentXIgnored", "XisPassedToProcVar", "AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap", - "ImplicitNarrowing,", "User"] + "ImplicitClosure,", "User"] HintsToStr*: array[0..13, string] = ["Success", "SuccessX", "LineTooLong", "XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded", diff --git a/compiler/parser.nim b/compiler/parser.nim index 26ffaf59c..7f11ddb2b 100755 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1164,7 +1164,7 @@ proc newCommentStmt(p: var TParser): PNode = result.info.line = result.info.line - int16(1) type - TDefParser = proc (p: var TParser): PNode + TDefParser = proc (p: var TParser): PNode {.nimcall.} proc parseSection(p: var TParser, kind: TNodeKind, defparser: TDefParser): PNode = diff --git a/compiler/passes.nim b/compiler/passes.nim index 24659fc4e..bedcbb16e 100755 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -26,11 +26,11 @@ type PPassContext* = ref TPassContext TPass* = tuple[ - open: proc (module: PSym, filename: string): PPassContext, + open: proc (module: PSym, filename: string): PPassContext {.nimcall.}, openCached: proc (module: PSym, filename: string, - rd: PRodReader): PPassContext, - close: proc (p: PPassContext, n: PNode): PNode, - process: proc (p: PPassContext, topLevelStmt: PNode): PNode] + rd: PRodReader): PPassContext {.nimcall.}, + close: proc (p: PPassContext, n: PNode): PNode {.nimcall.}, + process: proc (p: PPassContext, topLevelStmt: PNode): PNode {.nimcall.}] # a pass is a tuple of procedure vars ``TPass.close`` may produce additional # nodes. These are passed to the other close procedures. @@ -47,8 +47,8 @@ proc processModule*(module: PSym, filename: string, stream: PLLStream, # the semantic checker needs these: var - gImportModule*: proc (filename: string): PSym - gIncludeFile*: proc (filename: string): PNode + gImportModule*: proc (filename: string): PSym {.nimcall.} + gIncludeFile*: proc (filename: string): PNode {.nimcall.} # implementation diff --git a/compiler/semdata.nim b/compiler/semdata.nim index b524881da..74e82db61 100755 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -66,9 +66,9 @@ type converters*: TSymSeq # sequence of converters optionStack*: TLinkedList libs*: TLinkedList # all libs used by this module - semConstExpr*: proc (c: PContext, n: PNode): PNode # for the pragmas - semExpr*: proc (c: PContext, n: PNode): PNode # for the pragmas - semConstBoolExpr*: proc (c: PContext, n: PNode): PNode # XXX bite the bullet + semConstExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # for the pragmas + semExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # for the pragmas + semConstBoolExpr*: proc (c: PContext, n: PNode): PNode {.nimcall.} # XXX bite the bullet includedFiles*: TIntSet # used to detect recursive include files filename*: string # the module's filename userPragmas*: TStrTable diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 7e265d95c..256d19db1 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -616,7 +616,7 @@ proc SemTypeSection(c: PContext, n: PNode): PNode = 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.kind) proc addParams(c: PContext, n: PNode, kind: TSymKind) = diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index d082f8bb9..e9cb8babb 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -566,7 +566,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, block addImplicitGeneric: # is this a bindOnce type class already present in the param list? for i in countup(0, genericParams.len - 1): - if genericParams.sons[i].sym.name == paramTypId: + if genericParams.sons[i].sym.name.id == paramTypId.id: result = genericParams.sons[i].typ break addImplicitGeneric @@ -800,7 +800,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of nkPtrTy: result = semAnyRef(c, n, tyPtr, prev) of nkVarTy: result = semVarType(c, n, prev) of nkDistinctTy: result = semDistinct(c, n, prev) - of nkProcTy: + of nkProcTy: if n.sonsLen == 0: return newConstraint(c, tyProc) checkSonsLen(n, 2) openScope(c.tab) @@ -808,7 +808,12 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = # dummy symbol for `pragma`: var s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c) s.typ = result - pragma(c, s, n.sons[1], procTypePragmas) + if n.sons[1].kind == nkEmpty or n.sons[1].len == 0: + if result.callConv == ccDefault: + #result.callConv = ccClosure + Message(n.info, warnImplicitClosure, renderTree(n)) + else: + pragma(c, s, n.sons[1], procTypePragmas) closeScope(c.tab) of nkEnumTy: result = semEnum(c, n, prev) of nkType: result = n.typ diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 1b60450bb..af924bafe 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -457,7 +457,9 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation = case a.kind of tyPointer: result = isEqual of tyNil: result = isSubtype - of tyPtr, tyProc, tyCString: result = isConvertible + of tyProc: + if a.callConv != ccClosure: result = isConvertible + of tyPtr, tyCString: result = isConvertible else: nil of tyString: case a.kind diff --git a/compiler/transf.nim b/compiler/transf.nim index 3c3ae12c9..4e799a11f 100755 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -640,14 +640,6 @@ proc dontInlineConstant(orig, cnst: PNode): bool {.inline.} = result = orig.kind == nkSym and cnst.kind in {nkCurly, nkPar, nkBracket} and cnst.len != 0 -proc warnNarrowingConversion(n: PNode) = - if n.kind == nkHiddenStdConv: - var dest = skipTypes(n.typ, abstractVarRange) - var source = skipTypes(n.sons[1].typ, abstractVarRange) - if source.kind == tyInt and - source.size > dest.size and n.sons[1].kind != nkIntLit: - Message(n.info, warnImplicitNarrowing, renderTree(n.sons[1])) - proc transform(c: PTransf, n: PNode): PTransNode = case n.kind of nkSym: diff --git a/compiler/types.nim b/compiler/types.nim index e2200882d..8b99c00e8 100755 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -24,9 +24,9 @@ proc getProcHeader*(sym: PSym): string proc base*(t: PType): PType # ------------------- type iterator: ---------------------------------------- type - TTypeIter* = proc (t: PType, closure: PObject): bool # should return true if the iteration should stop - TTypeMutator* = proc (t: PType, closure: PObject): PType # copy t and mutate it - TTypePredicate* = proc (t: PType): bool + TTypeIter* = proc (t: PType, closure: PObject): bool {.nimcall.} # true if iteration should stop + TTypeMutator* = proc (t: PType, closure: PObject): PType {.nimcall.} # copy t and mutate it + TTypePredicate* = proc (t: PType): bool {.nimcall.} proc IterOverType*(t: PType, iter: TTypeIter, closure: PObject): bool # Returns result of `iter`. |