Skip to content

Class BSV::Script::Stack

Inherits: Object

Script execution stack providing push/pop/peek operations for bytes, integers ({ScriptNumber}), and booleans.

Implements Forth-like stack manipulation operations (dup, drop, swap, rot, over, pick, roll, tuck) parameterised by count for the multi-element opcodes (OP_2DUP, OP_2SWAP, etc.).

Public Class Methods

cast_bool(bytes)

Bitcoin consensus boolean: false if empty, all-zero, or negative zero (0x80 last byte).

Public Instance Methods

clear()

Not documented.

depth()

--- Info ---

drop_n(count)

Remove the top N items.

dup_n(count)

Duplicate the top N items.

empty?()

  • @return [Boolean]

initialize()

  • @return [Stack] a new instance of Stack

nip_n(idx)

Remove item at offset idx from top (0 = top).

over_n(count)

Copy N items from 2N depth to top. OP_OVER (n=1): [x1 x2] -> [x1 x2 x1] OP_2OVER (n=2): [x1 x2 x3 x4] -> [x1 x2 x3 x4 x1 x2]

peek_bool(idx = 0)

Not documented.

peek_bytes(idx = 0)

--- Peek ---

peek_int(idx = 0, max_length: = ScriptNumber::MAX_BYTE_LENGTH, require_minimal: = false)

Not documented.

pick_n(idx)

Copy item at index n to top (0 = top).

pop_bool()

Not documented.

pop_bytes()

--- Pop ---

pop_int(max_length: = ScriptNumber::MAX_BYTE_LENGTH, require_minimal: = false)

Not documented.

push_bool(val)

Not documented.

push_bytes(data)

--- Push ---

push_int(script_number)

Not documented.

roll_n(idx)

Move item at index n to top (0 = top).

rot_n(count)

Rotate: move the bottom N of the top 3N items to the top. OP_ROT (n=1): [x1 x2 x3] -> [x2 x3 x1] OP_2ROT (n=2): [x1 x2 x3 x4 x5 x6] -> [x3 x4 x5 x6 x1 x2]

swap_n(count)

Swap the top N items with the next N. OP_SWAP (n=1): [x1 x2] -> [x2 x1] OP_2SWAP (n=2): [x1 x2 x3 x4] -> [x3 x4 x1 x2]

to_a()

Not documented.

tuck()

Copy top and insert before second: [x1 x2] -> [x2 x1 x2]