LordXido commited on
Commit
314c0dc
·
verified ·
1 Parent(s): 77051f2

Create compiler.py

Browse files
Files changed (1) hide show
  1. compiler.py +25 -0
compiler.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ OPCODES = {
2
+ "HALT": 0x00,
3
+ "LOAD_IMM": 0x01,
4
+ "LOAD_MEM": 0x02,
5
+ "STORE": 0x03,
6
+ "ADD": 0x04,
7
+ "CMP": 0x08,
8
+ "JZ": 0x0A,
9
+ "HASH": 0x0C,
10
+ "COMMIT": 0x0F,
11
+ "EMIT": 0x11,
12
+ }
13
+
14
+ def compile_codexbyte(lines):
15
+ bytecode = []
16
+ for line in lines:
17
+ line = line.strip()
18
+ if not line or line.startswith(";"):
19
+ continue
20
+ parts = line.split()
21
+ opcode = OPCODES[parts[0]]
22
+ bytecode.append(opcode)
23
+ for arg in parts[1:]:
24
+ bytecode.append(int(arg, 0))
25
+ return bytecode