diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-18 06:25:52 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:46 +0200 |
commit | c1bea102df3f2907f345b89ff0f66f5055ac4767 (patch) | |
tree | 309d26329d190e24e9b4ebc36e89c42e369f0560 /doc | |
parent | 81c5f8e750fcda6a2451fb54604130431434f88f (diff) |
Add extern funcs, parameter registers, fix asm_rm RSP bug
Diffstat (limited to 'doc')
-rw-r--r-- | doc/Documentation.md | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/doc/Documentation.md b/doc/Documentation.md index 3f9bd1a..a046057 100644 --- a/doc/Documentation.md +++ b/doc/Documentation.md @@ -1,22 +1,25 @@ # Opcode -Variable length opcodes. Sizes range from 1 to 4 bytes. +Variable length opcodes. Sizes range from 1 to 5 bytes. ## Instruction formats Instructions can be in 7 different formats: 1. 1 byte: Opcode(u8) -2. 2 bytes: Opcode(u8) + register(u8) -3. 3 bytes: Opcode(u8) + register(u8) + register(u8) +2. 2 bytes: Opcode(u8) + register(i8) +3. 3 bytes: Opcode(u8) + register(i8) + register(i8) 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) +4.4 Opcode(u8) + register(i8) + num_args(u8) +5. 4 bytes: Opcode(u8) + register(i8) + register(i8) + register(i8) 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) +6.1 Opcode(u8) + register(i8) + offset(i16)\ +6.2 Opcode(u8) + register(i8) + intermediate(u16)\ +6.3 Opcode(u8) + register(i8) + data(u16)\ +6.4 Opcode(u8) + num_param_reg(u8) + num_local_var_reg(u16) +7. 5 bytes: Opcode(u8) + index(u16) + num_args(u8) + register(i8) +## Registers +Registers have a range of 128. Local variables start from register 0 and increment while parameters start from -1 +and decrement. # Compiler flow (Tokenize&parse -> Resolve AST -> Generate SSA -> Generate bytecode) -> Generate program\ @@ -26,7 +29,7 @@ and writing it to a file, which is an IO bottlenecked operation and it won't ben and may even lose performance because of it. # Bytecode -The layout of the full bytecode is: Header (Intermediates Strings Functions Instructions)* +The layout of the full bytecode is: Header (Intermediates Strings Functions External_Functions Instructions)* # Bytecode header ## Header layout @@ -63,7 +66,7 @@ The versions in the header only changes for every release, not every change. ## String |Type|Field|Description | |----|----|----------------------------------------------------------------------------------------| -|u16 |Size|The size of the string, in bytes. | +|u16 |Size|The size of the string, in bytes. Excluding the null-terminate character. | |u8* |Data|The data of the string, where the size is defined by @Size. Strings are null-terminated.| # Bytecode functions @@ -72,6 +75,21 @@ The versions in the header only changes for every release, not every change. |----|-------------------|---------------------------------| |u16 |Number of functions|The number of internal functions.| +# Bytecode external functions +## External functions layout +|Type |Field |Description | +|------------------|------------------|-----------------------------------------------------------------------------------------| +|u16 |num_extern_func |The number of external functions. | +|u32 |extern_funcs_size |The size of the external functions section, in bytes. | +|External function*|External functions|Multiple external functions, where the number of functions is defined by @num_extern_func| + +## External function +|Type|Field |Description | +|----|--------|-----------------------------------------------------------------------------------------------------| +|u8 |num_args|The number of arguments the functions has. | +|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 instructions ## Instructions layout |Type |Field |Description | |