preparations for 0.8.12
This commit is contained in:
parent
2565ff8dde
commit
5b96eaa953
81 changed files with 2355 additions and 826 deletions
0
compiler/ccgthreadvars.nim
Normal file → Executable file
0
compiler/ccgthreadvars.nim
Normal file → Executable file
|
|
@ -55,9 +55,9 @@ proc CloseScope*(tab: var TSymTab) =
|
||||||
while s != nil:
|
while s != nil:
|
||||||
if sfForward in s.flags:
|
if sfForward in s.flags:
|
||||||
LocalError(s.info, errImplOfXexpected, getSymRepr(s))
|
LocalError(s.info, errImplOfXexpected, getSymRepr(s))
|
||||||
elif ({sfUsed, sfInInterface} * s.flags == {}) and
|
elif {sfUsed, sfInInterface} * s.flags == {} and optHints in s.options:
|
||||||
(optHints in s.options): # BUGFIX: check options in s!
|
# BUGFIX: check options in s!
|
||||||
if not (s.kind in {skForVar, skParam, skMethod, skUnknown}):
|
if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam}:
|
||||||
Message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
|
Message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
|
||||||
s = NextIter(it, tab.stack[tab.tos-1])
|
s = NextIter(it, tab.stack[tab.tos-1])
|
||||||
astalgo.rawCloseScope(tab)
|
astalgo.rawCloseScope(tab)
|
||||||
|
|
|
||||||
|
|
@ -522,6 +522,7 @@ proc rawMessage*(msg: TMsgKind, args: openarray[string]) =
|
||||||
of warnMin..warnMax:
|
of warnMin..warnMax:
|
||||||
if not (optWarns in gOptions): return
|
if not (optWarns in gOptions): return
|
||||||
if not (msg in gNotes): return
|
if not (msg in gNotes): return
|
||||||
|
writeContext(unknownLineInfo())
|
||||||
frmt = rawWarningFormat
|
frmt = rawWarningFormat
|
||||||
inc(gWarnCounter)
|
inc(gWarnCounter)
|
||||||
of hintMin..hintMax:
|
of hintMin..hintMax:
|
||||||
|
|
@ -552,6 +553,7 @@ proc liMessage(info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
lastError = info
|
lastError = info
|
||||||
of warnMin..warnMax:
|
of warnMin..warnMax:
|
||||||
ignoreMsg = optWarns notin gOptions or msg notin gNotes
|
ignoreMsg = optWarns notin gOptions or msg notin gNotes
|
||||||
|
if not ignoreMsg: writeContext(info)
|
||||||
frmt = posWarningFormat
|
frmt = posWarningFormat
|
||||||
inc(gWarnCounter)
|
inc(gWarnCounter)
|
||||||
of hintMin..hintMax:
|
of hintMin..hintMax:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# The Nimrod Compiler
|
# The Nimrod Compiler
|
||||||
# (c) Copyright 2010 Andreas Rumpf
|
# (c) Copyright 2011 Andreas Rumpf
|
||||||
#
|
#
|
||||||
# See the file "copying.txt", included in this
|
# See the file "copying.txt", included in this
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
|
|
@ -15,6 +15,6 @@ const
|
||||||
defaultAsmMarkerSymbol* = '!'
|
defaultAsmMarkerSymbol* = '!'
|
||||||
VersionMajor* = 0
|
VersionMajor* = 0
|
||||||
VersionMinor* = 8
|
VersionMinor* = 8
|
||||||
VersionPatch* = 11
|
VersionPatch* = 12
|
||||||
VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch
|
VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ proc instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable) =
|
||||||
var q = a.sym
|
var q = a.sym
|
||||||
if not (q.typ.kind in {tyTypeDesc, tyGenericParam}): continue
|
if not (q.typ.kind in {tyTypeDesc, tyGenericParam}): continue
|
||||||
var s = newSym(skType, q.name, getCurrOwner())
|
var s = newSym(skType, q.name, getCurrOwner())
|
||||||
|
s.info = q.info
|
||||||
|
incl(s.flags, sfUsed)
|
||||||
var t = PType(IdTableGet(pt, q.typ))
|
var t = PType(IdTableGet(pt, q.typ))
|
||||||
if t == nil:
|
if t == nil:
|
||||||
LocalError(a.info, errCannotInstantiateX, s.name.s)
|
LocalError(a.info, errCannotInstantiateX, s.name.s)
|
||||||
|
|
|
||||||
36
compiler/semthreads.nim
Normal file → Executable file
36
compiler/semthreads.nim
Normal file → Executable file
|
|
@ -112,7 +112,7 @@ proc analyseSym(c: PProcCtx, n: PNode): TThreadOwner =
|
||||||
if sfGlobal in v.flags:
|
if sfGlobal in v.flags:
|
||||||
if sfThreadVar in v.flags:
|
if sfThreadVar in v.flags:
|
||||||
result = toMine
|
result = toMine
|
||||||
elif containsTyRef(v.typ):
|
elif containsGarbageCollectedRef(v.typ):
|
||||||
result = toTheirs
|
result = toTheirs
|
||||||
of skTemp, skForVar: result = toNil
|
of skTemp, skForVar: result = toNil
|
||||||
of skConst: result = toMine
|
of skConst: result = toMine
|
||||||
|
|
@ -126,7 +126,8 @@ proc analyseSym(c: PProcCtx, n: PNode): TThreadOwner =
|
||||||
|
|
||||||
proc lvalueSym(n: PNode): PNode =
|
proc lvalueSym(n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
while result.kind in {nkDotExpr, nkBracketExpr, nkDerefExpr, nkHiddenDeref}:
|
while result.kind in {nkDotExpr, nkCheckedFieldExpr,
|
||||||
|
nkBracketExpr, nkDerefExpr, nkHiddenDeref}:
|
||||||
result = result.sons[0]
|
result = result.sons[0]
|
||||||
|
|
||||||
proc writeAccess(c: PProcCtx, n: PNode, owner: TThreadOwner) =
|
proc writeAccess(c: PProcCtx, n: PNode, owner: TThreadOwner) =
|
||||||
|
|
@ -138,7 +139,18 @@ proc writeAccess(c: PProcCtx, n: PNode, owner: TThreadOwner) =
|
||||||
var lastOwner = analyseSym(c, a)
|
var lastOwner = analyseSym(c, a)
|
||||||
case lastOwner
|
case lastOwner
|
||||||
of toNil:
|
of toNil:
|
||||||
c.mapping[v.id] = owner # fine, toNil can be overwritten
|
# fine, toNil can be overwritten
|
||||||
|
var newOwner: TThreadOwner
|
||||||
|
if sfGlobal in v.flags:
|
||||||
|
newOwner = owner
|
||||||
|
elif containsTyRef(v.typ):
|
||||||
|
# ``var local = gNode`` --> ok, but ``local`` is theirs!
|
||||||
|
newOwner = owner
|
||||||
|
else:
|
||||||
|
# ``var local = gString`` --> string copy: ``local`` is mine!
|
||||||
|
newOwner = toMine
|
||||||
|
# XXX BUG what if the tuple contains both ``tyRef`` and ``tyString``?
|
||||||
|
c.mapping[v.id] = newOwner
|
||||||
of toVoid, toUndefined: InternalError(n.info, "writeAccess")
|
of toVoid, toUndefined: InternalError(n.info, "writeAccess")
|
||||||
of toTheirs: Message(n.info, warnWriteToForeignHeap)
|
of toTheirs: Message(n.info, warnWriteToForeignHeap)
|
||||||
of toMine:
|
of toMine:
|
||||||
|
|
@ -146,7 +158,7 @@ proc writeAccess(c: PProcCtx, n: PNode, owner: TThreadOwner) =
|
||||||
Message(n.info, warnDifferentHeaps)
|
Message(n.info, warnDifferentHeaps)
|
||||||
else:
|
else:
|
||||||
# we could not backtrack to a concrete symbol, but that's fine:
|
# we could not backtrack to a concrete symbol, but that's fine:
|
||||||
var lastOwner = analyseSym(c, n)
|
var lastOwner = analyse(c, n)
|
||||||
case lastOwner
|
case lastOwner
|
||||||
of toNil: nil # fine, toNil can be overwritten
|
of toNil: nil # fine, toNil can be overwritten
|
||||||
of toVoid, toUndefined: InternalError(n.info, "writeAccess")
|
of toVoid, toUndefined: InternalError(n.info, "writeAccess")
|
||||||
|
|
@ -178,7 +190,7 @@ proc analyseCall(c: PProcCtx, n: PNode): TThreadOwner =
|
||||||
pushInfoContext(n.info)
|
pushInfoContext(n.info)
|
||||||
result = analyse(newCtx, prc.ast.sons[codePos])
|
result = analyse(newCtx, prc.ast.sons[codePos])
|
||||||
if prc.ast.sons[codePos].kind == nkEmpty and
|
if prc.ast.sons[codePos].kind == nkEmpty and
|
||||||
{sfNoSideEffect, sfThread} * prc.flags == {}:
|
{sfNoSideEffect, sfThread, sfImportc} * prc.flags == {}:
|
||||||
Message(n.info, warnAnalysisLoophole, renderTree(n))
|
Message(n.info, warnAnalysisLoophole, renderTree(n))
|
||||||
if prc.typ.sons[0] != nil:
|
if prc.typ.sons[0] != nil:
|
||||||
if prc.ast.len > resultPos:
|
if prc.ast.len > resultPos:
|
||||||
|
|
@ -228,7 +240,7 @@ template aggregateOwner(result, ana: expr) =
|
||||||
var a = ana # eval once
|
var a = ana # eval once
|
||||||
if result != a:
|
if result != a:
|
||||||
if result == toNil: result = a
|
if result == toNil: result = a
|
||||||
else: Message(n.info, warnDifferentHeaps)
|
elif a != toNil: Message(n.info, warnDifferentHeaps)
|
||||||
|
|
||||||
proc analyseArgs(c: PProcCtx, n: PNode, start = 1) =
|
proc analyseArgs(c: PProcCtx, n: PNode, start = 1) =
|
||||||
for i in start..n.len-1: discard analyse(c, n[i])
|
for i in start..n.len-1: discard analyse(c, n[i])
|
||||||
|
|
@ -241,7 +253,14 @@ proc analyseOp(c: PProcCtx, n: PNode): TThreadOwner =
|
||||||
else:
|
else:
|
||||||
var prc = n[0].sym
|
var prc = n[0].sym
|
||||||
case prc.magic
|
case prc.magic
|
||||||
of mNone: result = analyseCall(c, n)
|
of mNone:
|
||||||
|
if sfSystemModule in prc.owner.flags:
|
||||||
|
# System module proc does no harm :-)
|
||||||
|
analyseArgs(c, n)
|
||||||
|
if prc.typ.sons[0] == nil: result = toVoid
|
||||||
|
else: result = toNil
|
||||||
|
else:
|
||||||
|
result = analyseCall(c, n)
|
||||||
of mNew, mNewFinalize, mNewSeq, mSetLengthStr, mSetLengthSeq,
|
of mNew, mNewFinalize, mNewSeq, mSetLengthStr, mSetLengthSeq,
|
||||||
mAppendSeqElem, mReset, mAppendStrCh, mAppendStrStr:
|
mAppendSeqElem, mReset, mAppendStrCh, mAppendStrStr:
|
||||||
writeAccess(c, n[1], toMine)
|
writeAccess(c, n[1], toMine)
|
||||||
|
|
@ -260,8 +279,7 @@ proc analyseOp(c: PProcCtx, n: PNode): TThreadOwner =
|
||||||
analyseArgs(c, n)
|
analyseArgs(c, n)
|
||||||
result = toMine
|
result = toMine
|
||||||
else:
|
else:
|
||||||
# don't recurse, but check args; NOTE: This is essential that
|
# don't recurse, but check args:
|
||||||
# ``mCreateThread`` is handled here to avoid the recursion
|
|
||||||
analyseArgs(c, n)
|
analyseArgs(c, n)
|
||||||
if prc.typ.sons[0] == nil: result = toVoid
|
if prc.typ.sons[0] == nil: result = toVoid
|
||||||
else: result = toNil
|
else: result = toNil
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,11 @@ Core
|
||||||
|
|
||||||
* `threads <threads.html>`_
|
* `threads <threads.html>`_
|
||||||
Nimrod thread support. **Note**: This is part of the system module. Do not
|
Nimrod thread support. **Note**: This is part of the system module. Do not
|
||||||
import it directly.
|
import it explicitely.
|
||||||
|
|
||||||
|
* `inboxes <inboxes.html>`_
|
||||||
|
Nimrod message passing support for threads. **Note**: This is part of the
|
||||||
|
system module. Do not import it explicitely.
|
||||||
|
|
||||||
* `macros <macros.html>`_
|
* `macros <macros.html>`_
|
||||||
Contains the AST API and documentation of Nimrod for writing macros.
|
Contains the AST API and documentation of Nimrod for writing macros.
|
||||||
|
|
|
||||||
142
doc/manual.txt
142
doc/manual.txt
|
|
@ -473,10 +473,9 @@ Pre-defined integer types
|
||||||
These integer types are pre-defined:
|
These integer types are pre-defined:
|
||||||
|
|
||||||
``int``
|
``int``
|
||||||
the generic signed integer type; its size is platform dependent
|
the generic signed integer type; its size is platform dependent and has the
|
||||||
(the compiler chooses the processor's fastest integer type).
|
same size as a pointer. This type should be used in general. An integer
|
||||||
This type should be used in general. An integer literal that has no type
|
literal that has no type suffix is of this type.
|
||||||
suffix is of this type.
|
|
||||||
|
|
||||||
intXX
|
intXX
|
||||||
additional signed integer types of XX bits use this naming scheme
|
additional signed integer types of XX bits use this naming scheme
|
||||||
|
|
@ -581,7 +580,7 @@ the ``+``, ``-``, ``*``, ``/`` operators for floating point types.
|
||||||
|
|
||||||
Boolean type
|
Boolean type
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
The `boolean`:idx: type is named ``bool`` in Nimrod and can be one of the two
|
The `boolean`:idx: type is named `bool`:idx: in Nimrod and can be one of the two
|
||||||
pre-defined values ``true`` and ``false``. Conditions in while,
|
pre-defined values ``true`` and ``false``. Conditions in while,
|
||||||
if, elif, when statements need to be of type bool.
|
if, elif, when statements need to be of type bool.
|
||||||
|
|
||||||
|
|
@ -670,7 +669,7 @@ use explicitely:
|
||||||
valueD = (3, "abc")
|
valueD = (3, "abc")
|
||||||
|
|
||||||
As can be seen from the example, it is possible to both specify a field's
|
As can be seen from the example, it is possible to both specify a field's
|
||||||
ordinal value and its string value by using a tuple construction. It is also
|
ordinal value and its string value by using a tuple. It is also
|
||||||
possible to only specify one of them.
|
possible to only specify one of them.
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -930,7 +929,7 @@ Reference and pointer types
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
References (similar to `pointers`:idx: in other programming languages) are a
|
References (similar to `pointers`:idx: in other programming languages) are a
|
||||||
way to introduce many-to-one relationships. This means different references can
|
way to introduce many-to-one relationships. This means different references can
|
||||||
point to and modify the same location in memory.
|
point to and modify the same location in memory (also called `aliasing`:idx:).
|
||||||
|
|
||||||
Nimrod distinguishes between `traced`:idx: and `untraced`:idx: references.
|
Nimrod distinguishes between `traced`:idx: and `untraced`:idx: references.
|
||||||
Untraced references are also called *pointers*. Traced references point to
|
Untraced references are also called *pointers*. Traced references point to
|
||||||
|
|
@ -1002,7 +1001,7 @@ pointer) as if it would have the type ``ptr TData``. Casting should only be
|
||||||
done if it is unavoidable: it breaks type safety and bugs can lead to
|
done if it is unavoidable: it breaks type safety and bugs can lead to
|
||||||
mysterious crashes.
|
mysterious crashes.
|
||||||
|
|
||||||
**Note**: The example only works because the memory is initialized with zero
|
**Note**: The example only works because the memory is initialized to zero
|
||||||
(``alloc0`` instead of ``alloc`` does this): ``d.s`` is thus initialized to
|
(``alloc0`` instead of ``alloc`` does this): ``d.s`` is thus initialized to
|
||||||
``nil`` which the string assignment can handle. You need to know low level
|
``nil`` which the string assignment can handle. You need to know low level
|
||||||
details like this when mixing garbage collected data with unmanaged memory.
|
details like this when mixing garbage collected data with unmanaged memory.
|
||||||
|
|
@ -1055,7 +1054,7 @@ each other:
|
||||||
`inline`:idx:
|
`inline`:idx:
|
||||||
The inline convention means the the caller should not call the procedure,
|
The inline convention means the the caller should not call the procedure,
|
||||||
but inline its code directly. Note that Nimrod does not inline, but leaves
|
but inline its code directly. Note that Nimrod does not inline, but leaves
|
||||||
this to the C compiler. Thus it generates ``__inline`` procedures. This is
|
this to the C compiler; it generates ``__inline`` procedures. This is
|
||||||
only a hint for the compiler: it may completely ignore it and
|
only a hint for the compiler: it may completely ignore it and
|
||||||
it may inline procedures that are not marked as ``inline``.
|
it may inline procedures that are not marked as ``inline``.
|
||||||
|
|
||||||
|
|
@ -1069,8 +1068,7 @@ each other:
|
||||||
|
|
||||||
`closure`:idx:
|
`closure`:idx:
|
||||||
indicates that the procedure expects a context, a closure that needs
|
indicates that the procedure expects a context, a closure that needs
|
||||||
to be passed to the procedure. The calling convention ``nimcall`` is
|
to be passed to the procedure.
|
||||||
compatible to ``closure``.
|
|
||||||
|
|
||||||
`syscall`:idx:
|
`syscall`:idx:
|
||||||
The syscall convention is the same as ``__syscall`` in C. It is used for
|
The syscall convention is the same as ``__syscall`` in C. It is used for
|
||||||
|
|
@ -1311,7 +1309,8 @@ algorithm returns true:
|
||||||
if b.kind == distinct and typeEquals(b.baseType, a): return true
|
if b.kind == distinct and typeEquals(b.baseType, a): return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
You can, however, define your own implicit converters:
|
The convertible relation can be relaxed by a user-defined type
|
||||||
|
`converter`:idx:.
|
||||||
|
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
converter toInt(x: char): int = result = ord(x)
|
converter toInt(x: char): int = result = ord(x)
|
||||||
|
|
@ -2036,7 +2035,7 @@ Overloading of the subscript operator
|
||||||
The ``[]`` subscript operator for arrays/openarrays/sequences can be overloaded.
|
The ``[]`` subscript operator for arrays/openarrays/sequences can be overloaded.
|
||||||
Overloading support is only possible if the first parameter has no type that
|
Overloading support is only possible if the first parameter has no type that
|
||||||
already supports the built-in ``[]`` notation. Currently the compiler
|
already supports the built-in ``[]`` notation. Currently the compiler
|
||||||
does not check this. XXX Multiple indexes
|
does not check this restriction.
|
||||||
|
|
||||||
|
|
||||||
Multi-methods
|
Multi-methods
|
||||||
|
|
@ -2612,8 +2611,8 @@ iterator in which case the overloading resolution takes place:
|
||||||
write(stdout, x) # not ambiguous: uses the module C's x
|
write(stdout, x) # not ambiguous: uses the module C's x
|
||||||
|
|
||||||
|
|
||||||
Messages
|
Compiler Messages
|
||||||
========
|
=================
|
||||||
|
|
||||||
The Nimrod compiler emits different kinds of messages: `hint`:idx:,
|
The Nimrod compiler emits different kinds of messages: `hint`:idx:,
|
||||||
`warning`:idx:, and `error`:idx: messages. An *error* message is emitted if
|
`warning`:idx:, and `error`:idx: messages. An *error* message is emitted if
|
||||||
|
|
@ -3045,3 +3044,116 @@ This is only useful if the program is compiled as a dynamic library via the
|
||||||
``--app:lib`` command line option.
|
``--app:lib`` command line option.
|
||||||
|
|
||||||
|
|
||||||
|
Threads
|
||||||
|
=======
|
||||||
|
|
||||||
|
Even though Nimrod's `thread`:idx: support and semantics are preliminary,
|
||||||
|
they should be quite usable already. To enable thread support
|
||||||
|
the ``--threads:on`` command line switch needs to be used. The ``system``
|
||||||
|
module then contains several threading primitives.
|
||||||
|
See the `threads <threads.html>`_ and `inboxes <inboxes.html>`_ modules
|
||||||
|
for the thread API.
|
||||||
|
|
||||||
|
Nimrod's memory model for threads is quite different than that of other common
|
||||||
|
programming languages (C, Pascal, Java): Each thread has its own (garbage
|
||||||
|
collected) heap and sharing of memory is restricted to global variables. This
|
||||||
|
helps to prevent race conditions. GC efficiency is improved quite a lot,
|
||||||
|
because the GC never has to stop other threads and see what they reference.
|
||||||
|
Memory allocation requires no lock at all! This design easily scales to massive
|
||||||
|
multicore processors that will become the norm in the future.
|
||||||
|
|
||||||
|
|
||||||
|
Thread pragma
|
||||||
|
-------------
|
||||||
|
|
||||||
|
A proc that is executed as a new thread of execution should be marked by the
|
||||||
|
`thread pragma`:idx:. The compiler checks procedures marked as ``thread`` for
|
||||||
|
violations of the `no heap sharing restriction`:idx:\: This restriction implies
|
||||||
|
that it is invalid to construct a data structure that consists of memory
|
||||||
|
allocated from different (thread local) heaps.
|
||||||
|
|
||||||
|
Since the semantic checking of threads requires a whole program analysis,
|
||||||
|
it is quite expensive and can be turned off with ``--threadanalysis:off`` to
|
||||||
|
improve compile times.
|
||||||
|
|
||||||
|
A thread proc is passed to ``createThread`` and invoked indirectly; so the
|
||||||
|
``thread`` pragma implies ``procvar``.
|
||||||
|
|
||||||
|
|
||||||
|
Actor model
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Nimrod supports the `actor model`:idx: of concurrency natively:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
type
|
||||||
|
TMsgKind = enum
|
||||||
|
mLine, mEof
|
||||||
|
TMsg = object {.pure, final.}
|
||||||
|
case k: TMsgKind
|
||||||
|
of mEof: nil
|
||||||
|
of mLine: data: string
|
||||||
|
|
||||||
|
var
|
||||||
|
thr: TThread[TMsg]
|
||||||
|
printedLines = 0
|
||||||
|
m: TMsg
|
||||||
|
|
||||||
|
proc print() {.thread.} =
|
||||||
|
while true:
|
||||||
|
var x = recv[TMsg]()
|
||||||
|
if x.k == mEof: break
|
||||||
|
echo x.data
|
||||||
|
discard atomicInc(printedLines)
|
||||||
|
|
||||||
|
createThread(thr, print)
|
||||||
|
|
||||||
|
var input = open("readme.txt")
|
||||||
|
while not endOfFile(input):
|
||||||
|
m.data = input.readLine()
|
||||||
|
thr.send(m)
|
||||||
|
close(input)
|
||||||
|
m.k = mEof
|
||||||
|
thr.send(m)
|
||||||
|
joinThread(thr)
|
||||||
|
|
||||||
|
echo printedLines
|
||||||
|
|
||||||
|
In the actor model threads communicate only over sending messages (`send`:idx:
|
||||||
|
and `recv`:idx: built-ins), not by sharing memory. Every thread has
|
||||||
|
an `inbox`:idx: that keeps incoming messages until the thread requests a new
|
||||||
|
message via the ``recv`` operation. The inbox is an unlimited FIFO queue.
|
||||||
|
|
||||||
|
In the above example the ``print`` thread also communicates with its
|
||||||
|
parent thread over the ``printedLines`` global variable. In general, it is
|
||||||
|
highly advisable to only read from globals, but not to write to them. In fact
|
||||||
|
a write to a global that contains GC'ed memory is always wrong, because it
|
||||||
|
violates the *no heap sharing restriction*:
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
var
|
||||||
|
global: string
|
||||||
|
t: TThread[string]
|
||||||
|
|
||||||
|
proc horrible() {.thread.} =
|
||||||
|
global = "string in thread local heap!"
|
||||||
|
|
||||||
|
createThread(t, horrible)
|
||||||
|
joinThread(t)
|
||||||
|
|
||||||
|
For the above code the compiler procudes "Warning: write to foreign heap". This
|
||||||
|
warning might become an error message in future versions of the compiler.
|
||||||
|
|
||||||
|
Creating a thread is an expensive operation, because a new stack and heap needs
|
||||||
|
to be created for the thread. It is therefore highly advisable that a thread
|
||||||
|
handles a large amount of work. Nimrod prefers *coarse grained*
|
||||||
|
over *fine grained* concurrency.
|
||||||
|
|
||||||
|
|
||||||
|
Threads and exceptions
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
The interaction between threads and exception is simple: A *handled* exception
|
||||||
|
in one thread cannot affect any other thread. However, an *unhandled*
|
||||||
|
exception in one thread terminates the whole *process*!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ Compiler Usage
|
||||||
|
|
||||||
Command line switches
|
Command line switches
|
||||||
---------------------
|
---------------------
|
||||||
Basis command line switches are:
|
Basic command line switches are:
|
||||||
|
|
||||||
.. include:: basicopt.txt
|
.. include:: basicopt.txt
|
||||||
|
|
||||||
|
|
@ -101,6 +101,8 @@ To link against ``nimrtl.dll`` use the command::
|
||||||
|
|
||||||
nimrod c -d:useNimRtl myprog.nim
|
nimrod c -d:useNimRtl myprog.nim
|
||||||
|
|
||||||
|
**Note**: Currently the creation of ``nimrtl.dll`` with thread support has
|
||||||
|
never been tested and is unlikely to work!
|
||||||
|
|
||||||
|
|
||||||
Additional Features
|
Additional Features
|
||||||
|
|
|
||||||
2295
doc/theindex.txt
2295
doc/theindex.txt
File diff suppressed because it is too large
Load diff
0
examples/0mq/client.nim
Normal file → Executable file
0
examples/0mq/client.nim
Normal file → Executable file
0
examples/0mq/server.nim
Normal file → Executable file
0
examples/0mq/server.nim
Normal file → Executable file
|
|
@ -185,6 +185,8 @@ if [ $# -eq 1 ] ; then
|
||||||
chmod 644 $libdir/system/gc.nim
|
chmod 644 $libdir/system/gc.nim
|
||||||
cp lib/system/hti.nim $libdir/system/hti.nim || exit 1
|
cp lib/system/hti.nim $libdir/system/hti.nim || exit 1
|
||||||
chmod 644 $libdir/system/hti.nim
|
chmod 644 $libdir/system/hti.nim
|
||||||
|
cp lib/system/inboxes.nim $libdir/system/inboxes.nim || exit 1
|
||||||
|
chmod 644 $libdir/system/inboxes.nim
|
||||||
cp lib/system/inclrtl.nim $libdir/system/inclrtl.nim || exit 1
|
cp lib/system/inclrtl.nim $libdir/system/inclrtl.nim || exit 1
|
||||||
chmod 644 $libdir/system/inclrtl.nim
|
chmod 644 $libdir/system/inclrtl.nim
|
||||||
cp lib/system/mmdisp.nim $libdir/system/mmdisp.nim || exit 1
|
cp lib/system/mmdisp.nim $libdir/system/mmdisp.nim || exit 1
|
||||||
|
|
@ -197,6 +199,8 @@ if [ $# -eq 1 ] ; then
|
||||||
chmod 644 $libdir/system/sets.nim
|
chmod 644 $libdir/system/sets.nim
|
||||||
cp lib/system/sysio.nim $libdir/system/sysio.nim || exit 1
|
cp lib/system/sysio.nim $libdir/system/sysio.nim || exit 1
|
||||||
chmod 644 $libdir/system/sysio.nim
|
chmod 644 $libdir/system/sysio.nim
|
||||||
|
cp lib/system/syslocks.nim $libdir/system/syslocks.nim || exit 1
|
||||||
|
chmod 644 $libdir/system/syslocks.nim
|
||||||
cp lib/system/sysstr.nim $libdir/system/sysstr.nim || exit 1
|
cp lib/system/sysstr.nim $libdir/system/sysstr.nim || exit 1
|
||||||
chmod 644 $libdir/system/sysstr.nim
|
chmod 644 $libdir/system/sysstr.nim
|
||||||
cp lib/system/threads.nim $libdir/system/threads.nim || exit 1
|
cp lib/system/threads.nim $libdir/system/threads.nim || exit 1
|
||||||
|
|
@ -237,8 +241,6 @@ if [ $# -eq 1 ] ; then
|
||||||
chmod 644 $libdir/pure/json.nim
|
chmod 644 $libdir/pure/json.nim
|
||||||
cp lib/pure/lexbase.nim $libdir/pure/lexbase.nim || exit 1
|
cp lib/pure/lexbase.nim $libdir/pure/lexbase.nim || exit 1
|
||||||
chmod 644 $libdir/pure/lexbase.nim
|
chmod 644 $libdir/pure/lexbase.nim
|
||||||
cp lib/pure/logging.nim $libdir/pure/logging.nim || exit 1
|
|
||||||
chmod 644 $libdir/pure/logging.nim
|
|
||||||
cp lib/pure/marshal.nim $libdir/pure/marshal.nim || exit 1
|
cp lib/pure/marshal.nim $libdir/pure/marshal.nim || exit 1
|
||||||
chmod 644 $libdir/pure/marshal.nim
|
chmod 644 $libdir/pure/marshal.nim
|
||||||
cp lib/pure/math.nim $libdir/pure/math.nim || exit 1
|
cp lib/pure/math.nim $libdir/pure/math.nim || exit 1
|
||||||
|
|
@ -301,8 +303,6 @@ if [ $# -eq 1 ] ; then
|
||||||
chmod 644 $libdir/pure/xmlparser.nim
|
chmod 644 $libdir/pure/xmlparser.nim
|
||||||
cp lib/pure/xmltree.nim $libdir/pure/xmltree.nim || exit 1
|
cp lib/pure/xmltree.nim $libdir/pure/xmltree.nim || exit 1
|
||||||
chmod 644 $libdir/pure/xmltree.nim
|
chmod 644 $libdir/pure/xmltree.nim
|
||||||
cp lib/pure/yamllexer.nim $libdir/pure/yamllexer.nim || exit 1
|
|
||||||
chmod 644 $libdir/pure/yamllexer.nim
|
|
||||||
cp lib/impure/db_mysql.nim $libdir/impure/db_mysql.nim || exit 1
|
cp lib/impure/db_mysql.nim $libdir/impure/db_mysql.nim || exit 1
|
||||||
chmod 644 $libdir/impure/db_mysql.nim
|
chmod 644 $libdir/impure/db_mysql.nim
|
||||||
cp lib/impure/db_postgres.nim $libdir/impure/db_postgres.nim || exit 1
|
cp lib/impure/db_postgres.nim $libdir/impure/db_postgres.nim || exit 1
|
||||||
|
|
|
||||||
8
lib/core/typeinfo.nim
Normal file → Executable file
8
lib/core/typeinfo.nim
Normal file → Executable file
|
|
@ -45,8 +45,8 @@ type
|
||||||
TAny* = object {.pure.} ## can represent any nimrod value; NOTE: the wrapped
|
TAny* = object {.pure.} ## can represent any nimrod value; NOTE: the wrapped
|
||||||
## value can be modified with its wrapper! This means
|
## value can be modified with its wrapper! This means
|
||||||
## that ``TAny`` keeps a non-traced pointer to its
|
## that ``TAny`` keeps a non-traced pointer to its
|
||||||
## wrapped value and MUST not live longer than its
|
## wrapped value and **must not** live longer than
|
||||||
## wrapped value.
|
## its wrapped value.
|
||||||
value: pointer
|
value: pointer
|
||||||
rawType: PNimType
|
rawType: PNimType
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ proc newAny(value: pointer, rawType: PNimType): TAny =
|
||||||
proc toAny*[T](x: var T): TAny {.inline.} =
|
proc toAny*[T](x: var T): TAny {.inline.} =
|
||||||
## constructs a ``TAny`` object from `x`. This captures `x`'s address, so
|
## constructs a ``TAny`` object from `x`. This captures `x`'s address, so
|
||||||
## `x` can be modified with its ``TAny`` wrapper! The client needs to ensure
|
## `x` can be modified with its ``TAny`` wrapper! The client needs to ensure
|
||||||
## that the wrapper DOES NOT live longer than `x`!
|
## that the wrapper **does not** live longer than `x`!
|
||||||
result.value = addr(x)
|
result.value = addr(x)
|
||||||
result.rawType = cast[PNimType](getTypeInfo(x))
|
result.rawType = cast[PNimType](getTypeInfo(x))
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@ proc kind*(x: TAny): TAnyKind {.inline.} =
|
||||||
result = TAnyKind(ord(x.rawType.kind))
|
result = TAnyKind(ord(x.rawType.kind))
|
||||||
|
|
||||||
proc baseTypeKind*(x: TAny): TAnyKind {.inline.} =
|
proc baseTypeKind*(x: TAny): TAnyKind {.inline.} =
|
||||||
## get the base type's kind; akNone is returned if `x` has no base type.
|
## get the base type's kind; ``akNone`` is returned if `x` has no base type.
|
||||||
if x.rawType.base != nil:
|
if x.rawType.base != nil:
|
||||||
result = TAnyKind(ord(x.rawType.base.kind))
|
result = TAnyKind(ord(x.rawType.base.kind))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ proc replacef*(s: string, sub: TRegEx, by: string): string =
|
||||||
## with the notation ``$i`` and ``$#`` (see strutils.`%`). Examples:
|
## with the notation ``$i`` and ``$#`` (see strutils.`%`). Examples:
|
||||||
##
|
##
|
||||||
## .. code-block:: nimrod
|
## .. code-block:: nimrod
|
||||||
## "var1=key; var2=key2".replace(re"(\w+)'='(\w+)", "$1<-$2$2")
|
## "var1=key; var2=key2".replacef(re"(\w+)'='(\w+)", "$1<-$2$2")
|
||||||
##
|
##
|
||||||
## Results in:
|
## Results in:
|
||||||
##
|
##
|
||||||
|
|
|
||||||
0
lib/prelude.nim
Normal file → Executable file
0
lib/prelude.nim
Normal file → Executable file
4
lib/pure/collections/intsets.nim
Normal file → Executable file
4
lib/pure/collections/intsets.nim
Normal file → Executable file
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
## The ``intsets`` module implements an efficient int set implemented as a
|
## The ``intsets`` module implements an efficient int set implemented as a
|
||||||
## sparse bit set.
|
## sparse bit set.
|
||||||
## **Note**: Since Nimrod does not allow the assignment operator to be
|
## **Note**: Since Nimrod currently does not allow the assignment operator to
|
||||||
## overloaded, ``=`` for int sets performs some rather meaningless shallow
|
## be overloaded, ``=`` for int sets performs some rather meaningless shallow
|
||||||
## copy.
|
## copy.
|
||||||
|
|
||||||
import
|
import
|
||||||
|
|
|
||||||
0
lib/pure/collections/queues.nim
Normal file → Executable file
0
lib/pure/collections/queues.nim
Normal file → Executable file
6
lib/pure/collections/sets.nim
Normal file → Executable file
6
lib/pure/collections/sets.nim
Normal file → Executable file
|
|
@ -9,9 +9,9 @@
|
||||||
|
|
||||||
## The ``sets`` module implements an efficient hash set and ordered hash set.
|
## The ``sets`` module implements an efficient hash set and ordered hash set.
|
||||||
##
|
##
|
||||||
## Note: The data types declared here have *value semantics*: This means that
|
## **Note**: The data types declared here have *value semantics*: This means
|
||||||
## ``=`` performs a copy of the hash table. If you are overly concerned with
|
## that ``=`` performs a copy of the hash table. If you are overly concerned
|
||||||
## efficiency and know what you do (!), you can define the symbol
|
## with efficiency and know what you do (!), you can define the symbol
|
||||||
## ``shallowADT`` to compile a version that uses shallow copies instead.
|
## ``shallowADT`` to compile a version that uses shallow copies instead.
|
||||||
|
|
||||||
import
|
import
|
||||||
|
|
|
||||||
8
lib/pure/collections/tables.nim
Normal file → Executable file
8
lib/pure/collections/tables.nim
Normal file → Executable file
|
|
@ -10,9 +10,9 @@
|
||||||
## The ``tables`` module implements an efficient hash table that is
|
## The ``tables`` module implements an efficient hash table that is
|
||||||
## a mapping from keys to values.
|
## a mapping from keys to values.
|
||||||
##
|
##
|
||||||
## Note: The data types declared here have *value semantics*: This means that
|
## **Note:** The data types declared here have *value semantics*: This means
|
||||||
## ``=`` performs a copy of the hash table. If you are overly concerned with
|
## that ``=`` performs a copy of the hash table. If you are overly concerned
|
||||||
## efficiency and know what you do (!), you can define the symbol
|
## with efficiency and know what you do (!), you can define the symbol
|
||||||
## ``shallowADT`` to compile a version that uses shallow copies instead.
|
## ``shallowADT`` to compile a version that uses shallow copies instead.
|
||||||
|
|
||||||
import
|
import
|
||||||
|
|
@ -27,7 +27,7 @@ type
|
||||||
TSlotEnum = enum seEmpty, seFilled, seDeleted
|
TSlotEnum = enum seEmpty, seFilled, seDeleted
|
||||||
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
||||||
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
||||||
TTable* {.final, myShallow.}[A, B] = object
|
TTable* {.final, myShallow.}[A, B] = object ## generic hash table
|
||||||
data: TKeyValuePairSeq[A, B]
|
data: TKeyValuePairSeq[A, B]
|
||||||
counter: int
|
counter: int
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -366,10 +366,12 @@ when defined(Windows) and not defined(useNimRtl):
|
||||||
result.id = procInfo.dwProcessID
|
result.id = procInfo.dwProcessID
|
||||||
|
|
||||||
proc close(p: PProcess) =
|
proc close(p: PProcess) =
|
||||||
discard CloseHandle(p.inputHandle)
|
when false:
|
||||||
discard CloseHandle(p.outputHandle)
|
# somehow this does not work on Windows:
|
||||||
discard CloseHandle(p.errorHandle)
|
discard CloseHandle(p.inputHandle)
|
||||||
discard CloseHandle(p.FProcessHandle)
|
discard CloseHandle(p.outputHandle)
|
||||||
|
discard CloseHandle(p.errorHandle)
|
||||||
|
discard CloseHandle(p.FProcessHandle)
|
||||||
|
|
||||||
proc suspend(p: PProcess) =
|
proc suspend(p: PProcess) =
|
||||||
discard SuspendThread(p.FProcessHandle)
|
discard SuspendThread(p.FProcessHandle)
|
||||||
|
|
|
||||||
0
lib/pure/redis.nim
Normal file → Executable file
0
lib/pure/redis.nim
Normal file → Executable file
0
lib/pure/romans.nim
Normal file → Executable file
0
lib/pure/romans.nim
Normal file → Executable file
|
|
@ -168,6 +168,7 @@ proc createMessage*(mSubject, mBody: string, mTo,
|
||||||
result.msgOtherHeaders = newStringTable()
|
result.msgOtherHeaders = newStringTable()
|
||||||
|
|
||||||
proc `$`*(msg: TMessage): string =
|
proc `$`*(msg: TMessage): string =
|
||||||
|
## stringify for ``TMessage``.
|
||||||
result = ""
|
result = ""
|
||||||
if msg.msgTo.len() > 0:
|
if msg.msgTo.len() > 0:
|
||||||
result = "TO: " & msg.msgTo.join(", ") & "\c\L"
|
result = "TO: " & msg.msgTo.join(", ") & "\c\L"
|
||||||
|
|
|
||||||
|
|
@ -1456,7 +1456,7 @@ else:
|
||||||
`x`[0][len] = 0
|
`x`[0][len] = 0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc echo*[Ty](x: openarray[Ty]) {.magic: "Echo".}
|
proc echo*[Ty](x: openarray[Ty]) {.magic: "Echo", noSideEffect.}
|
||||||
## special built-in that takes a variable number of arguments. Each argument
|
## special built-in that takes a variable number of arguments. Each argument
|
||||||
## is converted to a string via ``$``, so it works for user-defined
|
## is converted to a string via ``$``, so it works for user-defined
|
||||||
## types that have an overloaded ``$`` operator.
|
## types that have an overloaded ``$`` operator.
|
||||||
|
|
|
||||||
|
|
@ -66,8 +66,11 @@ elif defined(windows):
|
||||||
if result == nil: raiseOutOfMem()
|
if result == nil: raiseOutOfMem()
|
||||||
|
|
||||||
proc osDeallocPages(p: pointer, size: int) {.inline.} =
|
proc osDeallocPages(p: pointer, size: int) {.inline.} =
|
||||||
# according to Microsoft, 0 is the only correct value here:
|
# according to Microsoft, 0 is the only correct value for MEM_RELEASE:
|
||||||
when reallyOsDealloc: VirtualFree(p, 0, MEM_RELEASE)
|
# This means that the OS has some different view over how big the block is
|
||||||
|
# that we want to free! So, we cannot reliably release the memory back to
|
||||||
|
# Windows :-(. We have to live with MEM_DECOMMIT instead.
|
||||||
|
when reallyOsDealloc: VirtualFree(p, size, MEM_DECOMMIT)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
{.error: "Port memory manager to your platform".}
|
{.error: "Port memory manager to your platform".}
|
||||||
|
|
|
||||||
3
lib/system/atomics.nim
Normal file → Executable file
3
lib/system/atomics.nim
Normal file → Executable file
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
## Atomic operations for Nimrod.
|
## Atomic operations for Nimrod.
|
||||||
|
|
||||||
when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport:
|
when (defined(gcc) or defined(llvm_gcc)) and hasThreadSupport and
|
||||||
|
not defined(windows):
|
||||||
proc sync_add_and_fetch(p: var int, val: int): int {.
|
proc sync_add_and_fetch(p: var int, val: int): int {.
|
||||||
importc: "__sync_add_and_fetch", nodecl.}
|
importc: "__sync_add_and_fetch", nodecl.}
|
||||||
proc sync_sub_and_fetch(p: var int, val: int): int {.
|
proc sync_sub_and_fetch(p: var int, val: int): int {.
|
||||||
|
|
|
||||||
36
lib/system/inboxes.nim
Normal file → Executable file
36
lib/system/inboxes.nim
Normal file → Executable file
|
|
@ -7,8 +7,12 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
## Message passing for threads. The current implementation is slow and does
|
## Message passing for threads. **Note**: This is part of the system module.
|
||||||
## not work with cyclic data structures. But hey, it's better than nothing.
|
## Do not import it directly. To activate thread support you need to compile
|
||||||
|
## with the ``--threads:on`` command line switch.
|
||||||
|
##
|
||||||
|
## **Note:** The current implementation of message passing is slow and does
|
||||||
|
## not work with cyclic data structures.
|
||||||
|
|
||||||
type
|
type
|
||||||
pbytes = ptr array[0.. 0xffff, byte]
|
pbytes = ptr array[0.. 0xffff, byte]
|
||||||
|
|
@ -18,6 +22,7 @@ type
|
||||||
lock: TSysLock
|
lock: TSysLock
|
||||||
cond: TSysCond
|
cond: TSysCond
|
||||||
elemType: PNimType
|
elemType: PNimType
|
||||||
|
ready: bool
|
||||||
region: TMemRegion
|
region: TMemRegion
|
||||||
PInbox = ptr TInbox
|
PInbox = ptr TInbox
|
||||||
TLoadStoreMode = enum mStore, mLoad
|
TLoadStoreMode = enum mStore, mLoad
|
||||||
|
|
@ -178,9 +183,7 @@ template lockInbox(q: expr, action: stmt) =
|
||||||
action
|
action
|
||||||
releaseSys(q.lock)
|
releaseSys(q.lock)
|
||||||
|
|
||||||
proc send*[TMsg](receiver: var TThread[TMsg], msg: TMsg) =
|
template sendImpl(q: expr) =
|
||||||
## sends a message to a thread. `msg` is deeply copied.
|
|
||||||
var q = cast[PInbox](getInBoxMem(receiver))
|
|
||||||
if q.mask == ThreadDeadMask:
|
if q.mask == ThreadDeadMask:
|
||||||
raise newException(EDeadThread, "cannot send message; thread died")
|
raise newException(EDeadThread, "cannot send message; thread died")
|
||||||
acquireSys(q.lock)
|
acquireSys(q.lock)
|
||||||
|
|
@ -192,12 +195,24 @@ proc send*[TMsg](receiver: var TThread[TMsg], msg: TMsg) =
|
||||||
releaseSys(q.lock)
|
releaseSys(q.lock)
|
||||||
SignalSysCond(q.cond)
|
SignalSysCond(q.cond)
|
||||||
|
|
||||||
|
proc send*[TMsg](receiver: var TThread[TMsg], msg: TMsg) =
|
||||||
|
## sends a message to a thread. `msg` is deeply copied.
|
||||||
|
var q = cast[PInbox](getInBoxMem(receiver))
|
||||||
|
sendImpl(q)
|
||||||
|
|
||||||
|
proc send*[TMsg](receiver: TThreadId[TMsg], msg: TMsg) =
|
||||||
|
## sends a message to a thread. `msg` is deeply copied.
|
||||||
|
var q = cast[PInbox](getInBoxMem(receiver[]))
|
||||||
|
sendImpl(q)
|
||||||
|
|
||||||
proc llRecv(res: pointer, typ: PNimType) =
|
proc llRecv(res: pointer, typ: PNimType) =
|
||||||
# to save space, the generic is as small as possible
|
# to save space, the generic is as small as possible
|
||||||
var q = cast[PInbox](getInBoxMem())
|
var q = cast[PInbox](getInBoxMem())
|
||||||
acquireSys(q.lock)
|
acquireSys(q.lock)
|
||||||
|
q.ready = true
|
||||||
while q.count <= 0:
|
while q.count <= 0:
|
||||||
WaitSysCond(q.cond, q.lock)
|
WaitSysCond(q.cond, q.lock)
|
||||||
|
q.ready = false
|
||||||
if typ != q.elemType:
|
if typ != q.elemType:
|
||||||
releaseSys(q.lock)
|
releaseSys(q.lock)
|
||||||
raise newException(EInvalidValue, "cannot receive message of wrong type")
|
raise newException(EInvalidValue, "cannot receive message of wrong type")
|
||||||
|
|
@ -215,4 +230,15 @@ proc peek*(): int =
|
||||||
lockInbox(q):
|
lockInbox(q):
|
||||||
result = q.count
|
result = q.count
|
||||||
|
|
||||||
|
proc peek*[TMsg](t: var TThread[TMsg]): int =
|
||||||
|
## returns the current number of messages in the inbox of thread `t`.
|
||||||
|
var q = cast[PInbox](getInBoxMem(t))
|
||||||
|
if q.mask != ThreadDeadMask:
|
||||||
|
lockInbox(q):
|
||||||
|
result = q.count
|
||||||
|
|
||||||
|
proc ready*[TMsg](t: var TThread[TMsg]): bool =
|
||||||
|
## returns true iff the thread `t` is waiting on ``recv`` for new messages.
|
||||||
|
var q = cast[PInbox](getInBoxMem(t))
|
||||||
|
result = q.ready
|
||||||
|
|
||||||
|
|
|
||||||
2
lib/system/syslocks.nim
Normal file → Executable file
2
lib/system/syslocks.nim
Normal file → Executable file
|
|
@ -47,7 +47,7 @@ when defined(Windows):
|
||||||
proc CreateEvent(lpEventAttributes: pointer,
|
proc CreateEvent(lpEventAttributes: pointer,
|
||||||
bManualReset, bInitialState: int32,
|
bManualReset, bInitialState: int32,
|
||||||
lpName: cstring): TSysCond {.stdcall, noSideEffect,
|
lpName: cstring): TSysCond {.stdcall, noSideEffect,
|
||||||
dynlib: "kernel32", importc: "CreateEvent".}
|
dynlib: "kernel32", importc: "CreateEventA".}
|
||||||
|
|
||||||
proc CloseHandle(hObject: THandle) {.stdcall, noSideEffect,
|
proc CloseHandle(hObject: THandle) {.stdcall, noSideEffect,
|
||||||
dynlib: "kernel32", importc: "CloseHandle".}
|
dynlib: "kernel32", importc: "CloseHandle".}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
## Thread support for Nimrod. **Note**: This is part of the system module.
|
## Thread support for Nimrod. **Note**: This is part of the system module.
|
||||||
## Do not import it directly. To active thread support you need to compile
|
## Do not import it directly. To activate thread support you need to compile
|
||||||
## with the ``--threads:on`` command line switch.
|
## with the ``--threads:on`` command line switch.
|
||||||
##
|
##
|
||||||
## Nimrod's memory model for threads is quite different from other common
|
## Nimrod's memory model for threads is quite different from other common
|
||||||
|
|
@ -39,8 +39,8 @@
|
||||||
|
|
||||||
const
|
const
|
||||||
maxRegisters = 256 # don't think there is an arch with more registers
|
maxRegisters = 256 # don't think there is an arch with more registers
|
||||||
maxLocksPerThread* = 10 ## max number of locks a thread can hold
|
maxLocksPerThread = 10 ## max number of locks a thread can hold
|
||||||
## at the same time
|
## at the same time
|
||||||
useStackMaskHack = false ## use the stack mask hack for better performance
|
useStackMaskHack = false ## use the stack mask hack for better performance
|
||||||
StackGuardSize = 4096
|
StackGuardSize = 4096
|
||||||
ThreadStackMask = 1024*256*sizeof(int)-1
|
ThreadStackMask = 1024*256*sizeof(int)-1
|
||||||
|
|
@ -167,14 +167,17 @@ type
|
||||||
PGcThread = ptr TGcThread
|
PGcThread = ptr TGcThread
|
||||||
TGcThread {.pure.} = object
|
TGcThread {.pure.} = object
|
||||||
sys: TSysThread
|
sys: TSysThread
|
||||||
next, prev: PGcThread
|
|
||||||
stackBottom, stackTop: pointer
|
|
||||||
stackSize: int
|
|
||||||
inbox: TThreadLocalStorage
|
inbox: TThreadLocalStorage
|
||||||
when emulatedThreadVars and not useStackMaskHack:
|
when emulatedThreadVars and not useStackMaskHack:
|
||||||
tls: TThreadLocalStorage
|
tls: TThreadLocalStorage
|
||||||
else:
|
else:
|
||||||
nil
|
nil
|
||||||
|
when hasSharedHeap:
|
||||||
|
next, prev: PGcThread
|
||||||
|
stackBottom, stackTop: pointer
|
||||||
|
stackSize: int
|
||||||
|
else:
|
||||||
|
nil
|
||||||
|
|
||||||
# XXX it'd be more efficient to not use a global variable for the
|
# XXX it'd be more efficient to not use a global variable for the
|
||||||
# thread storage slot, but to rely on the implementation to assign slot 0
|
# thread storage slot, but to rely on the implementation to assign slot 0
|
||||||
|
|
@ -202,43 +205,44 @@ when not defined(useNimRtl):
|
||||||
initStackBottom()
|
initStackBottom()
|
||||||
initGC()
|
initGC()
|
||||||
|
|
||||||
var heapLock: TSysLock
|
|
||||||
InitSysLock(HeapLock)
|
|
||||||
|
|
||||||
when emulatedThreadVars:
|
when emulatedThreadVars:
|
||||||
if NimThreadVarsSize() > sizeof(TThreadLocalStorage):
|
if NimThreadVarsSize() > sizeof(TThreadLocalStorage):
|
||||||
echo "too large thread local storage size requested"
|
echo "too large thread local storage size requested"
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
var
|
when hasSharedHeap:
|
||||||
threadList: PGcThread
|
var heapLock: TSysLock
|
||||||
|
InitSysLock(HeapLock)
|
||||||
|
|
||||||
proc registerThread(t: PGcThread) =
|
var
|
||||||
# we need to use the GC global lock here!
|
threadList: PGcThread
|
||||||
AcquireSys(HeapLock)
|
|
||||||
t.prev = nil
|
|
||||||
t.next = threadList
|
|
||||||
if threadList != nil:
|
|
||||||
sysAssert(threadList.prev == nil)
|
|
||||||
threadList.prev = t
|
|
||||||
threadList = t
|
|
||||||
ReleaseSys(HeapLock)
|
|
||||||
|
|
||||||
proc unregisterThread(t: PGcThread) =
|
proc registerThread(t: PGcThread) =
|
||||||
# we need to use the GC global lock here!
|
# we need to use the GC global lock here!
|
||||||
AcquireSys(HeapLock)
|
AcquireSys(HeapLock)
|
||||||
if t == threadList: threadList = t.next
|
t.prev = nil
|
||||||
if t.next != nil: t.next.prev = t.prev
|
t.next = threadList
|
||||||
if t.prev != nil: t.prev.next = t.next
|
if threadList != nil:
|
||||||
# so that a thread can be unregistered twice which might happen if the
|
sysAssert(threadList.prev == nil)
|
||||||
# code executes `destroyThread`:
|
threadList.prev = t
|
||||||
t.next = nil
|
threadList = t
|
||||||
t.prev = nil
|
ReleaseSys(HeapLock)
|
||||||
ReleaseSys(HeapLock)
|
|
||||||
|
|
||||||
# on UNIX, the GC uses ``SIGFREEZE`` to tell every thread to stop so that
|
proc unregisterThread(t: PGcThread) =
|
||||||
# the GC can examine the stacks?
|
# we need to use the GC global lock here!
|
||||||
proc stopTheWord() = nil
|
AcquireSys(HeapLock)
|
||||||
|
if t == threadList: threadList = t.next
|
||||||
|
if t.next != nil: t.next.prev = t.prev
|
||||||
|
if t.prev != nil: t.prev.next = t.next
|
||||||
|
# so that a thread can be unregistered twice which might happen if the
|
||||||
|
# code executes `destroyThread`:
|
||||||
|
t.next = nil
|
||||||
|
t.prev = nil
|
||||||
|
ReleaseSys(HeapLock)
|
||||||
|
|
||||||
|
# on UNIX, the GC uses ``SIGFREEZE`` to tell every thread to stop so that
|
||||||
|
# the GC can examine the stacks?
|
||||||
|
proc stopTheWord() = nil
|
||||||
|
|
||||||
# We jump through some hops here to ensure that Nimrod thread procs can have
|
# We jump through some hops here to ensure that Nimrod thread procs can have
|
||||||
# the Nimrod calling convention. This is needed because thread procs are
|
# the Nimrod calling convention. This is needed because thread procs are
|
||||||
|
|
@ -248,10 +252,15 @@ when not defined(useNimRtl):
|
||||||
# GC'ed closures in Nimrod.
|
# GC'ed closures in Nimrod.
|
||||||
|
|
||||||
type
|
type
|
||||||
TThread* {.pure, final.}[TParam] = object of TGcThread ## Nimrod thread.
|
TThread* {.pure, final.}[TMsg] =
|
||||||
|
object of TGcThread ## Nimrod thread. A thread is a heavy object (~14K)
|
||||||
|
## that should not be part of a message! Use
|
||||||
|
## a ``TThreadId`` for that.
|
||||||
emptyFn: proc ()
|
emptyFn: proc ()
|
||||||
dataFn: proc (p: TParam)
|
dataFn: proc (p: TMsg)
|
||||||
data: TParam
|
data: TMsg
|
||||||
|
TThreadId*[TMsg] = ptr TThread[TMsg] ## the current implementation uses
|
||||||
|
## a pointer as a thread ID.
|
||||||
|
|
||||||
proc initInbox(p: pointer)
|
proc initInbox(p: pointer)
|
||||||
proc freeInbox(p: pointer)
|
proc freeInbox(p: pointer)
|
||||||
|
|
@ -260,47 +269,47 @@ when not defined(boehmgc) and not hasSharedHeap:
|
||||||
|
|
||||||
template ThreadProcWrapperBody(closure: expr) =
|
template ThreadProcWrapperBody(closure: expr) =
|
||||||
ThreadVarSetValue(globalsSlot, closure)
|
ThreadVarSetValue(globalsSlot, closure)
|
||||||
var t = cast[ptr TThread[TParam]](closure)
|
var t = cast[ptr TThread[TMsg]](closure)
|
||||||
when useStackMaskHack:
|
when useStackMaskHack:
|
||||||
var tls: TThreadLocalStorage
|
var tls: TThreadLocalStorage
|
||||||
when not defined(boehmgc) and not hasSharedHeap:
|
when not defined(boehmgc) and not hasSharedHeap:
|
||||||
# init the GC for this thread:
|
# init the GC for this thread:
|
||||||
setStackBottom(addr(t))
|
setStackBottom(addr(t))
|
||||||
initGC()
|
initGC()
|
||||||
t.stackBottom = addr(t)
|
when hasSharedHeap:
|
||||||
registerThread(t)
|
t.stackBottom = addr(t)
|
||||||
try:
|
registerThread(t)
|
||||||
when false:
|
if t.emptyFn == nil: t.dataFn(t.data)
|
||||||
var a = addr(tls)
|
else: t.emptyFn()
|
||||||
var b = MaskStackPointer(1293920-372736-303104-36864)
|
#finally:
|
||||||
c_fprintf(c_stdout, "TLS: %p\nmasked: %p\ndiff: %ld\n",
|
# XXX shut-down is not executed when the thread is forced down!
|
||||||
a, b, cast[int](a) - cast[int](b))
|
freeInbox(addr(t.inbox))
|
||||||
if t.emptyFn == nil: t.dataFn(t.data)
|
when hasSharedHeap: unregisterThread(t)
|
||||||
else: t.emptyFn()
|
when defined(deallocOsPages): deallocOsPages()
|
||||||
finally:
|
# Since an unhandled exception terminates the whole process (!), there is
|
||||||
# XXX shut-down is not executed when the thread is forced down!
|
# no need for a ``try finally`` here, nor would it be correct: The current
|
||||||
freeInbox(addr(t.inbox))
|
# exception is tried to be re-raised by the code-gen after the ``finally``!
|
||||||
unregisterThread(t)
|
# However this is doomed to fail, because we already unmapped every heap
|
||||||
when defined(deallocOsPages): deallocOsPages()
|
# page!
|
||||||
|
|
||||||
{.push stack_trace:off.}
|
{.push stack_trace:off.}
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
proc threadProcWrapper[TParam](closure: pointer): int32 {.stdcall.} =
|
proc threadProcWrapper[TMsg](closure: pointer): int32 {.stdcall.} =
|
||||||
ThreadProcWrapperBody(closure)
|
ThreadProcWrapperBody(closure)
|
||||||
# implicitely return 0
|
# implicitely return 0
|
||||||
else:
|
else:
|
||||||
proc threadProcWrapper[TParam](closure: pointer) {.noconv.} =
|
proc threadProcWrapper[TMsg](closure: pointer) {.noconv.} =
|
||||||
ThreadProcWrapperBody(closure)
|
ThreadProcWrapperBody(closure)
|
||||||
{.pop.}
|
{.pop.}
|
||||||
|
|
||||||
proc joinThread*[TParam](t: TThread[TParam]) {.inline.} =
|
proc joinThread*[TMsg](t: TThread[TMsg]) {.inline.} =
|
||||||
## waits for the thread `t` to finish.
|
## waits for the thread `t` to finish.
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
discard WaitForSingleObject(t.sys, -1'i32)
|
discard WaitForSingleObject(t.sys, -1'i32)
|
||||||
else:
|
else:
|
||||||
discard pthread_join(t.sys, nil)
|
discard pthread_join(t.sys, nil)
|
||||||
|
|
||||||
proc joinThreads*[TParam](t: openArray[TThread[TParam]]) =
|
proc joinThreads*[TMsg](t: openArray[TThread[TMsg]]) =
|
||||||
## waits for every thread in `t` to finish.
|
## waits for every thread in `t` to finish.
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
var a: array[0..255, TSysThread]
|
var a: array[0..255, TSysThread]
|
||||||
|
|
@ -312,7 +321,7 @@ proc joinThreads*[TParam](t: openArray[TThread[TParam]]) =
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
# XXX a thread should really release its heap here somehow:
|
# XXX a thread should really release its heap here somehow:
|
||||||
proc destroyThread*[TParam](t: var TThread[TParam]) =
|
proc destroyThread*[TMsg](t: var TThread[TMsg]) =
|
||||||
## forces the thread `t` to terminate. This is potentially dangerous if
|
## forces the thread `t` to terminate. This is potentially dangerous if
|
||||||
## you don't have full control over `t` and its acquired resources.
|
## you don't have full control over `t` and its acquired resources.
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
|
|
@ -321,18 +330,18 @@ when false:
|
||||||
discard pthread_cancel(t.sys)
|
discard pthread_cancel(t.sys)
|
||||||
unregisterThread(addr(t))
|
unregisterThread(addr(t))
|
||||||
|
|
||||||
proc createThread*[TParam](t: var TThread[TParam],
|
proc createThread*[TMsg](t: var TThread[TMsg],
|
||||||
tp: proc (param: TParam) {.thread.},
|
tp: proc (msg: TMsg) {.thread.},
|
||||||
param: TParam) =
|
param: TMsg) =
|
||||||
## creates a new thread `t` and starts its execution. Entry point is the
|
## creates a new thread `t` and starts its execution. Entry point is the
|
||||||
## proc `tp`. `param` is passed to `tp`.
|
## proc `tp`. `param` is passed to `tp`.
|
||||||
t.data = param
|
t.data = param
|
||||||
t.dataFn = tp
|
t.dataFn = tp
|
||||||
t.stackSize = ThreadStackSize
|
when hasSharedHeap: t.stackSize = ThreadStackSize
|
||||||
initInbox(addr(t.inbox))
|
initInbox(addr(t.inbox))
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
var dummyThreadId: int32
|
var dummyThreadId: int32
|
||||||
t.sys = CreateThread(nil, ThreadStackSize, threadProcWrapper[TParam],
|
t.sys = CreateThread(nil, ThreadStackSize, threadProcWrapper[TMsg],
|
||||||
addr(t), 0'i32, dummyThreadId)
|
addr(t), 0'i32, dummyThreadId)
|
||||||
if t.sys <= 0:
|
if t.sys <= 0:
|
||||||
raise newException(EResourceExhausted, "cannot create thread")
|
raise newException(EResourceExhausted, "cannot create thread")
|
||||||
|
|
@ -340,18 +349,18 @@ proc createThread*[TParam](t: var TThread[TParam],
|
||||||
var a: Tpthread_attr
|
var a: Tpthread_attr
|
||||||
pthread_attr_init(a)
|
pthread_attr_init(a)
|
||||||
pthread_attr_setstacksize(a, ThreadStackSize)
|
pthread_attr_setstacksize(a, ThreadStackSize)
|
||||||
if pthread_create(t.sys, a, threadProcWrapper[TParam], addr(t)) != 0:
|
if pthread_create(t.sys, a, threadProcWrapper[TMsg], addr(t)) != 0:
|
||||||
raise newException(EResourceExhausted, "cannot create thread")
|
raise newException(EResourceExhausted, "cannot create thread")
|
||||||
|
|
||||||
proc createThread*[TParam](t: var TThread[TParam], tp: proc () {.thread.}) =
|
proc createThread*[TMsg](t: var TThread[TMsg], tp: proc () {.thread.}) =
|
||||||
## creates a new thread `t` and starts its execution. Entry point is the
|
## creates a new thread `t` and starts its execution. Entry point is the
|
||||||
## proc `tp`.
|
## proc `tp`.
|
||||||
t.emptyFn = tp
|
t.emptyFn = tp
|
||||||
t.stackSize = ThreadStackSize
|
when hasSharedHeap: t.stackSize = ThreadStackSize
|
||||||
initInbox(addr(t.inbox))
|
initInbox(addr(t.inbox))
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
var dummyThreadId: int32
|
var dummyThreadId: int32
|
||||||
t.sys = CreateThread(nil, ThreadStackSize, threadProcWrapper[TParam],
|
t.sys = CreateThread(nil, ThreadStackSize, threadProcWrapper[TMsg],
|
||||||
addr(t), 0'i32, dummyThreadId)
|
addr(t), 0'i32, dummyThreadId)
|
||||||
if t.sys <= 0:
|
if t.sys <= 0:
|
||||||
raise newException(EResourceExhausted, "cannot create thread")
|
raise newException(EResourceExhausted, "cannot create thread")
|
||||||
|
|
@ -359,9 +368,17 @@ proc createThread*[TParam](t: var TThread[TParam], tp: proc () {.thread.}) =
|
||||||
var a: Tpthread_attr
|
var a: Tpthread_attr
|
||||||
pthread_attr_init(a)
|
pthread_attr_init(a)
|
||||||
pthread_attr_setstacksize(a, ThreadStackSize)
|
pthread_attr_setstacksize(a, ThreadStackSize)
|
||||||
if pthread_create(t.sys, a, threadProcWrapper[TParam], addr(t)) != 0:
|
if pthread_create(t.sys, a, threadProcWrapper[TMsg], addr(t)) != 0:
|
||||||
raise newException(EResourceExhausted, "cannot create thread")
|
raise newException(EResourceExhausted, "cannot create thread")
|
||||||
|
|
||||||
|
proc threadId*[TMsg](t: var TThread[TMsg]): TThreadId[TMsg] {.inline.} =
|
||||||
|
## returns the thread ID of `t`.
|
||||||
|
result = addr(t)
|
||||||
|
|
||||||
|
proc myThreadId*[TMsg](): TThreadId[TMsg] =
|
||||||
|
## returns the thread ID of the thread that calls this proc.
|
||||||
|
result = cast[TThreadId[TMsg]](ThreadVarGetValue(globalsSlot))
|
||||||
|
|
||||||
when useStackMaskHack:
|
when useStackMaskHack:
|
||||||
proc runMain(tp: proc () {.thread.}) {.compilerproc.} =
|
proc runMain(tp: proc () {.thread.}) {.compilerproc.} =
|
||||||
var mainThread: TThread[pointer]
|
var mainThread: TThread[pointer]
|
||||||
|
|
@ -371,7 +388,7 @@ when useStackMaskHack:
|
||||||
# --------------------------- lock handling ----------------------------------
|
# --------------------------- lock handling ----------------------------------
|
||||||
|
|
||||||
type
|
type
|
||||||
TLock* = TSysLock ## Nimrod lock
|
TLock* = TSysLock ## Nimrod lock; not re-entrant!
|
||||||
|
|
||||||
const
|
const
|
||||||
noDeadlocks = false # compileOption("deadlockPrevention")
|
noDeadlocks = false # compileOption("deadlockPrevention")
|
||||||
|
|
|
||||||
0
lib/wrappers/sphinx.nim
Normal file → Executable file
0
lib/wrappers/sphinx.nim
Normal file → Executable file
27
lib/wrappers/zmq.nim
Normal file → Executable file
27
lib/wrappers/zmq.nim
Normal file → Executable file
|
|
@ -27,7 +27,32 @@
|
||||||
## Nimrod 0mq wrapper. This file contains the low level C wrappers as well as
|
## Nimrod 0mq wrapper. This file contains the low level C wrappers as well as
|
||||||
## some higher level constructs. The higher level constructs are easily
|
## some higher level constructs. The higher level constructs are easily
|
||||||
## recognizable because they are the only ones that have documentation.
|
## recognizable because they are the only ones that have documentation.
|
||||||
|
##
|
||||||
|
## Example of a client:
|
||||||
|
##
|
||||||
|
## .. code-block:: nimrod
|
||||||
|
## import zmq
|
||||||
|
##
|
||||||
|
## var connection = zmq.open("tcp://localhost:5555", server=false)
|
||||||
|
## echo("Connecting...")
|
||||||
|
## for i in 0..10:
|
||||||
|
## echo("Sending hello...", i)
|
||||||
|
## send(connection, "Hello")
|
||||||
|
## var reply = receive(connection)
|
||||||
|
## echo("Received ...", reply)
|
||||||
|
## close(connection)
|
||||||
|
##
|
||||||
|
## Example of a server:
|
||||||
|
##
|
||||||
|
## .. code-block:: nimrod
|
||||||
|
##
|
||||||
|
## import zmq
|
||||||
|
## var connection = zmq.open("tcp://*:5555", server=true)
|
||||||
|
## while True:
|
||||||
|
## var request = receive(connection)
|
||||||
|
## echo("Received: ", request)
|
||||||
|
## send(connection, "World")
|
||||||
|
## close(connection)
|
||||||
|
|
||||||
{.deadCodeElim: on.}
|
{.deadCodeElim: on.}
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
|
||||||
0
tests/accept/compile/tcan_alias_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcan_alias_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcan_alias_specialised_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcan_alias_specialised_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcan_inherit_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcan_inherit_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcan_specialise_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcan_specialise_generic.nim
Normal file → Executable file
0
tests/accept/compile/tcodegenbug1.nim
Normal file → Executable file
0
tests/accept/compile/tcodegenbug1.nim
Normal file → Executable file
0
tests/accept/compile/tconstraints.nim
Normal file → Executable file
0
tests/accept/compile/tconstraints.nim
Normal file → Executable file
0
tests/accept/compile/teval1.nim
Normal file → Executable file
0
tests/accept/compile/teval1.nim
Normal file → Executable file
0
tests/accept/compile/tgenericmatcher.nim
Normal file → Executable file
0
tests/accept/compile/tgenericmatcher.nim
Normal file → Executable file
0
tests/accept/compile/tgenericmatcher2.nim
Normal file → Executable file
0
tests/accept/compile/tgenericmatcher2.nim
Normal file → Executable file
0
tests/accept/compile/tgenericrefs.nim
Normal file → Executable file
0
tests/accept/compile/tgenericrefs.nim
Normal file → Executable file
0
tests/accept/compile/titer2.nim
Normal file → Executable file
0
tests/accept/compile/titer2.nim
Normal file → Executable file
0
tests/accept/compile/titer_no_tuple_unpack.nim
Normal file → Executable file
0
tests/accept/compile/titer_no_tuple_unpack.nim
Normal file → Executable file
0
tests/accept/compile/tmacrostmt.nim
Normal file → Executable file
0
tests/accept/compile/tmacrostmt.nim
Normal file → Executable file
0
tests/accept/compile/tmarshal.nim
Normal file → Executable file
0
tests/accept/compile/tmarshal.nim
Normal file → Executable file
0
tests/accept/compile/tnimrodnode_for_runtime.nim
Normal file → Executable file
0
tests/accept/compile/tnimrodnode_for_runtime.nim
Normal file → Executable file
0
tests/accept/compile/tshadow_magic_type.nim
Normal file → Executable file
0
tests/accept/compile/tshadow_magic_type.nim
Normal file → Executable file
0
tests/accept/compile/tspecialised_is_equivalent.nim
Normal file → Executable file
0
tests/accept/compile/tspecialised_is_equivalent.nim
Normal file → Executable file
0
tests/accept/compile/ttableconstr.nim
Normal file → Executable file
0
tests/accept/compile/ttableconstr.nim
Normal file → Executable file
0
tests/accept/compile/ttempl4.nim
Normal file → Executable file
0
tests/accept/compile/ttempl4.nim
Normal file → Executable file
0
tests/accept/compile/ttemplreturntype.nim
Normal file → Executable file
0
tests/accept/compile/ttemplreturntype.nim
Normal file → Executable file
0
tests/accept/compile/ttypeconverter1.nim
Normal file → Executable file
0
tests/accept/compile/ttypeconverter1.nim
Normal file → Executable file
0
tests/accept/run/tcase_setconstr.nim
Normal file → Executable file
0
tests/accept/run/tcase_setconstr.nim
Normal file → Executable file
0
tests/accept/run/tfielditerator.nim
Normal file → Executable file
0
tests/accept/run/tfielditerator.nim
Normal file → Executable file
0
tests/accept/run/tgenericassign.nim
Normal file → Executable file
0
tests/accept/run/tgenericassign.nim
Normal file → Executable file
0
tests/accept/run/tgenericassigntuples.nim
Normal file → Executable file
0
tests/accept/run/tgenericassigntuples.nim
Normal file → Executable file
0
tests/accept/run/tkoeniglookup.nim
Normal file → Executable file
0
tests/accept/run/tkoeniglookup.nim
Normal file → Executable file
0
tests/accept/run/tlists.nim
Normal file → Executable file
0
tests/accept/run/tlists.nim
Normal file → Executable file
0
tests/accept/run/tmacro4.nim
Normal file → Executable file
0
tests/accept/run/tmacro4.nim
Normal file → Executable file
0
tests/accept/run/tmethods1.nim
Normal file → Executable file
0
tests/accept/run/tmethods1.nim
Normal file → Executable file
0
tests/accept/run/tnewderef.nim
Normal file → Executable file
0
tests/accept/run/tnewderef.nim
Normal file → Executable file
0
tests/accept/run/trepr.nim
Normal file → Executable file
0
tests/accept/run/trepr.nim
Normal file → Executable file
0
tests/accept/run/tsets2.nim
Normal file → Executable file
0
tests/accept/run/tsets2.nim
Normal file → Executable file
0
tests/accept/run/tsimplesort.nim
Normal file → Executable file
0
tests/accept/run/tsimplesort.nim
Normal file → Executable file
0
tests/accept/run/tslices.nim
Normal file → Executable file
0
tests/accept/run/tslices.nim
Normal file → Executable file
3
tests/accept/run/ttables.nim
Normal file → Executable file
3
tests/accept/run/ttables.nim
Normal file → Executable file
|
|
@ -80,5 +80,8 @@ block countTableTest1:
|
||||||
else: break
|
else: break
|
||||||
inc i
|
inc i
|
||||||
|
|
||||||
|
block SyntaxTest:
|
||||||
|
var x = toTable[int, string]({:})
|
||||||
|
|
||||||
echo "true"
|
echo "true"
|
||||||
|
|
||||||
|
|
|
||||||
0
tests/reject/tconstraints.nim
Normal file → Executable file
0
tests/reject/tconstraints.nim
Normal file → Executable file
0
tests/reject/temptycaseobj.nim
Normal file → Executable file
0
tests/reject/temptycaseobj.nim
Normal file → Executable file
0
tests/reject/tno_int_in_bool_context.nim
Normal file → Executable file
0
tests/reject/tno_int_in_bool_context.nim
Normal file → Executable file
0
tests/reject/tprocvar.nim
Normal file → Executable file
0
tests/reject/tprocvar.nim
Normal file → Executable file
44
tests/threads/threadex.nim
Executable file
44
tests/threads/threadex.nim
Executable file
|
|
@ -0,0 +1,44 @@
|
||||||
|
|
||||||
|
type
|
||||||
|
TMsgKind = enum
|
||||||
|
mLine, mEof
|
||||||
|
TMsg = object {.pure, final.}
|
||||||
|
case k: TMsgKind
|
||||||
|
of mEof: backTo: TThreadId[int]
|
||||||
|
of mLine: data: string
|
||||||
|
|
||||||
|
var
|
||||||
|
consumer: TThread[TMsg]
|
||||||
|
producer: TThread[int]
|
||||||
|
printedLines = 0
|
||||||
|
|
||||||
|
proc consume() {.thread.} =
|
||||||
|
while true:
|
||||||
|
var x = recv[TMsg]()
|
||||||
|
if x.k == mEof:
|
||||||
|
x.backTo.send(printedLines)
|
||||||
|
break
|
||||||
|
echo x.data
|
||||||
|
discard atomicInc(printedLines)
|
||||||
|
|
||||||
|
proc produce() {.thread.} =
|
||||||
|
var m: TMsg
|
||||||
|
var input = open("readme.txt")
|
||||||
|
while not endOfFile(input):
|
||||||
|
if consumer.ready:
|
||||||
|
m.data = input.readLine()
|
||||||
|
consumer.send(m)
|
||||||
|
close(input)
|
||||||
|
m.k = mEof
|
||||||
|
m.backTo = myThreadId[int]()
|
||||||
|
consumer.send(m)
|
||||||
|
var result = recv[int]()
|
||||||
|
echo result
|
||||||
|
|
||||||
|
createThread(consumer, consume)
|
||||||
|
createThread(producer, produce)
|
||||||
|
joinThread(consumer)
|
||||||
|
joinThread(producer)
|
||||||
|
|
||||||
|
echo printedLines
|
||||||
|
|
||||||
2
tests/accept/compile/tthreadanalysis.nim → tests/threads/tthreadanalysis.nim
Normal file → Executable file
2
tests/accept/compile/tthreadanalysis.nim → tests/threads/tthreadanalysis.nim
Normal file → Executable file
|
|
@ -37,7 +37,7 @@ proc echoLeTree(n: PNode) =
|
||||||
echo it.data
|
echo it.data
|
||||||
it = it.le
|
it = it.le
|
||||||
|
|
||||||
proc threadFunc(interval: tuple[a, b: int]) {.procvar.} =
|
proc threadFunc(interval: tuple[a, b: int]) {.thread.} =
|
||||||
doNothing()
|
doNothing()
|
||||||
for i in interval.a..interval.b:
|
for i in interval.a..interval.b:
|
||||||
var r = buildTree(i)
|
var r = buildTree(i)
|
||||||
4
tests/reject/tthreadanalysis2.nim → tests/threads/tthreadanalysis2.nim
Normal file → Executable file
4
tests/reject/tthreadanalysis2.nim → tests/threads/tthreadanalysis2.nim
Normal file → Executable file
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tthreadanalysis2.nim"
|
file: "tthreadanalysis2.nim"
|
||||||
line: 45
|
line: 45
|
||||||
errormsg: "possible inconsistency of thread local heaps"
|
errormsg: "write to foreign heap"
|
||||||
cmd: "nimrod cc --hints:on --threads:on $# $#"
|
cmd: "nimrod cc --hints:on --threads:on $# $#"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ proc echoLeTree(n: PNode) =
|
||||||
echo it.data
|
echo it.data
|
||||||
it = it.le
|
it = it.le
|
||||||
|
|
||||||
proc threadFunc(interval: tuple[a, b: int]) {.procvar.} =
|
proc threadFunc(interval: tuple[a, b: int]) {.thread.} =
|
||||||
doNothing()
|
doNothing()
|
||||||
for i in interval.a..interval.b:
|
for i in interval.a..interval.b:
|
||||||
var r = buildTree(i)
|
var r = buildTree(i)
|
||||||
14
tests/threads/tthreadheapviolation1.nim
Executable file
14
tests/threads/tthreadheapviolation1.nim
Executable file
|
|
@ -0,0 +1,14 @@
|
||||||
|
var
|
||||||
|
global: string = "test string"
|
||||||
|
t: TThread[string]
|
||||||
|
|
||||||
|
proc horrible() {.thread.} =
|
||||||
|
global = "string in thread local heap!"
|
||||||
|
var x = global
|
||||||
|
var mydata = (x, "my string too")
|
||||||
|
echo global
|
||||||
|
|
||||||
|
createThread(t, horrible)
|
||||||
|
joinThread(t)
|
||||||
|
|
||||||
|
|
||||||
21
todo.txt
21
todo.txt
|
|
@ -1,25 +1,11 @@
|
||||||
High priority (version 0.8.12)
|
|
||||||
==============================
|
|
||||||
* ``force_nosideEffect`` or some similar pragma is needed (``loophole``?)
|
|
||||||
* test threads on windows
|
|
||||||
* test thread analysis:
|
|
||||||
var x = globalString # ok, copied; `x` is mine!
|
|
||||||
vs
|
|
||||||
var x = globalRef # read access, `x` is theirs!
|
|
||||||
|
|
||||||
* make threadvar efficient again on linux after testing
|
|
||||||
* document Nimrod's threads
|
|
||||||
* document Nimrod's two phase symbol lookup for generics
|
|
||||||
* bug: {:}.toTable[int, string]()
|
|
||||||
|
|
||||||
|
|
||||||
version 0.9.0
|
version 0.9.0
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
- ``var T`` as a return type; easy to prove that location is not on the stack
|
||||||
|
- document Nimrod's two phase symbol lookup for generics
|
||||||
- add --deadlock_prevention:on|off switch? timeout for locks?
|
- add --deadlock_prevention:on|off switch? timeout for locks?
|
||||||
- bug: tfFinal not passed to generic
|
- bug: tfFinal not passed to generic
|
||||||
- bug: forward proc for generic seems broken
|
- bug: forward proc for generic seems broken
|
||||||
- ``var T`` as a return type; easy to prove that location is not on the stack
|
|
||||||
- test the sort implementation again
|
- test the sort implementation again
|
||||||
- warning for implicit openArray -> varargs convention
|
- warning for implicit openArray -> varargs convention
|
||||||
- implement explicit varargs
|
- implement explicit varargs
|
||||||
|
|
@ -28,6 +14,7 @@ version 0.9.0
|
||||||
- fix overloading resolution
|
- fix overloading resolution
|
||||||
- make ^ available as operator
|
- make ^ available as operator
|
||||||
- implement closures; implement proper coroutines
|
- implement closures; implement proper coroutines
|
||||||
|
- make threadvar efficient again on linux after testing
|
||||||
|
|
||||||
Bugs
|
Bugs
|
||||||
----
|
----
|
||||||
|
|
@ -57,7 +44,7 @@ version 0.9.XX
|
||||||
- test branch coverage
|
- test branch coverage
|
||||||
- checked exceptions
|
- checked exceptions
|
||||||
- fix implicit generic routines
|
- fix implicit generic routines
|
||||||
|
- think about ``{:}.toTable[int, string]()``
|
||||||
|
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
Here you can download the latest version of the Nimrod Compiler.
|
Here you can download the latest version of the Nimrod Compiler.
|
||||||
Please choose your platform:
|
Please choose your platform:
|
||||||
* source-based installation: `<download/nimrod_0.8.10.zip>`_
|
* source-based installation: `<download/nimrod_0.8.12.zip>`_
|
||||||
* installer for Windows XP/Vista (i386): `<download/nimrod_0.8.10.exe>`_
|
* installer for Windows XP/Vista (i386): `<download/nimrod_0.8.12.exe>`_
|
||||||
(includes GCC and everything else you need)
|
(includes GCC and everything else you need)
|
||||||
|
|
||||||
The source-based installation has been tested on these systems:
|
The source-based installation has been tested on these systems:
|
||||||
|
|
|
||||||
61
web/news.txt
61
web/news.txt
|
|
@ -3,7 +3,7 @@ News
|
||||||
====
|
====
|
||||||
|
|
||||||
|
|
||||||
2011-XX-XX Version 0.8.12 released
|
2011-07-10 Version 0.8.12 released
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
Version 0.8.12 has been released! Get it `here <download.html>`_.
|
Version 0.8.12 has been released! Get it `here <download.html>`_.
|
||||||
|
|
@ -22,6 +22,8 @@ Bugfixes
|
||||||
- Bugfix: The compiler does not emit very inaccurate floating point literals
|
- Bugfix: The compiler does not emit very inaccurate floating point literals
|
||||||
anymore.
|
anymore.
|
||||||
- Bugfix: Subclasses are taken into account for ``try except`` matching.
|
- Bugfix: Subclasses are taken into account for ``try except`` matching.
|
||||||
|
- Bugfix: Generics and macros are more stable. There are still known bugs left
|
||||||
|
though.
|
||||||
- Bugfix: Generated type information for tuples was sometimes wrong, causing
|
- Bugfix: Generated type information for tuples was sometimes wrong, causing
|
||||||
random crashes.
|
random crashes.
|
||||||
- Lots of other bugfixes: Too many to list them all.
|
- Lots of other bugfixes: Too many to list them all.
|
||||||
|
|
@ -38,7 +40,7 @@ Changes affecting backwards compatibility
|
||||||
- Changed and documented how generalized string literals work: The syntax
|
- Changed and documented how generalized string literals work: The syntax
|
||||||
``module.re"abc"`` is now supported.
|
``module.re"abc"`` is now supported.
|
||||||
- Changed the behaviour of ``strutils.%``, ``ropes.%``
|
- Changed the behaviour of ``strutils.%``, ``ropes.%``
|
||||||
if both ``$#`` and ``$i`` are involved.
|
if both notations ``$#`` and ``$i`` are involved.
|
||||||
- The ``pegs`` and ``re`` modules distinguish between ``replace``
|
- The ``pegs`` and ``re`` modules distinguish between ``replace``
|
||||||
and ``replacef`` operations.
|
and ``replacef`` operations.
|
||||||
- The pointer dereference operation ``p^`` is deprecated and might become
|
- The pointer dereference operation ``p^`` is deprecated and might become
|
||||||
|
|
@ -50,8 +52,42 @@ Changes affecting backwards compatibility
|
||||||
- Unsound co-/contravariance for procvars has been removed.
|
- Unsound co-/contravariance for procvars has been removed.
|
||||||
|
|
||||||
|
|
||||||
Additions
|
Language Additions
|
||||||
---------
|
------------------
|
||||||
|
|
||||||
|
- Source code filters are now documented.
|
||||||
|
- Added the ``linearScanEnd``, ``unroll``, ``shallow`` pragmas.
|
||||||
|
- Added ``emit`` pragma for direct code generator control.
|
||||||
|
- Case statement branches support constant sets for programming convenience.
|
||||||
|
- Tuple unpacking is not enforced in ``for`` loops anymore.
|
||||||
|
- The compiler now supports array, sequence and string slicing.
|
||||||
|
- A field in an ``enum`` may be given an explicit string representation.
|
||||||
|
This yields more maintainable code than using a constant
|
||||||
|
``array[TMyEnum, string]`` mapping.
|
||||||
|
- Indices in array literals may be explicitly given, enhancing readability:
|
||||||
|
``[enumValueA: "a", enumValueB: "b"]``.
|
||||||
|
- Added thread support via the ``threads`` core module and
|
||||||
|
the ``--threads:on`` command line switch.
|
||||||
|
- The built-in iterators ``system.fields`` and ``system.fieldPairs`` can be
|
||||||
|
used to iterate over any field of a tuple. With this mechanism operations
|
||||||
|
like ``==`` and ``hash`` are lifted to tuples.
|
||||||
|
- The slice ``..`` is now a first-class operator, allowing code like:
|
||||||
|
``x in 1000..100_000``.
|
||||||
|
|
||||||
|
|
||||||
|
Compiler Additions
|
||||||
|
------------------
|
||||||
|
|
||||||
|
- The compiler supports IDEs via the new group of ``idetools`` command line
|
||||||
|
options.
|
||||||
|
- The *interactive mode* (REPL) has been improved and documented for the
|
||||||
|
first time.
|
||||||
|
- The compiler now might use hashing for string case statements depending
|
||||||
|
on the number of string literals in the case statement.
|
||||||
|
|
||||||
|
|
||||||
|
Library Additions
|
||||||
|
-----------------
|
||||||
|
|
||||||
- Added ``lists`` module which contains generic linked lists.
|
- Added ``lists`` module which contains generic linked lists.
|
||||||
- Added ``sets`` module which contains generic hash sets.
|
- Added ``sets`` module which contains generic hash sets.
|
||||||
|
|
@ -70,37 +106,20 @@ Additions
|
||||||
``\title``, ``\white``.
|
``\title``, ``\white``.
|
||||||
- Pegs support the new built-in ``\skip`` operation.
|
- Pegs support the new built-in ``\skip`` operation.
|
||||||
- Pegs support the ``$`` and ``^`` anchors.
|
- Pegs support the ``$`` and ``^`` anchors.
|
||||||
- Source code filters are now documented.
|
|
||||||
- Added ``emit`` pragma for direct code generator control.
|
|
||||||
- Additional operations were added to the ``complex`` module.
|
- Additional operations were added to the ``complex`` module.
|
||||||
- Added ``strutils.formatFloat``, ``strutils.formatBiggestFloat``.
|
- Added ``strutils.formatFloat``, ``strutils.formatBiggestFloat``.
|
||||||
- A field in an ``enum`` may be given an explicit string representation.
|
|
||||||
This yields more maintainable code than using a constant
|
|
||||||
``array[TMyEnum, string]`` mapping.
|
|
||||||
- Indices in array literals may be explicitly given, enhancing readability:
|
|
||||||
``[enumValueA: "a", enumValueB: "b"]``.
|
|
||||||
- Added basic thread support via the ``threads`` core module and
|
|
||||||
the ``--threads:on`` command line switch.
|
|
||||||
- Added unary ``<`` for nice looking excluding upper bounds in ranges.
|
- Added unary ``<`` for nice looking excluding upper bounds in ranges.
|
||||||
- Added ``math.floor``.
|
- Added ``math.floor``.
|
||||||
- The *interactive mode* (REPL) has been improved and documented for the
|
|
||||||
first time.
|
|
||||||
- Added the ``linearScanEnd``, ``unroll``, ``shallow`` pragmas.
|
|
||||||
- Added ``system.reset`` and a version of ``system.open`` that
|
- Added ``system.reset`` and a version of ``system.open`` that
|
||||||
returns a ``TFile`` and raises an exception in case of an error.
|
returns a ``TFile`` and raises an exception in case of an error.
|
||||||
- The compiler now might use hashing for string case statements depending
|
|
||||||
on the number of string literals in the case statement.
|
|
||||||
- Tuple unpacking is not enforced in ``for`` loops anymore.
|
|
||||||
- Added a wrapper for ``redis``.
|
- Added a wrapper for ``redis``.
|
||||||
- Added a wrapper for ``0mq`` via the ``zmq`` module.
|
- Added a wrapper for ``0mq`` via the ``zmq`` module.
|
||||||
- Added a wrapper for ``sphinx``.
|
- Added a wrapper for ``sphinx``.
|
||||||
- The compiler now supports array, sequence and string slicing.
|
|
||||||
- Added ``system.newStringOfCap``.
|
- Added ``system.newStringOfCap``.
|
||||||
- Added ``system.raiseHook`` and ``system.outOfMemHook``.
|
- Added ``system.raiseHook`` and ``system.outOfMemHook``.
|
||||||
- Added ``system.writeFile``.
|
- Added ``system.writeFile``.
|
||||||
- Added ``system.shallowCopy``.
|
- Added ``system.shallowCopy``.
|
||||||
- ``system.echo`` is guaranteed to be thread-safe.
|
- ``system.echo`` is guaranteed to be thread-safe.
|
||||||
- Case statement branches support constant sets for programming convenience.
|
|
||||||
- Added ``prelude`` include file for scripting convenience.
|
- Added ``prelude`` include file for scripting convenience.
|
||||||
- Added ``typeinfo`` core module for access to runtime type information.
|
- Added ``typeinfo`` core module for access to runtime type information.
|
||||||
- Added ``marshal`` module for JSON serialization.
|
- Added ``marshal`` module for JSON serialization.
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,9 @@ doc: "endb;intern;apis;lib;manual;tut1;tut2;nimrodc;overview"
|
||||||
doc: "tools;c2nim;niminst"
|
doc: "tools;c2nim;niminst"
|
||||||
pdf: "manual;lib;tut1;tut2;nimrodc;c2nim;niminst"
|
pdf: "manual;lib;tut1;tut2;nimrodc;c2nim;niminst"
|
||||||
srcdoc: "core/macros;pure/marshal;core/typeinfo"
|
srcdoc: "core/macros;pure/marshal;core/typeinfo"
|
||||||
srcdoc: "impure/graphics;pure/sockets"
|
srcdoc: "impure/graphics;impure/re;pure/sockets"
|
||||||
srcdoc: "system.nim;system/threads.nim;pure/os;pure/strutils;pure/math"
|
srcdoc: "system.nim;system/threads.nim;system/inboxes.nim"
|
||||||
|
srcdoc: "pure/os;pure/strutils;pure/math"
|
||||||
srcdoc: "pure/complex;pure/times;pure/osproc;pure/pegs;pure/dynlib"
|
srcdoc: "pure/complex;pure/times;pure/osproc;pure/pegs;pure/dynlib"
|
||||||
srcdoc: "pure/parseopt;pure/hashes;pure/strtabs;pure/lexbase"
|
srcdoc: "pure/parseopt;pure/hashes;pure/strtabs;pure/lexbase"
|
||||||
srcdoc: "pure/parsecfg;pure/parsexml;pure/parsecsv;pure/parsesql"
|
srcdoc: "pure/parsecfg;pure/parsexml;pure/parsecsv;pure/parsesql"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
|
| `2011-07-10`:newsdate:
|
||||||
|
| Nimrod version 0.8.12 has been released!
|
||||||
|
Get it `here <./download.html>`_.
|
||||||
|
|
||||||
| `2010-10-20`:newsdate:
|
| `2010-10-20`:newsdate:
|
||||||
| Nimrod version 0.8.10 has been released!
|
| Nimrod version 0.8.10 has been released!
|
||||||
Get it `here <./download.html>`_.
|
|
||||||
|
|
||||||
| `2010-03-14`:newsdate:
|
| `2010-03-14`:newsdate:
|
||||||
| Nimrod version 0.8.8 has been released!
|
| Nimrod version 0.8.8 has been released!
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue