Merge remote-tracking branch 'nim-lang/devel' into emscripten-support
This commit is contained in:
commit
4c53a3a7a5
35 changed files with 156 additions and 83 deletions
14
.travis.yml
14
.travis.yml
|
|
@ -1,10 +1,20 @@
|
||||||
|
sudo: false
|
||||||
language: c
|
language: c
|
||||||
os: linux
|
os:
|
||||||
|
- linux
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- libcurl4-openssl-dev
|
||||||
|
- libsdl1.2-dev
|
||||||
script:
|
script:
|
||||||
- git clone --depth 1 https://github.com/nim-lang/csources.git
|
- git clone --depth 1 https://github.com/nim-lang/csources.git
|
||||||
- cd csources && sh build.sh
|
- cd csources
|
||||||
|
- sh build.sh
|
||||||
|
- cd ..
|
||||||
- ./bin/nim c koch
|
- ./bin/nim c koch
|
||||||
- ./koch boot
|
- ./koch boot
|
||||||
- ./koch boot -d:release
|
- ./koch boot -d:release
|
||||||
after_script:
|
after_script:
|
||||||
|
- export PATH=$(pwd)/bin:$PATH
|
||||||
- ./koch test
|
- ./koch test
|
||||||
|
|
|
||||||
|
|
@ -784,6 +784,7 @@ type
|
||||||
tab*: TStrTable # interface table for modules
|
tab*: TStrTable # interface table for modules
|
||||||
of skLet, skVar, skField, skForVar:
|
of skLet, skVar, skField, skForVar:
|
||||||
guard*: PSym
|
guard*: PSym
|
||||||
|
bitsize*: int
|
||||||
else: nil
|
else: nil
|
||||||
magic*: TMagic
|
magic*: TMagic
|
||||||
typ*: PType
|
typ*: PType
|
||||||
|
|
|
||||||
|
|
@ -441,6 +441,8 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
|
||||||
elif fieldType.kind == tySequence:
|
elif fieldType.kind == tySequence:
|
||||||
# we need to use a weak dependency here for trecursive_table.
|
# we need to use a weak dependency here for trecursive_table.
|
||||||
addf(result, "$1 $2;$n", [getTypeDescWeak(m, field.loc.t, check), sname])
|
addf(result, "$1 $2;$n", [getTypeDescWeak(m, field.loc.t, check), sname])
|
||||||
|
elif field.bitsize != 0:
|
||||||
|
addf(result, "$1 $2:$3;$n", [getTypeDescAux(m, field.loc.t, check), sname, rope($field.bitsize)])
|
||||||
else:
|
else:
|
||||||
# don't use fieldType here because we need the
|
# don't use fieldType here because we need the
|
||||||
# tyGenericInst for C++ template support
|
# tyGenericInst for C++ template support
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ const
|
||||||
wInheritable, wGensym, wInject, wRequiresInit, wUnchecked, wUnion, wPacked,
|
wInheritable, wGensym, wInject, wRequiresInit, wUnchecked, wUnion, wPacked,
|
||||||
wBorrow, wGcSafe}
|
wBorrow, wGcSafe}
|
||||||
fieldPragmas* = {wImportc, wExportc, wDeprecated, wExtern,
|
fieldPragmas* = {wImportc, wExportc, wDeprecated, wExtern,
|
||||||
wImportCpp, wImportObjC, wError, wGuard}
|
wImportCpp, wImportObjC, wError, wGuard, wBitsize}
|
||||||
varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl,
|
varPragmas* = {wImportc, wExportc, wVolatile, wRegister, wThreadVar, wNodecl,
|
||||||
wMagic, wHeader, wDeprecated, wCompilerproc, wDynlib, wExtern,
|
wMagic, wHeader, wDeprecated, wCompilerproc, wDynlib, wExtern,
|
||||||
wImportCpp, wImportObjC, wError, wNoInit, wCompileTime, wGlobal,
|
wImportCpp, wImportObjC, wError, wNoInit, wCompileTime, wGlobal,
|
||||||
|
|
@ -844,6 +844,11 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
if sym == nil: pragmaLockStmt(c, it)
|
if sym == nil: pragmaLockStmt(c, it)
|
||||||
elif sym.typ == nil: invalidPragma(it)
|
elif sym.typ == nil: invalidPragma(it)
|
||||||
else: sym.typ.lockLevel = pragmaLocks(c, it)
|
else: sym.typ.lockLevel = pragmaLocks(c, it)
|
||||||
|
of wBitsize:
|
||||||
|
if sym == nil or sym.kind != skField or it.kind != nkExprColonExpr:
|
||||||
|
invalidPragma(it)
|
||||||
|
else:
|
||||||
|
sym.bitsize = expectIntLit(c, it)
|
||||||
of wGuard:
|
of wGuard:
|
||||||
if sym == nil or sym.kind notin {skVar, skLet, skField}:
|
if sym == nil or sym.kind notin {skVar, skLet, skField}:
|
||||||
invalidPragma(it)
|
invalidPragma(it)
|
||||||
|
|
|
||||||
|
|
@ -140,4 +140,7 @@ proc runNimScript*(scriptName: string) =
|
||||||
# ensure we load 'system.nim' again for the real non-config stuff!
|
# ensure we load 'system.nim' again for the real non-config stuff!
|
||||||
resetAllModulesHard()
|
resetAllModulesHard()
|
||||||
vm.globalCtx = nil
|
vm.globalCtx = nil
|
||||||
initDefines()
|
# do not remove the defined symbols
|
||||||
|
#initDefines()
|
||||||
|
undefSymbol("nimscript")
|
||||||
|
undefSymbol("nimconfig")
|
||||||
|
|
|
||||||
|
|
@ -311,7 +311,7 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool =
|
||||||
if f.position == x:
|
if f.position == x:
|
||||||
dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal
|
dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal
|
||||||
return
|
return
|
||||||
internalError("opConv for enum")
|
dest.node.strVal = styp.sym.name.s & " " & $x
|
||||||
of tyInt..tyInt64:
|
of tyInt..tyInt64:
|
||||||
dest.node.strVal = $src.intVal
|
dest.node.strVal = $src.intVal
|
||||||
of tyUInt..tyUInt64:
|
of tyUInt..tyUInt64:
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ when hasFFI:
|
||||||
import evalffi
|
import evalffi
|
||||||
|
|
||||||
type
|
type
|
||||||
TGenFlag = enum gfNone, gfAddrOf
|
TGenFlag = enum gfAddrOf, gfFieldAccess
|
||||||
TGenFlags = set[TGenFlag]
|
TGenFlags = set[TGenFlag]
|
||||||
|
|
||||||
proc debugInfo(info: TLineInfo): string =
|
proc debugInfo(info: TLineInfo): string =
|
||||||
|
|
@ -535,7 +535,7 @@ proc genIndex(c: PCtx; n: PNode; arr: PType): TRegister =
|
||||||
proc genAsgnPatch(c: PCtx; le: PNode, value: TRegister) =
|
proc genAsgnPatch(c: PCtx; le: PNode, value: TRegister) =
|
||||||
case le.kind
|
case le.kind
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
let dest = c.genx(le.sons[0], {gfAddrOf})
|
let dest = c.genx(le.sons[0], {gfAddrOf, gfFieldAccess})
|
||||||
let idx = c.genIndex(le.sons[1], le.sons[0].typ)
|
let idx = c.genIndex(le.sons[1], le.sons[0].typ)
|
||||||
c.gABC(le, opcWrArr, dest, idx, value)
|
c.gABC(le, opcWrArr, dest, idx, value)
|
||||||
c.freeTemp(dest)
|
c.freeTemp(dest)
|
||||||
|
|
@ -543,7 +543,7 @@ proc genAsgnPatch(c: PCtx; le: PNode, value: TRegister) =
|
||||||
of nkDotExpr, nkCheckedFieldExpr:
|
of nkDotExpr, nkCheckedFieldExpr:
|
||||||
# XXX field checks here
|
# XXX field checks here
|
||||||
let left = if le.kind == nkDotExpr: le else: le.sons[0]
|
let left = if le.kind == nkDotExpr: le else: le.sons[0]
|
||||||
let dest = c.genx(left.sons[0], {gfAddrOf})
|
let dest = c.genx(left.sons[0], {gfAddrOf, gfFieldAccess})
|
||||||
let idx = genField(left.sons[1])
|
let idx = genField(left.sons[1])
|
||||||
c.gABC(left, opcWrObj, dest, idx, value)
|
c.gABC(left, opcWrObj, dest, idx, value)
|
||||||
c.freeTemp(dest)
|
c.freeTemp(dest)
|
||||||
|
|
@ -1216,7 +1216,7 @@ proc preventFalseAlias(c: PCtx; n: PNode; opc: TOpcode;
|
||||||
proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
|
proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
|
||||||
case le.kind
|
case le.kind
|
||||||
of nkBracketExpr:
|
of nkBracketExpr:
|
||||||
let dest = c.genx(le.sons[0], {gfAddrOf})
|
let dest = c.genx(le.sons[0], {gfAddrOf, gfFieldAccess})
|
||||||
let idx = c.genIndex(le.sons[1], le.sons[0].typ)
|
let idx = c.genIndex(le.sons[1], le.sons[0].typ)
|
||||||
let tmp = c.genx(ri)
|
let tmp = c.genx(ri)
|
||||||
if le.sons[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind in {
|
if le.sons[0].typ.skipTypes(abstractVarRange-{tyTypeDesc}).kind in {
|
||||||
|
|
@ -1228,7 +1228,7 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) =
|
||||||
of nkDotExpr, nkCheckedFieldExpr:
|
of nkDotExpr, nkCheckedFieldExpr:
|
||||||
# XXX field checks here
|
# XXX field checks here
|
||||||
let left = if le.kind == nkDotExpr: le else: le.sons[0]
|
let left = if le.kind == nkDotExpr: le else: le.sons[0]
|
||||||
let dest = c.genx(left.sons[0], {gfAddrOf})
|
let dest = c.genx(left.sons[0], {gfAddrOf, gfFieldAccess})
|
||||||
let idx = genField(left.sons[1])
|
let idx = genField(left.sons[1])
|
||||||
let tmp = c.genx(ri)
|
let tmp = c.genx(ri)
|
||||||
c.preventFalseAlias(left, opcWrObj, dest, idx, tmp)
|
c.preventFalseAlias(left, opcWrObj, dest, idx, tmp)
|
||||||
|
|
@ -1321,7 +1321,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
|
||||||
c.gABx(n, opcLdGlobal, cc, s.position)
|
c.gABx(n, opcLdGlobal, cc, s.position)
|
||||||
c.gABC(n, opcNodeToReg, dest, cc)
|
c.gABC(n, opcNodeToReg, dest, cc)
|
||||||
c.freeTemp(cc)
|
c.freeTemp(cc)
|
||||||
elif gfAddrOf in flags:
|
elif {gfAddrOf, gfFieldAccess} * flags == {gfAddrOf}:
|
||||||
c.gABx(n, opcLdGlobalAddr, dest, s.position)
|
c.gABx(n, opcLdGlobalAddr, dest, s.position)
|
||||||
else:
|
else:
|
||||||
c.gABx(n, opcLdGlobal, dest, s.position)
|
c.gABx(n, opcLdGlobal, dest, s.position)
|
||||||
|
|
@ -1773,6 +1773,9 @@ proc genExpr*(c: PCtx; n: PNode, requiresValue = true): int =
|
||||||
d = 0
|
d = 0
|
||||||
c.gABC(n, opcEof, d)
|
c.gABC(n, opcEof, d)
|
||||||
|
|
||||||
|
#echo renderTree(n)
|
||||||
|
#c.echoCode(result)
|
||||||
|
|
||||||
proc genParams(c: PCtx; params: PNode) =
|
proc genParams(c: PCtx; params: PNode) =
|
||||||
# res.sym.position is already 0
|
# res.sym.position is already 0
|
||||||
c.prc.slots[0] = (inUse: true, kind: slotFixedVar)
|
c.prc.slots[0] = (inUse: true, kind: slotFixedVar)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@ type
|
||||||
wStdIn, wStdOut, wStdErr,
|
wStdIn, wStdOut, wStdErr,
|
||||||
|
|
||||||
wInOut, wByCopy, wByRef, wOneWay,
|
wInOut, wByCopy, wByRef, wOneWay,
|
||||||
|
wBitsize,
|
||||||
|
|
||||||
TSpecialWords* = set[TSpecialWord]
|
TSpecialWords* = set[TSpecialWord]
|
||||||
|
|
||||||
|
|
@ -168,6 +169,7 @@ const
|
||||||
"stdin", "stdout", "stderr",
|
"stdin", "stdout", "stderr",
|
||||||
|
|
||||||
"inout", "bycopy", "byref", "oneway",
|
"inout", "bycopy", "byref", "oneway",
|
||||||
|
"bitsize",
|
||||||
]
|
]
|
||||||
|
|
||||||
proc findStr*(a: openArray[string], s: string): int =
|
proc findStr*(a: openArray[string], s: string): int =
|
||||||
|
|
|
||||||
|
|
@ -531,6 +531,24 @@ Implementation Specific Pragmas
|
||||||
This section describes additional pragmas that the current Nim implementation
|
This section describes additional pragmas that the current Nim implementation
|
||||||
supports but which should not be seen as part of the language specification.
|
supports but which should not be seen as part of the language specification.
|
||||||
|
|
||||||
|
Bitsize pragma
|
||||||
|
--------------
|
||||||
|
|
||||||
|
The ``bitsize`` pragma is for object field members. It declares the field as
|
||||||
|
a bitfield in C/C++.
|
||||||
|
|
||||||
|
.. code-block:: Nim
|
||||||
|
type
|
||||||
|
mybitfield = object
|
||||||
|
flag {.bitsize:1.}: cuint
|
||||||
|
|
||||||
|
generates:
|
||||||
|
|
||||||
|
.. code-block:: C
|
||||||
|
struct mybitfield {
|
||||||
|
unsigned int flag:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Volatile pragma
|
Volatile pragma
|
||||||
---------------
|
---------------
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
import
|
|
||||||
libcurl
|
|
||||||
|
|
||||||
var hCurl = easy_init()
|
|
||||||
if hCurl != nil:
|
|
||||||
discard easy_setopt(hCurl, OPT_VERBOSE, true)
|
|
||||||
discard easy_setopt(hCurl, OPT_URL, "http://nim-lang.org/")
|
|
||||||
discard easy_perform(hCurl)
|
|
||||||
easy_cleanup(hCurl)
|
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl | standard
|
#? stdtmpl | standard
|
||||||
#proc generateHTMLPage(title, currentTab, content: string,
|
#proc generateHTMLPage(title, currentTab, content: string,
|
||||||
# tabs: openArray[string]): string =
|
# tabs: openArray[string]): string =
|
||||||
# result = ""
|
# result = ""
|
||||||
|
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
# Example IUP program
|
|
||||||
|
|
||||||
# iupTabs: Creates a iupTabs control.
|
|
||||||
|
|
||||||
import iup
|
|
||||||
|
|
||||||
discard iup.open(nil, nil)
|
|
||||||
|
|
||||||
var vbox1 = iup.vbox(iup.label("Inside Tab A"), iup.button("Button A", ""), nil)
|
|
||||||
var vbox2 = iup.vbox(iup.label("Inside Tab B"), iup.button("Button B", ""), nil)
|
|
||||||
|
|
||||||
iup.setAttribute(vbox1, "TABTITLE", "Tab A")
|
|
||||||
iup.setAttribute(vbox2, "TABTITLE", "Tab B")
|
|
||||||
|
|
||||||
var tabs1 = iup.tabs(vbox1, vbox2, nil)
|
|
||||||
|
|
||||||
vbox1 = iup.vbox(iup.label("Inside Tab C"), iup.button("Button C", ""), nil)
|
|
||||||
vbox2 = iup.vbox(iup.label("Inside Tab D"), iup.button("Button D", ""), nil)
|
|
||||||
|
|
||||||
iup.setAttribute(vbox1, "TABTITLE", "Tab C")
|
|
||||||
iup.setAttribute(vbox2, "TABTITLE", "Tab D")
|
|
||||||
|
|
||||||
var tabs2 = iup.tabs(vbox1, vbox2, nil)
|
|
||||||
iup.setAttribute(tabs2, "TABTYPE", "LEFT")
|
|
||||||
|
|
||||||
var box = iup.hbox(tabs1, tabs2, nil)
|
|
||||||
iup.setAttribute(box, "MARGIN", "10x10")
|
|
||||||
iup.setAttribute(box, "GAP", "10")
|
|
||||||
|
|
||||||
var dlg = iup.dialog(box)
|
|
||||||
iup.setAttribute(dlg, "TITLE", "iupTabs")
|
|
||||||
iup.setAttribute(dlg, "SIZE", "200x100")
|
|
||||||
|
|
||||||
discard showXY(dlg, IUP_CENTER, IUP_CENTER)
|
|
||||||
discard mainLoop()
|
|
||||||
close()
|
|
||||||
|
|
||||||
|
|
@ -18,8 +18,9 @@ type Rational*[T] = object
|
||||||
## a rational number, consisting of a numerator and denominator
|
## a rational number, consisting of a numerator and denominator
|
||||||
num*, den*: T
|
num*, den*: T
|
||||||
|
|
||||||
proc initRational*[T](num, den: T): Rational[T] =
|
proc initRational*[T:SomeInteger](num, den: T): Rational[T] =
|
||||||
## Create a new rational number.
|
## Create a new rational number.
|
||||||
|
assert(den != 0, "a denominator of zero value is invalid")
|
||||||
result.num = num
|
result.num = num
|
||||||
result.den = den
|
result.den = den
|
||||||
|
|
||||||
|
|
@ -33,7 +34,7 @@ proc `$`*[T](x: Rational[T]): string =
|
||||||
## Turn a rational number into a string.
|
## Turn a rational number into a string.
|
||||||
result = $x.num & "/" & $x.den
|
result = $x.num & "/" & $x.den
|
||||||
|
|
||||||
proc toRational*[T](x: T): Rational[T] =
|
proc toRational*[T:SomeInteger](x: T): Rational[T] =
|
||||||
## Convert some integer `x` to a rational number.
|
## Convert some integer `x` to a rational number.
|
||||||
result.num = x
|
result.num = x
|
||||||
result.den = 1
|
result.den = 1
|
||||||
|
|
@ -47,7 +48,7 @@ proc toInt*[T](x: Rational[T]): int =
|
||||||
## `x` does not contain an integer value.
|
## `x` does not contain an integer value.
|
||||||
x.num div x.den
|
x.num div x.den
|
||||||
|
|
||||||
proc reduce*[T](x: var Rational[T]) =
|
proc reduce*[T:SomeInteger](x: var Rational[T]) =
|
||||||
## Reduce rational `x`.
|
## Reduce rational `x`.
|
||||||
let common = gcd(x.num, x.den)
|
let common = gcd(x.num, x.den)
|
||||||
if x.den > 0:
|
if x.den > 0:
|
||||||
|
|
|
||||||
|
|
@ -103,15 +103,16 @@ proc readData*(s: Stream, buffer: pointer, bufLen: int): int =
|
||||||
|
|
||||||
proc readAll*(s: Stream): string =
|
proc readAll*(s: Stream): string =
|
||||||
## Reads all available data.
|
## Reads all available data.
|
||||||
result = newString(1000)
|
const bufferSize = 1000
|
||||||
|
result = newString(bufferSize)
|
||||||
var r = 0
|
var r = 0
|
||||||
while true:
|
while true:
|
||||||
let readBytes = readData(s, addr(result[r]), 1000)
|
let readBytes = readData(s, addr(result[r]), bufferSize)
|
||||||
if readBytes < 1000:
|
if readBytes < bufferSize:
|
||||||
setLen(result, r+readBytes)
|
setLen(result, r+readBytes)
|
||||||
break
|
break
|
||||||
inc r, 1000
|
inc r, bufferSize
|
||||||
setLen(result, r+1000)
|
setLen(result, r+bufferSize)
|
||||||
|
|
||||||
proc readData*(s, unused: Stream, buffer: pointer,
|
proc readData*(s, unused: Stream, buffer: pointer,
|
||||||
bufLen: int): int {.deprecated.} =
|
bufLen: int): int {.deprecated.} =
|
||||||
|
|
|
||||||
|
|
@ -1256,7 +1256,7 @@ proc compileOption*(option, arg: string): bool {.
|
||||||
## echo "compiled with optimization for size and uses Boehm's GC"
|
## echo "compiled with optimization for size and uses Boehm's GC"
|
||||||
|
|
||||||
const
|
const
|
||||||
hasThreadSupport = compileOption("threads")
|
hasThreadSupport = compileOption("threads") and not defined(nimscript)
|
||||||
hasSharedHeap = defined(boehmgc) or defined(gogc) # don't share heaps; every thread has its own
|
hasSharedHeap = defined(boehmgc) or defined(gogc) # don't share heaps; every thread has its own
|
||||||
taintMode = compileOption("taintmode")
|
taintMode = compileOption("taintmode")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,11 @@ sysAssert(roundup(65, 8) == 72, "roundup broken 2")
|
||||||
# some platforms have really weird unmap behaviour: unmap(blockStart, PageSize)
|
# some platforms have really weird unmap behaviour: unmap(blockStart, PageSize)
|
||||||
# really frees the whole block. Happens for Linux/PowerPC for example. Amd64
|
# really frees the whole block. Happens for Linux/PowerPC for example. Amd64
|
||||||
# and x86 are safe though; Windows is special because MEM_RELEASE can only be
|
# and x86 are safe though; Windows is special because MEM_RELEASE can only be
|
||||||
# used with a size of 0:
|
# used with a size of 0. We also allow unmapping to be turned off with
|
||||||
const weirdUnmap = not (defined(amd64) or defined(i386)) or defined(windows)
|
# -d:nimAllocNoUnmap:
|
||||||
|
const doNotUnmap = not (defined(amd64) or defined(i386)) or
|
||||||
|
defined(windows) or defined(nimAllocNoUnmap)
|
||||||
|
|
||||||
|
|
||||||
when defined(emscripten):
|
when defined(emscripten):
|
||||||
const
|
const
|
||||||
|
|
@ -525,7 +528,7 @@ proc freeBigChunk(a: var MemRegion, c: PBigChunk) =
|
||||||
excl(a.chunkStarts, pageIndex(c))
|
excl(a.chunkStarts, pageIndex(c))
|
||||||
c = cast[PBigChunk](le)
|
c = cast[PBigChunk](le)
|
||||||
|
|
||||||
if c.size < ChunkOsReturn or weirdUnmap:
|
if c.size < ChunkOsReturn or doNotUnmap:
|
||||||
incl(a, a.chunkStarts, pageIndex(c))
|
incl(a, a.chunkStarts, pageIndex(c))
|
||||||
updatePrevSize(a, c, c.size)
|
updatePrevSize(a, c, c.size)
|
||||||
listAdd(a.freeChunksList, c)
|
listAdd(a.freeChunksList, c)
|
||||||
|
|
@ -809,7 +812,7 @@ proc deallocOsPages(a: var MemRegion) =
|
||||||
# we free every 'ordinarily' allocated page by iterating over the page bits:
|
# we free every 'ordinarily' allocated page by iterating over the page bits:
|
||||||
for p in elements(a.chunkStarts):
|
for p in elements(a.chunkStarts):
|
||||||
var page = cast[PChunk](p shl PageShift)
|
var page = cast[PChunk](p shl PageShift)
|
||||||
when not weirdUnmap:
|
when not doNotUnmap:
|
||||||
var size = if page.size < PageSize: PageSize else: page.size
|
var size = if page.size < PageSize: PageSize else: page.size
|
||||||
osDeallocPages(page, size)
|
osDeallocPages(page, size)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,7 @@ discard """
|
||||||
msg: '''[NimScript] exec: gcc -v'''
|
msg: '''[NimScript] exec: gcc -v'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
when not defined(definedefine):
|
||||||
|
{.fatal: "wrong nim script configuration".}
|
||||||
|
|
||||||
echo "hello world!"
|
echo "hello world!"
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,6 @@ task listDirs, "lists every subdirectory":
|
||||||
echo "DIR ", x
|
echo "DIR ", x
|
||||||
|
|
||||||
task default, "default target":
|
task default, "default target":
|
||||||
|
--define: definedefine
|
||||||
setCommand "c"
|
setCommand "c"
|
||||||
|
|
||||||
|
|
|
||||||
22
tests/pragmas/tbitsize.nim
Normal file
22
tests/pragmas/tbitsize.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
discard """
|
||||||
|
ccodeCheck: "\\i @'unsigned int flag:1;' .*"
|
||||||
|
"""
|
||||||
|
|
||||||
|
type
|
||||||
|
bits* = object
|
||||||
|
flag* {.bitsize: 1.}: cuint
|
||||||
|
opts* {.bitsize: 4.}: cint
|
||||||
|
|
||||||
|
var
|
||||||
|
b: bits
|
||||||
|
|
||||||
|
assert b.flag == 0
|
||||||
|
b.flag = 1
|
||||||
|
assert b.flag == 1
|
||||||
|
b.flag = 2
|
||||||
|
assert b.flag == 0
|
||||||
|
|
||||||
|
b.opts = 7
|
||||||
|
assert b.opts == 7
|
||||||
|
b.opts = 9
|
||||||
|
assert b.opts == -7
|
||||||
9
tests/rational/trat_float.nim
Normal file
9
tests/rational/trat_float.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
discard """
|
||||||
|
file: "trat_float.nim"
|
||||||
|
line: "9,19"
|
||||||
|
errormsg: '''type mismatch: got'''
|
||||||
|
"""
|
||||||
|
import rationals
|
||||||
|
var
|
||||||
|
# this fails - no floats as num or den
|
||||||
|
r = initRational(1.0'f, 1.0'f)
|
||||||
10
tests/rational/trat_init.nim
Normal file
10
tests/rational/trat_init.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
file: "trat_init.nim"
|
||||||
|
exitcode: "1"
|
||||||
|
"""
|
||||||
|
import rationals
|
||||||
|
var
|
||||||
|
z = Rational[int](num: 0, den: 1)
|
||||||
|
o = initRational(num=1, den=1)
|
||||||
|
a = initRational(1, 2)
|
||||||
|
r = initRational(1, 0) # this fails - no zero denominator
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tmemfiles2.nim"
|
file: "tmemfiles2.nim"
|
||||||
|
disabled: true
|
||||||
output: '''Full read size: 20
|
output: '''Full read size: 20
|
||||||
Half read size: 10 Data: Hello'''
|
Half read size: 10 Data: Hello'''
|
||||||
"""
|
"""
|
||||||
|
# doesn't work on windows. fmReadWrite doesn't create a file.
|
||||||
import memfiles, os
|
import memfiles, os
|
||||||
var
|
var
|
||||||
mm, mm_full, mm_half: MemFile
|
mm, mm_full, mm_half: MemFile
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl
|
#? stdtmpl
|
||||||
#proc sunsetTemplate*(current, ticker, content: string,
|
#proc sunsetTemplate*(current, ticker, content: string,
|
||||||
# tabs: openarray[array[0..1, string]]): string =
|
# tabs: openarray[array[0..1, string]]): string =
|
||||||
# result = ""
|
# result = ""
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ proc `&?.`(a, b: string): string =
|
||||||
# candidate for the stdlib?
|
# candidate for the stdlib?
|
||||||
result = if a.endswith(b): a else: a & b
|
result = if a.endswith(b): a else: a & b
|
||||||
|
|
||||||
proc processCategory(r: var TResults, cat: Category, options: string) =
|
proc processCategory(r: var TResults, cat: Category, options: string, fileGlob: string = "t*.nim") =
|
||||||
case cat.string.normalize
|
case cat.string.normalize
|
||||||
of "rodfiles":
|
of "rodfiles":
|
||||||
discard # Disabled for now
|
discard # Disabled for now
|
||||||
|
|
@ -377,5 +377,5 @@ proc processCategory(r: var TResults, cat: Category, options: string) =
|
||||||
of "nimble-all":
|
of "nimble-all":
|
||||||
testNimblePackages(r, cat, pfAll)
|
testNimblePackages(r, cat, pfAll)
|
||||||
else:
|
else:
|
||||||
for name in os.walkFiles("tests" & DirSep &.? cat.string / "t*.nim"):
|
for name in os.walkFiles("tests" & DirSep &.? cat.string / fileGlob):
|
||||||
testSpec r, makeTest(name, options, cat)
|
testSpec r, makeTest(name, options, cat)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ const
|
||||||
Command:
|
Command:
|
||||||
all run all tests
|
all run all tests
|
||||||
c|category <category> run all the tests of a certain category
|
c|category <category> run all the tests of a certain category
|
||||||
|
r|run <test> run single test file
|
||||||
html [commit] generate $1 from the database; uses the latest
|
html [commit] generate $1 from the database; uses the latest
|
||||||
commit or a specific one (use -1 for the commit
|
commit or a specific one (use -1 for the commit
|
||||||
before latest etc)
|
before latest etc)
|
||||||
|
|
@ -376,6 +377,11 @@ proc main() =
|
||||||
var cat = Category(p.key)
|
var cat = Category(p.key)
|
||||||
p.next
|
p.next
|
||||||
processCategory(r, cat, p.cmdLineRest.string)
|
processCategory(r, cat, p.cmdLineRest.string)
|
||||||
|
of "r", "run":
|
||||||
|
let (dir, file) = splitPath(p.key.string)
|
||||||
|
let (_, subdir) = splitPath(dir)
|
||||||
|
var cat = Category(subdir)
|
||||||
|
processCategory(r, cat, p.cmdLineRest.string, file)
|
||||||
of "html":
|
of "html":
|
||||||
var commit = 0
|
var commit = 0
|
||||||
discard parseInt(p.cmdLineRest.string, commit)
|
discard parseInt(p.cmdLineRest.string, commit)
|
||||||
|
|
|
||||||
16
tests/vm/tsimpleglobals.nim
Normal file
16
tests/vm/tsimpleglobals.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
discard """
|
||||||
|
msg: "abc xyz bb"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #2473
|
||||||
|
type
|
||||||
|
Test = tuple[a,b: string]
|
||||||
|
|
||||||
|
static:
|
||||||
|
var s:seq[Test] = @[(a:"a", b:"b")]
|
||||||
|
s[0] = (a:"aa", b:"bb")
|
||||||
|
|
||||||
|
var x: Test
|
||||||
|
x.a = "abc"
|
||||||
|
x.b = "xyz"
|
||||||
|
echo x.a, " ", x.b, " ", s[0].b
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "cannot evaluate at compile time: x"
|
errormsg: "cannot evaluate at compile time: x"
|
||||||
line: 9
|
line: 7
|
||||||
"""
|
"""
|
||||||
|
|
||||||
var x: array[100, char]
|
var x: array[100, char]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl(subsChar='?') | standard
|
#? stdtmpl(subsChar='?') | standard
|
||||||
#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex: int): string =
|
#proc generateBuildBatchScript(c: ConfigData, winIndex, cpuIndex: int): string =
|
||||||
# result = "@echo off\nREM Generated by niminst\n"
|
# result = "@echo off\nREM Generated by niminst\n"
|
||||||
SET CC=gcc
|
SET CC=gcc
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl(subsChar='?') | standard
|
#? stdtmpl(subsChar='?') | standard
|
||||||
#proc generateBuildShellScript(c: ConfigData): string =
|
#proc generateBuildShellScript(c: ConfigData): string =
|
||||||
# result = "#! /bin/sh\n# Generated from niminst\n" &
|
# result = "#! /bin/sh\n# Generated from niminst\n" &
|
||||||
# "# Template is in tools/niminst/buildsh.tmpl\n" &
|
# "# Template is in tools/niminst/buildsh.tmpl\n" &
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl(subsChar='?') | standard
|
#? stdtmpl(subsChar='?') | standard
|
||||||
#proc generateDeinstallScript(c: ConfigData): string =
|
#proc generateDeinstallScript(c: ConfigData): string =
|
||||||
# result = "#! /bin/sh\n# Generated by niminst\n"
|
# result = "#! /bin/sh\n# Generated by niminst\n"
|
||||||
# var proj = c.name.toLower
|
# var proj = c.name.toLower
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl | standard
|
#? stdtmpl | standard
|
||||||
#proc generateInnoSetup(c: ConfigData): string =
|
#proc generateInnoSetup(c: ConfigData): string =
|
||||||
# result = ""
|
# result = ""
|
||||||
; Default Template for NimInst
|
; Default Template for NimInst
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl(subsChar = '?') | standard
|
#? stdtmpl(subsChar = '?') | standard
|
||||||
#proc generateInstallScript(c: ConfigData): string =
|
#proc generateInstallScript(c: ConfigData): string =
|
||||||
# result = "#! /bin/sh\n# Generated by niminst\n"
|
# result = "#! /bin/sh\n# Generated by niminst\n"
|
||||||
# var proj = c.name.toLower
|
# var proj = c.name.toLower
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl(subsChar='?') | standard
|
#? stdtmpl(subsChar='?') | standard
|
||||||
#proc generateMakefile(c: ConfigData): string =
|
#proc generateMakefile(c: ConfigData): string =
|
||||||
# result = "# Generated from niminst\n" &
|
# result = "# Generated from niminst\n" &
|
||||||
# "# Template is in tools/niminst/makefile.tmpl\n" &
|
# "# Template is in tools/niminst/makefile.tmpl\n" &
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#! stdtmpl(subsChar='?') | standard
|
#? stdtmpl(subsChar='?') | standard
|
||||||
#proc generateNsisSetup(c: ConfigData): string =
|
#proc generateNsisSetup(c: ConfigData): string =
|
||||||
# result = "; NSIS script generated by niminst\n" &
|
# result = "; NSIS script generated by niminst\n" &
|
||||||
# "; To regenerate run ``niminst nsis`` or ``koch nsis``\n"
|
# "; To regenerate run ``niminst nsis`` or ``koch nsis``\n"
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,8 @@ News
|
||||||
- The compiler finally considers symbol binding rules in templates and
|
- The compiler finally considers symbol binding rules in templates and
|
||||||
generics for overloaded ``[]``, ``[]=``, ``{}``, ``{}=`` operators
|
generics for overloaded ``[]``, ``[]=``, ``{}``, ``{}=`` operators
|
||||||
(issue `#2599 <https://github.com/nim-lang/Nim/issues/2599>`_).
|
(issue `#2599 <https://github.com/nim-lang/Nim/issues/2599>`_).
|
||||||
|
- The compiler now supports a `bitsize pragma <docs/manual.html#pragmas-bitsize-pragma>`_
|
||||||
|
for constructing bitfields.
|
||||||
|
|
||||||
|
|
||||||
Language Additions
|
Language Additions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue