diff options
-rw-r--r-- | compiler/parser.nim | 5 | ||||
-rw-r--r-- | compiler/semstmts.nim | 8 | ||||
-rw-r--r-- | lib/core/macros.nim | 18 | ||||
-rw-r--r-- | tests/macros/tmemit.nim | 7 | ||||
-rw-r--r-- | tests/parser/tdomulttest.nim | 17 | ||||
-rw-r--r-- | tests/parser/tinvwhen.nim | 15 | ||||
-rw-r--r-- | tests/pragmas/tuserpragma.nim (renamed from tests/pragma/tuserpragma.nim) | 0 | ||||
-rw-r--r-- | todo.txt | 4 |
8 files changed, 61 insertions, 13 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index dd683eb19..d255949a4 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -990,7 +990,7 @@ proc primary(p: var TParser, mode: TPrimaryMode): PNode = of tkTuple: result = parseTuple(p, mode == pmTypeDef) of tkProc: result = parseProcExpr(p, mode notin {pmTypeDesc, pmTypeDef}) of tkIterator: - when true: + when false: if mode in {pmTypeDesc, pmTypeDef}: result = parseProcExpr(p, false) result.kind = nkIteratorTy @@ -1001,7 +1001,8 @@ proc primary(p: var TParser, mode: TPrimaryMode): PNode = result = ast.emptyNode else: result = parseProcExpr(p, mode notin {pmTypeDesc, pmTypeDef}) - result.kind = nkIteratorTy + if result.kind == nkLambda: result.kind = nkIteratorDef + else: result.kind = nkIteratorTy of tkEnum: if mode == pmTypeDef: result = parseEnum(p) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 1aa6a793c..fc1706200 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -922,7 +922,7 @@ proc activate(c: PContext, n: PNode) = of nkCallKinds: for i in 1 .. <n.len: activate(c, n[i]) else: - nil + discard proc maybeAddResult(c: PContext, s: PSym, n: PNode) = if s.typ.sons[0] != nil and @@ -951,7 +951,11 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, var typeIsDetermined = false if n[namePos].kind != nkSym: assert phase == stepRegisterSymbol - s = semIdentDef(c, n.sons[0], kind) + + if n[namePos].kind == nkEmpty: + s = newSym(kind, idAnon, getCurrOwner(), n.info) + else: + s = semIdentDef(c, n.sons[0], kind) n.sons[namePos] = newSymNode(s) s.ast = n s.scope = c.currentScope diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 0356067f1..7cb084653 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -300,9 +300,12 @@ when not defined(booting): ## that should be inserted verbatim in the program ## Example: ## + ## .. code-block:: nimrod ## emit("echo " & '"' & "hello world".toUpper & '"') ## - eval: result = e.parseStmt + macro payload: stmt {.gensym.} = + result = e.parseStmt + payload() proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} = ## checks that `n` is of kind `k`. If this is not the case, @@ -645,10 +648,13 @@ iterator children*(n: PNimrodNode): PNimrodNode {.inline.}= for i in 0 .. high(n): yield n[i] -template findChild*(n: PNimrodNode; cond: expr): PNimrodNode {.immediate, dirty.} = - ## Find the first child node matching condition (or nil) - ## var res = findChild(n, it.kind == nnkPostfix and it.basename.ident == !"foo") - +template findChild*(n: PNimrodNode; cond: expr): PNimrodNode {. + immediate, dirty.} = + ## Find the first child node matching condition (or nil). + ## + ## .. code-block:: nimrod + ## var res = findChild(n, it.kind == nnkPostfix and + ## it.basename.ident == !"foo") block: var result: PNimrodNode for it in n.children: @@ -736,6 +742,6 @@ proc addIdentIfAbsent*(dest: PNimrodNode, ident: string) {.compiletime.} = if ident.eqIdent($node): return of nnkExprColonExpr: if ident.eqIdent($node[0]): return - else: nil + else: discard dest.add(ident(ident)) diff --git a/tests/macros/tmemit.nim b/tests/macros/tmemit.nim new file mode 100644 index 000000000..e4bb2daed --- /dev/null +++ b/tests/macros/tmemit.nim @@ -0,0 +1,7 @@ +discard """ + out: '''HELLO WORLD''' +""" + +import macros, strutils + +emit("echo " & '"' & "hello world".toUpper & '"') diff --git a/tests/parser/tdomulttest.nim b/tests/parser/tdomulttest.nim new file mode 100644 index 000000000..4ee6de128 --- /dev/null +++ b/tests/parser/tdomulttest.nim @@ -0,0 +1,17 @@ +discard """ + file: "tdomulttest.nim" + output: "555\ntest\nmulti lines\n99999999\nend" + disabled: true +""" +proc foo(bar, baz: proc (x: int): int) = + echo bar(555) + echo baz(99999999) + +foo do (x: int) -> int: + return x +do (x: int) -> int: + echo("test") + echo("multi lines") + return x + +echo("end") \ No newline at end of file diff --git a/tests/parser/tinvwhen.nim b/tests/parser/tinvwhen.nim new file mode 100644 index 000000000..5ff94cc6c --- /dev/null +++ b/tests/parser/tinvwhen.nim @@ -0,0 +1,15 @@ +discard """ + file: "tinvwhen.nim" + line: 11 + errormsg: "invalid indentation" +""" +# This was parsed even though it should not! + +proc chdir(path: cstring): cint {.importc: "chdir", header: "dirHeader".} + +proc getcwd(buf: cstring, buflen: cint): cstring + when defined(unix): {.importc: "getcwd", header: "<unistd.h>".} #ERROR_MSG invalid indentation + elif defined(windows): {.importc: "getcwd", header: "<direct.h>"} + else: {.error: "os library not ported to your OS. Please help!".} + + diff --git a/tests/pragma/tuserpragma.nim b/tests/pragmas/tuserpragma.nim index 784baa176..784baa176 100644 --- a/tests/pragma/tuserpragma.nim +++ b/tests/pragmas/tuserpragma.nim diff --git a/todo.txt b/todo.txt index 21416f279..15ce93df7 100644 --- a/todo.txt +++ b/todo.txt @@ -6,6 +6,7 @@ version 0.9.4 - ensure (ref T)(a, b) works as a type conversion and type constructor - document new templating symbol binding rules - make '--implicitStatic:on' the default +- change comment handling in the AST - special rule for ``[]=`` - ``=`` should be overloadable; requires specialization for ``=``; general @@ -27,8 +28,6 @@ Bugs - docgen: sometimes effects are listed twice - 'result' is not properly cleaned for NRVO --> use uninit checking instead - sneaking with qualifiedLookup() is really broken! -- aporia.nim(968, 5) Error: ambiguous identifier: 'DELETE' -- - use a qualifier - blocks can "export" an identifier but the CCG generates {} for them ... - osproc execProcesses can deadlock if all processes fail (as experienced in c++ mode) @@ -54,7 +53,6 @@ version 0.9.X - implement the missing features wrt inheritance - better support for macros that rewrite procs - macros need access to types and symbols (partially implemented) -- perhaps: change comment handling in the AST - enforce 'simpleExpr' more often --> doesn't work; tkProc is part of primary! - the typeDesc/expr unification is weird and only necessary because of |