documentation improvements; added system.gorge (for Araq's fun)

This commit is contained in:
Araq 2012-06-22 08:30:55 +02:00
commit 0b509127d2
8 changed files with 50 additions and 16 deletions

View file

@ -267,6 +267,8 @@ const
sfByCopy* = sfBorrow sfByCopy* = sfBorrow
# a variable is to be captured by value in a closure # a variable is to be captured by value in a closure
sfHoist* = sfVolatile ## proc return value can be hoisted
const const
# getting ready for the future expr/stmt merge # getting ready for the future expr/stmt merge
nkWhen* = nkWhenStmt nkWhen* = nkWhenStmt

View file

@ -23,7 +23,7 @@ const
wMagic, wNosideEffect, wSideEffect, wNoreturn, wDynLib, wHeader, wMagic, wNosideEffect, wSideEffect, wNoreturn, wDynLib, wHeader,
wCompilerProc, wProcVar, wDeprecated, wVarargs, wCompileTime, wMerge, wCompilerProc, wProcVar, wDeprecated, wVarargs, wCompileTime, wMerge,
wBorrow, wExtern, wImportCompilerProc, wThread, wImportCpp, wImportObjC, wBorrow, wExtern, wImportCompilerProc, wThread, wImportCpp, wImportObjC,
wNoStackFrame, wError, wDiscardable, wNoInit, wDestructor} wNoStackFrame, wError, wDiscardable, wNoInit, wDestructor, wHoist}
converterPragmas* = procPragmas converterPragmas* = procPragmas
methodPragmas* = procPragmas methodPragmas* = procPragmas
templatePragmas* = {wImmediate, wDeprecated, wError} templatePragmas* = {wImmediate, wDeprecated, wError}
@ -51,7 +51,8 @@ const
wImportcpp, wImportobjc, wError} wImportcpp, wImportobjc, wError}
varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl, varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl,
wMagic, wHeader, wDeprecated, wCompilerProc, wDynLib, wExtern, 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, constPragmas* = {wImportc, wExportc, wHeader, wDeprecated, wMagic, wNodecl,
wExtern, wImportcpp, wImportobjc, wError} wExtern, wImportcpp, wImportobjc, wError}
letPragmas* = varPragmas letPragmas* = varPragmas
@ -597,6 +598,12 @@ proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) =
of wNoInit: of wNoInit:
noVal(it) noVal(it)
if sym != nil: incl(sym.flags, sfNoInit) 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, of wChecks, wObjChecks, wFieldChecks, wRangechecks, wBoundchecks,
wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints, wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints,
wLinedir, wStacktrace, wLinetrace, wOptimization, wByRef, wLinedir, wStacktrace, wLinetrace, wOptimization, wByRef,

View file

@ -61,7 +61,7 @@ type
wWatchPoint, wSubsChar, wWatchPoint, wSubsChar,
wAcyclic, wShallow, wUnroll, wLinearScanEnd, wAcyclic, wShallow, wUnroll, wLinearScanEnd,
wWrite, wPutEnv, wPrependEnv, wAppendEnv, wThreadVar, wEmit, wNoStackFrame, wWrite, wPutEnv, wPrependEnv, wAppendEnv, wThreadVar, wEmit, wNoStackFrame,
wImplicitStatic, wGlobal, wImplicitStatic, wGlobal, wHoist
wAuto, wBool, wCatch, wChar, wClass, wAuto, wBool, wCatch, wChar, wClass,
wConst_cast, wDefault, wDelete, wDouble, wDynamic_cast, wConst_cast, wDefault, wDelete, wDouble, wDynamic_cast,
@ -139,7 +139,7 @@ const
"watchpoint", "watchpoint",
"subschar", "acyclic", "shallow", "unroll", "linearscanend", "subschar", "acyclic", "shallow", "unroll", "linearscanend",
"write", "putenv", "prependenv", "appendenv", "threadvar", "emit", "write", "putenv", "prependenv", "appendenv", "threadvar", "emit",
"nostackframe", "implicitstatic", "global", "nostackframe", "implicitstatic", "global", "hoist",
"auto", "bool", "catch", "char", "class", "auto", "bool", "catch", "char", "class",
"const_cast", "default", "delete", "double", "const_cast", "default", "delete", "double",

View file

@ -33,10 +33,7 @@ with ``'``. An example::
ifStmt ::= 'if' expr ':' stmts ('elif' expr ':' stmts)* ['else' stmts] ifStmt ::= 'if' expr ':' stmts ('elif' expr ':' stmts)* ['else' stmts]
Other parts of Nimrod - like scoping rules or runtime semantics are only Other parts of Nimrod - like scoping rules or runtime semantics are only
described in an informal manner. The reason is that formal semantics are described in an informal manner for now.
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).
Definitions Definitions
@ -157,6 +154,11 @@ underscores ``__`` are not allowed::
digit ::= '0'..'9' digit ::= '0'..'9'
IDENTIFIER ::= letter ( ['_'] (letter | digit) )* 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: The following `keywords`:idx: are reserved and cannot be used as identifiers:
.. code-block:: nimrod .. code-block:: nimrod

View file

@ -1246,7 +1246,9 @@ iterator `||`*[S, T](a: S, b: T, annotation=""): T {.
## `annotation` is an additional annotation for the code generator to use. ## `annotation` is an additional annotation for the code generator to use.
## Note that the compiler maps that to ## Note that the compiler maps that to
## the ``#pragma omp parallel for`` construct of `OpenMP`:idx: and as ## 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 nil
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.} 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" ## 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 {. proc staticExec*(command: string, input = ""): string {.
magic: "StaticExec".} = nil magic: "StaticExec".} = nil
## executes an external process at compile-time. ## 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") & ## const buildInfo = "Revision " & staticExec("git rev-parse HEAD") &
## "\nCompiled on " & staticExec("uname -v") ## "\nCompiled on " & staticExec("uname -v")
## ##
## ``gorge`` is an alias for ``staticExec``.
proc `+=`*[T](x, y: ordinal[T]) {.magic: "Inc", noSideEffect.} proc `+=`*[T](x, y: ordinal[T]) {.magic: "Inc", noSideEffect.}
## Increments an ordinal ## Increments an ordinal

View file

@ -1,5 +1,5 @@
discard """ discard """
output: "02468101214161820" output: "02468101214161820\n15"
""" """
proc filter[T](list: seq[T], f: proc (item: T): bool {.closure.}): seq[T] = 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) for n in nums2: stdout.write(n)
stdout.write("\n")
outer() 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)

View file

@ -1,6 +1,10 @@
version 0.9.0 version 0.9.0
============= =============
New pragmas:
- ``hoist`` pragma for loop hoisting
- implement ``byCopy`` pragma
- complete and document optional indentation for 'case' statement - complete and document optional indentation for 'case' statement
- implement a warning message for shadowed 'result' variable - implement a warning message for shadowed 'result' variable
- make templates hygienic by default: try to gensym() everything in the 'block' - 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 - fix evals.nim with closures
- test sequence of closures; especially that the GC does not leak for those! - test sequence of closures; especially that the GC does not leak for those!
- proc types shall have closure calling convention per default - proc types shall have closure calling convention per default
- implement ``byCopy`` pragma - implement "closure tuple consists of a single 'ref'" optimization
- implement proper coroutines - implement proper coroutines
- document 'do' notation - document 'do' notation
@ -22,7 +26,6 @@ version 0.9.0
use tyInt+node for that use tyInt+node for that
- implement the high level optimizer - implement the high level optimizer
- change overloading resolution - change overloading resolution
- ``hoist`` pragma for loop hoisting
- we need to support iteration of 2 different data structures in parallel - we need to support iteration of 2 different data structures in parallel
- make exceptions compatible with C++ exceptions - make exceptions compatible with C++ exceptions
- change how comments are part of the AST - change how comments are part of the AST

View file

@ -27,8 +27,9 @@ Library Additions
assignments. assignments.
- Added ``system.eval`` that can execute an anonymous block of code at - Added ``system.eval`` that can execute an anonymous block of code at
compile time as if was a macro. compile time as if was a macro.
- Added ``system.staticExec`` for compile-time execution of external programs - Added ``system.staticExec`` and ``system.gorge`` for compile-time execution
- Added ``system.staticRead`` as a synonym for slurp of external programs.
- Added ``system.staticRead`` as a synonym for ``system.slurp``.
- Added ``macros.emit`` that can emit an arbitrary computed string as nimrod - Added ``macros.emit`` that can emit an arbitrary computed string as nimrod
code during compilation. code during compilation.
- Added ``strutils.parseEnum``. - Added ``strutils.parseEnum``.
@ -41,10 +42,10 @@ Library Additions
- Added a wrapper for ``libsvm``. - Added a wrapper for ``libsvm``.
- Added a wrapper for ``mongodb``. - Added a wrapper for ``mongodb``.
- Added ``terminal.isatty``. - 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. values of an enum.
- Added ``system.TInteger`` and ``system.TNumber`` type classes matching - 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 ``system.clamp`` to limit a value within an interval ``[a, b]``.
- Added ``strutils.continuesWith``. - Added ``strutils.continuesWith``.
- Added ``system.getStackTrace``. - Added ``system.getStackTrace``.