File: 54-dispatch-qast.t

package info (click to toggle)
nqp 2022.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,436 kB
  • sloc: java: 28,030; perl: 3,394; ansic: 451; makefile: 200; javascript: 68; sh: 1
file content (47 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use QAST;

plan(1);

# Following a test infrastructure.
sub compile_qast($qast) {
    my $*QAST_BLOCK_NO_CLOSE := 1;
    # Turn off the optimizer as it can only handle things things nqp generates
    nqp::getcomp('nqp').compile($qast, :from('ast'), :optimize('off'));
}
sub is_qast($qast, $value, $desc) {
    try {
        my $code := compile_qast($qast);
        is($code(), $value, $desc);
        CATCH { ok(0, 'Exception in is_qast: ' ~ $! ~ ", test: $desc") }
    }
}

{
    nqp::dispatch('boot-syscall', 'dispatcher-register', 'funnylang-hllize', -> $capture {
        nqp::dispatch('boot-syscall', 'dispatcher-delegate', 'boot-constant',
            nqp::dispatch('boot-syscall', 'dispatcher-insert-arg-literal-str',
                nqp::dispatch('boot-syscall', 'dispatcher-drop-arg', $capture, 0),
                0, 'hilarious'
            )
        );
    });

    is_qast(
        QAST::CompUnit.new(
            :hll<funnylang>,
            QAST::Block.new(
                QAST::Op.new(:op<sethllconfig>, QAST::SVal.new(:value<funnylang>),
                    QAST::Op.new(:op<hash>,
                        QAST::SVal.new(:value<null_value>),
                        QAST::SVal.new(:value<hilarious>),
                        QAST::SVal.new(:value<hllize_dispatcher>),
                        QAST::SVal.new(:value<funnylang-hllize>),
                    )
                ),
                QAST::Op.new(:op<hllize>, QAST::Op.new(:op<null>)),
            )

        ),
        'hilarious',
        'hllize');
}