# `Cartouche.VM.Context`
[🔗](https://github.com/zenhive/cartouche/blob/main/lib/cartouche/vm.ex#L79)

Runtime execution state of a `Cartouche.VM` step: program counter, stack,
memory, transient storage, halt/revert flags, return data, and the FFI
table available to the VM.

# `op_map`

```elixir
@type op_map() :: %{required(integer()) =&gt; Cartouche.VM.opcode()}
```

# `t`

```elixir
@type t() :: %Cartouche.VM.Context{
  code: Cartouche.VM.code(),
  code_encoded: binary(),
  ffis: Cartouche.VM.ffis(),
  halted: boolean(),
  memory: binary(),
  op_map: op_map(),
  pc: integer(),
  return_data: binary(),
  reverted: boolean(),
  stack: [binary()],
  tstorage: %{required(binary()) =&gt; binary()}
}
```

# `fetch_ffi`

```elixir
@spec fetch_ffi(t(), Cartouche.VM.address()) ::
  {:ok, Cartouche.VM.ffi()} | {:error, Cartouche.VM.vm_error()}
```

Looks up the FFI registered at `address` in the context's FFI table.
Returns `{:error, {:unknown_ffi, address}}` when no FFI is registered.

# `init_from`

```elixir
@spec init_from(Cartouche.VM.code(), Cartouche.VM.ffis()) :: t()
```

Builds a fresh `Context` for executing `code` with the given FFI table.
Pre-computes the program-counter-keyed `op_map` from the assembled
bytecode so subsequent steps can resolve operations in O(1).

# `show`

```elixir
@spec show(t()) :: String.t()
```

Renders the context as a multi-line string showing the program counter
and stack contents. Used for verbose VM tracing.

# `show_stack`

```elixir
@spec show_stack([binary()]) :: String.t()
```

Renders the EVM stack as a debugger-style multi-line string with
descending offsets and word values in hex.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
