summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-01-03 23:58:34 -0700
committerMike Buland <eichlan@xagasoft.com>2012-01-03 23:58:34 -0700
commit3a0f68b527cc85bd9847127085415739af784eca (patch)
treef6ea23fd940122d0d757182e4422f8cf86e8d071 /src
parent549069762ccc35352186eb4fe1922883a0c4f213 (diff)
downloadstage-3a0f68b527cc85bd9847127085415739af784eca.tar.gz
stage-3a0f68b527cc85bd9847127085415739af784eca.tar.bz2
stage-3a0f68b527cc85bd9847127085415739af784eca.tar.xz
stage-3a0f68b527cc85bd9847127085415739af784eca.zip
Fixes for +=, -=, *=, /=
Diffstat (limited to 'src')
-rw-r--r--src/gamestate.cpp14
-rw-r--r--src/variable.cpp146
2 files changed, 145 insertions, 15 deletions
diff --git a/src/gamestate.cpp b/src/gamestate.cpp
index 57dbe2f..285c151 100644
--- a/src/gamestate.cpp
+++ b/src/gamestate.cpp
@@ -427,34 +427,28 @@ void GameState::parse( const AstBranch::NodeList &lCode )
427 case AstNode::tPlusStore: 427 case AstNode::tPlusStore:
428 { 428 {
429 Variable y = popDeref(); 429 Variable y = popDeref();
430 Variable x = pop(); 430 deref( lStack.peek(), true ) += y;
431 deref( x ) += y;
432 } 431 }
433 break; 432 break;
434 433
435 case AstNode::tMinusStore: 434 case AstNode::tMinusStore:
436 { 435 {
437 Variable y = popDeref(); 436 Variable y = popDeref();
438 Variable x = pop(); 437 deref( lStack.peek(), true ) -= y;
439 deref( x ) -= y;
440 } 438 }
441 break; 439 break;
442 440
443 case AstNode::tDivideStore: 441 case AstNode::tDivideStore:
444 { 442 {
445 Variable y = popDeref(); 443 Variable y = popDeref();
446 Variable x = pop(); 444 deref( lStack.peek(), true ) /= y;
447 VariableRef r = x.getVariableRef();
448 setVariable( r.sName, getVariable( r.sName, r.sid ) / y, r.sid );
449 } 445 }
450 break; 446 break;
451 447
452 case AstNode::tMultiplyStore: 448 case AstNode::tMultiplyStore:
453 { 449 {
454 Variable y = popDeref(); 450 Variable y = popDeref();
455 Variable x = pop(); 451 deref( lStack.peek(), true ) *= y;
456 VariableRef r = x.getVariableRef();
457 setVariable( r.sName, getVariable( r.sName, r.sid ) * y, r.sid );
458 } 452 }
459 break; 453 break;
460 454
diff --git a/src/variable.cpp b/src/variable.cpp
index 2ea8334..68a1778 100644
--- a/src/variable.cpp
+++ b/src/variable.cpp
@@ -417,7 +417,7 @@ Variable &Variable::operator-=( const Variable &rhs )
417 break; 417 break;
418 418
419 default: 419 default:
420 throw VariableException("Int += invalid..."); 420 throw VariableException("Int -= invalid...");
421 } 421 }
422 break; 422 break;
423 423
@@ -445,10 +445,146 @@ Variable &Variable::operator-=( const Variable &rhs )
445 return *this; 445 return *this;
446} 446}
447 447
448/* 448Variable &Variable::operator*=( const Variable &rhs )
449Variable &Variable::operator*=( const Variable &rhs ); 449{
450Variable &Variable::operator/=( const Variable &rhs ); 450 switch( eType )
451*/ 451 {
452 case tNull:
453 throw VariableException("You cannot multiply nulls.");
454
455 case tBool:
456 throw VariableException("You cannot multiply bools.");
457
458 case tInt:
459 switch( rhs.eType )
460 {
461 case tInt:
462 iValue *= rhs.iValue;
463 break;
464
465 case tFloat:
466 {
467 double dTmp = iValue;
468 eType = tFloat;
469 fValue = dTmp * rhs.fValue;
470 }
471 break;
472
473 default:
474 throw VariableException("Int *= invalid...");
475 }
476 break;
477
478 case tFloat:
479 switch( rhs.eType )
480 {
481 case tInt:
482 fValue *= rhs.iValue;
483 break;
484
485 case tFloat:
486 fValue *= rhs.fValue;
487 break;
488
489 default:
490 throw VariableException("Int *= invalid...");
491 }
492 break;
493
494 case tString:
495 throw VariableException("You cannot multiply strings.");
496 break;
497
498 case tSituation:
499 throw VariableException("You cannot multiply situations.");
500 break;
501
502 case tVariable:
503 throw VariableException("You cannot multiply variable names.");
504 break;
505
506 case tList:
507 throw VariableException("You cannot multiply lists.");
508 break;
509
510 case tDictionary:
511 throw VariableException("You cannot multiply dictionaries.");
512 break;
513 }
514
515 return *this;
516}
517
518Variable &Variable::operator/=( const Variable &rhs )
519{
520 switch( eType )
521 {
522 case tNull:
523 throw VariableException("You cannot divide nulls.");
524
525 case tBool:
526 throw VariableException("You cannot divide bools.");
527
528 case tInt:
529 switch( rhs.eType )
530 {
531 case tInt:
532 iValue /= rhs.iValue;
533 break;
534
535 case tFloat:
536 {
537 double dTmp = iValue;
538 eType = tFloat;
539 fValue = dTmp / rhs.fValue;
540 }
541 break;
542
543 default:
544 throw VariableException("Int /= invalid...");
545 }
546 break;
547
548 case tFloat:
549 switch( rhs.eType )
550 {
551 case tInt:
552 fValue /= rhs.iValue;
553 break;
554
555 case tFloat:
556 fValue /= rhs.fValue;
557 break;
558
559 default:
560 throw VariableException("Int /= invalid...");
561 }
562 break;
563
564 case tString:
565 throw VariableException("You cannot divide strings.");
566 break;
567
568 case tSituation:
569 throw VariableException("You cannot divide situations.");
570 break;
571
572 case tVariable:
573 throw VariableException("You cannot divide variable names.");
574 break;
575
576 case tList:
577 throw VariableException("You cannot divide lists.");
578 break;
579
580 case tDictionary:
581 throw VariableException("You cannot divide dictionaries.");
582 break;
583 }
584
585 return *this;
586}
587
452Variable Variable::operator+( const Variable &rhs ) const 588Variable Variable::operator+( const Variable &rhs ) const
453{ 589{
454 if( eType != rhs.eType ) 590 if( eType != rhs.eType )