From 2e98c3d0644fc0c265844908f43b7e4526dd819c Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Thu, 23 Jun 2022 09:10:09 +0200
Subject: [PATCH 01/17] Grammar and spell check.
---
doc/ext_c_api.html | 4 +--
doc/ext_ffi.html | 14 ++++-----
doc/ext_ffi_api.html | 10 +++----
doc/ext_ffi_semantics.html | 58 +++++++++++++++++++-------------------
doc/ext_ffi_tutorial.html | 24 ++++++++--------
doc/ext_jit.html | 4 +--
doc/extensions.html | 8 +++---
doc/faq.html | 6 ++--
doc/install.html | 8 +++---
doc/running.html | 4 +--
doc/status.html | 4 +--
11 files changed, 72 insertions(+), 72 deletions(-)
diff --git a/doc/ext_c_api.html b/doc/ext_c_api.html
index a5d02473..b328047a 100644
--- a/doc/ext_c_api.html
+++ b/doc/ext_c_api.html
@@ -103,7 +103,7 @@ Turn the whole JIT compiler on or off or flush the whole cache of compiled code.
This sets the mode for the function at the stack index idx or
the parent of the calling function (idx = 0). It either
enables JIT compilation for a function, disables it and flushes any
-already compiled code or only flushes already compiled code. This
+already compiled code, or only flushes already compiled code. This
applies recursively to all sub-functions of the function with
LUAJIT_MODE_ALLFUNC or only to the sub-functions with
LUAJIT_MODE_ALLSUBFUNC.
@@ -122,7 +122,7 @@ traces which link to it.
This mode defines a wrapper function for calls to C functions. If
called with LUAJIT_MODE_ON, the stack index at idx
must be a lightuserdata object holding a pointer to the wrapper
-function. From now on all C functions are called through the wrapper
+function. From now on, all C functions are called through the wrapper
function. If called with LUAJIT_MODE_OFF this mode is turned
off and all C functions are directly called.
diff --git a/doc/ext_ffi.html b/doc/ext_ffi.html
index 7a87ca65..04b78d98 100644
--- a/doc/ext_ffi.html
+++ b/doc/ext_ffi.html
@@ -153,7 +153,7 @@ call the binding function. Phew!
Motivating Example: Using C Data Structures
The FFI library allows you to create and access C data
-structures. Of course the main use for this is for interfacing with
+structures. Of course, the main use for this is for interfacing with
C functions. But they can be used stand-alone, too.
@@ -165,7 +165,7 @@ implemented with a big table holding lots of tiny tables. This imposes
both a substantial memory overhead as well as a performance overhead.
-Here's a sketch of a library that operates on color images plus a
+Here's a sketch of a library that operates on color images, plus a
simple benchmark. First, the plain Lua version:
@@ -180,7 +180,7 @@ local function image_ramp_green(n)
return img
end
-local function image_to_grey(img, n)
+local function image_to_gray(img, n)
for i=1,n do
local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue)
img[i].red = y; img[i].green = y; img[i].blue = y
@@ -190,14 +190,14 @@ end
local N = 400*400
local img = image_ramp_green(N)
for i=1,1000 do
- image_to_grey(img, N)
+ image_to_gray(img, N)
end
This creates a table with 160.000 pixels, each of which is a table
-holding four number values in the range of 0-255. First an image with
+holding four number values in the range of 0-255. First, an image with
a green ramp is created (1D for simplicity), then the image is
-converted to greyscale 1000 times. Yes, that's silly, but I was in
+converted to grayscale 1000 times. Yes, that's silly, but I was in
need of a simple example ...
@@ -304,7 +304,7 @@ be more compact and faster. This is certainly true (by a factor of
~1.7x). Switching to a struct-of-arrays would help, too.
-However the resulting code would be less idiomatic and rather
+However, the resulting code would be less idiomatic and rather
error-prone. And it still doesn't get even close to the performance of
the FFI version of the code. Also, high-level data structures cannot
be easily passed to other C functions, especially I/O functions,
diff --git a/doc/ext_ffi_api.html b/doc/ext_ffi_api.html
index 687b85c5..962db6dc 100644
--- a/doc/ext_ffi_api.html
+++ b/doc/ext_ffi_api.html
@@ -117,7 +117,7 @@ separated by semicolons. The trailing semicolon for a single
declaration may be omitted.
-Please note that external symbols are only declared, but they
+Please note, that external symbols are only declared, but they
are not bound to any specific address, yet. Binding is
achieved with C library namespaces (see below).
@@ -205,7 +205,7 @@ parse the cdecl only once and get its ctype with
ffi.typeof(). Then use the ctype as a constructor repeatedly.
-Please note that an anonymous struct declaration implicitly
+Please note, that an anonymous struct declaration implicitly
creates a new and distinguished ctype every time you use it for
ffi.new(). This is probably not what you want,
especially if you create more than one cdata object. Different anonymous
@@ -252,12 +252,12 @@ afterwards. Neither the contents of the metatable nor the
contents of an __index table (if any) may be modified
afterwards. The associated metatable automatically applies to all uses
of this type, no matter how the objects are created or where they
-originate from. Note that pre-defined operations on types have
+originate from. Note that predefined operations on types have
precedence (e.g. declared field names cannot be overridden).
All standard Lua metamethods are implemented. These are called directly,
-without shortcuts and on any mix of types. For binary operations, the
+without shortcuts, and on any mix of types. For binary operations, the
left operand is checked first for a valid ctype metamethod. The
__gc metamethod only applies to struct/union
types and performs an implicit ffi.gc()
@@ -484,7 +484,7 @@ have some extra methods:
Free the resources associated with a callback. The associated Lua
function is unanchored and may be garbage collected. The callback
-function pointer is no longer valid and must not be called anymore
+function pointer is no longer valid and must not be called again
(it may be reused by a subsequently created callback).
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html
index 4909fedd..6c6f8ad7 100644
--- a/doc/ext_ffi_semantics.html
+++ b/doc/ext_ffi_semantics.html
@@ -84,7 +84,7 @@ footprint. It's used by the ffi.* library
functions to declare C types or external symbols.
-It's only purpose is to parse C declarations, as found e.g. in
+Its only purpose is to parse C declarations, as found e.g. in
C header files. Although it does evaluate constant expressions,
it's not a C compiler. The body of inline
C function definitions is simply ignored.
@@ -161,7 +161,7 @@ function declarations.
-The following C types are pre-defined by the C parser (like
+The following C types are predefined by the C parser (like
a typedef, except re-declarations will be ignored):
@@ -577,9 +577,9 @@ ffi.new("struct nested", {x=1,y={2,3}}) --> x = 1, y.a = 2, y.b = 3
Operations on cdata Objects
-All of the standard Lua operators can be applied to cdata objects or a
+All standard Lua operators can be applied to cdata objects or a
mix of a cdata object and another Lua object. The following list shows
-the pre-defined operations.
+the predefined operations.
Reference types are dereferenced before performing each of
@@ -587,7 +587,7 @@ the operations below — the operation is applied to the
C type pointed to by the reference.
-The pre-defined operations are always tried first before deferring to a
+The predefined operations are always tried first before deferring to a
metamethod or index table (if any) for the corresponding ctype (except
for __new). An error is raised if the metamethod lookup or
index table lookup fails.
@@ -637,7 +637,7 @@ assigning to an index of a vector raises an error.
A ctype object can be indexed with a string key, too. The only
-pre-defined operation is reading scoped constants of
+predefined operation is reading scoped constants of
struct/union types. All other accesses defer
to the corresponding metamethods or index tables (if any).
@@ -650,7 +650,7 @@ certain optimizations.
As a consequence, the elements of complex numbers and
vectors are immutable. But the elements of an aggregate holding these
-types may be modified of course. I.e. you cannot assign to
+types may be modified, of course. I.e. you cannot assign to
foo.c.im, but you can assign a (newly created) complex number
to foo.c.
@@ -669,8 +669,8 @@ through unions is explicitly detected and allowed.
to ffi.new(ct, ...), unless a __new metamethod is
defined. The __new metamethod is called with the ctype object
plus any other arguments passed to the constructor. Note that you have to
-use ffi.new inside of it, since calling ct(...) would
-cause infinite recursion.
+use ffi.new inside the metamethod, since calling ct(...)
+would cause infinite recursion.
C function call: a cdata function or cdata function
pointer can be called. The passed arguments are
@@ -681,7 +681,7 @@ variable argument part of vararg C function use
C function is called and the return value (if any) is
converted to a Lua object.
On Windows/x86 systems, __stdcall functions are automatically
-detected and a function declared as __cdecl (the default) is
+detected, and a function declared as __cdecl (the default) is
silently fixed up after the first call.
@@ -691,7 +691,7 @@ silently fixed up after the first call.
Pointer arithmetic: a cdata pointer/array and a cdata
number or a Lua number can be added or subtracted. The number must be
-on the right hand side for a subtraction. The result is a pointer of
+on the right-hand side for a subtraction. The result is a pointer of
the same type with an address plus or minus the number value
multiplied by the element size in bytes. An error is raised if the
element size is undefined.
@@ -706,7 +706,7 @@ operators (+ - * / % ^ and unary
minus) can be applied to two cdata numbers, or a cdata number and a
Lua number. If one of them is an uint64_t, the other side is
converted to an uint64_t and an unsigned arithmetic operation
-is performed. Otherwise both sides are converted to an
+is performed. Otherwise, both sides are converted to an
int64_t and a signed arithmetic operation is performed. The
result is a boxed 64 bit cdata object.
@@ -737,7 +737,7 @@ which is compatible with any other pointer type.
64 bit integer comparison: two cdata numbers, or a
cdata number and a Lua number can be compared with each other. If one
of them is an uint64_t, the other side is converted to an
-uint64_t and an unsigned comparison is performed. Otherwise
+uint64_t and an unsigned comparison is performed. Otherwise,
both sides are converted to an int64_t and a signed
comparison is performed.
@@ -762,9 +762,9 @@ keys!
A cdata object is treated like any other garbage-collected object and
is hashed and compared by its address for table indexing. Since
there's no interning for cdata value types, the same value may be
-boxed in different cdata objects with different addresses. Thus
+boxed in different cdata objects with different addresses. Thus,
t[1LL+1LL] and t[2LL] usually do not point to
-the same hash slot and they certainly do not point to the same
+the same hash slot, and they certainly do not point to the same
hash slot as t[2].
@@ -786,7 +786,7 @@ the resulting Lua number as a key when indexing tables.
One obvious benefit: t[tonumber(2LL)] does point to
the same slot as t[2].
-Otherwise use either tostring() on 64 bit integers
+Otherwise, use either tostring() on 64 bit integers
or complex numbers or combine multiple fields of a cdata aggregate to
a Lua string (e.g. with
ffi.string()). Then
@@ -794,7 +794,7 @@ use the resulting Lua string as a key when indexing tables.
Create your own specialized hash table implementation using the
C types provided by the FFI library, just like you would in
-C code. Ultimately this may give much better performance than the
+C code. Ultimately, this may give much better performance than the
other alternatives or what a generic by-value hash table could
possibly provide.
@@ -860,7 +860,7 @@ garbage collector will automatically free the memory used by it (at
the end of the next GC cycle).
-Please note that pointers themselves are cdata objects, however they
+Please note, that pointers themselves are cdata objects, however they
are not followed by the garbage collector. So e.g. if you
assign a cdata array to a pointer, you must keep the cdata object
holding the array alive as long as the pointer is still in use:
@@ -909,18 +909,18 @@ of the function pointer and the Lua function object (closure).
This can happen implicitly due to the usual conversions, e.g. when
-passing a Lua function to a function pointer argument. Or you can use
+passing a Lua function to a function pointer argument. Or, you can use
ffi.cast() to explicitly cast a Lua function to a
C function pointer.
-Currently only certain C function types can be used as callback
+Currently, only certain C function types can be used as callback
functions. Neither C vararg functions nor functions with
pass-by-value aggregate argument or result types are supported. There
-are no restrictions for the kind of Lua functions that can be called
+are no restrictions on the kind of Lua functions that can be called
from the callback — no checks for the proper number of arguments
are made. The return value of the Lua function will be converted to the
-result type and an error will be thrown for invalid conversions.
+result type, and an error will be thrown for invalid conversions.
It's allowed to throw errors across a callback invocation, but it's not
@@ -981,7 +981,7 @@ convention cannot be automatically detected, unlike for
__stdcall calls to Windows functions.
-For some use cases it's necessary to free up the resources or to
+For some use cases, it's necessary to free up the resources or to
dynamically redirect callbacks. Use an explicit cast to a
C function pointer and keep the resulting cdata object. Then use
the cb:free()
@@ -1034,7 +1034,7 @@ GUI application, which waits for user input most of the time, anyway.
For new designs avoid push-style APIs: a C function repeatedly
-calling a callback for each result. Instead use pull-style APIs:
+calling a callback for each result. Instead, use pull-style APIs:
call a C function repeatedly to get a new result. Calls from Lua
to C via the FFI are much faster than the other way round. Most well-designed
libraries already use pull-style APIs (read/write, get/put).
@@ -1053,7 +1053,7 @@ function.
Indexing a C library namespace object with a symbol name (a Lua
-string) automatically binds it to the library. First the symbol type
+string) automatically binds it to the library. First, the symbol type
is resolved — it must have been declared with
ffi.cdef. Then the
symbol address is resolved by searching for the symbol name in the
@@ -1108,7 +1108,7 @@ Performance notice: the JIT compiler specializes to the identity of
namespace objects and to the strings used to index it. This
effectively turns function cdata objects into constants. It's not
useful and actually counter-productive to explicitly cache these
-function objects, e.g. local strlen = ffi.C.strlen. OTOH it
+function objects, e.g. local strlen = ffi.C.strlen. OTOH, it
is useful to cache the namespace itself, e.g. local C =
ffi.C.
@@ -1133,14 +1133,14 @@ This behavior is inevitable, since the goal is to provide full
interoperability with C code. Adding extra safety measures, like
bounds checks, would be futile. There's no way to detect
misdeclarations of C functions, since shared libraries only
-provide symbol names, but no type information. Likewise there's no way
+provide symbol names, but no type information. Likewise, there's no way
to infer the valid range of indexes for a returned pointer.
Again: the FFI library is a low-level library. This implies it needs
to be used with care, but it's flexibility and performance often
outweigh this concern. If you're a C or C++ developer, it'll be easy
-to apply your existing knowledge. OTOH writing code for the FFI
+to apply your existing knowledge. OTOH, writing code for the FFI
library is not for the faint of heart and probably shouldn't be the
first exercise for someone with little experience in Lua, C or C++.
@@ -1168,7 +1168,7 @@ currently incomplete:
C declarations are not passed through a C pre-processor,
yet.
The C parser is able to evaluate most constant expressions
-commonly found in C header files. However it doesn't handle the
+commonly found in C header files. However, it doesn't handle the
full range of C expression semantics and may fail for some
obscure constructs.
static const declarations only work for integer types
diff --git a/doc/ext_ffi_tutorial.html b/doc/ext_ffi_tutorial.html
index c5e423b8..de6b6f5e 100644
--- a/doc/ext_ffi_tutorial.html
+++ b/doc/ext_ffi_tutorial.html
@@ -81,7 +81,7 @@ of its functions:
local ffi = require("ffi")
-Please note this doesn't define an ffi variable in the table
+Please note, this doesn't define an ffi variable in the table
of globals — you really need to use the local variable. The
require function ensures the library is only loaded once.
@@ -190,7 +190,7 @@ don't need to declare them as such.
⑤ The poll()
function takes a couple more arguments we're not going to use. You can
simply use nil to pass a NULL pointer and 0
-for the nfds parameter. Please note that the
+for the nfds parameter. Please note, that the
number 0 does not convert to a pointer value,
unlike in C++. You really have to pass pointers to pointer arguments
and numbers to number arguments.
@@ -287,12 +287,12 @@ Here's the step-by-step explanation:
① This defines some of the
C functions provided by zlib. For the sake of this example, some
-type indirections have been reduced and it uses the pre-defined
+type indirections have been reduced and it uses the predefined
fixed-size integer types, while still adhering to the zlib API/ABI.
② This loads the zlib shared
-library. On POSIX systems it's named libz.so and usually
+library. On POSIX systems, it's named libz.so and usually
comes pre-installed. Since ffi.load() automatically adds any
missing standard prefixes/suffixes, we can simply load the
"z" library. On Windows it's named zlib1.dll and
@@ -320,7 +320,7 @@ actual length that was used.
In C you'd pass in the address of a local variable
(&buflen). But since there's no address-of operator in
-Lua, we'll just pass in a one-element array. Conveniently it can be
+Lua, we'll just pass in a one-element array. Conveniently, it can be
initialized with the maximum buffer size in one step. Calling the
actual zlib.compress2 function is then straightforward.
@@ -344,7 +344,7 @@ for garbage collection and string interning.
⑥ The uncompress
functions does the exact opposite of the compress function.
The compressed data doesn't include the size of the original string,
-so this needs to be passed in. Otherwise no surprises here.
+so this needs to be passed in. Otherwise, no surprises here.
⑦ The code, that makes use
@@ -378,7 +378,7 @@ Ok, so the ffi.* functions generally accept cdata objects
wherever you'd want to use a number. That's why we get a away with
passing n to ffi.string() above. But other Lua
library functions or modules don't know how to deal with this. So for
-maximum portability one needs to use tonumber() on returned
+maximum portability, one needs to use tonumber() on returned
long results before passing them on. Otherwise the
application might work on some systems, but would fail in a POSIX/x64
environment.
@@ -450,7 +450,7 @@ the origin.
④ If we run out of operators, we can
-define named methods, too. Here the __index table defines an
+define named methods, too. Here, the __index table defines an
area function. For custom indexing needs, one might want to
define __index and __newindex functions instead.
@@ -464,13 +464,13 @@ be used e.g. to create an array of points. The metamethods automatically
apply to any and all uses of this type.
-Please note that the association with a metatable is permanent and
+Please note, that the association with a metatable is permanent and
the metatable must not be modified afterwards! Ditto for the
__index table.
⑥ Here are some simple usage examples
-for the point type and their expected results. The pre-defined
+for the point type and their expected results. The predefined
operations (such as a.x) can be freely mixed with the newly
defined metamethods. Note that area is a method and must be
called with the Lua syntax for methods: a:area(), not
@@ -479,7 +479,7 @@ called with the Lua syntax for methods: a:area(), not
The C type metamethod mechanism is most useful when used in
conjunction with C libraries that are written in an object-oriented
-style. Creators return a pointer to a new instance and methods take an
+style. Creators return a pointer to a new instance, and methods take an
instance pointer as the first argument. Sometimes you can just point
__index to the library namespace and __gc to the
destructor and you're done. But often enough you'll want to add
@@ -565,7 +565,7 @@ end
This turns them into indirect calls and generates bigger and slower
-machine code. Instead you'll want to cache the namespace itself and
+machine code. Instead, you'll want to cache the namespace itself and
rely on the JIT compiler to eliminate the lookups:
diff --git a/doc/ext_jit.html b/doc/ext_jit.html
index be1bdcf6..8f58a0c7 100644
--- a/doc/ext_jit.html
+++ b/doc/ext_jit.html
@@ -150,7 +150,7 @@ Contains the target architecture name:
jit.opt.* — JIT compiler optimization control
-This sub-module provides the backend for the -O command line
+This submodule provides the backend for the -O command line
option.
@@ -170,7 +170,7 @@ which was one of the ways to enable optimization.
jit.util.* — JIT compiler introspection
-This sub-module holds functions to introspect the bytecode, generated
+This submodule holds functions to introspect the bytecode, generated
traces, the IR and the generated machine code. The functionality
provided by this module is still in flux and therefore undocumented.
diff --git a/doc/extensions.html b/doc/extensions.html
index fe4df6f7..3ed13804 100644
--- a/doc/extensions.html
+++ b/doc/extensions.html
@@ -84,7 +84,7 @@ or LuaJIT.
LuaJIT extends the standard Lua VM with new functionality and adds
-several extension modules. Please note this page is only about
+several extension modules. Please note, this page is only about
functional enhancements and not about performance enhancements,
such as the optimized VM, the faster interpreter or the JIT compiler.
@@ -185,7 +185,7 @@ usage. See also the
The generated bytecode is portable and can be loaded on any architecture
-that LuaJIT supports, independent of word size or endianess. However the
+that LuaJIT supports, independent of word size or endianess. However, the
bytecode compatibility versions must match. Bytecode stays compatible
for dot releases (x.y.0 → x.y.1), but may change with major or
minor releases (2.0 → 2.1) or between any beta release. Foreign
@@ -197,7 +197,7 @@ bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.
LuaJIT uses a Tausworthe PRNG with period 2^223 to implement
math.random() and math.randomseed(). The quality of
the PRNG results is much superior compared to the standard Lua
-implementation which uses the platform-specific ANSI rand().
+implementation, which uses the platform-specific ANSI rand().
The PRNG generates the same sequences from the same seeds on all
@@ -215,7 +215,7 @@ Important: Neither this nor any other PRNG based on the simplistic
io.* functions handle 64 bit file offsets
The file I/O functions in the standard io.* library handle
-64 bit file offsets. In particular this means it's possible
+64 bit file offsets. In particular, this means it's possible
to open files larger than 2 Gigabytes and to reposition or obtain
the current file position for offsets beyond 2 GB
(fp:seek() method).
diff --git a/doc/faq.html b/doc/faq.html
index 36b2eafc..0b4b2df0 100644
--- a/doc/faq.html
+++ b/doc/faq.html
@@ -116,7 +116,7 @@ Direct3D version 10 or higher do not show this behavior anymore.
Consider testing your application with older versions, too.
Similarly, the Borland/Delphi runtime modifies the FPU control word and
-enables FP exceptions. Of course this violates the Windows ABI, too.
+enables FP exceptions. Of course, this violates the Windows ABI, too.
Please check the Delphi docs for the Set8087CW method.
@@ -126,7 +126,7 @@ Please check the Delphi docs for the Set8087CW method.
ignored by compiled code. If your program is running in a tight loop
and never falls back to the interpreter, the debug hook never runs and
can't throw the "interrupted!" error.
-You have to press Ctrl-C twice to get stop your program. That's similar
+You have to press Ctrl-C twice to stop your program. That's similar
to when it's stuck running inside a C function under the Lua interpreter.
@@ -146,7 +146,7 @@ so it doesn't rely on the key order. Or sort the table keys, if you must.
- Q: Can Lua code be safely sandboxed?
-
-Maybe for an extremly restricted subset of Lua and if you relentlessly
+Maybe for an extremely restricted subset of Lua and if you relentlessly
scrutinize every single interface function you offer to the untrusted code.
Although Lua provides some sandboxing functionality (setfenv(), hooks),
diff --git a/doc/install.html b/doc/install.html
index 19fab1b8..fe89fc5c 100644
--- a/doc/install.html
+++ b/doc/install.html
@@ -317,7 +317,7 @@ The recommended way to fetch the latest version is to do a pull from
the git repository.
-Alternatively download the latest source package of LuaJIT (pick the .tar.gz).
+Alternatively, download the latest source package of LuaJIT (pick the .tar.gz).
Move it to a directory of your choice, open a terminal window and change
to this directory. Now unpack the archive and change to the newly created
directory (replace XX.YY.ZZ with the version you downloaded):
@@ -475,7 +475,7 @@ important to compile with the proper CPU or architecture settings. You
can specify these when building the toolchain yourself. Or add
-mcpu=... or -march=... to TARGET_CFLAGS. For
ARM it's important to have the correct -mfloat-abi=... setting,
-too. Otherwise LuaJIT may not run at the full performance of your target
+too. Otherwise, LuaJIT may not run at the full performance of your target
CPU.
@@ -619,7 +619,7 @@ allocator from your system (no support for this on 64 bit architectures).
of calling luaopen_base etc. directly.
To change or extend the list of standard libraries to load, copy
src/lib_init.c to your project and modify it accordingly.
-Make sure the jit library is loaded or the JIT compiler
+Make sure the jit library is loaded, or the JIT compiler
will not be activated.
The bit.* module for bitwise operations
is already built-in. There's no need to statically link
@@ -638,7 +638,7 @@ in unspeakable ways.
There should be absolutely no need to patch luaconf.h or any
of the Makefiles. And please do not hand-pick files for your packages —
simply use whatever make install creates. There's a reason
-for all of the files and directories it creates.
+for all the files and directories it creates.
The build system uses GNU make and auto-detects most settings based on
diff --git a/doc/running.html b/doc/running.html
index 2ce02bc4..3f408141 100644
--- a/doc/running.html
+++ b/doc/running.html
@@ -179,7 +179,7 @@ written in Lua. They are mainly used for debugging the JIT compiler
itself. For a description of their options and output format, please
read the comment block at the start of their source.
They can be found in the lib directory of the source
-distribution or installed under the jit directory. By default
+distribution or installed under the jit directory. By default,
this is /usr/local/share/luajit-XX.YY.ZZ>/jit on POSIX
systems (replace XX.YY.ZZ by the installed version).
@@ -211,7 +211,7 @@ to a specific value.
You can either use this option multiple times (like -Ocse
-O-dce -Ohotloop=10) or separate several settings with a comma
(like -O+cse,-dce,hotloop=10). The settings are applied from
-left to right and later settings override earlier ones. You can freely
+left to right, and later settings override earlier ones. You can freely
mix the three forms, but note that setting an optimization level
overrides all earlier flags.
diff --git a/doc/status.html b/doc/status.html
index c251d224..7ecedf3d 100644
--- a/doc/status.html
+++ b/doc/status.html
@@ -79,7 +79,7 @@ Known incompatibilities and issues in LuaJIT 2.0:
-
There are some differences in implementation-defined behavior.
-These either have a good reason, are arbitrary design choices
+These either have a good reason, are arbitrary design choices,
or are due to quirks in the VM. The latter cases may get fixed if a
demonstrable need is shown.
@@ -89,7 +89,7 @@ hooks for non-Lua functions) and shows slightly different behavior
in LuaJIT (no per-coroutine hooks, no tail call counting).
-Currently some out-of-memory errors from on-trace code are not
+Currently, some out-of-memory errors from on-trace code are not
handled correctly. The error may fall through an on-trace
pcall or it may be passed on to the function set with
lua_atpanic on x64.
From 674afcd4e21d0cf64de3219d347557a0aed8ecc7 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Fri, 8 Jul 2022 14:57:01 +0200
Subject: [PATCH 02/17] x86/x64: Fix math.ceil(-0.9) result sign.
Reported by minoki.
---
src/vm_x86.dasc | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc
index 8c2740c3..7db5e710 100644
--- a/src/vm_x86.dasc
+++ b/src/vm_x86.dasc
@@ -415,9 +415,6 @@
|.macro sseconst_1, reg, tmp // Synthesize 1.0.
| sseconst_hi reg, tmp, 3ff00000
|.endmacro
-|.macro sseconst_m1, reg, tmp // Synthesize -1.0.
-| sseconst_hi reg, tmp, bff00000
-|.endmacro
|.macro sseconst_2p52, reg, tmp // Synthesize 2^52.
| sseconst_hi reg, tmp, 43300000
|.endmacro
@@ -3114,15 +3111,17 @@ static void build_subroutines(BuildCtx *ctx)
| addsd xmm1, xmm3 // (|x| + 2^52) - 2^52
| subsd xmm1, xmm3
| orpd xmm1, xmm2 // Merge sign bit back in.
+ | sseconst_1 xmm3, RDa
| .if mode == 1 // ceil(x)?
- | sseconst_m1 xmm2, RDa // Must subtract -1 to preserve -0.
| cmpsd xmm0, xmm1, 6 // x > result?
+ | andpd xmm0, xmm3
+ | addsd xmm1, xmm0 // If yes, add 1.
+ | orpd xmm1, xmm2 // Merge sign bit back in (again).
| .else // floor(x)?
- | sseconst_1 xmm2, RDa
| cmpsd xmm0, xmm1, 1 // x < result?
+ | andpd xmm0, xmm3
+ | subsd xmm1, xmm0 // If yes, subtract 1.
| .endif
- | andpd xmm0, xmm2
- | subsd xmm1, xmm0 // If yes, subtract +-1.
|.endif
| movaps xmm0, xmm1
|1:
From 6bda30d8c745b3963ba870221b9be6acdffed9b1 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Tue, 12 Jul 2022 22:21:26 +0200
Subject: [PATCH 03/17] LJ_GC64: Fix IR_VARG offset for fixed number of
results.
Reported by George Vaintrub. Fixed by Sergey Kaplun.
---
src/lj_record.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lj_record.c b/src/lj_record.c
index faa9a508..9c85f9f7 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -1961,7 +1961,7 @@ static void rec_varg(jit_State *J, BCReg dst, ptrdiff_t nresults)
emitir(IRTGI(IR_EQ), fr,
lj_ir_kint(J, (int32_t)frame_ftsz(J->L->base-1)));
vbase = emitir(IRT(IR_SUB, IRT_IGC), REF_BASE, fr);
- vbase = emitir(IRT(IR_ADD, IRT_PGC), vbase, lj_ir_kint(J, frofs-8));
+ vbase = emitir(IRT(IR_ADD, IRT_PGC), vbase, lj_ir_kint(J, frofs-8*(1+LJ_FR2)));
for (i = 0; i < nload; i++) {
IRType t = itype2irt(&J->L->base[i-1-LJ_FR2-nvararg]);
J->base[dst+i] = lj_record_vload(J, vbase, i, t);
From b98b37231bd2dcb79e10b0f974cefd91eb0d7b3a Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Tue, 12 Jul 2022 22:25:33 +0200
Subject: [PATCH 04/17] OSX/iOS/ARM64: Fix bytecode embedding in Mach-O object
file.
Thanks to Carlo Cabrera.
---
src/jit/bcsave.lua | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua
index 6227d136..adf197c6 100644
--- a/src/jit/bcsave.lua
+++ b/src/jit/bcsave.lua
@@ -501,6 +501,18 @@ typedef struct {
mach_nlist sym_entry;
uint8_t space[4096];
} mach_fat_obj;
+typedef struct {
+ mach_fat_header fat;
+ mach_fat_arch fat_arch[2];
+ struct {
+ mach_header_64 hdr;
+ mach_segment_command_64 seg;
+ mach_section_64 sec;
+ mach_symtab_command sym;
+ } arch[2];
+ mach_nlist_64 sym_entry;
+ uint8_t space[4096];
+} mach_fat_obj_64;
]]
local symname = '_'..LJBC_PREFIX..ctx.modname
local isfat, is64, align, mobj = false, false, 4, "mach_obj"
@@ -509,7 +521,7 @@ typedef struct {
elseif ctx.arch == "arm" then
isfat, mobj = true, "mach_fat_obj"
elseif ctx.arch == "arm64" then
- is64, align, isfat, mobj = true, 8, true, "mach_fat_obj"
+ is64, align, isfat, mobj = true, 8, true, "mach_fat_obj_64"
else
check(ctx.arch == "x86", "unsupported architecture for OSX")
end
From 27a6fee82e91319bbed8c3aa443aa2b0f1b0a470 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Wed, 13 Jul 2022 00:30:23 +0200
Subject: [PATCH 05/17] FFI: Allow ffi.metatype() for typedefs with attributes.
Reported by Eric Gouyer.
---
src/lib_ffi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index cc8d419d..6eaec71c 100644
--- a/src/lib_ffi.c
+++ b/src/lib_ffi.c
@@ -743,7 +743,7 @@ LJLIB_CF(ffi_metatype)
CTypeID id = ffi_checkctype(L, cts, NULL);
GCtab *mt = lj_lib_checktab(L, 2);
GCtab *t = cts->miscmap;
- CType *ct = ctype_get(cts, id); /* Only allow raw types. */
+ CType *ct = ctype_raw(cts, id);
TValue *tv;
GCcdata *cd;
if (!(ctype_isstruct(ct->info) || ctype_iscomplex(ct->info) ||
From 36b2962d400db3981a7d7322f85c469240eb6f3b Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Wed, 13 Jul 2022 00:32:04 +0200
Subject: [PATCH 06/17] FFI: Fix ffi.alignof() for reference types.
Reported by Eric Gouyer.
---
src/lib_ffi.c | 2 +-
src/lj_ctype.c | 8 ++++++++
src/lj_ctype.h | 1 +
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/lib_ffi.c b/src/lib_ffi.c
index 6eaec71c..654e71a2 100644
--- a/src/lib_ffi.c
+++ b/src/lib_ffi.c
@@ -615,7 +615,7 @@ LJLIB_CF(ffi_alignof) LJLIB_REC(ffi_xof FF_ffi_alignof)
CTState *cts = ctype_cts(L);
CTypeID id = ffi_checkctype(L, cts, NULL);
CTSize sz = 0;
- CTInfo info = lj_ctype_info(cts, id, &sz);
+ CTInfo info = lj_ctype_info_raw(cts, id, &sz);
setintV(L->top-1, 1 << ctype_align(info));
return 1;
}
diff --git a/src/lj_ctype.c b/src/lj_ctype.c
index 68edb287..7ef00521 100644
--- a/src/lj_ctype.c
+++ b/src/lj_ctype.c
@@ -328,6 +328,14 @@ CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp)
return qual;
}
+/* Ditto, but follow a reference. */
+CTInfo lj_ctype_info_raw(CTState *cts, CTypeID id, CTSize *szp)
+{
+ CType *ct = ctype_get(cts, id);
+ if (ctype_isref(ct->info)) id = ctype_cid(ct->info);
+ return lj_ctype_info(cts, id, szp);
+}
+
/* Get ctype metamethod. */
cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm)
{
diff --git a/src/lj_ctype.h b/src/lj_ctype.h
index 77551e76..4979a7ac 100644
--- a/src/lj_ctype.h
+++ b/src/lj_ctype.h
@@ -449,6 +449,7 @@ LJ_FUNC CType *lj_ctype_rawref(CTState *cts, CTypeID id);
LJ_FUNC CTSize lj_ctype_size(CTState *cts, CTypeID id);
LJ_FUNC CTSize lj_ctype_vlsize(CTState *cts, CType *ct, CTSize nelem);
LJ_FUNC CTInfo lj_ctype_info(CTState *cts, CTypeID id, CTSize *szp);
+LJ_FUNC CTInfo lj_ctype_info_raw(CTState *cts, CTypeID id, CTSize *szp);
LJ_FUNC cTValue *lj_ctype_meta(CTState *cts, CTypeID id, MMS mm);
LJ_FUNC GCstr *lj_ctype_repr(lua_State *L, CTypeID id, GCstr *name);
LJ_FUNC GCstr *lj_ctype_repr_int64(lua_State *L, uint64_t n, int isunsigned);
From 899093a9e0fa5b16f27016381ef4b15529dadff2 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Wed, 13 Jul 2022 00:32:31 +0200
Subject: [PATCH 07/17] FFI: Fix sizeof expression in C parser for reference
types.
---
src/lj_cparse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lj_cparse.c b/src/lj_cparse.c
index 9cd26d67..df85d23b 100644
--- a/src/lj_cparse.c
+++ b/src/lj_cparse.c
@@ -457,7 +457,7 @@ static void cp_expr_sizeof(CPState *cp, CPValue *k, int wantsz)
} else {
cp_expr_unary(cp, k);
}
- info = lj_ctype_info(cp->cts, k->id, &sz);
+ info = lj_ctype_info_raw(cp->cts, k->id, &sz);
if (wantsz) {
if (sz != CTSIZE_INVALID)
k->u32 = sz;
From 5677985dc1f19cf0a67112f4365c7fb79237fa16 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Tue, 19 Jul 2022 12:53:34 +0200
Subject: [PATCH 08/17] ARM64: Allow building with unwinding disabled.
---
src/vm_arm64.dasc | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc
index f5f1b5f1..3448d0d2 100644
--- a/src/vm_arm64.dasc
+++ b/src/vm_arm64.dasc
@@ -3988,6 +3988,7 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align 3\n"
".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
#endif
+#if !LJ_NO_UNWIND
fprintf(ctx->fp, "\t.section .eh_frame,\"a\",%%progbits\n");
fprintf(ctx->fp,
".Lframe1:\n"
@@ -4055,6 +4056,7 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.byte 0x94\n\t.uleb128 4\n" /* offset x20 */
"\t.align 3\n"
".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
+#endif
#endif
break;
#if !LJ_NO_UNWIND
From 32984282ddae666b3c94cd27538e1c78b49a1877 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Thu, 21 Jul 2022 17:30:56 +0200
Subject: [PATCH 09/17] Prevent trace start at BC_ITERL after compiled
BC_ITERN.
Reported by ccagml.
---
src/lj_record.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/lj_record.c b/src/lj_record.c
index 9c85f9f7..92bdbfc9 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -2665,6 +2665,8 @@ static const BCIns *rec_setup_root(jit_State *J)
J->bc_min = pc;
break;
case BC_ITERL:
+ if (bc_op(pc[-1]) == BC_JLOOP)
+ lj_trace_err(J, LJ_TRERR_LINNER);
lj_assertJ(bc_op(pc[-1]) == BC_ITERC, "no ITERC before ITERL");
J->maxslot = ra + bc_b(pc[-1]) - 1;
J->bc_extent = (MSize)(-bc_j(ins))*sizeof(BCIns);
From 3065c910ad6027031aabe2dfd3c26a3d0f014b4f Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Fri, 22 Jul 2022 12:14:40 +0200
Subject: [PATCH 10/17] OSX/iOS/ARM64: Fix generation of Mach-O object files.
Thanks to Carlo Cabrera.
---
src/jit/bcsave.lua | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua
index adf197c6..f8ed3a1b 100644
--- a/src/jit/bcsave.lua
+++ b/src/jit/bcsave.lua
@@ -456,18 +456,18 @@ typedef struct {
uint32_t value;
} mach_nlist;
typedef struct {
- uint32_t strx;
+ int32_t strx;
uint8_t type, sect;
uint16_t desc;
uint64_t value;
} mach_nlist_64;
typedef struct
{
- uint32_t magic, nfat_arch;
+ int32_t magic, nfat_arch;
} mach_fat_header;
typedef struct
{
- uint32_t cputype, cpusubtype, offset, size, align;
+ int32_t cputype, cpusubtype, offset, size, align;
} mach_fat_arch;
typedef struct {
struct {
From e1339aed3db2fb8488a170383fc456fe04879709 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Wed, 27 Jul 2022 11:32:33 +0200
Subject: [PATCH 11/17] x86/x64: Limit VLOAD fusion to simple cases.
Reported by ccagml.
---
src/lj_asm_x86.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/lj_asm_x86.h b/src/lj_asm_x86.h
index 4465efa2..2bf9d939 100644
--- a/src/lj_asm_x86.h
+++ b/src/lj_asm_x86.h
@@ -485,7 +485,8 @@ static Reg asm_fuseload(ASMState *as, IRRef ref, RegSet allow)
asm_fusexref(as, ir->op1, xallow);
return RID_MRM;
}
- } else if (ir->o == IR_VLOAD && !(LJ_GC64 && irt_isaddr(ir->t))) {
+ } else if (ir->o == IR_VLOAD && IR(ir->op1)->o == IR_AREF &&
+ !(LJ_GC64 && irt_isaddr(ir->t))) {
asm_fuseahuref(as, ir->op1, xallow);
as->mrm.ofs += 8 * ir->op2;
return RID_MRM;
From 9c3df68a1e00bd1fcaee13610fb063efe8ae3825 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Thu, 28 Jul 2022 15:38:54 +0200
Subject: [PATCH 12/17] Add missing GC steps to string buffer methods.
Reported by Cosmin Apreutesei.
---
src/lib_buffer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/lib_buffer.c b/src/lib_buffer.c
index e3d24504..aad8e7eb 100644
--- a/src/lib_buffer.c
+++ b/src/lib_buffer.c
@@ -323,6 +323,7 @@ LJLIB_CF(buffer_new)
setgcref(sbx->dict_str, obj2gco(dict_str));
setgcref(sbx->dict_mt, obj2gco(dict_mt));
if (sz > 0) lj_buf_need2((SBuf *)sbx, sz);
+ lj_gc_check(L);
return 1;
}
@@ -339,6 +340,7 @@ LJLIB_CF(buffer_decode) LJLIB_REC(.)
GCstr *str = lj_lib_checkstrx(L, 1);
setnilV(L->top++);
lj_serialize_decode(L, L->top-1, str);
+ lj_gc_check(L);
return 1;
}
From a7d0265480c662964988f83d4e245bf139eb7cc0 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Thu, 28 Jul 2022 15:40:28 +0200
Subject: [PATCH 13/17] Improve GC estimation for userdata with attached
managed memory.
This works well for string.buffers, but not for userdata or
cdata with attached unmanaged memory (malloc/free, mmap/munmap).
---
src/lj_gc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/lj_gc.c b/src/lj_gc.c
index b35a0d44..2fc52ec1 100644
--- a/src/lj_gc.c
+++ b/src/lj_gc.c
@@ -700,9 +700,12 @@ static size_t gc_onestep(lua_State *L)
}
case GCSfinalize:
if (gcref(g->gc.mmudata) != NULL) {
+ GCSize old = g->gc.total;
if (tvref(g->jit_base)) /* Don't call finalizers on trace. */
return LJ_MAX_MEM;
gc_finalize(L); /* Finalize one userdata object. */
+ if (old >= g->gc.total && g->gc.estimate > old - g->gc.total)
+ g->gc.estimate -= old - g->gc.total;
if (g->gc.estimate > GCFINALIZECOST)
g->gc.estimate -= GCFINALIZECOST;
return GCFINALIZECOST;
From a93f4bb39ff99399994b19249e0833da64bc2eb0 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Sun, 7 Aug 2022 20:02:40 +0200
Subject: [PATCH 14/17] Prevent use of RTLD_DEFAULT when NO_RTLD_DEFAULT is
defined.
Workaround for Android 4.4 bug.
Thanks to gudzpoz.
---
src/lib_package.c | 2 +-
src/lj_clib.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lib_package.c b/src/lib_package.c
index a9c1ca48..d2ef474f 100644
--- a/src/lib_package.c
+++ b/src/lib_package.c
@@ -57,7 +57,7 @@ static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
static const char *ll_bcsym(void *lib, const char *sym)
{
-#if defined(RTLD_DEFAULT)
+#if defined(RTLD_DEFAULT) && !defined(NO_RTLD_DEFAULT)
if (lib == NULL) lib = RTLD_DEFAULT;
#elif LJ_TARGET_OSX || LJ_TARGET_BSD
if (lib == NULL) lib = (void *)(intptr_t)-2;
diff --git a/src/lj_clib.c b/src/lj_clib.c
index e0f274bb..ab2db33a 100644
--- a/src/lj_clib.c
+++ b/src/lj_clib.c
@@ -24,7 +24,7 @@
#include
#include
-#if defined(RTLD_DEFAULT)
+#if defined(RTLD_DEFAULT) && !defined(NO_RTLD_DEFAULT)
#define CLIB_DEFHANDLE RTLD_DEFAULT
#elif LJ_TARGET_OSX || LJ_TARGET_BSD
#define CLIB_DEFHANDLE ((void *)(intptr_t)-2)
From 633f265f67f322cbe2c5fd11d3e46d968ac220f7 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Wed, 10 Aug 2022 19:27:53 +0200
Subject: [PATCH 15/17] LJ_GC64: Fix lua_concat().
Reported by Mathias Westerdahl.
---
src/lj_api.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lj_api.c b/src/lj_api.c
index d869ebf8..e6b67478 100644
--- a/src/lj_api.c
+++ b/src/lj_api.c
@@ -779,7 +779,7 @@ LUA_API void lua_concat(lua_State *L, int n)
L->top -= n;
break;
}
- n -= (int)(L->top - top);
+ n -= (int)(L->top - (top - 2*LJ_FR2));
L->top = top+2;
lj_vm_call(L, top, 1+1);
L->top -= 1+LJ_FR2;
From 3b3d427ae3bdb56c46ee75f7f596c837e97c5043 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Mon, 15 Aug 2022 14:16:14 +0200
Subject: [PATCH 16/17] Patch luajit.pc with INSTALL_INC, if customized.
Suggested by Henrique Bucher.
---
Makefile | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 35da2e73..0004c2c5 100644
--- a/Makefile
+++ b/Makefile
@@ -32,7 +32,8 @@ DPREFIX= $(DESTDIR)$(PREFIX)
INSTALL_BIN= $(DPREFIX)/bin
INSTALL_LIB= $(DPREFIX)/$(MULTILIB)
INSTALL_SHARE= $(DPREFIX)/share
-INSTALL_INC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER)
+INSTALL_DEFINC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER)
+INSTALL_INC= $(INSTALL_DEFINC)
INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(VERSION)
INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit
@@ -77,6 +78,9 @@ UNINSTALL= $(RM)
LDCONFIG= ldconfig -n 2>/dev/null
SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" \
-e "s|^multilib=.*|multilib=$(MULTILIB)|"
+ifneq ($(INSTALL_DEFINC),$(INSTALL_INC))
+ SED_PC+= -e "s|^includedir=.*|includedir=$(INSTALL_INC)|"
+endif
FILE_T= luajit
FILE_A= libluajit.a
From 03080b795aa3496ed62d4a0697c9f4767e7ca7e5 Mon Sep 17 00:00:00 2001
From: Mike Pall
Date: Mon, 15 Aug 2022 14:16:58 +0200
Subject: [PATCH 17/17] Add -F option to override filename in jit.bcsave
(luajit -b).
Suggested by Mathias Westerdahl.
---
doc/running.html | 1 +
src/jit/bcsave.lua | 29 ++++++++++++++++++++++-------
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/doc/running.html b/doc/running.html
index 177e6357..91a719f9 100644
--- a/doc/running.html
+++ b/doc/running.html
@@ -111,6 +111,7 @@ are accepted:
-t type — Set output file type (default: auto-detect from output name).
-a arch — Override architecture for object files (default: native).
-o os — Override OS for object files (default: native).
+-F name — Override filename (default: input filename).
-e chunk — Use chunk string as input.
- (a single minus sign) — Use stdin as input and/or stdout as output.
diff --git a/src/jit/bcsave.lua b/src/jit/bcsave.lua
index f8ed3a1b..90fe9daf 100644
--- a/src/jit/bcsave.lua
+++ b/src/jit/bcsave.lua
@@ -33,6 +33,7 @@ Save LuaJIT bytecode: luajit -b[options] input output
-t type Set output file type (default: auto-detect from output name).
-a arch Override architecture for object files (default: native).
-o os Override OS for object files (default: native).
+ -F name Override filename (default: input filename).
-e chunk Use chunk string as input.
-- Stop handling options.
- Use stdin as input and/or stdout as output.
@@ -49,10 +50,22 @@ local function check(ok, ...)
os.exit(1)
end
-local function readfile(input)
+local function readfile(ctx, input)
if type(input) == "function" then return input end
- if input == "-" then input = nil end
- return check(loadfile(input))
+ if ctx.filename then
+ local data
+ if input == "-" then
+ data = io.stdin:read("*a")
+ else
+ local fp = assert(io.open(input, "rb"))
+ data = assert(fp:read("*a"))
+ assert(fp:close())
+ end
+ return check(load(data, ctx.filename))
+ else
+ if input == "-" then input = nil end
+ return check(loadfile(input))
+ end
end
local function savefile(name, mode)
@@ -604,13 +617,13 @@ end
------------------------------------------------------------------------------
-local function bclist(input, output)
- local f = readfile(input)
+local function bclist(ctx, input, output)
+ local f = readfile(ctx, input)
require("jit.bc").dump(f, savefile(output, "w"), true)
end
local function bcsave(ctx, input, output)
- local f = readfile(input)
+ local f = readfile(ctx, input)
local s = string.dump(f, ctx.strip)
local t = ctx.type
if not t then
@@ -663,6 +676,8 @@ local function docmd(...)
ctx.arch = checkarg(tremove(arg, n), map_arch, "architecture")
elseif opt == "o" then
ctx.os = checkarg(tremove(arg, n), map_os, "OS name")
+ elseif opt == "F" then
+ ctx.filename = "@"..tremove(arg, n)
else
usage()
end
@@ -674,7 +689,7 @@ local function docmd(...)
end
if list then
if #arg == 0 or #arg > 2 then usage() end
- bclist(arg[1], arg[2] or "-")
+ bclist(ctx, arg[1], arg[2] or "-")
else
if #arg ~= 2 then usage() end
bcsave(ctx, arg[1], arg[2])