diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-12-23 08:57:48 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:37:00 +0200 |
commit | 902a81528b9d2edcf93226a2ca13da6fcc1839e5 (patch) | |
tree | ea868fae662aab61f1caa50b16a8b02fe1e6836b /doc | |
parent | 111bd0c7cb4b446c4bfe192b1df82845de17c005 (diff) |
wip: function pointers and other stuff
Diffstat (limited to 'doc')
-rw-r--r-- | doc/DESIGN.md | 14 | ||||
-rw-r--r-- | doc/Documentation.md | 35 |
2 files changed, 23 insertions, 26 deletions
diff --git a/doc/DESIGN.md b/doc/DESIGN.md index fae9ef2..f9e3cef 100644 --- a/doc/DESIGN.md +++ b/doc/DESIGN.md @@ -13,7 +13,9 @@ const main = fn { ``` const main = fn { var value = 23 + 50; - if value < 23 + if value == 0 + stderr.writeln("zero!"); + else if value < 23 stderr.writeln("less!"); else stderr.writeln("more!"); @@ -28,20 +30,14 @@ const main = fn { ## Closure Parentheses after `fn` is only required when the closure has parameters or returns data ``` -const apply = fn(func: () bool) { +const apply = fn(func: fn() bool) { const result = func(); } const main = fn { - // Return type is automatically deduced. If function returns multiple different types at different points, - // then you get an error and are required to specify the return type - apply(fn { - return true; - }) - apply(fn() bool { return true; - }) + }); // Or store in a variable and use it const func = fn { diff --git a/doc/Documentation.md b/doc/Documentation.md index 96cd3ef..493fcfa 100644 --- a/doc/Documentation.md +++ b/doc/Documentation.md @@ -16,8 +16,9 @@ Instructions can be in 7 different formats: 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) +6.4 Opcode(u8) + register(AmalReg) + index(u16)\ +6.5 Opcode(u8) + flags(u8) + num_local_var_reg(u16)\ +6.6 Opcode(u8) + index(u8) + index(u16) ## Registers Registers have a range of 128. Parameters have the most significant bit set while local variables dont. @@ -88,15 +89,15 @@ The versions in the header only changes for every release, not every change. |Function[]|Functions |Multiple non-extern functions, where the number of functions is defined by @num_funcs.| ## Function -|Type|Field |Description | -|----|-------------------------|------------------------------------------------------------------------------------------------------------------------| -|u32 |func_offset |The offset in the program code (machine code) where the function starts. Is always 0 until the program has been started.| -|u8 |num_params |The number of parameters. | -|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. | +|Type|Field |Description | +|----|-------------------------|-------------------------------------------------------------------------------------------------------------------------| +|u32 |func_offset |The offset in the program code (machine code) where the function starts. Is always ~0 until the program has been started.| +|u8 |num_params |The number of parameters. | +|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. | # Bytecode external functions ## External functions layout @@ -128,12 +129,12 @@ The versions in the header only changes for every release, not every change. |Exported function[]|Exported functions|Multiple exported functions, where the number of functions is defined by @num_export_func| ## Exported function -|Type|Field |Description | -|----|------------------|--------------------------------------------------------------------------------------------------------------------------| -|u32 |instruction_offset|The offset in the instruction data where the exported function is defined. Is always 0 until the program has been started.| -|u8 |num_args |The number of arguments the functions has. | -|u8 |name_len |The length of the exported function name, in bytes. Excluding the null-terminate character. | -|u8[]|name |The name of the exported function, where the size is defined by @name_len. Names are null-terminated. | +|Type|Field |Description | +|----|------------------|---------------------------------------------------------------------------------------------------------------------------| +|u32 |instruction_offset|The offset in the instruction data where the exported function is defined. Is always ~0 until the program has been started.| +|u8 |num_args |The number of arguments the functions has. | +|u8 |name_len |The length of the exported function name, in bytes. Excluding the null-terminate character. | +|u8[]|name |The name of the exported function, where the size is defined by @name_len. Names are null-terminated. | # Bytecode imports ## Imports layout |