diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/cgen.nim | 2 | ||||
-rw-r--r-- | compiler/charsets.nim | 49 | ||||
-rw-r--r-- | compiler/commands.nim | 22 | ||||
-rw-r--r-- | compiler/condsyms.nim | 1 | ||||
-rw-r--r-- | compiler/nversion.nim | 7 | ||||
-rw-r--r-- | compiler/options.nim | 2 | ||||
-rw-r--r-- | compiler/parsecfg.nim | 346 | ||||
-rw-r--r-- | compiler/pendx.nim | 18 | ||||
-rw-r--r-- | compiler/semtypes.nim | 13 | ||||
-rw-r--r-- | compiler/semtypinst.nim | 5 | ||||
-rw-r--r-- | compiler/syntaxes.nim | 2 | ||||
-rw-r--r-- | compiler/typesrenderer.nim | 8 |
12 files changed, 43 insertions, 432 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index f64ebacfb..8d66d7a3b 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -730,7 +730,7 @@ proc retIsNotVoid(s: PSym): bool = result = (s.typ.sons[0] != nil) and not isInvalidReturnType(s.typ.sons[0]) proc initFrame(p: BProc, procname, filename: PRope): PRope = - discard cgsym(p.module, "pushFrame") + discard cgsym(p.module, "nimFrame") if p.maxFrameLen > 0: discard cgsym(p.module, "TVarSlot") result = rfmt(nil, "\tnimfrs($1, $2, $3, $4)$N", diff --git a/compiler/charsets.nim b/compiler/charsets.nim deleted file mode 100644 index d3d00b687..000000000 --- a/compiler/charsets.nim +++ /dev/null @@ -1,49 +0,0 @@ -# -# -# The Nimrod Compiler -# (c) Copyright 2012 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# - -const - CharSize* = SizeOf(Char) - Lrz* = ' ' - Apo* = '\'' - Tabulator* = '\x09' - ESC* = '\x1B' - CR* = '\x0D' - FF* = '\x0C' - LF* = '\x0A' - BEL* = '\x07' - BACKSPACE* = '\x08' - VT* = '\x0B' - -when defined(macos): - DirSep == ':' - "\n" == CR & "" - FirstNLchar == CR - PathSep == ';' # XXX: is this correct? -else: - when defined(unix): - DirSep == '/' - "\n" == LF & "" - FirstNLchar == LF - PathSep == ':' - else: - # windows, dos - DirSep == '\\' - "\n" == CR + LF - FirstNLchar == CR - DriveSeparator == ':' - PathSep == ';' -UpLetters == {'A'..'Z', '\xC0'..'\xDE'} -DownLetters == {'a'..'z', '\xDF'..'\xFF'} -Numbers == {'0'..'9'} -Letters == UpLetters + DownLetters -type - TCharSet* = set[Char] - PCharSet* = ref TCharSet - -# implementation diff --git a/compiler/commands.nim b/compiler/commands.nim index 8339219ed..366019c19 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -50,11 +50,33 @@ proc writeAdvancedUsage(pass: TCmdLinePass) = CPU[platform.hostCPU].name]) & AdvancedUsage) quit(0) +template bootSwitch(name, expr, userString: expr): expr = + # Helper to build boot constants, for debugging you can 'echo' the else part. + const name = if expr: " " & userString else: "" + +bootSwitch(usedAvoidTimeMachine, noTimeMachine, "-d:avoidTimeMachine") +bootSwitch(usedRelease, defined(release), "-d:release") +bootSwitch(usedTinyC, hasTinyCBackend, "-d:tinyc") +bootSwitch(usedGnuReadline, defined(useGnuReadline), "-d:useGnuReadline") +bootSwitch(usedNativeStacktrace, + defined(nativeStackTrace) and nativeStackTraceSupported, + "-d:nativeStackTrace") +bootSwitch(usedNoCaas, defined(noCaas), "-d:noCaas") +bootSwitch(usedFFI, hasFFI, "-d:useFFI") +bootSwitch(usedBoehm, defined(boehmgc), "--gc:boehm") +bootSwitch(usedMarkAndSweep, defined(gcmarkandsweep), "--gc:markAndSweep") +bootSwitch(usedGenerational, defined(gcgenerational), "--gc:generational") +bootSwitch(usedNoGC, defined(nogc), "--gc:none") + + proc writeVersionInfo(pass: TCmdLinePass) = if pass == passCmd1: msgWriteln(`%`(HelpMessage, [VersionAsString, platform.OS[platform.hostOS].name, CPU[platform.hostCPU].name])) + msgWriteln("active boot switches:" & usedRelease & usedAvoidTimeMachine & + usedTinyC & usedGnuReadline & usedNativeStacktrace & usedNoCaas & + usedFFI & usedBoehm & usedMarkAndSweep & usedGenerational & usedNoGC) quit(0) var diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 4117fc461..17bb5db55 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -49,6 +49,7 @@ proc initDefines*() = defineSymbol("nimcomputedgoto") defineSymbol("nimunion") defineSymbol("nimnewshared") + defineSymbol("nimrequiresnimframe") # add platform specific symbols: case targetCPU diff --git a/compiler/nversion.nim b/compiler/nversion.nim index db38354ce..3c868ed2a 100644 --- a/compiler/nversion.nim +++ b/compiler/nversion.nim @@ -1,7 +1,7 @@ # # # The Nimrod Compiler -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2014 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -12,11 +12,10 @@ const MaxSetElements* = 1 shl 16 # (2^16) to support unicode character sets? - defaultAsmMarkerSymbol* = '!' VersionMajor* = 0 VersionMinor* = 9 - VersionPatch* = 3 + VersionPatch* = 5 VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch - RodFileVersion* = "1214" # modify this if the rod-format changes! + RodFileVersion* = "1215" # modify this if the rod-format changes! diff --git a/compiler/options.nim b/compiler/options.nim index 36d343d1b..58a340d21 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -16,7 +16,7 @@ const hasFFI* = defined(useFFI) newScopeForIf* = true useCaas* = not defined(noCaas) - noTimeMachine = defined(avoidTimeMachine) and defined(macosx) + noTimeMachine* = defined(avoidTimeMachine) and defined(macosx) type # please make sure we have under 32 options # (improves code efficiency a lot!) diff --git a/compiler/parsecfg.nim b/compiler/parsecfg.nim deleted file mode 100644 index e0d1afff1..000000000 --- a/compiler/parsecfg.nim +++ /dev/null @@ -1,346 +0,0 @@ -# -# -# Nimrod's Runtime Library -# (c) Copyright 2012 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# - -# A HIGH-PERFORMANCE configuration file parser; -# the Nimrod version of this file is part of the -# standard library. - -import - llstream, nhashes, strutils, nimlexbase - -type - TCfgEventKind* = enum - cfgEof, # end of file reached - cfgSectionStart, # a ``[section]`` has been parsed - cfgKeyValuePair, # a ``key=value`` pair has been detected - cfgOption, # a ``--key=value`` command line option - cfgError # an error ocurred during parsing; msg contains the - # error message - TCfgEvent* = object of TObject - case kind*: TCfgEventKind - of cfgEof: - nil - - of cfgSectionStart: - section*: string - - of cfgKeyValuePair, cfgOption: - key*, value*: string - - of cfgError: - msg*: string - - - TTokKind* = enum - tkInvalid, tkEof, # order is important here! - tkSymbol, tkEquals, tkColon, tkBracketLe, tkBracketRi, tkDashDash - TToken*{.final.} = object # a token - kind*: TTokKind # the type of the token - literal*: string # the parsed (string) literal - - TParserState* = enum - startState, commaState - TCfgParser* = object of TBaseLexer - tok*: TToken - state*: TParserState - filename*: string - - -proc Open*(c: var TCfgParser, filename: string, inputStream: PLLStream) -proc Close*(c: var TCfgParser) -proc next*(c: var TCfgParser): TCfgEvent -proc getColumn*(c: TCfgParser): int -proc getLine*(c: TCfgParser): int -proc getFilename*(c: TCfgParser): string -proc errorStr*(c: TCfgParser, msg: string): string -# implementation - -const - SymChars: TCharSet = {'a'..'z', 'A'..'Z', '0'..'9', '_', '\x80'..'\xFF'} # - # ---------------------------------------------------------------------------- - -proc rawGetTok(c: var TCfgParser, tok: var TToken) -proc open(c: var TCfgParser, filename: string, inputStream: PLLStream) = - openBaseLexer(c, inputStream) - c.filename = filename - c.state = startState - c.tok.kind = tkInvalid - c.tok.literal = "" - rawGetTok(c, c.tok) - -proc close(c: var TCfgParser) = - closeBaseLexer(c) - -proc getColumn(c: TCfgParser): int = - result = getColNumber(c, c.bufPos) - -proc getLine(c: TCfgParser): int = - result = c.linenumber - -proc getFilename(c: TCfgParser): string = - result = c.filename - -proc handleHexChar(c: var TCfgParser, xi: var int) = - case c.buf[c.bufpos] - of '0'..'9': - xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('0')) - inc(c.bufpos) - of 'a'..'f': - xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('a') + 10) - inc(c.bufpos) - of 'A'..'F': - xi = (xi shl 4) or (ord(c.buf[c.bufpos]) - ord('A') + 10) - inc(c.bufpos) - else: - nil - -proc handleDecChars(c: var TCfgParser, xi: var int) = - while c.buf[c.bufpos] in {'0'..'9'}: - xi = (xi * 10) + (ord(c.buf[c.bufpos]) - ord('0')) - inc(c.bufpos) - -proc getEscapedChar(c: var TCfgParser, tok: var TToken) = - var xi: int - inc(c.bufpos) # skip '\' - case c.buf[c.bufpos] - of 'n', 'N': - tok.literal = tok.literal & "\n" - Inc(c.bufpos) - of 'r', 'R', 'c', 'C': - add(tok.literal, CR) - Inc(c.bufpos) - of 'l', 'L': - add(tok.literal, LF) - Inc(c.bufpos) - of 'f', 'F': - add(tok.literal, FF) - inc(c.bufpos) - of 'e', 'E': - add(tok.literal, ESC) - Inc(c.bufpos) - of 'a', 'A': - add(tok.literal, BEL) - Inc(c.bufpos) - of 'b', 'B': - add(tok.literal, BACKSPACE) - Inc(c.bufpos) - of 'v', 'V': - add(tok.literal, VT) - Inc(c.bufpos) - of 't', 'T': - add(tok.literal, Tabulator) - Inc(c.bufpos) - of '\'', '\"': - add(tok.literal, c.buf[c.bufpos]) - Inc(c.bufpos) - of '\\': - add(tok.literal, '\\') - Inc(c.bufpos) - of 'x', 'X': - inc(c.bufpos) - xi = 0 - handleHexChar(c, xi) - handleHexChar(c, xi) - add(tok.literal, Chr(xi)) - of '0'..'9': - xi = 0 - handleDecChars(c, xi) - if (xi <= 255): add(tok.literal, Chr(xi)) - else: tok.kind = tkInvalid - else: tok.kind = tkInvalid - -proc HandleCRLF(c: var TCfgParser, pos: int): int = - case c.buf[pos] - of CR: result = lexbase.HandleCR(c, pos) - of LF: result = lexbase.HandleLF(c, pos) - else: result = pos - -proc getString(c: var TCfgParser, tok: var TToken, rawMode: bool) = - var - pos: int - ch: Char - buf: cstring - pos = c.bufPos + 1 # skip " - buf = c.buf # put `buf` in a register - tok.kind = tkSymbol - if (buf[pos] == '\"') and (buf[pos + 1] == '\"'): - # long string literal: - inc(pos, 2) # skip "" - # skip leading newline: - pos = HandleCRLF(c, pos) - buf = c.buf - while true: - case buf[pos] - of '\"': - if (buf[pos + 1] == '\"') and (buf[pos + 2] == '\"'): break - add(tok.literal, '\"') - Inc(pos) - of CR, LF: - pos = HandleCRLF(c, pos) - buf = c.buf - tok.literal = tok.literal & "\n" - of lexbase.EndOfFile: - tok.kind = tkInvalid - break - else: - add(tok.literal, buf[pos]) - Inc(pos) - c.bufpos = pos + - 3 # skip the three """ - else: - # ordinary string literal - while true: - ch = buf[pos] - if ch == '\"': - inc(pos) # skip '"' - break - if ch in {CR, LF, lexbase.EndOfFile}: - tok.kind = tkInvalid - break - if (ch == '\\') and not rawMode: - c.bufPos = pos - getEscapedChar(c, tok) - pos = c.bufPos - else: - add(tok.literal, ch) - Inc(pos) - c.bufpos = pos - -proc getSymbol(c: var TCfgParser, tok: var TToken) = - var - pos: int - buf: cstring - pos = c.bufpos - buf = c.buf - while true: - add(tok.literal, buf[pos]) - Inc(pos) - if not (buf[pos] in SymChars): break - c.bufpos = pos - tok.kind = tkSymbol - -proc skip(c: var TCfgParser) = - var - buf: cstring - pos: int - pos = c.bufpos - buf = c.buf - while true: - case buf[pos] - of ' ': - Inc(pos) - of Tabulator: - inc(pos) - of '#', ';': - while not (buf[pos] in {CR, LF, lexbase.EndOfFile}): inc(pos) - of CR, LF: - pos = HandleCRLF(c, pos) - buf = c.buf - else: - break # EndOfFile also leaves the loop - c.bufpos = pos - -proc rawGetTok(c: var TCfgParser, tok: var TToken) = - tok.kind = tkInvalid - setlen(tok.literal, 0) - skip(c) - case c.buf[c.bufpos] - of '=': - tok.kind = tkEquals - inc(c.bufpos) - tok.literal = "=" - of '-': - inc(c.bufPos) - if c.buf[c.bufPos] == '-': inc(c.bufPos) - tok.kind = tkDashDash - tok.literal = "--" - of ':': - tok.kind = tkColon - inc(c.bufpos) - tok.literal = ":" - of 'r', 'R': - if c.buf[c.bufPos + 1] == '\"': - Inc(c.bufPos) - getString(c, tok, true) - else: - getSymbol(c, tok) - of '[': - tok.kind = tkBracketLe - inc(c.bufpos) - tok.literal = "[" - of ']': - tok.kind = tkBracketRi - Inc(c.bufpos) - tok.literal = "]" - of '\"': - getString(c, tok, false) - of lexbase.EndOfFile: - tok.kind = tkEof - else: getSymbol(c, tok) - -proc errorStr(c: TCfgParser, msg: string): string = - result = `%`("$1($2, $3) Error: $4", - [c.filename, $(getLine(c)), $(getColumn(c)), msg]) - -proc getKeyValPair(c: var TCfgParser, kind: TCfgEventKind): TCfgEvent = - if c.tok.kind == tkSymbol: - result.kind = kind - result.key = c.tok.literal - result.value = "" - rawGetTok(c, c.tok) - while c.tok.literal == ".": - add(result.key, '.') - rawGetTok(c, c.tok) - if c.tok.kind == tkSymbol: - add(result.key, c.tok.literal) - rawGetTok(c, c.tok) - else: - result.kind = cfgError - result.msg = errorStr(c, "symbol expected, but found: " & c.tok.literal) - break - if c.tok.kind in {tkEquals, tkColon}: - rawGetTok(c, c.tok) - if c.tok.kind == tkSymbol: - result.value = c.tok.literal - else: - result.kind = cfgError - result.msg = errorStr(c, "symbol expected, but found: " & c.tok.literal) - rawGetTok(c, c.tok) - else: - result.kind = cfgError - result.msg = errorStr(c, "symbol expected, but found: " & c.tok.literal) - rawGetTok(c, c.tok) - -proc next(c: var TCfgParser): TCfgEvent = - case c.tok.kind - of tkEof: - result.kind = cfgEof - of tkDashDash: - rawGetTok(c, c.tok) - result = getKeyValPair(c, cfgOption) - of tkSymbol: - result = getKeyValPair(c, cfgKeyValuePair) - of tkBracketLe: - rawGetTok(c, c.tok) - if c.tok.kind == tkSymbol: - result.kind = cfgSectionStart - result.section = c.tok.literal - else: - result.kind = cfgError - result.msg = errorStr(c, "symbol expected, but found: " & c.tok.literal) - rawGetTok(c, c.tok) - if c.tok.kind == tkBracketRi: - rawGetTok(c, c.tok) - else: - result.kind = cfgError - result.msg = errorStr(c, "\']\' expected, but found: " & c.tok.literal) - of tkInvalid, tkBracketRi, tkEquals, tkColon: - result.kind = cfgError - result.msg = errorStr(c, "invalid token: " & c.tok.literal) - rawGetTok(c, c.tok) diff --git a/compiler/pendx.nim b/compiler/pendx.nim deleted file mode 100644 index 2942968a0..000000000 --- a/compiler/pendx.nim +++ /dev/null @@ -1,18 +0,0 @@ -# -# -# The Nimrod Compiler -# (c) Copyright 2012 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# - -import - llstream, lexer, parser, idents, strutils, ast, msgs - -proc ParseAll*(p: var TParser): PNode = - result = nil - -proc parseTopLevelStmt*(p: var TParser): PNode = - result = nil - diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 384bdc8a3..6289ecc85 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -194,10 +194,15 @@ proc semRange(c: PContext, n: PNode, prev: PType): PType = if isRange(n[1]): result = semRangeAux(c, n[1], prev) let n = result.n - if n.sons[0].kind in {nkCharLit..nkUInt64Lit}: - if n.sons[0].intVal > 0 or n.sons[1].intVal < 0: - incl(result.flags, tfNeedsInit) - elif n.sons[0].floatVal > 0.0 or n.sons[1].floatVal < 0.0: + if n.sons[0].kind in {nkCharLit..nkUInt64Lit} and n.sons[0].intVal > 0: + incl(result.flags, tfNeedsInit) + elif n.sons[1].kind in {nkCharLit..nkUInt64Lit} and n.sons[1].intVal < 0: + incl(result.flags, tfNeedsInit) + elif n.sons[0].kind in {nkFloatLit..nkFloat64Lit} and + n.sons[0].floatVal > 0.0: + incl(result.flags, tfNeedsInit) + elif n.sons[1].kind in {nkFloatLit..nkFloat64Lit} and + n.sons[1].floatVal < 0.0: incl(result.flags, tfNeedsInit) else: localError(n.sons[0].info, errRangeExpected) diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 271a01266..33de40f34 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -352,8 +352,9 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = result = handleGenericInvokation(cl, t) of tyGenericBody: - internalError(cl.info, "ReplaceTypeVarsT: tyGenericBody" ) - result = replaceTypeVarsT(cl, lastSon(t)) + localError(cl.info, errCannotInstantiateX, typeToString(t)) + result = t + #result = replaceTypeVarsT(cl, lastSon(t)) of tyFromExpr: if cl.allowMetaTypes: return diff --git a/compiler/syntaxes.nim b/compiler/syntaxes.nim index 478c2a837..d5062544f 100644 --- a/compiler/syntaxes.nim +++ b/compiler/syntaxes.nim @@ -62,7 +62,6 @@ proc parseAll(p: var TParsers): PNode = of skinEndX: internalError("parser to implement") result = ast.emptyNode - # skinEndX: result := pendx.parseAll(p.parser); proc parseTopLevelStmt(p: var TParsers): PNode = case p.skin @@ -73,7 +72,6 @@ proc parseTopLevelStmt(p: var TParsers): PNode = of skinEndX: internalError("parser to implement") result = ast.emptyNode - #skinEndX: result := pendx.parseTopLevelStmt(p.parser); proc utf8Bom(s: string): int = if (s[0] == '\xEF') and (s[1] == '\xBB') and (s[2] == '\xBF'): diff --git a/compiler/typesrenderer.nim b/compiler/typesrenderer.nim index ebb9b7e15..790bd1047 100644 --- a/compiler/typesrenderer.nim +++ b/compiler/typesrenderer.nim @@ -69,7 +69,7 @@ proc renderType(n: PNode): string = for i in 1 .. <len(n): result.add(renderType(n[i]) & ',') result[<len(result)] = ']' else: result = "" - assert (not result.isNil) + assert(not result.isNil) proc renderParamTypes(found: var seq[string], n: PNode) = @@ -86,13 +86,11 @@ proc renderParamTypes(found: var seq[string], n: PNode) = let typePos = len(n) - 2 assert typePos > 0 var typeStr = renderType(n[typePos]) - if typeStr.len < 1: + if typeStr.len < 1 and n[typePos+1].kind != nkEmpty: # Try with the last node, maybe its a default value. - assert n[typePos+1].kind != nkEmpty let typ = n[typePos+1].typ if not typ.isNil: typeStr = typeToString(typ, preferExported) - if typeStr.len < 1: - return + if typeStr.len < 1: return for i in 0 .. <typePos: assert n[i].kind == nkIdent found.add(typeStr) |