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

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

View File

@@ -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

View File

@@ -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,

View File

@@ -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",

View File

@@ -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

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.
## 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

View File

@@ -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)

View File

@@ -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

View File

@@ -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``.