### ----------------------------------------------------
### -- MoarVM::Bytecode
### -- Licenses: Artistic-2.0
### -- Authors: Elizabeth Mattijsen
### -- File: t/01-basic.rakutest
### ----------------------------------------------------
use Test;
use MoarVM::Bytecode;

plan 17;

my str $setting = "c";
my $M := MoarVM::Bytecode.new($setting);

is $M.version,   7,     "Is it the correct version";
is $M.hll-name, "Raku", "Is it the correct HLL";
is $M.cu-dependencies.elems, 0, 'No compunit dependencies';

ok $M.op("unless_i"),    "can we obtain normal ops";
ok $M.op("p6stateinit"), "can we obtain extension ops";

my @frames := $M.frames.reify-all;
is @frames.elems, $M.frames.elems, "did we get all frames";

my @files = $M.files(:instantiate);
ok @files.elems, "did we find any bytecode files";

my %hll-names;
%hll-names{.hll-name}++ for @files;
is %hll-names.elems, 2, 'Did we see 2 HLL names';

is $M.strings.elems, $M.string-heap-entries,
  "Found $M.strings.elems() strings in $setting setting";
is $M.sc-dependencies.elems, $M.sc-dependencies-entries,
  "Found $M.sc-dependencies.elems() sc dependencies in $setting setting";
is $M.extension-ops.elems, $M.extension-ops-entries,
  "Found $M.extension-ops.elems() extension ops in $setting setting";
is $M.frames.elems, $M.frames-data-entries,
  "Found $M.frames.elems() frames in $setting setting";
is $M.callsites.elems, $M.callsites-data-entries,
  "Found $M.callsites.elems() callsites in $setting setting";

for MoarVM::Op.new(0), MoarVM::Op.new("no_op") -> $op {
    subtest "Check if op info can be obtained" => {
        plan 7;

        is        $op.name,        "no_op",           "is name of op ok";
        is        $op.annotation,  "",                "is annotation of op ok";
        is-deeply $op.is-sequence, False,             "not a sequence";
        is        $op.index,       0,                 "is index of op ok";
        is        $op.bytes,       2,                 "is bytes of op ok";
        is-deeply $op.operands,    (),                "no operands involved?";
        is-deeply $op.adverbs,     { :confprog }.Map, "a single attribute?";
    }
}

is MoarVM::Op.all-ops.elems, 973, "Right number of ops?";

my %coverables := $M.coverables;
is-deeply %coverables.keys.map({
  %coverables{$_} if .starts-with("gen");
}).head.List, (1,), "did the generated file show a single initial line";

# vim: expandtab shiftwidth=4


