~starkingdoms/starkingdoms

ref: 337e611348882db2bf9cd0616169c2aebeb2d6ee starkingdoms/kabel/src/opcodes.rs -rw-r--r-- 759 bytes
337e6113 — ghostly_zsh mul and div 1 year, 4 months ago
                                                                                
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
pub enum OpCode {
    CONSTANT,
    ADD,
    SUB,
    MUL,
    DIV,
    MOD,
    PRINT,
    ERR,
}

impl From<OpCode> for u8 {
    fn from(value: OpCode) -> Self {
        use OpCode::*;
        match value {
            CONSTANT => 0x00,
            ADD => 0x01,
            SUB => 0x02,
            MUL => 0x03,
            DIV => 0x04,
            MOD => 0x05,
            PRINT => 0xFE,
            ERR => 0xFF
        }
    }
}
impl From<u8> for OpCode {
    fn from(value: u8) -> Self {
        use OpCode::*;
        match value {
            0x00 => CONSTANT,
            0x01 => ADD,
            0x02 => SUB,
            0x03 => MUL,
            0x04 => DIV,
            0x05 => MOD,
            0xFE => PRINT,
            _ => ERR
        }
    }
}