aboutsummaryrefslogtreecommitdiff
path: root/doc/Documentation.md
blob: f7dde0a0b2871f5a2200ebe48dcfa891a51fe7bf (plain)
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
# Opcode
Variable length opcodes. Sizes range from 1 to 4 bytes.
## Instruction formats
Instructions can be in 6 different formats:
1. 1 byte: Opcode(u8)
2. 2 bytes: Opcode(u8) + register(u8)
3. 3 bytes: Opcode(u8) + register(u8) + register(u8)
4. 3 bytes:\
4.1 Opcode(u8) + intermediate(u16)\
4.2 Opcode(u8) + data(u16)\
4.3 Opcode(u8) + offset(i16)\
4.4 Opcode(u8) + num_reg(u16)\
4.5 Opcode(u8) + register(u8) + num_args(u8)
5. 4 bytes: Opcode(u8) + register(u8) + register(u8) + register(u8)
6. 4 bytes:\
6.1 Opcode(u8) + register(u8) + offset(i16)\
6.2 Opcode(u8) + register(u8) + intermediate(u16)\
6.3 Opcode(u8) + register(u8) + data(u16)
7. 4 bytes: Opcode(u8) + index(u16) + num_args(u8)

# Compiler flow
(Tokenize&parse -> Resolve AST -> Generate SSA -> Generate bytecode) -> Generate program\
Each step except the last is done using multiple threads in parallel and the output of each step is used
in the next step. The last step is not done in parallel because the last step is combining all bytecode
and writing it to a file, which is an IO bottlenecked operation and it won't benefit from multithreading
and may even lose performance because of it.

# Bytecode header
## Header layout
|Size|Name         |Description                                                                 |
|----|-------------|----------------------------------------------------------------------------|
|4   |Magic number |The magic number used to identify an amalgam bytecode file.                 |
|1   |Major version|The major version of the bytecode. Updates in this is a breaking change.    |
|1   |Minor version|The minor version of the bytecode. Updates in this are backwards compatible.|
|1   |Patch version|The patch version of the bytecode. Updates in this are only minor bug fixes.|

The versions in the header only changes for every release, not every change.