diff options
Diffstat (limited to 'rod')
-rwxr-xr-x | rod/interact.nim | 15 | ||||
-rwxr-xr-x | rod/main.nim | 2 | ||||
-rwxr-xr-x | rod/msgs.nim | 27 | ||||
-rwxr-xr-x | rod/passaux.nim | 15 | ||||
-rwxr-xr-x | rod/semexprs.nim | 3 | ||||
-rwxr-xr-x | rod/seminst.nim | 17 | ||||
-rwxr-xr-x | rod/semtypes.nim | 7 | ||||
-rwxr-xr-x | rod/webrepl.nim | 71 |
8 files changed, 46 insertions, 111 deletions
diff --git a/rod/interact.nim b/rod/interact.nim deleted file mode 100755 index 36fee8413..000000000 --- a/rod/interact.nim +++ /dev/null @@ -1,15 +0,0 @@ -# -# -# The Nimrod Compiler -# (c) Copyright 2008 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# - -# This file implements interactive sessions. - -import - llstream, strutils, ropes, nstrtabs, msgs - -# implementation diff --git a/rod/main.nim b/rod/main.nim index 2ec65be58..977a4ff1b 100755 --- a/rod/main.nim +++ b/rod/main.nim @@ -15,7 +15,7 @@ import os, lists, condsyms, rodread, rodwrite, ropes, trees, wordrecg, sem, semdata, idents, passes, docgen, extccomp, cgen, ecmasgen, - platform, interact, nimconf, importer, passaux, depends, transf, evals, types + platform, nimconf, importer, passaux, depends, transf, evals, types const has_LLVM_Backend = false diff --git a/rod/msgs.nim b/rod/msgs.nim index dd60c4cae..96ad42923 100755 --- a/rod/msgs.nim +++ b/rod/msgs.nim @@ -412,8 +412,7 @@ proc includeFilename*(f: string): int = if filenames[i] == f: return i result = len(filenames) - setlen(filenames, result + 1) - filenames[result] = f + filenames.add(f) proc newLineInfo*(filename: string, line, col: int): TLineInfo = result.fileIndex = includeFilename(filename) @@ -421,7 +420,7 @@ proc newLineInfo*(filename: string, line, col: int): TLineInfo = result.col = int16(col) proc ToFilename*(info: TLineInfo): string = - if info.fileIndex == - 1: result = "???" + if info.fileIndex < 0: result = "???" else: result = filenames[info.fileIndex] proc ToLinenumber*(info: TLineInfo): int {.inline.} = @@ -456,7 +455,7 @@ proc MsgKindToString*(kind: TMsgKind): string = result = msgKindToStr[kind] proc getMessageStr(msg: TMsgKind, arg: string): string = - result = `%`(msgKindToString(msg), [arg]) + result = msgKindToString(msg) % [arg] type TCheckPointResult* = enum @@ -489,19 +488,17 @@ proc handleError(msg: TMsgKind, eh: TErrorHandling) = elif eh == doRaise: raiseRecoverableError() -proc sameLineInfo(a, b: TLineInfo): bool = - result = (a.line == b.line) and (a.fileIndex == b.fileIndex) +proc `==`(a, b: TLineInfo): bool = + result = a.line == b.line and a.fileIndex == b.fileIndex proc writeContext(lastinfo: TLineInfo) = - var info: TLineInfo - info = lastInfo + var info = lastInfo for i in countup(0, len(msgContext) - 1): - if not sameLineInfo(msgContext[i], lastInfo) and - not sameLineInfo(msgContext[i], info): - MsgWriteln(`%`(posErrorFormat, [toFilename(msgContext[i]), - coordToStr(msgContext[i].line), - coordToStr(msgContext[i].col), - getMessageStr(errInstantiationFrom, "")])) + if msgContext[i] != lastInfo and msgContext[i] != info: + MsgWriteln(posErrorFormat % [toFilename(msgContext[i]), + coordToStr(msgContext[i].line), + coordToStr(msgContext[i].col), + getMessageStr(errInstantiationFrom, "")]) info = msgContext[i] proc rawMessage*(msg: TMsgKind, args: openarray[string]) = @@ -539,7 +536,7 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string, frmt = posErrorFormat # we try to filter error messages so that not two error message # in the same file and line are produced: - ignoreMsg = sameLineInfo(lastError, info) + ignoreMsg = lastError == info lastError = info of warnMin..warnMax: ignoreMsg = optWarns notin gOptions or msg notin gNotes diff --git a/rod/passaux.nim b/rod/passaux.nim index 5df37c095..a57963c06 100755 --- a/rod/passaux.nim +++ b/rod/passaux.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -# implements some little helper passes +## implements some little helper passes import strutils, ast, astalgo, passes, msgs, options @@ -20,7 +20,11 @@ proc verboseOpen(s: PSym, filename: string): PPassContext = proc verboseProcess(context: PPassContext, n: PNode): PNode = result = n if context != nil: InternalError("logpass: context is not nil") - if gVerbosity == 3: Message(n.info, hintProcessing, $ast.gid) + if gVerbosity == 3: + # system.nim deactivates all hints, for verbosity:3 we want the processing + # messages nonetheless, so we activate them again unconditionally: + incl(msgs.gNotes, hintProcessing) + Message(n.info, hintProcessing, $ast.gid) proc verbosePass*(): TPass = initPass(result) @@ -28,7 +32,6 @@ proc verbosePass*(): TPass = result.process = verboseProcess proc cleanUp(c: PPassContext, n: PNode): PNode = - var s: PSym result = n # we cannot clean up if dead code elimination is activated if optDeadCodeElim in gGlobalOptions: return @@ -36,9 +39,9 @@ proc cleanUp(c: PPassContext, n: PNode): PNode = of nkStmtList: for i in countup(0, sonsLen(n) - 1): discard cleanup(c, n.sons[i]) of nkProcDef, nkMethodDef: - if (n.sons[namePos].kind == nkSym): - s = n.sons[namePos].sym - if not (sfDeadCodeElim in getModule(s).flags) and not astNeeded(s): + if n.sons[namePos].kind == nkSym: + var s = n.sons[namePos].sym + if sfDeadCodeElim notin getModule(s).flags and not astNeeded(s): s.ast.sons[codePos] = ast.emptyNode # free the memory else: nil diff --git a/rod/semexprs.nim b/rod/semexprs.nim index 7e46c69cd..1d20e5253 100755 --- a/rod/semexprs.nim +++ b/rod/semexprs.nim @@ -398,7 +398,8 @@ proc analyseIfAddressTakenInCall(c: PContext, n: PNode) = if (n.sons[0].kind == nkSym) and (n.sons[0].sym.magic in FakeVarParams): # BUGFIX: check for L-Value still needs to be done for the arguments! for i in countup(1, sonsLen(n) - 1): - if i < sonsLen(t) and skipTypes(t.sons[i], abstractInst).kind == tyVar: + if i < sonsLen(t) and t.sons[i] != nil and + skipTypes(t.sons[i], abstractInst).kind == tyVar: if isAssignable(n.sons[i]) != arLValue: LocalError(n.sons[i].info, errVarForOutParamNeeded) return diff --git a/rod/seminst.nim b/rod/seminst.nim index 3cd86b904..2f26026ad 100755 --- a/rod/seminst.nim +++ b/rod/seminst.nim @@ -47,6 +47,22 @@ proc GenericCacheAdd(c: PContext, genericSym, instSym: PSym) = addSon(n, newSymNode(instSym)) addSon(c.generics, n) +proc removeDefaultParamValues(n: PNode) = + # we remove default params, because they cannot be instantiated properly + # and they are not needed anyway for instantiation (each param is already + # provided). + when false: + for i in countup(1, sonsLen(n)-1): + var a = n.sons[i] + if a.kind != nkIdentDefs: IllFormedAst(a) + var L = a.len + if a.sons[L-1].kind != nkEmpty and a.sons[L-2].kind != nkEmpty: + # ``param: typ = defaultVal``. + # We don't need defaultVal for semantic checking and it's wrong for + # ``cmp: proc (a, b: T): int = cmp``. Hm, for ``cmp = cmp`` that is + # not possible... XXX We don't solve this issue here. + a.sons[L-1] = ast.emptyNode + proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, info: TLineInfo): PSym = # generates an instantiated proc @@ -76,6 +92,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, n.sons[genericParamsPos] = ast.emptyNode # semantic checking for the parameters: if n.sons[paramsPos].kind != nkEmpty: + removeDefaultParamValues(n.sons[ParamsPos]) semParamList(c, n.sons[ParamsPos], nil, result) addParams(c, result.typ.n) else: diff --git a/rod/semtypes.nim b/rod/semtypes.nim index 991a75792..4a676e00a 100755 --- a/rod/semtypes.nim +++ b/rod/semtypes.nim @@ -11,7 +11,9 @@ proc fitNode(c: PContext, formal: PType, arg: PNode): PNode = result = IndexTypesMatch(c, formal, arg.typ, arg) - if result == nil: typeMismatch(arg, formal, arg.typ) + if result == nil: + #debug(arg) + typeMismatch(arg, formal, arg.typ) proc newOrPrevType(kind: TTypeKind, prev: PType, c: PContext): PType = if prev == nil: @@ -518,7 +520,8 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, # check type compability between def.typ and typ: if typ == nil: typ = def.typ - elif def != nil and def.typ != nil and def.typ.kind != tyNone: + elif def != nil: + # and def.typ != nil and def.typ.kind != tyNone: # example code that triggers it: # proc sort[T](cmp: proc(a, b: T): int = cmp) def = fitNode(c, typ, def) diff --git a/rod/webrepl.nim b/rod/webrepl.nim deleted file mode 100755 index bf59bbfec..000000000 --- a/rod/webrepl.nim +++ /dev/null @@ -1,71 +0,0 @@ -# -# -# The Nimrod Compiler -# (c) Copyright 2010 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# - -## Creates a server, opens a browser and starts serving a Repl for the user. -## Unfortunately it doesn't ever stop... - -import httpserver, sockets, browsers, strutils, cgi, options - -const - gui = """ -<html> - <head> - <title>Nimrod Interactive Web Console</title> - </head> - - <body> - <form action="exec" method="get"> - <input type="submit" value="Run" /><br /> - <textarea name="code" cols="80" rows="30">import strutils, os - -# your code here</textarea> - <table border="0"> - <tr> - <td><input type="checkbox" name="objChecks" checked="true" - value="on">objChecks</input></td> - <td><input type="checkbox" name="fieldChecks" checked="true" - value="on">fieldChecks</input></td> - <td><input type="checkbox" name="rangeChecks" checked="true" - value="on">rangeChecks</input></td> - </tr><tr> - <td><input type="checkbox" name="boundChecks" checked="true" - value="on">boundChecks</input></td> - <td><input type="checkbox" name="overflowChecks" checked="true" - value="on">overflowChecks</input></td> - <td><input type="checkbox" name="nanChecks" checked="true" - value="on">nanChecks</input></td> - </tr><tr> - <td><input type="checkbox" name="infChecks" checked="true" - value="on">infChecks</input></td> - <td><input type="checkbox" name="assertions" checked="true" - value="on">assertions</input></td> - </tr> - </table> - </form> - $1 - </body> -</html> -""" - -proc runCode(input: string): string = - nil - -proc handleRequest(client: TSocket, path, query: string) = - var output = query - client.send(gui % output & wwwNL) - - -var s: TServer -open(s, TPort(0)) -browsers.openDefaultBrowser("http://localhost:" & $s.port) -while true: - next(s) - handleRequest(s.client, s.path, s.query) - close(s.client) -close(s) |