tursodatabase/turso

Cleanup opcode definitions

Open

#393 geöffnet am 16. Nov. 2024

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Rust (1.001 Forks)github user discovery
enhancementgood first issuehelp wanted

Repository-Metriken

Stars
 (19.103 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

We currently have SQLite VDBE opcodes defined in multiple places.

For example, for the If opcode, we have this in core/vdbe/mod.rs:

pub enum Insn {
    /// Jump to target_pc if r\[reg\] != 0 or (r\[reg\] == NULL && r\[null_reg\] != 0)
    If {
        reg: usize,              // P1
        target_pc: BranchOffset, // P2
        /// P3. If r\[reg\] is null, jump iff r\[null_reg\] != 0
        null_reg: usize,
    },
}

The following in core/vdbe/explain.rs:

Insn::Goto { target_pc } => (
    "Goto",
    0,
    *target_pc as i32,
    0,
    OwnedValue::Text(Rc::new("".to_string())),
    0,
    "".to_string(),
),

and the following in cli/opcodes_dictionary.rs:

Let's implement some macro magic where we can do something like:

pub enum Insn {
    /// Jump to target_pc if r\[reg\] != 0 or (r\[reg\] == NULL && r\[null_reg\] != 0)
    #[description = "Jump to P2 if the value in register P1 is true. The value is considered true if it is numeric and non-zero. If the value in P1 is NULL then take the jump if and only if P3 is non-zero."]
    If {
        #[p1] reg: usize,
        #[p2] target_pc: BranchOffset,
        /// If r\[reg\] is null, jump iff r\[null_reg\] != 0
        #[p3] null_reg: usize,
    },
}

Contributor Guide