From 9aa783624d133efd15e6720b5b59872258ee39fe Mon Sep 17 00:00:00 2001 From: Neelesh Chandola Date: Sun, 9 Dec 2018 12:33:58 +0530 Subject: [PATCH 1/4] `include` now accepts collective arguments --- compiler/semstmts.nim | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 48aa75528..7be4f6f05 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1836,17 +1836,33 @@ proc semMacroDef(c: PContext, n: PNode): PNode = if n.sons[bodyPos].kind == nkEmpty: localError(c.config, n.info, errImplOfXexpected % s.name.s) +proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) = + var f = checkModuleName(c.config, it) + if f != InvalidFileIDX: + if containsOrIncl(c.includedFiles, f.int): + localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f)) + else: + addSon(includeStmtResult, semStmt(c, c.graph.includeFileCallback(c.graph, c.module, f), {})) + excl(c.includedFiles, f.int) + proc evalInclude(c: PContext, n: PNode): PNode = result = newNodeI(nkStmtList, n.info) addSon(result, n) for i in countup(0, sonsLen(n) - 1): - var f = checkModuleName(c.config, n.sons[i]) - if f != InvalidFileIDX: - if containsOrIncl(c.includedFiles, f.int): - localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f)) - else: - addSon(result, semStmt(c, c.graph.includeFileCallback(c.graph, c.module, f), {})) - excl(c.includedFiles, f.int) + var imp: PNode + let it = n.sons[i] + if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket: + let sep = it[0] + let dir = it[1] + imp = newNodeI(nkInfix, it.info) + imp.add sep + imp.add dir + imp.add sep # dummy entry, replaced in the loop + for x in it[2]: + imp.sons[2] = x + incMod(c, n, imp, result) + else: + incMod(c, n, it, result) proc setLine(n: PNode, info: TLineInfo) = for i in 0 ..< safeLen(n): setLine(n.sons[i], info) From f77ddccb6c20acd0b8752dbd8d8040184f6460dc Mon Sep 17 00:00:00 2001 From: Neelesh Chandola Date: Sun, 9 Dec 2018 13:56:11 +0530 Subject: [PATCH 2/4] add tests --- tests/modules/t9627.nim | 7 +++++++ tests/modules/t9627/a.nim | 1 + tests/modules/t9627/b.nim | 1 + 3 files changed, 9 insertions(+) create mode 100644 tests/modules/t9627.nim create mode 100644 tests/modules/t9627/a.nim create mode 100644 tests/modules/t9627/b.nim diff --git a/tests/modules/t9627.nim b/tests/modules/t9627.nim new file mode 100644 index 000000000..be82edc45 --- /dev/null +++ b/tests/modules/t9627.nim @@ -0,0 +1,7 @@ +discard """ + output: "109" +""" + +include t9627 / [a, b] + +echo a, b \ No newline at end of file diff --git a/tests/modules/t9627/a.nim b/tests/modules/t9627/a.nim new file mode 100644 index 000000000..ef0c69db1 --- /dev/null +++ b/tests/modules/t9627/a.nim @@ -0,0 +1 @@ +var a = 10 \ No newline at end of file diff --git a/tests/modules/t9627/b.nim b/tests/modules/t9627/b.nim new file mode 100644 index 000000000..e9c9abf87 --- /dev/null +++ b/tests/modules/t9627/b.nim @@ -0,0 +1 @@ +var b = 9 \ No newline at end of file From 81427b535d2bf77755b5767e2ba8ecd61ec02c79 Mon Sep 17 00:00:00 2001 From: Neelesh Chandola Date: Sun, 9 Dec 2018 13:57:17 +0530 Subject: [PATCH 3/4] Add final newlines --- tests/modules/t9627.nim | 2 +- tests/modules/t9627/a.nim | 2 +- tests/modules/t9627/b.nim | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/modules/t9627.nim b/tests/modules/t9627.nim index be82edc45..646f030a1 100644 --- a/tests/modules/t9627.nim +++ b/tests/modules/t9627.nim @@ -4,4 +4,4 @@ discard """ include t9627 / [a, b] -echo a, b \ No newline at end of file +echo a, b diff --git a/tests/modules/t9627/a.nim b/tests/modules/t9627/a.nim index ef0c69db1..0dd32430e 100644 --- a/tests/modules/t9627/a.nim +++ b/tests/modules/t9627/a.nim @@ -1 +1 @@ -var a = 10 \ No newline at end of file +var a = 10 diff --git a/tests/modules/t9627/b.nim b/tests/modules/t9627/b.nim index e9c9abf87..2806a78ed 100644 --- a/tests/modules/t9627/b.nim +++ b/tests/modules/t9627/b.nim @@ -1 +1 @@ -var b = 9 \ No newline at end of file +var b = 9 From 96647618c289dc5ed025c141b4f7c8c191d4ab2b Mon Sep 17 00:00:00 2001 From: Neelesh Chandola Date: Sun, 9 Dec 2018 15:44:18 +0530 Subject: [PATCH 4/4] Fix compilation of test on linux and mac --- tests/modules/{t9627 => m9627}/a.nim | 0 tests/modules/{t9627 => m9627}/b.nim | 0 tests/modules/t9627.nim | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename tests/modules/{t9627 => m9627}/a.nim (100%) rename tests/modules/{t9627 => m9627}/b.nim (100%) diff --git a/tests/modules/t9627/a.nim b/tests/modules/m9627/a.nim similarity index 100% rename from tests/modules/t9627/a.nim rename to tests/modules/m9627/a.nim diff --git a/tests/modules/t9627/b.nim b/tests/modules/m9627/b.nim similarity index 100% rename from tests/modules/t9627/b.nim rename to tests/modules/m9627/b.nim diff --git a/tests/modules/t9627.nim b/tests/modules/t9627.nim index 646f030a1..daba46374 100644 --- a/tests/modules/t9627.nim +++ b/tests/modules/t9627.nim @@ -2,6 +2,6 @@ discard """ output: "109" """ -include t9627 / [a, b] +include m9627 / [a, b] echo a, b