File size: 553 Bytes
314c0dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
OPCODES = {
    "HALT": 0x00,
    "LOAD_IMM": 0x01,
    "LOAD_MEM": 0x02,
    "STORE": 0x03,
    "ADD": 0x04,
    "CMP": 0x08,
    "JZ": 0x0A,
    "HASH": 0x0C,
    "COMMIT": 0x0F,
    "EMIT": 0x11,
}

def compile_codexbyte(lines):
    bytecode = []
    for line in lines:
        line = line.strip()
        if not line or line.startswith(";"):
            continue
        parts = line.split()
        opcode = OPCODES[parts[0]]
        bytecode.append(opcode)
        for arg in parts[1:]:
            bytecode.append(int(arg, 0))
    return bytecode