Commit ac091d40988ebb00b87d4e56311db6f309d37bdf
- Diff rendering mode:
- inline
- side by side
src/lib/Glue.pir
(0 / 58)
|   | |||
| 1 | 1 | ||
| 2 | =begin | ||
| 3 | |||
| 4 | 2 | =head1 NAME | |
| 5 | 3 | ||
| 6 | 4 | Glue.pir - Rakudo "glue" builtins (functions/globals) converted for NQP | |
| … | … | ||
| 60 | 60 | our $OS; | |
| 61 | 61 | our $OSVER; | |
| 62 | 62 | ||
| 63 | =end | ||
| 64 | 63 | ||
| 65 | 64 | .namespace [] | |
| 66 | 65 | ||
| … | … | ||
| 67 | 67 | .include 'sysinfo.pasm' | |
| 68 | 68 | .include 'iglobals.pasm' | |
| 69 | 69 | ||
| 70 | =begin | ||
| 71 | 70 | ||
| 72 | 71 | =head1 DESCRIPTION | |
| 73 | 72 | ||
| … | … | ||
| 80 | 80 | the status code of the spawned process, which is equal the the result | |
| 81 | 81 | of the waitpid system call, right bitshifted by 8. | |
| 82 | 82 | ||
| 83 | =end | ||
| 84 | 83 | ||
| 85 | 84 | .sub 'run' | |
| 86 | 85 | .param pmc command_and_args :slurpy | |
| … | … | ||
| 94 | 94 | .return (status) | |
| 95 | 95 | .end | |
| 96 | 96 | ||
| 97 | =begin | ||
| 98 | 97 | ||
| 99 | 98 | =item $success := do_run($command, $and, $args, ...) | |
| 100 | 99 | ||
| … | … | ||
| 101 | 101 | arguments as a new process; return 1 if the process exited successfully, or | |
| 102 | 102 | 0 if not. | |
| 103 | 103 | ||
| 104 | =end | ||
| 105 | 104 | ||
| 106 | 105 | .sub 'do_run' | |
| 107 | 106 | .param pmc command_and_args :slurpy | |
| … | … | ||
| 118 | 118 | .return (0) | |
| 119 | 119 | .end | |
| 120 | 120 | ||
| 121 | =begin | ||
| 122 | 121 | ||
| 123 | 122 | =item $output := qx($command, $and, $args, ...) | |
| 124 | 123 | ||
| … | … | ||
| 126 | 126 | ||
| 127 | 127 | B<WARNING>: Parrot currently implements this B<INSECURELY>! | |
| 128 | 128 | ||
| 129 | =end | ||
| 130 | 129 | ||
| 131 | 130 | .sub 'qx' | |
| 132 | 131 | .param pmc command_and_args :slurpy | |
| … | … | ||
| 150 | 150 | die $S0 | |
| 151 | 151 | .end | |
| 152 | 152 | ||
| 153 | =begin | ||
| 154 | 153 | ||
| 155 | 154 | =item die($message) | |
| 156 | 155 | ||
| 157 | 156 | Kill program, reporting error C<$message>. | |
| 158 | 157 | ||
| 159 | =end | ||
| 160 | 158 | ||
| 161 | 159 | .sub 'die' | |
| 162 | 160 | .param string message | |
| … | … | ||
| 162 | 162 | die message | |
| 163 | 163 | .end | |
| 164 | 164 | ||
| 165 | =begin | ||
| 166 | 165 | ||
| 167 | 166 | =item $ret := try(&code, @args [, &handler]) | |
| 168 | 167 | ||
| … | … | ||
| 174 | 174 | catch($ex) { $ret := &handler ?? &handler($ex, &code, @args) !! 0 } | |
| 175 | 175 | return $ret; | |
| 176 | 176 | ||
| 177 | =end | ||
| 178 | 177 | ||
| 179 | 178 | .sub 'try' | |
| 180 | 179 | .param pmc code | |
| … | … | ||
| 198 | 198 | .return (0) | |
| 199 | 199 | .end | |
| 200 | 200 | ||
| 201 | =begin | ||
| 202 | 201 | ||
| 203 | 202 | =item @keys := keys(%hash) | |
| 204 | 203 | ||
| 205 | 204 | Return an array containing the keys of the C<%hash>. | |
| 206 | 205 | ||
| 207 | =end | ||
| 208 | 206 | ||
| 209 | 207 | .sub 'keys' | |
| 210 | 208 | .param pmc hash | |
| … | … | ||
| 223 | 223 | .return(key_list) | |
| 224 | 224 | .end | |
| 225 | 225 | ||
| 226 | =begin | ||
| 227 | 226 | ||
| 228 | 227 | =item $found := exists(%hash, $key) | |
| 229 | 228 | ||
| 230 | 229 | Determine if C<$key> exists in C<%hash>, returning a true value if so, and a | |
| 231 | 230 | false value if not. | |
| 232 | 231 | ||
| 233 | =end | ||
| 234 | 232 | ||
| 235 | 233 | .sub 'exists' | |
| 236 | 234 | .param pmc hash | |
| … | … | ||
| 239 | 239 | .return($I0) | |
| 240 | 240 | .end | |
| 241 | 241 | ||
| 242 | =begin | ||
| 243 | 242 | ||
| 244 | 243 | =item $does_role := does($object, $role) | |
| 245 | 244 | ||
| 246 | 245 | Determine if C<$object> does the C<$role>, returning a true value if so, and a | |
| 247 | 246 | false value if not. | |
| 248 | 247 | ||
| 249 | =end | ||
| 250 | 248 | ||
| 251 | 249 | .sub 'does' | |
| 252 | 250 | .param pmc object | |
| … | … | ||
| 255 | 255 | .return($I0) | |
| 256 | 256 | .end | |
| 257 | 257 | ||
| 258 | =begin | ||
| 259 | 258 | ||
| 260 | 259 | =item $contents := slurp($filename) | |
| 261 | 260 | ||
| 262 | 261 | Read the C<$contents> of a file as a single string. | |
| 263 | 262 | ||
| 264 | =end | ||
| 265 | 263 | ||
| 266 | 264 | .sub 'slurp' | |
| 267 | 265 | .param string filename | |
| … | … | ||
| 271 | 271 | .return(contents) | |
| 272 | 272 | .end | |
| 273 | 273 | ||
| 274 | =begin | ||
| 275 | 274 | ||
| 276 | 275 | =item spew($filename, $contents) | |
| 277 | 276 | ||
| 278 | 277 | Write the string C<$contents> to a file. | |
| 279 | 278 | ||
| 280 | =end | ||
| 281 | 279 | ||
| 282 | 280 | .sub 'spew' | |
| 283 | 281 | .param string filename | |
| … | … | ||
| 286 | 286 | close $P0 | |
| 287 | 287 | .end | |
| 288 | 288 | ||
| 289 | =begin | ||
| 290 | 289 | ||
| 291 | 290 | =item append($filename, $contents) | |
| 292 | 291 | ||
| 293 | 292 | Append the string C<$contents> to a file. | |
| 294 | 293 | ||
| 295 | =end | ||
| 296 | 294 | ||
| 297 | 295 | .sub 'append' | |
| 298 | 296 | .param string filename | |
| … | … | ||
| 301 | 301 | close $P0 | |
| 302 | 302 | .end | |
| 303 | 303 | ||
| 304 | =begin | ||
| 305 | 304 | ||
| 306 | 305 | =item $regex_object := rx($regex_source) | |
| 307 | 306 | ||
| … | … | ||
| 308 | 308 | Perl 6 Regex) into a C<$regex_object>, suitable for using in C<match()> and | |
| 309 | 309 | C<subst()>. | |
| 310 | 310 | ||
| 311 | =end | ||
| 312 | 311 | ||
| 313 | 312 | .sub 'rx' | |
| 314 | 313 | .param string source | |
| … | … | ||
| 319 | 319 | .return(object) | |
| 320 | 320 | .end | |
| 321 | 321 | ||
| 322 | =begin | ||
| 323 | 322 | ||
| 324 | 323 | =item @matches := all_matches($regex, $text) | |
| 325 | 324 | ||
| 326 | 325 | Find all matches (C<:g> style, not C<:exhaustive>) for C<$regex> in the | |
| 327 | 326 | C<$text>. The C<$regex> must be a regex object returned by C<rx()>. | |
| 328 | 327 | ||
| 329 | =end | ||
| 330 | 328 | ||
| 331 | 329 | .sub 'all_matches' | |
| 332 | 330 | .param pmc regex | |
| … | … | ||
| 349 | 349 | .return(matches) | |
| 350 | 350 | .end | |
| 351 | 351 | ||
| 352 | =begin | ||
| 353 | 352 | ||
| 354 | 353 | =item $edited := subst($original, $regex, $replacement) | |
| 355 | 354 | ||
| … | … | ||
| 360 | 360 | with each match object in turn, and must return the proper replacement string | |
| 361 | 361 | for that match. | |
| 362 | 362 | ||
| 363 | =end | ||
| 364 | 363 | ||
| 365 | 364 | .sub 'subst' | |
| 366 | 365 | .param string original | |
| … | … | ||
| 407 | 407 | .return(edited) | |
| 408 | 408 | .end | |
| 409 | 409 | ||
| 410 | =begin | ||
| 411 | 410 | ||
| 412 | 411 | =item chdir($path) | |
| 413 | 412 | ||
| 414 | 413 | Change the current working directory to the specified C<$path>. | |
| 415 | 414 | ||
| 416 | =end | ||
| 417 | 415 | ||
| 418 | 416 | .sub 'chdir' | |
| 419 | 417 | .param string path | |
| … | … | ||
| 421 | 421 | os.'chdir'(path) | |
| 422 | 422 | .end | |
| 423 | 423 | ||
| 424 | =begin | ||
| 425 | 424 | ||
| 426 | 425 | =item $path := cwd() | |
| 427 | 426 | ||
| 428 | 427 | Return the current working directory. | |
| 429 | 428 | ||
| 430 | =end | ||
| 431 | 429 | ||
| 432 | 430 | .sub 'cwd' | |
| 433 | 431 | .local pmc os | |
| … | … | ||
| 437 | 437 | .return(path) | |
| 438 | 438 | .end | |
| 439 | 439 | ||
| 440 | =begin | ||
| 441 | 440 | ||
| 442 | 441 | =item mkdir($path [, $mode]) | |
| 443 | 442 | ||
| … | … | ||
| 444 | 444 | optional and defaults to octal C<777> (full permissions) if absent. C<$mode> | |
| 445 | 445 | is modified by the user's current C<umask> as usual. | |
| 446 | 446 | ||
| 447 | =end | ||
| 448 | 447 | ||
| 449 | 448 | .sub 'mkdir' | |
| 450 | 449 | .param string path | |
| … | … | ||
| 459 | 459 | os.'mkdir'(path, mode) | |
| 460 | 460 | .end | |
| 461 | 461 | ||
| 462 | =begin | ||
| 463 | 462 | ||
| 464 | 463 | =item unlink($path) | |
| 465 | 464 | ||
| 466 | 465 | Unlink (delete) a file or empty directory named C<$path> in the filesystem. | |
| 467 | 466 | ||
| 468 | =end | ||
| 469 | 467 | ||
| 470 | 468 | .sub 'unlink' | |
| 471 | 469 | .param string path | |
| … | … | ||
| 473 | 473 | os.'rm'(path) | |
| 474 | 474 | .end | |
| 475 | 475 | ||
| 476 | =begin | ||
| 477 | 476 | ||
| 478 | 477 | =item @info := stat($path) | |
| 479 | 478 | ||
| 480 | 479 | Returns a 13-item list of information about the given C<$path>, as in Perl 5. | |
| 481 | 480 | (See C<perldoc -f stat> for more details.) | |
| 482 | 481 | ||
| 483 | =end | ||
| 484 | 482 | ||
| 485 | 483 | .sub 'stat' | |
| 486 | 484 | .param string path | |
| … | … | ||
| 490 | 490 | .return (stat_list) | |
| 491 | 491 | .end | |
| 492 | 492 | ||
| 493 | =begin | ||
| 494 | 493 | ||
| 495 | 494 | =item $found := path_exists($path); | |
| 496 | 495 | ||
| 497 | 496 | Return a true value if the C<$path> exists on the filesystem, or a false | |
| 498 | 497 | value if not. | |
| 499 | 498 | ||
| 500 | =end | ||
| 501 | 499 | ||
| 502 | 500 | .sub 'path_exists' | |
| 503 | 501 | .param string path | |
| … | … | ||
| 511 | 511 | .return (0) | |
| 512 | 512 | .end | |
| 513 | 513 | ||
| 514 | =begin | ||
| 515 | 514 | ||
| 516 | 515 | =item @names := readdir($directory) | |
| 517 | 516 | ||
| 518 | 517 | List the names of all entries in the C<$directory>. | |
| 519 | 518 | ||
| 520 | =end | ||
| 521 | 519 | ||
| 522 | 520 | .sub 'readdir' | |
| 523 | 521 | .param string dir | |
| … | … | ||
| 527 | 527 | .return (names) | |
| 528 | 528 | .end | |
| 529 | 529 | ||
| 530 | =begin | ||
| 531 | 530 | ||
| 532 | 531 | =item $path := fscat(@path_parts [, $filename]) | |
| 533 | 532 | ||
| … | … | ||
| 535 | 535 | trailing slash (though slashes inside the C<@path_parts> will not be removed, | |
| 536 | 536 | so don't do that). | |
| 537 | 537 | ||
| 538 | =end | ||
| 539 | 538 | ||
| 540 | 539 | .sub 'fscat' | |
| 541 | 540 | .param pmc parts | |
| … | … | ||
| 557 | 557 | .return (joined) | |
| 558 | 558 | .end | |
| 559 | 559 | ||
| 560 | =begin | ||
| 561 | 560 | ||
| 562 | 561 | =item $joined := join($delimiter, @strings) | |
| 563 | 562 | ||
| 564 | 563 | Join C<@strings> together with the specified C<$delimiter>. | |
| 565 | 564 | ||
| 566 | =end | ||
| 567 | 565 | ||
| 568 | 566 | .sub 'join' | |
| 569 | 567 | .param string delim | |
| … | … | ||
| 573 | 573 | .return (joined) | |
| 574 | 574 | .end | |
| 575 | 575 | ||
| 576 | =begin | ||
| 577 | 576 | ||
| 578 | 577 | =item @pieces := split($delimiter, $original) | |
| 579 | 578 | ||
| 580 | 579 | Split the C<$original> string with the specified C<$delimiter>, which is not | |
| 581 | 580 | included in the resulting C<@pieces>. | |
| 582 | 581 | ||
| 583 | =end | ||
| 584 | 582 | ||
| 585 | 583 | .sub 'split' | |
| 586 | 584 | .param string delim | |
| … | … | ||
| 590 | 590 | .return (pieces) | |
| 591 | 591 | .end | |
| 592 | 592 | ||
| 593 | =begin | ||
| 594 | 593 | ||
| 595 | 594 | =item @array := as_array($list, $of, $items, ...) | |
| 596 | 595 | ||
| 597 | 596 | Slurp the list of arguments into an array and return it. | |
| 598 | 597 | ||
| 599 | =end | ||
| 600 | 598 | ||
| 601 | 599 | .sub 'as_array' | |
| 602 | 600 | .param pmc items :slurpy | |
| … | … | ||
| 602 | 602 | .return (items) | |
| 603 | 603 | .end | |
| 604 | 604 | ||
| 605 | =begin | ||
| 606 | 605 | ||
| 607 | 606 | =item $result := call_flattened(&code, $mixed, @args, $list, ...) | |
| 608 | 607 | ||
| … | … | ||
| 615 | 615 | ||
| 616 | 616 | call_flattened(&code, as_array(@protected), @will_flatten) | |
| 617 | 617 | ||
| 618 | =end | ||
| 619 | 618 | ||
| 620 | 619 | .sub 'call_flattened' | |
| 621 | 620 | .param pmc code | |
| … | … | ||
| 643 | 643 | .tailcall code(flattened :flat) | |
| 644 | 644 | .end | |
| 645 | 645 | ||
| 646 | =begin | ||
| 647 | |||
| 648 | 646 | =back | |
| 649 | 647 | ||
| 650 | 648 | ||
| … | … | ||
| 676 | 676 | ||
| 677 | 677 | =back | |
| 678 | 678 | ||
| 679 | =end | ||
| 680 | 679 | ||
| 681 | 680 | .sub 'onload' :anon :load :init | |
| 682 | 681 | load_bytecode 'config.pbc' |

