implemented 'experimental' switch
This commit is contained in:
parent
e27ab36731
commit
4b7de4dc5e
12 changed files with 49 additions and 7 deletions
|
|
@ -294,6 +294,7 @@ const
|
||||||
# require RC ops
|
# require RC ops
|
||||||
sfCompileToCpp* = sfInfixCall # compile the module as C++ code
|
sfCompileToCpp* = sfInfixCall # compile the module as C++ code
|
||||||
sfCompileToObjc* = sfNamedParamCall # compile the module as Objective-C code
|
sfCompileToObjc* = sfNamedParamCall # compile the module as Objective-C code
|
||||||
|
sfExperimental* = sfOverriden # module uses the .experimental switch
|
||||||
|
|
||||||
const
|
const
|
||||||
# getting ready for the future expr/stmt merge
|
# getting ready for the future expr/stmt merge
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ proc testCompileOption*(switch: string, info: TLineInfo): bool =
|
||||||
of "tlsemulation": result = contains(gGlobalOptions, optTlsEmulation)
|
of "tlsemulation": result = contains(gGlobalOptions, optTlsEmulation)
|
||||||
of "implicitstatic": result = contains(gOptions, optImplicitStatic)
|
of "implicitstatic": result = contains(gOptions, optImplicitStatic)
|
||||||
of "patterns": result = contains(gOptions, optPatterns)
|
of "patterns": result = contains(gOptions, optPatterns)
|
||||||
|
of "experimental": result = gExperimentalMode
|
||||||
else: invalidCmdLineOption(passCmd1, switch, info)
|
else: invalidCmdLineOption(passCmd1, switch, info)
|
||||||
|
|
||||||
proc processPath(path: string, notRelativeToProj = false): string =
|
proc processPath(path: string, notRelativeToProj = false): string =
|
||||||
|
|
@ -568,6 +569,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
|
||||||
of "none": idents.firstCharIsCS = false
|
of "none": idents.firstCharIsCS = false
|
||||||
else: localError(info, errGenerated,
|
else: localError(info, errGenerated,
|
||||||
"'partial' or 'none' expected, but found " & arg)
|
"'partial' or 'none' expected, but found " & arg)
|
||||||
|
of "experimental":
|
||||||
|
expectNoArg(switch, arg, pass, info)
|
||||||
|
gExperimentalMode = true
|
||||||
else:
|
else:
|
||||||
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
|
if strutils.find(switch, '.') >= 0: options.setConfigVar(switch, arg)
|
||||||
else: invalidCmdLineOption(pass, switch, info)
|
else: invalidCmdLineOption(pass, switch, info)
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ var
|
||||||
# the tracked source X, saved by the CAAS client.
|
# the tracked source X, saved by the CAAS client.
|
||||||
gDirtyOriginalIdx* = 0'i32 # the original source file of the dirtified buffer.
|
gDirtyOriginalIdx* = 0'i32 # the original source file of the dirtified buffer.
|
||||||
gNoNimblePath* = false
|
gNoNimblePath* = false
|
||||||
|
gExperimentalMode*: bool
|
||||||
|
|
||||||
proc importantComments*(): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools}
|
proc importantComments*(): bool {.inline.} = gCmd in {cmdDoc, cmdIdeTools}
|
||||||
proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc
|
proc usesNativeGC*(): bool {.inline.} = gSelectedGC >= gcRefc
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ const
|
||||||
wBreakpoint, wWatchPoint, wPassl, wPassc, wDeadCodeElim, wDeprecated,
|
wBreakpoint, wWatchPoint, wPassl, wPassc, wDeadCodeElim, wDeprecated,
|
||||||
wFloatchecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
|
wFloatchecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
|
||||||
wLinearScanEnd, wPatterns, wEffects, wNoForward, wComputedGoto,
|
wLinearScanEnd, wPatterns, wEffects, wNoForward, wComputedGoto,
|
||||||
wInjectStmt, wDeprecated}
|
wInjectStmt, wDeprecated, wExperimental}
|
||||||
lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
lambdaPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
||||||
wNosideeffect, wSideeffect, wNoreturn, wDynlib, wHeader,
|
wNosideeffect, wSideeffect, wNoreturn, wDynlib, wHeader,
|
||||||
wDeprecated, wExtern, wThread, wImportCpp, wImportObjC, wAsmNoStackFrame,
|
wDeprecated, wExtern, wThread, wImportCpp, wImportObjC, wAsmNoStackFrame,
|
||||||
|
|
@ -850,6 +850,12 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
localError(it.info, errExprExpected)
|
localError(it.info, errExprExpected)
|
||||||
else:
|
else:
|
||||||
it.sons[1] = c.semExpr(c, it.sons[1])
|
it.sons[1] = c.semExpr(c, it.sons[1])
|
||||||
|
of wExperimental:
|
||||||
|
noVal(it)
|
||||||
|
if isTopLevel(c):
|
||||||
|
c.module.flags.incl sfExperimental
|
||||||
|
else:
|
||||||
|
localError(it.info, "'experimental' pragma only valid as toplevel statement")
|
||||||
else: invalidPragma(it)
|
else: invalidPragma(it)
|
||||||
else: invalidPragma(it)
|
else: invalidPragma(it)
|
||||||
else: processNote(c, it)
|
else: processNote(c, it)
|
||||||
|
|
|
||||||
|
|
@ -133,9 +133,6 @@ proc commonType*(x, y: PType): PType =
|
||||||
result = newType(k, r.owner)
|
result = newType(k, r.owner)
|
||||||
result.addSonSkipIntLit(r)
|
result.addSonSkipIntLit(r)
|
||||||
|
|
||||||
proc isTopLevel(c: PContext): bool {.inline.} =
|
|
||||||
result = c.currentScope.depthLevel <= 2
|
|
||||||
|
|
||||||
proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
|
proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
result = newSym(kind, considerQuotedIdent(n), getCurrOwner(), n.info)
|
result = newSym(kind, considerQuotedIdent(n), getCurrOwner(), n.info)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -312,3 +312,8 @@ proc checkSonsLen*(n: PNode, length: int) =
|
||||||
proc checkMinSonsLen*(n: PNode, length: int) =
|
proc checkMinSonsLen*(n: PNode, length: int) =
|
||||||
if sonsLen(n) < length: illFormedAst(n)
|
if sonsLen(n) < length: illFormedAst(n)
|
||||||
|
|
||||||
|
proc isTopLevel*(c: PContext): bool {.inline.} =
|
||||||
|
result = c.currentScope.depthLevel <= 2
|
||||||
|
|
||||||
|
proc experimentalMode*(c: PContext): bool {.inline.} =
|
||||||
|
result = gExperimentalMode or sfExperimental in c.module.flags
|
||||||
|
|
|
||||||
|
|
@ -1433,6 +1433,8 @@ proc newAnonSym(kind: TSymKind, info: TLineInfo,
|
||||||
|
|
||||||
proc semUsing(c: PContext, n: PNode): PNode =
|
proc semUsing(c: PContext, n: PNode): PNode =
|
||||||
result = newNodeI(nkEmpty, n.info)
|
result = newNodeI(nkEmpty, n.info)
|
||||||
|
if not experimentalMode(c):
|
||||||
|
localError(n.info, "use the {.experimental.} pragma to enable 'using'")
|
||||||
for e in n.sons:
|
for e in n.sons:
|
||||||
let usedSym = semExpr(c, e)
|
let usedSym = semExpr(c, e)
|
||||||
if usedSym.kind == nkSym:
|
if usedSym.kind == nkSym:
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,8 @@ type
|
||||||
wPassc, wPassl, wBorrow, wDiscardable,
|
wPassc, wPassl, wBorrow, wDiscardable,
|
||||||
wFieldChecks,
|
wFieldChecks,
|
||||||
wWatchPoint, wSubsChar,
|
wWatchPoint, wSubsChar,
|
||||||
wAcyclic, wShallow, wUnroll, wLinearScanEnd, wComputedGoto, wInjectStmt,
|
wAcyclic, wShallow, wUnroll, wLinearScanEnd, wComputedGoto,
|
||||||
|
wInjectStmt, wExperimental,
|
||||||
wWrite, wGensym, wInject, wDirty, wInheritable, wThreadVar, wEmit,
|
wWrite, wGensym, wInject, wDirty, wInheritable, wThreadVar, wEmit,
|
||||||
wAsmNoStackFrame,
|
wAsmNoStackFrame,
|
||||||
wImplicitStatic, wGlobal, wCodegenDecl, wUnchecked, wGuard, wLocks,
|
wImplicitStatic, wGlobal, wCodegenDecl, wUnchecked, wGuard, wLocks,
|
||||||
|
|
@ -144,7 +145,7 @@ const
|
||||||
"passc", "passl", "borrow", "discardable", "fieldchecks",
|
"passc", "passl", "borrow", "discardable", "fieldchecks",
|
||||||
"watchpoint",
|
"watchpoint",
|
||||||
"subschar", "acyclic", "shallow", "unroll", "linearscanend",
|
"subschar", "acyclic", "shallow", "unroll", "linearscanend",
|
||||||
"computedgoto", "injectstmt",
|
"computedgoto", "injectstmt", "experimental",
|
||||||
"write", "gensym", "inject", "dirty", "inheritable", "threadvar", "emit",
|
"write", "gensym", "inject", "dirty", "inheritable", "threadvar", "emit",
|
||||||
"asmnostackframe", "implicitstatic", "global", "codegendecl", "unchecked",
|
"asmnostackframe", "implicitstatic", "global", "codegendecl", "unchecked",
|
||||||
"guard", "locks",
|
"guard", "locks",
|
||||||
|
|
|
||||||
|
|
@ -91,4 +91,5 @@ Advanced options:
|
||||||
--verbosity:0|1|2|3 set Nim's verbosity level (1 is default)
|
--verbosity:0|1|2|3 set Nim's verbosity level (1 is default)
|
||||||
--cs:none|partial set case sensitivity level (default: none);
|
--cs:none|partial set case sensitivity level (default: none);
|
||||||
do not use! this setting affects the whole language
|
do not use! this setting affects the whole language
|
||||||
|
--experimental enable experimental language features
|
||||||
-v, --version show detailed version information
|
-v, --version show detailed version information
|
||||||
|
|
|
||||||
|
|
@ -495,3 +495,21 @@ identifier that can be used to enable or disable it:
|
||||||
This is often better than disabling all warnings at once.
|
This is often better than disabling all warnings at once.
|
||||||
|
|
||||||
|
|
||||||
|
experimental pragma
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
The ``experimental`` pragma enables experimental language features. Depending
|
||||||
|
on the concrete feature this means that the feature is either considered
|
||||||
|
too unstable for an otherwise stable release or that the future of the feature
|
||||||
|
is uncertain (it may be removed any time).
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
{.experimental.}
|
||||||
|
|
||||||
|
proc useUsing(dest: var string) =
|
||||||
|
using dest
|
||||||
|
add "foo"
|
||||||
|
add "bar"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,8 @@ Instead of:
|
||||||
Using statement
|
Using statement
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
**Warning**: The ``using`` statement is highly experimental!
|
**Warning**: The ``using`` statement is highly experimental and has to be
|
||||||
|
explicitly enabled with the `experimental`:idx: pragma or command line option!
|
||||||
|
|
||||||
The using statement provides syntactic convenience for procs that
|
The using statement provides syntactic convenience for procs that
|
||||||
heavily use a single contextual parameter. When applied to a variable or a
|
heavily use a single contextual parameter. When applied to a variable or a
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ News
|
||||||
- The "symmetric set difference" operator (``-+-``) never worked and has been
|
- The "symmetric set difference" operator (``-+-``) never worked and has been
|
||||||
removed.
|
removed.
|
||||||
- ``defer`` is a keyword now.
|
- ``defer`` is a keyword now.
|
||||||
|
- The ``using`` language feature now needs to be activated via the new
|
||||||
|
``{.experimental.}`` pragma that enables experimental language features.
|
||||||
|
|
||||||
Language Additions
|
Language Additions
|
||||||
------------------
|
------------------
|
||||||
|
|
@ -39,6 +41,9 @@ News
|
||||||
- ``deepCopy`` has been added to the language.
|
- ``deepCopy`` has been added to the language.
|
||||||
- The builtin ``procCall`` can be used to get ``super``-like functionality
|
- The builtin ``procCall`` can be used to get ``super``-like functionality
|
||||||
for multi methods.
|
for multi methods.
|
||||||
|
- There is a new pragma ``{.experimental.}`` that enables experimental
|
||||||
|
language features per module, or you can enable this features on a global
|
||||||
|
level with the ``--experimental`` command line option.
|
||||||
|
|
||||||
|
|
||||||
Compiler Additions
|
Compiler Additions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue