Index: trunk/extensions/WikiScripts/i18n/Messages.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | 'wikiscripts-exception-unknownfunction' => 'Trying to use an unnknown built-in function $2 $1', |
40 | 40 | 'wikiscripts-exception-notlist' => 'Trying to append an element to the end of \'\'associated\'\' array $1', |
41 | 41 | 'wikiscripts-exception-appendyield' => 'Trying to use append and yield in the same function $1', |
| 42 | + 'wikiscripts-exception-assocbadmerge' => 'Trying to merge an assoicated array with a non-array $1', |
42 | 43 | |
43 | 44 | 'wikiscripts-exception-notenoughargs-user' => 'Not enough arguments for function $2::$3 $1', |
44 | 45 | 'wikiscripts-exception-nonexistent-module' => 'Call to non-existent module $2 $1', |
Index: trunk/extensions/WikiScripts/interpreter/Data.php |
— | — | @@ -217,21 +217,27 @@ |
218 | 218 | return new WSData( $type, $data ); |
219 | 219 | } |
220 | 220 | |
221 | | - public static function sum( $a, $b ) { |
222 | | - if( $a->type == self::DString || $b->type == self::DString ) |
223 | | - return new WSData( self::DString, $a->toString() . $b->toString() ); |
224 | | - elseif( $a->type == self::DList && $b->type == self::DList ) |
| 221 | + public static function sum( $a, $b, $module, $line ) { |
| 222 | + // Lists |
| 223 | + if( $a->type == self::DList && $b->type == self::DList ) |
225 | 224 | return new WSData( self::DList, array_merge( $a->toList(), $b->toList() ) ); |
226 | 225 | elseif( $a->type == self::DList ) |
227 | 226 | return new WSData( self::DList, array_merge( $a->toList(), array( $b ) ) ); |
228 | 227 | elseif( $b->type == self::DList ) |
229 | 228 | return new WSData( self::DList, array_merge( array( $a ), $b->toList() ) ); |
| 229 | + // Associated arrays |
230 | 230 | elseif( $a->type == self::DAssoc && $b->type == self::DAssoc ) |
231 | 231 | return new WSData( self::DAssoc, array_merge( $a->toAssoc(), $b->toAssoc() ) ); |
232 | | - elseif( $a->type == self::DInt && $b->type == self::DInt ) |
| 232 | + elseif( $a->type == self::DAssoc || $b->type == self::DAssoc ) |
| 233 | + throw new WSUserVisibleException( 'assocbadmerge', $module, $line ); |
| 234 | + // Strings |
| 235 | + elseif( $a->type == self::DString || $b->type == self::DString ) |
| 236 | + return new WSData( self::DString, $a->toString() . $b->toString() ); |
| 237 | + // Number, booleans and null |
| 238 | + elseif( $a->type == self::DFloat || $b->type == self::DFloat ) |
| 239 | + return new WSData( self::DFloat, $a->toFloat() + $b->toFloat() ); |
| 240 | + else |
233 | 241 | return new WSData( self::DInt, $a->toInt() + $b->toInt() ); |
234 | | - else |
235 | | - return new WSData( self::DFloat, $a->toFloat() + $b->toFloat() ); |
236 | 242 | } |
237 | 243 | |
238 | 244 | public static function sub( $a, $b ) { |
Index: trunk/extensions/WikiScripts/interpreter/EvaluationContext.php |
— | — | @@ -190,7 +190,12 @@ |
191 | 191 | throw new WSUserVisibleException( 'appendyield', $this->mModuleName, $c[0]->line ); |
192 | 192 | } |
193 | 193 | |
194 | | - $this->mOutput = WSData::sum( $this->mOutput, $this->evaluateNode( $c[1], $rec + 1 ) ); |
| 194 | + $this->mOutput = WSData::sum( |
| 195 | + $this->mOutput, |
| 196 | + $this->evaluateNode( $c[1], $rec + 1 ), |
| 197 | + $this->mModuleName, |
| 198 | + $c[0]->line |
| 199 | + ); |
195 | 200 | break 2; |
196 | 201 | case 'yield': |
197 | 202 | if( $this->mOutput->type != WSData::DNull ) { |
— | — | @@ -255,7 +260,7 @@ |
256 | 261 | $arg2 = $this->evaluateNode( $c[2], $rec + 1 ); |
257 | 262 | switch( $c[1]->value ) { |
258 | 263 | case '+': |
259 | | - return WSData::sum( $arg1, $arg2 ); |
| 264 | + return WSData::sum( $arg1, $arg2, $this->mModuleName, $c[1]->line ); |
260 | 265 | case '-': |
261 | 266 | return WSData::sub( $arg1, $arg2 ); |
262 | 267 | } |
— | — | @@ -573,13 +578,13 @@ |
574 | 579 | protected function getValueForSetting( $old, $new, $set, $line ) { |
575 | 580 | switch( $set ) { |
576 | 581 | case '+=': |
577 | | - return WSData::sum( $old, $new ); |
| 582 | + return WSData::sum( $old, $new, $this->mModuleName, $line ); |
578 | 583 | case '-=': |
579 | 584 | return WSData::sub( $old, $new ); |
580 | 585 | case '*=': |
581 | | - return WSData::mulRel( $old, $new, '*', $line ); |
| 586 | + return WSData::mulRel( $old, $new, '*', $this->mModuleName, $line ); |
582 | 587 | case '/=': |
583 | | - return WSData::mulRel( $old, $new, '/', $line ); |
| 588 | + return WSData::mulRel( $old, $new, '/', $this->mModuleName, $line ); |
584 | 589 | default: |
585 | 590 | return $new; |
586 | 591 | } |
Index: trunk/extensions/WikiScripts/interpreterTests.txt |
— | — | @@ -81,6 +81,8 @@ |
82 | 82 | a = 2; |
83 | 83 | a += 3; |
84 | 84 | a -= 7; |
| 85 | + a *= 3; |
| 86 | + a /= 5; |
85 | 87 | return a; |
86 | 88 | } |
87 | 89 | !! endarticle |
— | — | @@ -90,7 +92,7 @@ |
91 | 93 | !! input |
92 | 94 | {{i:Assigment with arithmetics|run}} |
93 | 95 | !! result |
94 | | -<p>-2 |
| 96 | +<p>-1.2 |
95 | 97 | </p> |
96 | 98 | !! end |
97 | 99 | |