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
#[repr(u8)]
#[derive(Debug, Clone)]
pub enum Opcode {
/// Load a constant on to the stack.
Const,
True,
False,
Nil,
Unit,
String,
Add,
Sub,
Mul,
Div,
Mod,
Negate,
Equal,
NotEqual,
Gte,
Lte,
Gt,
Lt,
Not,
BitAnd,
BitOr,
BitXor,
DefGlobal,
SetGlobal,
GetGlobal,
LoadLocal,
SaveLocal,
LoadUpValue,
SaveUpValue,
CloseUpValue,
/// Set the stack's index pointer backwards by a certain amount.
Loop,
/// Unconditional jump.
Jump,
/// Jump to a given index pointer if the topmost value on
/// the stack is truthy.
JumpIfTrue,
/// Jump to a given index pointer if the topmost value on
/// the stack is falsy.
JumpIfFalse,
/// Call the topmost value off the stack.
Call,
Call0,
Call1,
Call2,
/// Return from the topmost function on the call stack.
Return,
/// Pop the topmost value off the stack.
Pop,
PopN,
/// Builds a class from the stack.
Class,
/// Build a closure from the stack.
Closure,
/// Builds a list from the stack.
List,
/// Construct a tuple from the stack.
Tuple,
/// Build a map from the stack.
Map,
/// Get index into the topmost value on the stack.
GetIndex,
/// Set an value at a given index with the supplied value.
SetIndex,
/// The get opcode.
Get,
/// Set opcode.
Set,
/// Import (unused).
Import,
/// Halt the vm's exectution.
Halt,
}
impl From<u8> for Opcode {
fn from(opcode: u8) -> Opcode {
unsafe { std::mem::transmute(opcode) }
}
}