diff options
-rw-r--r-- | compiler/renderer.nim | 9 | ||||
-rw-r--r-- | install.txt | 6 | ||||
-rw-r--r-- | lib/pure/os.nim | 8 | ||||
-rw-r--r-- | lib/pure/unicode.nim | 4 | ||||
-rw-r--r-- | tests/showoff/tformatopt.nim | 57 | ||||
-rw-r--r-- | tests/showoff/thello2.nim | 11 | ||||
-rw-r--r-- | tests/showoff/thtml1.nim | 11 | ||||
-rw-r--r-- | tests/showoff/thtml2.nim | 37 | ||||
-rw-r--r-- | tests/showoff/tonce.nim | 22 | ||||
-rw-r--r-- | tests/showoff/tquasiquote.nim | 14 | ||||
-rw-r--r-- | tools/niminst/buildbat.tmpl | 4 | ||||
-rw-r--r-- | tools/niminst/buildsh.tmpl | 4 | ||||
-rw-r--r-- | tools/niminst/niminst.nim | 10 | ||||
-rw-r--r-- | web/community.txt | 2 |
14 files changed, 186 insertions, 13 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim index f6fb0f8c0..61babed66 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -421,10 +421,11 @@ proc lsub(n: PNode): int = of nkElifExpr: result = lsons(n) + len("_elif_:_") of nkElseExpr: result = lsub(n.sons[0]) + len("_else:_") # type descriptions of nkTypeOfExpr: result = lsub(n.sons[0]) + len("type_") - of nkRefTy: result = lsub(n.sons[0]) + len("ref_") - of nkPtrTy: result = lsub(n.sons[0]) + len("ptr_") - of nkVarTy: result = lsub(n.sons[0]) + len("var_") - of nkDistinctTy: result = lsub(n.sons[0]) + len("Distinct_") + of nkRefTy: result = (if n.len > 0: lsub(n.sons[0])+1 else: 0) + len("ref") + of nkPtrTy: result = (if n.len > 0: lsub(n.sons[0])+1 else: 0) + len("ptr") + of nkVarTy: result = (if n.len > 0: lsub(n.sons[0])+1 else: 0) + len("var") + of nkDistinctTy: result = (if n.len > 0: lsub(n.sons[0])+1 else: 0) + + len("Distinct") of nkTypeDef: result = lsons(n) + 3 of nkOfInherit: result = lsub(n.sons[0]) + len("of_") of nkProcTy: result = lsons(n) + len("proc_") diff --git a/install.txt b/install.txt index 11c502235..2883c8495 100644 --- a/install.txt +++ b/install.txt @@ -62,3 +62,9 @@ Currently, the following C compilers are supported under Windows: | http://www.digitalmars.com/download/freecompiler.html However, most testing is done with GCC. + +Bootstrapping from Github +------------------------- + +Take a look at the readme file on github `here <https://github.com/Araq/Nimrod#readme>`_ +for instructions. diff --git a/lib/pure/os.nim b/lib/pure/os.nim index d74cb1fb9..7a8722ab4 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -398,6 +398,14 @@ proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [FReadDir].} = var res: TStat return stat(dir, res) >= 0'i32 and S_ISDIR(res.st_mode) +proc fileExists*(filename: string): bool {.inline.} = + ## Synonym for existsFile + existsFile(filename) + +proc dirExists*(dir: string): bool {.inline.} = + ## Synonym for existsDir + existsDir(dir) + proc getLastModificationTime*(file: string): TTime {.rtl, extern: "nos$1".} = ## Returns the `file`'s last modification time. when defined(posix): diff --git a/lib/pure/unicode.nim b/lib/pure/unicode.nim index 4aacb2f71..f90fc2745 100644 --- a/lib/pure/unicode.nim +++ b/lib/pure/unicode.nim @@ -132,6 +132,10 @@ proc toUTF8*(c: TRune): string {.rtl, extern: "nuc$1".} = result = newString(1) result[0] = chr(i) +proc `$`*(rune: TRune): string = + ## converts a rune to a string + rune.toUTF8 + proc `$`*(runes: seq[TRune]): string = ## converts a sequence of runes to a string result = "" diff --git a/tests/showoff/tformatopt.nim b/tests/showoff/tformatopt.nim new file mode 100644 index 000000000..f33ed6921 --- /dev/null +++ b/tests/showoff/tformatopt.nim @@ -0,0 +1,57 @@ +discard """ + output: '''(a: 3 +b: 4 +s: abc +)''' +""" + +import macros + +proc invalidFormatString() = + echo "invalidFormatString" + +template formatImpl(handleChar: expr) = + var i = 0 + while i < f.len: + if f[i] == '$': + case f[i+1] + of '1'..'9': + var j = 0 + i += 1 + while f[i] in {'0'..'9'}: + j = j * 10 + ord(f[i]) - ord('0') + i += 1 + result.add(a[j-1]) + else: + invalidFormatString() + else: + result.add(handleChar(f[i])) + i += 1 + +proc `%`*(f: string, a: openArray[string]): string = + template identity(x: expr): expr = x + result = "" + formatImpl(identity) + +macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): expr = + result = newNimNode(nnkBracket) + let f = f.strVal + formatImpl(newLit) + result = nestList(!"&", result) + +template optAdd1{x = y; add(x, z)}(x, y, z: string) = + x = y & z + +proc `/&` [T: object](x: T): string = + result = "(" + for name, value in fieldPairs(x): + result.add("$1: $2\n" % [name, $value]) + result.add(")") + +type + MyObject = object + a, b: int + s: string + +let obj = MyObject(a: 3, b: 4, s: "abc") +echo(/&obj) diff --git a/tests/showoff/thello2.nim b/tests/showoff/thello2.nim new file mode 100644 index 000000000..d2e2f6227 --- /dev/null +++ b/tests/showoff/thello2.nim @@ -0,0 +1,11 @@ +discard """ + output: '''(a: 3, b: 4, s: abc)''' +""" + +type + MyObject = object + a, b: int + s: string + +let obj = MyObject(a: 3, b: 4, s: "abc") +echo obj diff --git a/tests/showoff/thtml1.nim b/tests/showoff/thtml1.nim new file mode 100644 index 000000000..cd95c7971 --- /dev/null +++ b/tests/showoff/thtml1.nim @@ -0,0 +1,11 @@ +discard """ + output: "<br>" +""" + +template htmlTag(tag: expr) {.immediate.} = + proc tag(): string = "<" & astToStr(tag) & ">" + +htmlTag(br) +htmlTag(html) + +echo br() diff --git a/tests/showoff/thtml2.nim b/tests/showoff/thtml2.nim new file mode 100644 index 000000000..8a451ebf1 --- /dev/null +++ b/tests/showoff/thtml2.nim @@ -0,0 +1,37 @@ +discard """ + output: "<html><head><title>now look at this</title></head><body><ul><li>Nimrod is quite capable</li></ul></body></html>" +""" + +import strutils + +template html(name: expr, matter: stmt) {.immediate.} = + proc name(): string = + result = "<html>" + matter + result.add("</html>") + +template nestedTag(tag: expr) {.immediate.} = + template tag(matter: stmt) {.immediate.} = + result.add("<" & astToStr(tag) & ">") + matter + result.add("</" & astToStr(tag) & ">") + +template simpleTag(tag: expr) {.immediate.} = + template tag(matter: expr) {.immediate.} = + result.add("<$1>$2</$1>" % [astToStr(tag), matter]) + +nestedTag body +nestedTag head +nestedTag ul +simpleTag title +simpleTag li + + +html mainPage: + head: + title "now look at this" + body: + ul: + li "Nimrod is quite capable" + +echo mainPage() diff --git a/tests/showoff/tonce.nim b/tests/showoff/tonce.nim new file mode 100644 index 000000000..6fc372e87 --- /dev/null +++ b/tests/showoff/tonce.nim @@ -0,0 +1,22 @@ +discard """ + output: '''first call of p +some call of p +new instantiation +some call of p''' +""" + +template once(body: stmt) = + var x {.global.} = false + if not x: + x = true + body + +proc p() = + once: + echo "first call of p" + echo "some call of p" + +p() +once: + echo "new instantiation" +p() diff --git a/tests/showoff/tquasiquote.nim b/tests/showoff/tquasiquote.nim new file mode 100644 index 000000000..df7fccc33 --- /dev/null +++ b/tests/showoff/tquasiquote.nim @@ -0,0 +1,14 @@ +discard """ + outputsub: '''tquasiquote.nim(14,8): Check failed: 1 > 2''' +""" + +import macros + +macro check(ex: expr): stmt = + var info = ex.lineInfo + var expString = ex.toStrLit + result = quote do: + if not `ex`: + echo `info`, ": Check failed: ", `expString` + +check 1 > 2 diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl index 36e1a3e79..712ebc794 100644 --- a/tools/niminst/buildbat.tmpl +++ b/tools/niminst/buildbat.tmpl @@ -17,8 +17,8 @@ REM call the compiler: # var linkCmd = "" # for ff in items(c.cfiles[winIndex][cpuIndex]): # let f = ff.toWin -ECHO %CC% %COMP_FLAGS% -Inimcache -c ?{f} -o ?{changeFileExt(f, "o")} -%CC% %COMP_FLAGS% -Inimcache -c ?{f} -o ?{changeFileExt(f, "o")} +ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} +%CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} # linkCmd.add(" " & changeFileExt(f, "o")) # end for diff --git a/tools/niminst/buildsh.tmpl b/tools/niminst/buildsh.tmpl index 0fb4907cf..8fe5fea9f 100644 --- a/tools/niminst/buildsh.tmpl +++ b/tools/niminst/buildsh.tmpl @@ -128,8 +128,8 @@ case $myos in # var linkCmd = "" # for ff in items(c.cfiles[osA][cpuA]): # let f = ff.toUnix - echo "$CC $COMP_FLAGS -Inimcache -c ?{f} -o ?{changeFileExt(f, "o")}" - $CC $COMP_FLAGS -Inimcache -c ?{f} -o ?{changeFileExt(f, "o")} + echo "$CC $COMP_FLAGS -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}" + $CC $COMP_FLAGS -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} # add(linkCmd, " \\\n" & changeFileExt(f, "o")) # end for echo "$LINKER -o ?{"$binDir/" & toLower(c.name)} ?linkCmd $LINK_FLAGS" diff --git a/tools/niminst/niminst.nim b/tools/niminst/niminst.nim index 0c9717e12..96815ebe4 100644 --- a/tools/niminst/niminst.nim +++ b/tools/niminst/niminst.nim @@ -392,7 +392,7 @@ proc readCFiles(c: var TConfigData, osA, cpuA: int) = quit("Cannot open: " & f) proc buildDir(os, cpu: int): string = - return "nimcache" / ($os & "_" & $cpu) + return "c_code" / ($os & "_" & $cpu) proc getOutputDir(c: var TConfigData): string = if c.outdir.len > 0: c.outdir else: "build" @@ -432,11 +432,11 @@ proc writeInstallScripts(c: var TConfigData) = writeFile(deinstallShFile, generateDeinstallScript(c), "\10") proc srcdist(c: var TConfigData) = - if not existsDir(getOutputDir(c) / "nimcache"): - createDir(getOutputDir(c) / "nimcache") + if not existsDir(getOutputDir(c) / "c_code"): + createDir(getOutputDir(c) / "c_code") for x in walkFiles(c.libpath / "lib/*.h"): - echo(getOutputDir(c) / "nimcache" / extractFilename(x)) - copyFile(dest=getOutputDir(c) / "nimcache" / extractFilename(x), source=x) + echo(getOutputDir(c) / "c_code" / extractFilename(x)) + copyFile(dest=getOutputDir(c) / "c_code" / extractFilename(x), source=x) var winIndex = -1 var intel32Index = -1 var intel64Index = -1 diff --git a/web/community.txt b/web/community.txt index 6e2306f8f..b9a0a4196 100644 --- a/web/community.txt +++ b/web/community.txt @@ -9,6 +9,8 @@ Bug reports: http://github.com/Araq/Nimrod/issues. For quickest feedback, join our IRC channel: irc://irc.freenode.net/nimrod (logs at `<http://build.nimrod-code.org/irclogs/>`_). +Check out our Twitter account for latest news and announcements: `@nimrodlang <http://twitter.com/nimrodlang>`_. + How to help =========== |