comparison runtime/doc/vim9.txt @ 20379:7f88f6a3ed4c

Update runtime files Commit: https://github.com/vim/vim/commit/47e13953ffdbb9f163b901196dec8c2100b72edd Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 12 22:49:12 2020 +0200 Update runtime files
author Bram Moolenaar <Bram@vim.org>
date Tue, 12 May 2020 23:00:04 +0200
parents 2334bf788e8a
children 74e3316c1d5a
comparison
equal deleted inserted replaced
20378:e3511d21c324 20379:7f88f6a3ed4c
1 *vim9.txt* For Vim version 8.2. Last change: 2020 May 06 1 *vim9.txt* For Vim version 8.2. Last change: 2020 May 09
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
132 132
133 Four phases when loading a Vim9 script ~ 133 Four phases when loading a Vim9 script ~
134 134
135 In legacy script the functions are created when encountered, but parsed only 135 In legacy script the functions are created when encountered, but parsed only
136 when used. This allows for defining functions in any order and having them 136 when used. This allows for defining functions in any order and having them
137 call each other: > 137 call each other, so long as the function is defined when it is called: >
138 func One() 138 func One()
139 call Two() 139 call Two()
140 endfunc 140 endfunc
141 func Two() 141 func Two()
142 if cond 142 if cond
143 call One() " recursive call 143 call One() " recursive call
144 endif 144 endif
145 endfunc 145 endfunc
146 call One() 146 call One()
147 147
148 In Vim9 script the functions are compiled. If using the same functions as the 148 In Vim9 script the functions are compiled. When using the same functions as
149 above example it is not possible to compile function One without knowing that 149 the above example it is not possible to compile function One without knowing
150 function Two exists. Or this would require a runtime check, which is slow and 150 that function Two exists. Or this would require a runtime check, which is slow
151 does not allow for compile time type checking. 151 and does not allow for compile time type checking.
152 152
153 When sourcing a Vim9 script this happens in four phases: 153 When sourcing a Vim9 script this happens in four phases:
154 1. Cleanup: If the script was sourced before all script-local variables, 154 1. Cleanup: If the script was sourced before all script-local variables,
155 imports and functions are deleted. 155 imports and functions are deleted.
156 2. Discovery: The script is read and encountered functions, imports and 156 2. Discovery: The script is read and declarations of functions, imports and
157 variables are recognized. The type is parsed. Variable initializers that 157 variables are recognized and the type is parsed. Variable initializers
158 are a constant are evaluated, this can give the type of the variable. 158 that are a constant are evaluated, this can also give the type of the
159 variable.
159 3. Compilation: Functions are compiled. The script-local functions, imports 160 3. Compilation: Functions are compiled. The script-local functions, imports
160 and variables from the discovery phase are recognized and types are 161 and variables from the discovery phase are found and types are checked.
161 checked. 162 4. Execution: the commands in the script are executed, top to bottom.
162 4. Execution: the commands in the script are executed. Functions are skipped 163 Functions are skipped over, they do do not need to be processed again.
163 over. Variable initializers are evaluated, unless they are a constant. 164 Variable initializers are evaluated when encountered. Note that if a
165 function called earlier has set the value this will be over-written. It is
166 best to declare variables before where they are used to avoid confusion.
164 167
165 The result is that items defined at the script level can be used anywhere in 168 The result is that items defined at the script level can be used anywhere in
166 the script. This allows for putting the main function at the top: > 169 the script. This allows for putting the main function at the top: >
167 def Main() 170 def Main()
168 SubOne() 171 SubOne()