NAME=hbc disasm basic instructions
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
pd 3
EOF
EXPECT=<<EOF
            ;-- entry0:
            ;-- global_0x000000b0:
            0x000000b0      73000100       load_const_string r0, str.print_123__ ; 0xa2 ; "print(123);"
            0x000000b4      5e000000       direct_eval r0, r0, 0
            0x000000b8      5c00           ret r0
EOF
RUN

NAME=hbc file info arch
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
i~arch
EOF
EXPECT=<<EOF
arch     hbc
EOF
RUN

NAME=hbc file info type
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
i~type
EOF
EXPECT=<<EOF
type     Hermes bytecode
bintype  hermes
EOF
RUN

NAME=hbc file info cpu version
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
i~cpu
EOF
EXPECT=<<EOF
cpu      96
EOF
RUN

NAME=hbc symbols list
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
is~FUNC
EOF
EXPECT=<<EOF
0   0x000000b0 0x000000b0 NONE FUNC 10       global_0x000000b0
EOF
RUN

NAME=hbc entry point
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
ie~program
EOF
EXPECT=<<EOF
0x000000b0 0x000000b0 ---------- ---------- program
EOF
RUN

NAME=hbc disasm ret instruction
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
s 0xb8
pd 1
EOF
EXPECT=<<EOF
            0x000000b8      5c00           ret r0
EOF
RUN

NAME=hbc disasm load_const_string
ARGS=-e asm.sub.varmin=16
FILE=bins/hbc/bespoke_eval.hbc
CMDS=<<EOF
s 0xb0
pd 1
EOF
EXPECT=<<EOF
            ;-- entry0:
            ;-- global_0x000000b0:
            0x000000b0      73000100       load_const_string r0, str.print_123__ ; 0xa2 ; "print(123);"
EOF
RUN

NAME=hbc disasm direct_eval
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
s 0xb4
pd 1
EOF
EXPECT=<<EOF
            0x000000b4      5e000000       direct_eval r0, r0, 0
EOF
RUN

NAME=hbc sections
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
iS~hermes
EOF
EXPECT=<<EOF
0   0x00000000  0x124 0x00000000  0x124 -r-- 0x0   ---- hermes_bytecode
EOF
RUN

NAME=hbc seek and disasm
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
s entry0
pd 2
EOF
EXPECT=<<EOF
            ;-- entry0:
            ;-- global_0x000000b0:
            0x000000b0      73000100       load_const_string r0, str.print_123__ ; 0xa2 ; "print(123);"
            0x000000b4      5e000000       direct_eval r0, r0, 0
EOF
RUN

NAME=hbc print hex bytes
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
s 0xb0
px 10
EOF
EXPECT=<<EOF
- offset -  B0B1 B2B3 B4B5 B6B7 B8B9 BABB BCBD BEBF  0123456789ABCDEF
0x000000b0  7300 0100 5e00 0000 5c00                 s...^...\.
EOF
RUN

NAME=hbc unreachable padding
FILE=bins/hbc/bespoke_eval.hbc
ARGS=-e asm.sub.varmin=16
CMDS=<<EOF
s 0xba
pd 2
EOF
EXPECT=<<EOF
            0x000000ba      00             unreachable
            0x000000bb      00             unreachable
EOF
RUN

NAME=hbc large file symbols count
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
is~FUNC~?
EOF
EXPECT=<<EOF
5388
EOF
RUN

NAME=hbc get_global_object instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e510
pd 1
EOF
EXPECT=<<EOF
            ;-- clear_0x0003e510:
            0x0003e510      3000           get_global_object r0
EOF
RUN

NAME=hbc try_get_by_id instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e512
ao~mnemonic
EOF
EXPECT=<<EOF
mnemonic: try_get_by_id
EOF
RUN

NAME=hbc get_by_id_short instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e518
ao~mnemonic
EOF
EXPECT=<<EOF
mnemonic: get_by_id_short
EOF
RUN

NAME=hbc create_this instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e51d
pd 1
EOF
EXPECT=<<EOF
            0x0003e51d      6a010100       create_this r1, r1, r0
EOF
RUN

NAME=hbc mov instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e521
pd 1
EOF
EXPECT=<<EOF
            0x0003e521      080201         mov r2, r1
EOF
RUN

NAME=hbc construct instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e524
pd 1
EOF
EXPECT=<<EOF
            0x0003e524      50000001       construct r0, r0, 1
EOF
RUN

NAME=hbc select_object instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e528
pd 1
EOF
EXPECT=<<EOF
            0x0003e528      6b000100       select_object r0, r1, r0
EOF
RUN

NAME=hbc get_environment instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e52c
pd 1
EOF
EXPECT=<<EOF
            0x0003e52c      290100         get_environment r1, 0
EOF
RUN

NAME=hbc store_to_environment instruction
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e52f
pd 1
EOF
EXPECT=<<EOF
            0x0003e52f      2a010100       store_to_environment r1, 1, r0
EOF
RUN

NAME=hbc complete function disasm
FILE=bins/hbc/index.android.bundle
CMDS=<<EOF
s 0x3e510
pd 3~get_global
pd 1 @ 0x3e51d~create_this
pd 1 @ 0x3e533~ret
EOF
EXPECT=<<EOF
            0x0003e510      3000           get_global_object r0
            0x0003e51d      6a010100       create_this r1, r1, r0
            0x0003e533      5c00           ret r0
EOF
RUN

NAME=hbc assembler
FILE=--
CMDS=<<EOF
-a hbc
pa ret r0
EOF
EXPECT=<<EOF
5c00
EOF
RUN
