Merge remote-tracking branch 'nim-lang/devel' into emscripten-support

This commit is contained in:
Andrey Sobolev 2015-09-25 14:05:33 +06:00
commit 30362315a0
19 changed files with 381 additions and 636 deletions

View file

@ -0,0 +1,28 @@
discard """
output: "500"
"""
import threadpool, sequtils
{.experimental.}
proc linearFind(a: openArray[int]; x, offset: int): int =
for i, y in a:
if y == x: return i+offset
result = -1
proc parFind(a: seq[int]; x: int): int =
var results: array[4, int]
parallel:
if a.len >= 4:
let chunk = a.len div 4
results[0] = spawn linearFind(a[0 ..< chunk], x, 0)
results[1] = spawn linearFind(a[chunk ..< chunk*2], x, chunk)
results[2] = spawn linearFind(a[chunk*2 ..< chunk*3], x, chunk*2)
results[3] = spawn linearFind(a[chunk*3 ..< a.len], x, chunk*3)
result = max(results)
let data = toSeq(0..1000)
echo parFind(data, 500)

View file

@ -0,0 +1,13 @@
discard """
test that closing a closed file is ignored (no error raised)
file: "tmemfiles1.nim"
"""
import memfiles, os
var
mm: MemFile
fn = "test.mmap"
# Create a new file
mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20)
mm.close()
mm.close()
if fileExists(fn): removeFile(fn)

View file

@ -0,0 +1,38 @@
discard """
test creating/reading/writing/changing memfiles
file: "tmemfiles2.nim"
output: '''Full read size: 20
Half read size: 10 Data: Hello'''
"""
import memfiles, os
var
mm, mm_full, mm_half: MemFile
fn = "test.mmap"
p: pointer
if fileExists(fn): removeFile(fn)
# Create a new file, data all zeros
mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20)
mm.close()
# read, change
mm_full = memfiles.open(fn, mode = fmWrite, mappedSize = -1)
echo "Full read size: ",mm_full.size
p = mm_full.mapMem(fmReadWrite, 20, 0)
var p2 = cast[cstring](p)
p2[0] = 'H'
p2[1] = 'e'
p2[2] = 'l'
p2[3] = 'l'
p2[4] = 'o'
p2[5] = '\0'
mm_full.unmapMem(p, 20)
mm_full.close()
# read half, and verify data change
mm_half = memfiles.open(fn, mode = fmRead, mappedSize = 10)
echo "Half read size: ",mm_half.size, " Data: ", cast[cstring](mm_half.mem)
mm_half.close()
if fileExists(fn): removeFile(fn)

21
tests/vm/tyaytypedesc.nim Normal file
View file

@ -0,0 +1,21 @@
discard """
output: "ntWhitespace"
"""
# bug #3357
type NodeType* = enum
ntWhitespace
type TokenType* = enum
ttWhitespace
proc enumTable*[A, B, C](a: openarray[tuple[key: A, val: B]], ret: typedesc[C]): C =
for item in a:
result[item.key] = item.val
const tokenTypeToNodeType = {
ttWhitespace: ntWhitespace,
}.enumTable(array[ttWhitespace..ttWhitespace, NodeType])
echo tokenTypeToNodeType[ttWhitespace]