|
480 | 480 | (call $caml_unix_error (pop externref) (ref.null eq))))
|
481 | 481 | (ref.i31 (i32.const 0)))
|
482 | 482 |
|
483 |
| - (func (export "unix_opendir") (export "caml_unix_opendir") |
| 483 | + (func $unix_opendir (export "unix_opendir") (export "caml_unix_opendir") |
484 | 484 | (param $name (ref eq)) (result (ref eq))
|
485 | 485 | (try (result (ref eq))
|
486 | 486 | (do
|
|
492 | 492 | (call $caml_unix_error (pop externref) (ref.null eq))
|
493 | 493 | (ref.i31 (i32.const 0)))))
|
494 | 494 |
|
495 |
| - (func (export "unix_readdir") (export "caml_unix_readdir") |
496 |
| - (param $dir (ref eq)) (result (ref eq)) |
| 495 | + (func $throw_ebadf (param $cmd (ref eq)) |
| 496 | + (throw $ocaml_exception |
| 497 | + (array.new_fixed $block 5 |
| 498 | + (ref.i31 (i32.const 0)) |
| 499 | + (call $get_unix_error_exn) |
| 500 | + (ref.i31 (i32.const 3)) ;; EBADF |
| 501 | + (local.get $cmd) |
| 502 | + (global.get $no_arg)))) |
| 503 | + |
| 504 | + (data $readdir "readdir") |
| 505 | + |
| 506 | + (func $readdir_helper (param $dir (ref eq)) (result (ref eq)) |
497 | 507 | (block $end
|
498 | 508 | (return
|
499 | 509 | (try (result (ref eq))
|
|
503 | 513 | (br_on_null $end
|
504 | 514 | (call $readdir (call $unwrap (local.get $dir)))))))
|
505 | 515 | (catch $javascript_exception
|
506 |
| - (call $caml_unix_error (pop externref) (ref.null eq)) |
| 516 | + (drop (pop externref)) |
| 517 | + (call $throw_ebadf |
| 518 | + (array.new_data $string $readdir |
| 519 | + (i32.const 0) (i32.const 7))) |
507 | 520 | (ref.i31 (i32.const 0))))))
|
508 | 521 | (call $caml_raise_end_of_file)
|
509 | 522 | (ref.i31 (i32.const 0)))
|
510 | 523 |
|
511 |
| - (func (export "unix_closedir") (export "caml_unix_closedir") |
| 524 | + (data $closedir "closedir") |
| 525 | + |
| 526 | + (func $unix_closedir (export "unix_closedir") (export "caml_unix_closedir") |
| 527 | + (export "win_findclose") (export "caml_unix_findclose") |
512 | 528 | (param $dir (ref eq)) (result (ref eq))
|
513 | 529 | (try
|
514 | 530 | (do
|
515 | 531 | (call $closedir (call $unwrap (local.get $dir))))
|
516 | 532 | (catch $javascript_exception
|
517 |
| - (call $caml_unix_error (pop externref) (ref.null eq)))) |
| 533 | + (drop (pop externref)) |
| 534 | + (call $throw_ebadf |
| 535 | + (array.new_data $string $closedir (i32.const 0) (i32.const 8))))) |
518 | 536 | (ref.i31 (i32.const 0)))
|
519 | 537 |
|
| 538 | + (func (export "unix_readdir") (export "caml_unix_readdir") |
| 539 | + (param $dir (ref eq)) (result (ref eq)) |
| 540 | + (block $return (result (ref eq)) |
| 541 | + (br_on_non_null $return (call $readdir_helper (local.get $dir))) |
| 542 | + (call $caml_raise_end_of_file) |
| 543 | + (ref.i31 (i32.const 0)))) |
| 544 | + |
| 545 | + (func $win_find_next (export "win_findnext") (export "caml_unix_findnext") |
| 546 | + (param $dir (ref eq)) (result (ref eq)) |
| 547 | + (block $return (result (ref eq)) |
| 548 | + (br_on_non_null $return (call $readdir_helper (local.get $dir))) |
| 549 | + (drop (call $unix_closedir (local.get $dir))) |
| 550 | + (call $caml_raise_end_of_file) |
| 551 | + (ref.i31 (i32.const 0)))) |
| 552 | + |
| 553 | + (func (export "win_findfirst") (export "caml_unix_findfirst") |
| 554 | + (param $vpath (ref eq)) (result (ref eq)) |
| 555 | + (local $dir (ref eq)) (local $p (ref $string)) (local $p' (ref $string)) |
| 556 | + (local $len i32) |
| 557 | + (local.set $p (ref.cast (ref $string) (local.get $vpath))) |
| 558 | + (local.set $len (i32.sub (array.len (local.get $p)) (i32.const 3))) |
| 559 | + (local.set $p' (array.new $string (i32.const 0) (local.get $len))) |
| 560 | + (array.copy $string $string |
| 561 | + (local.get $p') (i32.const 0) |
| 562 | + (local.get $p) (i32.const 0) |
| 563 | + (local.get $len)) |
| 564 | + (local.set $dir (call $unix_opendir (local.get $p'))) |
| 565 | + (array.new_fixed $block 3 (ref.i31 (i32.const 0)) |
| 566 | + (call $win_find_next (local.get $dir)) |
| 567 | + (local.get $dir))) |
| 568 | + |
520 | 569 | (data $rewinddir_not_implemented "rewinddir not implemented")
|
521 | 570 |
|
522 | 571 | (func (export "unix_rewinddir") (export "caml_unix_rewinddir")
|
|
0 commit comments