|
1 | 1 | # YSH specific features of eval
|
2 | 2 |
|
3 | 3 | ## our_shell: ysh
|
4 |
| -## oils_failures_allowed: 4 |
| 4 | +## oils_failures_allowed: 2 |
5 | 5 |
|
6 | 6 | #### eval builtin does not take a literal block - can restore this later
|
7 | 7 |
|
@@ -575,66 +575,58 @@ inner2=z
|
575 | 575 |
|
576 | 576 | #### io->evalInFrame() can express try, cd builtins
|
577 | 577 |
|
578 |
| -var frag = ^(echo $i) |
579 |
| - |
580 | 578 | proc my-cd (new_dir; ; ; block) {
|
581 |
| - pushd $new_dir |
| 579 | + pushd $new_dir >/dev/null |
582 | 580 |
|
| 581 | + # Get calling frame. (The top-most frame, this one, has index -1) |
583 | 582 | var calling_frame = vm.getFrame(-2)
|
584 | 583 |
|
585 |
| - # could call this "unbound"? or unbind()? What about procs and funcs and |
586 |
| - # exprs? |
587 |
| - var frag = getCommandFrag(block) |
588 |
| - |
589 |
| - call io->evalInFrame(frag, calling_frame) |
| 584 | + call io->evalInFrame(block, calling_frame) |
590 | 585 |
|
591 |
| - popd |
| 586 | + popd >/dev/null |
592 | 587 | }
|
593 | 588 |
|
594 | 589 | var i = 42
|
595 | 590 | my-cd /tmp {
|
596 | 591 | echo $PWD
|
| 592 | + var my_pwd = PWD |
597 | 593 | var j = i + 1
|
598 | 594 | }
|
| 595 | +echo "my_pwd=$my_pwd" |
599 | 596 | echo "j = $j"
|
600 | 597 |
|
601 | 598 | ## STDOUT:
|
602 |
| -x: i = 0, j = 2 |
603 |
| -x: i = 1, j = 3 |
604 |
| -x: i = 2, j = 4 |
| 599 | +/tmp |
| 600 | +my_pwd=/tmp |
| 601 | +j = 43 |
605 | 602 | ## END
|
606 | 603 |
|
607 | 604 |
|
608 |
| -#### parseCommand(), io->evalInFrame(frag, frame) can behave like eval $mystr |
609 |
| - |
610 |
| -# NO LONGER WORKS, but is this a feature rather than a bug? |
| 605 | +#### io->evalInFrame(frag, frame) can behave like eval $mystr |
611 | 606 |
|
612 | 607 | proc p2(code_str) {
|
613 | 608 | var mylocal = 42
|
| 609 | + # mylocal is visible |
614 | 610 | eval $code_str
|
615 | 611 | }
|
616 | 612 |
|
617 |
| -p2 'echo mylocal=$mylocal' |
| 613 | +p2 'echo "eval string mylocal=$mylocal"' |
618 | 614 |
|
619 | 615 | proc p (;;; block) {
|
620 |
| - # To behave like eval $code_str, without variable capture: |
621 |
| - # |
622 |
| - # var frag = getCommandFrag(block) |
623 |
| - # var this_frame = vm.getFrame(-1) |
624 |
| - # call io->evalInFrame(frag, this_frame) |
| 616 | + var this_frame = vm.getFrame(-1) |
625 | 617 |
|
| 618 | + # mylocal is visible |
626 | 619 | var mylocal = 99
|
627 |
| - call io->eval(block) |
| 620 | + call io->evalInFrame(block, this_frame) |
628 | 621 | }
|
629 | 622 |
|
630 | 623 | p {
|
631 |
| - echo mylocal=$mylocal |
| 624 | + echo "evalInFrame mylocal=$mylocal" |
632 | 625 | }
|
633 | 626 |
|
634 |
| - |
635 | 627 | ## STDOUT:
|
636 |
| -mylocal=42 |
637 |
| -mylocal=99 |
| 628 | +eval string mylocal=42 |
| 629 | +evalInFrame mylocal=99 |
638 | 630 | ## END
|
639 | 631 |
|
640 | 632 | #### eval should have a sandboxed mode
|
|
0 commit comments