Merge branch 'devel' of github.com:nim-lang/Nim into devel

This commit is contained in:
Andreas Rumpf 2016-02-19 01:08:00 +01:00
commit 608170b9d6
20 changed files with 148 additions and 20 deletions

View file

@ -2111,8 +2111,10 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
initLocExpr(p, n.sons[0], a) initLocExpr(p, n.sons[0], a)
of nkAsmStmt: genAsmStmt(p, n) of nkAsmStmt: genAsmStmt(p, n)
of nkTryStmt: of nkTryStmt:
if p.module.compileToCpp: genTryCpp(p, n, d) if p.module.compileToCpp and optNoCppExceptions notin gGlobalOptions:
else: genTry(p, n, d) genTryCpp(p, n, d)
else:
genTry(p, n, d)
of nkRaiseStmt: genRaiseStmt(p, n) of nkRaiseStmt: genRaiseStmt(p, n)
of nkTypeSection: of nkTypeSection:
# we have to emit the type information for object types here to support # we have to emit the type information for object types here to support

View file

@ -327,7 +327,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
lists.excludePath(options.lazyPaths, strippedPath) lists.excludePath(options.lazyPaths, strippedPath)
of "nimcache": of "nimcache":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
options.nimcacheDir = processPath(arg) options.nimcacheDir = processPath(arg, true)
of "out", "o": of "out", "o":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
options.outFile = arg options.outFile = arg
@ -619,6 +619,10 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
cAssembler = nameToCC(arg) cAssembler = nameToCC(arg)
if cAssembler notin cValidAssemblers: if cAssembler notin cValidAssemblers:
localError(info, errGenerated, "'$1' is not a valid assembler." % [arg]) localError(info, errGenerated, "'$1' is not a valid assembler." % [arg])
of "nocppexceptions":
expectNoArg(switch, arg, pass, info)
incl(gGlobalOptions, optNoCppExceptions)
defineSymbol("noCppExceptions")
else: else:
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg) if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
else: invalidCmdLineOption(pass, switch, info) else: invalidCmdLineOption(pass, switch, info)

View file

@ -731,6 +731,8 @@ proc callCCompiler*(projectfile: string) =
builddll = "" builddll = ""
if options.outFile.len > 0: if options.outFile.len > 0:
exefile = options.outFile.expandTilde exefile = options.outFile.expandTilde
if not exefile.isAbsolute():
exefile = getCurrentDir() / exefile
if not noAbsolutePaths(): if not noAbsolutePaths():
if not exefile.isAbsolute(): if not exefile.isAbsolute():
exefile = joinPath(splitFile(projectfile).dir, exefile) exefile = joinPath(splitFile(projectfile).dir, exefile)

View file

@ -66,6 +66,7 @@ type # please make sure we have under 32 options
# also: generate header file # also: generate header file
optIdeDebug # idetools: debug mode optIdeDebug # idetools: debug mode
optIdeTerse # idetools: use terse descriptions optIdeTerse # idetools: use terse descriptions
optNoCppExceptions # use C exception handling even with CPP
TGlobalOptions* = set[TGlobalOption] TGlobalOptions* = set[TGlobalOption]
TCommands* = enum # Nim's commands TCommands* = enum # Nim's commands
# **keep binary compatible** # **keep binary compatible**

View file

@ -443,6 +443,7 @@ proc semAsmOrEmit*(con: PContext, n: PNode, marker: char): PNode =
var e = searchInScopes(con, getIdent(sub)) var e = searchInScopes(con, getIdent(sub))
if e != nil: if e != nil:
if e.kind == skStub: loadStub(e) if e.kind == skStub: loadStub(e)
incl(e.flags, sfUsed)
addSon(result, newSymNode(e)) addSon(result, newSymNode(e))
else: else:
addSon(result, newStrNode(nkStrLit, sub)) addSon(result, newStrNode(nkStrLit, sub))

View file

@ -69,6 +69,7 @@ Advanced options:
--putenv:key=value set an environment variable --putenv:key=value set an environment variable
--NimblePath:PATH add a path for Nimble support --NimblePath:PATH add a path for Nimble support
--noNimblePath deactivate the Nimble path --noNimblePath deactivate the Nimble path
--noCppExceptions use default exception handling with C++ backend
--excludePath:PATH exclude a path from the list of search paths --excludePath:PATH exclude a path from the list of search paths
--dynlibOverride:SYMBOL marks SYMBOL so that dynlib:SYMBOL --dynlibOverride:SYMBOL marks SYMBOL so that dynlib:SYMBOL
has no effect and can be statically linked instead; has no effect and can be statically linked instead;

View file

@ -46,6 +46,9 @@ Core
* `locks <locks.html>`_ * `locks <locks.html>`_
Locks and condition variables for Nim. Locks and condition variables for Nim.
* `rlocks <rlocks.html>`_
Reentrant locks for Nim.
* `macros <macros.html>`_ * `macros <macros.html>`_
Contains the AST API and documentation of Nim for writing macros. Contains the AST API and documentation of Nim for writing macros.

View file

@ -127,7 +127,7 @@ Produces roughly this C code:
} MySeq; } MySeq;
The bounds checking done at compile time is not disabled for now, so to access The bounds checking done at compile time is not disabled for now, so to access
``s.data[C]`` (where ``C`` is a constant) the array's index needs needs to ``s.data[C]`` (where ``C`` is a constant) the array's index needs to
include ``C``. include ``C``.
The base type of the unchecked array may not contain any GC'ed memory but this The base type of the unchecked array may not contain any GC'ed memory but this

View file

@ -601,7 +601,7 @@ proc last*(node: NimNode): NimNode {.compileTime.} = node[<node.len]
const const
RoutineNodes* = {nnkProcDef, nnkMethodDef, nnkDo, nnkLambda, nnkIteratorDef} RoutineNodes* = {nnkProcDef, nnkMethodDef, nnkDo, nnkLambda, nnkIteratorDef, nnkTemplateDef, nnkConverterDef}
AtomicNodes* = {nnkNone..nnkNilLit} AtomicNodes* = {nnkNone..nnkNilLit}
CallNodes* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand, CallNodes* = {nnkCall, nnkInfix, nnkPrefix, nnkPostfix, nnkCommand,
nnkCallStrLit, nnkHiddenCallConv} nnkCallStrLit, nnkHiddenCallConv}

50
lib/core/rlocks.nim Normal file
View file

@ -0,0 +1,50 @@
#
#
# Nim's Runtime Library
# (c) Copyright 2016 Anatoly Galiulin
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This module contains Nim's support for reentrant locks.
include "system/syslocks"
type
RLock* = SysLock ## Nim lock, re-entrant
proc initRLock*(lock: var RLock) {.inline.} =
## Initializes the given lock.
when defined(posix):
var a: SysLockAttr
initSysLockAttr(a)
setSysLockType(a, SysLockType_Reentrant())
initSysLock(lock, a.addr)
else:
initSysLock(lock)
proc deinitRLock*(lock: var RLock) {.inline.} =
## Frees the resources associated with the lock.
deinitSys(lock)
proc tryAcquire*(lock: var RLock): bool =
## Tries to acquire the given lock. Returns `true` on success.
result = tryAcquireSys(lock)
proc acquire*(lock: var RLock) =
## Acquires the given lock.
acquireSys(lock)
proc release*(lock: var RLock) =
## Releases the given lock.
releaseSys(lock)
template withRLock*(lock: var RLock, code: untyped): untyped =
## Acquires the given lock and then executes the code.
block:
acquire(lock)
defer:
release(lock)
{.locks: [lock].}:
code

View file

@ -55,7 +55,7 @@ when defined(Windows):
event*: KEY_EVENT_RECORD event*: KEY_EVENT_RECORD
safetyBuffer: array[0..5, DWORD] safetyBuffer: array[0..5, DWORD]
proc readConsoleInputW*(hConsoleInput: THANDLE, lpBuffer: var INPUTRECORD, proc readConsoleInputW*(hConsoleInput: HANDLE, lpBuffer: var INPUTRECORD,
nLength: uint32, nLength: uint32,
lpNumberOfEventsRead: var uint32): WINBOOL{. lpNumberOfEventsRead: var uint32): WINBOOL{.
stdcall, dynlib: "kernel32", importc: "ReadConsoleInputW".} stdcall, dynlib: "kernel32", importc: "ReadConsoleInputW".}

View file

@ -23,6 +23,31 @@ __clang__
#ifndef NIMBASE_H #ifndef NIMBASE_H
#define NIMBASE_H #define NIMBASE_H
/* ------------ ignore typical warnings in Nim-generated files ------------- */
#if defined(__GNUC__) || defined(__clang__)
# pragma GCC diagnostic ignored "-Wpragmas"
# pragma GCC diagnostic ignored "-Wwritable-strings"
# pragma GCC diagnostic ignored "-Winvalid-noreturn"
# pragma GCC diagnostic ignored "-Wformat"
# pragma GCC diagnostic ignored "-Wlogical-not-parentheses"
# pragma GCC diagnostic ignored "-Wlogical-op-parentheses"
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wunused-function"
# pragma GCC diagnostic ignored "-Wunused-variable"
# pragma GCC diagnostic ignored "-Winvalid-offsetof"
# pragma GCC diagnostic ignored "-Wtautological-compare"
# pragma GCC diagnostic ignored "-Wswitch-bool"
# pragma GCC diagnostic ignored "-Wmacro-redefined"
# pragma GCC diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers"
#endif
#if defined(_MSC_VER)
# pragma warning(disable: 4005 4100 4101 4189 4191 4200 4244 4293 4296 4309)
# pragma warning(disable: 4310 4365 4456 4477 4514 4574 4611 4668 4702 4706)
# pragma warning(disable: 4710 4711 4774 4800 4820 4996)
#endif
/* ------------------------------------------------------------------------- */
#if defined(__GNUC__) #if defined(__GNUC__)
# define _GNU_SOURCE 1 # define _GNU_SOURCE 1
#endif #endif

View file

@ -216,7 +216,7 @@ proc raiseExceptionAux(e: ref Exception) =
if not localRaiseHook(e): return if not localRaiseHook(e): return
if globalRaiseHook != nil: if globalRaiseHook != nil:
if not globalRaiseHook(e): return if not globalRaiseHook(e): return
when defined(cpp): when defined(cpp) and not defined(noCppExceptions):
if e[] of OutOfMemError: if e[] of OutOfMemError:
showErrorMessage(e.name) showErrorMessage(e.name)
quitOrDebug() quitOrDebug()

View file

@ -76,6 +76,7 @@ proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} =
# we read an 'int' but this may have been too large, so mask the other bits: # we read an 'int' but this may have been too large, so mask the other bits:
let e = if typ.size == 1: e and 0xff let e = if typ.size == 1: e and 0xff
elif typ.size == 2: e and 0xffff elif typ.size == 2: e and 0xffff
elif typ.size == 4: e and 0xffffffff
else: e else: e
# XXX we need a proper narrowing based on signedness here # XXX we need a proper narrowing based on signedness here
#e and ((1 shl (typ.size*8)) - 1) #e and ((1 shl (typ.size*8)) - 1)

View file

@ -7,7 +7,7 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
## Low level system locks and condition vars. # Low level system locks and condition vars.
when defined(Windows): when defined(Windows):
type type
@ -75,12 +75,24 @@ else:
type type
SysLock {.importc: "pthread_mutex_t", pure, final, SysLock {.importc: "pthread_mutex_t", pure, final,
header: "<sys/types.h>".} = object header: "<sys/types.h>".} = object
SysLockAttr {.importc: "pthread_mutexattr_t", pure, final
header: "<sys/types.h>".} = object
SysCond {.importc: "pthread_cond_t", pure, final, SysCond {.importc: "pthread_cond_t", pure, final,
header: "<sys/types.h>".} = object header: "<sys/types.h>".} = object
SysLockType = distinct cint
proc initSysLock(L: var SysLock, attr: pointer = nil) {. proc SysLockType_Reentrant: SysLockType =
{.emit: "`result` = PTHREAD_MUTEX_RECURSIVE;".}
proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) {.
importc: "pthread_mutex_init", header: "<pthread.h>", noSideEffect.} importc: "pthread_mutex_init", header: "<pthread.h>", noSideEffect.}
proc initSysLockAttr(a: var SysLockAttr) {.
importc: "pthread_mutexattr_init", header: "<pthread.h>", noSideEffect.}
proc setSysLockType(a: var SysLockAttr, t: SysLockType) {.
importc: "pthread_mutexattr_settype", header: "<pthread.h>", noSideEffect.}
proc acquireSys(L: var SysLock) {.noSideEffect, proc acquireSys(L: var SysLock) {.noSideEffect,
importc: "pthread_mutex_lock", header: "<pthread.h>".} importc: "pthread_mutex_lock", header: "<pthread.h>".}
proc tryAcquireSysAux(L: var SysLock): cint {.noSideEffect, proc tryAcquireSysAux(L: var SysLock): cint {.noSideEffect,

View file

@ -309,9 +309,9 @@ when useWinUnicode:
stdcall, dynlib: "kernel32", importc: "FindNextFileW".} stdcall, dynlib: "kernel32", importc: "FindNextFileW".}
else: else:
proc findFirstFileA*(lpFileName: cstring, proc findFirstFileA*(lpFileName: cstring,
lpFindFileData: var WIN32_FIND_DATA): THANDLE {. lpFindFileData: var WIN32_FIND_DATA): Handle {.
stdcall, dynlib: "kernel32", importc: "FindFirstFileA".} stdcall, dynlib: "kernel32", importc: "FindFirstFileA".}
proc findNextFileA*(hFindFile: THANDLE, proc findNextFileA*(hFindFile: Handle,
lpFindFileData: var WIN32_FIND_DATA): int32 {. lpFindFileData: var WIN32_FIND_DATA): int32 {.
stdcall, dynlib: "kernel32", importc: "FindNextFileA".} stdcall, dynlib: "kernel32", importc: "FindNextFileA".}
@ -685,7 +685,7 @@ else:
proc createFileA*(lpFileName: cstring, dwDesiredAccess, dwShareMode: DWORD, proc createFileA*(lpFileName: cstring, dwDesiredAccess, dwShareMode: DWORD,
lpSecurityAttributes: pointer, lpSecurityAttributes: pointer,
dwCreationDisposition, dwFlagsAndAttributes: DWORD, dwCreationDisposition, dwFlagsAndAttributes: DWORD,
hTemplateFile: THANDLE): THANDLE {. hTemplateFile: Handle): Handle {.
stdcall, dynlib: "kernel32", importc: "CreateFileA".} stdcall, dynlib: "kernel32", importc: "CreateFileA".}
proc deleteFileA*(pathName: cstring): int32 {. proc deleteFileA*(pathName: cstring): int32 {.
importc: "DeleteFileA", dynlib: "kernel32", stdcall.} importc: "DeleteFileA", dynlib: "kernel32", stdcall.}
@ -715,10 +715,10 @@ proc createFileMappingW*(hFile: Handle,
stdcall, dynlib: "kernel32", importc: "CreateFileMappingW".} stdcall, dynlib: "kernel32", importc: "CreateFileMappingW".}
when not useWinUnicode: when not useWinUnicode:
proc createFileMappingA*(hFile: THANDLE, proc createFileMappingA*(hFile: Handle,
lpFileMappingAttributes: pointer, lpFileMappingAttributes: pointer,
flProtect, dwMaximumSizeHigh: DWORD, flProtect, dwMaximumSizeHigh: DWORD,
dwMaximumSizeLow: DWORD, lpName: cstring): THANDLE {. dwMaximumSizeLow: DWORD, lpName: cstring): Handle {.
stdcall, dynlib: "kernel32", importc: "CreateFileMappingA".} stdcall, dynlib: "kernel32", importc: "CreateFileMappingA".}
proc unmapViewOfFile*(lpBaseAddress: pointer): WINBOOL {.stdcall, proc unmapViewOfFile*(lpBaseAddress: pointer): WINBOOL {.stdcall,

View file

@ -127,9 +127,13 @@ Nim's Community
Gittip Gittip
.. raw:: html .. raw:: html
<iframe style="border: 0; margin: 0; padding: 0;" <img src="http://img.shields.io/gratipay/nim.svg">
src="https://www.gittip.com/nim-lang/widget.html"
width="64pt" height="22pt"></iframe> BountySource
.. raw:: html
<img src="https://img.shields.io/bountysource/team/mozilla-core/activity.svg">
Paypal Paypal
.. raw:: html .. raw:: html

View file

@ -2,6 +2,29 @@
News News
==== ====
2016-XX-XX Version 0.13.1 released
==================================
Changes affecting backwards compatibility
-----------------------------------------
- ``--out`` and ``--nimcache`` command line arguments are now relative to
current directory. Previously they were relative to project directory.
Library Additions
-----------------
- The rlocks module has been added providing reentrant lock synchronization
primitive
Compiler Additions
------------------
- Added a new ``--noCppExceptions`` switch that allows to use default exception
handling (no ``throw`` or ``try``/``catch`` generated) when compiling to C++
code
2016-01-27 Nim in Action is now available! 2016-01-27 Nim in Action is now available!
========================================== ==========================================
@ -11,7 +34,6 @@ News
<img src="assets/niminaction/banner.jpg" alt="New in Manning Early Access Program: Nim in Action!" width="682"/> <img src="assets/niminaction/banner.jpg" alt="New in Manning Early Access Program: Nim in Action!" width="682"/>
</a> </a>
We are proud to announce that *Nim in Action*, a book about the Nim programming We are proud to announce that *Nim in Action*, a book about the Nim programming
language, is now available! language, is now available!

View file

@ -126,7 +126,7 @@ General FAQ
-------------------------- --------------------------
- Nim IDE: https://github.com/nim-lang/Aporia - Nim IDE: https://github.com/nim-lang/Aporia
- Emacs: https://github.com/reactormonk/nim-mode - Emacs: https://github.com/nim-lang/nim-mode
- Vim: https://github.com/zah/nimrod.vim/ - Vim: https://github.com/zah/nimrod.vim/
- Scite: Included - Scite: Included
- Gedit: The `Aporia .lang file <https://github.com/nim-lang/Aporia/blob/master/share/gtksourceview-2.0/language-specs/nim.lang>`_ - Gedit: The `Aporia .lang file <https://github.com/nim-lang/Aporia/blob/master/share/gtksourceview-2.0/language-specs/nim.lang>`_

View file

@ -54,7 +54,7 @@ srcdoc2: "pure/collections/tables;pure/collections/sets;pure/collections/lists"
srcdoc2: "pure/collections/intsets;pure/collections/queues;pure/encodings" srcdoc2: "pure/collections/intsets;pure/collections/queues;pure/encodings"
srcdoc2: "pure/events;pure/collections/sequtils;pure/cookies" srcdoc2: "pure/events;pure/collections/sequtils;pure/cookies"
srcdoc2: "pure/memfiles;pure/subexes;pure/collections/critbits" srcdoc2: "pure/memfiles;pure/subexes;pure/collections/critbits"
srcdoc2: "deprecated/pure/asyncio;deprecated/pure/actors;core/locks;pure/oids;pure/endians;pure/uri" srcdoc2: "deprecated/pure/asyncio;deprecated/pure/actors;core/locks;core/rlocks;pure/oids;pure/endians;pure/uri"
srcdoc2: "pure/nimprof;pure/unittest;packages/docutils/highlite" srcdoc2: "pure/nimprof;pure/unittest;packages/docutils/highlite"
srcdoc2: "packages/docutils/rst;packages/docutils/rstast" srcdoc2: "packages/docutils/rst;packages/docutils/rstast"
srcdoc2: "packages/docutils/rstgen;pure/logging;pure/options;pure/asyncdispatch;pure/asyncnet" srcdoc2: "packages/docutils/rstgen;pure/logging;pure/options;pure/asyncdispatch;pure/asyncnet"