diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 23:15:31 -0700 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2011-12-30 23:15:31 -0700 |
| commit | 3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df (patch) | |
| tree | 1a79525100ddc5cbff5331b2e37312ffce862026 | |
| parent | 70076bb00bdedb57405ed2ef27e2fec172e2f38a (diff) | |
| download | stage-3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df.tar.gz stage-3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df.tar.bz2 stage-3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df.tar.xz stage-3357b0a0ecc4d36ccd3c2668e9d55aaaefedf4df.zip | |
All variants of for each loop are tested and work
| -rw-r--r-- | src/gamestate.cpp | 18 | ||||
| -rw-r--r-- | src/variable.cpp | 5 | ||||
| -rw-r--r-- | src/variable.h | 1 | ||||
| -rw-r--r-- | support/vim/syntax/stage.vim | 2 | ||||
| -rw-r--r-- | test.stage | 7 |
5 files changed, 27 insertions, 6 deletions
diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 4af49aa..dcae848 100644 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp | |||
| @@ -428,8 +428,6 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
| 428 | Variable y = popDeref(); | 428 | Variable y = popDeref(); |
| 429 | Variable x = pop(); | 429 | Variable x = pop(); |
| 430 | deref( x ) += y; | 430 | deref( x ) += y; |
| 431 | // VariableRef r = x.getVariableRef(); | ||
| 432 | // setVariable( r.sName, getVariable( r.sName, r.sid ) + y, r.sid ); | ||
| 433 | } | 431 | } |
| 434 | break; | 432 | break; |
| 435 | 433 | ||
| @@ -438,8 +436,6 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
| 438 | Variable y = popDeref(); | 436 | Variable y = popDeref(); |
| 439 | Variable x = pop(); | 437 | Variable x = pop(); |
| 440 | deref( x ) -= y; | 438 | deref( x ) -= y; |
| 441 | // VariableRef r = x.getVariableRef(); | ||
| 442 | // setVariable( r.sName, getVariable( r.sName, r.sid ) - y, r.sid ); | ||
| 443 | } | 439 | } |
| 444 | break; | 440 | break; |
| 445 | 441 | ||
| @@ -618,6 +614,20 @@ void GameState::parse( const AstBranch::NodeList &lCode ) | |||
| 618 | parse( rDo ); | 614 | parse( rDo ); |
| 619 | } | 615 | } |
| 620 | } | 616 | } |
| 617 | else if( vIn.getType() == Variable::tList ) | ||
| 618 | { | ||
| 619 | if( bUseKey ) | ||
| 620 | { | ||
| 621 | throw Bu::ExceptionBase("You cannot use key:value pairs as iterators in a for each loop iterating over a list."); | ||
| 622 | } | ||
| 623 | const Variable::VariableList &rList = vIn.getList(); | ||
| 624 | for( Variable::VariableList::const_iterator i = | ||
| 625 | rList.begin(); i; i++ ) | ||
| 626 | { | ||
| 627 | setVariable( vrValue.sName, *i, vrValue.sid ); | ||
| 628 | parse( rDo ); | ||
| 629 | } | ||
| 630 | } | ||
| 621 | } | 631 | } |
| 622 | break; | 632 | break; |
| 623 | 633 | ||
diff --git a/src/variable.cpp b/src/variable.cpp index 0ce9793..5296848 100644 --- a/src/variable.cpp +++ b/src/variable.cpp | |||
| @@ -113,6 +113,11 @@ Variable *Variable::getVariablePtr() const | |||
| 113 | return pValue; | 113 | return pValue; |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | const Variable::VariableList &Variable::getList() const | ||
| 117 | { | ||
| 118 | return *lValue; | ||
| 119 | } | ||
| 120 | |||
| 116 | const Variable::VariableHash &Variable::getHash() const | 121 | const Variable::VariableHash &Variable::getHash() const |
| 117 | { | 122 | { |
| 118 | return *hValue; | 123 | return *hValue; |
diff --git a/src/variable.h b/src/variable.h index 22a1b26..8741b28 100644 --- a/src/variable.h +++ b/src/variable.h | |||
| @@ -61,6 +61,7 @@ public: | |||
| 61 | Bu::String getString() const; | 61 | Bu::String getString() const; |
| 62 | VariableRef getVariableRef() const; | 62 | VariableRef getVariableRef() const; |
| 63 | Variable *getVariablePtr() const; | 63 | Variable *getVariablePtr() const; |
| 64 | const VariableList &getList() const; | ||
| 64 | const VariableHash &getHash() const; | 65 | const VariableHash &getHash() const; |
| 65 | 66 | ||
| 66 | Variable to( Type e ) const; | 67 | Variable to( Type e ) const; |
diff --git a/support/vim/syntax/stage.vim b/support/vim/syntax/stage.vim index b18ec0d..34da126 100644 --- a/support/vim/syntax/stage.vim +++ b/support/vim/syntax/stage.vim | |||
| @@ -21,8 +21,6 @@ syn keyword Type function command situation game global player | |||
| 21 | syn keyword Constant null true false | 21 | syn keyword Constant null true false |
| 22 | syn keyword Builtins display goto exists delete exit return | 22 | syn keyword Builtins display goto exists delete exit return |
| 23 | 23 | ||
| 24 | syn match TargetProcess /[a-zA-Z_][a-zA-Z0-9_]*:/he=e-1 | ||
| 25 | |||
| 26 | syn cluster CommentGroup contains=Todo | 24 | syn cluster CommentGroup contains=Todo |
| 27 | 25 | ||
| 28 | syn match Special display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)" | 26 | syn match Special display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)" |
| @@ -28,6 +28,13 @@ situation <<start>> | |||
| 28 | display( lst ); | 28 | display( lst ); |
| 29 | lst -= 55; | 29 | lst -= 55; |
| 30 | display( lst ); | 30 | display( lst ); |
| 31 | lst += "hi"; | ||
| 32 | lst += "Things"; | ||
| 33 | display("---For each test---"); | ||
| 34 | for each x : y in dict do | ||
| 35 | { | ||
| 36 | display( x ); | ||
| 37 | } | ||
| 31 | exit(); | 38 | exit(); |
| 32 | } | 39 | } |
| 33 | 40 | ||
