aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/Documentation.md35
1 files changed, 20 insertions, 15 deletions
diff --git a/doc/Documentation.md b/doc/Documentation.md
index afc890c..f04a3a2 100644
--- a/doc/Documentation.md
+++ b/doc/Documentation.md
@@ -1,29 +1,33 @@
# Instructions
Variable length instructions. Instruction size ranges from 1 to 4 bytes.
+
## Instruction formats
Instructions can be in 7 different formats:
1. 1 byte: Opcode(u8)
-2. 2 bytes: Opcode(u8) + register(i8)
-3. 3 bytes: Opcode(u8) + register(i8) + register(i8)
+2. 2 bytes: Opcode(u8) + register(AmalReg)
+3. 3 bytes: Opcode(u8) + register(AmalReg) + register(AmalReg)
4. 3 bytes:\
4.1 Opcode(u8) + intermediate(u16)\
4.2 Opcode(u8) + data(u16)\
4.3 Opcode(u8) + label(i16)\
-4.4 Opcode(u8) + register(i8) + num_args(u8)
-5. 4 bytes: Opcode(u8) + register(i8) + register(i8) + register(i8)
+4.4 Opcode(u8) + register(AmalReg) + num_args(u8)
+5. 4 bytes: Opcode(u8) + register(AmalReg) + register(AmalReg) + register(AmalReg)
6. 4 bytes:\
-6.1 Opcode(u8) + register(i8) + label(i16)\
-6.2 Opcode(u8) + register(i8) + intermediate(u16)\
-6.3 Opcode(u8) + register(i8) + data(u16)\
+6.1 Opcode(u8) + register(AmalReg) + label(i16)\
+6.2 Opcode(u8) + register(AmalReg) + intermediate(u16)\
+6.3 Opcode(u8) + register(AmalReg) + data(u16)\
6.4 Opcode(u8) + flags(u8) + num_local_var_reg(u16)\
6.5 Opcode(u8) + index(u8) + index(u16)
+
## Registers
-Registers have a range of 128. Local variables start from register 0 and increment while parameters start from -1
-and decrement. Registers have the scope of functions and reset after instructions reach a new function (AMAL_OP_FUNC_START).
+Registers have a range of 128. Parameters have the most significant bit set while local variables dont.
+Registers have the scope of functions and reset after instructions reach a new function (AMAL_OP_FUNC_START).
If import index for call and calle is 0, then that means the function resides in the same file the function call
is being called from. Which means that import index 1 is actually import index 0 into the import list.
+@AmalReg is an alias for 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
@@ -106,12 +110,13 @@ The versions in the header only changes for every release, not every change.
|Type|Field |Description |
|----|-------------------------|-----------------------------------------------------------------------------------------------------|
|u8 |num_params |The number of parameters. |
+|u8 |num_return_types |The number of return values. |
+|u8 |name_len |The length of the external function name, in bytes. Excluding the null-terminate character. |
+|u8 |flags |The flags for the external function. The values are defined in @amal_func_flag. |
|u32 |params_num_pointers |The number of pointers in the parameters. |
|u32 |params_fixed_size |The size of all non-pointer type parameters, in bytes. |
-|u8 |num_return_types |The number of return values. |
|u32 |return_types_num_pointers|The number of pointers in the return types. |
|u32 |return_types_fixed_size |The size of all non-pointer type return types, in bytes. |
-|u8 |name_len |The length of the external function name, in bytes. Excluding the null-terminate character. |
|u8[]|name |The name of the external function, where the size is defined by @name_len. Names are null-terminated.|
# Bytecode exported functions
@@ -146,10 +151,10 @@ The versions in the header only changes for every release, not every change.
# Bytecode instructions
## Instructions layout
-|Type |Field |Description |
-|-----------|-----------------|---------------------------------------------------------------------------|
-|u32 |Instructions size|The size of the instructions section, in bytes. |
-|Instruction|Instructions data|The instructions data. Each instructions begins with an opcode, see #Opcode|
+|Type |Field |Description |
+|-------------|-----------------|---------------------------------------------------------------------------|
+|u32 |Instructions size|The size of the instructions section, in bytes. |
+|Instruction[]|Instructions data|The instructions data. Each instructions begins with an opcode, see #Opcode|
# Execution backend
Amalgam supports multiple execution backend and they can be implemented with minimal