summaryrefslogtreecommitdiff
path: root/src/gamestate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gamestate.cpp')
-rw-r--r--src/gamestate.cpp83
1 files changed, 82 insertions, 1 deletions
diff --git a/src/gamestate.cpp b/src/gamestate.cpp
index 4cab5c1..5577c17 100644
--- a/src/gamestate.cpp
+++ b/src/gamestate.cpp
@@ -118,12 +118,17 @@ void GameState::parse( const AstBranch::NodeList &lCode )
118{ 118{
119 for( AstBranch::NodeList::const_iterator i = lCode.begin(); i; i++ ) 119 for( AstBranch::NodeList::const_iterator i = lCode.begin(); i; i++ )
120 { 120 {
121 sio << "Stack: " << lStack << sio.nl; 121// sio << "Stack: " << lStack << sio.nl;
122 switch( (*i)->getType() ) 122 switch( (*i)->getType() )
123 { 123 {
124 // tLeaf 124 // tLeaf
125 case AstNode::tNot: 125 case AstNode::tNot:
126 case AstNode::tComp: 126 case AstNode::tComp:
127 {
128 push( popDeref() == popDeref() );
129 }
130 break;
131
127 case AstNode::tCompGt: 132 case AstNode::tCompGt:
128 case AstNode::tCompLt: 133 case AstNode::tCompLt:
129 case AstNode::tCompGtEq: 134 case AstNode::tCompGtEq:
@@ -147,13 +152,65 @@ void GameState::parse( const AstBranch::NodeList &lCode )
147 break; 152 break;
148 153
149 case AstNode::tMinus: 154 case AstNode::tMinus:
155 {
156 Variable y = popDeref();
157 Variable x = popDeref();
158 lStack.push( x - y );
159 }
160 break;
161
150 case AstNode::tDivide: 162 case AstNode::tDivide:
163 {
164 Variable y = popDeref();
165 Variable x = popDeref();
166 lStack.push( x / y );
167 }
168 break;
169
151 case AstNode::tMultiply: 170 case AstNode::tMultiply:
171 {
172 Variable y = popDeref();
173 Variable x = popDeref();
174 lStack.push( x * y );
175 }
176 break;
177
152 case AstNode::tPlusStore: 178 case AstNode::tPlusStore:
179 {
180 Variable y = popDeref();
181 Variable x = pop();
182 setVariable( x.getString(), getVariable( x.getString() ) + y );
183 }
184 break;
185
153 case AstNode::tMinusStore: 186 case AstNode::tMinusStore:
187 {
188 Variable y = popDeref();
189 Variable x = pop();
190 setVariable( x.getString(), getVariable( x.getString() ) - y );
191 }
192 break;
193
154 case AstNode::tDivideStore: 194 case AstNode::tDivideStore:
195 {
196 Variable y = popDeref();
197 Variable x = pop();
198 setVariable( x.getString(), getVariable( x.getString() ) / y );
199 }
200 break;
201
155 case AstNode::tMultiplyStore: 202 case AstNode::tMultiplyStore:
203 {
204 Variable y = popDeref();
205 Variable x = pop();
206 setVariable( x.getString(), getVariable( x.getString() ) * y );
207 }
208 break;
209
156 case AstNode::tNegate: 210 case AstNode::tNegate:
211 push( -popDeref() );
212 break;
213
157 case AstNode::tIn: 214 case AstNode::tIn:
158 215
159 // tLeafLiteral 216 // tLeafLiteral
@@ -172,6 +229,30 @@ void GameState::parse( const AstBranch::NodeList &lCode )
172 // tBranch 229 // tBranch
173 case AstNode::tScope: 230 case AstNode::tScope:
174 case AstNode::tIf: 231 case AstNode::tIf:
232 {
233 AstBranch::NodeList lIf =
234 dynamic_cast<const AstBranch *>(*i)->getNodeList();
235 AstBranch::NodeList::const_iterator iIf = lIf.begin();
236 parse( dynamic_cast<const AstBranch *>(*iIf)->getNodeList() );
237 Variable v = popDeref();
238 if( v.getType() != Variable::tBool )
239 throw Bu::ExceptionBase("conditional did not evaluate to boolean.");
240 iIf++;
241 if( v.getBool() )
242 {
243 parse( dynamic_cast<const AstBranch *>(*iIf)->
244 getNodeList() );
245 }
246 else
247 {
248 iIf++;
249 if( iIf )
250 parse( dynamic_cast<const AstBranch *>(*iIf)->
251 getNodeList() );
252 }
253 }
254 break;
255
175 case AstNode::tForEach: 256 case AstNode::tForEach:
176 case AstNode::tWhile: 257 case AstNode::tWhile:
177 break; 258 break;