diff options
-rwxr-xr-x | compiler/ast.nim | 2 | ||||
-rwxr-xr-x | compiler/pragmas.nim | 11 | ||||
-rwxr-xr-x | compiler/wordrecg.nim | 4 | ||||
-rwxr-xr-x | doc/manual.txt | 10 | ||||
-rwxr-xr-x | lib/system.nim | 8 | ||||
-rw-r--r-- | tests/run/tfilter.nim | 15 | ||||
-rwxr-xr-x | todo.txt | 7 | ||||
-rwxr-xr-x | web/news.txt | 9 |
8 files changed, 50 insertions, 16 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index fc8c54ed1..d14bef9f7 100755 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -266,6 +266,8 @@ const sfByCopy* = sfBorrow # a variable is to be captured by value in a closure + + sfHoist* = sfVolatile ## proc return value can be hoisted const # getting ready for the future expr/stmt merge diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 96ae9d701..d4a635058 100755 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -23,7 +23,7 @@ const wMagic, wNosideEffect, wSideEffect, wNoreturn, wDynLib, wHeader, wCompilerProc, wProcVar, wDeprecated, wVarargs, wCompileTime, wMerge, wBorrow, wExtern, wImportCompilerProc, wThread, wImportCpp, wImportObjC, - wNoStackFrame, wError, wDiscardable, wNoInit, wDestructor} + wNoStackFrame, wError, wDiscardable, wNoInit, wDestructor, wHoist} converterPragmas* = procPragmas methodPragmas* = procPragmas templatePragmas* = {wImmediate, wDeprecated, wError} @@ -51,7 +51,8 @@ const wImportcpp, wImportobjc, wError} varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl, wMagic, wHeader, wDeprecated, wCompilerProc, wDynLib, wExtern, - wImportcpp, wImportobjc, wError, wNoInit, wCompileTime, wGlobal} + wImportcpp, wImportobjc, wError, wNoInit, wCompileTime, wGlobal, + wByCopy} constPragmas* = {wImportc, wExportc, wHeader, wDeprecated, wMagic, wNodecl, wExtern, wImportcpp, wImportobjc, wError} letPragmas* = varPragmas @@ -597,6 +598,12 @@ proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = of wNoInit: noVal(it) if sym != nil: incl(sym.flags, sfNoInit) + of wByCopy: + noVal(it) + if sym != nil: incl(sym.flags, sfByCopy) + of wHoist: + noVal(it) + if sym != nil: incl(sym.flags, sfHoist) of wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks, wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints, wLinedir, wStacktrace, wLinetrace, wOptimization, wByRef, diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index cec76c998..382b6c765 100755 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -61,7 +61,7 @@ type wWatchPoint, wSubsChar, wAcyclic, wShallow, wUnroll, wLinearScanEnd, wWrite, wPutEnv, wPrependEnv, wAppendEnv, wThreadVar, wEmit, wNoStackFrame, - wImplicitStatic, wGlobal, + wImplicitStatic, wGlobal, wHoist wAuto, wBool, wCatch, wChar, wClass, wConst_cast, wDefault, wDelete, wDouble, wDynamic_cast, @@ -139,7 +139,7 @@ const "watchpoint", "subschar", "acyclic", "shallow", "unroll", "linearscanend", "write", "putenv", "prependenv", "appendenv", "threadvar", "emit", - "nostackframe", "implicitstatic", "global", + "nostackframe", "implicitstatic", "global", "hoist", "auto", "bool", "catch", "char", "class", "const_cast", "default", "delete", "double", diff --git a/doc/manual.txt b/doc/manual.txt index 5359dfc57..ae19ba8b7 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -33,10 +33,7 @@ with ``'``. An example:: ifStmt ::= 'if' expr ':' stmts ('elif' expr ':' stmts)* ['else' stmts] Other parts of Nimrod - like scoping rules or runtime semantics are only -described in an informal manner. The reason is that formal semantics are -difficult to write and understand. However, there is only one Nimrod -implementation, so one may consider it as the formal specification; -especially since the compiler's code is pretty clean (well, some parts of it). +described in an informal manner for now. Definitions @@ -157,6 +154,11 @@ underscores ``__`` are not allowed:: digit ::= '0'..'9' IDENTIFIER ::= letter ( ['_'] (letter | digit) )* +Currently any unicode character with an ordinal value > 127 (non ASCII) is +classified as a ``letter`` and may thus be part of an identifier but later +versions of the language may assign some Unicode characters to belong to the +operator characters instead. + The following `keywords`:idx: are reserved and cannot be used as identifiers: .. code-block:: nimrod diff --git a/lib/system.nim b/lib/system.nim index fe8f7a517..b57b2fec5 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -1246,7 +1246,9 @@ iterator `||`*[S, T](a: S, b: T, annotation=""): T {. ## `annotation` is an additional annotation for the code generator to use. ## Note that the compiler maps that to ## the ``#pragma omp parallel for`` construct of `OpenMP`:idx: and as - ## such isn't aware of the parallelism in your code. Be careful. + ## such isn't aware of the parallelism in your code! Be careful! Later + ## versions of ``||`` will get proper support by Nimrod's code generator + ## and GC. nil proc min*(x, y: int): int {.magic: "MinI", noSideEffect.} @@ -2214,7 +2216,10 @@ proc staticRead*(filename: string): string {.magic: "Slurp".} ## ## const myResource = staticRead"mydatafile.bin" ## + ## ``slurp`` is an alias for ``staticRead``. +proc gorge*(command: string, input = ""): string {. + magic: "StaticExec".} = nil proc staticExec*(command: string, input = ""): string {. magic: "StaticExec".} = nil ## executes an external process at compile-time. @@ -2225,6 +2230,7 @@ proc staticExec*(command: string, input = ""): string {. ## const buildInfo = "Revision " & staticExec("git rev-parse HEAD") & ## "\nCompiled on " & staticExec("uname -v") ## + ## ``gorge`` is an alias for ``staticExec``. proc `+=`*[T](x, y: ordinal[T]) {.magic: "Inc", noSideEffect.} ## Increments an ordinal diff --git a/tests/run/tfilter.nim b/tests/run/tfilter.nim index e82d05742..5846d0efb 100644 --- a/tests/run/tfilter.nim +++ b/tests/run/tfilter.nim @@ -1,5 +1,5 @@ discard """ - output: "02468101214161820" + output: "02468101214161820\n15" """ proc filter[T](list: seq[T], f: proc (item: T): bool {.closure.}): seq[T] = @@ -24,5 +24,18 @@ proc outer = ) for n in nums2: stdout.write(n) + stdout.write("\n") outer() + +import math +proc compose[T](f1, f2: proc (x: T): T {.closure.}): proc (x: T): T {.closure.} = + result = (proc (x: T): T = + result = f1(f2(x))) + + +proc add5(x: int): int = result = x + 5 + +var test = compose(add5, add5) +echo test(5) + diff --git a/todo.txt b/todo.txt index 9e22e9561..8a49943d5 100755 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,10 @@ version 0.9.0 ============= +New pragmas: + - ``hoist`` pragma for loop hoisting + - implement ``byCopy`` pragma + - complete and document optional indentation for 'case' statement - implement a warning message for shadowed 'result' variable - make templates hygienic by default: try to gensym() everything in the 'block' @@ -13,7 +17,7 @@ version 0.9.0 - fix evals.nim with closures - test sequence of closures; especially that the GC does not leak for those! - proc types shall have closure calling convention per default - - implement ``byCopy`` pragma + - implement "closure tuple consists of a single 'ref'" optimization - implement proper coroutines - document 'do' notation @@ -22,7 +26,6 @@ version 0.9.0 use tyInt+node for that - implement the high level optimizer - change overloading resolution -- ``hoist`` pragma for loop hoisting - we need to support iteration of 2 different data structures in parallel - make exceptions compatible with C++ exceptions - change how comments are part of the AST diff --git a/web/news.txt b/web/news.txt index eeff4bf8a..feaa5c2aa 100755 --- a/web/news.txt +++ b/web/news.txt @@ -27,8 +27,9 @@ Library Additions assignments. - Added ``system.eval`` that can execute an anonymous block of code at compile time as if was a macro. -- Added ``system.staticExec`` for compile-time execution of external programs -- Added ``system.staticRead`` as a synonym for slurp +- Added ``system.staticExec`` and ``system.gorge`` for compile-time execution + of external programs. +- Added ``system.staticRead`` as a synonym for ``system.slurp``. - Added ``macros.emit`` that can emit an arbitrary computed string as nimrod code during compilation. - Added ``strutils.parseEnum``. @@ -41,10 +42,10 @@ Library Additions - Added a wrapper for ``libsvm``. - Added a wrapper for ``mongodb``. - Added ``terminal.isatty``. -- Added overload for ``system.items`` that can be used to iterate over the +- Added an overload for ``system.items`` that can be used to iterate over the values of an enum. - Added ``system.TInteger`` and ``system.TNumber`` type classes matching - any of the corresponding types available in nimrod. + any of the corresponding types available in Nimrod. - Added ``system.clamp`` to limit a value within an interval ``[a, b]``. - Added ``strutils.continuesWith``. - Added ``system.getStackTrace``. |