diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-12 11:38:42 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-12 11:38:42 -0300 |
commit | f6aab3ec1f111cd8d968bdcb7ca800e93b819d24 (patch) | |
tree | 4c36c418ecc9062e6d95de73457198b38b0afce9 /manual | |
parent | be8445d7e4b6122620c428877b51a27d464253d5 (diff) | |
download | lua-f6aab3ec1f111cd8d968bdcb7ca800e93b819d24.tar.gz lua-f6aab3ec1f111cd8d968bdcb7ca800e93b819d24.tar.bz2 lua-f6aab3ec1f111cd8d968bdcb7ca800e93b819d24.zip |
First implementation of constant propagation
Local constant variables initialized with compile-time constants
are optimized away from the code.
Diffstat (limited to 'manual')
-rw-r--r-- | manual/manual.of | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/manual/manual.of b/manual/manual.of index 136e9022..61fcdaa3 100644 --- a/manual/manual.of +++ b/manual/manual.of | |||
@@ -223,7 +223,7 @@ In Lua, the global variable @Lid{_G} is initialized with this same value. | |||
223 | so changing its value will affect only your own code.) | 223 | so changing its value will affect only your own code.) |
224 | 224 | ||
225 | When Lua loads a chunk, | 225 | When Lua loads a chunk, |
226 | the default value for its @id{_ENV} upvalue | 226 | the default value for its @id{_ENV} variable |
227 | is the global environment @seeF{load}. | 227 | is the global environment @seeF{load}. |
228 | Therefore, by default, | 228 | Therefore, by default, |
229 | free names in Lua code refer to entries in the global environment | 229 | free names in Lua code refer to entries in the global environment |
@@ -233,7 +233,7 @@ and some functions there operate on that environment. | |||
233 | You can use @Lid{load} (or @Lid{loadfile}) | 233 | You can use @Lid{load} (or @Lid{loadfile}) |
234 | to load a chunk with a different environment. | 234 | to load a chunk with a different environment. |
235 | (In C, you have to load the chunk and then change the value | 235 | (In C, you have to load the chunk and then change the value |
236 | of its first upvalue.) | 236 | of its first upvalue; see @See{lua_setupvalue}.) |
237 | 237 | ||
238 | } | 238 | } |
239 | 239 | ||
@@ -1224,7 +1224,7 @@ As such, chunks can define local variables, | |||
1224 | receive arguments, and return values. | 1224 | receive arguments, and return values. |
1225 | Moreover, such anonymous function is compiled as in the | 1225 | Moreover, such anonymous function is compiled as in the |
1226 | scope of an external local variable called @id{_ENV} @see{globalenv}. | 1226 | scope of an external local variable called @id{_ENV} @see{globalenv}. |
1227 | The resulting function always has @id{_ENV} as its only upvalue, | 1227 | The resulting function always has @id{_ENV} as its only external variable, |
1228 | even if it does not use that variable. | 1228 | even if it does not use that variable. |
1229 | 1229 | ||
1230 | A chunk can be stored in a file or in a string inside the host program. | 1230 | A chunk can be stored in a file or in a string inside the host program. |
@@ -2241,8 +2241,8 @@ and so the second @id{x} refers to the outside variable. | |||
2241 | Because of the @x{lexical scoping} rules, | 2241 | Because of the @x{lexical scoping} rules, |
2242 | local variables can be freely accessed by functions | 2242 | local variables can be freely accessed by functions |
2243 | defined inside their scope. | 2243 | defined inside their scope. |
2244 | A local variable used by an inner function is called | 2244 | A local variable used by an inner function is called an @def{upvalue} |
2245 | an @def{upvalue}, or @emphx{external local variable}, | 2245 | (or @emphx{external local variable}, or simply @emphx{external variable}) |
2246 | inside the inner function. | 2246 | inside the inner function. |
2247 | 2247 | ||
2248 | Notice that each execution of a @Rw{local} statement | 2248 | Notice that each execution of a @Rw{local} statement |
@@ -4765,11 +4765,7 @@ and returns its name. | |||
4765 | Returns @id{NULL} (and pushes nothing) | 4765 | Returns @id{NULL} (and pushes nothing) |
4766 | when the index @id{n} is greater than the number of upvalues. | 4766 | when the index @id{n} is greater than the number of upvalues. |
4767 | 4767 | ||
4768 | For @N{C functions}, this function uses the empty string @T{""} | 4768 | See @Lid{debug.getupvalue} for more information about upvalues. |
4769 | as a name for all upvalues. | ||
4770 | (For Lua functions, | ||
4771 | upvalues are the external local variables that the function uses, | ||
4772 | and that are consequently included in its closure.) | ||
4773 | 4769 | ||
4774 | } | 4770 | } |
4775 | 4771 | ||
@@ -8485,6 +8481,8 @@ The first parameter or local variable has @N{index 1}, and so on, | |||
8485 | following the order that they are declared in the code, | 8481 | following the order that they are declared in the code, |
8486 | counting only the variables that are active | 8482 | counting only the variables that are active |
8487 | in the current scope of the function. | 8483 | in the current scope of the function. |
8484 | Compile-time constants may not appear in this listing, | ||
8485 | if they were optimized away by the compiler. | ||
8488 | Negative indices refer to vararg arguments; | 8486 | Negative indices refer to vararg arguments; |
8489 | @num{-1} is the first vararg argument. | 8487 | @num{-1} is the first vararg argument. |
8490 | The function returns @nil if there is no variable with the given index, | 8488 | The function returns @nil if there is no variable with the given index, |
@@ -8520,8 +8518,15 @@ This function returns the name and the value of the upvalue | |||
8520 | with index @id{up} of the function @id{f}. | 8518 | with index @id{up} of the function @id{f}. |
8521 | The function returns @nil if there is no upvalue with the given index. | 8519 | The function returns @nil if there is no upvalue with the given index. |
8522 | 8520 | ||
8523 | Variable names starting with @Char{(} (open parenthesis) @C{)} | 8521 | (For Lua functions, |
8524 | represent variables with no known names | 8522 | upvalues are the external local variables that the function uses, |
8523 | and that are consequently included in its closure.) | ||
8524 | |||
8525 | For @N{C functions}, this function uses the empty string @T{""} | ||
8526 | as a name for all upvalues. | ||
8527 | |||
8528 | Variable name @Char{?} (interrogation mark) | ||
8529 | represents variables with no known names | ||
8525 | (variables from chunks saved without debug information). | 8530 | (variables from chunks saved without debug information). |
8526 | 8531 | ||
8527 | } | 8532 | } |
@@ -8626,6 +8631,8 @@ The function returns @nil if there is no upvalue | |||
8626 | with the given index. | 8631 | with the given index. |
8627 | Otherwise, it returns the name of the upvalue. | 8632 | Otherwise, it returns the name of the upvalue. |
8628 | 8633 | ||
8634 | See @Lid{debug.getupvalue} for more information about upvalues. | ||
8635 | |||
8629 | } | 8636 | } |
8630 | 8637 | ||
8631 | @LibEntry{debug.setuservalue (udata, value, n)| | 8638 | @LibEntry{debug.setuservalue (udata, value, n)| |