From c93655e8b492dacbf35e5152e716035e112c899f Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 3 Jan 2018 21:47:59 +0200 Subject: Unify async macro and futures for js and native targets --- tests/async/config.nims | 2 -- tests/async/tjsandnativeasync.nim | 30 ++++++++++++++++++++++++++++++ tests/js/tasync.nim | 1 - tests/testament/categories.nim | 3 ++- 4 files changed, 32 insertions(+), 4 deletions(-) delete mode 100644 tests/async/config.nims create mode 100644 tests/async/tjsandnativeasync.nim (limited to 'tests') diff --git a/tests/async/config.nims b/tests/async/config.nims deleted file mode 100644 index 97c2e0aa4..000000000 --- a/tests/async/config.nims +++ /dev/null @@ -1,2 +0,0 @@ -when defined(upcoming): - patchFile("stdlib", "asyncdispatch", "$lib/upcoming/asyncdispatch") diff --git a/tests/async/tjsandnativeasync.nim b/tests/async/tjsandnativeasync.nim new file mode 100644 index 000000000..45839899f --- /dev/null +++ b/tests/async/tjsandnativeasync.nim @@ -0,0 +1,30 @@ +discard """ + output: '''hi +bye''' +""" + +import async, times +when defined(js): + proc sleepAsync(t: int): Future[void] = + var promise = newPromise() do(resolve: proc()): + {.emit: """ + setTimeout(function(){ + `resolve`(); + }, `t`); + """.} + result = promise +else: + from asyncdispatch import sleepAsync, waitFor + +proc foo() {.async.} = + echo "hi" + var s = epochTime() + await sleepAsync(500) + var e = epochTime() + doAssert(e - s > 0.1) + echo "bye" + +when defined(js): + discard foo() +else: + waitFor foo() diff --git a/tests/js/tasync.nim b/tests/js/tasync.nim index 34ef97b8b..76db38b27 100644 --- a/tests/js/tasync.nim +++ b/tests/js/tasync.nim @@ -1,5 +1,4 @@ discard """ - disabled: true output: ''' x e diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 33b93e3c4..9a8d80273 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -225,7 +225,8 @@ proc jsTests(r: var TResults, cat: Category, options: string) = "actiontable/tactiontable", "method/tmultim1", "method/tmultim3", "method/tmultim4", "varres/tvarres0", "varres/tvarres3", "varres/tvarres4", - "varres/tvartup", "misc/tints", "misc/tunsignedinc"]: + "varres/tvartup", "misc/tints", "misc/tunsignedinc", + "async/tjsandnativeasync"]: test "tests/" & testfile & ".nim" for testfile in ["strutils", "json", "random", "times", "logging"]: -- cgit 1.4.1-2-gfad0 From d9c922fc70b226b1c64c11d5ed3599c7b9322fd5 Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Thu, 18 Jan 2018 11:04:32 +0300 Subject: Fix gc tests for BoehmGC (#7094) --- tests/gc/gcleak.nim | 3 +-- tests/gc/gcleak2.nim | 4 +--- tests/gc/gcleak4.nim | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/gc/gcleak.nim b/tests/gc/gcleak.nim index 4e47db609..8852a8d91 100644 --- a/tests/gc/gcleak.nim +++ b/tests/gc/gcleak.nim @@ -13,11 +13,10 @@ proc MakeObj(): TTestObj = result.x = "Hello" for i in 1 .. 1_000_000: - when defined(gcMarkAndSweep): + when defined(gcMarkAndSweep) or defined(boehmgc): GC_fullcollect() var obj = MakeObj() if getOccupiedMem() > 300_000: quit("still a leak!") # echo GC_getstatistics() echo "no leak: ", getOccupiedMem() - diff --git a/tests/gc/gcleak2.nim b/tests/gc/gcleak2.nim index 101421683..facb8a008 100644 --- a/tests/gc/gcleak2.nim +++ b/tests/gc/gcleak2.nim @@ -16,7 +16,7 @@ proc MakeObj(): TTestObj = proc inProc() = for i in 1 .. 1_000_000: - when defined(gcMarkAndSweep): + when defined(gcMarkAndSweep) or defined(boehmgc): GC_fullcollect() var obj: TTestObj obj = MakeObj() @@ -24,5 +24,3 @@ proc inProc() = inProc() echo "no leak: ", getOccupiedMem() - - diff --git a/tests/gc/gcleak4.nim b/tests/gc/gcleak4.nim index d93a13854..e9b17e557 100644 --- a/tests/gc/gcleak4.nim +++ b/tests/gc/gcleak4.nim @@ -38,7 +38,7 @@ proc newPlus(a, b: ref TExpr): ref TPlusExpr = result.b = b result.op2 = $getOccupiedMem() -const Limit = when compileOption("gc", "markAndSweep"): 5*1024*1024 else: 500_000 +const Limit = when compileOption("gc", "markAndSweep") or compileOption("gc", "boehm"): 5*1024*1024 else: 500_000 for i in 0..100_000: var s: array[0..11, ref TExpr] -- cgit 1.4.1-2-gfad0 From 27aab0be162de4cca6132b46c12d98ce9c83d60e Mon Sep 17 00:00:00 2001 From: cooldome Date: Thu, 18 Jan 2018 09:38:55 +0000 Subject: Custom pragmas in procs bug fix (#7086) --- compiler/ast.nim | 1 + compiler/pragmas.nim | 1 - compiler/semstmts.nim | 10 ++++++---- tests/pragmas/tcustom_pragma.nim | 10 ++++++++++ 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/compiler/ast.nim b/compiler/ast.nim index 69f2eb1c7..5c70bda18 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -979,6 +979,7 @@ const nkIdentKinds* = {nkIdent, nkSym, nkAccQuoted, nkOpenSymChoice, nkClosedSymChoice} + nkPragmaCallKinds* = {nkExprColonExpr, nkCall, nkCallStrLit} nkLiterals* = {nkCharLit..nkTripleStrLit} nkLambdaKinds* = {nkLambda, nkDo} declarativeDefs* = {nkProcDef, nkFuncDef, nkMethodDef, nkIteratorDef, nkConverterDef} diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index b6229796f..810c4c416 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -17,7 +17,6 @@ import const FirstCallConv* = wNimcall LastCallConv* = wNoconv - nkPragmaCallKinds = {nkExprColonExpr, nkCall, nkCallStrLit} const procPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl, diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index ccddabcbe..78833adad 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1143,7 +1143,7 @@ proc semProcAnnotation(c: PContext, prc: PNode; if n == nil or n.kind == nkEmpty: return for i in countup(0, n.len-1): var it = n.sons[i] - var key = if it.kind == nkExprColonExpr: it.sons[0] else: it + var key = if it.kind in nkPragmaCallKinds and it.len >= 1: it.sons[0] else: it let m = lookupMacro(c, key) if m == nil: if key.kind == nkIdent and key.ident.id == ord(wDelegator): @@ -1164,10 +1164,12 @@ proc semProcAnnotation(c: PContext, prc: PNode; if prc[pragmasPos].kind != nkEmpty and prc[pragmasPos].len == 0: prc.sons[pragmasPos] = emptyNode - if it.kind == nkExprColonExpr: - # pass pragma argument to the macro too: - x.add(it.sons[1]) + if it.kind in nkPragmaCallKinds and it.len > 1: + # pass pragma arguments to the macro too: + for i in 1..7e747d11c ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14