From ff03b50668d59bb9f1cce040a3388860b8ffb228 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Fri, 24 Jul 2020 20:09:47 +0200 Subject: [PATCH] Update documentation --- docs/lang/syntax.md | 23 ++++++++++++++++++++++- docs/various/optimization.md | 4 ++++ mkdocs.yml | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/lang/syntax.md b/docs/lang/syntax.md index 399c63f3..be31d039 100644 --- a/docs/lang/syntax.md +++ b/docs/lang/syntax.md @@ -417,7 +417,7 @@ for : [ ] { * `` – traverse enum constants of given type, in arbitrary order -* `` – traverse array contents, in arbitrary order, +* `` – traverse given array, in arbitrary order, assigning the index to `` and either the element or the pointer to the element to `` * `` – traverse every value in the list, in the given order. @@ -425,6 +425,26 @@ Values do not have to be constant. If a value is not a constant and its value changes while executing the loop, the behaviour is undefined. Jumps using `goto` across the scope of this kind of loop are disallowed. +Examples: + + struct S { ... } + pointer.S p + S s + byte i + array(str) arr [8] + enum E { E_1, E_2, E_3 } + E e + + for i,0,until,8 { ... } // executes the body with i=0, i=1, ... i=7 + for i,0,to,7 { ... } // executes the body with i=0, i=1, ... i=7 + for i,0,paralleluntil,8 { ... } // executes the body with i=0, i=1, ... i=7 (in arbitrary order) + for i,0,parallelto,8 { ... } // executes the body with i=0, i=1, ... i=7 (in arbitrary order) + for i,7,downto,0 { ... } // executes the body with i=7, i=6, ... i=0 + for i:arr { ... } // executes the body with i=0, i=1, ... i=7 (in arbitrary order) + for i,s:arr { ... } // executes the body with i=0, s=arr[0]; i=1, s=arr[1]; ... i=7, s=arr[7] (in arbitrary order) + for i,p:arr { ... } // executes the body with i=0, p=arr[0].pointer; ... i=7, p=arr[7].pointer (in arbitrary order) + for e:E { ... } // executes the body with e=E_1, e=E_2, e=E_3 (in arbitrary order) + ### `break` and `continue` statements Syntax: @@ -447,6 +467,7 @@ Labelless `break` and `continue` apply to the innermost `for`, `while` or `do-wh `break for`, `continue do` etc. apply to the innermost loop of the given type. `break i` and `continue i` apply to the innermost `for` loop that uses the `i` variable. +`for` loops of the form `for i,j:array` can be broken from using `break i` only, not `break j`. ### `goto` and `label` diff --git a/docs/various/optimization.md b/docs/various/optimization.md index 15e8fa94..563669ba 100644 --- a/docs/various/optimization.md +++ b/docs/various/optimization.md @@ -36,6 +36,10 @@ where `X` is a power of two. Even if this makes the struct 12 bytes instead of 1 * Avoid reusing temporary variables. It makes it easier for the optimizer to eliminate the variable entirely. +* Mark the most frequently used local variables as `register`. +It will increase chances that those variables, and not the ones less frequently used, +are inlined into registers or put in the zeropage. + ## Functions * Write many functions with no parameters and use `-finline`. diff --git a/mkdocs.yml b/mkdocs.yml index 764a9902..0a959255 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -58,6 +58,10 @@ nav: - Undefined behaviour: abi/undefined-behaviour.md - Undocumented instruction support: abi/undocumented.md - Variable storage: abi/variable-storage.md + - Additional guides: + - Optimization guide: various/optimization.md + - Differences from C: various/cdiff.md + - Differences in assembly: various/asmdiff.md - External links: - Downloads: https://github.com/KarolS/millfork/releases/ - Source code: https://github.com/KarolS/millfork