the codegen doesn't emit deepCopy for parallel statements

This commit is contained in:
Araq 2014-11-08 15:47:00 +01:00
commit 830e0c0009
9 changed files with 64 additions and 52 deletions

View file

@ -204,7 +204,7 @@ proc flowVarKind(t: PType): TFlowVarKind =
else: fvBlob else: fvBlob
proc addLocalVar(varSection, varInit: PNode; owner: PSym; typ: PType; proc addLocalVar(varSection, varInit: PNode; owner: PSym; typ: PType;
v: PNode): PSym = v: PNode; useShallowCopy=false): PSym =
result = newSym(skTemp, getIdent(genPrefix), owner, varSection.info) result = newSym(skTemp, getIdent(genPrefix), owner, varSection.info)
result.typ = typ result.typ = typ
incl(result.flags, sfFromGeneric) incl(result.flags, sfFromGeneric)
@ -215,6 +215,9 @@ proc addLocalVar(varSection, varInit: PNode; owner: PSym; typ: PType;
vpart.sons[2] = if varInit.isNil: v else: ast.emptyNode vpart.sons[2] = if varInit.isNil: v else: ast.emptyNode
varSection.add vpart varSection.add vpart
if varInit != nil: if varInit != nil:
if useShallowCopy:
varInit.add newFastAsgnStmt(newSymNode(result), v)
else:
let deepCopyCall = newNodeI(nkCall, varInit.info, 3) let deepCopyCall = newNodeI(nkCall, varInit.info, 3)
deepCopyCall.sons[0] = newSymNode(createMagic("deepCopy", mDeepCopy)) deepCopyCall.sons[0] = newSymNode(createMagic("deepCopy", mDeepCopy))
deepCopyCall.sons[1] = newSymNode(result) deepCopyCall.sons[1] = newSymNode(result)
@ -420,7 +423,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), n[3]) result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), n[3])
let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldA.typ, let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldA.typ,
indirectAccess(castExpr, fieldA, n.info)) indirectAccess(castExpr, fieldA, n.info),
useShallowCopy=true)
slice.sons[2] = threadLocal.newSymNode slice.sons[2] = threadLocal.newSymNode
else: else:
let a = genAddrOf(n) let a = genAddrOf(n)
@ -434,7 +438,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
slice.sons[1] = genDeref(indirectAccess(castExpr, field, n.info)) slice.sons[1] = genDeref(indirectAccess(castExpr, field, n.info))
let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldB.typ, let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldB.typ,
indirectAccess(castExpr, fieldB, n.info)) indirectAccess(castExpr, fieldB, n.info),
useShallowCopy=true)
slice.sons[3] = threadLocal.newSymNode slice.sons[3] = threadLocal.newSymNode
call.add slice call.add slice
elif (let size = computeSize(argType); size < 0 or size > 16) and elif (let size = computeSize(argType); size < 0 or size > 16) and
@ -445,7 +450,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
objType.addField(field) objType.addField(field)
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a)
let threadLocal = addLocalVar(varSection,nil, objType.owner, field.typ, let threadLocal = addLocalVar(varSection,nil, objType.owner, field.typ,
indirectAccess(castExpr, field, n.info)) indirectAccess(castExpr, field, n.info),
useShallowCopy=true)
call.add(genDeref(threadLocal.newSymNode)) call.add(genDeref(threadLocal.newSymNode))
else: else:
# boring case # boring case
@ -454,7 +460,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n)
let threadLocal = addLocalVar(varSection, varInit, let threadLocal = addLocalVar(varSection, varInit,
objType.owner, field.typ, objType.owner, field.typ,
indirectAccess(castExpr, field, n.info)) indirectAccess(castExpr, field, n.info),
useShallowCopy=true)
call.add(threadLocal.newSymNode) call.add(threadLocal.newSymNode)
proc wrapProcForSpawn*(owner: PSym; spawnExpr: PNode; retType: PType; proc wrapProcForSpawn*(owner: PSym; spawnExpr: PNode; retType: PType;

View file

@ -113,7 +113,7 @@ proc parseDirective(L: var TLexer, tok: var TToken) =
case whichKeyword(tok.ident) case whichKeyword(tok.ident)
of wIf: of wIf:
setLen(condStack, len(condStack) + 1) setLen(condStack, len(condStack) + 1)
var res = evalppIf(L, tok) let res = evalppIf(L, tok)
condStack[high(condStack)] = res condStack[high(condStack)] = res
if not res: jumpToDirective(L, tok, jdElseEndif) if not res: jumpToDirective(L, tok, jdElseEndif)
of wElif: doElif(L, tok) of wElif: doElif(L, tok)
@ -224,9 +224,11 @@ proc loadConfigs*(cfg: string) =
if libpath == "": if libpath == "":
# choose default libpath: # choose default libpath:
var prefix = getPrefixDir() var prefix = getPrefixDir()
when defined(posix):
if prefix == "/usr": libpath = "/usr/lib/nim" if prefix == "/usr": libpath = "/usr/lib/nim"
elif prefix == "/usr/local": libpath = "/usr/local/lib/nim" elif prefix == "/usr/local": libpath = "/usr/local/lib/nim"
else: libpath = joinPath(prefix, "lib") else: libpath = joinPath(prefix, "lib")
else: libpath = joinPath(prefix, "lib")
if optSkipConfigFile notin gGlobalOptions: if optSkipConfigFile notin gGlobalOptions:
readConfigFile(getSystemConfigPath(cfg)) readConfigFile(getSystemConfigPath(cfg))

View file

@ -30,9 +30,9 @@ To build from source you will need:
If you are on a fairly modern *nix system, the following steps should work: If you are on a fairly modern *nix system, the following steps should work:
``` ```
$ git clone git://github.com/Araq/Nimrod.git $ git clone git://github.com/Araq/Nim.git
$ cd Nimrod $ cd Nim
$ git clone --depth 1 git://github.com/nimrod-code/csources $ git clone --depth 1 git://github.com/nim-code/csources
$ cd csources && sh build.sh $ cd csources && sh build.sh
$ cd .. $ cd ..
$ bin/nim c koch $ bin/nim c koch

View file

@ -5,6 +5,8 @@ true
true true
true true
true''' true'''
ccodeCheck: "!'deepcopy('"
""" """
# parallel convex hull for Nim bigbreak # parallel convex hull for Nim bigbreak

View file

@ -27,9 +27,9 @@ proc main =
var dummy: ref Bar[int] var dummy: ref Bar[int]
new(dummy) new(dummy)
dummy.x = 44 dummy.x = 44
parallel: #parallel:
let f = spawn foo(dummy) let f = spawn foo(dummy)
let b = spawn foo(dummy) let b = spawn foo(dummy)
echo "done", f, " ", b echo "done", ^f, " ", ^b
main() main()

View file

@ -1,9 +1,8 @@
version 0.10 version 0.10
============ ============
- fix missing GC_ref bug for flow variables - find out why global installations end up using the wrong stdlib
- fix deepCopy bug in parallel section - implement 'procCall'
- implement 'static_call'
- make nimble part of the distribution - make nimble part of the distribution
- split idetools into separate tool - split idetools into separate tool
- split docgen into separate tool - split docgen into separate tool

View file

@ -1,74 +1,74 @@
Forum Forum
===== =====
The `Nimrod forum <http://forum.nimrod-code.org/>`_ is the place where most The `Nim forum <http://forum.nim-lang.org/>`_ is the place where most
discussions related to the language happen. It not only includes discussions discussions related to the language happen. It not only includes discussions
relating to the design of Nimrod but also allows for beginners to ask questions relating to the design of Nim but also allows for beginners to ask questions
relating to Nimrod. relating to Nim.
IRC IRC
==== ====
Many Nimrod developers are a part of the Many Nim developers are a part of the
`#nimrod IRC channel <http://webchat.freenode.net/?channels=nimrod>`_ on `#nim IRC channel <http://webchat.freenode.net/?channels=nim>`_ on
Freenode. That is the place where the rest of the discussion relating to Nimrod Freenode. That is the place where the rest of the discussion relating to Nim
occurs. Be sure to join us there if you wish to discuss Nimrod in real-time. occurs. Be sure to join us there if you wish to discuss Nim in real-time.
IRC is the perfect place for people just starting to learn Nimrod and we IRC is the perfect place for people just starting to learn Nim and we
welcome any questions that you may have! welcome any questions that you may have!
You may also be interested in reading the You may also be interested in reading the
`IRC logs <http://build.nimrod-code.org/irclogs/>`_ which are an archive of all `IRC logs <http://build.nim-code.org/irclogs/>`_ which are an archive of all
of the previous discussions that took place in the IRC channel. of the previous discussions that took place in the IRC channel.
Github Github
====== ======
Nimrod's `source code <http://github.com/Araq/Nimrod>`_ is hosted on Github. Nim's `source code <http://github.com/Araq/Nim>`_ is hosted on Github.
Together with the `wiki <http://github.com/Araq/Nimrod/wiki>`_ and Together with the `wiki <http://github.com/Araq/Nim/wiki>`_ and
`issue tracker <http://github.com/Araq/Nimrod/issues>`_. `issue tracker <http://github.com/Araq/Nim/issues>`_.
Github also hosts other projects relating to Nimrod. These projects are a part Github also hosts other projects relating to Nim. These projects are a part
of the `nimrod-code organisation <http://github.com/nimrod-code>`_. of the `nim-code organisation <http://github.com/nim-code>`_.
This includes the `Babel package manager <http://github.com/nimrod-code/babel>`_ This includes the `Babel package manager <http://github.com/nim-code/babel>`_
and its `package repository <http://github.com/nimrod-code/packages>`_. and its `package repository <http://github.com/nim-code/packages>`_.
Twitter Twitter
======= =======
Follow us `@nimrodlang <http://twitter.com/nimrodlang>`_ for latest news about Follow us `@nimlang <http://twitter.com/nimlang>`_ for latest news about
Nimrod. Nim.
Reddit Reddit
====== ======
Subscribe to `/r/nimrod <http://reddit.com/r/nimrod>`_ for latest news about Subscribe to `/r/nim <http://reddit.com/r/nim>`_ for latest news about
Nimrod. Nim.
StackOverflow StackOverflow
============= =============
When asking a question relating to Nimrod, be sure to use the When asking a question relating to Nim, be sure to use the
`Nimrod <http://stackoverflow.com/questions/tagged/nimrod>`_ tag in your `Nim <http://stackoverflow.com/questions/tagged/nim>`_ tag in your
question. question.
How to help How to help
=========== ===========
There are always many things to be done in the main There are always many things to be done in the main
`Nimrod repository <https://github.com/Araq/Nimrod>`_, check out the `Nim repository <https://github.com/Araq/Nim>`_, check out the
`issues <https://github.com/Araq/Nimrod/issues>`_ for `issues <https://github.com/Araq/Nim/issues>`_ for
things to do; pull requests are always welcome. You can things to do; pull requests are always welcome. You can
also contribute to the many other projects hosted by the also contribute to the many other projects hosted by the
`nimrod-code <https://github.com/nimrod-code>`_ organisation on github. If you `nim-code <https://github.com/nim-code>`_ organisation on github. If you
can't find anything you fancy doing, you can always ask for inspiration on IRC can't find anything you fancy doing, you can always ask for inspiration on IRC
(irc.freenode.net #nimrod) or on the `Nimrod forums <http://forum.nimrod-code.org>`_. (irc.freenode.net #nim) or on the `Nim forums <http://forum.nim-code.org>`_.
Donations Donations
--------- ---------
If you love what we do and are feeling generous then you can always donate. If you love what we do and are feeling generous then you can always donate.
Contributions of any quantity are greatly appreciated and will contribute to Contributions of any quantity are greatly appreciated and will contribute to
making Nimrod even better! making Nim even better!
Gittip Gittip
`````` ``````

View file

@ -92,7 +92,7 @@ Nim plays nice with others
the POSIX API, OpenGL, SDL, Cairo, Python, Lua, TCL, X11, libzip, PCRE, the POSIX API, OpenGL, SDL, Cairo, Python, Lua, TCL, X11, libzip, PCRE,
libcurl, mySQL and SQLite are included in the standard distribution or libcurl, mySQL and SQLite are included in the standard distribution or
can easily be obtained via the can easily be obtained via the
`Babel package manager <https://github.com/nimrod-code/babel>`_. `Nimble package manager <https://github.com/nimrod-code/nimble>`_.
* A C to Nim conversion utility: New bindings to C libraries are easily * A C to Nim conversion utility: New bindings to C libraries are easily
generated by ``c2nim``. generated by ``c2nim``.
@ -101,5 +101,5 @@ Roadmap to 1.0
============== ==============
Please have a look at Please have a look at
this `wiki page <https://github.com/Araq/Nimrod/wiki/Roadmap>`_ for this `wiki page <https://github.com/Araq/Nim/wiki/Roadmap>`_ for
an up-to-date overview. an up-to-date overview.

View file

@ -9,6 +9,8 @@ News
Changes affecting backwards compatibility Changes affecting backwards compatibility
----------------------------------------- -----------------------------------------
- **The language has been renamed from Nimrod to Nim.** The name of the
compiler changed from ``nimrod`` to ``nim`` too.
- ``system.fileHandle`` has been renamed to ``system.getFileHandle`` to - ``system.fileHandle`` has been renamed to ``system.getFileHandle`` to
prevent name conflicts with the new type ``FileHandle``. prevent name conflicts with the new type ``FileHandle``.
- Comments are now not part of the AST, as such you cannot use them in place - Comments are now not part of the AST, as such you cannot use them in place