tests: Trim .nim files trailing whitespace
via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
This commit is contained in:
parent
ac9c1cd6b9
commit
e80465dacf
372 changed files with 4486 additions and 4486 deletions
|
|
@ -4,23 +4,23 @@ discard """
|
||||||
|
|
||||||
import tables
|
import tables
|
||||||
|
|
||||||
proc action1(arg: string) =
|
proc action1(arg: string) =
|
||||||
echo "action 1 ", arg
|
echo "action 1 ", arg
|
||||||
|
|
||||||
proc action2(arg: string) =
|
proc action2(arg: string) =
|
||||||
echo "action 2 ", arg
|
echo "action 2 ", arg
|
||||||
|
|
||||||
proc action3(arg: string) =
|
proc action3(arg: string) =
|
||||||
echo "action 3 ", arg
|
echo "action 3 ", arg
|
||||||
|
|
||||||
proc action4(arg: string) =
|
proc action4(arg: string) =
|
||||||
echo "action 4 ", arg
|
echo "action 4 ", arg
|
||||||
|
|
||||||
var
|
var
|
||||||
actionTable = {
|
actionTable = {
|
||||||
"A": action1,
|
"A": action1,
|
||||||
"B": action2,
|
"B": action2,
|
||||||
"C": action3,
|
"C": action3,
|
||||||
"D": action4}.toTable
|
"D": action4}.toTable
|
||||||
|
|
||||||
actionTable["C"]("arg")
|
actionTable["C"]("arg")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ type
|
||||||
|
|
||||||
proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {.
|
proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {.
|
||||||
magic: "IsPartOf", noSideEffect.}
|
magic: "IsPartOf", noSideEffect.}
|
||||||
## not yet exported properly.
|
## not yet exported properly.
|
||||||
|
|
||||||
template compileTimeAssert(cond: expr) =
|
template compileTimeAssert(cond: expr) =
|
||||||
when not cond:
|
when not cond:
|
||||||
|
|
@ -35,30 +35,30 @@ proc p(param1, param2: TC): TC =
|
||||||
local: TC
|
local: TC
|
||||||
plocal: ptr TC
|
plocal: ptr TC
|
||||||
plocal2: ptr TA
|
plocal2: ptr TA
|
||||||
|
|
||||||
local.arr <| local
|
local.arr <| local
|
||||||
local.arr[0] <| local
|
local.arr[0] <| local
|
||||||
local.arr[2] !<| local.arr[1]
|
local.arr[2] !<| local.arr[1]
|
||||||
|
|
||||||
plocal2[] ?<| local
|
plocal2[] ?<| local
|
||||||
|
|
||||||
param1 ?<| param2
|
param1 ?<| param2
|
||||||
|
|
||||||
local.arr[0] !<| param1
|
local.arr[0] !<| param1
|
||||||
local.arr !<| param1
|
local.arr !<| param1
|
||||||
local.le[] ?<| param1
|
local.le[] ?<| param1
|
||||||
|
|
||||||
param1 !<| local.arr[0]
|
param1 !<| local.arr[0]
|
||||||
param1 !<| local.arr
|
param1 !<| local.arr
|
||||||
param1 ?<| local.le[]
|
param1 ?<| local.le[]
|
||||||
|
|
||||||
result !<| local
|
result !<| local
|
||||||
result <| result
|
result <| result
|
||||||
|
|
||||||
var
|
var
|
||||||
a, b: int
|
a, b: int
|
||||||
x: TC
|
x: TC
|
||||||
|
|
||||||
a <| a
|
a <| a
|
||||||
a !<| b
|
a !<| b
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import mambsym2 # import TExport
|
import mambsym2 # import TExport
|
||||||
|
|
||||||
type
|
type
|
||||||
TExport* = enum x, y, z
|
TExport* = enum x, y, z
|
||||||
TOtherEnum* = enum mDec, mInc, mAssign
|
TOtherEnum* = enum mDec, mInc, mAssign
|
||||||
|
|
||||||
proc ha() =
|
proc ha() =
|
||||||
var
|
var
|
||||||
x: TExport # no error
|
x: TExport # no error
|
||||||
discard
|
discard
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
type
|
type
|
||||||
TExport* = enum a, b, c
|
TExport* = enum a, b, c
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import mambsys2 # import TExport
|
import mambsys2 # import TExport
|
||||||
|
|
||||||
type
|
type
|
||||||
TExport* = enum x, y, z
|
TExport* = enum x, y, z
|
||||||
|
|
||||||
proc foo*(x: int) =
|
proc foo*(x: int) =
|
||||||
discard
|
discard
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
type
|
type
|
||||||
TExport* = enum x, y, z # exactly the same type!
|
TExport* = enum x, y, z # exactly the same type!
|
||||||
|
|
||||||
proc foo*(x: int) = discard
|
proc foo*(x: int) = discard
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ discard """
|
||||||
line: 11
|
line: 11
|
||||||
errormsg: "ambiguous identifier"
|
errormsg: "ambiguous identifier"
|
||||||
"""
|
"""
|
||||||
# Test ambiguous symbols
|
# Test ambiguous symbols
|
||||||
|
|
||||||
import mambsym1, mambsym2
|
import mambsym1, mambsym2
|
||||||
|
|
||||||
var
|
var
|
||||||
v: TExport #ERROR_MSG ambiguous identifier
|
v: TExport #ERROR_MSG ambiguous identifier
|
||||||
|
|
||||||
v = y
|
v = y
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ type
|
||||||
TMyType = object
|
TMyType = object
|
||||||
len: int
|
len: int
|
||||||
data: string
|
data: string
|
||||||
|
|
||||||
proc len(x: TMyType): int {.inline.} = return x.len
|
proc len(x: TMyType): int {.inline.} = return x.len
|
||||||
|
|
||||||
proc x(s: TMyType, len: int) =
|
proc x(s: TMyType, len: int) =
|
||||||
writeLine(stdout, len(s))
|
writeLine(stdout, len(s))
|
||||||
|
|
||||||
var
|
var
|
||||||
m: TMyType
|
m: TMyType
|
||||||
m.len = 7
|
m.len = 7
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ discard """
|
||||||
line: 11
|
line: 11
|
||||||
errormsg: "ambiguous identifier"
|
errormsg: "ambiguous identifier"
|
||||||
"""
|
"""
|
||||||
# Test ambiguous symbols
|
# Test ambiguous symbols
|
||||||
|
|
||||||
import mambsym1, times
|
import mambsym1, times
|
||||||
|
|
||||||
var
|
var
|
||||||
v = mDec #ERROR_MSG ambiguous identifier
|
v = mDec #ERROR_MSG ambiguous identifier
|
||||||
|
|
||||||
writeLine(stdout, ord(v))
|
writeLine(stdout, ord(v))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,33 +2,33 @@ discard """
|
||||||
file: "tarray.nim"
|
file: "tarray.nim"
|
||||||
output: "100124"
|
output: "100124"
|
||||||
"""
|
"""
|
||||||
# simple check for one dimensional arrays
|
# simple check for one dimensional arrays
|
||||||
|
|
||||||
type
|
type
|
||||||
TMyArray = array[0..2, int]
|
TMyArray = array[0..2, int]
|
||||||
TMyRecord = tuple[x, y: int]
|
TMyRecord = tuple[x, y: int]
|
||||||
|
|
||||||
proc sum(a: TMyarray): int =
|
proc sum(a: TMyarray): int =
|
||||||
result = 0
|
result = 0
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < len(a):
|
while i < len(a):
|
||||||
inc(result, a[i])
|
inc(result, a[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
proc sum(a: openarray[int]): int =
|
proc sum(a: openarray[int]): int =
|
||||||
result = 0
|
result = 0
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < len(a):
|
while i < len(a):
|
||||||
inc(result, a[i])
|
inc(result, a[i])
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
||||||
proc getPos(r: TMyRecord): int =
|
proc getPos(r: TMyRecord): int =
|
||||||
result = r.x + r.y
|
result = r.x + r.y
|
||||||
|
|
||||||
write(stdout, sum([1, 2, 3, 4]))
|
write(stdout, sum([1, 2, 3, 4]))
|
||||||
write(stdout, sum([]))
|
write(stdout, sum([]))
|
||||||
write(stdout, getPos( (x: 5, y: 7) ))
|
write(stdout, getPos( (x: 5, y: 7) ))
|
||||||
#OUT 10012
|
#OUT 10012
|
||||||
|
|
||||||
# bug #1669
|
# bug #1669
|
||||||
let filesToCreate = ["tempdir/fl1.a", "tempdir/fl2.b",
|
let filesToCreate = ["tempdir/fl1.a", "tempdir/fl2.b",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ type
|
||||||
|
|
||||||
TObj = object
|
TObj = object
|
||||||
arr: TMyarray
|
arr: TMyarray
|
||||||
|
|
||||||
proc mul(a, b: TMyarray): TMyArray =
|
proc mul(a, b: TMyarray): TMyArray =
|
||||||
result = a
|
result = a
|
||||||
for i in 0..len(a)-1:
|
for i in 0..len(a)-1:
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ discard """
|
||||||
file: "tarray3.nim"
|
file: "tarray3.nim"
|
||||||
output: "3"
|
output: "3"
|
||||||
"""
|
"""
|
||||||
# simple check for two dimensional arrays
|
# simple check for two dimensional arrays
|
||||||
|
|
||||||
const
|
const
|
||||||
myData = [[1,2,3], [4, 5, 6]]
|
myData = [[1,2,3], [4, 5, 6]]
|
||||||
|
|
||||||
echo myData[0][2] #OUT 3
|
echo myData[0][2] #OUT 3
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ discard """
|
||||||
type
|
type
|
||||||
TEnum = enum
|
TEnum = enum
|
||||||
eA, eB, eC, eD, eE, eF
|
eA, eB, eC, eD, eE, eF
|
||||||
|
|
||||||
const
|
const
|
||||||
myMapping: array[TEnum, array[0..1, int]] = [
|
myMapping: array[TEnum, array[0..1, int]] = [
|
||||||
eA: [1, 2],
|
eA: [1, 2],
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ discard """
|
||||||
type
|
type
|
||||||
TEnum = enum
|
TEnum = enum
|
||||||
eA, eB, eC, eD, eE, eF
|
eA, eB, eC, eD, eE, eF
|
||||||
|
|
||||||
const
|
const
|
||||||
myMapping: array[TEnum, array[0..1, int]] = [
|
myMapping: array[TEnum, array[0..1, int]] = [
|
||||||
eA: [1, 2],
|
eA: [1, 2],
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ proc `+`*[R, T] (v1, v2: array[R, T]): array[R, T] =
|
||||||
for i in low(v1)..high(v1):
|
for i in low(v1)..high(v1):
|
||||||
result[i] = v1[i] + v2[i]
|
result[i] = v1[i] + v2[i]
|
||||||
|
|
||||||
var
|
var
|
||||||
v1: array[0..2, float] = [3.0, 1.2, 3.0]
|
v1: array[0..2, float] = [3.0, 1.2, 3.0]
|
||||||
v2: array[0..1, float] = [2.0, 1.0]
|
v2: array[0..1, float] = [2.0, 1.0]
|
||||||
v3 = v1 + v2
|
v3 = v1 + v2
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
# test another strange bug ... (I hate this compiler; it is much too buggy!)
|
# test another strange bug ... (I hate this compiler; it is much too buggy!)
|
||||||
|
|
||||||
proc putEnv(key, val: string) =
|
proc putEnv(key, val: string) =
|
||||||
# XXX: we have to leak memory here, as we cannot
|
# XXX: we have to leak memory here, as we cannot
|
||||||
# free it before the program ends (says Borland's
|
# free it before the program ends (says Borland's
|
||||||
# documentation)
|
# documentation)
|
||||||
var
|
var
|
||||||
env: ptr array[0..500000, char]
|
env: ptr array[0..500000, char]
|
||||||
env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2))
|
env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2))
|
||||||
for i in 0..len(key)-1: env[i] = key[i]
|
for i in 0..len(key)-1: env[i] = key[i]
|
||||||
env[len(key)] = '='
|
env[len(key)] = '='
|
||||||
for i in 0..len(val)-1:
|
for i in 0..len(val)-1:
|
||||||
env[len(key)+1+i] = val[i]
|
env[len(key)+1+i] = val[i]
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ discard """
|
||||||
output: "x == 45ugh"
|
output: "x == 45ugh"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
template myAssert(cond: expr) =
|
template myAssert(cond: expr) =
|
||||||
when 3 <= 3:
|
when 3 <= 3:
|
||||||
let c = cond.astToStr
|
let c = cond.astToStr
|
||||||
if not cond:
|
if not cond:
|
||||||
echo c, "ugh"
|
echo c, "ugh"
|
||||||
|
|
||||||
var x = 454
|
var x = 454
|
||||||
myAssert(x == 45)
|
myAssert(x == 45)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,31 @@
|
||||||
# Test the assignment operator for complex types which need RTTI
|
# Test the assignment operator for complex types which need RTTI
|
||||||
|
|
||||||
type
|
type
|
||||||
TRec = object
|
TRec = object
|
||||||
x, y: int
|
x, y: int
|
||||||
s: string
|
s: string
|
||||||
seq: seq[string]
|
seq: seq[string]
|
||||||
arr: seq[seq[array[0..3, string]]]
|
arr: seq[seq[array[0..3, string]]]
|
||||||
TRecSeq = seq[TRec]
|
TRecSeq = seq[TRec]
|
||||||
|
|
||||||
proc test() =
|
proc test() =
|
||||||
var
|
var
|
||||||
a, b: TRec
|
a, b: TRec
|
||||||
a.x = 1
|
a.x = 1
|
||||||
a.y = 2
|
a.y = 2
|
||||||
a.s = "Hallo!"
|
a.s = "Hallo!"
|
||||||
a.seq = @["abc", "def", "ghi", "jkl"]
|
a.seq = @["abc", "def", "ghi", "jkl"]
|
||||||
a.arr = @[]
|
a.arr = @[]
|
||||||
setLen(a.arr, 4)
|
setLen(a.arr, 4)
|
||||||
a.arr[0] = @[]
|
a.arr[0] = @[]
|
||||||
a.arr[1] = @[]
|
a.arr[1] = @[]
|
||||||
|
|
||||||
b = a # perform a deep copy here!
|
b = a # perform a deep copy here!
|
||||||
b.seq = @["xyz", "huch", "was", "soll"]
|
b.seq = @["xyz", "huch", "was", "soll"]
|
||||||
writeLine(stdout, len(a.seq))
|
writeLine(stdout, len(a.seq))
|
||||||
writeLine(stdout, a.seq[3])
|
writeLine(stdout, a.seq[3])
|
||||||
writeLine(stdout, len(b.seq))
|
writeLine(stdout, len(b.seq))
|
||||||
writeLine(stdout, b.seq[3])
|
writeLine(stdout, b.seq[3])
|
||||||
writeLine(stdout, b.y)
|
writeLine(stdout, b.y)
|
||||||
|
|
||||||
test()
|
test()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ type
|
||||||
TAny* = object {.pure.}
|
TAny* = object {.pure.}
|
||||||
value*: pointer
|
value*: pointer
|
||||||
rawType: pointer
|
rawType: pointer
|
||||||
|
|
||||||
proc newAny(value, rawType: pointer): TAny =
|
proc newAny(value, rawType: pointer): TAny =
|
||||||
result.value = value
|
result.value = value
|
||||||
result.rawType = rawType
|
result.rawType = rawType
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
|
|
||||||
var t, s: tuple[x: string, c: int]
|
var t, s: tuple[x: string, c: int]
|
||||||
|
|
||||||
proc ugh: seq[tuple[x: string, c: int]] =
|
proc ugh: seq[tuple[x: string, c: int]] =
|
||||||
result = @[("abc", 232)]
|
result = @[("abc", 232)]
|
||||||
|
|
||||||
t = ugh()[0]
|
t = ugh()[0]
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ type
|
||||||
a, b: int
|
a, b: int
|
||||||
PSomeObj = ref object
|
PSomeObj = ref object
|
||||||
a, b: int
|
a, b: int
|
||||||
|
|
||||||
var a = TSomeObj(a: 8)
|
var a = TSomeObj(a: 8)
|
||||||
var b = PSomeObj(a: 5)
|
var b = PSomeObj(a: 5)
|
||||||
echo a.a, " ", b.a, " ", a.b, " ", b.b
|
echo a.a, " ", b.a, " ", a.b, " ", b.b
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ proc createServer(port: TPort) {.async.} =
|
||||||
if bindAddr(server.SocketHandle, cast[ptr SockAddr](addr(name)),
|
if bindAddr(server.SocketHandle, cast[ptr SockAddr](addr(name)),
|
||||||
sizeof(name).Socklen) < 0'i32:
|
sizeof(name).Socklen) < 0'i32:
|
||||||
raiseOSError(osLastError())
|
raiseOSError(osLastError())
|
||||||
|
|
||||||
discard server.SocketHandle.listen()
|
discard server.SocketHandle.listen()
|
||||||
while true:
|
while true:
|
||||||
asyncCheck readMessages(await accept(server))
|
asyncCheck readMessages(await accept(server))
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ else:
|
||||||
s = newAsyncSocket()
|
s = newAsyncSocket()
|
||||||
|
|
||||||
await s.connect(testHost, testPort)
|
await s.connect(testHost, testPort)
|
||||||
|
|
||||||
var ps = await ls.accept()
|
var ps = await ls.accept()
|
||||||
SocketHandle(ls).close()
|
SocketHandle(ls).close()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ proc main() {.async.} =
|
||||||
let data = await file.readAll()
|
let data = await file.readAll()
|
||||||
doAssert data == "foot"
|
doAssert data == "foot"
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
# Append test
|
# Append test
|
||||||
block:
|
block:
|
||||||
var file = openAsync(fn, fmAppend)
|
var file = openAsync(fn, fmAppend)
|
||||||
|
|
@ -29,8 +29,8 @@ proc main() {.async.} =
|
||||||
file.close()
|
file.close()
|
||||||
file = openAsync(fn, fmRead)
|
file = openAsync(fn, fmRead)
|
||||||
let data = await file.readAll()
|
let data = await file.readAll()
|
||||||
|
|
||||||
doAssert data == "foot\ntest2"
|
doAssert data == "foot\ntest2"
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
waitFor main()
|
waitFor main()
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ disp = newDispatcher()
|
||||||
var msgCount = 0
|
var msgCount = 0
|
||||||
|
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
var ctx = newContext(verifyMode = CVerifyNone,
|
var ctx = newContext(verifyMode = CVerifyNone,
|
||||||
certFile = "tests/testdata/mycert.pem", keyFile = "tests/testdata/mycert.pem")
|
certFile = "tests/testdata/mycert.pem", keyFile = "tests/testdata/mycert.pem")
|
||||||
|
|
||||||
var ctx1 = newContext(verifyMode = CVerifyNone)
|
var ctx1 = newContext(verifyMode = CVerifyNone)
|
||||||
|
|
||||||
const
|
const
|
||||||
swarmSize = 50
|
swarmSize = 50
|
||||||
messagesToSend = 100
|
messagesToSend = 100
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ proc serverRead(s: PAsyncSocket) =
|
||||||
if s.recvFromAsync(data, 9, address, port):
|
if s.recvFromAsync(data, 9, address, port):
|
||||||
assert address == "127.0.0.1"
|
assert address == "127.0.0.1"
|
||||||
msgCount.inc()
|
msgCount.inc()
|
||||||
|
|
||||||
discard """
|
discard """
|
||||||
|
|
||||||
var line = ""
|
var line = ""
|
||||||
assert s.recvLine(line)
|
assert s.recvLine(line)
|
||||||
|
|
||||||
if line == "":
|
if line == "":
|
||||||
assert(false)
|
assert(false)
|
||||||
else:
|
else:
|
||||||
|
|
@ -66,11 +66,11 @@ while true:
|
||||||
|
|
||||||
if not disp.poll():
|
if not disp.poll():
|
||||||
break
|
break
|
||||||
|
|
||||||
if (msgCount div messagesToSend) * serverCount == currentClient:
|
if (msgCount div messagesToSend) * serverCount == currentClient:
|
||||||
createClient(disp, TPort(10335), false)
|
createClient(disp, TPort(10335), false)
|
||||||
createClient(disp, TPort(10336), true)
|
createClient(disp, TPort(10336), true)
|
||||||
|
|
||||||
if msgCount == messagesToSend * serverCount * swarmSize:
|
if msgCount == messagesToSend * serverCount * swarmSize:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,4 +44,4 @@ when isMainModule:
|
||||||
var b = doBench()
|
var b = doBench()
|
||||||
var output = genOutput(b)
|
var output = genOutput(b)
|
||||||
writeFile("benchmarkResults.json", pretty(output))
|
writeFile("benchmarkResults.json", pretty(output))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import os
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
proc fannkuch (n: int): int =
|
proc fannkuch (n: int): int =
|
||||||
var
|
var
|
||||||
count: seq[int]
|
count: seq[int]
|
||||||
maxFlips = 0
|
maxFlips = 0
|
||||||
m = n-1
|
m = n-1
|
||||||
|
|
@ -58,7 +58,7 @@ proc fannkuch (n: int): int =
|
||||||
for i in 0 .. r-1:
|
for i in 0 .. r-1:
|
||||||
perm1[i] = perm1[i+1]
|
perm1[i] = perm1[i+1]
|
||||||
perm1[r] = tmp
|
perm1[r] = tmp
|
||||||
|
|
||||||
dec (count[r])
|
dec (count[r])
|
||||||
if count[r] > 0:
|
if count[r] > 0:
|
||||||
break makePerm
|
break makePerm
|
||||||
|
|
@ -66,4 +66,4 @@ proc fannkuch (n: int): int =
|
||||||
return maxFlips
|
return maxFlips
|
||||||
|
|
||||||
var n = 10
|
var n = 10
|
||||||
echo ("Pfannkuchen(" & $n & ") = " & $fannkuch (n))
|
echo ("Pfannkuchen(" & $n & ") = " & $fannkuch (n))
|
||||||
|
|
|
||||||
|
|
@ -51,4 +51,4 @@ proc sort (start, stop: int) =
|
||||||
sort (0, data.len)
|
sort (0, data.len)
|
||||||
echo (data[n div 2 - 1] and 0xFFFF_FFFF'i64, ", ",
|
echo (data[n div 2 - 1] and 0xFFFF_FFFF'i64, ", ",
|
||||||
data[n div 2] and 0xFFFF_FFFF'i64, ", ",
|
data[n div 2] and 0xFFFF_FFFF'i64, ", ",
|
||||||
data[n div 2 + 1] and 0xFFFF_FFFF'i64)
|
data[n div 2 + 1] and 0xFFFF_FFFF'i64)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
# Module A
|
# Module A
|
||||||
var
|
var
|
||||||
lastId = 0
|
lastId = 0
|
||||||
|
|
||||||
template genId*: expr =
|
template genId*: expr =
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,14 @@ discard """
|
||||||
|
|
||||||
proc p1(x: int8, y: int): int = return x + y
|
proc p1(x: int8, y: int): int = return x + y
|
||||||
|
|
||||||
template tempBind(x, y: expr): expr =
|
template tempBind(x, y: expr): expr =
|
||||||
bind p1
|
bind p1
|
||||||
p1(x, y)
|
p1(x, y)
|
||||||
|
|
||||||
proc p1(x: int, y: int8): int = return x - y
|
proc p1(x: int, y: int8): int = return x - y
|
||||||
|
|
||||||
# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6,
|
# This is tricky: the call to ``p1(1'i8, 2'i8)`` should not fail in line 6,
|
||||||
# because it is not ambiguous there. But it is ambiguous after line 8.
|
# because it is not ambiguous there. But it is ambiguous after line 8.
|
||||||
|
|
||||||
echo tempBind(1'i8, 2'i8) #OUT 3
|
echo tempBind(1'i8, 2'i8) #OUT 3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ discard """
|
||||||
proc p1(x: int8, y: int): int = return x + y
|
proc p1(x: int8, y: int): int = return x + y
|
||||||
proc p1(x: int, y: int8): int = return x - y
|
proc p1(x: int, y: int8): int = return x - y
|
||||||
|
|
||||||
template tempBind(x, y: expr): expr =
|
template tempBind(x, y: expr): expr =
|
||||||
(bind p1(x, y)) #ERROR_MSG ambiguous call
|
(bind p1(x, y)) #ERROR_MSG ambiguous call
|
||||||
|
|
||||||
echo tempBind(1'i8, 2'i8)
|
echo tempBind(1'i8, 2'i8)
|
||||||
|
|
|
||||||
|
|
@ -31,14 +31,14 @@ proc newProperty*[T](value: T): TProperty[T] =
|
||||||
|
|
||||||
proc setter(property: var TProperty[T], v: T) =
|
proc setter(property: var TProperty[T], v: T) =
|
||||||
property.value = v
|
property.value = v
|
||||||
|
|
||||||
# fire event here
|
# fire event here
|
||||||
var args: TValueEventArgs[T]
|
var args: TValueEventArgs[T]
|
||||||
args.Property = property
|
args.Property = property
|
||||||
property.EEmitter.emit(property.ValueChanged, args)
|
property.EEmitter.emit(property.ValueChanged, args)
|
||||||
|
|
||||||
prop.setProc = setter
|
prop.setProc = setter
|
||||||
|
|
||||||
return prop
|
return prop
|
||||||
|
|
||||||
proc `prop`[T] (p: TProperty[T]): T =
|
proc `prop`[T] (p: TProperty[T]): T =
|
||||||
|
|
@ -56,7 +56,7 @@ proc `$`[T] (p: TProperty[T]): string =
|
||||||
|
|
||||||
proc propertyBind*[T](p1: var TProperty[T], p2: var TProperty[T]) =
|
proc propertyBind*[T](p1: var TProperty[T], p2: var TProperty[T]) =
|
||||||
p1.Binders.add(p2)
|
p1.Binders.add(p2)
|
||||||
|
|
||||||
# make handler -> handler[T] so trigger even more generics bugs ...
|
# make handler -> handler[T] so trigger even more generics bugs ...
|
||||||
proc handler(e: TEventArgs) =
|
proc handler(e: TEventArgs) =
|
||||||
type TEA = TValueEventArgs[T]
|
type TEA = TValueEventArgs[T]
|
||||||
|
|
@ -77,9 +77,9 @@ proc `->`[T](p1: var TProperty[T], p2: var TProperty[T]) =
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
# Initial value testing
|
# Initial value testing
|
||||||
var myProp = newProperty(5)
|
var myProp = newProperty(5)
|
||||||
|
|
||||||
echo(myProp)
|
echo(myProp)
|
||||||
|
|
||||||
myProp ~= 7 # Temp operator until overloading of '=' is implemented.
|
myProp ~= 7 # Temp operator until overloading of '=' is implemented.
|
||||||
echo(myProp)
|
echo(myProp)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ discard """
|
||||||
|
|
||||||
proc `++`*[T: int | float](a, b: T): T =
|
proc `++`*[T: int | float](a, b: T): T =
|
||||||
result = a + b
|
result = a + b
|
||||||
|
|
||||||
type
|
type
|
||||||
DI = distinct int
|
DI = distinct int
|
||||||
DF = distinct float
|
DF = distinct float
|
||||||
DS = distinct string
|
DS = distinct string
|
||||||
|
|
||||||
proc `++`(x, y: DI): DI {.borrow.}
|
proc `++`(x, y: DI): DI {.borrow.}
|
||||||
proc `++`(x, y: DF): DF {.borrow.}
|
proc `++`(x, y: DF): DF {.borrow.}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ type
|
||||||
|
|
||||||
var
|
var
|
||||||
e: TE
|
e: TE
|
||||||
|
|
||||||
case e
|
case e
|
||||||
of A..D, B..C:
|
of A..D, B..C:
|
||||||
echo "redundant"
|
echo "redundant"
|
||||||
else: nil
|
else: nil
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ discard """
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proc checkDuplicates(myval: int32): bool =
|
proc checkDuplicates(myval: int32): bool =
|
||||||
case myval
|
case myval
|
||||||
of 0x7B:
|
of 0x7B:
|
||||||
echo "this should not compile"
|
echo "this should not compile"
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ of "will", "it", "finally", "be", "generated": discard
|
||||||
var z = case i
|
var z = case i
|
||||||
of 1..5, 8, 9: "aa"
|
of 1..5, 8, 9: "aa"
|
||||||
of 6, 7: "bb"
|
of 6, 7: "bb"
|
||||||
elif x == "Ha":
|
elif x == "Ha":
|
||||||
"cc"
|
"cc"
|
||||||
elif x == "yyy":
|
elif x == "yyy":
|
||||||
write(stdout, x)
|
write(stdout, x)
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import strutils
|
||||||
var x = 343
|
var x = 343
|
||||||
|
|
||||||
case stdin.readline.parseInt
|
case stdin.readline.parseInt
|
||||||
of 0:
|
of 0:
|
||||||
echo "most common case"
|
echo "most common case"
|
||||||
of 1:
|
of 1:
|
||||||
{.linearScanEnd.}
|
{.linearScanEnd.}
|
||||||
echo "second most common case"
|
echo "second most common case"
|
||||||
of 2: echo "unlikely: use branch table"
|
of 2: echo "unlikely: use branch table"
|
||||||
else:
|
else:
|
||||||
echo "unlikely too: use branch table"
|
echo "unlikely too: use branch table"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ case x
|
||||||
of 23: echo "23"
|
of 23: echo "23"
|
||||||
of 343: echo "343"
|
of 343: echo "343"
|
||||||
of 21: echo "21"
|
of 21: echo "21"
|
||||||
else:
|
else:
|
||||||
{.linearScanEnd.}
|
{.linearScanEnd.}
|
||||||
echo "default"
|
echo "default"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,21 +18,21 @@ type
|
||||||
FOwnerDocument: PDocument # Read-Only
|
FOwnerDocument: PDocument # Read-Only
|
||||||
FParentNode: PNode # Read-Only
|
FParentNode: PNode # Read-Only
|
||||||
prefix*: string # Setting this should change some values... TODO!
|
prefix*: string # Setting this should change some values... TODO!
|
||||||
|
|
||||||
PElement* = ref Element
|
PElement* = ref Element
|
||||||
Element = object of Node
|
Element = object of Node
|
||||||
FTagName: string # Read-only
|
FTagName: string # Read-only
|
||||||
|
|
||||||
PCharacterData = ref CharacterData
|
PCharacterData = ref CharacterData
|
||||||
CharacterData = object of Node
|
CharacterData = object of Node
|
||||||
data*: string
|
data*: string
|
||||||
|
|
||||||
PDocument* = ref Document
|
PDocument* = ref Document
|
||||||
Document = object of Node
|
Document = object of Node
|
||||||
FImplementation: PDOMImplementation # Read-only
|
FImplementation: PDOMImplementation # Read-only
|
||||||
FDocumentElement: PElement # Read-only
|
FDocumentElement: PElement # Read-only
|
||||||
|
|
||||||
PAttr* = ref Attr
|
PAttr* = ref Attr
|
||||||
Attr = object of Node
|
Attr = object of Node
|
||||||
FName: string # Read-only
|
FName: string # Read-only
|
||||||
FSpecified: bool # Read-only
|
FSpecified: bool # Read-only
|
||||||
|
|
@ -44,22 +44,22 @@ type
|
||||||
|
|
||||||
PText* = ref Text
|
PText* = ref Text
|
||||||
Text = object of CharacterData
|
Text = object of CharacterData
|
||||||
|
|
||||||
PComment* = ref Comment
|
PComment* = ref Comment
|
||||||
Comment = object of CharacterData
|
Comment = object of CharacterData
|
||||||
|
|
||||||
PCDataSection* = ref CDataSection
|
PCDataSection* = ref CDataSection
|
||||||
CDataSection = object of Text
|
CDataSection = object of Text
|
||||||
|
|
||||||
PProcessingInstruction* = ref ProcessingInstruction
|
PProcessingInstruction* = ref ProcessingInstruction
|
||||||
ProcessingInstruction = object of Node
|
ProcessingInstruction = object of Node
|
||||||
data*: string
|
data*: string
|
||||||
FTarget: string # Read-only
|
FTarget: string # Read-only
|
||||||
|
|
||||||
proc `namespaceURI=`*(n: var PNode, value: string) =
|
proc `namespaceURI=`*(n: var PNode, value: string) =
|
||||||
n.FNamespaceURI = value
|
n.FNamespaceURI = value
|
||||||
|
|
||||||
proc main =
|
proc main =
|
||||||
var n: PNode
|
var n: PNode
|
||||||
new(n)
|
new(n)
|
||||||
n.namespaceURI = "test"
|
n.namespaceURI = "test"
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ proc p(a: PObj) =
|
||||||
proc q(a: var PObj) =
|
proc q(a: var PObj) =
|
||||||
a.p()
|
a.p()
|
||||||
|
|
||||||
var
|
var
|
||||||
a: PObj
|
a: PObj
|
||||||
new(a)
|
new(a)
|
||||||
q(a)
|
q(a)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ type
|
||||||
status*: TStatusEnum
|
status*: TStatusEnum
|
||||||
desc*: string
|
desc*: string
|
||||||
hash*: string
|
hash*: string
|
||||||
|
|
||||||
proc initStatus*(): TStatus =
|
proc initStatus*(): TStatus =
|
||||||
result.status = sUnknown
|
result.status = sUnknown
|
||||||
result.desc = ""
|
result.desc = ""
|
||||||
|
|
@ -49,7 +49,7 @@ proc `$`*(status: TStatusEnum): string =
|
||||||
return "csource generation succeeded"
|
return "csource generation succeeded"
|
||||||
of sUnknown:
|
of sUnknown:
|
||||||
return "unknown"
|
return "unknown"
|
||||||
|
|
||||||
proc makeCommitPath*(platform, hash: string): string =
|
proc makeCommitPath*(platform, hash: string): string =
|
||||||
return platform / "nim_" & hash.substr(0, 11) # 11 Chars.
|
return platform / "nim_" & hash.substr(0, 11) # 11 Chars.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ type
|
||||||
|
|
||||||
proc getInterf(): ITest =
|
proc getInterf(): ITest =
|
||||||
var shared: int
|
var shared: int
|
||||||
|
|
||||||
return (setter: proc (x: int) = shared = x,
|
return (setter: proc (x: int) = shared = x,
|
||||||
getter: proc (): int = return shared)
|
getter: proc (): int = return shared)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,13 +33,13 @@ when true:
|
||||||
for xxxx in 0..9:
|
for xxxx in 0..9:
|
||||||
var i = 0
|
var i = 0
|
||||||
proc bx =
|
proc bx =
|
||||||
if i > 10:
|
if i > 10:
|
||||||
echo xxxx
|
echo xxxx
|
||||||
return
|
return
|
||||||
i += 1
|
i += 1
|
||||||
#for j in 0 .. 0: echo i
|
#for j in 0 .. 0: echo i
|
||||||
bx()
|
bx()
|
||||||
|
|
||||||
bx()
|
bx()
|
||||||
echo i
|
echo i
|
||||||
|
|
||||||
|
|
@ -50,11 +50,11 @@ when true:
|
||||||
var x = start-1
|
var x = start-1
|
||||||
#let dummy = proc =
|
#let dummy = proc =
|
||||||
# discard start
|
# discard start
|
||||||
|
|
||||||
result = proc (): int =
|
result = proc (): int =
|
||||||
#var x = 9
|
#var x = 9
|
||||||
for i in 0 .. 0: x = x + 1
|
for i in 0 .. 0: x = x + 1
|
||||||
|
|
||||||
return x
|
return x
|
||||||
|
|
||||||
var a = accumulator(3)
|
var a = accumulator(3)
|
||||||
|
|
@ -69,7 +69,7 @@ when true:
|
||||||
for i in 0..3: echo "py"
|
for i in 0..3: echo "py"
|
||||||
|
|
||||||
py()
|
py()
|
||||||
|
|
||||||
outer()
|
outer()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ when true:
|
||||||
if n < 0: result = errorValue
|
if n < 0: result = errorValue
|
||||||
elif n <= 1: result = 1
|
elif n <= 1: result = 1
|
||||||
else: result = n * fac(n-1)
|
else: result = n * fac(n-1)
|
||||||
|
|
||||||
proc px() {.closure.} =
|
proc px() {.closure.} =
|
||||||
echo "px"
|
echo "px"
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ when true:
|
||||||
"xyz": py
|
"xyz": py
|
||||||
}
|
}
|
||||||
mapping[0][1]()
|
mapping[0][1]()
|
||||||
|
|
||||||
echo fac(3)
|
echo fac(3)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ proc main =
|
||||||
for i in 0 .. n-1:
|
for i in 0 .. n-1:
|
||||||
let val = s[i]()
|
let val = s[i]()
|
||||||
if val != $(i*i): echo "bug ", val
|
if val != $(i*i): echo "bug ", val
|
||||||
|
|
||||||
if getOccupiedMem() > 3000_000: quit("still a leak!")
|
if getOccupiedMem() > 3000_000: quit("still a leak!")
|
||||||
echo "success"
|
echo "success"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ proc hasKey*[A, B](t: TOrderedTable[A, B], key: A): bool =
|
||||||
## returns true iff `key` is in the table `t`.
|
## returns true iff `key` is in the table `t`.
|
||||||
result = rawGet(t, key) >= 0
|
result = rawGet(t, key) >= 0
|
||||||
|
|
||||||
proc rawInsert[A, B](t: var TOrderedTable[A, B],
|
proc rawInsert[A, B](t: var TOrderedTable[A, B],
|
||||||
data: var TOrderedKeyValuePairSeq[A, B],
|
data: var TOrderedKeyValuePairSeq[A, B],
|
||||||
key: A, val: B) =
|
key: A, val: B) =
|
||||||
rawInsertImpl()
|
rawInsertImpl()
|
||||||
|
|
@ -128,7 +128,7 @@ proc enlarge[A, B](t: var TOrderedTable[A, B]) =
|
||||||
t.last = -1
|
t.last = -1
|
||||||
while h >= 0:
|
while h >= 0:
|
||||||
var nxt = t.data[h].next
|
var nxt = t.data[h].next
|
||||||
if t.data[h].slot == seFilled:
|
if t.data[h].slot == seFilled:
|
||||||
rawInsert(t, n, t.data[h].key, t.data[h].val)
|
rawInsert(t, n, t.data[h].key, t.data[h].val)
|
||||||
h = nxt
|
h = nxt
|
||||||
swap(t.data, n)
|
swap(t.data, n)
|
||||||
|
|
@ -150,16 +150,16 @@ proc initOrderedTable*[A, B](initialSize=64): TOrderedTable[A, B] =
|
||||||
result.last = -1
|
result.last = -1
|
||||||
newSeq(result.data, initialSize)
|
newSeq(result.data, initialSize)
|
||||||
|
|
||||||
proc toOrderedTable*[A, B](pairs: openarray[tuple[key: A,
|
proc toOrderedTable*[A, B](pairs: openarray[tuple[key: A,
|
||||||
val: B]]): TOrderedTable[A, B] =
|
val: B]]): TOrderedTable[A, B] =
|
||||||
## creates a new ordered hash table that contains the given `pairs`.
|
## creates a new ordered hash table that contains the given `pairs`.
|
||||||
result = initOrderedTable[A, B](nextPowerOfTwo(pairs.len+10))
|
result = initOrderedTable[A, B](nextPowerOfTwo(pairs.len+10))
|
||||||
for key, val in items(pairs): result[key] = val
|
for key, val in items(pairs): result[key] = val
|
||||||
|
|
||||||
proc sort*[A, B](t: var TOrderedTable[A,B],
|
proc sort*[A, B](t: var TOrderedTable[A,B],
|
||||||
cmp: proc (x, y: tuple[key: A, val: B]): int {.closure.}) =
|
cmp: proc (x, y: tuple[key: A, val: B]): int {.closure.}) =
|
||||||
## sorts the ordered table so that the entry with the highest counter comes
|
## sorts the ordered table so that the entry with the highest counter comes
|
||||||
## first. This is destructive (with the advantage of being efficient)!
|
## first. This is destructive (with the advantage of being efficient)!
|
||||||
## You must not modify `t` afterwards!
|
## You must not modify `t` afterwards!
|
||||||
## You can use the iterators `pairs`, `keys`, and `values` to iterate over
|
## You can use the iterators `pairs`, `keys`, and `values` to iterate over
|
||||||
## `t` in the sorted order.
|
## `t` in the sorted order.
|
||||||
|
|
@ -186,7 +186,7 @@ proc sort*[A, B](t: var TOrderedTable[A,B],
|
||||||
let item1 = (x.key, x.val)
|
let item1 = (x.key, x.val)
|
||||||
let item2 = (y.key, y.val)
|
let item2 = (y.key, y.val)
|
||||||
return cmp(item1, item2)
|
return cmp(item1, item2)
|
||||||
|
|
||||||
while rawCmp(t.data[j-h], t.data[j]) <= 0:
|
while rawCmp(t.data[j-h], t.data[j]) <= 0:
|
||||||
swap(t.data[j], t.data[j-h])
|
swap(t.data[j], t.data[j-h])
|
||||||
j = j-h
|
j = j-h
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ type
|
||||||
|
|
||||||
proc getInterf(): ITest =
|
proc getInterf(): ITest =
|
||||||
var shared1, shared2: int
|
var shared1, shared2: int
|
||||||
|
|
||||||
return (setter: proc (x: int) =
|
return (setter: proc (x: int) =
|
||||||
shared1 = x
|
shared1 = x
|
||||||
shared2 = x + 10,
|
shared2 = x + 10,
|
||||||
getter1: proc (): int = result = shared1,
|
getter1: proc (): int = result = shared1,
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ discard """
|
||||||
errormsg: "illegal capture 'A'"
|
errormsg: "illegal capture 'A'"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc outer() =
|
proc outer() =
|
||||||
var A: int
|
var A: int
|
||||||
|
|
||||||
proc ugh[T](x: T) {.cdecl.} =
|
proc ugh[T](x: T) {.cdecl.} =
|
||||||
echo "ugha", A, x
|
echo "ugha", A, x
|
||||||
|
|
||||||
ugh[int](12)
|
ugh[int](12)
|
||||||
|
|
||||||
outer()
|
outer()
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ proc cbOuter(response: string) {.closure, discardable.} =
|
||||||
var iterVar = fooIter
|
var iterVar = fooIter
|
||||||
iterVar().data
|
iterVar().data
|
||||||
yield Future[int](data: foo())
|
yield Future[int](data: foo())
|
||||||
|
|
||||||
var iterVar2 = cbIter
|
var iterVar2 = cbIter
|
||||||
proc cb2() {.closure.} =
|
proc cb2() {.closure.} =
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ proc cbOuter() =
|
||||||
proc fooIter() =
|
proc fooIter() =
|
||||||
echo response
|
echo response
|
||||||
fooIter()
|
fooIter()
|
||||||
|
|
||||||
cbIter()
|
cbIter()
|
||||||
|
|
||||||
cbOuter()
|
cbOuter()
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ discard """
|
||||||
output: "11"
|
output: "11"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc p(x, y: int): int =
|
proc p(x, y: int): int =
|
||||||
result = x + y
|
result = x + y
|
||||||
|
|
||||||
echo p((proc (): int =
|
echo p((proc (): int =
|
||||||
var x = 7
|
var x = 7
|
||||||
return x)(),
|
return x)(),
|
||||||
(proc (): int = return 4)())
|
(proc (): int = return 4)())
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import unittest
|
||||||
|
|
||||||
test "loop variables are captured by copy":
|
test "loop variables are captured by copy":
|
||||||
var funcs: seq[proc (): int {.closure.}] = @[]
|
var funcs: seq[proc (): int {.closure.}] = @[]
|
||||||
|
|
||||||
for i in 0..10:
|
for i in 0..10:
|
||||||
let ii = i
|
let ii = i
|
||||||
funcs.add do -> int: return ii * ii
|
funcs.add do -> int: return ii * ii
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import strutils
|
||||||
|
|
||||||
const
|
const
|
||||||
myWords = "Angelika Anne Anna Anka Anja".split()
|
myWords = "Angelika Anne Anna Anka Anja".split()
|
||||||
|
|
||||||
for x in items(myWords):
|
for x in items(myWords):
|
||||||
write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja
|
write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ discard """
|
||||||
|
|
||||||
const
|
const
|
||||||
myWords = @["Angelika", "Anne", "Anna", "Anka", "Anja"]
|
myWords = @["Angelika", "Anne", "Anna", "Anka", "Anja"]
|
||||||
|
|
||||||
for i in 0 .. high(myWords):
|
for i in 0 .. high(myWords):
|
||||||
write(stdout, myWords[i]) #OUT AngelikaAnneAnnaAnkaAnja
|
write(stdout, myWords[i]) #OUT AngelikaAnneAnnaAnkaAnja
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ type
|
||||||
TElem = object
|
TElem = object
|
||||||
foo: int
|
foo: int
|
||||||
bar: string
|
bar: string
|
||||||
|
|
||||||
let
|
let
|
||||||
elem1 = TElem(foo: 1, bar: "bar")
|
elem1 = TElem(foo: 1, bar: "bar")
|
||||||
elem2 = TElem(foo: 2, bar: "baz")
|
elem2 = TElem(foo: 2, bar: "baz")
|
||||||
|
|
||||||
var tbl2 = initTable[string, TElem]()
|
var tbl2 = initTable[string, TElem]()
|
||||||
tbl2.add("bar", elem1)
|
tbl2.add("bar", elem1)
|
||||||
tbl2.add("baz", elem2)
|
tbl2.add("baz", elem2)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
template ignoreExpr(e: expr): stmt {.immediate.} =
|
template ignoreExpr(e: expr): stmt {.immediate.} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
# test first class '..' syntactical citizen:
|
# test first class '..' syntactical citizen:
|
||||||
ignoreExpr x <> 2..4
|
ignoreExpr x <> 2..4
|
||||||
# test table constructor:
|
# test table constructor:
|
||||||
ignoreExpr({:})
|
ignoreExpr({:})
|
||||||
|
|
|
||||||
|
|
@ -3,28 +3,28 @@ discard """
|
||||||
line: 25
|
line: 25
|
||||||
errormsg: "type mismatch"
|
errormsg: "type mismatch"
|
||||||
"""
|
"""
|
||||||
# Test array, record constructors
|
# Test array, record constructors
|
||||||
|
|
||||||
type
|
type
|
||||||
TComplexRecord = tuple[
|
TComplexRecord = tuple[
|
||||||
s: string,
|
s: string,
|
||||||
x, y: int,
|
x, y: int,
|
||||||
z: float,
|
z: float,
|
||||||
chars: set[char]]
|
chars: set[char]]
|
||||||
|
|
||||||
proc testSem =
|
proc testSem =
|
||||||
var
|
var
|
||||||
things: array [0..1, TComplexRecord] = [
|
things: array [0..1, TComplexRecord] = [
|
||||||
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
||||||
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})]
|
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})]
|
||||||
write(stdout, things[0].x)
|
write(stdout, things[0].x)
|
||||||
|
|
||||||
const
|
const
|
||||||
things: array [0..1, TComplexRecord] = [
|
things: array [0..1, TComplexRecord] = [
|
||||||
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
||||||
(s: "hi", x: 69, y: 45, z: 1.0)] #ERROR
|
(s: "hi", x: 69, y: 45, z: 1.0)] #ERROR
|
||||||
otherThings = [ # the same
|
otherThings = [ # the same
|
||||||
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
||||||
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
|
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,25 +2,25 @@ discard """
|
||||||
file: "tconstr2.nim"
|
file: "tconstr2.nim"
|
||||||
output: "69"
|
output: "69"
|
||||||
"""
|
"""
|
||||||
# Test array, record constructors
|
# Test array, record constructors
|
||||||
|
|
||||||
type
|
type
|
||||||
TComplexRecord = tuple[
|
TComplexRecord = tuple[
|
||||||
s: string,
|
s: string,
|
||||||
x, y: int,
|
x, y: int,
|
||||||
z: float,
|
z: float,
|
||||||
chars: set[char]]
|
chars: set[char]]
|
||||||
|
|
||||||
const
|
const
|
||||||
things: array [0..1, TComplexRecord] = [
|
things: array [0..1, TComplexRecord] = [
|
||||||
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
||||||
(s: "hi", x: 69, y: 45, z: 1.0, chars: {})]
|
(s: "hi", x: 69, y: 45, z: 1.0, chars: {})]
|
||||||
otherThings = [ # the same
|
otherThings = [ # the same
|
||||||
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
|
||||||
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
|
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]
|
||||||
|
|
||||||
write(stdout, things[0].x)
|
write(stdout, things[0].x)
|
||||||
#OUT 69
|
#OUT 69
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ discard """
|
||||||
errormsg: "type mismatch: got (int literal(232))"
|
errormsg: "type mismatch: got (int literal(232))"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc myGenericProc[T: object|tuple|ptr|ref|distinct](x: T): string =
|
proc myGenericProc[T: object|tuple|ptr|ref|distinct](x: T): string =
|
||||||
result = $x
|
result = $x
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@ discard """
|
||||||
line: 14
|
line: 14
|
||||||
errormsg: "undeclared identifier: \'ha\'"
|
errormsg: "undeclared identifier: \'ha\'"
|
||||||
"""
|
"""
|
||||||
# check for forward label and
|
# check for forward label and
|
||||||
# for failure when label is not declared
|
# for failure when label is not declared
|
||||||
|
|
||||||
proc main =
|
proc main =
|
||||||
block endLess:
|
block endLess:
|
||||||
write(stdout, "Muaahh!\N")
|
write(stdout, "Muaahh!\N")
|
||||||
break endLess
|
break endLess
|
||||||
|
|
||||||
break ha #ERROR
|
break ha #ERROR
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ var i = 0
|
||||||
while i < 400:
|
while i < 400:
|
||||||
|
|
||||||
if i == 10: break
|
if i == 10: break
|
||||||
elif i == 3:
|
elif i == 3:
|
||||||
inc i
|
inc i
|
||||||
continue
|
continue
|
||||||
inc i
|
inc i
|
||||||
|
|
@ -16,7 +16,7 @@ var j = 0
|
||||||
while j < 300:
|
while j < 300:
|
||||||
for x in 0..34:
|
for x in 0..34:
|
||||||
if j < 300: continue
|
if j < 300: continue
|
||||||
if x == 10:
|
if x == 10:
|
||||||
echo "failure: should never happen"
|
echo "failure: should never happen"
|
||||||
break
|
break
|
||||||
f = "came here"
|
f = "came here"
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,23 @@ discard """
|
||||||
file: "tnestif.nim"
|
file: "tnestif.nim"
|
||||||
output: "i == 2"
|
output: "i == 2"
|
||||||
"""
|
"""
|
||||||
# test nested ifs
|
# test nested ifs
|
||||||
|
|
||||||
var
|
var
|
||||||
x, y: int
|
x, y: int
|
||||||
x = 2
|
x = 2
|
||||||
if x == 0:
|
if x == 0:
|
||||||
write(stdout, "i == 0")
|
write(stdout, "i == 0")
|
||||||
if y == 0:
|
if y == 0:
|
||||||
write(stdout, x)
|
write(stdout, x)
|
||||||
else:
|
else:
|
||||||
write(stdout, y)
|
write(stdout, y)
|
||||||
elif x == 1:
|
elif x == 1:
|
||||||
write(stdout, "i == 1")
|
write(stdout, "i == 1")
|
||||||
elif x == 2:
|
elif x == 2:
|
||||||
write(stdout, "i == 2")
|
write(stdout, "i == 2")
|
||||||
else:
|
else:
|
||||||
write(stdout, "looks like Python")
|
write(stdout, "looks like Python")
|
||||||
#OUT i == 2
|
#OUT i == 2
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ discard """
|
||||||
line: 9
|
line: 9
|
||||||
errormsg: "statement not allowed after"
|
errormsg: "statement not allowed after"
|
||||||
"""
|
"""
|
||||||
# no statement after return
|
# no statement after return
|
||||||
proc main() =
|
proc main() =
|
||||||
return
|
return
|
||||||
echo("huch?") #ERROR_MSG statement not allowed after
|
echo("huch?") #ERROR_MSG statement not allowed after
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ converter p(i: int): bool = return i != 0
|
||||||
|
|
||||||
if 1:
|
if 1:
|
||||||
echo if 4: "foo" else: "barr"
|
echo if 4: "foo" else: "barr"
|
||||||
while 0:
|
while 0:
|
||||||
echo "bar"
|
echo "bar"
|
||||||
|
|
||||||
var a: array[3, bool]
|
var a: array[3, bool]
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,4 @@ proc main() =
|
||||||
thread.createThread(threadMain, 0)
|
thread.createThread(threadMain, 0)
|
||||||
thread.joinThreads()
|
thread.joinThreads()
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
# Test for the compiler to be able to compile a Nim file with spaces in it.
|
# Test for the compiler to be able to compile a Nim file with spaces in it.
|
||||||
|
|
||||||
echo("Successful")
|
echo("Successful")
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
# Test the discardable pragma
|
# Test the discardable pragma
|
||||||
|
|
||||||
proc p(x, y: int): int {.discardable.} =
|
proc p(x, y: int): int {.discardable.} =
|
||||||
return x + y
|
return x + y
|
||||||
|
|
||||||
# test that it is inherited from generic procs too:
|
# test that it is inherited from generic procs too:
|
||||||
proc q[T](x, y: T): T {.discardable.} =
|
proc q[T](x, y: T): T {.discardable.} =
|
||||||
return x + y
|
return x + y
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ discard """
|
||||||
proc p =
|
proc p =
|
||||||
var f: TFile
|
var f: TFile
|
||||||
echo "hi"
|
echo "hi"
|
||||||
|
|
||||||
open(f, "arg.txt")
|
open(f, "arg.txt")
|
||||||
|
|
||||||
p()
|
p()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ discard """
|
||||||
template Additive(typ: typeDesc): stmt =
|
template Additive(typ: typeDesc): stmt =
|
||||||
proc `+` *(x, y: typ): typ {.borrow.}
|
proc `+` *(x, y: typ): typ {.borrow.}
|
||||||
proc `-` *(x, y: typ): typ {.borrow.}
|
proc `-` *(x, y: typ): typ {.borrow.}
|
||||||
|
|
||||||
# unary operators:
|
# unary operators:
|
||||||
proc `+` *(x: typ): typ {.borrow.}
|
proc `+` *(x: typ): typ {.borrow.}
|
||||||
proc `-` *(x: typ): typ {.borrow.}
|
proc `-` *(x: typ): typ {.borrow.}
|
||||||
|
|
@ -27,7 +27,7 @@ template DefineCurrency(typ, base: expr): stmt {.immediate.} =
|
||||||
Additive(typ)
|
Additive(typ)
|
||||||
Multiplicative(typ, base)
|
Multiplicative(typ, base)
|
||||||
Comparable(typ)
|
Comparable(typ)
|
||||||
|
|
||||||
proc `$` * (t: typ): string {.borrow.}
|
proc `$` * (t: typ): string {.borrow.}
|
||||||
|
|
||||||
DefineCurrency(TDollar, int)
|
DefineCurrency(TDollar, int)
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ else:
|
||||||
|
|
||||||
proc newLit(x: int): PNode {.importc: "newLit", dynlib: dllname.}
|
proc newLit(x: int): PNode {.importc: "newLit", dynlib: dllname.}
|
||||||
proc newOp(k: TNodeKind, a, b: PNode): PNode {.
|
proc newOp(k: TNodeKind, a, b: PNode): PNode {.
|
||||||
importc: "newOp", dynlib: dllname.}
|
importc: "newOp", dynlib: dllname.}
|
||||||
proc buildTree(x: int): PNode {.importc: "buildTree", dynlib: dllname.}
|
proc buildTree(x: int): PNode {.importc: "buildTree", dynlib: dllname.}
|
||||||
|
|
||||||
proc eval(n: PNode): int =
|
proc eval(n: PNode): int =
|
||||||
case n.k
|
case n.k
|
||||||
|
|
@ -36,6 +36,6 @@ proc eval(n: PNode): int =
|
||||||
# Test the GC:
|
# Test the GC:
|
||||||
for i in 0..100_000:
|
for i in 0..100_000:
|
||||||
discard eval(buildTree(2))
|
discard eval(buildTree(2))
|
||||||
|
|
||||||
echo "Done"
|
echo "Done"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ type
|
||||||
else: a, b: ref TNode
|
else: a, b: ref TNode
|
||||||
|
|
||||||
PNode = ref TNode
|
PNode = ref TNode
|
||||||
|
|
||||||
proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} =
|
proc newLit(x: int): PNode {.exportc: "newLit", dynlib.} =
|
||||||
new(result)
|
new(result)
|
||||||
result.x = x
|
result.x = x
|
||||||
|
|
||||||
proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
|
proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
|
||||||
assert a != nil
|
assert a != nil
|
||||||
assert b != nil
|
assert b != nil
|
||||||
|
|
@ -22,13 +22,13 @@ proc newOp(k: TNodeKind, a, b: PNode): PNode {.exportc: "newOp", dynlib.} =
|
||||||
result.k = k
|
result.k = k
|
||||||
result.a = a
|
result.a = a
|
||||||
result.b = b
|
result.b = b
|
||||||
|
|
||||||
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
|
proc buildTree(x: int): PNode {.exportc: "buildTree", dynlib.} =
|
||||||
result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))
|
result = newOp(nkMul, newOp(nkAdd, newLit(x), newLit(x)), newLit(x))
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
# Test the GC:
|
# Test the GC:
|
||||||
for i in 0..100_000:
|
for i in 0..100_000:
|
||||||
discard buildTree(2)
|
discard buildTree(2)
|
||||||
|
|
||||||
echo "Done"
|
echo "Done"
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ type
|
||||||
TObj = object {.pure, inheritable.}
|
TObj = object {.pure, inheritable.}
|
||||||
TObjB = object of TObj
|
TObjB = object of TObj
|
||||||
a, b, c: string
|
a, b, c: string
|
||||||
|
|
||||||
IO2Error = ref object of IOError
|
IO2Error = ref object of IOError
|
||||||
|
|
||||||
proc forw: int {. .}
|
proc forw: int {. .}
|
||||||
|
|
||||||
proc lier(): int {.raises: [IO2Error].} =
|
proc lier(): int {.raises: [IO2Error].} =
|
||||||
writeLine stdout, "arg"
|
writeLine stdout, "arg"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ type
|
||||||
TObj = object {.pure, inheritable.}
|
TObj = object {.pure, inheritable.}
|
||||||
TObjB = object of TObj
|
TObjB = object of TObj
|
||||||
a, b, c: string
|
a, b, c: string
|
||||||
|
|
||||||
EIO2 = ref object of IOError
|
EIO2 = ref object of IOError
|
||||||
|
|
||||||
proc forw: int {.raises: [].}
|
proc forw: int {.raises: [].}
|
||||||
|
|
||||||
proc lier(): int {.raises: [IOError].} =
|
proc lier(): int {.raises: [IOError].} =
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ type
|
||||||
TObjB = object of TObj
|
TObjB = object of TObj
|
||||||
a, b, c: string
|
a, b, c: string
|
||||||
fn: proc (): int {.tags: [].}
|
fn: proc (): int {.tags: [].}
|
||||||
|
|
||||||
EIO2 = ref object of EIO
|
EIO2 = ref object of EIO
|
||||||
|
|
||||||
proc raiser(): int {.tags: [TObj, FWriteIO].} =
|
proc raiser(): int {.tags: [TObj, FWriteIO].} =
|
||||||
writeLine stdout, "arg"
|
writeLine stdout, "arg"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ type
|
||||||
TObjB = object of TObj
|
TObjB = object of TObj
|
||||||
a, b, c: string
|
a, b, c: string
|
||||||
fn: proc (): int {.tags: [FReadIO].}
|
fn: proc (): int {.tags: [FReadIO].}
|
||||||
|
|
||||||
EIO2 = ref object of EIO
|
EIO2 = ref object of EIO
|
||||||
|
|
||||||
proc q() {.tags: [FIO].} =
|
proc q() {.tags: [FIO].} =
|
||||||
nil
|
nil
|
||||||
|
|
||||||
proc raiser(): int =
|
proc raiser(): int =
|
||||||
writeLine stdout, "arg"
|
writeLine stdout, "arg"
|
||||||
if true:
|
if true:
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ discard """
|
||||||
proc p(q: proc() ): proc() {.tags: [], raises: [], closure.} =
|
proc p(q: proc() ): proc() {.tags: [], raises: [], closure.} =
|
||||||
return proc () =
|
return proc () =
|
||||||
q()
|
q()
|
||||||
|
|
||||||
let yay = p(proc () = raise newException(EIO, "IO"))
|
let yay = p(proc () = raise newException(EIO, "IO"))
|
||||||
|
|
||||||
proc main() {.raises: [], tags: [].} = yay()
|
proc main() {.raises: [], tags: [].} = yay()
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ type
|
||||||
PMenu = ref object
|
PMenu = ref object
|
||||||
PMenuItem = ref object
|
PMenuItem = ref object
|
||||||
|
|
||||||
proc createMenuItem*(menu: PMenu, label: string,
|
proc createMenuItem*(menu: PMenu, label: string,
|
||||||
action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = discard
|
action: proc (i: PMenuItem, p: pointer) {.cdecl.}) = discard
|
||||||
|
|
||||||
var s: PMenu
|
var s: PMenu
|
||||||
|
|
@ -19,7 +19,7 @@ createMenuItem(s, "Go to definition...",
|
||||||
proc noRaise(x: proc()) {.raises: [].} =
|
proc noRaise(x: proc()) {.raises: [].} =
|
||||||
# unknown call that might raise anything, but valid:
|
# unknown call that might raise anything, but valid:
|
||||||
x()
|
x()
|
||||||
|
|
||||||
proc doRaise() {.raises: [EIO].} =
|
proc doRaise() {.raises: [EIO].} =
|
||||||
raise newException(EIO, "IO")
|
raise newException(EIO, "IO")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ proc dontcare(x: int): int = return x + global
|
||||||
|
|
||||||
proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects
|
proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects
|
||||||
return x + y + dontcare(x)
|
return x + y + dontcare(x)
|
||||||
|
|
||||||
echo SideEffectLyer(1, 3)
|
echo SideEffectLyer(1, 3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ var
|
||||||
|
|
||||||
proc dontcare(x: int): int = return x
|
proc dontcare(x: int): int = return x
|
||||||
|
|
||||||
proc SideEffectLyer(x, y: int): int {.noSideEffect.} =
|
proc SideEffectLyer(x, y: int): int {.noSideEffect.} =
|
||||||
return x + y + dontcare(x)
|
return x + y + dontcare(x)
|
||||||
|
|
||||||
echo SideEffectLyer(1, 3) #OUT 5
|
echo SideEffectLyer(1, 3) #OUT 5
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ var
|
||||||
|
|
||||||
proc dontcare(x: int): int {.noSideEffect.} = return x
|
proc dontcare(x: int): int {.noSideEffect.} = return x
|
||||||
|
|
||||||
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
|
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
|
||||||
return x + y + dontcare(x)
|
return x + y + dontcare(x)
|
||||||
|
|
||||||
echo noSideEffect(1, 3, dontcare) #OUT 5
|
echo noSideEffect(1, 3, dontcare) #OUT 5
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,9 @@ var
|
||||||
|
|
||||||
proc dontcare(x: int): int = return x
|
proc dontcare(x: int): int = return x
|
||||||
|
|
||||||
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
|
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
|
||||||
return x + y + dontcare(x)
|
return x + y + dontcare(x)
|
||||||
|
|
||||||
echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch
|
echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
# Test enums
|
# Test enums
|
||||||
|
|
||||||
type
|
type
|
||||||
E = enum a, b, c, x, y, z
|
E = enum a, b, c, x, y, z
|
||||||
|
|
||||||
var
|
var
|
||||||
en: E
|
en: E
|
||||||
en = a
|
en = a
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
# Test that enum with holes is handled correctly by case statement
|
# Test that enum with holes is handled correctly by case statement
|
||||||
|
|
||||||
type
|
type
|
||||||
TEnumHole = enum
|
TEnumHole = enum
|
||||||
eA = 0,
|
eA = 0,
|
||||||
eB = 4,
|
eB = 4,
|
||||||
eC = 5
|
eC = 5
|
||||||
|
|
||||||
var
|
var
|
||||||
e: TEnumHole = eB
|
e: TEnumHole = eB
|
||||||
|
|
||||||
case e
|
case e
|
||||||
of eA: echo "A"
|
of eA: echo "A"
|
||||||
of eB: echo "B"
|
of eB: echo "B"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
# Test enum with explicit size
|
# Test enum with explicit size
|
||||||
|
|
||||||
type
|
type
|
||||||
TEnumHole {.size: sizeof(int).} = enum
|
TEnumHole {.size: sizeof(int).} = enum
|
||||||
eA = 0,
|
eA = 0,
|
||||||
eB = 4,
|
eB = 4,
|
||||||
eC = 5
|
eC = 5
|
||||||
|
|
||||||
var
|
var
|
||||||
e: TEnumHole = eB
|
e: TEnumHole = eB
|
||||||
|
|
||||||
case e
|
case e
|
||||||
of eA: echo "A"
|
of eA: echo "A"
|
||||||
of eB: echo "B"
|
of eB: echo "B"
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,10 @@ type
|
||||||
valueB = strValB & "conc",
|
valueB = strValB & "conc",
|
||||||
valueC,
|
valueC,
|
||||||
valueD = (4, "abc")
|
valueD = (4, "abc")
|
||||||
|
|
||||||
# test the new "proc body can be an expr" feature:
|
# test the new "proc body can be an expr" feature:
|
||||||
proc getValue: TMyEnum = valueD
|
proc getValue: TMyEnum = valueD
|
||||||
|
|
||||||
# trick the optimizer with a variable:
|
# trick the optimizer with a variable:
|
||||||
var x = getValue()
|
var x = getValue()
|
||||||
echo valueA, ord(valueA), valueB, ord(valueB), valueC, valueD, ord(valueD), x
|
echo valueA, ord(valueA), valueB, ord(valueB), valueC, valueD, ord(valueD), x
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,5 @@ discard """
|
||||||
type
|
type
|
||||||
TE1 = enum eA, eB
|
TE1 = enum eA, eB
|
||||||
TE2 = enum eC, eD
|
TE2 = enum eC, eD
|
||||||
|
|
||||||
assert eA != eC
|
assert eA != eC
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
|
|
||||||
type
|
type
|
||||||
# please make sure we have under 32 options (improves code efficiency!)
|
# please make sure we have under 32 options (improves code efficiency!)
|
||||||
TOption = enum
|
TOption = enum
|
||||||
optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck,
|
optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck,
|
||||||
optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir,
|
optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir,
|
||||||
optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly,
|
optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly,
|
||||||
optSafeCode, # only allow safe code
|
optSafeCode, # only allow safe code
|
||||||
optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib,
|
optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib,
|
||||||
optGenGuiApp, optStackTrace
|
optGenGuiApp, optStackTrace
|
||||||
|
|
||||||
TOptionset = set[TOption]
|
TOptionset = set[TOption]
|
||||||
|
|
||||||
var
|
var
|
||||||
gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck,
|
gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck,
|
||||||
optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace}
|
optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace}
|
||||||
compilerArgs: int
|
compilerArgs: int
|
||||||
gExitcode: int8
|
gExitcode: int8
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ try:
|
||||||
stdout.write("E")
|
stdout.write("E")
|
||||||
stdout.write("C")
|
stdout.write("C")
|
||||||
raise newException(EsomeotherErr, "bla")
|
raise newException(EsomeotherErr, "bla")
|
||||||
finally:
|
finally:
|
||||||
echo "caught"
|
echo "caught"
|
||||||
|
|
||||||
#OUT ECcaught
|
#OUT ECcaught
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ discard """
|
||||||
"""
|
"""
|
||||||
# Test return in try statement:
|
# Test return in try statement:
|
||||||
|
|
||||||
proc main: int =
|
proc main: int =
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
return 1
|
return 1
|
||||||
finally:
|
finally:
|
||||||
echo("came")
|
echo("came")
|
||||||
return 2
|
return 2
|
||||||
finally:
|
finally:
|
||||||
echo("here")
|
echo("here")
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ D'''
|
||||||
"""
|
"""
|
||||||
# Test break in try statement:
|
# Test break in try statement:
|
||||||
|
|
||||||
proc main: int =
|
proc main: int =
|
||||||
try:
|
try:
|
||||||
block AB:
|
block AB:
|
||||||
try:
|
try:
|
||||||
|
|
@ -16,14 +16,14 @@ proc main: int =
|
||||||
finally:
|
finally:
|
||||||
echo("A")
|
echo("A")
|
||||||
echo("skipped")
|
echo("skipped")
|
||||||
finally:
|
finally:
|
||||||
block B:
|
block B:
|
||||||
echo("B")
|
echo("B")
|
||||||
echo("skipped")
|
echo("skipped")
|
||||||
echo("C")
|
echo("C")
|
||||||
finally:
|
finally:
|
||||||
echo("D")
|
echo("D")
|
||||||
|
|
||||||
discard main() #OUT ABCD
|
discard main() #OUT ABCD
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
# Test break in try statement:
|
# Test break in try statement:
|
||||||
|
|
||||||
proc main: bool =
|
proc main: bool =
|
||||||
while true:
|
while true:
|
||||||
try:
|
try:
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ proc test4() =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
# Should cause unhandled exception error,
|
# Should cause unhandled exception error,
|
||||||
# but could cause segmentation fault if
|
# but could cause segmentation fault if
|
||||||
# exceptions are not handled properly.
|
# exceptions are not handled properly.
|
||||||
test4()
|
test4()
|
||||||
raise newException(OSError, "Problem")
|
raise newException(OSError, "Problem")
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,6 @@ when true:
|
||||||
genErrors("errssor!")
|
genErrors("errssor!")
|
||||||
except ESomething:
|
except ESomething:
|
||||||
echo("Error happened")
|
echo("Error happened")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ try:
|
||||||
raise newException(ValueError, "")
|
raise newException(ValueError, "")
|
||||||
except OverflowError:
|
except OverflowError:
|
||||||
echo("Error caught")
|
echo("Error caught")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,16 +26,16 @@ when true:
|
||||||
result.bar = "bar"
|
result.bar = "bar"
|
||||||
|
|
||||||
echo($newfoo())
|
echo($newfoo())
|
||||||
|
|
||||||
|
|
||||||
proc retInt(x, y: int): int =
|
|
||||||
|
proc retInt(x, y: int): int =
|
||||||
if (var yy = 0; yy != 0):
|
if (var yy = 0; yy != 0):
|
||||||
echo yy
|
echo yy
|
||||||
else:
|
else:
|
||||||
echo(try: parseInt("1244") except EINvalidValue: -1)
|
echo(try: parseInt("1244") except EINvalidValue: -1)
|
||||||
result = case x
|
result = case x
|
||||||
of 23: 3
|
of 23: 3
|
||||||
of 64:
|
of 64:
|
||||||
case y
|
case y
|
||||||
of 1: 2
|
of 1: 2
|
||||||
of 2: 3
|
of 2: 3
|
||||||
|
|
@ -79,7 +79,7 @@ semiProblem()
|
||||||
|
|
||||||
# bug #844
|
# bug #844
|
||||||
|
|
||||||
import json
|
import json
|
||||||
proc parseResponse(): PJsonNode =
|
proc parseResponse(): PJsonNode =
|
||||||
result = % { "key1": % { "key2": % "value" } }
|
result = % { "key1": % { "key2": % "value" } }
|
||||||
for key, val in result["key1"]:
|
for key, val in result["key1"]:
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ proc indexOf*(t: typedesc, name: string): int =
|
||||||
for n, x in fieldPairs(d):
|
for n, x in fieldPairs(d):
|
||||||
if n == name: return i
|
if n == name: return i
|
||||||
i.inc
|
i.inc
|
||||||
raise newException(EInvalidValue, "No field " & name & " in type " &
|
raise newException(EInvalidValue, "No field " & name & " in type " &
|
||||||
astToStr(t))
|
astToStr(t))
|
||||||
|
|
||||||
echo TMyTuple.indexOf("b")
|
echo TMyTuple.indexOf("b")
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ proc p(x: string) = echo "a string: ", x
|
||||||
var x: TMyTuple = ('a', 'b', 5, 6, "abc")
|
var x: TMyTuple = ('a', 'b', 5, 6, "abc")
|
||||||
var y: TMyTuple = ('A', 'b', 5, 9, "abc")
|
var y: TMyTuple = ('A', 'b', 5, 9, "abc")
|
||||||
|
|
||||||
for f in fields(x):
|
for f in fields(x):
|
||||||
p f
|
p f
|
||||||
|
|
||||||
for a, b in fields(x, y):
|
for a, b in fields(x, y):
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ type
|
||||||
a, b: char
|
a, b: char
|
||||||
x, y: int
|
x, y: int
|
||||||
z: string
|
z: string
|
||||||
|
|
||||||
TEnum = enum enA, enB, enC
|
TEnum = enum enA, enB, enC
|
||||||
TMyCaseObj = object
|
TMyCaseObj = object
|
||||||
case myDisc: TEnum
|
case myDisc: TEnum
|
||||||
|
|
@ -51,7 +51,7 @@ proc myobj(a, b: char, x, y: int, z: string): TMyObj =
|
||||||
var x = myobj('a', 'b', 5, 6, "abc")
|
var x = myobj('a', 'b', 5, 6, "abc")
|
||||||
var y = myobj('A', 'b', 5, 9, "abc")
|
var y = myobj('A', 'b', 5, 9, "abc")
|
||||||
|
|
||||||
for f in fields(x):
|
for f in fields(x):
|
||||||
p f
|
p f
|
||||||
|
|
||||||
for a, b in fields(x, y):
|
for a, b in fields(x, y):
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import math, strutils
|
||||||
{.emit: """
|
{.emit: """
|
||||||
void printFloats(void) {
|
void printFloats(void) {
|
||||||
double y = 1.234567890123456789;
|
double y = 1.234567890123456789;
|
||||||
|
|
||||||
printf("C double: %.10f, %.10f ", exp(y), cos(y));
|
printf("C double: %.10f, %.10f ", exp(y), cos(y));
|
||||||
}
|
}
|
||||||
""".}
|
""".}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
|
|
||||||
type
|
type
|
||||||
TMyObj = object
|
TMyObj = object
|
||||||
x: int
|
x: int
|
||||||
|
|
||||||
proc gen*[T](): T =
|
proc gen*[T](): T =
|
||||||
var d: TMyObj
|
var d: TMyObj
|
||||||
# access private field here
|
# access private field here
|
||||||
d.x = 3
|
d.x = 3
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ proc free*(some: ref TFoo) =
|
||||||
alive_foos.del alive_foos.find(some.id)
|
alive_foos.del alive_foos.find(some.id)
|
||||||
proc newFoo*(): ref TFoo =
|
proc newFoo*(): ref TFoo =
|
||||||
new result, free
|
new result, free
|
||||||
|
|
||||||
result.id = foo_counter
|
result.id = foo_counter
|
||||||
alive_foos.add result.id
|
alive_foos.add result.id
|
||||||
inc foo_counter
|
inc foo_counter
|
||||||
|
|
@ -26,7 +26,7 @@ for i in 0 .. <10:
|
||||||
|
|
||||||
for i in 0 .. <10:
|
for i in 0 .. <10:
|
||||||
let f = newFoo()
|
let f = newFoo()
|
||||||
f.fn = proc =
|
f.fn = proc =
|
||||||
echo f.id
|
echo f.id
|
||||||
|
|
||||||
GC_fullcollect()
|
GC_fullcollect()
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue