diff --git a/.gitignore b/.gitignore index 825f7c3f..d34ecfe7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ nimcache/ nimblecache/ htmldocs/ *.exe -nifcache/ \ No newline at end of file +nifcache/ +src/nifc/nifc_grammar.nim diff --git a/doc/nifc-spec.md b/doc/nifc-spec.md index 2a83d4dc..981b0a16 100644 --- a/doc/nifc-spec.md +++ b/doc/nifc-spec.md @@ -141,8 +141,9 @@ Stmt ::= Call | (case Expr (of BranchRanges StmtList)* (else StmtList)?) | (lab SymbolDef) | (jmp Symbol) | - (scope StmtList) - (ret [Empty | Expr]) # return statement + (scope StmtList) | + (ret [Empty | Expr]) | # return statement + (discard Expr) StmtList ::= (stmts SCOPE Stmt*) diff --git a/src/nifc/codegen.nim b/src/nifc/codegen.nim index b0238e55..1d170044 100644 --- a/src/nifc/codegen.nim +++ b/src/nifc/codegen.nim @@ -60,6 +60,7 @@ type TypedefKeyword = "typedef " IncludeKeyword = "#include " LineDirKeyword = "#line " + DiscardToken = "(void) " proc fillTokenTable(tab: var BiTable[Token, string]) = for e in EmptyToken..high(PredefinedToken): diff --git a/src/nifc/genstmts.nim b/src/nifc/genstmts.nim index 58919c75..3ed65966 100644 --- a/src/nifc/genstmts.nim +++ b/src/nifc/genstmts.nim @@ -201,5 +201,9 @@ proc genStmt(c: var GeneratedCode; t: Tree; n: NodePos) = c.add Space c.genx t, n.firstSon c.add Semicolon + of DiscardC: + c.add DiscardToken + c.genx t, n.firstSon + c.add Semicolon else: error c.m, "expected statement but got: ", t, n diff --git a/src/nifc/nifc_grammar.nif b/src/nifc/nifc_grammar.nif index 3572a762..fc57cf4f 100644 --- a/src/nifc/nifc_grammar.nif +++ b/src/nifc/nifc_grammar.nif @@ -66,7 +66,9 @@ (lab SYMBOLDEF) (jmp SYMBOL) (scope StmtList) - (ret (OR . Expr)))) + (ret (OR . Expr)) + (discard Expr) + )) (RULE :StmtList (SCOPE (stmts (ZERO_OR_MANY Stmt)))) diff --git a/src/nifc/nifc_model.nim b/src/nifc/nifc_model.nim index 4cfaf15d..80f3043d 100644 --- a/src/nifc/nifc_model.nim +++ b/src/nifc/nifc_model.nim @@ -118,6 +118,7 @@ type InfC = "inf" NegInfC = "neginf" NanC = "nan" + DiscardC = "discard" const diff --git a/src/nifc/typenav.nim b/src/nifc/typenav.nim index b36ade28..33746d3d 100644 --- a/src/nifc/typenav.nim +++ b/src/nifc/typenav.nim @@ -156,5 +156,5 @@ proc getType*(m: var Module; t: Tree; n: NodePos): TypeDesc = VoidC, PtrC, ArrayC, FlexarrayC, APtrC, TypeC, CdeclC, StdcallC, SafecallC, SyscallC, FastcallC, ThiscallC, NoconvC, MemberC, AttrC, InlineC, NoinlineC, VarargsC, WasC, SelectanyC, - PragmasC, AlignC, BitsC, VectorC, ImpC, NodeclC, InclC, ScopeC: + PragmasC, AlignC, BitsC, VectorC, ImpC, NodeclC, InclC, ScopeC, DiscardC: result = errorType() diff --git a/tests/data/nifc_grammar.nim b/tests/data/nifc_grammar.nim index aeaad5d3..71b7f987 100644 --- a/tests/data/nifc_grammar.nim +++ b/tests/data/nifc_grammar.nim @@ -832,6 +832,15 @@ proc matchStmt(c: var Context; it: var Item): bool = if kw18: or2 = true break or3 + var kw21 = false + if isTag(c, it, DiscardT): + if not matchExpr(c, it): + error(c, it, "Expr expected") + break or3 + kw21 = matchParRi(c, it) + if kw21: + or2 = true + break or3 if not or2: return false when declared(handleStmt): handleStmt(c, it, before1) diff --git a/tests/nifc/issues.nif b/tests/nifc/issues.nif index 2617c351..e9b52ce1 100644 --- a/tests/nifc/issues.nif +++ b/tests/nifc/issues.nif @@ -203,6 +203,7 @@ (call foo.intminmax) (call foo.inline) + (discard (call foo.inline)) (call foo.noinline) (call foo.cdecl) (call foo.stdcall) @@ -212,6 +213,7 @@ (call foo.member) (var :x.c . (i +8) (suf +12 "i8")) + (discard x.c) (var :x.m . (i +16) (suf -12 "i16")) (var :x1 . (i +32) (suf +12 "i32")) (var :y1 . (u +32) (suf +12 "u32"))