Merge pull request #2859 from nanoant/patch/norewrite-pragma
{.noRewrite.} pragma for term rewriting
This commit is contained in:
commit
f8326ad4c0
6 changed files with 21 additions and 8 deletions
|
|
@ -423,6 +423,7 @@ type
|
||||||
# but unfortunately it has measurable impact for compilation
|
# but unfortunately it has measurable impact for compilation
|
||||||
# efficiency
|
# efficiency
|
||||||
nfTransf, # node has been transformed
|
nfTransf, # node has been transformed
|
||||||
|
nfNoRewrite # node should not be transformed anymore
|
||||||
nfSem # node has been checked for semantics
|
nfSem # node has been checked for semantics
|
||||||
nfLL # node has gone through lambda lifting
|
nfLL # node has gone through lambda lifting
|
||||||
nfDotField # the call can use a dot operator
|
nfDotField # the call can use a dot operator
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ proc setBaseFlags*(n: PNode, base: TNumericalBase)
|
||||||
proc parseSymbol*(p: var TParser, allowNil = false): PNode
|
proc parseSymbol*(p: var TParser, allowNil = false): PNode
|
||||||
proc parseTry(p: var TParser; isExpr: bool): PNode
|
proc parseTry(p: var TParser; isExpr: bool): PNode
|
||||||
proc parseCase(p: var TParser): PNode
|
proc parseCase(p: var TParser): PNode
|
||||||
|
proc parseStmtPragma(p: var TParser): PNode
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
proc getTok(p: var TParser) =
|
proc getTok(p: var TParser) =
|
||||||
|
|
@ -499,10 +500,13 @@ proc parsePar(p: var TParser): PNode =
|
||||||
#| parKeyw = 'discard' | 'include' | 'if' | 'while' | 'case' | 'try'
|
#| parKeyw = 'discard' | 'include' | 'if' | 'while' | 'case' | 'try'
|
||||||
#| | 'finally' | 'except' | 'for' | 'block' | 'const' | 'let'
|
#| | 'finally' | 'except' | 'for' | 'block' | 'const' | 'let'
|
||||||
#| | 'when' | 'var' | 'mixin'
|
#| | 'when' | 'var' | 'mixin'
|
||||||
#| par = '(' optInd (&parKeyw complexOrSimpleStmt ^+ ';'
|
#| par = '(' optInd
|
||||||
#| | simpleExpr ('=' expr (';' complexOrSimpleStmt ^+ ';' )? )?
|
#| ( &parKeyw complexOrSimpleStmt ^+ ';'
|
||||||
#| | (':' expr)? (',' (exprColonEqExpr comma?)*)? )?
|
#| | ';' complexOrSimpleStmt ^+ ';'
|
||||||
#| optPar ')'
|
#| | pragmaStmt
|
||||||
|
#| | simpleExpr ( ('=' expr (';' complexOrSimpleStmt ^+ ';' )? )
|
||||||
|
#| | (':' expr (',' exprColonEqExpr ^+ ',' )? ) ) )
|
||||||
|
#| optPar ')'
|
||||||
#
|
#
|
||||||
# unfortunately it's ambiguous: (expr: expr) vs (exprStmt); however a
|
# unfortunately it's ambiguous: (expr: expr) vs (exprStmt); however a
|
||||||
# leading ';' could be used to enforce a 'stmt' context ...
|
# leading ';' could be used to enforce a 'stmt' context ...
|
||||||
|
|
@ -521,6 +525,8 @@ proc parsePar(p: var TParser): PNode =
|
||||||
getTok(p)
|
getTok(p)
|
||||||
optInd(p, result)
|
optInd(p, result)
|
||||||
semiStmtList(p, result)
|
semiStmtList(p, result)
|
||||||
|
elif p.tok.tokType == tkCurlyDotLe:
|
||||||
|
result.add(parseStmtPragma(p))
|
||||||
elif p.tok.tokType != tkParRi:
|
elif p.tok.tokType != tkParRi:
|
||||||
var a = simpleExpr(p)
|
var a = simpleExpr(p)
|
||||||
if p.tok.tokType == tkEquals:
|
if p.tok.tokType == tkEquals:
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,9 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool =
|
||||||
|
|
||||||
proc matches(c: PPatternContext, p, n: PNode): bool =
|
proc matches(c: PPatternContext, p, n: PNode): bool =
|
||||||
# hidden conversions (?)
|
# hidden conversions (?)
|
||||||
if isPatternParam(c, p):
|
if nfNoRewrite in n.flags:
|
||||||
|
result = false
|
||||||
|
elif isPatternParam(c, p):
|
||||||
result = bindOrCheck(c, p.sym, n)
|
result = bindOrCheck(c, p.sym, n)
|
||||||
elif n.kind == nkSym and p.kind == nkIdent:
|
elif n.kind == nkSym and p.kind == nkIdent:
|
||||||
result = p.ident.id == n.sym.name.id
|
result = p.ident.id == n.sym.name.id
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ const
|
||||||
wImportc, wExportc, wNodecl, wMagic, wDeprecated, wBorrow, wExtern,
|
wImportc, wExportc, wNodecl, wMagic, wDeprecated, wBorrow, wExtern,
|
||||||
wImportCpp, wImportObjC, wError, wDiscardable, wGensym, wInject, wRaises,
|
wImportCpp, wImportObjC, wError, wDiscardable, wGensym, wInject, wRaises,
|
||||||
wTags, wLocks, wGcSafe}
|
wTags, wLocks, wGcSafe}
|
||||||
exprPragmas* = {wLine, wLocks}
|
exprPragmas* = {wLine, wLocks, wNoRewrite}
|
||||||
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangechecks,
|
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangechecks,
|
||||||
wBoundchecks, wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints,
|
wBoundchecks, wOverflowchecks, wNilchecks, wAssertions, wWarnings, wHints,
|
||||||
wLinedir, wStacktrace, wLinetrace, wOptimization, wHint, wWarning, wError,
|
wLinedir, wStacktrace, wLinetrace, wOptimization, wHint, wWarning, wError,
|
||||||
|
|
@ -859,6 +859,8 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
c.module.flags.incl sfExperimental
|
c.module.flags.incl sfExperimental
|
||||||
else:
|
else:
|
||||||
localError(it.info, "'experimental' pragma only valid as toplevel statement")
|
localError(it.info, "'experimental' pragma only valid as toplevel statement")
|
||||||
|
of wNoRewrite:
|
||||||
|
noVal(it)
|
||||||
else: invalidPragma(it)
|
else: invalidPragma(it)
|
||||||
else: invalidPragma(it)
|
else: invalidPragma(it)
|
||||||
else: processNote(c, it)
|
else: processNote(c, it)
|
||||||
|
|
|
||||||
|
|
@ -1268,6 +1268,8 @@ proc semPragmaBlock(c: PContext, n: PNode): PNode =
|
||||||
of wLocks:
|
of wLocks:
|
||||||
result = n
|
result = n
|
||||||
result.typ = n.sons[1].typ
|
result.typ = n.sons[1].typ
|
||||||
|
of wNoRewrite:
|
||||||
|
incl(result.flags, nfNoRewrite)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc semStaticStmt(c: PContext, n: PNode): PNode =
|
proc semStaticStmt(c: PContext, n: PNode): PNode =
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ type
|
||||||
wFloatchecks, wNanChecks, wInfChecks,
|
wFloatchecks, wNanChecks, wInfChecks,
|
||||||
wAssertions, wPatterns, wWarnings,
|
wAssertions, wPatterns, wWarnings,
|
||||||
wHints, wOptimization, wRaises, wWrites, wReads, wSize, wEffects, wTags,
|
wHints, wOptimization, wRaises, wWrites, wReads, wSize, wEffects, wTags,
|
||||||
wDeadCodeElim, wSafecode, wNoForward,
|
wDeadCodeElim, wSafecode, wNoForward, wNoRewrite,
|
||||||
wPragma,
|
wPragma,
|
||||||
wCompileTime, wNoInit,
|
wCompileTime, wNoInit,
|
||||||
wPassc, wPassl, wBorrow, wDiscardable,
|
wPassc, wPassl, wBorrow, wDiscardable,
|
||||||
|
|
@ -139,7 +139,7 @@ const
|
||||||
|
|
||||||
"assertions", "patterns", "warnings", "hints",
|
"assertions", "patterns", "warnings", "hints",
|
||||||
"optimization", "raises", "writes", "reads", "size", "effects", "tags",
|
"optimization", "raises", "writes", "reads", "size", "effects", "tags",
|
||||||
"deadcodeelim", "safecode", "noforward",
|
"deadcodeelim", "safecode", "noforward", "norewrite",
|
||||||
"pragma",
|
"pragma",
|
||||||
"compiletime", "noinit",
|
"compiletime", "noinit",
|
||||||
"passc", "passl", "borrow", "discardable", "fieldchecks",
|
"passc", "passl", "borrow", "discardable", "fieldchecks",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue