first steps to deprecate 'nil' statement

This commit is contained in:
Araq 2012-09-09 01:08:00 +02:00
commit d3d9d32c35
9 changed files with 34 additions and 36 deletions

View file

@ -853,9 +853,10 @@ proc genStmts(p: BProc, t: PNode) =
# transf is overly aggressive with 'nkFastAsgn', so we work around here. # transf is overly aggressive with 'nkFastAsgn', so we work around here.
# See tests/run/tcnstseq3 for an example that would fail otherwise. # See tests/run/tcnstseq3 for an example that would fail otherwise.
genAsgn(p, t, fastAsgn=p.prc != nil) genAsgn(p, t, fastAsgn=p.prc != nil)
of nkDiscardStmt: of nkDiscardStmt:
genLineDir(p, t) if t.sons[0].kind != nkEmpty:
initLocExpr(p, t.sons[0], a) genLineDir(p, t)
initLocExpr(p, t.sons[0], a)
of nkAsmStmt: genAsmStmt(p, t) of nkAsmStmt: genAsmStmt(p, t)
of nkTryStmt: of nkTryStmt:
if gCmd == cmdCompileToCpp: genTryStmtCpp(p, t) if gCmd == cmdCompileToCpp: genTryStmtCpp(p, t)

View file

@ -1458,9 +1458,10 @@ proc genStmt(p: var TProc, n: PNode, r: var TCompRes) =
of nkAsgn: genAsgn(p, n, r) of nkAsgn: genAsgn(p, n, r)
of nkFastAsgn: genFastAsgn(p, n, r) of nkFastAsgn: genFastAsgn(p, n, r)
of nkDiscardStmt: of nkDiscardStmt:
genLineDir(p, n, r) if n.sons[0].kind != nkEmpty:
gen(p, n.sons[0], r) genLineDir(p, n, r)
app(r.res, ';' & tnl) gen(p, n.sons[0], r)
app(r.res, ';' & tnl)
of nkAsmStmt: genAsmStmt(p, n, r) of nkAsmStmt: genAsmStmt(p, n, r)
of nkTryStmt: genTryStmt(p, n, r) of nkTryStmt: genTryStmt(p, n, r)
of nkRaiseStmt: genRaiseStmt(p, n, r) of nkRaiseStmt: genRaiseStmt(p, n, r)

View file

@ -102,7 +102,7 @@ type
warnDeprecated, warnConfigDeprecated, warnDeprecated, warnConfigDeprecated,
warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel, warnSmallLshouldNotBeUsed, warnUnknownMagic, warnRedefinitionOfLabel,
warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored, warnUnknownSubstitutionX, warnLanguageXNotSupported, warnCommentXIgnored,
warnXisPassedToProcVar, warnAnalysisLoophole, warnNilStatement, warnAnalysisLoophole,
warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure, warnDifferentHeaps, warnWriteToForeignHeap, warnImplicitClosure,
warnEachIdentIsTuple, warnUser, warnEachIdentIsTuple, warnUser,
hintSuccess, hintSuccessX, hintSuccess, hintSuccessX,
@ -345,7 +345,7 @@ const
warnUnknownSubstitutionX: "unknown substitution \'$1\' [UnknownSubstitutionX]", warnUnknownSubstitutionX: "unknown substitution \'$1\' [UnknownSubstitutionX]",
warnLanguageXNotSupported: "language \'$1\' not supported [LanguageXNotSupported]", warnLanguageXNotSupported: "language \'$1\' not supported [LanguageXNotSupported]",
warnCommentXIgnored: "comment \'$1\' ignored [CommentXIgnored]", warnCommentXIgnored: "comment \'$1\' ignored [CommentXIgnored]",
warnXisPassedToProcVar: "\'$1\' is passed to a procvar; deprecated [XisPassedToProcVar]", warnNilStatement: "'nil' statement is deprecated; use an empty 'discard' statement instead [NilStmt]",
warnAnalysisLoophole: "thread analysis incomplete due to unknown call '$1' [AnalysisLoophole]", warnAnalysisLoophole: "thread analysis incomplete due to unknown call '$1' [AnalysisLoophole]",
warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]", warnDifferentHeaps: "possible inconsistency of thread local heaps [DifferentHeaps]",
warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]", warnWriteToForeignHeap: "write to foreign heap [WriteToForeignHeap]",
@ -375,7 +375,7 @@ const
"Deprecated", "ConfigDeprecated", "Deprecated", "ConfigDeprecated",
"SmallLshouldNotBeUsed", "UnknownMagic", "SmallLshouldNotBeUsed", "UnknownMagic",
"RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported", "RedefinitionOfLabel", "UnknownSubstitutionX", "LanguageXNotSupported",
"CommentXIgnored", "XisPassedToProcVar", "CommentXIgnored", "NilStmt",
"AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap", "AnalysisLoophole", "DifferentHeaps", "WriteToForeignHeap",
"ImplicitClosure", "EachIdentIsTuple", "User"] "ImplicitClosure", "EachIdentIsTuple", "User"]

View file

@ -1487,7 +1487,7 @@ proc simpleStmt(p: var TParser): PNode =
of tkReturn: result = parseReturnOrRaise(p, nkReturnStmt) of tkReturn: result = parseReturnOrRaise(p, nkReturnStmt)
of tkRaise: result = parseReturnOrRaise(p, nkRaiseStmt) of tkRaise: result = parseReturnOrRaise(p, nkRaiseStmt)
of tkYield: result = parseYieldOrDiscard(p, nkYieldStmt) of tkYield: result = parseYieldOrDiscard(p, nkYieldStmt)
of tkDiscard: result = parseYieldOrDiscard(p, nkDiscardStmt) of tkDiscard: result = parseReturnOrRaise(p, nkDiscardStmt)
of tkBreak: result = parseBreakOrContinue(p, nkBreakStmt) of tkBreak: result = parseBreakOrContinue(p, nkBreakStmt)
of tkContinue: result = parseBreakOrContinue(p, nkContinueStmt) of tkContinue: result = parseBreakOrContinue(p, nkContinueStmt)
of tkCurlyDotLe: result = parseStmtPragma(p) of tkCurlyDotLe: result = parseStmtPragma(p)

View file

@ -121,9 +121,6 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool =
add(arglist, n) add(arglist, n)
else: else:
result = false result = false
debug p.sons[2].sym.typ
debug n.typ
echo "type check failed!"
if n.kind notin nkCallKinds: return false if n.kind notin nkCallKinds: return false
if matches(c, p.sons[1], n.sons[0]): if matches(c, p.sons[1], n.sons[0]):

View file

@ -62,8 +62,9 @@ proc semIf(c: PContext, n: PNode): PNode =
proc semDiscard(c: PContext, n: PNode): PNode = proc semDiscard(c: PContext, n: PNode): PNode =
result = n result = n
checkSonsLen(n, 1) checkSonsLen(n, 1)
n.sons[0] = semExprWithType(c, n.sons[0]) if n.sons[0].kind != nkEmpty:
if n.sons[0].typ == nil: localError(n.info, errInvalidDiscard) n.sons[0] = semExprWithType(c, n.sons[0])
if n.sons[0].typ == nil: localError(n.info, errInvalidDiscard)
proc semBreakOrContinue(c: PContext, n: PNode): PNode = proc semBreakOrContinue(c: PContext, n: PNode): PNode =
result = n result = n
@ -935,7 +936,8 @@ proc semStaticStmt(c: PContext, n: PNode): PNode =
if result.isNil: if result.isNil:
LocalError(n.info, errCannotInterpretNodeX, renderTree(n)) LocalError(n.info, errCannotInterpretNodeX, renderTree(n))
elif result.kind == nkEmpty: elif result.kind == nkEmpty:
result = newNodeI(nkNilLit, n.info) result = newNodeI(nkDiscardStmt, n.info, 1)
result.sons[0] = emptyNode
# special marker values that indicates that we are # special marker values that indicates that we are
# 1) AnalyzingDestructor: currenlty analyzing the type for destructor # 1) AnalyzingDestructor: currenlty analyzing the type for destructor
@ -1132,7 +1134,10 @@ proc SemStmt(c: PContext, n: PNode): PNode =
of nkAsgn: result = semAsgn(c, n) of nkAsgn: result = semAsgn(c, n)
of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkMacroStmt, nkCallStrLit: of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkMacroStmt, nkCallStrLit:
result = semCommand(c, n) result = semCommand(c, n)
of nkEmpty, nkCommentStmt, nkNilLit: nil of nkEmpty, nkCommentStmt: nil
of nkNilLit:
# XXX too much work and fixing would break bootstrapping:
#Message(n.info, warnNilStatement)
of nkBlockStmt: result = semBlock(c, n) of nkBlockStmt: result = semBlock(c, n)
of nkStmtList: of nkStmtList:
var length = sonsLen(n) var length = sonsLen(n)

View file

@ -185,16 +185,6 @@ proc transformConstSection(c: PTransf, v: PNode): PTransNode =
else: else:
result[i] = PTransNode(it) result[i] = PTransNode(it)
proc trivialBody(s: PSym): PNode =
# a routine's body is trivially inlinable if marked as 'inline' and its
# body consists of only 1 statement. It is important that we perform this
# optimization here as 'distinct strings' may cause string copying otherwise:
# proc xml(s: string): TXmlString = return xmlstring(s)
# We have to generate a ``nkLineTracking`` node though to not lose
# debug information:
# XXX to implement
nil
proc hasContinue(n: PNode): bool = proc hasContinue(n: PNode): bool =
case n.kind case n.kind
of nkEmpty..nkNilLit, nkForStmt, nkParForStmt, nkWhileStmt: nil of nkEmpty..nkNilLit, nkForStmt, nkParForStmt, nkWhileStmt: nil
@ -627,11 +617,14 @@ proc transform(c: PTransf, n: PNode): PTransNode =
result = transformAddrDeref(c, n, nkAddr, nkHiddenAddr) result = transformAddrDeref(c, n, nkAddr, nkHiddenAddr)
of nkHiddenStdConv, nkHiddenSubConv, nkConv: of nkHiddenStdConv, nkHiddenSubConv, nkConv:
result = transformConv(c, n) result = transformConv(c, n)
of nkDiscardStmt: of nkDiscardStmt:
result = transformSons(c, n) result = PTransNode(n)
if isConstExpr(PNode(result).sons[0]): if n.sons[0].kind != nkEmpty:
# ensure that e.g. discard "some comment" gets optimized away completely: result = transformSons(c, n)
result = PTransNode(newNode(nkCommentStmt)) if isConstExpr(PNode(result).sons[0]):
# ensure that e.g. discard "some comment" gets optimized away
# completely:
result = PTransNode(newNode(nkCommentStmt))
of nkCommentStmt, nkTemplateDef: of nkCommentStmt, nkTemplateDef:
return n.ptransNode return n.ptransNode
of nkConstSection: of nkConstSection:

View file

@ -1,5 +1,6 @@
Comex Comex
Eric Doughty-Papassideris Eric Doughty-Papassideris
Simon Hafner
Keita Haga Keita Haga
Philippe Lhoste Philippe Lhoste
Zahary Karadjov Zahary Karadjov

View file

@ -6,9 +6,6 @@ version 0.9.0
- make 'bind' default for templates and introduce 'mixin' - make 'bind' default for templates and introduce 'mixin'
- implement "closure tuple consists of a single 'ref'" optimization
- implement for loop transformation for first class iterators
- implicit deref for parameter matching - implicit deref for parameter matching
- optimize genericAssign in the code generator - optimize genericAssign in the code generator
- the lookup rules for generics really are too permissive; global scope only - the lookup rules for generics really are too permissive; global scope only
@ -43,6 +40,8 @@ version 0.9.XX
echo a echo a
echo b) echo b)
- implement "closure tuple consists of a single 'ref'" optimization
- implement for loop transformation for first class iterators
- JS gen: - JS gen:
- fix exception handling - fix exception handling
- object branch transitions can't work with the current 'reset'; add a 'reset' - object branch transitions can't work with the current 'reset'; add a 'reset'
@ -60,7 +59,8 @@ version 0.9.XX
a full blown statement; a ``try`` expression might be a good idea to make a full blown statement; a ``try`` expression might be a good idea to make
error handling more light-weight error handling more light-weight
- ``=`` should be overloadable; requires specialization for ``=`` - ``=`` should be overloadable; requires specialization for ``=``
- ``hoist`` pragma for loop hoisting - ``hoist`` pragma for loop hoisting: can be easily done with
AST overloading + global
- document destructors; don't work yet when used as expression - document destructors; don't work yet when used as expression
- make use of ``tyIter`` to fix the implicit items/pairs issue - make use of ``tyIter`` to fix the implicit items/pairs issue
- better support for macros that rewrite procs - better support for macros that rewrite procs