first steps for cleaner static/const distinction

This commit is contained in:
Araq 2012-03-13 02:01:56 +01:00
commit c25ffbf262
19 changed files with 193 additions and 66 deletions

View file

@ -51,6 +51,7 @@ Advanced options:
--tlsEmulation:on|off turn thread local storage emulation on|off
--taintMode:on|off turn taint mode on|off
--symbolFiles:on|off turn symbol files on|off (experimental)
--implicitStatic:on|off turn implicit compile time evaluation on|off
--skipCfg do not read the general configuration file
--skipUserCfg do not read the user's configuration file
--skipParentCfg do not read the parent dirs' configuration files

View file

@ -26,6 +26,7 @@ indexExpr ::= expr
castExpr ::= 'cast' '[' optInd typeDesc optPar ']' '(' optInd expr optPar ')'
addrExpr ::= 'addr' '(' optInd expr optPar ')'
staticExpr ::= 'static' '(' optInd expr optPar ')'
symbol ::= '`' (KEYWORD | IDENT | operator | '(' ')' | '[' ']' | '{' '}'
| '=' | literal)+ '`'
| IDENT
@ -37,7 +38,7 @@ primarySuffix ::= '.' optInd symbol [generalizedLit]
| '{' optInd [indexExpr (comma indexExpr)* [comma]] optPar '}'
primary ::= primaryPrefix* (symbol [generalizedLit] |
constructor | castExpr | addrExpr)
constructor | castExpr | addrExpr | staticExpr)
primarySuffix*
generalizedLit ::= GENERALIZED_STR_LIT | GENERALIZED_TRIPLESTR_LIT
@ -97,7 +98,7 @@ simpleStmt ::= returnStmt
| includeStmt
| exprStmt
complexStmt ::= ifStmt | whileStmt | caseStmt | tryStmt | forStmt
| blockStmt | asmStmt
| blockStmt | staticStmt | asmStmt
| procDecl | iteratorDecl | macroDecl | templateDecl | methodDecl
| constSection | letSection | varSection
| typeSection | whenStmt | bindStmt
@ -131,6 +132,7 @@ tryStmt ::= 'try' ':' stmt
['finally' ':' stmt]
asmStmt ::= 'asm' [pragma] (STR_LIT | RSTR_LIT | TRIPLESTR_LIT)
blockStmt ::= 'block' [symbol] ':' stmt
staticStmt ::= 'static' ':' stmt
filename ::= symbol | STR_LIT | RSTR_LIT | TRIPLESTR_LIT
importStmt ::= 'import' filename (comma filename)*
includeStmt ::= 'include' filename (comma filename)*

View file

@ -12,7 +12,7 @@ nil not notin
object of or out
proc ptr
raise ref return
shl shr
shl shr static
template try tuple type
var
when while with without

View file

@ -1640,6 +1640,30 @@ Constants cannot be of type ``ptr``, ``ref``, ``var`` or ``object``, nor can
they contain such a type.
Static statement/expression
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Syntax::
staticExpr ::= 'static' '(' optInd expr optPar ')'
staticStmt ::= 'static' ':' stmt
A `static`:idx: statement/expression can be used to enforce compile
time evaluation explicitely. Enforced compile time evaluation can even evaluate
code that has side effects:
.. code-block::
static:
echo "echo at compile time"
It's a static error if the compiler cannot perform the evaluation at compile time.
The current implementation poses some restrictions for compile time
evaluation: Code which contains ``cast`` or makes use of the foreign function
interface cannot be evaluated at compile time. Later versions of Nimrod will
support the FFI at compile time.
If statement
~~~~~~~~~~~~