Skip to content

VM: Print more details with grain-dump. - #1168

Merged
schungx merged 1 commit into
mainfrom
vm-enhance-grain-dump
Sep 13, 2026
Merged

VM: Print more details with grain-dump.#1168
schungx merged 1 commit into
mainfrom
vm-enhance-grain-dump

Conversation

@schungx

@schungx schungx commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

grain-dump is a very useful tool.

This PR extends it with more information, such as constant values, variable/function names, etc. plus flushing out the display for the Switch and Chain opcodes.

Previous:

    184  56:9      Call { name: 16, argc: 2, op: Some(0), capture_parent_scope: false }
    190  56:9      JumpIfFalse { target: 223 }
    195            LoadLocal(9)
    198  57:22     Chain(8)
    201  57:13     AssignLocal { slot: 8, var_name: 14, op: Some(0) }
    208            Const(9)
    211  58:7      AssignLocal { slot: 9, var_name: 15, op: Some(0) }
    218            Jump(177)
    223            Unit
    224            Pop
    225            Checkpoint
    226            Unit
    227            DeclareLocal { name: 19, is_const: false }
    230            Checkpoint
    231  67:10     PushHandler { target: 296, catch_var: Some(20) }
    238            LoadLocal(8)
    241            Const(7)
    244  63:16     Call { name: 21, argc: 2, op: Some(1), capture_parent_scope: false }
    250  63:16     JumpIfTrue { target: 269 }
    255  63:28     Chain(9, 0 total operands): Local { slot: 4, name: 4 }
    258  63:28     JumpIfTrue { target: 269 }
    263            Bool(false)
    264            Jump(270)
    269            Bool(true)
    270  63:20     JumpIfFalse { target: 279 }
    275            Const(10) = thrown
    278  64:9      Throw
    279            Const(11)
    282  66:20     Chain(10)
    285  66:12     AssignLocal { slot: 10, var_name: 19, op: None }
    290            PopHandler
    291            Jump(308)
    296            LoadLocal(11)
    299  68:12     AssignLocal { slot: 10, var_name: 19, op: None }

Now:

    184  56:9      Call { name: 16, argc: 2, op: Some(0), capture_parent_scope: false } : < (LessThan)
    190  56:9      JumpIfFalse { target: 223 }
    195            LoadLocal(9)
    198  57:22     Chain(8, 1 total operands): Local { slot: 1, name: 1 } counts [0]
    201  57:13     AssignLocal { slot: 8, var_name: 14, op: Some(0) } : doubled += (PlusAssign) / + (Plus)
    208            Const(9) = 1
    211  58:7      AssignLocal { slot: 9, var_name: 15, op: Some(0) } : i += (PlusAssign) / + (Plus)
    218            Jump(177)
    223            Unit
    224            Pop
    225            Checkpoint
    226            Unit
    227            DeclareLocal { name: 19, is_const: false } : let caught
    230            Checkpoint
    231  67:10     PushHandler { target: 296, catch_var: Some(20) }
    238            LoadLocal(8)
    241            Const(7) = 0
    244  63:16     Call { name: 21, argc: 2, op: Some(1), capture_parent_scope: false } : > (GreaterThan)
    250  63:16     JumpIfTrue { target: 269 }
    255  63:28     Chain(9, 0 total operands): Local { slot: 4, name: 4 } flags .off
    258  63:28     JumpIfTrue { target: 269 }
    263            Bool(false)
    264            Jump(270)
    269            Bool(true)
    270  63:20     JumpIfFalse { target: 279 }
    275            Const(10) = thrown
    278  64:9      Throw
    279            Const(11) = 99
    282  66:20     Chain(10, 1 total operands): Local { slot: 1, name: 1 } counts [0]
    285  66:12     AssignLocal { slot: 10, var_name: 19, op: None } : caught
    290            PopHandler
    291            Jump(308)
    296            LoadLocal(11)
    299  68:12     AssignLocal { slot: 10, var_name: 19, op: None } : caught

@schungx
schungx requested a review from ImTheSquid September 10, 2026 05:28
@schungx schungx added enhancement vm Issues related to the Rhai Grain bytecodes compiler and VM. labels Sep 10, 2026
@schungx
schungx force-pushed the vm-enhance-grain-dump branch from 0d31de9 to b224674 Compare September 10, 2026 05:29
@schungx
schungx force-pushed the vm-enhance-grain-dump branch from b224674 to d4b792e Compare September 10, 2026 05:45
@schungx
schungx merged commit e557112 into main Sep 13, 2026
54 checks passed
@schungx
schungx deleted the vm-enhance-grain-dump branch September 13, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement vm Issues related to the Rhai Grain bytecodes compiler and VM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants