« blib/lib/SPVM/Document/Language/GarbageCollection.pm
↑ Summary
blib/lib/SPVM/Document/Language/Statements.pm »
| 1 | =encoding utf8 | ||
| 2 | |||
| 3 | =head1 Name | ||
| 4 | |||
| 5 | SPVM::Document::Language::Operators - Operators in the SPVM Language | ||
| 6 | |||
| 7 | =head1 Description | ||
| 8 | |||
| 9 | This document describes operators in the SPVM language. | ||
| 10 | |||
| 11 | =head1 Operators | ||
| 12 | |||
| 13 | An operator is a basic instruction that normally a return value. | ||
| 14 | |||
| 15 | =head2 Numeric Operators | ||
| 16 | |||
| 17 | =head3 Unary Plus Operator | ||
| 18 | |||
| 19 | The unary plus operator C<+> is a unary operator that returns its operand. | ||
| 20 | |||
| 21 | +OPERAND | ||
| 22 | |||
| 23 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on the operand I<OPERAND>, and returns it. | ||
| 24 | |||
| 25 | The return type is the type after the conversion is performed. | ||
| 26 | |||
| 27 | Compilation Errors: | ||
| 28 | |||
| 29 | The type of I<OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 30 | |||
| 31 | Examples: | ||
| 32 | |||
| 33 | # Examples of the unary plus operator | ||
| 34 | my $num = +10; | ||
| 35 | |||
| 36 | =head3 Unary Minus Operator | ||
| 37 | |||
| 38 | The unary minus operator C<-> is a unary operator that returns the negated value of its operand. | ||
| 39 | |||
| 40 | -OPERAND | ||
| 41 | |||
| 42 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on the operand I<OPERAND>, negates it, and returns it. | ||
| 43 | |||
| 44 | The return type is the type after the conversion is performed. | ||
| 45 | |||
| 46 | Compilation Errors: | ||
| 47 | |||
| 48 | The type of I<OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 49 | |||
| 50 | Examples: | ||
| 51 | |||
| 52 | # Examples of the unary minus operator | ||
| 53 | my $num = -10; | ||
| 54 | |||
| 55 | =head3 Addition Operator | ||
| 56 | |||
| 57 | The addition operator C<+> adds two operands. | ||
| 58 | |||
| 59 | LEFT_OPERAND + RIGHT_OPERAND | ||
| 60 | |||
| 61 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 62 | |||
| 63 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 64 | |||
| 65 | LEFT_OPERAND + RIGHT_OPERAND | ||
| 66 | |||
| 67 | The return type is the type after L<binary numeric conversion|/"Binary Numeric Conversion"> is performed. | ||
| 68 | |||
| 69 | Compilation Errors: | ||
| 70 | |||
| 71 | The type of I<LEFT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 72 | |||
| 73 | The type of I<RIGHT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 74 | |||
| 75 | Examples: | ||
| 76 | |||
| 77 | # Examples of addition operator | ||
| 78 | my $result = 1 + 2; | ||
| 79 | |||
| 80 | =head3 Subtraction Operator | ||
| 81 | |||
| 82 | The subtraction operator C<-> subtracts its right operand from its left operand. | ||
| 83 | |||
| 84 | LEFT_OPERAND - RIGHT_OPERAND | ||
| 85 | |||
| 86 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 87 | |||
| 88 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 89 | |||
| 90 | LEFT_OPERAND - RIGHT_OPERAND | ||
| 91 | |||
| 92 | The return type is the type after L<binary numeric conversion|/"Binary Numeric Conversion"> is performed. | ||
| 93 | |||
| 94 | Compilation Errors: | ||
| 95 | |||
| 96 | The type of I<LEFT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 97 | |||
| 98 | The type of I<RIGHT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 99 | |||
| 100 | Examples: | ||
| 101 | |||
| 102 | # Examples of subtraction operator | ||
| 103 | my $result = 1 - 2; | ||
| 104 | |||
| 105 | =head3 Multiplication Operator | ||
| 106 | |||
| 107 | The multiplication operator C<*> multiplies two operands. | ||
| 108 | |||
| 109 | LEFT_OPERAND * RIGHT_OPERAND | ||
| 110 | |||
| 111 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 112 | |||
| 113 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 114 | |||
| 115 | LEFT_OPERAND * RIGHT_OPERAND | ||
| 116 | |||
| 117 | The return type is the type after L<binary numeric conversion|/"Binary Numeric Conversion"> is performed. | ||
| 118 | |||
| 119 | Compilation Errors: | ||
| 120 | |||
| 121 | The type of I<LEFT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 122 | |||
| 123 | The type of I<RIGHT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 124 | |||
| 125 | Examples: | ||
| 126 | |||
| 127 | # Examples of multiplication operator | ||
| 128 | my $result = 1 * 2; | ||
| 129 | |||
| 130 | =head3 Division Operator | ||
| 131 | |||
| 132 | The division operator C</> divides its left operand by its right operand. | ||
| 133 | |||
| 134 | LEFT_OPERAND / RIGHT_OPERAND | ||
| 135 | |||
| 136 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 137 | |||
| 138 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 139 | |||
| 140 | LEFT_OPERAND / RIGHT_OPERAND | ||
| 141 | |||
| 142 | The return type is the type after L<binary numeric conversion|/"Binary Numeric Conversion"> is performed. | ||
| 143 | |||
| 144 | Exceptions: | ||
| 145 | |||
| 146 | If the left operand type I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND> are an integer type and I<RIGHT_OPERAND> is 0, an exception is thrown. | ||
| 147 | |||
| 148 | Compilation Errors: | ||
| 149 | |||
| 150 | The type of I<LEFT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 151 | |||
| 152 | The type of I<RIGHT_OPERAND> must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. Otherwise, a compilation error occurs. | ||
| 153 | |||
| 154 | Examples: | ||
| 155 | |||
| 156 | # Examples of division operator | ||
| 157 | my $result = 1 / 2; | ||
| 158 | |||
| 159 | =head3 Division Unsigned Int Operator | ||
| 160 | |||
| 161 | The division unsigned int operator C<div_uint> interprets its two operands as unsigned 32bit integers, and divides its left operand by its right operand. | ||
| 162 | |||
| 163 | LEFT_OPERAND div_uint RIGHT_OPERAND | ||
| 164 | |||
| 165 | This operator performs the same operation as the following C language operation, and returns its return value. | ||
| 166 | |||
| 167 | (uint32_t)LEFT_OPERAND / (uint32_t)RIGHT_OPERAND | ||
| 168 | |||
| 169 | The return type is int type. | ||
| 170 | |||
| 171 | Exceptions: | ||
| 172 | |||
| 173 | If I<RIGHT_OPERAND> is 0, an exception is thrown. | ||
| 174 | |||
| 175 | Compilation Errors: | ||
| 176 | |||
| 177 | The type of I<LEFT_OPERAND> must be int type. Otherwise, a compilation error occurs. | ||
| 178 | |||
| 179 | The type of I<RIGHT_OPERAND> must be int type. Otherwise, a compilation error occurs. | ||
| 180 | |||
| 181 | Examples: | ||
| 182 | |||
| 183 | # Examples of the division unsigned int operator | ||
| 184 | my $result = 1 div_uint 2; | ||
| 185 | |||
| 186 | =head3 Division Unsigned Long Operator | ||
| 187 | |||
| 188 | The division unsigned long operator C<div_ulong> interprets its two operands as unsigned 64bit integers, and divides its left operand by its right operand. | ||
| 189 | |||
| 190 | LEFT_OPERAND div_ulong RIGHT_OPERAND | ||
| 191 | |||
| 192 | This operator performs the same operation as the following C language operation, and returns its return value. | ||
| 193 | |||
| 194 | (uint64_t)LEFT_OPERAND / (uint64_t)RIGHT_OPERAND | ||
| 195 | |||
| 196 | The return type is long type. | ||
| 197 | |||
| 198 | Exceptions: | ||
| 199 | |||
| 200 | If I<RIGHT_OPERAND> is 0, an exception is thrown. | ||
| 201 | |||
| 202 | Compilation Errors: | ||
| 203 | |||
| 204 | The type of I<LEFT_OPERAND> must be long type. Otherwise, a compilation error occurs. | ||
| 205 | |||
| 206 | The type of I<RIGHT_OPERAND> must be long type. Otherwise, a compilation error occurs. | ||
| 207 | |||
| 208 | Examples: | ||
| 209 | |||
| 210 | # Examples of the division unsigned long operator | ||
| 211 | my $result = 1L div_ulong 2L; | ||
| 212 | |||
| 213 | =head3 Modulo Operator | ||
| 214 | |||
| 215 | The modulo operator C<%> calculates the modulo of the division of its two operands. | ||
| 216 | |||
| 217 | LEFT_OPERAND % RIGHT_OPERAND | ||
| 218 | |||
| 219 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 220 | |||
| 221 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 222 | |||
| 223 | RETURN_VALUE = LEFT_OPERAND % RIGHT_OPERAND; | ||
| 224 | if ((LEFT_OPERAND < 0) != (RIGHT_OPERAND < 0) && RETURN_VALUE) { RETURN_VALUE += RIGHT_OPERAND; } | ||
| 225 | |||
| 226 | The return type is the type after L<binary numeric conversion|/"Binary Numeric Conversion"> is performed. | ||
| 227 | |||
| 228 | Exceptions: | ||
| 229 | |||
| 230 | If I<RIGHT_OPERAND> is 0, an exception is thrown. | ||
| 231 | |||
| 232 | Compilation Errors: | ||
| 233 | |||
| 234 | The type of I<LEFT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 235 | |||
| 236 | The type of I<RIGHT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 237 | |||
| 238 | Examples: | ||
| 239 | |||
| 240 | # Examples of modulo operator | ||
| 241 | my $result = 1 % 2; | ||
| 242 | |||
| 243 | =head3 Modulo Unsigned Int Operator | ||
| 244 | |||
| 245 | The modulo unsigned int operator C<mod_uint> interprets its two operands as unsigned 32bit integers, and calculates the modulo of the division of its two operands. | ||
| 246 | |||
| 247 | LEFT_OPERAND mod_uint RIGHT_OPERAND | ||
| 248 | |||
| 249 | This operator performs the same operation as the following C language operation, and returns its return value. | ||
| 250 | |||
| 251 | (uint32_t)LEFT_OPERAND % (uint32_t)RIGHT_OPERAND | ||
| 252 | |||
| 253 | The return type is int type. | ||
| 254 | |||
| 255 | Exceptions: | ||
| 256 | |||
| 257 | If I<RIGHT_OPERAND> is 0, an exception is thrown. | ||
| 258 | |||
| 259 | Compilation Errors: | ||
| 260 | |||
| 261 | The type of I<LEFT_OPERAND> must be int type. Otherwise, a compilation error occurs. | ||
| 262 | |||
| 263 | The type of I<RIGHT_OPERAND> must be int type. Otherwise, a compilation error occurs. | ||
| 264 | |||
| 265 | Examples: | ||
| 266 | |||
| 267 | # Examples of the modulo unsigned int operator | ||
| 268 | my $result = 1 mod_uint 2; | ||
| 269 | |||
| 270 | =head3 Modulo Unsigned Long Operator | ||
| 271 | |||
| 272 | The modulo unsigned long operator C<mod_ulong> interprets its two operands as unsigned 64bit integers, and calculates the modulo of the division of its two operands. | ||
| 273 | |||
| 274 | LEFT_OPERAND mod_ulong RIGHT_OPERAND | ||
| 275 | |||
| 276 | This operator performs the same operation as the following C language operation, and returns its return value. | ||
| 277 | |||
| 278 | (uint64_t)LEFT_OPERAND % (uint64_t)RIGHT_OPERAND | ||
| 279 | |||
| 280 | The return type is is long type. | ||
| 281 | |||
| 282 | Exceptions: | ||
| 283 | |||
| 284 | If I<RIGHT_OPERAND> is 0, an exception is thrown. | ||
| 285 | |||
| 286 | Compilation Errors: | ||
| 287 | |||
| 288 | The type of I<LEFT_OPERAND> must be long type. Otherwise, a compilation error occurs. | ||
| 289 | |||
| 290 | The type of I<RIGHT_OPERAND> must be long type. Otherwise, a compilation error occurs. | ||
| 291 | |||
| 292 | Examples: | ||
| 293 | |||
| 294 | # Examples of the modulo unsigned long operator | ||
| 295 | my $result = 1L mod_ulong 2L; | ||
| 296 | |||
| 297 | =head3 Increment Operators | ||
| 298 | |||
| 299 | =head4 Pre-Increment Operator | ||
| 300 | |||
| 301 | The pre-increment operator C<++> increases the value of an operand by 1, and returns it. | ||
| 302 | |||
| 303 | ++OPERAND | ||
| 304 | |||
| 305 | This operator increases the value of the operand I<OPERAND> by 1 using L<additonal operator|/"Addition Operator">, performs a L<type cast|/"Type Cast"> to the type of I<OPERAND> on it, and returns it. | ||
| 306 | |||
| 307 | The return type is the type of I<OPERAND>. | ||
| 308 | |||
| 309 | Compilation Errors: | ||
| 310 | |||
| 311 | I<OPERAND> must be a local variable, a class variable, a field access, an element access, a dereference. Otherwise, a compilation error occurs. | ||
| 312 | |||
| 313 | The type of I<OPERAND> must be a numeric type. Otherwise, a compilation error occurs. | ||
| 314 | |||
| 315 | Examples: | ||
| 316 | |||
| 317 | # Examples of the pre-increment operator | ||
| 318 | |||
| 319 | # A local variable | ||
| 320 | ++$num; | ||
| 321 | |||
| 322 | # A class variable | ||
| 323 | ++$NUM; | ||
| 324 | |||
| 325 | # A field access | ||
| 326 | ++$point->{x}; | ||
| 327 | |||
| 328 | # An element access | ||
| 329 | ++$nums->[0]; | ||
| 330 | |||
| 331 | # A dereference | ||
| 332 | ++$$num_ref; | ||
| 333 | |||
| 334 | =head4 Post-Increment Operator | ||
| 335 | |||
| 336 | The post-increment operator C<++> increases the value of an operand by 1, and returns the value before performing the incrementation. | ||
| 337 | |||
| 338 | OPERAND++ | ||
| 339 | |||
| 340 | This operator increases the value of the operand I<OPERAND> by 1 using L<additonal operator|/"Addition Operator">, performs a L<type cast|/"Type Cast"> to the type of I<OPERAND> on it, assigns it on I<OPERAND>, and returns I<OPERAND> before performing the incrementation. | ||
| 341 | |||
| 342 | The return type is the type of I<OPERAND>. | ||
| 343 | |||
| 344 | Compilation Errors: | ||
| 345 | |||
| 346 | I<OPERAND> must be a local variable, a class variable, a field access, an element access, a dereference. Otherwise, a compilation error occurs. | ||
| 347 | |||
| 348 | The type of I<OPERAND> must be a numeric type. Otherwise, a compilation error occurs. | ||
| 349 | |||
| 350 | Examples: | ||
| 351 | |||
| 352 | # Examples of the post-increment operator | ||
| 353 | |||
| 354 | # A local variable | ||
| 355 | $num++; | ||
| 356 | |||
| 357 | # A class variable | ||
| 358 | $NUM++; | ||
| 359 | |||
| 360 | # A field access | ||
| 361 | $point->{x}++; | ||
| 362 | |||
| 363 | # An element access | ||
| 364 | $nums->[0]++; | ||
| 365 | |||
| 366 | # A dereference | ||
| 367 | $$num_ref++; | ||
| 368 | |||
| 369 | =head3 Decrement Operators | ||
| 370 | |||
| 371 | =head4 Pre-Decrement Operator | ||
| 372 | |||
| 373 | The pre-decrement operator C<--> decreases the value of an operand by 1, and returns it. | ||
| 374 | |||
| 375 | --OPERAND | ||
| 376 | |||
| 377 | This operator decreases the value of the operand I<OPERAND> by 1 using L<subtraction operator|/"Subtraction Operator">, performs a L<type cast|/"Type Cast"> to the type of I<OPERAND> on it, and returns it. | ||
| 378 | |||
| 379 | The return type is the type of I<OPERAND>. | ||
| 380 | |||
| 381 | Complation Errors: | ||
| 382 | |||
| 383 | I<OPERAND> must be a local variable, a class variable, a field access, an element access, a dereference. Otherwise, a compilation error occurs. | ||
| 384 | |||
| 385 | The type of I<OPERAND> must be a numeric type. Otherwise, a compilation error occurs. | ||
| 386 | |||
| 387 | Examples: | ||
| 388 | |||
| 389 | # Examples of the pre-decrement operator | ||
| 390 | |||
| 391 | # A local variable | ||
| 392 | --$num; | ||
| 393 | |||
| 394 | # A class variable | ||
| 395 | --$NUM; | ||
| 396 | |||
| 397 | # A field access | ||
| 398 | --$point->{x}; | ||
| 399 | |||
| 400 | # An element access | ||
| 401 | --$nums->[0]; | ||
| 402 | |||
| 403 | # A dereferenced value | ||
| 404 | --$$num_ref; | ||
| 405 | |||
| 406 | =head4 Post-Decrement Operator | ||
| 407 | |||
| 408 | The post-increment operator C<--> decreases the value of an operand by 1, and returns the value before performing the decrementation. | ||
| 409 | |||
| 410 | OPERAND-- | ||
| 411 | |||
| 412 | This operator decreases the value of the operand I<OPERAND> by 1 using L<subtraction operator|/"Subtraction Operator">, performs a L<type cast|/"Type Cast"> to the type of I<OPERAND> on it, assigns it on I<OPERAND>, and returns I<OPERAND> before performing the decrementation. | ||
| 413 | |||
| 414 | The return type is the type of I<OPERAND>. | ||
| 415 | |||
| 416 | Compilation Errors: | ||
| 417 | |||
| 418 | I<OPERAND> must be a local variable, a class variable, a field access, an element access, a dereference. Otherwise, a compilation error occurs. | ||
| 419 | |||
| 420 | The type of I<OPERAND> must be a numeric type. Otherwise, a compilation error occurs. | ||
| 421 | |||
| 422 | Examples: | ||
| 423 | |||
| 424 | # Examples of the post-decrement operator | ||
| 425 | |||
| 426 | # A local variable | ||
| 427 | $num--; | ||
| 428 | |||
| 429 | # A class variable | ||
| 430 | $NUM--; | ||
| 431 | |||
| 432 | # A field access | ||
| 433 | $point->{x}--; | ||
| 434 | |||
| 435 | # An element access | ||
| 436 | $nums->[0]--; | ||
| 437 | |||
| 438 | # A dereference | ||
| 439 | $$num_ref--; | ||
| 440 | |||
| 441 | =head3 Bitwise Operators | ||
| 442 | |||
| 443 | =head4 Bitwise AND Operator | ||
| 444 | |||
| 445 | The bitwise AND operator C<&> performs L<bitwise AND operation|https://en.wikipedia.org/wiki/Bitwise_operation#AND>. | ||
| 446 | |||
| 447 | LEFT_OPERAND & RIGHT_OPERAND | ||
| 448 | |||
| 449 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 450 | |||
| 451 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 452 | |||
| 453 | LEFT_OPERAND & RIGHT_OPERAND | ||
| 454 | |||
| 455 | The return type is the type after L<binary numeric conversion|/"Binary Numeric Conversion"> is performed. | ||
| 456 | |||
| 457 | Compilation Errors: | ||
| 458 | |||
| 459 | The type of I<LEFT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 460 | |||
| 461 | The type of I<RIGHT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 462 | |||
| 463 | Examples: | ||
| 464 | |||
| 465 | # Examples of bitwise AND operator | ||
| 466 | my $num1 = 0xff; | ||
| 467 | my $num2 = 0x12; | ||
| 468 | my $result = $num1 & $num2; | ||
| 469 | |||
| 470 | =head4 Bitwise OR Operator | ||
| 471 | |||
| 472 | The bitwise OR operator C<|> performs L<bitwise OR operation|https://en.wikipedia.org/wiki/Bitwise_operation#OR>. | ||
| 473 | |||
| 474 | LEFT_OPERAND | RIGHT_OPERAND | ||
| 475 | |||
| 476 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 477 | |||
| 478 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 479 | |||
| 480 | LEFT_OPERAND | RIGHT_OPERAND | ||
| 481 | |||
| 482 | The return type is the type after L<binary numeric conversion|/"Binary Numeric Conversion"> is performed. | ||
| 483 | |||
| 484 | Compilation Errors: | ||
| 485 | |||
| 486 | The type of I<LEFT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 487 | |||
| 488 | The type of I<RIGHT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 489 | |||
| 490 | Examples: | ||
| 491 | |||
| 492 | # Examples of the bitwise OR operator | ||
| 493 | my $num1 = 0xff; | ||
| 494 | my $num2 = 0x12; | ||
| 495 | my $result = $num1 | $num2; | ||
| 496 | |||
| 497 | =head4 Bitwise NOT Operator | ||
| 498 | |||
| 499 | The bitwise NOT operator C<~> performs L<bitwise NOT operation|https://en.wikipedia.org/wiki/Bitwise_operation#NOT>. | ||
| 500 | |||
| 501 | ~OPERAND | ||
| 502 | |||
| 503 | This operator performs L<numeric widening conversion|/"Numeric Widening Conversion"> on the operand I<OPERAND>. | ||
| 504 | |||
| 505 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 506 | |||
| 507 | ~OPERAND | ||
| 508 | |||
| 509 | The return type is the type that L<numeric widening conversion|/"Numeric Widening Conversion"> is performed. | ||
| 510 | |||
| 511 | Compilation Errors: | ||
| 512 | |||
| 513 | The type of I<OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 514 | |||
| 515 | Examples: | ||
| 516 | |||
| 517 | # Examples of bitwise NOT operator | ||
| 518 | my $result = ~0xFF0A; | ||
| 519 | |||
| 520 | =head3 Shift Operators | ||
| 521 | |||
| 522 | =head4 Left Shift Operator | ||
| 523 | |||
| 524 | The left shift operator C<E<lt>E<lt>> performs L<arithmetic left shift|https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift>. | ||
| 525 | |||
| 526 | LEFT_OPERAND << RIGHT_OPERAND | ||
| 527 | |||
| 528 | This operator performs L<numeric widening conversion|/"Numeric Widening Conversion"> on the left operand I<LEFT_OPERAND>. | ||
| 529 | |||
| 530 | And it performs L<numeric widening conversion|/"Numeric Widening Conversion"> on the right operand I<RIGHT_OPERAND>. | ||
| 531 | |||
| 532 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 533 | |||
| 534 | LEFT_OPERAND << RIGHT_OPERAND | ||
| 535 | |||
| 536 | The return type is the type of I<LEFT_OPERAND>. | ||
| 537 | |||
| 538 | Compilation Erorrs: | ||
| 539 | |||
| 540 | The type of I<LEFT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 541 | |||
| 542 | The type of I<RIGHT_OPERAND> must be an L<integer types|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 543 | |||
| 544 | Examples: | ||
| 545 | |||
| 546 | # Examples of left shift operator | ||
| 547 | my $result = 0xFF0A << 3; | ||
| 548 | |||
| 549 | =head4 Arithmetic Right Shift Operator | ||
| 550 | |||
| 551 | The arithmetic right shift operator C<E<gt>E<gt>> performs L<arithmetic right shift|https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shift>. | ||
| 552 | |||
| 553 | LEFT_OPERAND >> RIGHT_OPERAND | ||
| 554 | |||
| 555 | This operator performs L<numeric widening conversion|/"Numeric Widening Conversion"> on the left operand I<LEFT_OPERAND>. | ||
| 556 | |||
| 557 | And it performs L<numeric widening conversion|/"Numeric Widening Conversion"> on the right operand I<RIGHT_OPERAND>. | ||
| 558 | |||
| 559 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 560 | |||
| 561 | LEFT_OPERAND >> RIGHT_OPERAND; | ||
| 562 | |||
| 563 | The return type is the type of I<LEFT_OPERAND>. | ||
| 564 | |||
| 565 | Compilation Errors: | ||
| 566 | |||
| 567 | The type of I<LEFT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 568 | |||
| 569 | The type of I<RIGHT_OPERAND> must be an L<integer types|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 570 | |||
| 571 | Examples: | ||
| 572 | |||
| 573 | # Examples of arithmetic right shift operator | ||
| 574 | my $result = 0xFF0A >> 3; | ||
| 575 | |||
| 576 | =head4 Logical Right Shift Operator | ||
| 577 | |||
| 578 | The logical right shift operator C<E<gt>E<gt>E<gt>> performs L<logical right shift|https://en.wikipedia.org/wiki/Bitwise_operation#Logical_shift>. | ||
| 579 | |||
| 580 | LEFT_OPERAND >>> RIGHT_OPERAND | ||
| 581 | |||
| 582 | This operator performs L<numeric widening conversion|/"Numeric Widening Conversion"> on the left operand I<LEFT_OPERAND>. | ||
| 583 | |||
| 584 | And it performs L<numeric widening conversion|/"Numeric Widening Conversion"> on the right operand I<RIGHT_OPERAND>. | ||
| 585 | |||
| 586 | And if the type of I<LEFT_OPERAND> is int type, it performs the same operation as the following C language operation | ||
| 587 | |||
| 588 | (uint32_t)LEFT_OPERAND >> RIGHT_OPERAND | ||
| 589 | |||
| 590 | If the type of I<LEFT_OPERAND> is long type, it performs the same operation as the following C language operation. | ||
| 591 | |||
| 592 | (uint64_t)LEFT_OPERAND >> RIGHT_OPERAND | ||
| 593 | |||
| 594 | And returns its return value. | ||
| 595 | |||
| 596 | The return type is the type of I<LEFT_OPERAND>. | ||
| 597 | |||
| 598 | Compilation Errors: | ||
| 599 | |||
| 600 | The type of I<LEFT_OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types">. Otherwise, a compilation error occurs. | ||
| 601 | |||
| 602 | The type of I<RIGHT_OPERAND> must be an L<integer types|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 603 | |||
| 604 | Examples: | ||
| 605 | |||
| 606 | # Examples of logical right shift operator | ||
| 607 | my $result = 0xFF0A >>> 3; | ||
| 608 | |||
| 609 | =head2 Logical Operators | ||
| 610 | |||
| 611 | =head3 Logical AND Operator | ||
| 612 | |||
| 613 | The logical AND operator C<&&> performs a logical AND operation. | ||
| 614 | |||
| 615 | LEFT_OPERAND && RIGHT_OPERAND | ||
| 616 | |||
| 617 | This operator performs L<condition evaluation|/"Condition Evaluation"> on the left operand I<LEFT_OPERAND>. | ||
| 618 | |||
| 619 | If the evaluated value is 0, it returns 0. Otherwise, performs L<condition evaluation|/"Condition Evaluation"> on the right operand I<RIGHT_OPERAND>. | ||
| 620 | |||
| 621 | And it returns the evaluated value of I<RIGHT_OPERAND>. | ||
| 622 | |||
| 623 | The return type is int type. | ||
| 624 | |||
| 625 | Examples: | ||
| 626 | |||
| 627 | # Examples of logical AND operator | ||
| 628 | if (1 && 0) { | ||
| 629 | |||
| 630 | } | ||
| 631 | |||
| 632 | =head3 Logical OR Operator | ||
| 633 | |||
| 634 | The logical OR operator C<||> performes a logical OR operation. | ||
| 635 | |||
| 636 | # logical OR operator | ||
| 637 | LEFT_OPERAND || RIGHT_OPERAND | ||
| 638 | |||
| 639 | Thg logical OR operator performs L<condition evaluation|/"Condition Evaluation"> on the left operand I<LEFT_OPERAND>. | ||
| 640 | |||
| 641 | If the evaluated value is not 0, it returns the evaluated value. Otherwise, performs L<condition evaluation|/"Condition Evaluation"> on the right operand I<RIGHT_OPERAND>. | ||
| 642 | |||
| 643 | And it returns the evaluated value of I<RIGHT_OPERAND>. | ||
| 644 | |||
| 645 | The return type is int type. | ||
| 646 | |||
| 647 | Examples: | ||
| 648 | |||
| 649 | # Examples of logical OR operator | ||
| 650 | if (1 || 0) { | ||
| 651 | |||
| 652 | } | ||
| 653 | |||
| 654 | =head3 Logical NOT Operator | ||
| 655 | |||
| 656 | The logical NOT operator C<!> performes a logical NOT operation. | ||
| 657 | |||
| 658 | !OPERAND | ||
| 659 | |||
| 660 | Thg logical NOT operator performs L<condition evaluation|/"Condition Evaluation"> on the operand I<OPERAND>. | ||
| 661 | |||
| 662 | If the evaluated value is 0, returns 1, otherwise returns 0. | ||
| 663 | |||
| 664 | The return type is int type. | ||
| 665 | |||
| 666 | # Examples of logical NOT operator | ||
| 667 | if (!1) { | ||
| 668 | |||
| 669 | } | ||
| 670 | |||
| 671 | =head2 Defined-OR Operator | ||
| 672 | |||
| 673 | The defined-OR operator C<//> performes a defined-OR operation. | ||
| 674 | |||
| 675 | # defined-OR operator | ||
| 676 | LEFT_OPERAND // RIGHT_OPERAND | ||
| 677 | |||
| 678 | Thg defined-OR operator performs L<condition evaluation|/"Condition Evaluation"> on the left operand I<LEFT_OPERAND>. | ||
| 679 | |||
| 680 | If the evaluated value is not 0, it returns the evaluated value. Otherwise, returns I<RIGHT_OPERAND>. | ||
| 681 | |||
| 682 | The return type is the type of I<LEFT_OPERAND>. | ||
| 683 | |||
| 684 | Compilation Errors: | ||
| 685 | |||
| 686 | The left operand type of defined-or operator // must be an object type. Otherwise, an compication error occurs. | ||
| 687 | |||
| 688 | Examples: | ||
| 689 | |||
| 690 | # Examples of defined-OR operator | ||
| 691 | my $value = "foo"; | ||
| 692 | my $default = "default"; | ||
| 693 | my $ret = $value // $default; | ||
| 694 | |||
| 695 | =head2 Ternary Operator | ||
| 696 | |||
| 697 | The ternary operator performes a ternary operation. | ||
| 698 | |||
| 699 | # ternary operator | ||
| 700 | CONDITION ? LEFT_OPERAND : RIGHT_OPERAND | ||
| 701 | |||
| 702 | The type of I<LEFT_OPERAND> and I<RIGHT_OPERAND> must satisfy assignment requrement to any object type. | ||
| 703 | |||
| 704 | I<CONDITION> is evaluated by L<condition evaluation|/"Condition Evaluation">. | ||
| 705 | |||
| 706 | If the evaluated value is not 0, it returns I<LEFT_OPERAND>. Otherwise, returns I<RIGHT_OPERAND>. | ||
| 707 | |||
| 708 | The return type is the type of I<LEFT_OPERAND>. | ||
| 709 | |||
| 710 | Compilation Errors: | ||
| 711 | |||
| 712 | |||
| 713 | |||
| 714 | Examples: | ||
| 715 | |||
| 716 | # Examples of ternary operator | ||
| 717 | my $flag = 1; | ||
| 718 | my $left = "foo"; | ||
| 719 | my $right = "default"; | ||
| 720 | my $ret = $flag ? $left : $right; | ||
| 721 | |||
| 722 | =head2 Condition Evaluation | ||
| 723 | |||
| 724 | The condition evaluation is the operation performed on the operand at a conditional part of L<if statement|SPVM::Document::Language::Statements/"if Statement">, L<while statement|SPVM::Document::Language::Statements/"while Statement">, and L<logical operators|/"Logical Operators">. | ||
| 725 | |||
| 726 | The condition evaluation performs the following operations corresponding to the operand type. | ||
| 727 | |||
| 728 | The return type is int type. | ||
| 729 | |||
| 730 | B<byte:> | ||
| 731 | |||
| 732 | B<short:> | ||
| 733 | |||
| 734 | B<int:> | ||
| 735 | |||
| 736 | The L<integer promotional conversion|/"Integer Promotional Conversion"> is performed on the operand. | ||
| 737 | |||
| 738 | And return the value after conversion. | ||
| 739 | |||
| 740 | B<undef:> | ||
| 741 | |||
| 742 | Returns 0. | ||
| 743 | |||
| 744 | B<BOOL:> | ||
| 745 | |||
| 746 | Return the C<value> field in L<Bool|SPVM::Bool> object. | ||
| 747 | |||
| 748 | B<long:> | ||
| 749 | |||
| 750 | B<float:> | ||
| 751 | |||
| 752 | B<double:> | ||
| 753 | |||
| 754 | B<a reference type:> | ||
| 755 | |||
| 756 | Performs the following C language operation, and returns it. | ||
| 757 | |||
| 758 | !!OPERAND | ||
| 759 | |||
| 760 | B<an object type:> | ||
| 761 | |||
| 762 | If the compile type of the operand is not L<Bool|SPVM::Bool> class, performs the following C language operation, and returns it. | ||
| 763 | |||
| 764 | !!OPERAND | ||
| 765 | |||
| 766 | Compilation Errors: | ||
| 767 | |||
| 768 | The operand type of the condition evaluation must be a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">, an L<object type|SPVM::Document::Language::Types/"Object Types">, a L<reference type|SPVM::Document::Language::Types/"Reference Types">, or L<undef type|SPVM::Document::Language::Types/"undef Type">. Otherwise, a compilation error occurs. | ||
| 769 | |||
| 770 | Examples: | ||
| 771 | |||
| 772 | # Examples of the condition evaluation | ||
| 773 | if (1) { | ||
| 774 | # ok | ||
| 775 | } | ||
| 776 | |||
| 777 | if (0) { | ||
| 778 | # not ok | ||
| 779 | } | ||
| 780 | |||
| 781 | if (1.5) { | ||
| 782 | # ok | ||
| 783 | } | ||
| 784 | |||
| 785 | if (0.0) { | ||
| 786 | # not ok | ||
| 787 | } | ||
| 788 | |||
| 789 | if (true) { | ||
| 790 | # ok | ||
| 791 | } | ||
| 792 | |||
| 793 | if (Bool->TRUE) { | ||
| 794 | # ok | ||
| 795 | } | ||
| 796 | |||
| 797 | if (false) { | ||
| 798 | # not ok | ||
| 799 | } | ||
| 800 | |||
| 801 | if (Bool->FALSE) { | ||
| 802 | # not ok | ||
| 803 | } | ||
| 804 | |||
| 805 | my $object = SPVM::Int->new(1); | ||
| 806 | |||
| 807 | if ($object) { | ||
| 808 | # ok | ||
| 809 | } | ||
| 810 | |||
| 811 | $object = undef; | ||
| 812 | if ($object) { | ||
| 813 | # not ok | ||
| 814 | } | ||
| 815 | |||
| 816 | my $value = 1; | ||
| 817 | my $ref = \$value; | ||
| 818 | |||
| 819 | if ($ref) { | ||
| 820 | # ok | ||
| 821 | } | ||
| 822 | |||
| 823 | if (undef) { | ||
| 824 | # not ok | ||
| 825 | } | ||
| 826 | |||
| 827 | =head2 Array Length Operator | ||
| 828 | |||
| 829 | The array length operator C<@> gets the length of an array. | ||
| 830 | |||
| 831 | @OPERAND | ||
| 832 | @{OPERAND} | ||
| 833 | |||
| 834 | This operator returns the length the array I<OPERAND>. | ||
| 835 | |||
| 836 | The return type is int type. | ||
| 837 | |||
| 838 | If I<OPERAND> is a class type or an interface type, this operation is replaced with C<length> method call of L<Countable|SPVM::Countable> interface. | ||
| 839 | |||
| 840 | OPERAND->length | ||
| 841 | |||
| 842 | Exceptions: | ||
| 843 | |||
| 844 | I<OPERAND> must be defined. Otherwise, an exception is thrown. | ||
| 845 | |||
| 846 | Compilation Errors: | ||
| 847 | |||
| 848 | The type of I<OPERAND> must be an array type or a class with L<Countable|SPVM::Countable> interface. Otherwise, a compilation error occurs. | ||
| 849 | |||
| 850 | Examples: | ||
| 851 | |||
| 852 | # Examples of the array length operator | ||
| 853 | my $nums = new int[10]; | ||
| 854 | my $length = @$nums; | ||
| 855 | |||
| 856 | =head2 scalar Operator | ||
| 857 | |||
| 858 | The C<scalar> operator returns its operand. | ||
| 859 | |||
| 860 | scalar OPERAND | ||
| 861 | |||
| 862 | This operator returns the operand I<OPERAND>. I<OPERAND> must be L<array length operator|/"Array Length Operator">. | ||
| 863 | |||
| 864 | This operator exists only for readability. | ||
| 865 | |||
| 866 | The return type is int type. | ||
| 867 | |||
| 868 | Compilation Errors: | ||
| 869 | |||
| 870 | I<OPERAND> must be L<array length operator|/"Array Length Operator">. Otherwise, a compilation error occurs. | ||
| 871 | |||
| 872 | Examples: | ||
| 873 | |||
| 874 | # Examples of scalar operator | ||
| 875 | my $nums = new int[3]; | ||
| 876 | say scalar @$nums; | ||
| 877 | |||
| 878 | =head2 Sequential Operator | ||
| 879 | |||
| 880 | The sequential operator is an operator with the following syntax. | ||
| 881 | |||
| 882 | (OPERAND1, OPERAND2, ..., OPERANDn) | ||
| 883 | |||
| 884 | This operator evaluates operands C<OPERAND1>, C<OPERAND1> ... C<OPERANDn> from left to right, and returns the value of the rightmost operand C<OPERANDn>. | ||
| 885 | |||
| 886 | The return type is the type of C<OPERANDn>. | ||
| 887 | |||
| 888 | The L<if statement|SPVM::Document::Language::Statements/"if Statement"> C<IF_STATEMENT> can place directory before C<OPERANDn>. | ||
| 889 | |||
| 890 | (OPERAND1, OPERAND2, ..., IF_STATEMENT, OPERANDn) | ||
| 891 | |||
| 892 | Examples: | ||
| 893 | |||
| 894 | # Examples of sequential operator | ||
| 895 | |||
| 896 | # 3 is assigned to $foo | ||
| 897 | my $foo = (1, 2, 3); | ||
| 898 | |||
| 899 | # $x is 3, $ret is 5 | ||
| 900 | my $x = 1; | ||
| 901 | my $y = 2; | ||
| 902 | my $result = ($x += 2, $x + $y); | ||
| 903 | |||
| 904 | # Peseud ternary operator | ||
| 905 | { | ||
| 906 | my $condition = 1; | ||
| 907 | my $ret = (my $_ = 0, if ($condition) { $_ = 3; } else { $_ = 5; }, $_); | ||
| 908 | } | ||
| 909 | |||
| 910 | =head2 Comparison Operators | ||
| 911 | |||
| 912 | Comparison operators compare two operands. | ||
| 913 | |||
| 914 | =head3 Numeric Comparison Operators | ||
| 915 | |||
| 916 | Numeric comparison operators compare two numbers or two addresses of objects. | ||
| 917 | |||
| 918 | LEFT_OPERAND == RIGHT_OPERAND | ||
| 919 | LEFT_OPERAND != RIGHT_OPERAND | ||
| 920 | LEFT_OPERAND > RIGHT_OPERAND | ||
| 921 | LEFT_OPERAND >= RIGHT_OPERAND | ||
| 922 | LEFT_OPERAND < RIGHT_OPERAND | ||
| 923 | LEFT_OPERAND <= RIGHT_OPERAND | ||
| 924 | LEFT_OPERAND <=> RIGHT_OPERAND | ||
| 925 | |||
| 926 | This operator performs L<binary numeric conversion|/"Binary Numeric Conversion"> on the left operand I<LEFT_OPERAND> and the right operand I<RIGHT_OPERAND>. | ||
| 927 | |||
| 928 | And it performs the same operation as the following C language operation, and returns its return value. | ||
| 929 | |||
| 930 | (int32_t)(LEFT_OPERAND == RIGHT_OPERAND); | ||
| 931 | (int32_t)(LEFT_OPERAND != RIGHT_OPERAND); | ||
| 932 | (int32_t)(LEFT_OPERAND > RIGHT_OPERAND); | ||
| 933 | (int32_t)(LEFT_OPERAND >= RIGHT_OPERAND); | ||
| 934 | (int32_t)(LEFT_OPERAND < RIGHT_OPERAND); | ||
| 935 | (int32_t)(LEFT_OPERAND <= RIGHT_OPERAND); | ||
| 936 | (int32_t)(LEFT_OPERAND > RIGHT_OPERAND ? 1 : LEFT_OPERAND < RIGHT_OPERAND ? -1 : 0); | ||
| 937 | |||
| 938 | The return type is int type. | ||
| 939 | |||
| 940 | Compilation Errors: | ||
| 941 | |||
| 942 | C<==>, C<!=> | ||
| 943 | |||
| 944 | The type of the I<LEFT_OPERAND> must be a numeric type, an object type, a reference type, or the undef type. Otherwise, a compilation error occurs. | ||
| 945 | |||
| 946 | The type of the I<RIGHT_OPERAND> must be a numeric type, an object type, a reference type, or the undef type. Otherwise, a compilation error occurs. | ||
| 947 | |||
| 948 | If the type of the I<LEFT_OPERAND> is a numeric type, the type of the I<RIGHT_OPERAND> must be a numeric type. Otherwise, a compilation error occurs. | ||
| 949 | |||
| 950 | If the type of the I<LEFT_OPERAND> is an object type, the type of the I<RIGHT_OPERAND> must be an object type or the undef type. Otherwise, a compilation error occurs. | ||
| 951 | |||
| 952 | If the type of the I<LEFT_OPERAND> is the undef type, the type of the I<RIGHT_OPERAND> must be an object type or the undef type. Otherwise, a compilation error occurs. | ||
| 953 | |||
| 954 | If the type of the I<LEFT_OPERAND> is a reference type, the type of the I<RIGHT_OPERAND> must be a reference type or undef type. Otherwise, a compilation error occurs. | ||
| 955 | |||
| 956 | C<E<lt>>, C<E<lt>=>, C<E<gt>>, C<E<gt>=>, C<E<lt>=E<gt>> | ||
| 957 | |||
| 958 | The type of the I<LEFT_OPERAND> must be a numeric type. Otherwise, a compilation error occurs. | ||
| 959 | |||
| 960 | The type of the I<RIGHT_OPERAND> must be a numeric type. Otherwise, a compilation error occurs. | ||
| 961 | |||
| 962 | =head3 String Comparison Operators | ||
| 963 | |||
| 964 | String comparison operators compare tow strings in the dictionary order. | ||
| 965 | |||
| 966 | LEFT_OPERAND eq RIGHT_OPERAND | ||
| 967 | LEFT_OPERAND ne RIGHT_OPERAND | ||
| 968 | LEFT_OPERAND gt RIGHT_OPERAND | ||
| 969 | LEFT_OPERAND ge RIGHT_OPERAND | ||
| 970 | LEFT_OPERAND lt RIGHT_OPERAND | ||
| 971 | LEFT_OPERAND le RIGHT_OPERAND | ||
| 972 | LEFT_OPERAND cmp RIGHT_OPERAND | ||
| 973 | |||
| 974 | These operators perform the following operations. | ||
| 975 | |||
| 976 | =begin html | ||
| 977 | |||
| 978 | <table> | ||
| 979 | <tr> | ||
| 980 | <th>Operators</th> | ||
| 981 | <th>Operations</th> | ||
| 982 | </tr> | ||
| 983 | <tr> | ||
| 984 | <td> | ||
| 985 | <i>eq</i> | ||
| 986 | </td> | ||
| 987 | <td> | ||
| 988 | If <i>LEFT_OPERAND</i> is equal to <i>RIGHT_OPERAND</i> in the dictionary order, returns 1, otherwise returns 0. | ||
| 989 | </td> | ||
| 990 | </tr> | ||
| 991 | <tr> | ||
| 992 | <td> | ||
| 993 | <i>ne</i> | ||
| 994 | </td> | ||
| 995 | <td> | ||
| 996 | If <i>LEFT_OPERAND</i> is not equal to <i>RIGHT_OPERAND</i> in the dictionary order, returns 1, otherwise returns 0. | ||
| 997 | </td> | ||
| 998 | </tr> | ||
| 999 | <tr> | ||
| 1000 | <td> | ||
| 1001 | <i>gt</i> | ||
| 1002 | </td> | ||
| 1003 | <td> | ||
| 1004 | If <i>LEFT_OPERAND</i> is greater than <i>RIGHT_OPERAND</i> in the dictionary order, returns 1, otherwise returns 0. | ||
| 1005 | </td> | ||
| 1006 | </tr> | ||
| 1007 | <tr> | ||
| 1008 | <td> | ||
| 1009 | <i>ge</i> | ||
| 1010 | </td> | ||
| 1011 | <td> | ||
| 1012 | If <i>LEFT_OPERAND</i> is greater than or equal to <i>RIGHT_OPERAND</i> in the dictionary order, returns 1, otherwise returns 0. | ||
| 1013 | </td> | ||
| 1014 | </tr> | ||
| 1015 | <tr> | ||
| 1016 | <td> | ||
| 1017 | <i>lt</i> | ||
| 1018 | </td> | ||
| 1019 | <td> | ||
| 1020 | If <i>LEFT_OPERAND</i> is less than <i>RIGHT_OPERAND</i> in the dictionary order, returns 1, otherwise returns 0. | ||
| 1021 | </td> | ||
| 1022 | </tr> | ||
| 1023 | <tr> | ||
| 1024 | <td> | ||
| 1025 | <i>le</i> | ||
| 1026 | </td> | ||
| 1027 | <td> | ||
| 1028 | If <i>LEFT_OPERAND</i> is less than or equal to <i>RIGHT_OPERAND</i> in the dictionary order, returns 1, otherwise returns 0. | ||
| 1029 | </td> | ||
| 1030 | </tr> | ||
| 1031 | <tr> | ||
| 1032 | <td> | ||
| 1033 | <i>cmp</i> | ||
| 1034 | </td> | ||
| 1035 | <td> | ||
| 1036 | If <i>LEFT_OPERAND</i> is greater than <i>RIGHT_OPERAND</i> in the dictionary order, returns 1. If <i>LEFT_OPERAND</i> is less than <i>RIGHT_OPERAND</i> in the dictionary order, return -1. If <i>LEFT_OPERAND</i> is equal to <i>RIGHT_OPERAND</i> in the dictionary order, returns 0. | ||
| 1037 | </td> | ||
| 1038 | </tr> | ||
| 1039 | </table> | ||
| 1040 | |||
| 1041 | =end html | ||
| 1042 | |||
| 1043 | The return type is int type. | ||
| 1044 | |||
| 1045 | Compilation Errors. | ||
| 1046 | |||
| 1047 | The type of I<LEFT_OPERAND> must be string type or the byte[] type. Otherwise, a compilation error occurs. | ||
| 1048 | |||
| 1049 | The type of I<RIGHT_OPERAND> must be string type or the byte[] type. Otherwise, a compilation error occurs. | ||
| 1050 | |||
| 1051 | =head2 Constant Operator | ||
| 1052 | |||
| 1053 | The constant operator gets a constant value represented by a literal. | ||
| 1054 | |||
| 1055 | LITERAL | ||
| 1056 | |||
| 1057 | I<LITERAL> is a L<literal|SPVM::Document::Language::Tokenization/"Literals">. | ||
| 1058 | |||
| 1059 | The return type is the type of I<LITERAL>. | ||
| 1060 | |||
| 1061 | Compilation Errors: | ||
| 1062 | |||
| 1063 | Compilation errors casued by L<literal|SPVM::Document::Language::Tokenization/"Literals"> syntax could occur. | ||
| 1064 | |||
| 1065 | =head2 length Operator | ||
| 1066 | |||
| 1067 | The C<length> operator gets the length of a string. | ||
| 1068 | |||
| 1069 | length OPERAND | ||
| 1070 | |||
| 1071 | If the string I<OPERAND> is defind, this operator returns the length of I<OPERAND>. Note that this length is in bytes, not the number of UTF-8 characters. | ||
| 1072 | |||
| 1073 | If I<OPERAND> is not defined, returns 0. | ||
| 1074 | |||
| 1075 | The return type is int type. | ||
| 1076 | |||
| 1077 | Compilation Errors: | ||
| 1078 | |||
| 1079 | The type of I<OPERAND> must be string type. Otherwise, a compilation error occurs. | ||
| 1080 | |||
| 1081 | Examples: | ||
| 1082 | |||
| 1083 | # Examples of The length operator | ||
| 1084 | |||
| 1085 | # The length is 5 | ||
| 1086 | my $message = "Hello"; | ||
| 1087 | my $length = length $message; | ||
| 1088 | |||
| 1089 | # The length is 9 | ||
| 1090 | my $message = "あいう"; | ||
| 1091 | my $length = length $message; | ||
| 1092 | |||
| 1093 | =head2 capacity Operator | ||
| 1094 | |||
| 1095 | The C<capacity> operator gets the capacity of a string or an array. | ||
| 1096 | |||
| 1097 | capacity OPERAND | ||
| 1098 | |||
| 1099 | This operator returns the capacity of I<OPERAND>. | ||
| 1100 | |||
| 1101 | The return type is int type. | ||
| 1102 | |||
| 1103 | Exceptions: | ||
| 1104 | |||
| 1105 | I<OPERAND> must be defined. Otherwise, an exception is thrown. | ||
| 1106 | |||
| 1107 | Compilation Errors: | ||
| 1108 | |||
| 1109 | The type of I<OPERAND> must be string type or an array type. Otherwise, a compilation error occurs. | ||
| 1110 | |||
| 1111 | Examples: | ||
| 1112 | |||
| 1113 | # Examples of capacity operator | ||
| 1114 | |||
| 1115 | # The capacity is 5 | ||
| 1116 | my $message = "Hello"; | ||
| 1117 | my $capacity = capacity $message; | ||
| 1118 | |||
| 1119 | =head2 String Concatenation Operator | ||
| 1120 | |||
| 1121 | The string concatenation operator C<.> concats two strings. | ||
| 1122 | |||
| 1123 | LEFT_OPERAND . RIGHT_OPERAND | ||
| 1124 | |||
| 1125 | This operator performs L<numeric-to-string conversion|/"Numeric-to-String Conversion"> on the left operand I<LEFT_OPERAND> if the type of I<LEFT_OPERAND> is a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. | ||
| 1126 | |||
| 1127 | And it performs L<numeric-to-string conversion|/"Numeric-to-String Conversion"> on the right operand I<RIGHT_OPERAND> if the type of I<RIGHT_OPERAND> is a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. | ||
| 1128 | |||
| 1129 | And it concats I<LEFT_OPERAND> and I<RIGHT_OPERAND>, and returns its return value. | ||
| 1130 | |||
| 1131 | The type of I<LEFT_OPERAND> and I<RIGHT_OPERAND> are allowed to be the byte[] type. | ||
| 1132 | |||
| 1133 | The return type is string type. | ||
| 1134 | |||
| 1135 | Exceptions: | ||
| 1136 | |||
| 1137 | I<LEFT_OPERAND> must be defined. Otherwise, an exception is thrown. | ||
| 1138 | |||
| 1139 | I<RIGHT_OPERAND> must be defined. Otherwise, an exception is thrown. | ||
| 1140 | |||
| 1141 | Compilation Errors: | ||
| 1142 | |||
| 1143 | The type of I<LEFT_OPERAND> must be string type, the byte[] type, or a numeric type. Otherwise, a compilation error occurs. | ||
| 1144 | |||
| 1145 | The type of I<RIGHT_OPERAND> must be string type, the byte[] type, or a numeric type. Otherwise, a compilation error occurs. | ||
| 1146 | |||
| 1147 | Examples: | ||
| 1148 | |||
| 1149 | # Examples of the string concatenation operator | ||
| 1150 | my $result = "abc" . "def"; | ||
| 1151 | my $result = "def" . 34; | ||
| 1152 | |||
| 1153 | =head2 new_string_len Operator | ||
| 1154 | |||
| 1155 | The C<new_string_len> operator creates a new string with a length. | ||
| 1156 | |||
| 1157 | new_string_len OPERAND | ||
| 1158 | |||
| 1159 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on the length I<OPERAND>. | ||
| 1160 | |||
| 1161 | And creates a new string with the length, fills all characters in the string with C<\0>, and returns it. | ||
| 1162 | |||
| 1163 | The return type is mutable string type. | ||
| 1164 | |||
| 1165 | Exceptions: | ||
| 1166 | |||
| 1167 | I<OPERAND> must be greater than or equal to 0. Otherwise, an exception is thrown. | ||
| 1168 | |||
| 1169 | Compilation Errors: | ||
| 1170 | |||
| 1171 | The type of I<OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 1172 | |||
| 1173 | Examples: | ||
| 1174 | |||
| 1175 | # Examples of new_string_len operator | ||
| 1176 | my $message = new_string_len 5; | ||
| 1177 | |||
| 1178 | =head2 make_read_only Operator | ||
| 1179 | |||
| 1180 | The C<make_read_only> operator makes a string read-only. | ||
| 1181 | |||
| 1182 | make_read_only OPERAND | ||
| 1183 | |||
| 1184 | If the string I<OPERAND> is defined, this operator makes I<OPERAND> read-only. | ||
| 1185 | |||
| 1186 | A read-only string cannnot be cast to L<mutable|SPVM::Document::Language::Types/"mutable Type Qualifier"> string type. If so, an exception is thrown. | ||
| 1187 | |||
| 1188 | The return type is the void type. | ||
| 1189 | |||
| 1190 | Compilation Errors: | ||
| 1191 | |||
| 1192 | I<OPERAND> must be string type. Otherwise, a compilation error occurs. | ||
| 1193 | |||
| 1194 | Examples: | ||
| 1195 | |||
| 1196 | # Examples of make_read_only operator | ||
| 1197 | |||
| 1198 | # A string | ||
| 1199 | my $string = new_string_len 3; | ||
| 1200 | |||
| 1201 | # Make the string read-only | ||
| 1202 | make_read_only $string; | ||
| 1203 | |||
| 1204 | # The conversion to the mutable string type throw an exception. | ||
| 1205 | my $string_mutable = (mutable string)$string; | ||
| 1206 | |||
| 1207 | =head2 make_fixed_length Operator | ||
| 1208 | |||
| 1209 | The C<make_fixed_length> operator makes a string or an array fixed length. | ||
| 1210 | |||
| 1211 | make_fixed_length OPERAND | ||
| 1212 | |||
| 1213 | If I<OPERAND> is defined, this operator makes I<OPERAND> fixed length. | ||
| 1214 | |||
| 1215 | A fixed length string or array cannnot change its length and capacity. If so, an exception is thrown. | ||
| 1216 | |||
| 1217 | The return type is the void type. | ||
| 1218 | |||
| 1219 | Compilation Errors: | ||
| 1220 | |||
| 1221 | I<OPERAND> must be string or an array type. Otherwise, a compilation error occurs. | ||
| 1222 | |||
| 1223 | Examples: | ||
| 1224 | |||
| 1225 | # Examples of make_fixed_length operator | ||
| 1226 | |||
| 1227 | # A string | ||
| 1228 | my $string = new_string_len 3; | ||
| 1229 | |||
| 1230 | # Make the string read-only | ||
| 1231 | make_fixed_length $string; | ||
| 1232 | |||
| 1233 | =head2 enable_options Operator | ||
| 1234 | |||
| 1235 | The C<enable_options> operator enables C<options> flag of an object. | ||
| 1236 | |||
| 1237 | enable_options OPERAND | ||
| 1238 | |||
| 1239 | The type of object I<OPERAND> must be an object type. | ||
| 1240 | |||
| 1241 | If I<OPERAND> is defined and its type is any object array type C<object[]>, this operator enables C<options> flag of I<OPERAND>. | ||
| 1242 | |||
| 1243 | The return type is the void type. | ||
| 1244 | |||
| 1245 | Compilation Errors: | ||
| 1246 | |||
| 1247 | The type of I<OPERAND> must be an object type. Otherwise, a compilation error occurs. | ||
| 1248 | |||
| 1249 | Examples: | ||
| 1250 | |||
| 1251 | # Examples of enable_options operator | ||
| 1252 | my $options = [(object)max => 1, title => "Hello"]; | ||
| 1253 | enable_options $options; | ||
| 1254 | |||
| 1255 | =head2 disable_options Operator | ||
| 1256 | |||
| 1257 | The C<disable_options> operator disables C<options> flag of an object. | ||
| 1258 | |||
| 1259 | disable_options OPERAND | ||
| 1260 | |||
| 1261 | The type of object I<OPERAND> must be an object type. | ||
| 1262 | |||
| 1263 | If I<OPERAND> is defined, this operator disables C<options> flag of I<OPERAND>. | ||
| 1264 | |||
| 1265 | The return type is the void type. | ||
| 1266 | |||
| 1267 | Compilation Errors: | ||
| 1268 | |||
| 1269 | The type of I<OPERAND> must be an object type. Otherwise, a compilation error occurs. | ||
| 1270 | |||
| 1271 | Examples: | ||
| 1272 | |||
| 1273 | # Examples of disable_options operator | ||
| 1274 | my $options = {max => 1, title => "Hello"}; | ||
| 1275 | disable_options $options; | ||
| 1276 | |||
| 1277 | =head2 is_options Operator | ||
| 1278 | |||
| 1279 | The C<is_options> operator checks if C<options> flag of an object is enabled. | ||
| 1280 | |||
| 1281 | is_options OPERAND | ||
| 1282 | |||
| 1283 | The type of object I<OPERAND> must be an object type. | ||
| 1284 | |||
| 1285 | If I<OPERAND> is defined and C<options> flag of I<OPERAND> is enabled, the C<is_options> operator returns 1; otherwise returns 0. | ||
| 1286 | |||
| 1287 | The return type is int type. | ||
| 1288 | |||
| 1289 | Compilation Errors: | ||
| 1290 | |||
| 1291 | The type of I<OPERAND> must be an object type. Otherwise, a compilation error occurs. | ||
| 1292 | |||
| 1293 | Examples: | ||
| 1294 | |||
| 1295 | # Examples of is_options operator | ||
| 1296 | my $options = {max => 1, title => "Hello"}; | ||
| 1297 | my $is_options = is_options $options; | ||
| 1298 | |||
| 1299 | =head2 is_read_only Operator | ||
| 1300 | |||
| 1301 | The C<is_read_only> operator checks if a string is read-only. | ||
| 1302 | |||
| 1303 | is_read_only OPERAND | ||
| 1304 | |||
| 1305 | If the string I<OPERAND> is defined and read-only, the C<is_read_only> operator returns 1, otherwise returns 0. | ||
| 1306 | |||
| 1307 | The return type is int type. | ||
| 1308 | |||
| 1309 | Compilation Errors: | ||
| 1310 | |||
| 1311 | I<OPERAND> must be string type. Otherwise, a compilation error occurs. | ||
| 1312 | |||
| 1313 | Examples: | ||
| 1314 | |||
| 1315 | # Examples of is_read_only operator | ||
| 1316 | my $message = "Hello"; | ||
| 1317 | my $is_read_only = is_read_only $message; | ||
| 1318 | |||
| 1319 | =head2 is_fixed_length Operator | ||
| 1320 | |||
| 1321 | The C<is_fixed_length> operator checks if a string or array is read-only. | ||
| 1322 | |||
| 1323 | is_fixed_length OPERAND | ||
| 1324 | |||
| 1325 | If I<OPERAND> is defined and fixed length, the C<is_fixed_length> operator returns 1, otherwise returns 0. | ||
| 1326 | |||
| 1327 | The return type is int type. | ||
| 1328 | |||
| 1329 | Compilation Errors: | ||
| 1330 | |||
| 1331 | I<OPERAND> must be string or an array type. Otherwise, a compilation error occurs. | ||
| 1332 | |||
| 1333 | Examples: | ||
| 1334 | |||
| 1335 | # Examples of is_fixed_length operator | ||
| 1336 | my $message = (mutable string)copy "Hello"; | ||
| 1337 | my $is_fixed_length = is_fixed_length $message; | ||
| 1338 | |||
| 1339 | =head2 print Operator | ||
| 1340 | |||
| 1341 | The C<print> operator prints a string to standard output. | ||
| 1342 | |||
| 1343 | print OPERAND | ||
| 1344 | print STDERR OPERAND | ||
| 1345 | |||
| 1346 | This operator outputs the string I<OPERAND> to L<SPVM's standard output|SPVM::Document::Language::System/"Standard Streams">. | ||
| 1347 | |||
| 1348 | If I<OPERAND> is not defined, this operator outputs nothing. | ||
| 1349 | |||
| 1350 | The return type is the void type. | ||
| 1351 | |||
| 1352 | If C<STDERR> is specified, prints the output to L<SPVM's standard error|SPVM::Document::Language::System/"Standard Streams">. | ||
| 1353 | |||
| 1354 | Compilation Errors: | ||
| 1355 | |||
| 1356 | I<OPERAND> must be string type. Otherwise, a compilation error occurs. | ||
| 1357 | |||
| 1358 | =head2 say Operator | ||
| 1359 | |||
| 1360 | The C<say> operator prints a string to standard output with a newline. | ||
| 1361 | |||
| 1362 | say OPERAND | ||
| 1363 | say STDERR OPERAND | ||
| 1364 | |||
| 1365 | This operator outputs the string I<OPERAND> to L<SPVM's standard output|SPVM::Document::Language::System/"Standard Streams"> with a newline C<\n>. | ||
| 1366 | |||
| 1367 | If I<OPERAND> is not defined, this operator outputs a newline C<\n>. | ||
| 1368 | |||
| 1369 | The return type is the void type. | ||
| 1370 | |||
| 1371 | If C<STDERR> is specified, prints the output to L<SPVM's standard error|SPVM::Document::Language::System/"Standard Streams">. | ||
| 1372 | |||
| 1373 | Compilation Errors: | ||
| 1374 | |||
| 1375 | I<OPERAND> must be string type. Otherwise, a compilation error occurs. | ||
| 1376 | |||
| 1377 | =head2 warn Operator | ||
| 1378 | |||
| 1379 | The C<warn> operator prints a string to standard error with a stack trace. | ||
| 1380 | |||
| 1381 | warn | ||
| 1382 | warn OPERAND | ||
| 1383 | |||
| 1384 | If I<OPERAND> is omitted, I<OPERAND> is set to the string C<"Warning">. | ||
| 1385 | |||
| 1386 | This operator outputs I<OPERAND> to L<SPVM's standard error|SPVM::Document::Language::System/"Standard Streams">. | ||
| 1387 | |||
| 1388 | If I<OPERAND> is not defined, this operator outputs the string C<"undef">. | ||
| 1389 | |||
| 1390 | If the type of I<OPERAND> is string type and I<OPERAND> is defined, this operator outputs I<OPERAND>. | ||
| 1391 | |||
| 1392 | If the type of I<OPERAND> is an object type except for string type and I<OPERAND> is defined, this operator outputs the type name and the address of I<OPERAND>, such as C<"Point(0x55d8a44ed090)">. | ||
| 1393 | |||
| 1394 | If the type of I<OPERAND> is a reference type, this operator outputs the return value of L</"address Operator"> such as C<"0x55d8a44ed090">. | ||
| 1395 | |||
| 1396 | This operator outputs a newline, two tabs and a stack trace information following the output above. | ||
| 1397 | |||
| 1398 | A stack trace information consists of the current method name, file name, and line number. | ||
| 1399 | |||
| 1400 | MyClass->test at path/MyClass.spvm line 33 | ||
| 1401 | |||
| 1402 | The return type is the void type. | ||
| 1403 | |||
| 1404 | Compilation Errors: | ||
| 1405 | |||
| 1406 | The type of I<OPERAND> must be a numeric type, an object type, or a reference type. Otherwise, a compilation error occurs. | ||
| 1407 | |||
| 1408 | Examples: | ||
| 1409 | |||
| 1410 | warn; | ||
| 1411 | warn "Something is wrong."; | ||
| 1412 | |||
| 1413 | # Point(0x55d8a44ed090) | ||
| 1414 | my $point = Point->new; | ||
| 1415 | warn $point; | ||
| 1416 | |||
| 1417 | =head2 warn_level Operator | ||
| 1418 | |||
| 1419 | The C<warn_level> operator warns or dies or does nothing according to a level. | ||
| 1420 | |||
| 1421 | warn_level OPERAND, LEVEL | ||
| 1422 | |||
| 1423 | This operator expects two operands. I<OPERAND> is a message, and I<LEVEL> is an integer value that determines the behavior. | ||
| 1424 | |||
| 1425 | This operator behaves differently depending on the value of I<LEVEL>: | ||
| 1426 | |||
| 1427 | =over 2 | ||
| 1428 | |||
| 1429 | =item * If I<LEVEL> is a negative value (less than 0), this operator does nothing. | ||
| 1430 | |||
| 1431 | =item * If I<LEVEL> is 0, this operator calls L</"warn Operator"> with I<OPERAND>. | ||
| 1432 | |||
| 1433 | =item * If I<LEVEL> is a positive value (greater than 0), this operator calls L<die statement|SPVM::Document::Language::Statements/"die Statement"> with I<OPERAND>. | ||
| 1434 | |||
| 1435 | =back | ||
| 1436 | |||
| 1437 | If I<OPERAND> is not defined, it is treated the same way as in L</"warn Operator"> or L<die statement|SPVM::Document::Language::Statements/"die Statement">. | ||
| 1438 | |||
| 1439 | The return type is the void type. | ||
| 1440 | |||
| 1441 | Compilation Errors: | ||
| 1442 | |||
| 1443 | The type of I<OPERAND> must be a numeric type, an object type, or a reference type. Otherwise, a compilation error occurs. | ||
| 1444 | |||
| 1445 | The type of I<LEVEL> must be an integer type. Otherwise, a compilation error occurs. | ||
| 1446 | |||
| 1447 | Examples: | ||
| 1448 | |||
| 1449 | # Ignore | ||
| 1450 | warn_level "This is ignored.", -1; | ||
| 1451 | |||
| 1452 | # Same as warn "This is a warning."; | ||
| 1453 | warn_level "This is a warning.", 0; | ||
| 1454 | |||
| 1455 | # Same as die "This is a fatal error."; | ||
| 1456 | warn_level "This is a fatal error.", 1; | ||
| 1457 | |||
| 1458 | =head2 diag Operator | ||
| 1459 | |||
| 1460 | Same as L</"warn"> operator, but prints the caller's stack trace. | ||
| 1461 | |||
| 1462 | =head2 diag_level Operator | ||
| 1463 | |||
| 1464 | Same as L</"warn_level"> operator, but prints the caller's stack trace. | ||
| 1465 | |||
| 1466 | =head2 address Operator | ||
| 1467 | |||
| 1468 | The C<address> operator gets the address of an object or a reference as a hex string. | ||
| 1469 | |||
| 1470 | address OPERAND | ||
| 1471 | |||
| 1472 | This operator gets the address of I<OPERAND> and converts it to a hex string(such as 0x7ffee23b8ac4), and returns it. | ||
| 1473 | |||
| 1474 | The return type is string type. | ||
| 1475 | |||
| 1476 | The type of I<OPERAND> must be an object type or a reference type. | ||
| 1477 | |||
| 1478 | Compilation Errors: | ||
| 1479 | |||
| 1480 | The type of I<OPERAND> must be an object type or a reference type. Otherwise compilation error occurs. | ||
| 1481 | |||
| 1482 | =head2 __FILE__ Operator | ||
| 1483 | |||
| 1484 | The C<__FILE__> operator gets the path of the file where the current class is defined. | ||
| 1485 | |||
| 1486 | __FILE__ | ||
| 1487 | |||
| 1488 | This operator creates a string with the path of the file where the current class is defined, and returns it. | ||
| 1489 | |||
| 1490 | The return type is string type. | ||
| 1491 | |||
| 1492 | The return value can be changed by L<file directive|SPVM::Document::Language::Tokenization/"File Directive">. | ||
| 1493 | |||
| 1494 | Examples: | ||
| 1495 | |||
| 1496 | # Examples of __FILE__ operator | ||
| 1497 | class Foo::Bar { | ||
| 1498 | static method baz : void () { | ||
| 1499 | # path/SPVM/Foo/Bar.spvm | ||
| 1500 | my $file_name = __FILE__; | ||
| 1501 | } | ||
| 1502 | } | ||
| 1503 | |||
| 1504 | =head2 __LINE__ Operator | ||
| 1505 | |||
| 1506 | The C<__LINE__> operator gets the current line number. | ||
| 1507 | |||
| 1508 | __LINE__ | ||
| 1509 | |||
| 1510 | This operator returns the current line number. | ||
| 1511 | |||
| 1512 | The return type is int type. | ||
| 1513 | |||
| 1514 | Examples: | ||
| 1515 | |||
| 1516 | # Examples of __LINE__ operator | ||
| 1517 | class Foo::Bar { | ||
| 1518 | static method baz : void () { | ||
| 1519 | my $line = __LINE__; | ||
| 1520 | } | ||
| 1521 | } | ||
| 1522 | |||
| 1523 | =head2 __PACKAGE__ Operator | ||
| 1524 | |||
| 1525 | The C<__PACKAGE__> operator gets the name of L<outmost class|SPVM::Document::Language::Class/"Outmost Class">. | ||
| 1526 | |||
| 1527 | __PACKAGE__ | ||
| 1528 | |||
| 1529 | This operator creates a string with the name of L<outmost class|SPVM::Document::Language::Class/"Outmost Class">, and returns it. | ||
| 1530 | |||
| 1531 | The return type is string type. | ||
| 1532 | |||
| 1533 | Examples: | ||
| 1534 | |||
| 1535 | class Foo::Bar { | ||
| 1536 | static method baz : void () { | ||
| 1537 | # Foo::Bar | ||
| 1538 | my $outmost_class_name = __PACKAGE__; | ||
| 1539 | |||
| 1540 | my $anon_method = method : void () { | ||
| 1541 | # Foo::Bar | ||
| 1542 | my $outmost_class_name = __PACKAGE__; | ||
| 1543 | }; | ||
| 1544 | } | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | =head2 new Operator | ||
| 1548 | |||
| 1549 | The C<new> operator creates a new object, a new array, and a new multi-dimensional array. | ||
| 1550 | |||
| 1551 | See also L<use statement|SPVM::Document::Language::Class/"use Statement"> about the way to load classes. | ||
| 1552 | |||
| 1553 | See also L<SPVM::Document::Language::GarbageCollection> about garbage collection of objects. | ||
| 1554 | |||
| 1555 | =head3 Creating an Object | ||
| 1556 | |||
| 1557 | The following syntax of new operator creates a new object. | ||
| 1558 | |||
| 1559 | new CLASS_TYPE; | ||
| 1560 | |||
| 1561 | The class type I<CLASS_TYPE> must be a loaded L<class type|SPVM::Document::Language::Types/"Class Types">. | ||
| 1562 | |||
| 1563 | This operator creates a new object of I<CLASS_TYPE>, and returns it. | ||
| 1564 | |||
| 1565 | The fields of the new object are initialized by its L<type initial value|SPVM::Document::Language::Types/"Type Initial Value">. | ||
| 1566 | |||
| 1567 | The return type is I<CLASS_TYPE>. | ||
| 1568 | |||
| 1569 | Compilation Errors: | ||
| 1570 | |||
| 1571 | I<CLASS_TYPE> must be a loaded class type. Otherwise, a compilation error occurs. | ||
| 1572 | |||
| 1573 | Examples: | ||
| 1574 | |||
| 1575 | # Examples of new operator - Creating a new object | ||
| 1576 | my $object = new Foo; | ||
| 1577 | |||
| 1578 | =head3 Creating an Array | ||
| 1579 | |||
| 1580 | The following syntax of new operator creates a new array. | ||
| 1581 | |||
| 1582 | new BASIC_TYPE[LENGTH] | ||
| 1583 | |||
| 1584 | The basic type I<BASIC_TYPE> must be a loaded L<basic type|SPVM::Document::Language::Types/"Basic Types">. | ||
| 1585 | |||
| 1586 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on the length I<LENGTH>. | ||
| 1587 | |||
| 1588 | And creates a new array of the length I<LENGTH> which element type is I<BASIC_TYPE>. | ||
| 1589 | |||
| 1590 | And all elements of the new array are initialized by its L<type initial value|SPVM::Document::Language::Types/"Type Initial Value">. | ||
| 1591 | |||
| 1592 | And returns the new array. | ||
| 1593 | |||
| 1594 | The return type is C<I<BASIC_TYPE>[]>. | ||
| 1595 | |||
| 1596 | Exceptions: | ||
| 1597 | |||
| 1598 | I<LENGTH> must be greater than or equal to 0. Otherwise, an exception is thrown. | ||
| 1599 | |||
| 1600 | Compilation Errors: | ||
| 1601 | |||
| 1602 | I<LENGTH> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 1603 | |||
| 1604 | Examples: | ||
| 1605 | |||
| 1606 | # Examples of new operator - Creating a new array | ||
| 1607 | my $values = new int[3]; | ||
| 1608 | my $objects = new Foo[3]; | ||
| 1609 | my $objects = new object[3]; | ||
| 1610 | my $mulnum_values = new Complex_2d[3] | ||
| 1611 | |||
| 1612 | =head3 Creating a Multi-Dimensional Array | ||
| 1613 | |||
| 1614 | The following syntax of new operator creates a new multi-dimensional array. | ||
| 1615 | |||
| 1616 | new BASIC_TYPE[]..[LENGTH] | ||
| 1617 | |||
| 1618 | (C<[]..> means one or more C<[]>.) | ||
| 1619 | |||
| 1620 | The basic type I<BASIC_TYPE> must be a loaded L<basic type|SPVM::Document::Language::Types/"Basic Types">. | ||
| 1621 | |||
| 1622 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on the length I<LENGTH>. | ||
| 1623 | |||
| 1624 | And creates a new multi-dimensional array of the length I<LENGTH> which element type is C<I<BASIC_TYPE>[]..>. | ||
| 1625 | |||
| 1626 | And all elements of the new multi-dimensional array are initialized by its L<type initial value|SPVM::Document::Language::Types/"Type Initial Value">. | ||
| 1627 | |||
| 1628 | And returns the new multi-dimensional array. | ||
| 1629 | |||
| 1630 | The return type is C<I<BASIC_TYPE>[]..[]>. | ||
| 1631 | |||
| 1632 | Exceptions: | ||
| 1633 | |||
| 1634 | I<LENGTH> must be greater than or equal to 0. Otherwise, an exception is thrown. | ||
| 1635 | |||
| 1636 | Compilation Errors: | ||
| 1637 | |||
| 1638 | I<LENGTH> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 1639 | |||
| 1640 | The type dimension must be less than or equal to 255. Otherwise, a compilation error occurs. | ||
| 1641 | |||
| 1642 | Examples: | ||
| 1643 | |||
| 1644 | # Examples of new operator - Creating a new multi-dimensional array | ||
| 1645 | |||
| 1646 | # 2 dimentional int array | ||
| 1647 | my $muldim_values = new int[][3]; | ||
| 1648 | |||
| 1649 | # 3 dimentional int array | ||
| 1650 | my $muldim_values = new int[][][3]; | ||
| 1651 | |||
| 1652 | =head2 Array Initialization | ||
| 1653 | |||
| 1654 | The syntax of the array initialization creates a new array and sets the elements, and returns the new array. | ||
| 1655 | |||
| 1656 | [ELEMENT1, ELEMENT2, .., ELEMENTn] | ||
| 1657 | |||
| 1658 | This is expanded to the following code. | ||
| 1659 | |||
| 1660 | ( | ||
| 1661 | # Create a new array | ||
| 1662 | my $array = new ELEMENT1_TYPE[n], | ||
| 1663 | |||
| 1664 | # Set elements | ||
| 1665 | $array->[0] = ELEMENT1, | ||
| 1666 | $array->[1] = ELEMENT2, | ||
| 1667 | ..., | ||
| 1668 | $array->[n - 1] = ELEMENTn, | ||
| 1669 | $array, | ||
| 1670 | ) | ||
| 1671 | |||
| 1672 | I<ELEMENT1_TYPE> is the type of I<ELEMENT1>. | ||
| 1673 | |||
| 1674 | If elements does not exist, I<ELEMENT1_TYPE> is the any object type C<object>, I<n> is 0, and setting elements is not performed. | ||
| 1675 | |||
| 1676 | The return type is C<I<ELEMENT1_TYPE>[]>. | ||
| 1677 | |||
| 1678 | Compilation Errors: | ||
| 1679 | |||
| 1680 | If the type of I<ELEMENT1> is the undef type, a compilation error occurs. | ||
| 1681 | |||
| 1682 | Examples: | ||
| 1683 | |||
| 1684 | # Examples of the array initialization | ||
| 1685 | |||
| 1686 | # int array | ||
| 1687 | my $nums = [1, 2, 3]; | ||
| 1688 | |||
| 1689 | # double array | ||
| 1690 | my $nums = [1.5, 2.6, 3.7]; | ||
| 1691 | |||
| 1692 | # string array | ||
| 1693 | my $strings = ["foo", "bar", "baz"]; | ||
| 1694 | |||
| 1695 | The int array example is expanded to the following code. | ||
| 1696 | |||
| 1697 | # int array | ||
| 1698 | my $nums = new int[3]; | ||
| 1699 | $nums->[0] = 1; | ||
| 1700 | $nums->[1] = 2; | ||
| 1701 | $nums->[2] = 3; | ||
| 1702 | |||
| 1703 | =head3 Key-Value Array Initialization | ||
| 1704 | |||
| 1705 | The syntax of the key-value array initialization creates a new array and sets the elements with key-value pairs, and returns the new array. | ||
| 1706 | |||
| 1707 | {ELEMENT1, ELEMENT2, ELEMENT3, ELEMENT4} | ||
| 1708 | |||
| 1709 | This syntax is the same as L</"Array Initialization">, but the return type is always L<any object array type|SPVM::Document::Language::Types/"Any Object Array Type"> C<object[]>. | ||
| 1710 | |||
| 1711 | And the length of the elements must be an even number. | ||
| 1712 | |||
| 1713 | The array created in this way is called "Options" and C<options> flag of this object is enabled. | ||
| 1714 | |||
| 1715 | Compilation Errors: | ||
| 1716 | |||
| 1717 | The length of the elements must be an even number, a compilation error occurs. | ||
| 1718 | |||
| 1719 | Examples: | ||
| 1720 | |||
| 1721 | # Examples of the key-value array initialization | ||
| 1722 | |||
| 1723 | # Empty | ||
| 1724 | my $key_values = {}; | ||
| 1725 | |||
| 1726 | # Key values | ||
| 1727 | my $key_values = {foo => 1, bar => "Hello"}; | ||
| 1728 | |||
| 1729 | =head4 Options | ||
| 1730 | |||
| 1731 | The object of C<object[]> type created by L</"Key-Value Array Initialization"> is called "Options". | ||
| 1732 | |||
| 1733 | # Called "Options" | ||
| 1734 | {foo => 1, bar => 2} | ||
| 1735 | |||
| 1736 | =head2 Anon Method Operator | ||
| 1737 | |||
| 1738 | An anon method operator creates an object of an L<anon method class|SPVM::Document::Language::Class/"Anon Method Class">. | ||
| 1739 | |||
| 1740 | ANON_METHOD_CLASS_DEFINTION | ||
| 1741 | |||
| 1742 | This operator defines an anon method class using L<anon method class definition|SPVM::Document::Language::Class/"Anon Method Class Definition"> I<ANON_METHOD_CLASS_DEFINTION>, creates a new object from the class, and retunrs it. | ||
| 1743 | |||
| 1744 | If the anon method class field definition in I<ANON_METHOD_CLASS_DEFINTION> has field default values, the fields of the anon method object are set to these values. | ||
| 1745 | |||
| 1746 | Examples: | ||
| 1747 | |||
| 1748 | # Examples of the anon method operator | ||
| 1749 | my $comparator = (Comparator)method : int ($x1 : object, $x2 : object) { | ||
| 1750 | my $point1 = (Point)$x1; | ||
| 1751 | my $point2 = (Point)$x2; | ||
| 1752 | |||
| 1753 | return $point1->x <=> $point2->x; | ||
| 1754 | }; | ||
| 1755 | |||
| 1756 | # With an anon method class field definition | ||
| 1757 | my $num = 1; | ||
| 1758 | my $comparator = [$num : int] (Comparator)method : int ($x1 : object, $x2 : object) { | ||
| 1759 | my $point1 = (Point)$x1; | ||
| 1760 | my $point2 = (Point)$x2; | ||
| 1761 | |||
| 1762 | say $num; | ||
| 1763 | |||
| 1764 | return $point1->x <=> $point2->x; | ||
| 1765 | }; | ||
| 1766 | |||
| 1767 | =head2 undef Operator | ||
| 1768 | |||
| 1769 | The C<undef> operator returns an L<undefined value|SPVM::Document::Language::Types/"Undefined Value">. | ||
| 1770 | |||
| 1771 | undef | ||
| 1772 | |||
| 1773 | The return type is L<undef type|SPVM::Document::Language::Types/"undef Type">. | ||
| 1774 | |||
| 1775 | Examples: | ||
| 1776 | |||
| 1777 | # Examples of undef operator | ||
| 1778 | my $string = (string)undef; | ||
| 1779 | |||
| 1780 | if (undef) { | ||
| 1781 | |||
| 1782 | } | ||
| 1783 | |||
| 1784 | my $message = "Hello"; | ||
| 1785 | if ($message == undef) { | ||
| 1786 | |||
| 1787 | } | ||
| 1788 | |||
| 1789 | =head2 copy Operator | ||
| 1790 | |||
| 1791 | The C<copy> operator copies a numeric array, a multi-numeric array or a string. | ||
| 1792 | |||
| 1793 | copy OPERAND | ||
| 1794 | |||
| 1795 | If the operand I<OPERAND> is not an undefined value, this operator creates a new object of the same type as the operand I<OPERAND>, and copies the elements of the array or the characters of the string into the new object, and returns it. | ||
| 1796 | |||
| 1797 | If I<OPERAND> is not defined, this operator returns an undefined value. | ||
| 1798 | |||
| 1799 | The read-only flag of the string is not copied. | ||
| 1800 | |||
| 1801 | The return type is the type of I<OPERAND>. | ||
| 1802 | |||
| 1803 | Compilation Errors: | ||
| 1804 | |||
| 1805 | The operand type must be string type, a numeric array type, or a multi-numeric array type. Otherwise, a compilation error occurs. | ||
| 1806 | |||
| 1807 | Examples: | ||
| 1808 | |||
| 1809 | # Exampels of copy operator | ||
| 1810 | my $message = copy "abc"; | ||
| 1811 | |||
| 1812 | =head2 dump Operator | ||
| 1813 | |||
| 1814 | The C<dump> operator gets the string representation dumping the data contained in the object. | ||
| 1815 | |||
| 1816 | dump OPERAND | ||
| 1817 | |||
| 1818 | This operator creates a new string with the string representation dumping the data contained in the object I<OPERAND> and returns it. | ||
| 1819 | |||
| 1820 | The following is an example of the return value the C<dump> operator. | ||
| 1821 | |||
| 1822 | # An return vlaue of dump operator | ||
| 1823 | TestCase::Operator::DumpTest1 (0x55f21f7e6050) { | ||
| 1824 | byte_value => 1, | ||
| 1825 | short_value => 2, | ||
| 1826 | int_value => 3, | ||
| 1827 | long_value => 4, | ||
| 1828 | float_value => 1.1, | ||
| 1829 | double_value => 1.2, | ||
| 1830 | string_value => "a", | ||
| 1831 | int_array => [ | ||
| 1832 | 1, | ||
| 1833 | 2, | ||
| 1834 | 3 | ||
| 1835 | ] : int[](0x55f21fb9b8d0), | ||
| 1836 | object_value => TestCase::Operator::DumpTest1 (0x55f21f764640) { | ||
| 1837 | byte_value => 0, | ||
| 1838 | short_value => 0, | ||
| 1839 | int_value => 0, | ||
| 1840 | long_value => 0, | ||
| 1841 | float_value => 0, | ||
| 1842 | double_value => 0, | ||
| 1843 | string_value => undef, | ||
| 1844 | int_array => undef, | ||
| 1845 | object_value => undef | ||
| 1846 | } | ||
| 1847 | } | ||
| 1848 | |||
| 1849 | The return type is string type. | ||
| 1850 | |||
| 1851 | The string representation might be changed to make it more readable. So don't use the C<dump> operator for the purpose of the data serialization. | ||
| 1852 | |||
| 1853 | Compilation Errors: | ||
| 1854 | |||
| 1855 | I<OPERAND> must be an object type, ohterwise a compilation error occurs. | ||
| 1856 | |||
| 1857 | =head2 Reference Operator | ||
| 1858 | |||
| 1859 | The reference operator C<\> creates the reference to the value owned by a variable. | ||
| 1860 | |||
| 1861 | \VARIALBE | ||
| 1862 | |||
| 1863 | This operator creates the reference to the value owned by the variable I<VARIALBE>, and returns it. | ||
| 1864 | |||
| 1865 | I<VARIALBE> is must be a local variable of a numeric type or a multi-numeric type. | ||
| 1866 | |||
| 1867 | The return type is L<Reference Types|SPVM::Document::Language::Types/"Reference Types"> of I<VARIALBE>. | ||
| 1868 | |||
| 1869 | Compilation Errors: | ||
| 1870 | |||
| 1871 | I<VARIALBE> must be a local variable of a numeric type or a multi-numeric type. Otherwise, a compilation error occurs. | ||
| 1872 | |||
| 1873 | Examples: | ||
| 1874 | |||
| 1875 | # Examples of reference operator | ||
| 1876 | |||
| 1877 | # Create a reference of a numeric type | ||
| 1878 | my $num : int; | ||
| 1879 | my $num_ref = \$num; | ||
| 1880 | |||
| 1881 | # Create a reference of a multi-numeric type | ||
| 1882 | my $z : Complex_2d; | ||
| 1883 | my $z_ref = \$z; | ||
| 1884 | |||
| 1885 | =head2 Dereference Operator | ||
| 1886 | |||
| 1887 | The dereference operator C<$> gets a referenced value. | ||
| 1888 | |||
| 1889 | $VARIABLE | ||
| 1890 | |||
| 1891 | This operator returns the value referenced by the variable I<VARIABLE> of a reference type. | ||
| 1892 | |||
| 1893 | The return type is the type of the value referenced by I<VARIABLE>. | ||
| 1894 | |||
| 1895 | Compilation Errors: | ||
| 1896 | |||
| 1897 | The type of I<VARIABLE> must be a reference type. Otherwise, a compilation error occurs. | ||
| 1898 | |||
| 1899 | Exceptions: | ||
| 1900 | |||
| 1901 | If I<VARIABLE> is undef, an exception is thrown. | ||
| 1902 | |||
| 1903 | Examples: | ||
| 1904 | |||
| 1905 | # Examples of dereference operator | ||
| 1906 | my $num : int; | ||
| 1907 | my $num_ref = \$num; | ||
| 1908 | my $num_deref = $$num_ref; | ||
| 1909 | |||
| 1910 | my $z : Complex_2d; | ||
| 1911 | my $z_ref = \$z; | ||
| 1912 | my $z_deref = $$z_ref; | ||
| 1913 | |||
| 1914 | =head2 Assignment Operator | ||
| 1915 | |||
| 1916 | The assignment operator C<=> performs an assignment. | ||
| 1917 | |||
| 1918 | LEFT_OPERAND = RIGHTH_OPERAND | ||
| 1919 | |||
| 1920 | A data conversion described in L<Assignment Requirement|SPVM::Document::Language::Types/"Assignment Requirement"> is performed on I<RIGHTH_OPERAND> if necessary. | ||
| 1921 | |||
| 1922 | And assignment operator performs different operations depending on the left operand I<LEFT_OPERAND>. | ||
| 1923 | |||
| 1924 | If I<LEFT_OPERAND> is a local variable, this operator performs the operation that L<sets a local variable|/"Local Variable Set Operation">. | ||
| 1925 | |||
| 1926 | If I<LEFT_OPERAND> is a class variable, this operator performs the operation that L<sets a class variable|/"Class Variable Set Operation">. | ||
| 1927 | |||
| 1928 | If I<LEFT_OPERAND> is an element access, this operator performs the operation that L<sets an array element|/"Array Element Set Operation">. | ||
| 1929 | |||
| 1930 | If I<LEFT_OPERAND> is a field access, this operator performs the operation that L<sets a field|/"Field Set Operation">. | ||
| 1931 | |||
| 1932 | If I<LEFT_OPERAND> is a dereference, this operator performs the operation that L<sets a referenced value|/"Referenced Value Set Operation">. | ||
| 1933 | |||
| 1934 | If I<LEFT_OPERAND> is the exception variable, this operator performs the operation that L<sets the exception variable|/"Exception Variable Set Operation">. | ||
| 1935 | |||
| 1936 | See also L<SPVM::Document::Language::GarbageCollection/"Assignment"> about how assignment operator changes the reference counts of I<LEFT_OPERAND> and I<RIGHTH_OPERAND>. | ||
| 1937 | |||
| 1938 | Examples: | ||
| 1939 | |||
| 1940 | # Examples of assignment operator | ||
| 1941 | |||
| 1942 | # A local variable | ||
| 1943 | $num = 1; | ||
| 1944 | |||
| 1945 | # A class variable | ||
| 1946 | $NUM = 1; | ||
| 1947 | |||
| 1948 | # A field access | ||
| 1949 | $point->{x} = 1; | ||
| 1950 | |||
| 1951 | # An element access | ||
| 1952 | $nums->[0] = 1; | ||
| 1953 | |||
| 1954 | # A dereference | ||
| 1955 | $$num_ref = 1; | ||
| 1956 | |||
| 1957 | # The exception variable | ||
| 1958 | $@ = 2; | ||
| 1959 | |||
| 1960 | =head2 Special Assignment Operators | ||
| 1961 | |||
| 1962 | A special assignment operator is the combination of an operator such as C<+>, C<-> and L<assignment operator|/"Assignment Operator"> C<=>. | ||
| 1963 | |||
| 1964 | LEFT_OPERAND OPERATOR= RIGHTH_OPERAND | ||
| 1965 | |||
| 1966 | A special assignment operator is expanded to the following code. | ||
| 1967 | |||
| 1968 | LEFT_OPERAND = (TYPE_OF_LEFT_OPERAND)(LEFT_OPERAND OPERATOR RIGHTH_OPERAND) | ||
| 1969 | |||
| 1970 | See the following code using a special assignment operator C<+=>. C<$x> is int type. | ||
| 1971 | |||
| 1972 | $x += 2; | ||
| 1973 | |||
| 1974 | This is expanded to the following code. | ||
| 1975 | |||
| 1976 | $x = (int)($x + 2) | ||
| 1977 | |||
| 1978 | List of Special Assignment Operators: | ||
| 1979 | |||
| 1980 | =begin html | ||
| 1981 | |||
| 1982 | <table> | ||
| 1983 | <tr> | ||
| 1984 | <td>The addition assignment operator</td> | ||
| 1985 | <td>+=</td> | ||
| 1986 | </tr> | ||
| 1987 | <tr> | ||
| 1988 | <td>The subtraction assignment operator</td> | ||
| 1989 | <td>-=</td> | ||
| 1990 | </tr> | ||
| 1991 | <tr> | ||
| 1992 | <td>The multiplication assignment operator</td> | ||
| 1993 | <td>*=</td> | ||
| 1994 | </tr> | ||
| 1995 | <tr> | ||
| 1996 | <td>The division assignment operator</td> | ||
| 1997 | <td>/=</td> | ||
| 1998 | </tr> | ||
| 1999 | <tr> | ||
| 2000 | <td>The modulo assignment operator</td> | ||
| 2001 | <td>%=</td> | ||
| 2002 | </tr> | ||
| 2003 | <tr> | ||
| 2004 | <td>The bitwise AND assignment operator</td> | ||
| 2005 | <td>&=</td> | ||
| 2006 | </tr> | ||
| 2007 | <tr> | ||
| 2008 | <td>The bitwise OR assignment operator</td> | ||
| 2009 | <td>|=</td> | ||
| 2010 | </tr> | ||
| 2011 | <tr> | ||
| 2012 | <td>The left shift assignment operator</td> | ||
| 2013 | <td><<=</td> | ||
| 2014 | </tr> | ||
| 2015 | <tr> | ||
| 2016 | <td>The arithmetic right shift assignment operator</td> | ||
| 2017 | <td>>>=</td> | ||
| 2018 | </tr> | ||
| 2019 | <tr> | ||
| 2020 | <td>The logical right shift assignment operator</td> | ||
| 2021 | <td>>>>=</td> | ||
| 2022 | </tr> | ||
| 2023 | <tr> | ||
| 2024 | <td>The concatenation assignment operator</td> | ||
| 2025 | <td>.=</td> | ||
| 2026 | </tr> | ||
| 2027 | <tr> | ||
| 2028 | <td>The defined-or assignment operator</td> | ||
| 2029 | <td>//=</td> | ||
| 2030 | </tr> | ||
| 2031 | </table> | ||
| 2032 | |||
| 2033 | =end html | ||
| 2034 | |||
| 2035 | Examples: | ||
| 2036 | |||
| 2037 | # Special assignment operators | ||
| 2038 | $x += 1; | ||
| 2039 | $x -= 1; | ||
| 2040 | $x *= 1; | ||
| 2041 | $x /= 1; | ||
| 2042 | $x &= 1; | ||
| 2043 | $x |= 1; | ||
| 2044 | $x ^= 1; | ||
| 2045 | $x %= 1; | ||
| 2046 | $x <<= 1; | ||
| 2047 | $x >>= 1; | ||
| 2048 | $x >>>= 1; | ||
| 2049 | $x .= "abc"; | ||
| 2050 | |||
| 2051 | =head2 Get and Set Operations | ||
| 2052 | |||
| 2053 | =head3 Local Variable Get Operation | ||
| 2054 | |||
| 2055 | The operation of getting local variable gets the value of a L<local variable|SPVM::Document::Language::Class/"Local Variable">. | ||
| 2056 | |||
| 2057 | $var | ||
| 2058 | |||
| 2059 | I<$var> is a L<local variable access|/"Local Variable Access">. | ||
| 2060 | |||
| 2061 | This operation returns the value of I<$var>. | ||
| 2062 | |||
| 2063 | The return type is the type of I<$var>. | ||
| 2064 | |||
| 2065 | Compilation Errors: | ||
| 2066 | |||
| 2067 | Compiliation errors caused by the syntax of L<local variable access|/"Local Variable Access"> could occur. | ||
| 2068 | |||
| 2069 | Examples: | ||
| 2070 | |||
| 2071 | $var; | ||
| 2072 | |||
| 2073 | =head3 Local Variable Set Operation | ||
| 2074 | |||
| 2075 | The operation of setting a local variable sets a L<local variable|SPVM::Document::Language::Class/"Local Variable">. | ||
| 2076 | |||
| 2077 | $var = OPERAND | ||
| 2078 | |||
| 2079 | I<$var> is a L<local variable access|/"Local Variable Access">. | ||
| 2080 | |||
| 2081 | This operation sets I<$var> to I<OPERAND> using L<assignment operator|/"Assignment Operator">, and returns the value after setting. | ||
| 2082 | |||
| 2083 | The return value is the type of I<$var>. | ||
| 2084 | |||
| 2085 | Compilation Errors: | ||
| 2086 | |||
| 2087 | Compiliation errors caused by the syntax of L<local variable access|/"Local Variable Access"> could occur. | ||
| 2088 | |||
| 2089 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2090 | |||
| 2091 | Examples: | ||
| 2092 | |||
| 2093 | $var = 3; | ||
| 2094 | |||
| 2095 | =head3 Local Variable Access | ||
| 2096 | |||
| 2097 | The local variable access has the following syntax. | ||
| 2098 | |||
| 2099 | VAR_NAME | ||
| 2100 | |||
| 2101 | See L<Variable Name Resolution|SPVM::Document::Language::Class/"Variable Name Resolution"> about I<VAR_NAME> and the resolution of a local variable name. | ||
| 2102 | |||
| 2103 | Examples: | ||
| 2104 | |||
| 2105 | $var | ||
| 2106 | |||
| 2107 | =head3 Class Variable Get Operation | ||
| 2108 | |||
| 2109 | The operation of getting a class variable gets the value of a L<class variable|SPVM::Document::Language::Class/"Class Variable">. | ||
| 2110 | |||
| 2111 | $VAR | ||
| 2112 | |||
| 2113 | I<$VAR> is a L<class variable access|/"Class Variable Access">. | ||
| 2114 | |||
| 2115 | This operation returns the value of I<$VAR>. | ||
| 2116 | |||
| 2117 | The return type is the type of I<$VAR>. | ||
| 2118 | |||
| 2119 | Compilation Errors: | ||
| 2120 | |||
| 2121 | Compiliation errors caused by the syntax of L<class variable access|/"Class Variable Access"> could occur. | ||
| 2122 | |||
| 2123 | Examples: | ||
| 2124 | |||
| 2125 | # Examples of getting a class variable | ||
| 2126 | class Foo { | ||
| 2127 | our $VAR : int; | ||
| 2128 | |||
| 2129 | static method bar : int () { | ||
| 2130 | |||
| 2131 | my $var1 = $Foo::VAR; | ||
| 2132 | |||
| 2133 | # $Foo::VAR | ||
| 2134 | my $var2 = $VAR; | ||
| 2135 | |||
| 2136 | my $anon_method = method : void () { | ||
| 2137 | # $Foo::BAR | ||
| 2138 | $VAR; | ||
| 2139 | } | ||
| 2140 | } | ||
| 2141 | } | ||
| 2142 | |||
| 2143 | =head3 Class Variable Set Operation | ||
| 2144 | |||
| 2145 | The operation of setting a class variable operator sets a L<class variable|SPVM::Document::Language::Class/"Class Variable">. | ||
| 2146 | |||
| 2147 | $VAR = OPERAND | ||
| 2148 | |||
| 2149 | I<$VAR> is a L<class variable access|/"Class Variable Access">. | ||
| 2150 | |||
| 2151 | This operation sets I<$VAR> to I<OPERAND> using L<assignment operator|/"Assignment Operator">, and returns the value after setting. | ||
| 2152 | |||
| 2153 | The return type is the type of I<$VAR>. | ||
| 2154 | |||
| 2155 | Compilation Errors: | ||
| 2156 | |||
| 2157 | Compiliation errors caused by the syntax of L<class variable access|/"Class Variable Access"> could occur. | ||
| 2158 | |||
| 2159 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2160 | |||
| 2161 | Examples: | ||
| 2162 | |||
| 2163 | # Examples of setting a class variable | ||
| 2164 | class Foo { | ||
| 2165 | our $VAR : int; | ||
| 2166 | |||
| 2167 | static method bar : int () { | ||
| 2168 | $Foo::VAR = 1; | ||
| 2169 | |||
| 2170 | # $Foo::VAR = 3 | ||
| 2171 | $VAR = 3; | ||
| 2172 | } | ||
| 2173 | my $anon_method = method : void () { | ||
| 2174 | # $Foo::VAR = 5 | ||
| 2175 | $VAR = 5; | ||
| 2176 | } | ||
| 2177 | } | ||
| 2178 | |||
| 2179 | =head3 Class Variable Access | ||
| 2180 | |||
| 2181 | The class variable access has the following syntax. | ||
| 2182 | |||
| 2183 | VAR_NAME | ||
| 2184 | CLASS_TYPE::VAR_NAME | ||
| 2185 | |||
| 2186 | See L<Variable Name Resolution|SPVM::Document::Language::Class/"Variable Name Resolution"> about I<VAR_NAME>, I<CLASS_TYPE>, and the resolution of a class variable name. | ||
| 2187 | |||
| 2188 | Examples: | ||
| 2189 | |||
| 2190 | $VAR | ||
| 2191 | $MyClass::VAR | ||
| 2192 | |||
| 2193 | =head3 Array Element Get Operation | ||
| 2194 | |||
| 2195 | The operation of getting an array element gets an element of an L<array|SPVM::Document::Language::Types/"Array">. | ||
| 2196 | |||
| 2197 | ARRAY->[INDEX] | ||
| 2198 | |||
| 2199 | I<ARRAY-E<gt>[INDEX]> is an L<element access|/"Array Element Access">. | ||
| 2200 | |||
| 2201 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on I<INDEX>. | ||
| 2202 | |||
| 2203 | And returns the element of I<ARRAY> at I<INDEX>. | ||
| 2204 | |||
| 2205 | The return type is the element type of I<ARRAY>. | ||
| 2206 | |||
| 2207 | Exceptions: | ||
| 2208 | |||
| 2209 | I<ARRAY> must be defined. Otherwise, an exception is thrown. | ||
| 2210 | |||
| 2211 | I<INDEX> must be greater than or equal to 0. Otherwise, an exception is thrown. | ||
| 2212 | |||
| 2213 | Compilation Errors: | ||
| 2214 | |||
| 2215 | Compiliation errors caused by the syntax of L<element access|/"Array Element Access"> could occur. | ||
| 2216 | |||
| 2217 | Examples: | ||
| 2218 | |||
| 2219 | my $nums = new int[3]; | ||
| 2220 | my $num = $nums->[1]; | ||
| 2221 | |||
| 2222 | my $points = new Point[3]; | ||
| 2223 | my $point = $points->[1]; | ||
| 2224 | |||
| 2225 | =head3 Array Element Set Operation | ||
| 2226 | |||
| 2227 | The operation of setting array element sets an element of an array. | ||
| 2228 | |||
| 2229 | ARRAY->[INDEX] = OPERAND | ||
| 2230 | |||
| 2231 | I<ARRAY-E<gt>[INDEX]> is an L<element access|/"Array Element Access">. | ||
| 2232 | |||
| 2233 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on I<INDEX>. | ||
| 2234 | |||
| 2235 | And sets the element of I<ARRAY> at I<INDEX> to I<OPERAND> using L<assignment operator|/"Assignment Operator">, and returns the element after setting. | ||
| 2236 | |||
| 2237 | The return type is the element type. | ||
| 2238 | |||
| 2239 | Exceptions: | ||
| 2240 | |||
| 2241 | I<ARRAY> must be defined. Otherwise, an exception is thrown. | ||
| 2242 | |||
| 2243 | I<INDEX> must be greater than or equal to 0. Otherwise, an exception is thrown. | ||
| 2244 | |||
| 2245 | Compilation Errors: | ||
| 2246 | |||
| 2247 | Compiliation errors caused by the syntax of L<element access|/"Array Element Access"> could occur. | ||
| 2248 | |||
| 2249 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2250 | |||
| 2251 | Examples: | ||
| 2252 | |||
| 2253 | my $nums = new int[3]; | ||
| 2254 | $nums->[1] = 3; | ||
| 2255 | |||
| 2256 | my $points = new Point[3]; | ||
| 2257 | $points->[1] = Point->new(1, 2); | ||
| 2258 | |||
| 2259 | =head3 List Element Get Operation | ||
| 2260 | |||
| 2261 | The list element get operation gets an element of a list object with an index. | ||
| 2262 | |||
| 2263 | INVOCANT->[INDEX_OPERAND] | ||
| 2264 | |||
| 2265 | I<INVOCANT-E<gt>[INDEX_OPERAND]> is a L<array element access|/"Array Element Access">. | ||
| 2266 | |||
| 2267 | This operation is replaced with C<get> method call. | ||
| 2268 | |||
| 2269 | INVOCANT->get(INDEX_OPERAND) | ||
| 2270 | |||
| 2271 | Compilation Errors: | ||
| 2272 | |||
| 2273 | Compiliation errors caused by the syntax of L<array element access|/"Array Element Access"> could occur. | ||
| 2274 | |||
| 2275 | Examples: | ||
| 2276 | |||
| 2277 | my $list = List->new([1, 2]); | ||
| 2278 | my $x = $list->[1]; | ||
| 2279 | |||
| 2280 | =head3 List Element Set Operation | ||
| 2281 | |||
| 2282 | The list element set operation gets an element of a list object with an index. | ||
| 2283 | |||
| 2284 | INVOCANT->[INDEX_OPERAND] = OPERAND | ||
| 2285 | |||
| 2286 | I<INVOCANT-E<gt>[INDEX_OPERAND]> is a L<array element access|/"Array Element Access">. | ||
| 2287 | |||
| 2288 | This operation is replaced with C<set> method call. | ||
| 2289 | |||
| 2290 | INVOCANT->set(INDEX_OPERAND, OPERAND) | ||
| 2291 | |||
| 2292 | Compilation Errors: | ||
| 2293 | |||
| 2294 | Compiliation errors caused by the syntax of L<array element access|/"Array Element Access"> could occur. | ||
| 2295 | |||
| 2296 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2297 | |||
| 2298 | Examples: | ||
| 2299 | |||
| 2300 | my $list = List->new([1, 2]); | ||
| 2301 | $list->[1] = 3; | ||
| 2302 | |||
| 2303 | =head3 Array Element Access | ||
| 2304 | |||
| 2305 | The element access has the following syntax. | ||
| 2306 | |||
| 2307 | ARRAY->[INDEX] | ||
| 2308 | |||
| 2309 | The type of the array I<ARRAY> is an array type. | ||
| 2310 | |||
| 2311 | The type of the index I<INDEX> is an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. | ||
| 2312 | |||
| 2313 | If I<INDEX> is a minus value, it is set to I<INDEX> plus the length of the array. | ||
| 2314 | |||
| 2315 | Exceptions: | ||
| 2316 | |||
| 2317 | If I<INDEX> is less than 0 or more than or equal to the length of the array, an exception is thrown. | ||
| 2318 | |||
| 2319 | Compilation Errors: | ||
| 2320 | |||
| 2321 | I<ARRAY> must be an array type, string type, a class type, or an interface type. Otherwise, a compilation error occurs. | ||
| 2322 | |||
| 2323 | I<INDEX> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 2324 | |||
| 2325 | =head3 Character Get Operation | ||
| 2326 | |||
| 2327 | The operation of getting a character gets a character of a string. | ||
| 2328 | |||
| 2329 | STRING->[INDEX] | ||
| 2330 | |||
| 2331 | I<STRING-E<gt>[INDEX]> is an L<character access|/"Character Access">. | ||
| 2332 | |||
| 2333 | The type of I<STRING> is string type. | ||
| 2334 | |||
| 2335 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on I<INDEX>. | ||
| 2336 | |||
| 2337 | And returns the character of I<STRING> at I<INDEX>. | ||
| 2338 | |||
| 2339 | The return type is byte type. | ||
| 2340 | |||
| 2341 | Exceptions: | ||
| 2342 | |||
| 2343 | I<STRING> must be defined. Otherwise, an exception is thrown. | ||
| 2344 | |||
| 2345 | I<INDEX> must be greater than or equal to 0. Otherwise, an exception is thrown. | ||
| 2346 | |||
| 2347 | Compilation Errors: | ||
| 2348 | |||
| 2349 | Compiliation errors caused by the syntax of L<character access|/"Character Access"> could occur. | ||
| 2350 | |||
| 2351 | Examples: | ||
| 2352 | |||
| 2353 | my $string = "abc"; | ||
| 2354 | my $char = $string->[0]; | ||
| 2355 | |||
| 2356 | =head3 Character Set Operation | ||
| 2357 | |||
| 2358 | The operation of setting a character sets the character of a string. | ||
| 2359 | |||
| 2360 | STRING->[INDEX] = OPERAND | ||
| 2361 | |||
| 2362 | I<STRING-E<gt>[INDEX]> is an L<character access|/"Character Access">. | ||
| 2363 | |||
| 2364 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on I<INDEX>. | ||
| 2365 | |||
| 2366 | And sets the character of I<STRING> at I<INDEX> to I<OPERAND> using L<assignment operator|/"Assignment Operator">, and returns the character after setting. | ||
| 2367 | |||
| 2368 | The return type is byte type. | ||
| 2369 | |||
| 2370 | Exceptions: | ||
| 2371 | |||
| 2372 | I<STRING> must be defined. Otherwise, an exception is thrown. | ||
| 2373 | |||
| 2374 | I<INDEX> must be greater than or equal to 0. Otherwise, an exception is thrown. | ||
| 2375 | |||
| 2376 | If I<STRING> is not a mutable string, an exception is thrown. | ||
| 2377 | |||
| 2378 | Compilation Errors: | ||
| 2379 | |||
| 2380 | Compiliation errors caused by the syntax of L<character access|/"Character Access"> could occur. | ||
| 2381 | |||
| 2382 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2383 | |||
| 2384 | Examples: | ||
| 2385 | |||
| 2386 | my $string = new_string_len 3; | ||
| 2387 | $string->[0] = 'a'; | ||
| 2388 | |||
| 2389 | =head3 Character Access | ||
| 2390 | |||
| 2391 | The character access has the following syntax. | ||
| 2392 | |||
| 2393 | STRING->[INDEX] | ||
| 2394 | |||
| 2395 | The type of the string I<STRING> is string type. | ||
| 2396 | |||
| 2397 | The type of the index I<INDEX> is an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. | ||
| 2398 | |||
| 2399 | Compilation Errors: | ||
| 2400 | |||
| 2401 | I<STRING> must be string type. Otherwise, a compilation error occurs. | ||
| 2402 | |||
| 2403 | I<INDEX> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 2404 | |||
| 2405 | =head3 Field Get Operation | ||
| 2406 | |||
| 2407 | The operation of getting field gets the value of a field of a class type. | ||
| 2408 | |||
| 2409 | INVOCANT->{FIELD_NAME} | ||
| 2410 | |||
| 2411 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 2412 | |||
| 2413 | This operation gets the value of the field specified by I<FIELD_NAME> of the type of I<INVOCANT>. | ||
| 2414 | |||
| 2415 | The retrun type is the type of the field. | ||
| 2416 | |||
| 2417 | Compilation Errors: | ||
| 2418 | |||
| 2419 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 2420 | |||
| 2421 | Examples: | ||
| 2422 | |||
| 2423 | my $point = Point->new; | ||
| 2424 | my $x = $point->{x}; | ||
| 2425 | |||
| 2426 | =head3 Field Set Operation | ||
| 2427 | |||
| 2428 | The operation of setting field sets the field of a class type. | ||
| 2429 | |||
| 2430 | INVOCANT->{FIELD_NAME} = OPERAND | ||
| 2431 | |||
| 2432 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 2433 | |||
| 2434 | The type of I<INVOCANT> is a class type. | ||
| 2435 | |||
| 2436 | This operation sets the field specified by I<FIELD_NAME> of the type of I<INVOCANT> to I<OPERAND> using L<assignment operator|/"Assignment Operator">, and returns the value of the field after setting. | ||
| 2437 | |||
| 2438 | The return type is the field type. | ||
| 2439 | |||
| 2440 | Compilation Errors: | ||
| 2441 | |||
| 2442 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 2443 | |||
| 2444 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2445 | |||
| 2446 | Examples: | ||
| 2447 | |||
| 2448 | my $point = Point->new; | ||
| 2449 | $point->{x} = 1; | ||
| 2450 | |||
| 2451 | =head3 Multi-Numeric Field Get Operation | ||
| 2452 | |||
| 2453 | The operation of getting a multi-numeric field gets the value of a field of a L<multi-numeric type|SPVM::Document::Language::Types/"Multi-Numeric Types">. | ||
| 2454 | |||
| 2455 | INVOCANT->{FIELD_NAME} | ||
| 2456 | |||
| 2457 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 2458 | |||
| 2459 | The type of I<INVOCANT> is a multi-numeric type. | ||
| 2460 | |||
| 2461 | This operation gets the value of the field specified by I<FIELD_NAME> of the type of I<INVOCANT>. | ||
| 2462 | |||
| 2463 | The retrun type is the type of the field. | ||
| 2464 | |||
| 2465 | Compilation Errors: | ||
| 2466 | |||
| 2467 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 2468 | |||
| 2469 | Examples: | ||
| 2470 | |||
| 2471 | my $z : Complex_2d; | ||
| 2472 | my $re = $z->{re}; | ||
| 2473 | |||
| 2474 | =head3 Multi-Numeric Field Set Operation | ||
| 2475 | |||
| 2476 | The operation of setting multi-numeric field sets the field of L<multi-numeric type|SPVM::Document::Language::Types/"Multi-Numeric Types">. | ||
| 2477 | |||
| 2478 | INVOCANT->{FIELD_NAME} = OPERAND | ||
| 2479 | |||
| 2480 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 2481 | |||
| 2482 | The type of I<INVOCANT> is a multi-numeric type. | ||
| 2483 | |||
| 2484 | This operation sets the field specified by I<FIELD_NAME> of the type of I<INVOCANT> to I<OPERAND> using L<assignment operator|/"Assignment Operator">, and returns the value of the field after setting. | ||
| 2485 | |||
| 2486 | The return type is the field type. | ||
| 2487 | |||
| 2488 | Compilation Errors: | ||
| 2489 | |||
| 2490 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 2491 | |||
| 2492 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2493 | |||
| 2494 | Examples: | ||
| 2495 | |||
| 2496 | my $z : Complex_2d; | ||
| 2497 | $z->{re} = 2.5; | ||
| 2498 | |||
| 2499 | =head3 Referenced Multi-Numeric Field Get Operation | ||
| 2500 | |||
| 2501 | The operation of getting a multi-numeric field gets the value of a field of a L<multi-numeric type|SPVM::Document::Language::Types/"Multi-Numeric Types"> referenced by a multi-numeric Reference Types. | ||
| 2502 | |||
| 2503 | This operation is expaned to the following code. | ||
| 2504 | |||
| 2505 | ($INVOCANT)->{FIELD_NAME} | ||
| 2506 | |||
| 2507 | The type of I<INVOCANT> is a multi-numeric refenrece type. | ||
| 2508 | |||
| 2509 | Compilation Errors: | ||
| 2510 | |||
| 2511 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 2512 | |||
| 2513 | Compiliation errors caused by L<dereference operator|/"Dereference Operator"> could occur. | ||
| 2514 | |||
| 2515 | Exceptions: | ||
| 2516 | |||
| 2517 | If I<INVOCANT> is undef, an exception is thrown. | ||
| 2518 | |||
| 2519 | Examples: | ||
| 2520 | |||
| 2521 | my $z : Complex_2d; | ||
| 2522 | my $z_ref = \$z; | ||
| 2523 | my $re = $z_ref->{re}; | ||
| 2524 | |||
| 2525 | =head3 Referenced Multi-Numeric Field Set Operation | ||
| 2526 | |||
| 2527 | The operation of setting a multi-numeric field sets the value of a field of a L<multi-numeric type|SPVM::Document::Language::Types/"Multi-Numeric Types"> referenced by a multi-numeric Reference Types. | ||
| 2528 | |||
| 2529 | This operation is expaned to the following code. | ||
| 2530 | |||
| 2531 | ($INVOCANT)->{FIELD_NAME} = OPERAND | ||
| 2532 | |||
| 2533 | The type of I<INVOCANT> is a multi-numeric refenrece type. | ||
| 2534 | |||
| 2535 | Compilation Errors: | ||
| 2536 | |||
| 2537 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 2538 | |||
| 2539 | Compiliation errors caused by L<dereference operator|/"Dereference Operator"> could occur. | ||
| 2540 | |||
| 2541 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2542 | |||
| 2543 | Exceptions: | ||
| 2544 | |||
| 2545 | If I<INVOCANT> is undef, an exception is thrown. | ||
| 2546 | |||
| 2547 | Examples: | ||
| 2548 | |||
| 2549 | my $z : Complex_2d; | ||
| 2550 | my $z_ref = \$z; | ||
| 2551 | $z_ref->{re} = 2.5; | ||
| 2552 | |||
| 2553 | =head3 Hash Value Get Operation | ||
| 2554 | |||
| 2555 | The operation of getting field gets the value of a field of a class type. | ||
| 2556 | |||
| 2557 | INVOCANT->{KEY_OPERAND} | ||
| 2558 | |||
| 2559 | I<INVOCANT-E<gt>{KEY_OPERAND}> is a L<hash value access|/"Hash Value Access">. | ||
| 2560 | |||
| 2561 | This operation is replaced with C<get> method call. | ||
| 2562 | |||
| 2563 | INVOCANT->get(KEY_OPERAND) | ||
| 2564 | |||
| 2565 | Compilation Errors: | ||
| 2566 | |||
| 2567 | Compiliation errors caused by the syntax of L<hash value access|/"Hash Value Access"> could occur. | ||
| 2568 | |||
| 2569 | Examples: | ||
| 2570 | |||
| 2571 | my $hash = Hash->new({x => 1}); | ||
| 2572 | my $x = $hash->{"x"}; | ||
| 2573 | |||
| 2574 | =head3 Hash Value Set Operation | ||
| 2575 | |||
| 2576 | The operation of setting field sets the field of a class type. | ||
| 2577 | |||
| 2578 | INVOCANT->{KEY_OPERAND} = OPERAND | ||
| 2579 | |||
| 2580 | I<INVOCANT-E<gt>{KEY_OPERAND}> is a L<hash value access|/"Hash Value Access">. | ||
| 2581 | |||
| 2582 | This operation is replaced with C<set> method call. | ||
| 2583 | |||
| 2584 | INVOCANT->set(KEY_OPERAND, OPERAND) | ||
| 2585 | |||
| 2586 | Compilation Errors: | ||
| 2587 | |||
| 2588 | Compiliation errors caused by the syntax of L<hash value access|/"Hash Value Access"> could occur. | ||
| 2589 | |||
| 2590 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2591 | |||
| 2592 | Examples: | ||
| 2593 | |||
| 2594 | my $hash = Hash->new({x => 1}); | ||
| 2595 | $hash->{"x"} = 2; | ||
| 2596 | |||
| 2597 | =head3 Field Access | ||
| 2598 | |||
| 2599 | The field access has the following syntax. | ||
| 2600 | |||
| 2601 | INVOCANT->{FIELD_NAME} | ||
| 2602 | |||
| 2603 | See L<Field Access Resolution|SPVM::Document::Language::Class/"Field Access Resolution"> about I<INVOCANT>, I<FIELD_NAME>, and the resolution of a field access. | ||
| 2604 | |||
| 2605 | Examples: | ||
| 2606 | |||
| 2607 | $point->{x} | ||
| 2608 | |||
| 2609 | =head3 Hash Value Access | ||
| 2610 | |||
| 2611 | The hash value access has the following syntax. | ||
| 2612 | |||
| 2613 | INVOCANT->{KEY_OPERAND} | ||
| 2614 | |||
| 2615 | The type of I<INVOCANT> is a class type or an interface type. | ||
| 2616 | |||
| 2617 | The type of I<KEY_OPERAND> is string type. | ||
| 2618 | |||
| 2619 | Examples: | ||
| 2620 | |||
| 2621 | $hash->{"x"}; | ||
| 2622 | |||
| 2623 | Compilation Errors: | ||
| 2624 | |||
| 2625 | The type of INVOCANT must be a class type or an interface type. Otherwise a compilation error occurs. | ||
| 2626 | |||
| 2627 | The type of KEY_OPERAND must be string type. Otherwise a compilation error occurs. | ||
| 2628 | |||
| 2629 | =head3 Referenced Value Get Operation | ||
| 2630 | |||
| 2631 | The operation of getting the referenced value gets a referenced value. | ||
| 2632 | |||
| 2633 | See L<dereference operator|/"Dereference Operator">. | ||
| 2634 | |||
| 2635 | =head3 Referenced Value Set Operation | ||
| 2636 | |||
| 2637 | The operation of setting the referenced value sets a referenced value. | ||
| 2638 | |||
| 2639 | $VARIABLE = OPERAND | ||
| 2640 | |||
| 2641 | Thie operation sets the value referenced by the reference I<VARIABLE> to I<OPERAND> using L<assignment operator|/"Assignment Operator">, and returns the value after setting. | ||
| 2642 | |||
| 2643 | The return type is the type of the referenced value. | ||
| 2644 | |||
| 2645 | Compilation Errors: | ||
| 2646 | |||
| 2647 | The type of I<VARIABLE> must be a reference type. Otherwise, a compilation error occurs. | ||
| 2648 | |||
| 2649 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2650 | |||
| 2651 | Examples: | ||
| 2652 | |||
| 2653 | my $num : int; | ||
| 2654 | my $num_ref : int* = \$num; | ||
| 2655 | $$num_ref = 1; | ||
| 2656 | |||
| 2657 | my $z : Complex_2d; | ||
| 2658 | my $z_ref : Complex_2d* = \$z; | ||
| 2659 | |||
| 2660 | my $z2 : Complex_2d; | ||
| 2661 | |||
| 2662 | $$z_ref = $z2; | ||
| 2663 | |||
| 2664 | =head3 Exception Variable Get Operation | ||
| 2665 | |||
| 2666 | The operation of getting the exception variable gets the string stored in L<exception variable|SPVM::Document::Language::ExceptionHandling/"Exception Variable">. | ||
| 2667 | |||
| 2668 | $@ | ||
| 2669 | |||
| 2670 | This operator returns the string stored in the exception variable. | ||
| 2671 | |||
| 2672 | The return type is string type. | ||
| 2673 | |||
| 2674 | Examples: | ||
| 2675 | |||
| 2676 | # Examples of getting the exception variable | ||
| 2677 | my $message = $@; | ||
| 2678 | |||
| 2679 | =head3 Exception Variable Set Operation | ||
| 2680 | |||
| 2681 | The operation of setting the exception variable sets L<exception variable|SPVM::Document::Language::ExceptionHandling/"Exception Variable">. | ||
| 2682 | |||
| 2683 | $@ = OPERAND | ||
| 2684 | |||
| 2685 | This operator sets the exception variable to I<OPERAND> using L<assignment operator|/"Assignment Operator">. | ||
| 2686 | |||
| 2687 | The return type is string type. | ||
| 2688 | |||
| 2689 | Compilation Errors: | ||
| 2690 | |||
| 2691 | The assignment must satisfy L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. Otherwise, a compilation error occurs. | ||
| 2692 | |||
| 2693 | Examples: | ||
| 2694 | |||
| 2695 | # Examples of setting the exception variable | ||
| 2696 | $@ = "Error"; | ||
| 2697 | |||
| 2698 | =head2 Data Conversions | ||
| 2699 | |||
| 2700 | This section describes data conversions. | ||
| 2701 | |||
| 2702 | =head3 Numeric Widening Conversion | ||
| 2703 | |||
| 2704 | The numeric widening conversion is the data conversion from a L<numeric type|SPVM::Document::Language::Types/"Numeric Types"> to a larger L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. | ||
| 2705 | |||
| 2706 | See L<numeric types order|SPVM::Document::Language::Types/"Numeric Types Order"> about the order of numeric types. | ||
| 2707 | |||
| 2708 | This conversion performs the same operation as the C language type cast. | ||
| 2709 | |||
| 2710 | (TYPE)OPERAND | ||
| 2711 | |||
| 2712 | B<byte to short:> | ||
| 2713 | |||
| 2714 | (int16_t)OPERAND_int8_t; | ||
| 2715 | |||
| 2716 | B<byte to int:> | ||
| 2717 | |||
| 2718 | (int32_t)OPERAND_int8_t; | ||
| 2719 | |||
| 2720 | B<byte to long:> | ||
| 2721 | |||
| 2722 | (int64_t)OPERAND_int8_t; | ||
| 2723 | |||
| 2724 | B<byte to float:> | ||
| 2725 | |||
| 2726 | (float)OPERAND_int8_t; | ||
| 2727 | |||
| 2728 | B<byte to double:> | ||
| 2729 | |||
| 2730 | (double)OPERAND_int8_t; | ||
| 2731 | |||
| 2732 | B<short to int:> | ||
| 2733 | |||
| 2734 | (int32_t)OPERAND_int16_t; | ||
| 2735 | |||
| 2736 | B<short to long:> | ||
| 2737 | |||
| 2738 | (int64_t)OPERAND_int16_t; | ||
| 2739 | |||
| 2740 | B<short to float:> | ||
| 2741 | |||
| 2742 | (float)OPERAND_int16_t; | ||
| 2743 | |||
| 2744 | B<short to double:> | ||
| 2745 | |||
| 2746 | (double)OPERAND_int16_t; | ||
| 2747 | |||
| 2748 | B<int to long:> | ||
| 2749 | |||
| 2750 | (int64_t)OPERAND_int32_t; | ||
| 2751 | |||
| 2752 | B<int to float:> | ||
| 2753 | |||
| 2754 | (float)OPERAND_int32_t; | ||
| 2755 | |||
| 2756 | B<int to double:> | ||
| 2757 | |||
| 2758 | (double)OPERAND_int32_t; | ||
| 2759 | |||
| 2760 | B<long to float:> | ||
| 2761 | |||
| 2762 | (float)OPERAND_int64_t; | ||
| 2763 | |||
| 2764 | B<long to double:> | ||
| 2765 | |||
| 2766 | (double)OPERAND_int64_t; | ||
| 2767 | |||
| 2768 | B<float to double:> | ||
| 2769 | |||
| 2770 | (double)OPERAND_float; | ||
| 2771 | |||
| 2772 | =head3 Integer Promotional Conversion | ||
| 2773 | |||
| 2774 | The integer promotional conversion is the data conversion from an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int to int type using L<numeric widening conversion|/"Numeric Widening Conversion">. | ||
| 2775 | |||
| 2776 | =head3 Numeric Narrowing Conversion | ||
| 2777 | |||
| 2778 | The numeric narrowing conversion is the data conversion from a L<numeric type|SPVM::Document::Language::Types/"Numeric Types"> to a smaller L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. | ||
| 2779 | |||
| 2780 | See L<numeric types order|SPVM::Document::Language::Types/"Numeric Types Order"> about the order of numeric types. | ||
| 2781 | |||
| 2782 | This conversion performs the same operation as the C language type cast. | ||
| 2783 | |||
| 2784 | (TYPE)OPERAND | ||
| 2785 | |||
| 2786 | B<double to float:> | ||
| 2787 | |||
| 2788 | (float)OPERAND_double; | ||
| 2789 | |||
| 2790 | B<double to long:> | ||
| 2791 | |||
| 2792 | (int64_t)OPERAND_double; | ||
| 2793 | |||
| 2794 | B<double to int:> | ||
| 2795 | |||
| 2796 | (int32_t)OPERAND_double; | ||
| 2797 | |||
| 2798 | B<double to short:> | ||
| 2799 | |||
| 2800 | (int16_t)OPERAND_double; | ||
| 2801 | |||
| 2802 | B<double to byte:> | ||
| 2803 | |||
| 2804 | (int8_t)OPERAND_double; | ||
| 2805 | |||
| 2806 | B<float to long:> | ||
| 2807 | |||
| 2808 | (int64_t)OPERAND_float; | ||
| 2809 | |||
| 2810 | B<float to int:> | ||
| 2811 | |||
| 2812 | (int32_t)OPERAND_float; | ||
| 2813 | |||
| 2814 | B<float to short:> | ||
| 2815 | |||
| 2816 | (int16_t)OPERAND_float; | ||
| 2817 | |||
| 2818 | B<float to byte:> | ||
| 2819 | |||
| 2820 | (int8_t)OPERAND_float; | ||
| 2821 | |||
| 2822 | B<long to int:> | ||
| 2823 | |||
| 2824 | (int32_)OPERAND_int64_t; | ||
| 2825 | |||
| 2826 | B<long to short:> | ||
| 2827 | |||
| 2828 | (int16_t)OPERAND_int64_t; | ||
| 2829 | |||
| 2830 | B<long to byte:> | ||
| 2831 | |||
| 2832 | (int8_t)OPERAND_int64_t; | ||
| 2833 | |||
| 2834 | B<int to short:> | ||
| 2835 | |||
| 2836 | (int16_t)OPERAND_int32_t; | ||
| 2837 | |||
| 2838 | B<int to byte:> | ||
| 2839 | |||
| 2840 | (int16_t)OPERAND_int32_t; | ||
| 2841 | |||
| 2842 | B<short to byte:> | ||
| 2843 | |||
| 2844 | (int8_t)OPERAND_int16_t; | ||
| 2845 | |||
| 2846 | =head3 Binary Numeric Conversion | ||
| 2847 | |||
| 2848 | The binary numeric conversion is the data conversion to upgrade L<numeric type|SPVM::Document::Language::Types/"Numeric Types"> of the left operand and the right operand of a binary operator. | ||
| 2849 | |||
| 2850 | This conversion performs the following operations. | ||
| 2851 | |||
| 2852 | If the left operand type is smaller than the right operand, L<numeric widening conversion|/"Numeric Widening Conversion"> from the left operand type to the right operand type is performed on the left operand. | ||
| 2853 | |||
| 2854 | If the right operand type is smaller than the left operand, L<numeric widening conversion|/"Numeric Widening Conversion"> from the right operand type to the left operand type is performed on the right operand. | ||
| 2855 | |||
| 2856 | If the converted type of the left operand is the smaller than int type, L<numeric widening conversion|/"Numeric Widening Conversion"> from the left operand type to int type is performed on the left operand. | ||
| 2857 | |||
| 2858 | If the converted type of the right operand is the smaller than int type, L<numeric widening conversion|/"Numeric Widening Conversion"> from the right operand type to int type is performed on the right operand. | ||
| 2859 | |||
| 2860 | =head3 Numeric-to-String Conversion | ||
| 2861 | |||
| 2862 | The numeric-to-string conversion is the data conversion from a L<numeric type|SPVM::Document::Language::Types/"Numeric Types"> to L<string type|SPVM::Document::Language::Types/"string Type">. | ||
| 2863 | |||
| 2864 | This conversion performs the same operation as the C language C<sprintf>. | ||
| 2865 | |||
| 2866 | B<byte to string:> | ||
| 2867 | |||
| 2868 | sprintf(RETURN_VALUE, "%" PRId8, OPERAND_byte); | ||
| 2869 | |||
| 2870 | B<short to string:> | ||
| 2871 | |||
| 2872 | sprintf(RETURN_VALUE, "%" PRId16, OPERAND_short); | ||
| 2873 | |||
| 2874 | B<int to string:> | ||
| 2875 | |||
| 2876 | sprintf(RETURN_VALUE, "%" PRId32, OPERAND_int); | ||
| 2877 | |||
| 2878 | B<long to string:> | ||
| 2879 | |||
| 2880 | sprintf(RETURN_VALUE, "%" PRId64, OPERAND_long); | ||
| 2881 | |||
| 2882 | B<float to string:> | ||
| 2883 | |||
| 2884 | sprintf(RETURN_VALUE, "%g", OPERAND_float); | ||
| 2885 | |||
| 2886 | B<double to string:> | ||
| 2887 | |||
| 2888 | sprintf(RETURN_VALUE, "%g", OPERAND_double); | ||
| 2889 | |||
| 2890 | Examples: | ||
| 2891 | |||
| 2892 | # Examples of the numeric-to-string conversion | ||
| 2893 | my $byte = (byte)1; | ||
| 2894 | my $string_byte = (string)$byte; | ||
| 2895 | |||
| 2896 | my $short = (short)2; | ||
| 2897 | my $string_short = (string)$short; | ||
| 2898 | |||
| 2899 | my $int = 3; | ||
| 2900 | my $string_int = (string)$int; | ||
| 2901 | |||
| 2902 | my $long = 4L; | ||
| 2903 | my $string_long = (string)$long; | ||
| 2904 | |||
| 2905 | my $float = 2.5f; | ||
| 2906 | my $string_float = (string)$float; | ||
| 2907 | |||
| 2908 | my $double = 3.3; | ||
| 2909 | my $string_double = (string)$double; | ||
| 2910 | |||
| 2911 | =head3 String-to-Numeric Conversion | ||
| 2912 | |||
| 2913 | The string-to-numeric conversion is the data conversion from L<string type|SPVM::Document::Language::Types/"string Type"> to a L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. | ||
| 2914 | |||
| 2915 | B<string to byte:> | ||
| 2916 | |||
| 2917 | If the string is not defined, it returns 0. | ||
| 2918 | |||
| 2919 | If it is defined, it is coverted to a number by the C<strtoll> function in the C language. | ||
| 2920 | |||
| 2921 | The number is greater than C<INT8_MAX>, the number is set to C<INT8_MAX>. | ||
| 2922 | |||
| 2923 | The number is less than C<INT8_MIN>, the number is set to C<INT8_MIN>. | ||
| 2924 | |||
| 2925 | And returns the number. | ||
| 2926 | |||
| 2927 | B<string to short:> | ||
| 2928 | |||
| 2929 | If the string is not defined, it returns 0. | ||
| 2930 | |||
| 2931 | If it is defined, it is coverted to a number by the C<strtoll> function in the C language. | ||
| 2932 | |||
| 2933 | The number is greater than C<INT16_MAX>, the number is set to C<INT16_MAX>. | ||
| 2934 | |||
| 2935 | The number is less than C<INT16_MIN>, the number is set to C<INT16_MIN>. | ||
| 2936 | |||
| 2937 | And returns the number. | ||
| 2938 | |||
| 2939 | B<string to int:> | ||
| 2940 | |||
| 2941 | If the string is not defined, it returns 0. | ||
| 2942 | |||
| 2943 | If it is defined, it is coverted to a number by the C<strtoll> function in the C language. | ||
| 2944 | |||
| 2945 | The number is greater than C<INT32_MAX>, the number is set to C<INT32_MAX>. | ||
| 2946 | |||
| 2947 | The number is less than C<INT32_MIN>, the number is set to C<INT32_MIN>. | ||
| 2948 | |||
| 2949 | And returns the number. | ||
| 2950 | |||
| 2951 | B<string to long:> | ||
| 2952 | |||
| 2953 | If the string is not defined, it returns 0. | ||
| 2954 | |||
| 2955 | If it is defined, it is coverted to a number by the C<strtoll> function in the C language. | ||
| 2956 | |||
| 2957 | And returns the number. | ||
| 2958 | |||
| 2959 | B<string to float:> | ||
| 2960 | |||
| 2961 | If the string is not defined, it returns 0. | ||
| 2962 | |||
| 2963 | If it is defined, it is coverted to a number by the C<strtof> function in the C language. | ||
| 2964 | |||
| 2965 | And returns the number. | ||
| 2966 | |||
| 2967 | B<string to double:> | ||
| 2968 | |||
| 2969 | If the string is not defined, it returns 0. | ||
| 2970 | |||
| 2971 | If it is defined, it is coverted to a number by the C<strtod> function in the C language. | ||
| 2972 | |||
| 2973 | And returns the number. | ||
| 2974 | |||
| 2975 | Exampels: | ||
| 2976 | |||
| 2977 | # Examples of string to numeric conversions | ||
| 2978 | |||
| 2979 | # string to byte | ||
| 2980 | my $string : string = "Hello"; | ||
| 2981 | my $number : byte = (byte)$string; | ||
| 2982 | |||
| 2983 | # string to short | ||
| 2984 | my $string : string = "Hello"; | ||
| 2985 | my $number : short = (short)$string; | ||
| 2986 | |||
| 2987 | # string to int | ||
| 2988 | my $string : string = "Hello"; | ||
| 2989 | my $number : int = (int)$string; | ||
| 2990 | |||
| 2991 | # string to long | ||
| 2992 | my $string : string = "Hello"; | ||
| 2993 | my $number : long = (long)$string; | ||
| 2994 | |||
| 2995 | # string to float | ||
| 2996 | my $string : string = "Hello"; | ||
| 2997 | my $float : float = (float)$string; | ||
| 2998 | |||
| 2999 | # string to double | ||
| 3000 | my $string : string = "Hello"; | ||
| 3001 | my $number : double = (double)$string; | ||
| 3002 | |||
| 3003 | =head3 String-to-byte[] Conversion | ||
| 3004 | |||
| 3005 | The string-to-byte[] conversion is the data conversion from string type to the byte[] type. | ||
| 3006 | |||
| 3007 | This conversion creates a new array which type is the C<byte[]> type, copies all characters in the string to the elements of the new array, and returns the new array. | ||
| 3008 | |||
| 3009 | If the string is not defined, it returns C<undef>. | ||
| 3010 | |||
| 3011 | Examples: | ||
| 3012 | |||
| 3013 | # Examples of the string-to-byte[] conversion | ||
| 3014 | my $string : string = "Hello"; | ||
| 3015 | my $bytes : byte[] = (byte[])$string; | ||
| 3016 | |||
| 3017 | =head3 byte[]-to-string Conversion | ||
| 3018 | |||
| 3019 | The byte[]-to-string conversion is the data conversion from the byte[] type to string type. | ||
| 3020 | |||
| 3021 | This conversion creates a new string, copies all elements in the array which type is the byte[] type to the characters of the new string, and returns the new string. | ||
| 3022 | |||
| 3023 | If the array is not defined, returns C<undef>. | ||
| 3024 | |||
| 3025 | # Examples of the byte[]-to-string conversion | ||
| 3026 | my $bytes : byte[] = new byte[3]; | ||
| 3027 | $bytes->[0] = 'a'; | ||
| 3028 | $bytes->[1] = 'b'; | ||
| 3029 | $bytes->[2] = 'c'; | ||
| 3030 | my $string : string = (string)$bytes; | ||
| 3031 | |||
| 3032 | =head3 Boxing Conversion | ||
| 3033 | |||
| 3034 | The boxing conversion is the type coversion from a L<numeric type|SPVM::Document::Language::Types/"Numeric Types"> to its corresponding L<numeric object type|SPVM::Document::Language::Types/"Numeric Object Types">. | ||
| 3035 | |||
| 3036 | =begin html | ||
| 3037 | |||
| 3038 | <table> | ||
| 3039 | <tr> | ||
| 3040 | <th> | ||
| 3041 | To | ||
| 3042 | </th> | ||
| 3043 | <th> | ||
| 3044 | From | ||
| 3045 | </th> | ||
| 3046 | </tr> | ||
| 3047 | <tr> | ||
| 3048 | <td> | ||
| 3049 | <a href="https://metacpan.org/pod/SPVM::Byte">Byte</a> | ||
| 3050 | </td> | ||
| 3051 | <td> | ||
| 3052 | byte | ||
| 3053 | </td> | ||
| 3054 | </tr> | ||
| 3055 | <tr> | ||
| 3056 | <td> | ||
| 3057 | <a href="https://metacpan.org/pod/SPVM::Short">Short</a> | ||
| 3058 | </td> | ||
| 3059 | <td> | ||
| 3060 | short | ||
| 3061 | </td> | ||
| 3062 | </tr> | ||
| 3063 | <tr> | ||
| 3064 | <td> | ||
| 3065 | <a href="https://metacpan.org/pod/SPVM::Int">Int</a> | ||
| 3066 | </td> | ||
| 3067 | <td> | ||
| 3068 | int | ||
| 3069 | </td> | ||
| 3070 | </tr> | ||
| 3071 | <tr> | ||
| 3072 | <td> | ||
| 3073 | <a href="https://metacpan.org/pod/SPVM::Long">Long</a> | ||
| 3074 | </td> | ||
| 3075 | <td> | ||
| 3076 | long | ||
| 3077 | </td> | ||
| 3078 | </tr> | ||
| 3079 | <tr> | ||
| 3080 | <td> | ||
| 3081 | <a href="https://metacpan.org/pod/SPVM::Float">Float</a> | ||
| 3082 | </td> | ||
| 3083 | <td> | ||
| 3084 | float | ||
| 3085 | </td> | ||
| 3086 | </tr> | ||
| 3087 | <tr> | ||
| 3088 | <td> | ||
| 3089 | <a href="https://metacpan.org/pod/SPVM::Double">Double</a> | ||
| 3090 | </td> | ||
| 3091 | <td> | ||
| 3092 | double | ||
| 3093 | </td> | ||
| 3094 | </tr> | ||
| 3095 | </table> | ||
| 3096 | |||
| 3097 | =end html | ||
| 3098 | |||
| 3099 | A boxing conversion creates a new numeric object corresponding to its numeric type, and copyes the value of the numeric type to the C<value> field of the new numeric object, and return the new numeric object. | ||
| 3100 | |||
| 3101 | =head3 Unboxing Conversion | ||
| 3102 | |||
| 3103 | The unboxing conversion is the type coversion from an object of a L<numeric object type|SPVM::Document::Language::Types/"Numeric Object Types"> to the value of its corresponding L<numeric type|SPVM::Document::Language::Types/"Numeric Types">. | ||
| 3104 | |||
| 3105 | =begin html | ||
| 3106 | |||
| 3107 | <table> | ||
| 3108 | <tr> | ||
| 3109 | <th> | ||
| 3110 | To | ||
| 3111 | </th> | ||
| 3112 | <th> | ||
| 3113 | From | ||
| 3114 | </th> | ||
| 3115 | </tr> | ||
| 3116 | <tr> | ||
| 3117 | <td> | ||
| 3118 | byte, short, int, long, float, double | ||
| 3119 | </td> | ||
| 3120 | <td> | ||
| 3121 | <a href="https://metacpan.org/pod/SPVM::Byte">Byte</a> | ||
| 3122 | </td> | ||
| 3123 | </tr> | ||
| 3124 | <tr> | ||
| 3125 | <td> | ||
| 3126 | byte, short, int, long, float, double | ||
| 3127 | </td> | ||
| 3128 | <td> | ||
| 3129 | <a href="https://metacpan.org/pod/SPVM::Short">Short</a> | ||
| 3130 | </td> | ||
| 3131 | </tr> | ||
| 3132 | <tr> | ||
| 3133 | <td> | ||
| 3134 | byte, short, int, long, float, double | ||
| 3135 | </td> | ||
| 3136 | <td> | ||
| 3137 | <a href="https://metacpan.org/pod/SPVM::Int">Int</a> | ||
| 3138 | </td> | ||
| 3139 | </tr> | ||
| 3140 | <tr> | ||
| 3141 | <td> | ||
| 3142 | byte, short, int, long, float, double | ||
| 3143 | </td> | ||
| 3144 | <td> | ||
| 3145 | <a href="https://metacpan.org/pod/SPVM::Long">Long</a> | ||
| 3146 | </td> | ||
| 3147 | </tr> | ||
| 3148 | <tr> | ||
| 3149 | <td> | ||
| 3150 | byte, short, int, long, float, double | ||
| 3151 | </td> | ||
| 3152 | <td> | ||
| 3153 | <a href="https://metacpan.org/pod/SPVM::Float">Float</a> | ||
| 3154 | </td> | ||
| 3155 | </tr> | ||
| 3156 | <tr> | ||
| 3157 | <td> | ||
| 3158 | byte, short, int, long, float, double | ||
| 3159 | </td> | ||
| 3160 | <td> | ||
| 3161 | <a href="https://metacpan.org/pod/SPVM::Double">Double</a> | ||
| 3162 | </td> | ||
| 3163 | </tr> | ||
| 3164 | </table> | ||
| 3165 | |||
| 3166 | =end html | ||
| 3167 | |||
| 3168 | If the destination numeric type is bigger than the source numeric type, L<Numeric Widening Conversion|https://metacpan.org/pod/SPVM::Document::Language::Operators#Numeric-Widening-Conversion> is performed. | ||
| 3169 | |||
| 3170 | If the destination numeric type is smaller than the source numeric type, L<Numeric Narrowing Conversion|https://metacpan.org/pod/SPVM::Document::Language::Operators#Numeric-Narrowing-Conversion> is performed. | ||
| 3171 | |||
| 3172 | An unboxing conversion could be performed on the object of any object type C<object>. | ||
| 3173 | |||
| 3174 | If the sorce type is C<undef> type, 0 is returned. | ||
| 3175 | |||
| 3176 | Exceptions: | ||
| 3177 | |||
| 3178 | If the type of the object is not its corresponding numeric type, an exception is thrown. | ||
| 3179 | |||
| 3180 | =over 2 | ||
| 3181 | |||
| 3182 | =item * The right operand of L<assignment operator|SPVM::Document::Language::Operators/"Assignment Operator">. | ||
| 3183 | |||
| 3184 | =item * Arguments given to a L<method call|SPVM::Document::Language::Operators/"Method Call"> | ||
| 3185 | |||
| 3186 | =item * A return value given to L<return statement|SPVM::Document::Language::Statements/"return Statement"> | ||
| 3187 | |||
| 3188 | =back | ||
| 3189 | |||
| 3190 | What type combinations cause implicit data conversions is explained in L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement">. | ||
| 3191 | |||
| 3192 | Examples: | ||
| 3193 | |||
| 3194 | # Assignment operators | ||
| 3195 | # int to double | ||
| 3196 | my $number : double = 5; | ||
| 3197 | |||
| 3198 | # double to Double | ||
| 3199 | my $number_object : Double = 5.1; | ||
| 3200 | |||
| 3201 | # Double to double | ||
| 3202 | my $number : double = Double->new(5.1); | ||
| 3203 | |||
| 3204 | # int to string | ||
| 3205 | my $string : string = 4; | ||
| 3206 | |||
| 3207 | # Method call | ||
| 3208 | # int to double | ||
| 3209 | my $double_object = Double->new(3); | ||
| 3210 | |||
| 3211 | # Return value | ||
| 3212 | method my_method : double () { | ||
| 3213 | |||
| 3214 | # int to double | ||
| 3215 | return 3; | ||
| 3216 | } | ||
| 3217 | |||
| 3218 | =head2 Type Cast | ||
| 3219 | |||
| 3220 | A type cast converts a value from its type to another type. | ||
| 3221 | |||
| 3222 | # A type cast | ||
| 3223 | (TYPE)OPERAND | ||
| 3224 | |||
| 3225 | # A postfix type cast | ||
| 3226 | OPERAND->(TYPE) | ||
| 3227 | |||
| 3228 | The return type is I<TYPE>. | ||
| 3229 | |||
| 3230 | If a data conversion is needed in the type cast, a type cast performs a data conversion on I<OPERAND>, and returns the value after the data conversion. | ||
| 3231 | |||
| 3232 | Otherwise it returns I<OPERAND>. | ||
| 3233 | |||
| 3234 | If a data check is needed in the type cast, a type cast performs a data check on I<OPERAND>. | ||
| 3235 | |||
| 3236 | Data conversions and data checks in type casts are explained in L<Cast Requirement|SPVM::Document::Language::Types/"Cast Requirement">. | ||
| 3237 | |||
| 3238 | Exceptions: | ||
| 3239 | |||
| 3240 | If a data check returns 0, an exception is thrown. | ||
| 3241 | |||
| 3242 | Compilation Errors: | ||
| 3243 | |||
| 3244 | I<OPERAND> must satisfy L<cast requirement|SPVM::Document::Language::Types/"Cast Requirement">. Otherwise, a compilation error occurs. | ||
| 3245 | |||
| 3246 | Examples: | ||
| 3247 | |||
| 3248 | # Examples of the type cast | ||
| 3249 | |||
| 3250 | # long to int | ||
| 3251 | my $num = (int)123L; | ||
| 3252 | |||
| 3253 | # byte[] to string | ||
| 3254 | my $num = (string)new byte[3]; | ||
| 3255 | |||
| 3256 | # string to byte[] | ||
| 3257 | my $num = (byte[])"Hello"; | ||
| 3258 | |||
| 3259 | # Postfix type cast | ||
| 3260 | my $stringable = Point->new->(Stringable); | ||
| 3261 | |||
| 3262 | =head2 isa Operator | ||
| 3263 | |||
| 3264 | The C<isa> operator checks whether an operand can be assigned to a type. | ||
| 3265 | |||
| 3266 | OPERAND isa TYPE | ||
| 3267 | $@ isa TYPE_WITHOUT_STRING | ||
| 3268 | |||
| 3269 | If the type I<TYPE> is a numeric type, a multi-numeric type, a reference type, this operator checks L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement"> without data convertion. | ||
| 3270 | |||
| 3271 | If the assignment requirement is satisfied, this operator returns 1, otherwise returns 0. | ||
| 3272 | |||
| 3273 | If I<TYPE> is an object type, this operator checks L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement"> at runtime. | ||
| 3274 | |||
| 3275 | If the assignment requirement at runtime is satisfied, this operator returns 1, otherwise returns 0. | ||
| 3276 | |||
| 3277 | The return type is int type. | ||
| 3278 | |||
| 3279 | If the left operand is $@ and the right type is not string type, a special interpretation is applied. | ||
| 3280 | |||
| 3281 | $@ isa TYPE_WITHOUT_STRING | ||
| 3282 | |||
| 3283 | is replaced with | ||
| 3284 | |||
| 3285 | $@ && eval_error_id isa_error TYPE_WITHOUT_STRING | ||
| 3286 | |||
| 3287 | See also L</"eval_error_id Operator"> and L</"isa_error Operator">. | ||
| 3288 | |||
| 3289 | Compilation Errors: | ||
| 3290 | |||
| 3291 | The right type I<TYPE> of isa operator must not be any object type. Otherwise, a compilation error occurs. | ||
| 3292 | |||
| 3293 | The left operand type I<OPERAND> of isa operator must be an object type. Otherwise, a compilation error occurs. | ||
| 3294 | |||
| 3295 | Examples: | ||
| 3296 | |||
| 3297 | if ($value isa int) { | ||
| 3298 | |||
| 3299 | } | ||
| 3300 | |||
| 3301 | if ($value isa Point) { | ||
| 3302 | |||
| 3303 | } | ||
| 3304 | |||
| 3305 | if ($value isa Point3D) { | ||
| 3306 | |||
| 3307 | } | ||
| 3308 | |||
| 3309 | if ($value isa Stringable) { | ||
| 3310 | |||
| 3311 | } | ||
| 3312 | |||
| 3313 | if ($value isa int) { | ||
| 3314 | |||
| 3315 | } | ||
| 3316 | |||
| 3317 | if ($@ isa Error::System) { | ||
| 3318 | |||
| 3319 | } | ||
| 3320 | |||
| 3321 | =head2 is_type Operator | ||
| 3322 | |||
| 3323 | The C<is_type> operator checks if the type of an operand is equal to a type. | ||
| 3324 | |||
| 3325 | OPERAND is_type TYPE | ||
| 3326 | $@ is_type TYPE_WITHOUT_STRING | ||
| 3327 | |||
| 3328 | If the type I<TYPE> is a numeric type, a multi-numeric type, or a reference type, this operator checks if the compilation type of I<OPERAND> is equal to I<TYPE>. | ||
| 3329 | |||
| 3330 | If the check is true, this operator returns 1, otherwise returns 0. | ||
| 3331 | |||
| 3332 | If I<TYPE> is an object type, this operator checks if the runtime type of I<OPERAND> is equal to I<TYPE> at runtime. | ||
| 3333 | |||
| 3334 | If it is true, this operator returns 1, otherwise returns 0. | ||
| 3335 | |||
| 3336 | The return type is int type. | ||
| 3337 | |||
| 3338 | If the left operand is $@ and the right type is not string type, a special interpretation is applied. | ||
| 3339 | |||
| 3340 | $@ is_type TYPE_WITHOUT_STRING | ||
| 3341 | |||
| 3342 | is replaced with | ||
| 3343 | |||
| 3344 | $@ && eval_error_id is_error TYPE_WITHOUT_STRING | ||
| 3345 | |||
| 3346 | See also L</"eval_error_id Operator"> and L</"is_error Operator">. | ||
| 3347 | |||
| 3348 | Compilation Errors: | ||
| 3349 | |||
| 3350 | The right type I<TYPE> of is_type operator must not be any object type. Otherwise, a compilation error occurs. | ||
| 3351 | |||
| 3352 | The left operand type I<OPERAND> of is_type operator must be an object type. Otherwise, a compilation error occurs. | ||
| 3353 | |||
| 3354 | Examples: | ||
| 3355 | |||
| 3356 | if ($object is_type int) { | ||
| 3357 | |||
| 3358 | } | ||
| 3359 | |||
| 3360 | if ($object is_type Point) { | ||
| 3361 | |||
| 3362 | } | ||
| 3363 | |||
| 3364 | if ($object is_type int[]) { | ||
| 3365 | |||
| 3366 | } | ||
| 3367 | |||
| 3368 | if ($object is_type Stringable[]) { | ||
| 3369 | |||
| 3370 | } | ||
| 3371 | |||
| 3372 | if ($@ is_type Error::System) { | ||
| 3373 | |||
| 3374 | } | ||
| 3375 | |||
| 3376 | =head2 is_compile_type Operator | ||
| 3377 | |||
| 3378 | The C<is_compile_type> operator checks whether the compilation type of an operand is equal to a type. | ||
| 3379 | |||
| 3380 | OPERAND is_compile_type TYPE | ||
| 3381 | |||
| 3382 | If the compilation type of I<OPERAND> is equal to the type with type modifier I<TYPE>, returns 1. | ||
| 3383 | |||
| 3384 | If I<TYPE> is a generic type and I<TYPE> matches patially the compilation type of I<OPERAND> from the top, returns 1. | ||
| 3385 | |||
| 3386 | I<TYPE> must not contain union types. | ||
| 3387 | |||
| 3388 | Otherwise returns 0. | ||
| 3389 | |||
| 3390 | The return type is int type. | ||
| 3391 | |||
| 3392 | Examples: | ||
| 3393 | |||
| 3394 | { | ||
| 3395 | my $value : int; | ||
| 3396 | if ($value is_compile_type int) { | ||
| 3397 | # Pass | ||
| 3398 | } | ||
| 3399 | } | ||
| 3400 | |||
| 3401 | { | ||
| 3402 | my $object : object = new TestCase::Minimal; | ||
| 3403 | if ($object is_compile_type object) { | ||
| 3404 | # Pass | ||
| 3405 | } | ||
| 3406 | } | ||
| 3407 | |||
| 3408 | { | ||
| 3409 | my $value : Stringer = method : string () { return "aaa"; }; | ||
| 3410 | if ($value is_compile_type Stringer) { | ||
| 3411 | # Pass | ||
| 3412 | } | ||
| 3413 | } | ||
| 3414 | |||
| 3415 | { | ||
| 3416 | my $value : string; | ||
| 3417 | if ($value is_compile_type string) { | ||
| 3418 | # Pass | ||
| 3419 | } | ||
| 3420 | } | ||
| 3421 | |||
| 3422 | { | ||
| 3423 | my $value : mutable string; | ||
| 3424 | if ($value is_compile_type mutable string) { | ||
| 3425 | # Pass | ||
| 3426 | } | ||
| 3427 | } | ||
| 3428 | |||
| 3429 | { | ||
| 3430 | my $object = (Hash of List of string)undef; | ||
| 3431 | if ($object is_compile_type Hash of List of string) { | ||
| 3432 | # Pass | ||
| 3433 | } | ||
| 3434 | } | ||
| 3435 | |||
| 3436 | { | ||
| 3437 | my $object = (Hash of List of string)undef; | ||
| 3438 | if ($object is_compile_type Hash of List) { | ||
| 3439 | # Pass | ||
| 3440 | } | ||
| 3441 | } | ||
| 3442 | |||
| 3443 | { | ||
| 3444 | my $object = (Hash of List of string)undef; | ||
| 3445 | if ($object is_compile_type Hash) { | ||
| 3446 | # Pass | ||
| 3447 | } | ||
| 3448 | } | ||
| 3449 | |||
| 3450 | =head2 isa_error Operator | ||
| 3451 | |||
| 3452 | The C<isa_error> operator checks whether the type specified by a basic type ID can be assigned to a class type. This operator is normally used for error classes to check L</"eval_error_id Operator">. | ||
| 3453 | |||
| 3454 | OPERAND isa_error TYPE | ||
| 3455 | |||
| 3456 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on the operand I<OPERAND>. | ||
| 3457 | |||
| 3458 | And this operator checks whether the type specified by the basic type ID I<OPERAND> satisfies L<assignment requirement|SPVM::Document::Language::Types/"Assignment Requirement"> without data conversion to the type I<TYPE>. | ||
| 3459 | |||
| 3460 | If it is satisfied, this operator returns 1, otherwise returns 0. | ||
| 3461 | |||
| 3462 | The return type is int type. | ||
| 3463 | |||
| 3464 | Compilation Errors: | ||
| 3465 | |||
| 3466 | I<OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 3467 | |||
| 3468 | I<TYPE> must be a class type. Otherwise, a compilation error occurs. | ||
| 3469 | |||
| 3470 | Examples: | ||
| 3471 | |||
| 3472 | if (eval_error_id isa_error Error) { | ||
| 3473 | |||
| 3474 | } | ||
| 3475 | |||
| 3476 | if (eval_error_id isa_error Error::System) { | ||
| 3477 | |||
| 3478 | } | ||
| 3479 | |||
| 3480 | =head2 is_error Operator | ||
| 3481 | |||
| 3482 | The C<is_error> operator checks whether the type specified by a basic type ID is equal to a class type. This operator is normally used for error classes to check L</"eval_error_id Operator">. | ||
| 3483 | |||
| 3484 | OPERAND is_error TYPE | ||
| 3485 | |||
| 3486 | This operator performs L<integer promotional conversion|/"Integer Promotional Conversion"> on the operand I<OPERAND>. | ||
| 3487 | |||
| 3488 | And this operator checks whether the type specified by the basic type ID I<OPERAND> is equal to the type I<TYPE>. | ||
| 3489 | |||
| 3490 | If it is, this operator returns 1, otherwise returns 0. | ||
| 3491 | |||
| 3492 | The return type is int type. | ||
| 3493 | |||
| 3494 | Compilation Errors: | ||
| 3495 | |||
| 3496 | I<OPERAND> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 3497 | |||
| 3498 | I<TYPE> must be a class type. Otherwise, a compilation error occurs. | ||
| 3499 | |||
| 3500 | Examples: | ||
| 3501 | |||
| 3502 | if (eval_error_id is_error Error) { | ||
| 3503 | |||
| 3504 | } | ||
| 3505 | |||
| 3506 | if (eval_error_id is_error Error::System) { | ||
| 3507 | |||
| 3508 | } | ||
| 3509 | |||
| 3510 | =head2 type_name Operator | ||
| 3511 | |||
| 3512 | The C<type_name> operator gets the type name of the object. | ||
| 3513 | |||
| 3514 | type_name OPERAND | ||
| 3515 | |||
| 3516 | If the object I<OPERAND> is defined, creates a string with the type name of I<OPERAND> and returns it. Otherwise, returns an undefined value. | ||
| 3517 | |||
| 3518 | The return type is string type. | ||
| 3519 | |||
| 3520 | Compilation Errors. | ||
| 3521 | |||
| 3522 | I<OPERAND> must be an object type. Otherwise, a compilation error occurs. | ||
| 3523 | |||
| 3524 | type_name $@ | ||
| 3525 | |||
| 3526 | This is special case. Returns the return value of L</"eval_error_name"> operator. | ||
| 3527 | |||
| 3528 | Examples: | ||
| 3529 | |||
| 3530 | # "Point" | ||
| 3531 | my $point = Point->new; | ||
| 3532 | my $type_name = type_name $point; | ||
| 3533 | |||
| 3534 | # "Point" | ||
| 3535 | my $point = (object)Point->new; | ||
| 3536 | my $type_name = type_name $point; | ||
| 3537 | |||
| 3538 | # Such as Error::System | ||
| 3539 | my $error_name = type_name $@; | ||
| 3540 | |||
| 3541 | =head2 compile_type_name Operator | ||
| 3542 | |||
| 3543 | The C<compile_type_name> operator gets the compilation type of the operand I<OPERAND>. | ||
| 3544 | |||
| 3545 | compile_type_name OPERAND | ||
| 3546 | |||
| 3547 | This operator creates a new string with the compilation type name of I<OPERAND> and returns it. | ||
| 3548 | |||
| 3549 | The return type is string type. | ||
| 3550 | |||
| 3551 | Examples: | ||
| 3552 | |||
| 3553 | # Point | ||
| 3554 | my $point = Point->new; | ||
| 3555 | my $compile_type_name = type_name $point; | ||
| 3556 | |||
| 3557 | # object | ||
| 3558 | my $point = (object)Point->new; | ||
| 3559 | my $compile_type_name = type_name $point; | ||
| 3560 | |||
| 3561 | # mutable string | ||
| 3562 | my $string = (mutable string)copy "abc"; | ||
| 3563 | my $compile_type_name = compile_type_name $string; | ||
| 3564 | |||
| 3565 | # Hash of List of string | ||
| 3566 | my $object = (Hash of List of string)undef; | ||
| 3567 | my $compile_type_name = compile_type_name $object; | ||
| 3568 | |||
| 3569 | =head2 basic_type_id Operator | ||
| 3570 | |||
| 3571 | The C<basic_type_id> operator gets the basic type ID of a type. | ||
| 3572 | |||
| 3573 | basic_type_id TYPE | ||
| 3574 | |||
| 3575 | This operator returns the basic type ID of the type I<TYPE>. | ||
| 3576 | |||
| 3577 | The return type is int type. | ||
| 3578 | |||
| 3579 | Examples: | ||
| 3580 | |||
| 3581 | my $basic_type_id = basic_type_id int; | ||
| 3582 | |||
| 3583 | my $basic_type_id = basic_type_id int[]; | ||
| 3584 | |||
| 3585 | my $error_basic_type_id = basic_type_id Error; | ||
| 3586 | |||
| 3587 | =head2 can Operator | ||
| 3588 | |||
| 3589 | The C<can> operator checks if a method can be called. | ||
| 3590 | |||
| 3591 | OPERAND can METHOD_NAME | ||
| 3592 | |||
| 3593 | If I<OPERAND> is able to call the method given by I<METHOD_NAME>, returns 1, otherwise returns 0. | ||
| 3594 | |||
| 3595 | I<METHOD_NAME> is a L<method name|SPVM::Document::Language::Tokenization/"Method Name"> or an empty string C<"">. | ||
| 3596 | |||
| 3597 | The return type is int type. | ||
| 3598 | |||
| 3599 | Compilation Errors: | ||
| 3600 | |||
| 3601 | The type of I<OPERAND> must be the class type or L<interface type|SPVM::Document::Language::Types/"Interface Types">. Otherwise, a compilation error occurs. | ||
| 3602 | |||
| 3603 | The METHOD_NAME must be a method name or an empty string C<"">. Otherwise, a compilation error occurs. | ||
| 3604 | |||
| 3605 | Examples: | ||
| 3606 | |||
| 3607 | my $stringable = (Stringable)Point->new(1, 2); | ||
| 3608 | |||
| 3609 | if ($stringable can to_string) { | ||
| 3610 | # ... | ||
| 3611 | } | ||
| 3612 | |||
| 3613 | if ($stringable can "") { | ||
| 3614 | # ... | ||
| 3615 | } | ||
| 3616 | |||
| 3617 | =head2 args_width Operator | ||
| 3618 | |||
| 3619 | The C<args_width> operator gets the stack length of the arguments passed to the method. | ||
| 3620 | |||
| 3621 | args_width | ||
| 3622 | |||
| 3623 | Note that the stack length of the arguments is different from the length of the arguments. | ||
| 3624 | |||
| 3625 | If the method call is the instance method call, the stack length of the arguments is the length of the arguments + 1 for the invocant. | ||
| 3626 | |||
| 3627 | If an argument is a multi-numeric type, the stack length of the argument becomes the length of the fields. | ||
| 3628 | |||
| 3629 | Examples: | ||
| 3630 | |||
| 3631 | static method my_static_method : int ($args : int, $bar : int = 0) { | ||
| 3632 | my $args_width = args_width; | ||
| 3633 | |||
| 3634 | return $args_width; | ||
| 3635 | }; | ||
| 3636 | |||
| 3637 | # 1 | ||
| 3638 | &my_static_method(1); | ||
| 3639 | |||
| 3640 | # 2 | ||
| 3641 | &my_static_method(1, 2); | ||
| 3642 | |||
| 3643 | static method my_instance_method : int ($args : int, $bar : int = 0) { | ||
| 3644 | my $args_width = args_width; | ||
| 3645 | |||
| 3646 | return $args_width; | ||
| 3647 | }; | ||
| 3648 | |||
| 3649 | # 2 (1 + the invocant) | ||
| 3650 | &my_instance_method(1); | ||
| 3651 | |||
| 3652 | # 3 (2 + the invocant) | ||
| 3653 | &my_instance_method(1, 2); | ||
| 3654 | |||
| 3655 | static method my_mulnum_method : int ($z : Complex_2d, $bar : int = 0) { | ||
| 3656 | my $args_width = args_width; | ||
| 3657 | |||
| 3658 | return $args_width; | ||
| 3659 | }; | ||
| 3660 | |||
| 3661 | # 2 (The length of the fields of Complex_2d) | ||
| 3662 | my $z : Complex_2d; | ||
| 3663 | &my_mulnum_method($z); | ||
| 3664 | |||
| 3665 | # 3 (The length of the fields of Complex_2d + 1) | ||
| 3666 | my $z : Complex_2d; | ||
| 3667 | &my_mulnum_method($z, 2); | ||
| 3668 | |||
| 3669 | =head2 eval_error_id Operator | ||
| 3670 | |||
| 3671 | The C<eval_error_id> operatoer gets the value of C<eval_error_id>. | ||
| 3672 | |||
| 3673 | eval_error_id | ||
| 3674 | |||
| 3675 | See L<SPVM::Document::Language::ExceptionHandling> about the way to use the C<eval_error_id> operator. | ||
| 3676 | |||
| 3677 | =head2 eval_error_name Operator | ||
| 3678 | |||
| 3679 | The C<eval_error_name> operatoer gets the type name of C<eval_error_id>. | ||
| 3680 | |||
| 3681 | eval_error_name | ||
| 3682 | |||
| 3683 | =head2 weaken Operator | ||
| 3684 | |||
| 3685 | The C<weaken> operator enables a L<weak reference|SPVM::Document::Language::GarbageCollection/"Weak Reference">. | ||
| 3686 | |||
| 3687 | weaken INVOCANT->{FIELD_NAME}; | ||
| 3688 | |||
| 3689 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 3690 | |||
| 3691 | This operator enable a weak reference of the field specified by I<FIELD_NAME> of the type of I<INVOCANT>. | ||
| 3692 | |||
| 3693 | The return type is the void type. | ||
| 3694 | |||
| 3695 | Compilation Errors: | ||
| 3696 | |||
| 3697 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 3698 | |||
| 3699 | The incovant of the field access must be a class type. | ||
| 3700 | |||
| 3701 | The type of I<INVOCANT-E<gt>{FIELD_NAME}> must be an object type. Otherwise, a compilation error occurs. | ||
| 3702 | |||
| 3703 | Examples: | ||
| 3704 | |||
| 3705 | # Exmaples of weaken operator | ||
| 3706 | weaken $object->{point}; | ||
| 3707 | |||
| 3708 | =head2 unweaken Operator | ||
| 3709 | |||
| 3710 | The C<unweaken> operator disables a L<weak reference|SPVM::Document::Language::GarbageCollection/"Weak Reference">. | ||
| 3711 | |||
| 3712 | unweaken INVOCANT->{FIELD_NAME}; | ||
| 3713 | |||
| 3714 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 3715 | |||
| 3716 | This operator enable a weak reference of the field specified by I<FIELD_NAME> of the type of I<INVOCANT>. | ||
| 3717 | |||
| 3718 | The return type is the void type. | ||
| 3719 | |||
| 3720 | Compilation Errors: | ||
| 3721 | |||
| 3722 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 3723 | |||
| 3724 | The incovant of the field access must be a class type. | ||
| 3725 | |||
| 3726 | The type of I<INVOCANT-E<gt>{FIELD_NAME}> must be an object type. Otherwise, a compilation error occurs. | ||
| 3727 | |||
| 3728 | Examples: | ||
| 3729 | |||
| 3730 | # Exmaples of unweaken operator | ||
| 3731 | unweaken $object->{point}; | ||
| 3732 | |||
| 3733 | =head2 isweak Operator | ||
| 3734 | |||
| 3735 | The C<isweak> operator checks if L<weak reference|SPVM::Document::Language::GarbageCollection/"Weak Reference"> of a field is enabled. | ||
| 3736 | |||
| 3737 | isweak INVOCANT->{FIELD_NAME}; | ||
| 3738 | |||
| 3739 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 3740 | |||
| 3741 | If the field specified by I<FIELD_NAME> of the object I<INVOCANT> is weaken, this operator returns 1, otherwise returns 0. | ||
| 3742 | |||
| 3743 | The return type is int type. | ||
| 3744 | |||
| 3745 | Compilation Errors: | ||
| 3746 | |||
| 3747 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 3748 | |||
| 3749 | The incovant of the field access must be a class type. | ||
| 3750 | |||
| 3751 | The type of I<INVOCANT-E<gt>{FIELD_NAME}> must be an object type. Otherwise, a compilation error occurs. | ||
| 3752 | |||
| 3753 | Examples: | ||
| 3754 | |||
| 3755 | # Exmaples of isweak operator | ||
| 3756 | my $isweak = isweak $object->{point}; | ||
| 3757 | |||
| 3758 | =head2 exists Operator | ||
| 3759 | |||
| 3760 | The C<exists> operator checks if a field value exists. | ||
| 3761 | |||
| 3762 | exists INVOCANT->{FIELD_NAME}; | ||
| 3763 | |||
| 3764 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 3765 | |||
| 3766 | If the field specified by I<FIELD_NAME> of the object I<INVOCANT> exists, this operator returns 1, otherwise returns 0. | ||
| 3767 | |||
| 3768 | The return type is int type. | ||
| 3769 | |||
| 3770 | Compilation Errors: | ||
| 3771 | |||
| 3772 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 3773 | |||
| 3774 | The incovant of the field access must be a class type. | ||
| 3775 | |||
| 3776 | The type of I<INVOCANT-E<gt>{FIELD_NAME}> must be an object type or a numeric type. Otherwise, a compilation error occurs. | ||
| 3777 | |||
| 3778 | Examples: | ||
| 3779 | |||
| 3780 | # Exmaples of exists operator | ||
| 3781 | my $exists = exists $object->{point}; | ||
| 3782 | |||
| 3783 | =head2 delete Operator | ||
| 3784 | |||
| 3785 | The C<delete> operator delete a field value. | ||
| 3786 | |||
| 3787 | delete INVOCANT->{FIELD_NAME}; | ||
| 3788 | |||
| 3789 | The field existence flag is set to 0, and the value of the field is set to 0 in the case of numeric types or undef in the case of object types. | ||
| 3790 | |||
| 3791 | I<INVOCANT-E<gt>{FIELD_NAME}> is a L<field access|/"Field Access">. | ||
| 3792 | |||
| 3793 | This operator enable a weak reference of the field specified by I<FIELD_NAME> of the type of I<INVOCANT>. | ||
| 3794 | |||
| 3795 | The return type is the void type. | ||
| 3796 | |||
| 3797 | Compilation Errors: | ||
| 3798 | |||
| 3799 | Compiliation errors caused by the syntax of L<field access|/"Field Access"> could occur. | ||
| 3800 | |||
| 3801 | The incovant of the field access must be a class type. | ||
| 3802 | |||
| 3803 | The type of I<INVOCANT-E<gt>{FIELD_NAME}> must be an object type or a numeric type. Otherwise, a compilation error occurs. | ||
| 3804 | |||
| 3805 | Examples: | ||
| 3806 | |||
| 3807 | # Exmaples of delete operator | ||
| 3808 | delete $object->{point}; | ||
| 3809 | |||
| 3810 | =head2 copy_fields Operator | ||
| 3811 | |||
| 3812 | The C<copy_fields> operator copies fields. | ||
| 3813 | |||
| 3814 | copy_fields DIST_OPERAND, SRC_OPERAND, TYPE; | ||
| 3815 | |||
| 3816 | The type of I<TYPE> must be a class type. | ||
| 3817 | |||
| 3818 | The copy_fields operator copies every field from I<SRC_OPERAND> to I<DIST_OPERAND> using all the field names defined in I<TYPE> class. | ||
| 3819 | |||
| 3820 | For example, if the field names defined in I<TYPE> class are C<x>, C<y>, and C<z>, then copy_field operator is expanded to the following codes: | ||
| 3821 | |||
| 3822 | if (exists SRC_OPERAND->{x}) { | ||
| 3823 | DIST_OPERAND->{x} = SRC_OPERAND->{x}; | ||
| 3824 | } | ||
| 3825 | if (exists SRC_OPERAND->{y}) { | ||
| 3826 | DIST_OPERAND->{y} = SRC_OPERAND->{y}; | ||
| 3827 | } | ||
| 3828 | if (exists SRC_OPERAND->{z}) { | ||
| 3829 | DIST_OPERAND->{z} = SRC_OPERAND->{z}; | ||
| 3830 | } | ||
| 3831 | |||
| 3832 | Compilation Errors: | ||
| 3833 | |||
| 3834 | The type of I<TYPE> must be a class type. Otherwise, a compilation error occurs. | ||
| 3835 | |||
| 3836 | Examples: | ||
| 3837 | |||
| 3838 | # Exampels of copy_fields operator | ||
| 3839 | my $object = MyClass->new; | ||
| 3840 | |||
| 3841 | my $object_child = MyClass::Child->new; | ||
| 3842 | |||
| 3843 | copy_fields $object_child, $object, MyClass; | ||
| 3844 | |||
| 3845 | =head2 set_length Operator | ||
| 3846 | |||
| 3847 | The C<set_length> operator sets the length of a string or an array. | ||
| 3848 | |||
| 3849 | set_length(OBJECT_OPERAND, LENGTH_OPERAND); | ||
| 3850 | |||
| 3851 | The type of I<OBJECT_OPERAND> must be a string or an array. | ||
| 3852 | |||
| 3853 | The type of I<LENGTH_OPERAND> is an integer value with C<int>. | ||
| 3854 | |||
| 3855 | If the length is extended, L</"set_capacity Operator"> is called if needed. | ||
| 3856 | |||
| 3857 | If the length is extended, the extended elements are set to its default value. | ||
| 3858 | |||
| 3859 | If the length is shorten, unused elements is destroyed. | ||
| 3860 | |||
| 3861 | Compilation Errors: | ||
| 3862 | |||
| 3863 | I<OBJECT_OPERAND> type must be an array type or string type. Otherwise a compilation error occurs. | ||
| 3864 | |||
| 3865 | I<OBJECT_OPERAND> type must be an integer type. Otherwise a compilation error occurs. | ||
| 3866 | |||
| 3867 | I<LENGTH_OPERAND> type must be an integer type. Otherwise a compilation error occurs. | ||
| 3868 | |||
| 3869 | Exceptions: | ||
| 3870 | |||
| 3871 | I<OBJECT_OPERAND> must be defined. Otherwise an exception is thrown. | ||
| 3872 | |||
| 3873 | the type of I<OBJECT_OPERAND> must be string type or an array type. Otherwise an exception is thrown. | ||
| 3874 | |||
| 3875 | I<OBJECT_OPERAND> must not be a fixed length object. If so, an exception is thrown. | ||
| 3876 | |||
| 3877 | Examples: | ||
| 3878 | |||
| 3879 | # Examples of set_length operator | ||
| 3880 | my $string = (mutable string)copy "abc"; | ||
| 3881 | |||
| 3882 | set_length($string, 4); | ||
| 3883 | |||
| 3884 | =head2 set_capacity Operator | ||
| 3885 | |||
| 3886 | The C<set_capacity> operator sets the capacity of a string or an array. | ||
| 3887 | |||
| 3888 | set_capacity(OBJECT_OPERAND, CAPACITY_OPERAND); | ||
| 3889 | |||
| 3890 | The type of I<OBJECT_OPERAND> must be a string or an array. | ||
| 3891 | |||
| 3892 | The type of I<CAPACITY_OPERAND> is an integer value with C<int>. | ||
| 3893 | |||
| 3894 | The new capacity is allocated and old elements are copied on it. | ||
| 3895 | |||
| 3896 | Compilation Errors: | ||
| 3897 | |||
| 3898 | I<OBJECT_OPERAND> type must be an array type or string type. Otherwise a compilation error occurs. | ||
| 3899 | |||
| 3900 | I<OBJECT_OPERAND> type must be an integer type. Otherwise a compilation error occurs. | ||
| 3901 | |||
| 3902 | I<CAPACITY_OPERAND> type must be an integer type. Otherwise a compilation error occurs. | ||
| 3903 | |||
| 3904 | Exceptions: | ||
| 3905 | |||
| 3906 | I<OBJECT_OPERAND> must be defined. Otherwise an exception is thrown. | ||
| 3907 | |||
| 3908 | The type of I<OBJECT_OPERAND> must be string type or an array type. Otherwise an exception is thrown. | ||
| 3909 | |||
| 3910 | I<OBJECT_OPERAND> must not be a fixed capacity object. If so, an exception is thrown. | ||
| 3911 | |||
| 3912 | If this operator cannot allocate memory, an exception is thrown. | ||
| 3913 | |||
| 3914 | If I<CAPACITY_OPERAND> is smaller capacity than its length plus 1, an exception is thrown. | ||
| 3915 | |||
| 3916 | Examples: | ||
| 3917 | |||
| 3918 | # Examples of set_capacity operator | ||
| 3919 | my $string = (mutable string)copy "abc"; | ||
| 3920 | |||
| 3921 | set_capacity($string, 4); | ||
| 3922 | |||
| 3923 | =head2 caller Operator | ||
| 3924 | |||
| 3925 | The C<caller> operator gets the information of the caller of the current method. | ||
| 3926 | |||
| 3927 | caller LEVEL | ||
| 3928 | caller | ||
| 3929 | |||
| 3930 | This operator returns a L<CallerInfo|SPVM::CallerInfo> object that contains the information of the caller at the level specified by I<LEVEL>. | ||
| 3931 | |||
| 3932 | If I<LEVEL> is omitted, it is treated as 0. | ||
| 3933 | |||
| 3934 | If the level is 0, it returns the information of the caller of the current method. | ||
| 3935 | |||
| 3936 | The return type is L<CallerInfo|SPVM::CallerInfo> class. | ||
| 3937 | |||
| 3938 | Exceptions: | ||
| 3939 | |||
| 3940 | If I<LEVEL> is less than 0, an exception is thrown. | ||
| 3941 | |||
| 3942 | If I<LEVEL> exceeds the call depth of methods, an exception is thrown. | ||
| 3943 | |||
| 3944 | Compilation Errors: | ||
| 3945 | |||
| 3946 | The type of I<LEVEL> must be an L<integer type|SPVM::Document::Language::Types/"Integer Types"> within int. Otherwise, a compilation error occurs. | ||
| 3947 | |||
| 3948 | Examples: | ||
| 3949 | |||
| 3950 | # Examples of the caller operator | ||
| 3951 | use CallerInfo; | ||
| 3952 | |||
| 3953 | # Get the caller information of the current method | ||
| 3954 | my $caller_info = caller; | ||
| 3955 | |||
| 3956 | # Get the absolute method name of the caller | ||
| 3957 | my $method_abs_name = $caller_info->method_abs_name; | ||
| 3958 | |||
| 3959 | # Get the file name of the caller | ||
| 3960 | my $file = $caller_info->file; | ||
| 3961 | |||
| 3962 | # Get the line number of the caller | ||
| 3963 | my $line = $caller_info->line; | ||
| 3964 | |||
| 3965 | =head2 break_point Operator | ||
| 3966 | |||
| 3967 | The C<break_point> operator sets a break point for debugging. | ||
| 3968 | |||
| 3969 | break_point; | ||
| 3970 | |||
| 3971 | This operator pauses the program execution as a break point and waits for a user input from the standard input. | ||
| 3972 | |||
| 3973 | If the user input is a newline character C<"\n"> or an EOF(End of File), the program execution resumes. | ||
| 3974 | |||
| 3975 | Otherwise, the program waits for a user input again. | ||
| 3976 | |||
| 3977 | The return type is C<void> type. | ||
| 3978 | |||
| 3979 | Examples: | ||
| 3980 | |||
| 3981 | # Set a break point for debugging | ||
| 3982 | break_point; | ||
| 3983 | |||
| 3984 | =head1 Scope Operations | ||
| 3985 | |||
| 3986 | See the doc of L<scope|SPVM::Document::Language::GarbageCollection/"Scope"> about scope operations. | ||
| 3987 | |||
| 3988 | =head1 Method Call | ||
| 3989 | |||
| 3990 | A method call is an L<operator|/"Operators"> to call a L<method|SPVM::Document::Language::Class/"Method">. | ||
| 3991 | |||
| 3992 | A method call resolves to one of the three types of method calls, a L<class method call|/"Class Method Call">, a L<static instance method call|/"Static Instance Method Call">, and an L<instance method call|/"Instance Method Call"> by L<method call resolution|SPVM::Document::Language::Class/"Method Call Resolution">. | ||
| 3993 | |||
| 3994 | If the method call is a static instance method call or an instance method call, the invocant is prepended to the given arguments. | ||
| 3995 | |||
| 3996 | The method call performs L<method call execution|/"Method Call Execution"> given the arguments. | ||
| 3997 | |||
| 3998 | =head2 Class Method Call | ||
| 3999 | |||
| 4000 | A class method call calls a class method. | ||
| 4001 | |||
| 4002 | CLASS_TYPE->METHOD_NAME | ||
| 4003 | CLASS_TYPE->METHOD_NAME(OPT_ARGS) | ||
| 4004 | &METHOD_NAME | ||
| 4005 | &METHOD_NAME(OPT_ARGS) | ||
| 4006 | |||
| 4007 | See L<Class Method Call Resolution|SPVM::Document::Language::Class/"Class Method Call Resolution"> about I<CLASS_TYPE>, I<METHOD_NAME>, I<OPT_ARGS>, C<&>, and the resolution of a class method call. | ||
| 4008 | |||
| 4009 | Examples: | ||
| 4010 | |||
| 4011 | # Examples of static instance method calls | ||
| 4012 | my $point3d = Point3D->new; | ||
| 4013 | |||
| 4014 | $point3d->Point::clear; | ||
| 4015 | |||
| 4016 | $point3d->SUPER::clear; | ||
| 4017 | |||
| 4018 | =head2 Static Instance Method Call | ||
| 4019 | |||
| 4020 | A static instance method call calls an instance method specifying a class. | ||
| 4021 | |||
| 4022 | INVOCANT->CLASS_TYPE::METHOD_NAME | ||
| 4023 | INVOCANT->CLASS_TYPE::METHOD_NAME(OPT_ARGS) | ||
| 4024 | |||
| 4025 | See L<Static Instance Method Call Resolution|SPVM::Document::Language::Class/"Static Instance Method Call Resolution"> about I<INVOCANT>, I<CLASS_TYPE>, I<METHOD_NAME>, I<OPT_ARGS>, and the resolution of a static instance method call. | ||
| 4026 | |||
| 4027 | Examples: | ||
| 4028 | |||
| 4029 | # Examples of static instance method calls | ||
| 4030 | $object->SUPER::bar(5, 3. 6); | ||
| 4031 | |||
| 4032 | $point3d->Point::clear; | ||
| 4033 | |||
| 4034 | =head2 Instance Method Call | ||
| 4035 | |||
| 4036 | An instance method call calls an instance method. | ||
| 4037 | |||
| 4038 | INVOCANT->METHOD_NAME | ||
| 4039 | INVOCANT->METHOD_NAME(OPT_ARGS) | ||
| 4040 | |||
| 4041 | See L<Instance Method Call Resolution|SPVM::Document::Language::Class/"Instance Method Call Resolution"> about I<INVOCANT>, I<CLASS_TYPE>, I<METHOD_NAME>, I<OPT_ARGS>, and the resolution of an instance method call. | ||
| 4042 | |||
| 4043 | Examples: | ||
| 4044 | |||
| 4045 | # Examples of instance method calls | ||
| 4046 | |||
| 4047 | my $point = Point->new; | ||
| 4048 | |||
| 4049 | $point->clear; | ||
| 4050 | |||
| 4051 | my $stringable = (Stringable)$point; | ||
| 4052 | |||
| 4053 | my $string = $strinble->to_string; | ||
| 4054 | |||
| 4055 | =head2 Method Call Execution | ||
| 4056 | |||
| 4057 | The L<argument width|SPVM::Document::NativeClass/"Arguments Width"> is stored to L<runtime stack|SPVM::Document::NativeClass/"Runtime Stack">. | ||
| 4058 | |||
| 4059 | The call stack depth stored in L<runtime stack|SPVM::Document::NativeClass/"Runtime Stack"> is incremented by 1. | ||
| 4060 | |||
| 4061 | If the call stack depth is greater than 1000, an exception is thrown. | ||
| 4062 | |||
| 4063 | If the method call is not a class method call, the arugments of the object type are checked whether the following L<isa|/"isa Operator"> operator returns a true value. | ||
| 4064 | |||
| 4065 | ARG isa TYPE_OF_ARG | ||
| 4066 | |||
| 4067 | I<ARG> is an argument. I<TYPE_OF_ARG> is the type of the corresponding arugment of the method. | ||
| 4068 | |||
| 4069 | If the return vlaue is not a true value, an exception is thrown. | ||
| 4070 | |||
| 4071 | If the method is a L<INIT method|SPVM::Document::Language::Class/"INIT Method"> and it is already called, nothing is performed. | ||
| 4072 | |||
| 4073 | If the method is a L<native method|SPVM::Document::Language::Class/"Native Method">, a L<native method call execution|/"Native Method Call Execution"> is performed. | ||
| 4074 | |||
| 4075 | Otherwise if the method is a L<precompilation method|SPVM::Document::Language::Class/"Precompilation Method">, a L<precompilation method call execution|/"Precompilation Method Call Execution"> is performed. | ||
| 4076 | |||
| 4077 | Otherwise a L<VM method call execution|/"VM Method Call Execution"> is performed. | ||
| 4078 | |||
| 4079 | If an exception is thrown by the method call execution, the exception is thrown. | ||
| 4080 | |||
| 4081 | If the return type of the method is an object type, the object is pushed to L<native mortal stack|SPVM::Document::NativeClass/"Native Mortal Stack">. | ||
| 4082 | |||
| 4083 | The call stack depth stored in L<runtime stack|SPVM::Document::NativeClass/"Runtime Stack"> is decremented by 1. This resotre is always performed even if an excetpion is thrown. | ||
| 4084 | |||
| 4085 | =head3 VM Method Call Execution | ||
| 4086 | |||
| 4087 | Heap memories for local variables are allocated. | ||
| 4088 | |||
| 4089 | The L<enter_scope|SPVM::Document::NativeAPI/"enter_scope"> native API is called. | ||
| 4090 | |||
| 4091 | SPVM operation codes generated from L<method implementation|SPVM::Document::Language::Class/"Method Implementation"> are executed. | ||
| 4092 | |||
| 4093 | The L<leave_scope|SPVM::Document::NativeAPI/"leave_scope"> native API is called. | ||
| 4094 | |||
| 4095 | Heap memories for local variables are released. | ||
| 4096 | |||
| 4097 | =head3 Precompilation Method Call Execution | ||
| 4098 | |||
| 4099 | If a set of the machine codes of the precompilation method is loaded, the program executes it. | ||
| 4100 | |||
| 4101 | Otherwise if L<is_precompile_fallback|SPVM::Document::NativeAPI::Method/"is_precompile_fallback"> native API returns a true value, the program executes L</"VM Method Call Execution">. | ||
| 4102 | |||
| 4103 | Otherwise an exception is thrown. | ||
| 4104 | |||
| 4105 | =head3 Native Method Call Execution | ||
| 4106 | |||
| 4107 | The L<enter_scope|SPVM::Document::NativeAPI/"enter_scope"> native API is called. | ||
| 4108 | |||
| 4109 | If a set of the machine codes of L<native function|SPVM::Document::NativeClass/"Native Function"> of the native method is loaded, the program executes it. | ||
| 4110 | |||
| 4111 | Otherwise an exception is thrown after executing the following code. | ||
| 4112 | |||
| 4113 | The L<leave_scope|SPVM::Document::NativeAPI/"leave_scope"> native API is called. | ||
| 4114 | |||
| 4115 | =head1 See Also | ||
| 4116 | |||
| 4117 | =over 2 | ||
| 4118 | |||
| 4119 | =item * L<Class Definition|SPVM::Document::Language::Statements> | ||
| 4120 | |||
| 4121 | =item * L<Class Definition|SPVM::Document::Language::Class> | ||
| 4122 | |||
| 4123 | =item * L<Types|SPVM::Document::Language::Types> | ||
| 4124 | |||
| 4125 | =item * L<Exception Handling|SPVM::Document::Language::ExceptionHandling> | ||
| 4126 | |||
| 4127 | =item * L<Garbage Collection|SPVM::Document::Language::GarbageCollection> | ||
| 4128 | |||
| 4129 | =item * L<SPVM::Document::Language> | ||
| 4130 | |||
| 4131 | =item * L<SPVM::Document> | ||
| 4132 | |||
| 4133 | =back | ||
| 4134 | |||
| 4135 | =head1 Copyright & License | ||
| 4136 | |||
| 4137 | Copyright (c) 2023 Yuki Kimoto | ||
| 4138 | |||
| 4139 | MIT License |