|
1 | 1 | use QAST;
|
2 | 2 |
|
3 |
| -plan(106); |
| 3 | +plan(108); |
4 | 4 |
|
5 | 5 | # Following a test infrastructure.
|
6 | 6 | sub compile_qast($qast) {
|
@@ -882,6 +882,87 @@ is_qast(
|
882 | 882 | 'call with named flattened argument works');
|
883 | 883 | }
|
884 | 884 |
|
| 885 | + |
| 886 | +{ |
| 887 | + my sub wrap(int $value, int $thunk, $content) { |
| 888 | + my $block := QAST::Block.new( |
| 889 | + :blocktype('immediate'), |
| 890 | + QAST::Op.new( |
| 891 | + :op<bind>, |
| 892 | + QAST::Var.new( :name('a'), :scope('lexical'), :decl('var')), |
| 893 | + QAST::IVal.new( :value($value) ) |
| 894 | + ), |
| 895 | + $content |
| 896 | + ); |
| 897 | + $block.is_thunk($thunk); |
| 898 | + $block; |
| 899 | + } |
| 900 | + |
| 901 | + test_qast_result( |
| 902 | + QAST::Block.new( |
| 903 | + QAST::Op.new(:op<takeclosure>, # needed for JVM |
| 904 | + QAST::Block.new( |
| 905 | + wrap(100, 0, |
| 906 | + wrap(200, 0, |
| 907 | + wrap(300, 1, |
| 908 | + wrap(400, 1, |
| 909 | + wrap(500, 1, |
| 910 | + QAST::Op.new(:op<ctx>) |
| 911 | + ) |
| 912 | + ) |
| 913 | + ) |
| 914 | + ) |
| 915 | + ) |
| 916 | + ) |
| 917 | + ) |
| 918 | + ), |
| 919 | + -> $r { |
| 920 | + my $ctx := nqp::ctxouterskipthunks($r()); |
| 921 | + is($ctx<a>, 200, 'nqp::ctxouterskipthunks returns the correct context'); |
| 922 | + }); |
| 923 | +} |
| 924 | + |
| 925 | +{ |
| 926 | + my sub block($name, $is_thunk, $value, $content) { |
| 927 | + my $block := QAST::Block.new( |
| 928 | + QAST::Op.new( |
| 929 | + :op<bind>, |
| 930 | + QAST::Var.new( :name('value'), :decl('var'), :scope('lexical')), |
| 931 | + QAST::IVal.new( :value($value) ) |
| 932 | + ), |
| 933 | + $content |
| 934 | + ); |
| 935 | + |
| 936 | + $block.is_thunk($is_thunk); |
| 937 | + |
| 938 | + QAST::Op.new( |
| 939 | + :op<bind>, |
| 940 | + QAST::Var.new( :name($name), :decl('var'), :scope('lexical')), |
| 941 | + QAST::Op.new(:op<takeclosure>, # needed for JVM |
| 942 | + $block |
| 943 | + ) |
| 944 | + ) |
| 945 | + } |
| 946 | + |
| 947 | + test_qast_result( |
| 948 | + QAST::Block.new( |
| 949 | + block('a', 0, 500, QAST::Op.new(:op<ctx>)), |
| 950 | + block('b', 1, 400, QAST::Op.new(:op<call>, :name<a>)), |
| 951 | + block('c', 1, 300, QAST::Op.new(:op<call>, :name<b>)), |
| 952 | + block('d', 0, 200, QAST::Op.new(:op<call>, :name<c>)), |
| 953 | + block('e', 0, 100, QAST::Op.new(:op<call>, :name<d>)), |
| 954 | + QAST::Var.new( |
| 955 | + :name('e'), |
| 956 | + :scope('lexical') |
| 957 | + ) |
| 958 | + ), |
| 959 | + -> $e { |
| 960 | + my $ctx := nqp::ctxcallerskipthunks($e()); |
| 961 | + is($ctx<value>, 200, 'nqp::ctxouterskipthunks return the correct context'); |
| 962 | + } |
| 963 | + ); |
| 964 | +} |
| 965 | + |
885 | 966 | is_qast(
|
886 | 967 | QAST::CompUnit.new(
|
887 | 968 | QAST::Block.new(
|
|
0 commit comments