1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//! Types for the compiled format of a QVM.

/// Size of procedure stack adjustment.
pub type FrameSize = u32;

/// Size of memory block to copy.
pub type BlockSize = u32;

/// Offset within stack frame.
pub type FrameOffset = u32;

/// Offset within the argument marshalling space.
pub type ArgOffset = u8;

/// Absolute instruction offset within code segment.
pub type Address = u32;

/// Literal value.
pub type Literal = u32;

// These should match their opcodes
#[allow(non_camel_case_types)]
/// A QVM instruction.
#[derive(Debug,PartialEq, Copy, Clone)]
pub enum Instruction {
    /// Undefined instruction.
    ///
    /// Used for padding the code segment. Should not occur at runtime.
    UNDEF,

    /// No-operation (NOP).
    IGNORE,

    /// Software breakpoint.
    BREAK,

    /// Enter a procedure, adjusting stack.
    ENTER(FrameSize),
    /// Leave a procedure, adjusting stack.
    LEAVE(FrameSize),
    /// Call a procedure.
    CALL,
    /// Push stack.
    PUSH,
    /// Pop stack.
    POP,

    /// Push constant onto stack.
    CONST(Literal),
    /// Get address of frame local variable or argument.
    LOCAL(FrameOffset),

    /// Jump to top of stack.
    JUMP,

    /// Check (signed integer) equality, jump to `Address` if true.
    EQ(Address),
    /// Check (signed integer) inequality, jump to `Address` if true.
    NE(Address),

    /// Check (signed integer) less-than, jump to `Address` if true.
    LTI(Address),
    /// Check (signed integer) less-than or equal-to, jump to `Address` if true.
    LEI(Address),
    /// Check (signed integer) greater-than, jump to `Address` if true.
    GTI(Address),
    /// Check (signed integer) greater-than or equal-to, jump to `Address` if true.
    GEI(Address),

    /// Check (unsigned integer) less-than, jump to `Address` if true.
    LTU(Address),
    /// Check (unsigned integer) less-than or equal-to, jump to `Address` if true.
    LEU(Address),
    /// Check (unsigned integer) greater-than, jump to `Address` if true.
    GTU(Address),
    /// Check (unsigned integer) greater-than or equal-to, jump to `Address` if true.
    GEU(Address),

    /// Check (float) equality, jump to `Address` if true.
    EQF(Address),
    /// Check (float) inequality, jump to `Address` if true.
    NEF(Address),

    /// Check (float) less-than, jump to `Address` if true.
    LTF(Address),
    /// Check (float) less-than or equal-to, jump to `Address` if true.
    LEF(Address),
    /// Check (float) greater-than, jump to `Address` if true.
    GTF(Address),
    /// Check (float) greater-than or equal-to, jump to `Address` if true.
    GEF(Address),

    /// Load 1-octet value.
    LOAD1,
    /// Load 2-octet value.
    LOAD2,
    /// Load 4-octet value.
    LOAD4,
    /// Store 1-octet value.
    STORE1,
    /// Store 2-octet value.
    STORE2,
    /// Store 4-octet value.
    STORE4,
    /// Store value into marshalling space.
    ARG(ArgOffset),

    /// Copy a block of memory.
    BLOCK_COPY(BlockSize),

    /// Sign-extend 8-bit.
    SEX8,
    /// Sign-extend 16-bit.
    SEX16,

    /// Negate (signed integer).
    NEGI,
    /// Add.
    ADD,
    /// Subtract.
    SUB,
    /// Divide (signed integer).
    DIVI,
    /// Divide (unsigned integer).
    DIVU,
    /// Modulo (signed integer).
    MODI,
    /// Modulo (unsigned integer).
    MODU,
    /// Multiply (signed integer).
    MULI,
    /// Multiply (unsigned integer).
    MULU,

    /// Bitwise AND.
    BAND,
    /// Bitwise OR.
    BOR,
    /// Bitwise XOR.
    BXOR,
    /// Bitwise complement.
    BCOM,

    /// Bitwise left-shift.
    LSH,
    /// Algebraic (signed) right-shift.
    RSHI,
    /// Bitwise (unsigned) right-shift.
    RSHU,

    /// Negate (float).
    NEGF,
    /// Add (float).
    ADDF,
    /// Subtract (float).
    SUBF,
    /// Divide (float).
    DIVF,
    /// Multiply (float).
    MULF,

    /// Convert signed integer to float.
    CVIF,
    /// Convert float to signed integer.
    CVFI,
}