summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMikalaiR <nikolay.romanovich@narod.ru>2016-02-17 16:53:59 +0000
committerMikalaiR <nikolay.romanovich@narod.ru>2016-02-17 16:53:59 +0000
commit7a8fafbb2c8a2d1175c4f92b08d1b8c30f475a4a (patch)
treec1c93b4724215879f61ee94ff9ee99a1ead49115 /plugins
parent939e01edacc5746bc9c6501721f270751a9be10d (diff)
MirLua: fb ffi module
git-svn-id: http://svn.miranda-ng.org/main/trunk@16294 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/MirLua/Modules/ffi/luaffi.vcxproj (renamed from plugins/MirLua/Modules/luaffi/luaffi.vcxproj)2
-rw-r--r--plugins/MirLua/Modules/ffi/src/.gitignore23
-rw-r--r--plugins/MirLua/Modules/ffi/src/CONTRIBUTING.md30
-rw-r--r--plugins/MirLua/Modules/ffi/src/LICENSE58
-rw-r--r--plugins/MirLua/Modules/ffi/src/Makefile32
-rw-r--r--plugins/MirLua/Modules/ffi/src/PATENTS33
-rw-r--r--plugins/MirLua/Modules/ffi/src/README.md84
-rw-r--r--plugins/MirLua/Modules/ffi/src/call.c (renamed from plugins/MirLua/Modules/luaffi/src/call.c)16
-rw-r--r--plugins/MirLua/Modules/ffi/src/call_arm.dasc (renamed from plugins/MirLua/Modules/luaffi/src/call_arm.dasc)199
-rw-r--r--plugins/MirLua/Modules/ffi/src/call_arm.h (renamed from plugins/MirLua/Modules/luaffi/src/call_arm.h)396
-rw-r--r--plugins/MirLua/Modules/ffi/src/call_x64.h (renamed from plugins/MirLua/Modules/luaffi/src/call_x64.h)278
-rw-r--r--plugins/MirLua/Modules/ffi/src/call_x64win.h (renamed from plugins/MirLua/Modules/luaffi/src/call_x64win.h)271
-rw-r--r--plugins/MirLua/Modules/ffi/src/call_x86.dasc (renamed from plugins/MirLua/Modules/luaffi/src/call_x86.dasc)67
-rw-r--r--plugins/MirLua/Modules/ffi/src/call_x86.h (renamed from plugins/MirLua/Modules/luaffi/src/call_x86.h)249
-rw-r--r--plugins/MirLua/Modules/ffi/src/ctype.c (renamed from plugins/MirLua/Modules/luaffi/src/ctype.c)22
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_arm.h (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_arm.h)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_arm.lua (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_arm.lua)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_ppc.h (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_ppc.h)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_ppc.lua (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_ppc.lua)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_proto.h (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_proto.h)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_x64.lua (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x64.lua)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_x86.h (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x86.h)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dasm_x86.lua (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x86.lua)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/dynasm/dynasm.lua (renamed from plugins/MirLua/Modules/luaffi/src/dynasm/dynasm.lua)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/ffi.c (renamed from plugins/MirLua/Modules/luaffi/src/ffi.c)459
-rw-r--r--plugins/MirLua/Modules/ffi/src/ffi.h (renamed from plugins/MirLua/Modules/luaffi/src/ffi.h)67
-rw-r--r--plugins/MirLua/Modules/ffi/src/generate_call_h.bat (renamed from plugins/MirLua/Modules/luaffi/src/generate_call_h.bat)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/luaffi-scm-1.rockspec34
-rw-r--r--plugins/MirLua/Modules/ffi/src/msvc/inttypes.h (renamed from plugins/MirLua/Modules/luaffi/src/msvc/inttypes.h)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/msvc/stdbool.h (renamed from plugins/MirLua/Modules/luaffi/src/msvc/stdbool.h)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/msvc/stdint.h (renamed from plugins/MirLua/Modules/luaffi/src/msvc/stdint.h)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/msvcbuild.bat (renamed from plugins/MirLua/Modules/luaffi/src/msvcbuild.bat)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/parser.c (renamed from plugins/MirLua/Modules/luaffi/src/parser.c)226
-rw-r--r--plugins/MirLua/Modules/ffi/src/pretty.lua (renamed from plugins/MirLua/Modules/luaffi/src/pretty.lua)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/stdafx.cxx (renamed from plugins/MirLua/Modules/luaffi/src/stdafx.cxx)0
-rw-r--r--plugins/MirLua/Modules/ffi/src/test.c0 (renamed from plugins/MirLua/Modules/luaffi/src/test.c)53
-rw-r--r--plugins/MirLua/Modules/ffi/src/test.lua (renamed from plugins/MirLua/Modules/luaffi/src/test.lua)149
-rw-r--r--plugins/MirLua/Modules/ffi/src/test_includes.sh25
-rw-r--r--plugins/MirLua/Modules/luaffi/src/Makefile54
-rw-r--r--plugins/MirLua/Modules/luaffi/src/stdafx.h14
40 files changed, 1759 insertions, 1082 deletions
diff --git a/plugins/MirLua/Modules/luaffi/luaffi.vcxproj b/plugins/MirLua/Modules/ffi/luaffi.vcxproj
index f1ed45bbbd..bef3567b8e 100644
--- a/plugins/MirLua/Modules/luaffi/luaffi.vcxproj
+++ b/plugins/MirLua/Modules/ffi/luaffi.vcxproj
@@ -19,7 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
- <ProjectName>luaffi</ProjectName>
+ <ProjectName>ffi</ProjectName>
<ProjectGuid>{817D2806-9EC5-4607-A404-F031C98A1872}</ProjectGuid>
</PropertyGroup>
<ImportGroup Label="PropertySheets">
diff --git a/plugins/MirLua/Modules/ffi/src/.gitignore b/plugins/MirLua/Modules/ffi/src/.gitignore
new file mode 100644
index 0000000000..5d9b232efa
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/.gitignore
@@ -0,0 +1,23 @@
+*.dll
+*.exp
+*.lib
+*.pdb
+*.ilk
+.*.swp
+*.user
+/BuildLog.htm
+*.o
+*.so
+.*.swo
+.DS_Store
+/luaffi.xcodeproj
+*.ncb
+*.sln
+*.suo
+*.dSYM
+*.vcproj
+/luaffi
+/test_includes/
+*.swp
+*.dylib
+/tmp
diff --git a/plugins/MirLua/Modules/ffi/src/CONTRIBUTING.md b/plugins/MirLua/Modules/ffi/src/CONTRIBUTING.md
new file mode 100644
index 0000000000..3e7edc59cc
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/CONTRIBUTING.md
@@ -0,0 +1,30 @@
+# Contributing to luaffifb
+We want to make contributing to this project as easy and transparent as
+possible.
+
+## Our Development Process
+... (in particular how this is synced with internal changes to the project)
+
+## Pull Requests
+We actively welcome your pull requests.
+1. Fork the repo and create your branch from `master`.
+2. If you've added code that should be tested, add tests
+3. If you haven't already, complete the Contributor License Agreement ("CLA").
+
+## Contributor License Agreement ("CLA")
+In order to accept your pull request, we need you to submit a CLA. You only need
+to do this once to work on any of Facebook's open source projects.
+
+Complete your CLA here: <https://code.facebook.com/cla>
+
+## Issues
+We use GitHub issues to track public bugs. Please ensure your description is
+clear and has sufficient instructions to be able to reproduce the issue.
+
+## Coding Style
+* Use four spaces for indentation rather than tabs
+* 80 character line length
+
+## License
+By contributing to luaffifb, you agree that your contributions will be licensed
+under its BSD license.
diff --git a/plugins/MirLua/Modules/ffi/src/LICENSE b/plugins/MirLua/Modules/ffi/src/LICENSE
new file mode 100644
index 0000000000..dbfa937f14
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/LICENSE
@@ -0,0 +1,58 @@
+BSD License
+
+For luaffifb software
+
+Copyright (c) 2015, Facebook, Inc. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+ * Neither the name Facebook nor the names of its contributors may be used to
+ endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+--------------------------------------------------------------------------
+
+This product contains portions of third party software provided under this license:
+
+luaffi software
+
+Copyright (c) 2011 James R. McKaskill
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+Facebook provides this code under the BSD License above.
diff --git a/plugins/MirLua/Modules/ffi/src/Makefile b/plugins/MirLua/Modules/ffi/src/Makefile
new file mode 100644
index 0000000000..0c62c282f3
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/Makefile
@@ -0,0 +1,32 @@
+#
+# Use luarocks to install LuaFFI:
+# > git clone https://github.com/facebook/luaffifb
+# > cd luaffifb && luarocks make
+#
+# To rebuild the call_* headers:
+# > rm call_*.h && make headers
+#
+
+.PHONY: build clean headers
+LUA=lua
+
+build:
+ luarocks make
+
+clean:
+ rm -f *.o *.so *.dylib
+
+headers:
+ $(MAKE) call_x86.h call_x64.h call_x64win.h call_arm.h
+
+call_x86.h: call_x86.dasc dynasm/*.lua
+ $(LUA) dynasm/dynasm.lua -LN -o $@ $<
+
+call_x64.h: call_x86.dasc dynasm/*.lua
+ $(LUA) dynasm/dynasm.lua -D X64 -LN -o $@ $<
+
+call_x64win.h: call_x86.dasc dynasm/*.lua
+ $(LUA) dynasm/dynasm.lua -D X64 -D X64WIN -LN -o $@ $<
+
+call_arm.h: call_arm.dasc dynasm/*.lua
+ $(LUA) dynasm/dynasm.lua -LNE -o $@ $<
diff --git a/plugins/MirLua/Modules/ffi/src/PATENTS b/plugins/MirLua/Modules/ffi/src/PATENTS
new file mode 100644
index 0000000000..ec53abd7c9
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/PATENTS
@@ -0,0 +1,33 @@
+Additional Grant of Patent Rights Version 2
+
+"Software" means the luaffifb software distributed by Facebook, Inc.
+
+Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
+("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
+(subject to the termination provision below) license under any Necessary
+Claims, to make, have made, use, sell, offer to sell, import, and otherwise
+transfer the Software. For avoidance of doubt, no license is granted under
+Facebook’s rights in any patent claims that are infringed by (i) modifications
+to the Software made by you or any third party or (ii) the Software in
+combination with any software or other technology.
+
+The license granted hereunder will terminate, automatically and without notice,
+if you (or any of your subsidiaries, corporate affiliates or agents) initiate
+directly or indirectly, or take a direct financial interest in, any Patent
+Assertion: (i) against Facebook or any of its subsidiaries or corporate
+affiliates, (ii) against any party if such Patent Assertion arises in whole or
+in part from any software, technology, product or service of Facebook or any of
+its subsidiaries or corporate affiliates, or (iii) against any party relating
+to the Software. Notwithstanding the foregoing, if Facebook or any of its
+subsidiaries or corporate affiliates files a lawsuit alleging patent
+infringement against you in the first instance, and you respond by filing a
+patent infringement counterclaim in that lawsuit against that party that is
+unrelated to the Software, the license granted hereunder will not terminate
+under section (i) of this paragraph due to such counterclaim.
+
+A "Necessary Claim" is a claim of a patent owned by Facebook that is
+necessarily infringed by the Software standing alone.
+
+A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
+or contributory infringement or inducement to infringe any patent, including a
+cross-claim or counterclaim.
diff --git a/plugins/MirLua/Modules/ffi/src/README.md b/plugins/MirLua/Modules/ffi/src/README.md
new file mode 100644
index 0000000000..df6ffba165
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/README.md
@@ -0,0 +1,84 @@
+About
+-----
+This is a library for calling C function and manipulating C types from lua. It
+is designed to be interface compatible with the FFI library in LuaJIT (see
+http://luajit.org/ext_ffi.html). It can parse C function declarations and
+struct definitions that have been directly copied out of C header files and
+into lua source as a string.
+
+This is a fork of https://github.com/jmckaskill/luaffi
+
+Source
+------
+https://github.com/facebook/luaffifb
+
+Platforms
+---------
+Currently supported:
+- Linux x86/x64
+- OS X x86/x64
+
+Runs with both Lua 5.1 and Lua 5.2.
+
+Build
+-----
+In a terminal:
+
+```bash
+git clone https://github.com/facebook/luaffifb
+cd luaffifb
+luarocks make
+```
+
+Documentation
+-------------
+This library is designed to be source compatible with LuaJIT's FFI extension. The documentation at http://luajit.org/ext_ffi.html describes the API and semantics.
+
+Pointer Comparison
+------------
+Use `ffi.NULL` instead of `nil` when checking for `NULL` pointers.
+```lua
+ ffi.new('void *', 0) == ffi.NULL -- true
+```
+
+Known Issues
+------------
+- Comparing a ctype pointer to `nil` doesn't work the same as in LuaJIT (see above).
+ This is unfixable with the current metamethod semantics.
+- Constant expressions can't handle non integer intermediate values (eg
+ offsetof won't work because it manipulates pointers)
+- Not all metamethods work with Lua 5.1 (eg char* + number). This is due to
+ the way metamethods are looked up with mixed types in Lua 5.1. If you need
+this upgrade to Lua 5.2 or use boxed numbers (uint64_t and uintptr_t).
+- All bitfields are treated as unsigned (does anyone even use signed
+ bitfields?). Note that "int s:8" is unsigned on unix x86/x64, but signed on
+windows.
+
+
+How it works
+------------
+Types are represented by a struct ctype structure and an associated user value
+table. The table is shared between all related types for structs, unions, and
+functions. It's members have the types of struct members, function argument
+types, etc. The struct ctype structure then contains the modifications from
+the base type (eg number of pointers, array size, etc).
+
+Types are pushed into lua as a userdata containing the struct ctype with a
+user value (or fenv in 5.1) set to the shared type table.
+
+Boxed cdata types are pushed into lua as a userdata containing the struct
+cdata structure (which contains the struct ctype of the data as its header)
+followed by the boxed data.
+
+The functions in `ffi.C` provide the `cdata` and `ctype` metatables and ffi.*
+functions which manipulate these two types.
+
+C functions (and function pointers) are pushed into lua as a lua c function
+with the function pointer cdata as the first upvalue. The actual code is JITed
+using dynasm (see call_x86.dasc). The JITed code does the following in order:
+
+1. Calls the needed unpack functions in `ffi.C` placing each argument on the HW stack
+2. Updates `errno`
+3. Performs the C call
+4. Retrieves `errno`
+5. Pushes the result back into lua from the HW register or stack
diff --git a/plugins/MirLua/Modules/luaffi/src/call.c b/plugins/MirLua/Modules/ffi/src/call.c
index aff5b8ce38..d483d4cc69 100644
--- a/plugins/MirLua/Modules/luaffi/src/call.c
+++ b/plugins/MirLua/Modules/ffi/src/call.c
@@ -1,5 +1,10 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
#include "ffi.h"
@@ -9,17 +14,14 @@ static void* reserve_code(struct jit* jit, lua_State* L, size_t sz);
static void commit_code(struct jit* jit, void* p, size_t sz);
static void push_int(lua_State* L, int val)
-{ lua_pushnumber(L, val); }
+{ lua_pushinteger(L, val); }
static void push_uint(lua_State* L, unsigned int val)
-{ lua_pushnumber(L, val); }
+{ lua_pushinteger(L, val); }
static void push_float(lua_State* L, float val)
{ lua_pushnumber(L, val); }
-static void _remove(lua_State* L, int idx)
-{ lua_remove(L, idx); }
-
#ifndef _WIN32
static int GetLastError(void)
{ return errno; }
@@ -179,7 +181,7 @@ static void* reserve_code(struct jit* jit, lua_State* L, size_t sz)
ADDFUNC(jit->lua_dll, lua_pushnil);
ADDFUNC(jit->lua_dll, lua_callk);
ADDFUNC(jit->lua_dll, lua_settop);
- ADDFUNC(jit->lua_dll, _remove);
+ ADDFUNC(jit->lua_dll, lua_remove);
#undef ADDFUNC
for (i = 0; extnames[i] != NULL; i++) {
diff --git a/plugins/MirLua/Modules/luaffi/src/call_arm.dasc b/plugins/MirLua/Modules/ffi/src/call_arm.dasc
index 1f2de1c029..9551c18f7e 100644
--- a/plugins/MirLua/Modules/luaffi/src/call_arm.dasc
+++ b/plugins/MirLua/Modules/ffi/src/call_arm.dasc
@@ -1,5 +1,10 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
|.arch arm
|.actionlist build_actionlist
@@ -11,7 +16,7 @@
#define MAX_BRANCH ((INT32_MAX) >> 8)
#define BRANCH_OFF 4
-static void compile_extern_jump(struct jit* jit, lua_State* L, function_t func, uint8_t* code)
+static void compile_extern_jump(struct jit* jit, lua_State* L, cfunction func, uint8_t* code)
{
/* The jump code is the function pointer followed by a stub to call the
* function pointer. The stub exists so we can jump to functions with an
@@ -20,7 +25,7 @@ static void compile_extern_jump(struct jit* jit, lua_State* L, function_t func,
* Note we have to manually set this up since there are commands buffered
* in the jit state.
*/
- *(function_t*) code = func;
+ *(cfunction*) code = func;
/* ldr pc, [pc - 12] */
*(uint32_t*) &code[4] = 0xE51FF00CU;
}
@@ -47,9 +52,9 @@ void compile_globals(struct jit* jit, lua_State* L)
(void) jit;
}
-function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, const struct ctype* ct)
+cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctype* ct)
{
- struct jit* Dst = jit;
+ struct jit* Dst = get_jit(L);;
int i, nargs, num_upvals, ref;
const struct ctype* mt;
@@ -94,7 +99,7 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -113,7 +118,6 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
} else {
switch (mt->type) {
case INT64_TYPE:
- case UINT64_TYPE:
lua_rawseti(L, -2, ++num_upvals); /* mt */
| lcall extern lua_pushnil
| load32 r2, mt
@@ -127,7 +131,7 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
| lcall extern lua_remove // remove the nil usr
break;
- case UINTPTR_TYPE:
+ case INTPTR_TYPE:
lua_rawseti(L, -2, ++num_upvals); /* mt */
| lcall extern lua_pushnil
| load32 r2, mt
@@ -149,33 +153,26 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
lua_pop(L, 1);
| ldr r1, [DATA], #4
| mov r1, r1, lsl #24
- | mov r1, r1, asr #24
+ if (mt->is_unsigned) {
+ | mov r1, r1, lsr #24
+ } else {
+ | mov r1, r1, asr #24
+ }
| lcall extern push_int
break;
- case UINT8_TYPE:
- lua_pop(L, 1);
- | ldr r1, [DATA], #4
- | and r1, r1, #0xFF
- | lcall extern push_uint
- break;
-
case INT16_TYPE:
lua_pop(L, 1);
| ldr r1, [DATA], #4
| mov r1, r1, lsl #16
- | mov r1, r1, asr #16
+ if (mt->is_unsigned) {
+ | mov r1, r1, lsr #16
+ } else {
+ | mov r1, r1, asr #16
+ }
| lcall extern push_int
break;
- case UINT16_TYPE:
- lua_pop(L, 1);
- | ldr r1, [DATA], #4
- | mov r1, r1, lsl #16
- | mov r1, r1, lsr #16
- | lcall extern push_uint
- break;
-
case ENUM_TYPE:
case INT32_TYPE:
lua_pop(L, 1);
@@ -183,12 +180,6 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
| lcall extern push_int
break;
- case UINT32_TYPE:
- lua_pop(L, 1);
- | ldr r1, [DATA], #4
- | lcall extern push_uint
- break;
-
case FLOAT_TYPE:
lua_pop(L, 1);
| ldr r1, [DATA], #4
@@ -211,11 +202,11 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
mt = (const struct ctype*) lua_touserdata(L, -1);
| mov r3, #0
- | mov r2, #((mt->pointers || mt->type != VOID_TYPE) ? 1 : 0)
+ | mov r2, #((mt->pointers || mt->is_reference || mt->type != VOID_TYPE) ? 1 : 0)
| mov r1, #nargs
| lcall extern lua_callk
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -262,39 +253,35 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
case INT16_TYPE:
case INT32_TYPE:
| mvn r1, #0 // -1
- | lcall extern to_int32
- goto single;
-
- case UINT8_TYPE:
- case UINT16_TYPE:
- case UINT32_TYPE:
- | mvn r1, #0 // -1
- | lcall extern to_uint32
+ if (mt->is_unsigned) {
+ | lcall extern check_uint32
+ } else {
+ | lcall extern check_int32
+ }
goto single;
case INT64_TYPE:
| mvn r1, #0 // -1
- | lcall extern to_int64
- goto dual;
-
- case UINT64_TYPE:
- | mvn r1, #0 // -1
- | lcall extern to_uint64
+ if (mt->is_unsigned) {
+ | lcall extern check_uint64
+ } else {
+ | lcall extern check_int64
+ }
goto dual;
- case UINTPTR_TYPE:
+ case INTPTR_TYPE:
| mvn r1, #0 // -1
- | lcall extern to_uintptr
+ | lcall extern check_intptr
goto single;
case FLOAT_TYPE:
| mvn r1, #0 // -1
- | lcall extern to_float
+ | lcall extern check_float
goto single;
case DOUBLE_TYPE:
| mvn r1, #0 // -1
- | lcall extern to_double
+ | lcall extern check_double
goto dual;
single:
@@ -328,14 +315,14 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
{
void* p;
struct ctype ft;
- function_t func;
+ cfunction func;
- func = compile(jit, L, NULL, ref);
+ func = compile(Dst, L, NULL, ref);
ft = *ct;
ft.is_jitted = 1;
p = push_cdata(L, ct_usr, &ft);
- *(function_t*) p = func;
+ *(cfunction*) p = func;
assert(lua_gettop(L) == top + 1);
@@ -343,9 +330,9 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
}
}
-void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, const struct ctype* ct)
+void compile_function(lua_State* L, cfunction func, int ct_usr, const struct ctype* ct)
{
- struct jit* Dst = jit;
+ struct jit* Dst = get_jit(L);;
int i, nargs, num_upvals;
const struct ctype* mt;
void* p;
@@ -356,7 +343,7 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
nargs = (int) lua_rawlen(L, ct_usr);
p = push_cdata(L, ct_usr, ct);
- *(function_t*) p = func;
+ *(cfunction*) p = func;
num_upvals = 1;
dasm_setup(Dst, build_actionlist);
@@ -393,7 +380,7 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers || mt->type == FUNCTION_PTR_TYPE || mt->type == ENUM_TYPE) {
+ if (mt->pointers || mt->is_reference || mt->type == FUNCTION_PTR_TYPE || mt->type == ENUM_TYPE) {
lua_getuservalue(L, -1);
num_upvals += 2;
@@ -405,7 +392,7 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
| mov r1, #i
| mov r0, L_ARG
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
| bl extern to_typed_pointer
} else if (mt->type == FUNCTION_PTR_TYPE) {
| bl extern to_typed_function
@@ -421,67 +408,60 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
switch (mt->type) {
case INT8_TYPE:
- | lcall extern to_int32
- | mov r0, r0, lsl #24
- | mov r0, r0, asr #24
+ | lcall extern check_int32
+ if (mt->is_unsigned) {
+ | and r0, r0, #0xFF
+ } else {
+ | mov r0, r0, lsl #24
+ | mov r0, r0, asr #24
+ }
| str r0, [DATA], #4
break;
case INT16_TYPE:
- | lcall extern to_int32
- | mov r0, r0, lsl #16
- | mov r0, r0, asr #16
+ | lcall extern check_int32
+ if (mt->is_unsigned) {
+ | mov r0, r0, lsl #16
+ | mov r0, r0, lsr #16
+ } else {
+ | mov r0, r0, lsl #16
+ | mov r0, r0, asr #16
+ }
| str r0, [DATA], #4
break;
case INT32_TYPE:
- | lcall extern to_int32
- | str r0, [DATA], #4
- break;
-
- case UINT8_TYPE:
- | lcall extern to_uint32
- | and r0, r0, #0xFF
- | str r0, [DATA], #4
- break;
-
- case UINT16_TYPE:
- | lcall extern to_uint32
- | mov r0, r0, lsl #16
- | mov r0, r0, lsr #16
- | str r0, [DATA], #4
- break;
-
- case UINT32_TYPE:
- | lcall extern to_uint32
+ if (mt->is_unsigned) {
+ | lcall extern check_uint32
+ } else {
+ | lcall extern check_int32
+ }
| str r0, [DATA], #4
break;
case INT64_TYPE:
- | lcall extern to_int64
- | str r0, [DATA], #4
- | str r1, [DATA], #4
- break;
-
- case UINT64_TYPE:
- | lcall extern to_uint64
+ if (mt->is_unsigned) {
+ | lcall extern check_uint64
+ } else {
+ | lcall extern check_int64
+ }
| str r0, [DATA], #4
| str r1, [DATA], #4
break;
case DOUBLE_TYPE:
- | lcall extern to_double
+ | lcall extern check_double
| str r0, [DATA], #4
| str r1, [DATA], #4
break;
- case UINTPTR_TYPE:
- | lcall extern to_uintptr
+ case INTPTR_TYPE:
+ | lcall extern check_intptr
| str r0, [DATA], #4
break;
case FLOAT_TYPE:
- | lcall extern to_float
+ | lcall extern check_float
| str r0, [DATA], #4
break;
@@ -498,7 +478,7 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
| lcall extern unpack_varargs_stack
}
- | load32 r0, &jit->last_errno
+ | load32 r0, &Dst->last_errno
| ldr r0, [r0]
| bl extern SetLastError
@@ -507,7 +487,7 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
|.macro get_errno
| bl extern GetLastError
- | load32 r1, &jit->last_errno
+ | load32 r1, &Dst->last_errno
| str r0, [r1]
|.endmacro
@@ -518,7 +498,7 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
num_upvals += 2;
| mov DATA, r0
@@ -536,7 +516,6 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
} else {
switch (mt->type) {
case INT64_TYPE:
- case UINT64_TYPE:
num_upvals++;
| mov DATA, r0
| mov DATA2, r1
@@ -551,7 +530,7 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
| return
break;
- case UINTPTR_TYPE:
+ case INTPTR_TYPE:
num_upvals++;
| mov DATA, r0
| get_errno
@@ -589,19 +568,11 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
| mov DATA, r0
| get_errno
| mov r1, DATA
- | lcall extern push_int
- | mov r0, #1
- | return
- break;
-
- case UINT8_TYPE:
- case UINT16_TYPE:
- case UINT32_TYPE:
- lua_pop(L, 1);
- | mov DATA, r0
- | get_errno
- | mov r1, DATA
- | lcall extern push_uint
+ if (mt->is_unsigned) {
+ | lcall extern push_uint
+ } else {
+ | lcall extern push_int
+ }
| mov r0, #1
| return
break;
@@ -634,6 +605,6 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
}
assert(lua_gettop(L) == top + num_upvals);
- lua_pushcclosure(L, (lua_CFunction) compile(jit, L, func, LUA_NOREF), num_upvals);
+ lua_pushcclosure(L, (lua_CFunction) compile(Dst, L, func, LUA_NOREF), num_upvals);
}
diff --git a/plugins/MirLua/Modules/luaffi/src/call_arm.h b/plugins/MirLua/Modules/ffi/src/call_arm.h
index a0a1e7aec4..a84f69e762 100644
--- a/plugins/MirLua/Modules/luaffi/src/call_arm.h
+++ b/plugins/MirLua/Modules/ffi/src/call_arm.h
@@ -10,9 +10,14 @@
#endif
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
-static const unsigned int build_actionlist[571] = {
+static const unsigned int build_actionlist[546] = {
0xe1a0c00d,
0xe92d000f,
0xe92d50f0,
@@ -107,32 +112,22 @@ static const unsigned int build_actionlist[571] = {
0x00000000,
0xe4961004,
0xe1a01c01,
-0xe1a01c41,
-0xe1a00005,
-0xeb000000,
-0x00030005,
0x00000000,
-0xe4961004,
-0xe20110ff,
-0xe1a00005,
-0xeb000000,
-0x00030006,
+0xe1a01c21,
+0x00000000,
+0xe1a01c41,
0x00000000,
-0xe4961004,
-0xe1a01801,
-0xe1a01841,
0xe1a00005,
0xeb000000,
0x00030005,
0x00000000,
0xe4961004,
0xe1a01801,
+0x00000000,
0xe1a01821,
-0xe1a00005,
-0xeb000000,
-0x00030006,
0x00000000,
-0xe4961004,
+0xe1a01841,
+0x00000000,
0xe1a00005,
0xeb000000,
0x00030005,
@@ -140,17 +135,17 @@ static const unsigned int build_actionlist[571] = {
0xe4961004,
0xe1a00005,
0xeb000000,
-0x00030006,
+0x00030005,
0x00000000,
0xe4961004,
0xe1a00005,
0xeb000000,
-0x00030007,
+0x00030006,
0x00000000,
0xe8b60006,
0xe1a00005,
0xeb000000,
-0x00030008,
+0x00030007,
0x00000000,
0xe3a03000,
0xe3a02000,
@@ -159,7 +154,7 @@ static const unsigned int build_actionlist[571] = {
0x000b0000,
0xe1a00005,
0xeb000000,
-0x00030009,
+0x00030008,
0x00000000,
0xe3a02000,
0x000b0000,
@@ -176,12 +171,12 @@ static const unsigned int build_actionlist[571] = {
0xe3e01001,
0xe1a00005,
0xeb000000,
-0x0003000a,
+0x00030009,
0xe1a06000,
0xe3e01003,
0xe1a00005,
0xeb000000,
-0x0003000b,
+0x0003000a,
0xe1a00006,
0x00000000,
0xe3a02000,
@@ -199,30 +194,35 @@ static const unsigned int build_actionlist[571] = {
0xe3e01001,
0xe1a00005,
0xeb000000,
-0x0003000c,
+0x0003000b,
0xe1a06000,
0xe3e01003,
0xe1a00005,
0xeb000000,
-0x0003000b,
+0x0003000a,
0xe1a00006,
0x00000000,
0xe3e01001,
0xe1a00005,
0xeb000000,
-0x0003000b,
+0x0003000a,
0x00000000,
0xe3e01000,
+0x00000000,
+0xe1a00005,
+0xeb000000,
+0x0003000c,
+0x00000000,
0xe1a00005,
0xeb000000,
0x0003000d,
0x00000000,
0xe3e01000,
+0x00000000,
0xe1a00005,
0xeb000000,
0x0003000e,
0x00000000,
-0xe3e01000,
0xe1a00005,
0xeb000000,
0x0003000f,
@@ -242,16 +242,11 @@ static const unsigned int build_actionlist[571] = {
0xeb000000,
0x00030012,
0x00000000,
-0xe3e01000,
-0xe1a00005,
-0xeb000000,
-0x00030013,
-0x00000000,
0xe1a06000,
0xe3e01002,
0xe1a00005,
0xeb000000,
-0x0003000b,
+0x0003000a,
0xe1a00006,
0x00000000,
0xe1a06000,
@@ -259,7 +254,7 @@ static const unsigned int build_actionlist[571] = {
0xe3e01002,
0xe1a00005,
0xeb000000,
-0x0003000b,
+0x0003000a,
0xe1a00006,
0xe1a01007,
0x00000000,
@@ -272,7 +267,7 @@ static const unsigned int build_actionlist[571] = {
0xe1a05000,
0xe1a00005,
0xeb000000,
-0x00030014,
+0x00030013,
0xe1a04000,
0xe3540000,
0x000b0000,
@@ -286,7 +281,7 @@ static const unsigned int build_actionlist[571] = {
0x0006000f,
0xe1a00005,
0xeb000000,
-0x00030015,
+0x00030014,
0x0006000b,
0x00000000,
0x0a000000,
@@ -298,7 +293,7 @@ static const unsigned int build_actionlist[571] = {
0x0006000f,
0xe1a00005,
0xeb000000,
-0x00030015,
+0x00030014,
0x0006000b,
0x00000000,
0xe04dd184,
@@ -317,13 +312,13 @@ static const unsigned int build_actionlist[571] = {
0xe1a00005,
0x00000000,
0xeb000000,
-0x0003000a,
+0x00030009,
0x00000000,
0xeb000000,
-0x00030016,
+0x00030015,
0x00000000,
0xeb000000,
-0x0003000c,
+0x0003000b,
0x00000000,
0xe4860004,
0x00000000,
@@ -333,66 +328,61 @@ static const unsigned int build_actionlist[571] = {
0xe1a00005,
0xeb000000,
0x0003000d,
+0x00000000,
+0xe20000ff,
+0x00000000,
0xe1a00c00,
0xe1a00c40,
+0x00000000,
0xe4860004,
0x00000000,
0xe1a00005,
0xeb000000,
0x0003000d,
+0x00000000,
+0xe1a00800,
+0xe1a00820,
+0x00000000,
0xe1a00800,
0xe1a00840,
-0xe4860004,
0x00000000,
-0xe1a00005,
-0xeb000000,
-0x0003000d,
0xe4860004,
0x00000000,
0xe1a00005,
0xeb000000,
-0x0003000e,
-0xe20000ff,
-0xe4860004,
+0x0003000c,
0x00000000,
0xe1a00005,
0xeb000000,
-0x0003000e,
-0xe1a00800,
-0xe1a00820,
+0x0003000d,
+0x00000000,
0xe4860004,
0x00000000,
0xe1a00005,
0xeb000000,
0x0003000e,
-0xe4860004,
0x00000000,
0xe1a00005,
0xeb000000,
0x0003000f,
-0xe4860004,
-0xe4861004,
0x00000000,
-0xe1a00005,
-0xeb000000,
-0x00030010,
0xe4860004,
0xe4861004,
0x00000000,
0xe1a00005,
0xeb000000,
-0x00030013,
+0x00030012,
0xe4860004,
0xe4861004,
0x00000000,
0xe1a00005,
0xeb000000,
-0x00030011,
+0x00030010,
0xe4860004,
0x00000000,
0xe1a00005,
0xeb000000,
-0x00030012,
+0x00030011,
0xe4860004,
0x00000000,
0xe1a03006,
@@ -401,7 +391,7 @@ static const unsigned int build_actionlist[571] = {
0x000b0000,
0xe1a00005,
0xeb000000,
-0x00030017,
+0x00030016,
0x00000000,
0xe59f0000,
0xea000000,
@@ -410,15 +400,15 @@ static const unsigned int build_actionlist[571] = {
0x0006000f,
0xe5900000,
0xeb000000,
-0x00030018,
+0x00030017,
0x00000000,
0xe8bd000f,
0xeb000000,
-0x00030019,
+0x00030018,
0x00000000,
0xe1a06000,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -442,7 +432,7 @@ static const unsigned int build_actionlist[571] = {
0xe1a06000,
0xe1a07001,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -468,7 +458,7 @@ static const unsigned int build_actionlist[571] = {
0x00000000,
0xe1a06000,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -492,7 +482,7 @@ static const unsigned int build_actionlist[571] = {
0xe91ba870,
0x00000000,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -504,7 +494,7 @@ static const unsigned int build_actionlist[571] = {
0x00000000,
0xe1a06000,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -520,7 +510,7 @@ static const unsigned int build_actionlist[571] = {
0x00000000,
0xe1a06000,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -528,31 +518,21 @@ static const unsigned int build_actionlist[571] = {
0x0006000f,
0xe5810000,
0xe1a01006,
-0xe1a00005,
-0xeb000000,
-0x00030005,
-0xe3a00001,
-0xe91ba870,
0x00000000,
-0xe1a06000,
+0xe1a00005,
0xeb000000,
0x0003001a,
-0xe59f1000,
-0xea000000,
-0x00050005,
-0x00090000,
-0x0006000f,
-0xe5810000,
-0xe1a01006,
+0x00000000,
0xe1a00005,
0xeb000000,
-0x00030006,
+0x00030005,
+0x00000000,
0xe3a00001,
0xe91ba870,
0x00000000,
0xe1a06000,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -562,14 +542,14 @@ static const unsigned int build_actionlist[571] = {
0xe1a01006,
0xe1a00005,
0xeb000000,
-0x00030007,
+0x00030006,
0xe3a00001,
0xe91ba870,
0x00000000,
0xe1a06000,
0xe1a07001,
0xeb000000,
-0x0003001a,
+0x00030019,
0xe59f1000,
0xea000000,
0x00050005,
@@ -580,7 +560,7 @@ static const unsigned int build_actionlist[571] = {
0xe1a01006,
0xe1a00005,
0xeb000000,
-0x00030008,
+0x00030007,
0xe3a00001,
0xe91ba870,
0x00000000
@@ -596,20 +576,19 @@ static const char *const extnames[] = {
"lua_pushnil",
"lua_pushboolean",
"push_int",
- "push_uint",
"push_float",
"lua_pushnumber",
"lua_callk",
"to_typed_pointer",
"lua_settop",
"to_enum",
- "to_int32",
- "to_uint32",
- "to_int64",
- "to_uint64",
- "to_uintptr",
- "to_float",
- "to_double",
+ "check_uint32",
+ "check_int32",
+ "check_uint64",
+ "check_int64",
+ "check_intptr",
+ "check_float",
+ "check_double",
"lua_gettop",
"luaL_error",
"to_typed_function",
@@ -617,6 +596,7 @@ static const char *const extnames[] = {
"SetLastError",
"FUNCTION",
"GetLastError",
+ "push_uint",
(const char *)0
};
@@ -625,7 +605,7 @@ static const char *const extnames[] = {
#define MAX_BRANCH ((INT32_MAX) >> 8)
#define BRANCH_OFF 4
-static void compile_extern_jump(struct jit* jit, lua_State* L, function_t func, uint8_t* code)
+static void compile_extern_jump(struct jit* jit, lua_State* L, cfunction func, uint8_t* code)
{
/* The jump code is the function pointer followed by a stub to call the
* function pointer. The stub exists so we can jump to functions with an
@@ -634,7 +614,7 @@ static void compile_extern_jump(struct jit* jit, lua_State* L, function_t func,
* Note we have to manually set this up since there are commands buffered
* in the jit state.
*/
- *(function_t*) code = func;
+ *(cfunction*) code = func;
/* ldr pc, [pc - 12] */
*(uint32_t*) &code[4] = 0xE51FF00CU;
}
@@ -647,9 +627,9 @@ void compile_globals(struct jit* jit, lua_State* L)
(void) jit;
}
-function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, const struct ctype* ct)
+cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctype* ct)
{
- struct jit* Dst = jit;
+ struct jit* Dst = get_jit(L);;
int i, nargs, num_upvals, ref;
const struct ctype* mt;
@@ -682,7 +662,7 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -692,12 +672,11 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
} else {
switch (mt->type) {
case INT64_TYPE:
- case UINT64_TYPE:
lua_rawseti(L, -2, ++num_upvals); /* mt */
dasm_put(Dst, 47, (uintptr_t)(mt));
break;
- case UINTPTR_TYPE:
+ case INTPTR_TYPE:
lua_rawseti(L, -2, ++num_upvals); /* mt */
dasm_put(Dst, 68, (uintptr_t)(mt));
break;
@@ -710,42 +689,39 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
case INT8_TYPE:
lua_pop(L, 1);
dasm_put(Dst, 92);
- break;
-
- case UINT8_TYPE:
- lua_pop(L, 1);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 95);
+ } else {
+ dasm_put(Dst, 97);
+ }
dasm_put(Dst, 99);
break;
case INT16_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 105);
- break;
-
- case UINT16_TYPE:
- lua_pop(L, 1);
- dasm_put(Dst, 112);
+ dasm_put(Dst, 103);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 106);
+ } else {
+ dasm_put(Dst, 108);
+ }
+ dasm_put(Dst, 110);
break;
case ENUM_TYPE:
case INT32_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 119);
- break;
-
- case UINT32_TYPE:
- lua_pop(L, 1);
- dasm_put(Dst, 124);
+ dasm_put(Dst, 114);
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 129);
+ dasm_put(Dst, 119);
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 134);
+ dasm_put(Dst, 124);
break;
default:
@@ -757,14 +733,14 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- dasm_put(Dst, 139, ((mt->pointers || mt->type != VOID_TYPE) ? 1 : 0), nargs);
+ dasm_put(Dst, 129, ((mt->pointers || mt->is_reference || mt->type != VOID_TYPE) ? 1 : 0), nargs);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
- dasm_put(Dst, 148, num_upvals-1, (uintptr_t)(mt));
+ dasm_put(Dst, 138, num_upvals-1, (uintptr_t)(mt));
} else {
switch (mt->type) {
case ENUM_TYPE:
@@ -772,11 +748,11 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
- dasm_put(Dst, 171, num_upvals-1, (uintptr_t)(mt));
+ dasm_put(Dst, 161, num_upvals-1, (uintptr_t)(mt));
break;
case VOID_TYPE:
- dasm_put(Dst, 194);
+ dasm_put(Dst, 184);
lua_pop(L, 1);
break;
@@ -784,42 +760,42 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
case INT8_TYPE:
case INT16_TYPE:
case INT32_TYPE:
- dasm_put(Dst, 199);
- goto single;
-
- case UINT8_TYPE:
- case UINT16_TYPE:
- case UINT32_TYPE:
- dasm_put(Dst, 204);
+ dasm_put(Dst, 189);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 191);
+ } else {
+ dasm_put(Dst, 195);
+ }
goto single;
case INT64_TYPE:
- dasm_put(Dst, 209);
- goto dual;
-
- case UINT64_TYPE:
- dasm_put(Dst, 214);
+ dasm_put(Dst, 199);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 201);
+ } else {
+ dasm_put(Dst, 205);
+ }
goto dual;
- case UINTPTR_TYPE:
- dasm_put(Dst, 219);
+ case INTPTR_TYPE:
+ dasm_put(Dst, 209);
goto single;
case FLOAT_TYPE:
- dasm_put(Dst, 224);
+ dasm_put(Dst, 214);
goto single;
case DOUBLE_TYPE:
- dasm_put(Dst, 229);
+ dasm_put(Dst, 219);
goto dual;
single:
- dasm_put(Dst, 234);
+ dasm_put(Dst, 224);
lua_pop(L, 1);
break;
dual:
- dasm_put(Dst, 241);
+ dasm_put(Dst, 231);
lua_pop(L, 1);
break;
@@ -828,7 +804,7 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
}
}
- dasm_put(Dst, 250);
+ dasm_put(Dst, 240);
lua_pop(L, 1); /* upval table - already in registry */
assert(lua_gettop(L) == top);
@@ -836,14 +812,14 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
{
void* p;
struct ctype ft;
- function_t func;
+ cfunction func;
- func = compile(jit, L, NULL, ref);
+ func = compile(Dst, L, NULL, ref);
ft = *ct;
ft.is_jitted = 1;
p = push_cdata(L, ct_usr, &ft);
- *(function_t*) p = func;
+ *(cfunction*) p = func;
assert(lua_gettop(L) == top + 1);
@@ -851,9 +827,9 @@ function_t push_callback(struct jit* jit, lua_State* L, int fidx, int ct_usr, co
}
}
-void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, const struct ctype* ct)
+void compile_function(lua_State* L, cfunction func, int ct_usr, const struct ctype* ct)
{
- struct jit* Dst = jit;
+ struct jit* Dst = get_jit(L);;
int i, nargs, num_upvals;
const struct ctype* mt;
void* p;
@@ -864,90 +840,96 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
nargs = (int) lua_rawlen(L, ct_usr);
p = push_cdata(L, ct_usr, ct);
- *(function_t*) p = func;
+ *(cfunction*) p = func;
num_upvals = 1;
dasm_setup(Dst, build_actionlist);
- dasm_put(Dst, 252, nargs);
+ dasm_put(Dst, 242, nargs);
if (ct->has_var_arg) {
- dasm_put(Dst, 264, (uintptr_t)("too few arguments"));
+ dasm_put(Dst, 254, (uintptr_t)("too few arguments"));
} else {
- dasm_put(Dst, 276, (uintptr_t)("incorrect number of arguments"));
+ dasm_put(Dst, 266, (uintptr_t)("incorrect number of arguments"));
}
/* reserve enough stack space for all of the arguments (8 bytes per
* argument for double and maintains alignment). Add an extra 16 bytes so
* that the pop {r0, r1, r2, r3} doesn't clean out our stack frame */
- dasm_put(Dst, 288);
+ dasm_put(Dst, 278);
for (i = 1; i <= nargs; i++) {
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers || mt->type == FUNCTION_PTR_TYPE || mt->type == ENUM_TYPE) {
+ if (mt->pointers || mt->is_reference || mt->type == FUNCTION_PTR_TYPE || mt->type == ENUM_TYPE) {
lua_getuservalue(L, -1);
num_upvals += 2;
- dasm_put(Dst, 292, (uintptr_t)(mt), (uintptr_t)(lua_upvalueindex(num_upvals)), i);
+ dasm_put(Dst, 282, (uintptr_t)(mt), (uintptr_t)(lua_upvalueindex(num_upvals)), i);
- if (mt->pointers) {
- dasm_put(Dst, 303);
+ if (mt->pointers || mt->is_reference) {
+ dasm_put(Dst, 293);
} else if (mt->type == FUNCTION_PTR_TYPE) {
- dasm_put(Dst, 306);
+ dasm_put(Dst, 296);
} else if (mt->type == ENUM_TYPE) {
- dasm_put(Dst, 309);
+ dasm_put(Dst, 299);
}
- dasm_put(Dst, 312);
+ dasm_put(Dst, 302);
} else {
lua_pop(L, 1);
- dasm_put(Dst, 314, i);
+ dasm_put(Dst, 304, i);
switch (mt->type) {
case INT8_TYPE:
- dasm_put(Dst, 317);
+ dasm_put(Dst, 307);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 311);
+ } else {
+ dasm_put(Dst, 313);
+ }
+ dasm_put(Dst, 316);
break;
case INT16_TYPE:
- dasm_put(Dst, 324);
+ dasm_put(Dst, 318);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 322);
+ } else {
+ dasm_put(Dst, 325);
+ }
+ dasm_put(Dst, 328);
break;
case INT32_TYPE:
- dasm_put(Dst, 331);
- break;
-
- case UINT8_TYPE:
- dasm_put(Dst, 336);
- break;
-
- case UINT16_TYPE:
- dasm_put(Dst, 342);
- break;
-
- case UINT32_TYPE:
- dasm_put(Dst, 349);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 330);
+ } else {
+ dasm_put(Dst, 334);
+ }
+ dasm_put(Dst, 338);
break;
case INT64_TYPE:
- dasm_put(Dst, 354);
- break;
-
- case UINT64_TYPE:
- dasm_put(Dst, 360);
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 340);
+ } else {
+ dasm_put(Dst, 344);
+ }
+ dasm_put(Dst, 348);
break;
case DOUBLE_TYPE:
- dasm_put(Dst, 366);
+ dasm_put(Dst, 351);
break;
- case UINTPTR_TYPE:
- dasm_put(Dst, 372);
+ case INTPTR_TYPE:
+ dasm_put(Dst, 357);
break;
case FLOAT_TYPE:
- dasm_put(Dst, 377);
+ dasm_put(Dst, 362);
break;
default:
@@ -957,44 +939,43 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
}
if (ct->has_var_arg) {
- dasm_put(Dst, 382, nargs+1);
+ dasm_put(Dst, 367, nargs+1);
}
- dasm_put(Dst, 390, (uintptr_t)(&jit->last_errno));
+ dasm_put(Dst, 375, (uintptr_t)(&Dst->last_errno));
- dasm_put(Dst, 399);
+ dasm_put(Dst, 384);
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
num_upvals += 2;
- dasm_put(Dst, 403, (uintptr_t)(&jit->last_errno), (uintptr_t)(mt), (uintptr_t)(lua_upvalueindex(num_upvals)));
+ dasm_put(Dst, 388, (uintptr_t)(&Dst->last_errno), (uintptr_t)(mt), (uintptr_t)(lua_upvalueindex(num_upvals)));
} else {
switch (mt->type) {
case INT64_TYPE:
- case UINT64_TYPE:
num_upvals++;
- dasm_put(Dst, 426, (uintptr_t)(&jit->last_errno), (uintptr_t)(mt));
+ dasm_put(Dst, 411, (uintptr_t)(&Dst->last_errno), (uintptr_t)(mt));
break;
- case UINTPTR_TYPE:
+ case INTPTR_TYPE:
num_upvals++;
- dasm_put(Dst, 453, (uintptr_t)(&jit->last_errno), (uintptr_t)(mt));
+ dasm_put(Dst, 438, (uintptr_t)(&Dst->last_errno), (uintptr_t)(mt));
break;
case VOID_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 478, (uintptr_t)(&jit->last_errno));
+ dasm_put(Dst, 463, (uintptr_t)(&Dst->last_errno));
break;
case BOOL_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 489, (uintptr_t)(&jit->last_errno));
+ dasm_put(Dst, 474, (uintptr_t)(&Dst->last_errno));
break;
case INT8_TYPE:
@@ -1002,24 +983,23 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
case INT32_TYPE:
case ENUM_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 505, (uintptr_t)(&jit->last_errno));
- break;
-
- case UINT8_TYPE:
- case UINT16_TYPE:
- case UINT32_TYPE:
- lua_pop(L, 1);
- dasm_put(Dst, 521, (uintptr_t)(&jit->last_errno));
+ dasm_put(Dst, 490, (uintptr_t)(&Dst->last_errno));
+ if (mt->is_unsigned) {
+ dasm_put(Dst, 501);
+ } else {
+ dasm_put(Dst, 505);
+ }
+ dasm_put(Dst, 509);
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 537, (uintptr_t)(&jit->last_errno));
+ dasm_put(Dst, 512, (uintptr_t)(&Dst->last_errno));
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 553, (uintptr_t)(&jit->last_errno));
+ dasm_put(Dst, 528, (uintptr_t)(&Dst->last_errno));
break;
default:
@@ -1028,6 +1008,6 @@ void push_function(struct jit* jit, lua_State* L, function_t func, int ct_usr, c
}
assert(lua_gettop(L) == top + num_upvals);
- lua_pushcclosure(L, (lua_CFunction) compile(jit, L, func, LUA_NOREF), num_upvals);
+ lua_pushcclosure(L, (lua_CFunction) compile(Dst, L, func, LUA_NOREF), num_upvals);
}
diff --git a/plugins/MirLua/Modules/luaffi/src/call_x64.h b/plugins/MirLua/Modules/ffi/src/call_x64.h
index 3fa8ab7f91..095118ec43 100644
--- a/plugins/MirLua/Modules/luaffi/src/call_x64.h
+++ b/plugins/MirLua/Modules/ffi/src/call_x64.h
@@ -10,115 +10,113 @@
#endif
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
-static const unsigned char build_actionlist[2022] = {
- 248,10,184,1,0.0,0.0,0.0,76,139,109,252,240,76,139,101,252,248,72,137,252,
- 236,93,195,255,248,11,232,251,1,0,72,185,237,237,137,1,184,0,0.0,0.0,0.0,
- 76,139,109,252,240,76,139,101,252,248,72,137,252,236,93,195,255,248,12,102.0,
- 15.0,214,68,36,32,232,251,1,0,72,185,237,237,137,1,252,243.0,15.0,126,68,
- 36,32,76,137,231,232,251,1,1,252,233,244,10,255,248,13,15.0,182,192,137,68,
- 36,32,232,251,1,0,72,185,237,237,137,1,139,68,36,32,72,137,198,76,137,231,
- 232,251,1,2,252,233,244,10,255,248,14,137,68,36,32,232,251,1,0,72,185,237,
- 237,137,1,139,68,36,32,72,137,198,76,137,231,232,251,1,3,252,233,244,10,255,
- 248,15,137,68,36,32,232,251,1,0,72,185,237,237,137,1,139,68,36,32,72,137,
- 198,76,137,231,232,251,1,4,252,233,244,10,255,248,16,102,184,0,0.0,72,190,
- 237,237,76,137,231,232,251,1,5,255,248,17,102,184,0,0.0,72,190,237,237,76,
- 137,231,232,251,1,5,255,248,18,102.0,15.0,214,69,252,240,102.0,15.0,214,77,
- 232,102.0,15.0,214,85,224,102.0,15.0,214,93,216,102.0,15.0,214,101,208,102.0,
- 15.0,214,109,200,102.0,15.0,214,117,192,102.0,15.0,214,125,184,72,137,125,
- 176,72,137,117,168,72,137,85,160,72,137,77,152,76,137,69,144,76,137,77,136,
- 195,255,72,139,141,233,255,72,137,132,253,36,233,255,221.0,133,233,255,217.0,
- 133,233,255,252,243.0,15.0,126,133,233,255,252,243.0,15.0,90,133,233,255,
- 221.0,156,253,36,233,255,217.0,156,253,36,233,255,102.0,15.0,214,132,253,
- 36,233,255,252,242.0,15.0,90,192,102.0,15.0,214,132,253,36,233,255,252,242.0,
- 15.0,90,192,102.0,15.0,126,132,253,36,233,255,85,72,137,229,65,84,72,129.0,
- 252,236,239,232,244,18,255,73,188,237,237,255,72,199.0,194,237,72,199.0,198,
- 237,76,137,231,232,251,1,6,255,72,199.0,194,237,72,199.0,198,252,255,252,
- 255.0,252,255.0,252,255.0,76,137,231,232,251,1,6,255,72,199.0,194,237,72,
- 199.0,198,237,76,137,231,232,251,1,6,72,186,237,237,72,199.0,198,252,255,
- 252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,7,255,72,137,8,72,199.0,
- 198,252,254,252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,8,255,72,186,
- 237,237,72,199.0,198,0,0.0,0.0,0.0,76,137,231,232,251,1,7,255,72,137,8,255,
- 102.0,15.0,214,0,255,217.0,24,255,217.0,88,4,255,102.0,15.0,214,64,8,255,
- 76,137,231,232,251,1,1,255,15.0,182,201,72,137,206,76,137,231,232,251,1,2,
- 255,15.0,182,201,255,15.0,190,201,255,72,137,206,76,137,231,232,251,1,3,255,
- 15.0,183,201,255,15.0,191,201,255,72,137,206,76,137,231,232,251,1,4,255,72,
- 185,237,237,72,199.0,194,237,72,199.0,198,237,76,137,231,232,251,1,9,255,
- 72,199.0,194,237,72,199.0,198,252,254,252,255.0,252,255.0,252,255.0,76,137,
- 231,232,251,1,6,72,185,237,237,72,199.0,194,252,255,252,255.0,252,255.0,252,
- 255.0,72,199.0,198,252,254,252,255.0,252,255.0,252,255.0,76,137,231,232,251,
- 1,10,72,137,68,36,32,72,199.0,198,252,252,252,255.0,252,255.0,252,255.0,76,
- 137,231,232,251,1,11,72,139,68,36,32,255,72,199.0,194,237,72,199.0,198,252,
- 254,252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,6,72,185,237,237,72,
- 199.0,194,252,255,252,255.0,252,255.0,252,255.0,72,199.0,198,252,254,252,
- 255.0,252,255.0,252,255.0,76,137,231,232,251,1,12,137,68,36,32,72,199.0,198,
- 252,252,252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,11,139,68,36,32,
- 255,72,199.0,198,252,254,252,255.0,252,255.0,252,255.0,76,137,231,232,251,
- 1,11,255,72,199.0,198,252,255,252,255.0,252,255.0,252,255.0,76,137,231,232,
- 251,1,13,255,72,199.0,198,252,255,252,255.0,252,255.0,252,255.0,76,137,231,
- 232,251,1,14,255,137,68,36,32,72,199.0,198,252,253,252,255.0,252,255.0,252,
- 255.0,76,137,231,232,251,1,11,139,68,36,32,255,72,199.0,198,252,255,252,255.0,
- 252,255.0,252,255.0,76,137,231,232,251,1,15,255,72,199.0,198,252,255,252,
- 255.0,252,255.0,252,255.0,76,137,231,232,251,1,16,255,72,137,68,36,32,72,
- 199.0,198,252,253,252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,11,72,
- 139,68,36,32,255,72,199.0,198,252,255,252,255.0,252,255.0,252,255.0,76,137,
- 231,232,251,1,17,72,137,68,36,32,72,199.0,198,252,253,252,255.0,252,255.0,
- 252,255.0,76,137,231,232,251,1,11,72,139,68,36,32,255,72,199.0,198,252,255,
- 252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,18,102.0,15.0,214,68,36,
- 32,72,199.0,198,252,253,252,255.0,252,255.0,252,255.0,76,137,231,232,251,
- 1,11,255,252,242.0,15.0,90,68,36,32,255,252,243.0,15.0,126,68,36,32,255,72,
- 199.0,198,252,255,252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,19,102.0,
- 15.0,214,68,36,32,72,199.0,198,252,253,252,255.0,252,255.0,252,255.0,76,137,
- 231,232,251,1,11,252,243.0,15.0,126,68,36,32,255,72,199.0,198,252,255,252,
- 255.0,252,255.0,252,255.0,76,137,231,232,251,1,20,102.0,15.0,214,68,36,32,
- 102.0,15.0,214,76,36,40,72,199.0,198,252,253,252,255.0,252,255.0,252,255.0,
- 76,137,231,232,251,1,11,252,243.0,15.0,126,68,36,32,252,243.0,15.0,126,76,
- 36,40,255,72,139,141,233,72,199.0,194,252,255,252,255.0,252,255.0,252,255.0,
- 76,137,230,72,137,207,232,251,1,20,72,131.0,252,236,4,72,199.0,198,252,253,
- 252,255.0,252,255.0,252,255.0,76,137,231,232,251,1,11,255,76,139,101,252,
- 248,72,137,252,236,93,194,236,255,85,72,137,229,65,84,65,85,73,137,252,252,
- 76,137,231,232,251,1,21,73,137,197,72,129.0,252,248,239,15.0,140,244,16,255,
- 15.0,143,244,17,255,72,193.0,224,4,72,41,196,72,129.0,252,236,239,255,72,
- 186,237,237,72,199.0,198,0,0.0,0.0,0.0,76,137,231,232,251,1,7,72,131.0,252,
- 236,16,255,72,185,237,237,72,199.0,194,237,72,199.0,198,237,76,137,231,232,
- 251,1,10,255,72,185,237,237,72,199.0,194,237,72,199.0,198,237,76,137,231,
- 232,251,1,22,255,72,185,237,237,72,199.0,194,237,72,199.0,198,237,76,137,
- 231,232,251,1,12,255,72,199.0,198,237,76,137,231,232,251,1,14,255,15.0,182,
- 192,255,15.0,190,192,255,15.0,183,192,255,15.0,191,192,255,72,199.0,198,237,
- 76,137,231,232,251,1,14,131.0,252,248,0,15.0,149.0,208,15.0,182,192,255,72,
- 199.0,198,237,76,137,231,232,251,1,13,255,72,199.0,198,237,76,137,231,232,
- 251,1,17,255,72,199.0,198,237,76,137,231,232,251,1,15,255,72,199.0,198,237,
- 76,137,231,232,251,1,16,255,72,199.0,198,237,76,137,231,232,251,1,18,255,
- 72,199.0,198,237,76,137,231,232,251,1,20,255,252,243.0,15.0,126,193,255,72,
- 141,132,253,36,233,72,131.0,252,236,4,72,199.0,194,237,76,137,230,72,137,
- 199,232,251,1,20,255,72,199.0,198,237,76,137,231,232,251,1,19,255,72,199.0,
- 198,237,76,137,231,232,251,1,19,137,4,36,217.0,4,36,255,137,20,36,217.0,4,
- 36,255,72,137,224,72,129.0,192,239,73,137,192,72,199.0,193,237,76,137,252,
- 234,72,199.0,198,237,76,137,231,232,251,1,23,255,72,137,224,72,129.0,192,
- 239,73,137,192,72,199.0,193,237,76,137,252,234,72,199.0,198,237,76,137,231,
- 232,251,1,24,255,72,137,224,72,129.0,192,239,73,137,193,73,199.0,192,237,
- 72,199.0,193,237,76,137,252,234,72,199.0,198,237,76,137,231,232,251,1,25,
- 255,72,185,237,237,139,1,72,137,199,232,251,1,26,255,72,131.0,196,32,255,
- 252,243.0,15.0,126,188,253,36,233,255,252,243.0,15.0,126,180,253,36,233,255,
- 252,243.0,15.0,126,172,253,36,233,255,252,243.0,15.0,126,164,253,36,233,255,
- 252,243.0,15.0,126,156,253,36,233,255,252,243.0,15.0,126,148,253,36,233,255,
- 252,243.0,15.0,126,140,253,36,233,255,252,243.0,15.0,126,132,253,36,233,255,
- 76,139,140,253,36,233,255,76,139,132,253,36,233,255,72,139,140,253,36,233,
- 255,72,139,148,253,36,233,255,72,139,180,253,36,233,255,72,139,60,36,255,
- 72,129.0,196,239,255,176,8,255,232,251,1,27,72,131.0,252,236,48,255,72,137,
- 68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,199.0,198,237,
- 76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,72,137,
- 68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,199.0,198,0,0.0,
- 0.0,0.0,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,
- 102.0,15.0,214,68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,
- 199.0,198,0,0.0,0.0,0.0,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,
- 233,244,10,255,102.0,15.0,214,76,36,40,102.0,15.0,214,68,36,32,232,251,1,
- 0,72,185,237,237,137,1,72,186,237,237,72,199.0,198,0,0.0,0.0,0.0,76,137,231,
- 232,251,1,7,72,139,76,36,40,72,137,72,8,72,139,76,36,32,72,137,8,252,233,
- 244,10,255,252,233,244,11,255,252,233,244,13,255,252,233,244,14,255,252,233,
- 244,15,255,252,243.0,15.0,90,192,252,233,244,12,255
+static const unsigned char build_actionlist[2016] = {
+ 248,10,184,1,0,0,0,76,139,109,252,240,76,139,101,252,248,72,137,252,236,93,
+ 195,255,248,11,232,251,1,0,72,185,237,237,137,1,184,0,0,0,0,76,139,109,252,
+ 240,76,139,101,252,248,72,137,252,236,93,195,255,248,12,102,15,214,68,36,
+ 32,232,251,1,0,72,185,237,237,137,1,252,243,15,126,68,36,32,76,137,231,232,
+ 251,1,1,252,233,244,10,255,248,13,15,182,192,137,68,36,32,232,251,1,0,72,
+ 185,237,237,137,1,139,68,36,32,72,137,198,76,137,231,232,251,1,2,252,233,
+ 244,10,255,248,14,137,68,36,32,232,251,1,0,72,185,237,237,137,1,139,68,36,
+ 32,72,137,198,76,137,231,232,251,1,3,252,233,244,10,255,248,15,137,68,36,
+ 32,232,251,1,0,72,185,237,237,137,1,139,68,36,32,72,137,198,76,137,231,232,
+ 251,1,4,252,233,244,10,255,248,16,102,184,0,0,72,190,237,237,76,137,231,232,
+ 251,1,5,255,248,17,102,184,0,0,72,190,237,237,76,137,231,232,251,1,5,255,
+ 248,18,102,15,214,69,252,240,102,15,214,77,232,102,15,214,85,224,102,15,214,
+ 93,216,102,15,214,101,208,102,15,214,109,200,102,15,214,117,192,102,15,214,
+ 125,184,72,137,125,176,72,137,117,168,72,137,85,160,72,137,77,152,76,137,
+ 69,144,76,137,77,136,195,255,72,139,141,233,255,72,137,132,253,36,233,255,
+ 221,133,233,255,217,133,233,255,252,243,15,126,133,233,255,252,243,15,90,
+ 133,233,255,221,156,253,36,233,255,217,156,253,36,233,255,102,15,214,132,
+ 253,36,233,255,252,242,15,90,192,102,15,214,132,253,36,233,255,252,242,15,
+ 90,192,102,15,126,132,253,36,233,255,85,72,137,229,65,84,72,129,252,236,239,
+ 232,244,18,255,73,188,237,237,255,72,199,194,237,72,199,198,237,76,137,231,
+ 232,251,1,6,255,72,199,194,237,72,199,198,252,255,252,255,252,255,252,255,
+ 76,137,231,232,251,1,6,255,72,199,194,237,72,199,198,237,76,137,231,232,251,
+ 1,6,72,186,237,237,72,199,198,252,255,252,255,252,255,252,255,76,137,231,
+ 232,251,1,7,255,72,137,8,72,199,198,252,254,252,255,252,255,252,255,76,137,
+ 231,232,251,1,8,255,72,186,237,237,72,199,198,0,0,0,0,76,137,231,232,251,
+ 1,7,255,72,137,8,255,102,15,214,0,255,217,24,255,217,88,4,255,102,15,214,
+ 64,8,255,76,137,231,232,251,1,1,255,15,182,201,72,137,206,76,137,231,232,
+ 251,1,2,255,15,182,201,255,15,190,201,255,72,137,206,76,137,231,232,251,1,
+ 3,255,15,183,201,255,15,191,201,255,72,137,206,76,137,231,232,251,1,4,255,
+ 72,185,237,237,72,199,194,237,72,199,198,237,76,137,231,232,251,1,9,255,72,
+ 199,194,237,72,199,198,252,254,252,255,252,255,252,255,76,137,231,232,251,
+ 1,6,72,185,237,237,72,199,194,252,255,252,255,252,255,252,255,72,199,198,
+ 252,254,252,255,252,255,252,255,76,137,231,232,251,1,10,72,137,68,36,32,72,
+ 199,198,252,252,252,255,252,255,252,255,76,137,231,232,251,1,11,72,139,68,
+ 36,32,255,72,199,194,237,72,199,198,252,254,252,255,252,255,252,255,76,137,
+ 231,232,251,1,6,72,185,237,237,72,199,194,252,255,252,255,252,255,252,255,
+ 72,199,198,252,254,252,255,252,255,252,255,76,137,231,232,251,1,12,137,68,
+ 36,32,72,199,198,252,252,252,255,252,255,252,255,76,137,231,232,251,1,11,
+ 139,68,36,32,255,72,199,198,252,254,252,255,252,255,252,255,76,137,231,232,
+ 251,1,11,255,72,199,198,252,255,252,255,252,255,252,255,76,137,231,232,251,
+ 1,13,255,72,199,198,252,255,252,255,252,255,252,255,76,137,231,232,251,1,
+ 14,255,137,68,36,32,72,199,198,252,253,252,255,252,255,252,255,76,137,231,
+ 232,251,1,11,139,68,36,32,255,72,199,198,252,255,252,255,252,255,252,255,
+ 76,137,231,232,251,1,15,255,72,199,198,252,255,252,255,252,255,252,255,76,
+ 137,231,232,251,1,16,255,72,137,68,36,32,72,199,198,252,253,252,255,252,255,
+ 252,255,76,137,231,232,251,1,11,72,139,68,36,32,255,72,199,198,252,255,252,
+ 255,252,255,252,255,76,137,231,232,251,1,17,72,137,68,36,32,72,199,198,252,
+ 253,252,255,252,255,252,255,76,137,231,232,251,1,11,72,139,68,36,32,255,72,
+ 199,198,252,255,252,255,252,255,252,255,76,137,231,232,251,1,18,102,15,214,
+ 68,36,32,72,199,198,252,253,252,255,252,255,252,255,76,137,231,232,251,1,
+ 11,255,252,242,15,90,68,36,32,255,252,243,15,126,68,36,32,255,72,199,198,
+ 252,255,252,255,252,255,252,255,76,137,231,232,251,1,19,102,15,214,68,36,
+ 32,72,199,198,252,253,252,255,252,255,252,255,76,137,231,232,251,1,11,252,
+ 243,15,126,68,36,32,255,72,199,198,252,255,252,255,252,255,252,255,76,137,
+ 231,232,251,1,20,102,15,214,68,36,32,102,15,214,76,36,40,72,199,198,252,253,
+ 252,255,252,255,252,255,76,137,231,232,251,1,11,252,243,15,126,68,36,32,252,
+ 243,15,126,76,36,40,255,72,139,141,233,72,199,194,252,255,252,255,252,255,
+ 252,255,76,137,230,72,137,207,232,251,1,20,72,131,252,236,4,72,199,198,252,
+ 253,252,255,252,255,252,255,76,137,231,232,251,1,11,255,76,139,101,252,248,
+ 72,137,252,236,93,194,236,255,85,72,137,229,65,84,65,85,73,137,252,252,76,
+ 137,231,232,251,1,21,73,137,197,72,129,252,248,239,15,140,244,16,255,15,143,
+ 244,17,255,72,193,224,4,72,41,196,72,129,252,236,239,255,72,186,237,237,72,
+ 199,198,0,0,0,0,76,137,231,232,251,1,7,72,131,252,236,16,255,72,185,237,237,
+ 72,199,194,237,72,199,198,237,76,137,231,232,251,1,10,255,72,185,237,237,
+ 72,199,194,237,72,199,198,237,76,137,231,232,251,1,22,255,72,185,237,237,
+ 72,199,194,237,72,199,198,237,76,137,231,232,251,1,12,255,72,199,198,237,
+ 76,137,231,232,251,1,14,255,15,182,192,255,15,190,192,255,15,183,192,255,
+ 15,191,192,255,72,199,198,237,76,137,231,232,251,1,14,131,252,248,0,15,149,
+ 208,15,182,192,255,72,199,198,237,76,137,231,232,251,1,13,255,72,199,198,
+ 237,76,137,231,232,251,1,17,255,72,199,198,237,76,137,231,232,251,1,15,255,
+ 72,199,198,237,76,137,231,232,251,1,16,255,72,199,198,237,76,137,231,232,
+ 251,1,18,255,72,199,198,237,76,137,231,232,251,1,20,255,252,243,15,126,193,
+ 255,72,141,132,253,36,233,72,131,252,236,4,72,199,194,237,76,137,230,72,137,
+ 199,232,251,1,20,255,72,199,198,237,76,137,231,232,251,1,19,255,72,199,198,
+ 237,76,137,231,232,251,1,19,137,4,36,217,4,36,255,137,20,36,217,4,36,255,
+ 72,137,224,72,129,192,239,73,137,192,72,199,193,237,76,137,252,234,72,199,
+ 198,237,76,137,231,232,251,1,23,255,72,137,224,72,129,192,239,73,137,192,
+ 72,199,193,237,76,137,252,234,72,199,198,237,76,137,231,232,251,1,24,255,
+ 72,137,224,72,129,192,239,73,137,193,73,199,192,237,72,199,193,237,76,137,
+ 252,234,72,199,198,237,76,137,231,232,251,1,25,255,72,185,237,237,139,1,72,
+ 137,199,232,251,1,26,255,72,131,196,32,255,252,243,15,126,188,253,36,233,
+ 255,252,243,15,126,180,253,36,233,255,252,243,15,126,172,253,36,233,255,252,
+ 243,15,126,164,253,36,233,255,252,243,15,126,156,253,36,233,255,252,243,15,
+ 126,148,253,36,233,255,252,243,15,126,140,253,36,233,255,252,243,15,126,132,
+ 253,36,233,255,76,139,140,253,36,233,255,76,139,132,253,36,233,255,72,139,
+ 140,253,36,233,255,72,139,148,253,36,233,255,72,139,180,253,36,233,255,72,
+ 139,60,36,255,72,129,196,239,255,176,8,255,232,251,1,27,72,131,252,236,48,
+ 255,72,137,68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,199,
+ 198,237,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,
+ 72,137,68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,199,198,
+ 0,0,0,0,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,
+ 102,15,214,68,36,32,232,251,1,0,72,185,237,237,137,1,72,186,237,237,72,199,
+ 198,237,76,137,231,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,
+ 102,15,214,76,36,40,102,15,214,68,36,32,232,251,1,0,72,185,237,237,137,1,
+ 72,186,237,237,72,199,198,237,76,137,231,232,251,1,7,72,139,76,36,40,72,137,
+ 72,8,72,139,76,36,32,72,137,8,252,233,244,10,255,252,233,244,11,255,252,233,
+ 244,13,255,252,233,244,14,255,252,233,244,15,255,252,243,15,90,192,252,233,
+ 244,12,255
};
static const char *const globnames[] = {
@@ -263,7 +261,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
lua_rawgeti(L, usr, (int) i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
ret += sizeof(void*);
} else {
switch (mt->type) {
@@ -301,7 +299,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
ret += sizeof(void*);
}
lua_pop(L, 1);
@@ -397,13 +395,19 @@ static void add_int(Dst_DECL, const struct ctype* ct, struct reg_alloc* reg, int
reg->ints++;
}
#endif
-
- else if (is_int64) {
- dasm_put(Dst, 313, reg->off);
- reg->off += 8;
- } else {
- dasm_put(Dst, 314, reg->off);
- reg->off += 4;
+ else {
+#if defined _WIN64 || defined __amd64__
+ if (reg->off % 8 != 0) {
+ reg->off += 8 - (reg->off % 8);
+ }
+#endif
+ if (is_int64) {
+ dasm_put(Dst, 313, reg->off);
+ reg->off += 8;
+ } else {
+ dasm_put(Dst, 314, reg->off);
+ reg->off += 4;
+ }
}
}
@@ -557,7 +561,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
hidden_arg_off = reg.off;
reg.off += sizeof(void*);
}
@@ -570,7 +574,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -683,12 +687,12 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- dasm_put(Dst, 608, (unsigned int)((uintptr_t)(0)), (unsigned int)(((uintptr_t)(0))>>32), (mt->pointers || mt->type != VOID_TYPE) ? 1 : 0, nargs);
+ dasm_put(Dst, 608, (unsigned int)((uintptr_t)(0)), (unsigned int)(((uintptr_t)(0))>>32), (mt->pointers || mt->is_reference || mt->type != VOID_TYPE) ? 1 : 0, nargs);
// Unpack the return argument if not "void", also clean-up the lua stack
// to remove the return argument and bind table. Use lua_settop rather
// than lua_pop as lua_pop is implemented as a macro.
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -837,7 +841,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
* data is stored, which is popped by the calling code. */
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (!mbr_ct->pointers && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mbr_ct->pointers && !mbr_ct->is_reference && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
/* we can allocate more space for arguments as long as no add_*
* function has been called yet, mbr_ct will be added as an upvalue in
* the return processing later */
@@ -851,7 +855,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, (int) i);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers) {
+ if (mbr_ct->pointers || mbr_ct->is_reference) {
lua_getuservalue(L, -1);
num_upvals += 2;
dasm_put(Dst, 1300, (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals), i);
@@ -1109,7 +1113,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers || mbr_ct->type == INTPTR_TYPE) {
+ if (mbr_ct->pointers || mbr_ct->is_reference || mbr_ct->type == INTPTR_TYPE) {
lua_getuservalue(L, -1);
num_upvals += 2;
dasm_put(Dst, 1794, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
@@ -1128,23 +1132,25 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
- dasm_put(Dst, 1883, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1883, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
- dasm_put(Dst, 1930, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1927, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case VOID_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1992);
+ dasm_put(Dst, 1986);
break;
case BOOL_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1997);
+ dasm_put(Dst, 1991);
break;
case INT8_TYPE:
@@ -1154,7 +1160,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1376);
}
- dasm_put(Dst, 2002);
+ dasm_put(Dst, 1996);
break;
case INT16_TYPE:
@@ -1164,27 +1170,27 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1384);
}
- dasm_put(Dst, 2002);
+ dasm_put(Dst, 1996);
break;
case INT32_TYPE:
case ENUM_TYPE:
lua_pop(L, 1);
if (mbr_ct->is_unsigned) {
- dasm_put(Dst, 2007);
+ dasm_put(Dst, 2001);
} else {
- dasm_put(Dst, 2002);
+ dasm_put(Dst, 1996);
}
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 2012);
+ dasm_put(Dst, 2006);
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 2017);
+ dasm_put(Dst, 2011);
break;
default:
@@ -1197,7 +1203,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
cfunction f = compile(Dst, L, func, LUA_NOREF);
/* add a callback as an upval so that the jitted code gets cleaned up when
* the function gets gc'd */
- push_callback(L, f);
+ push_callback(L, f, func);
lua_pushcclosure(L, (lua_CFunction) f, num_upvals+1);
}
}
diff --git a/plugins/MirLua/Modules/luaffi/src/call_x64win.h b/plugins/MirLua/Modules/ffi/src/call_x64win.h
index 00041fe07f..fae36a0f96 100644
--- a/plugins/MirLua/Modules/luaffi/src/call_x64win.h
+++ b/plugins/MirLua/Modules/ffi/src/call_x64win.h
@@ -10,112 +10,109 @@
#endif
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
-static const unsigned char build_actionlist[1965] = {
- 248,10,184,1,0.0,0.0,0.0,76,139,109,252,240,76,139,101,252,248,72,137,252,
- 236,93,195,255,248,11,232,251,1,0,72,185,237,237,137,1,184,0,0.0,0.0,0.0,
- 76,139,109,252,240,76,139,101,252,248,72,137,252,236,93,195,255,248,12,102.0,
- 15.0,214,68,36,32,232,251,1,0,72,185,237,237,137,1,252,243.0,15.0,126,76,
- 36,32,76,137,225,232,251,1,1,252,233,244,10,255,248,13,15.0,182,192,137,68,
- 36,32,232,251,1,0,72,185,237,237,137,1,139,68,36,32,72,137,194,76,137,225,
- 232,251,1,2,252,233,244,10,255,248,14,137,68,36,32,232,251,1,0,72,185,237,
- 237,137,1,139,68,36,32,72,137,194,76,137,225,232,251,1,3,252,233,244,10,255,
- 248,15,137,68,36,32,232,251,1,0,72,185,237,237,137,1,139,68,36,32,72,137,
- 194,76,137,225,232,251,1,4,252,233,244,10,255,248,16,102,184,0,0.0,72,186,
- 237,237,76,137,225,232,251,1,5,255,248,17,102,184,0,0.0,72,186,237,237,76,
- 137,225,232,251,1,5,255,248,18,72,137,77,16,72,137,85,24,76,137,69,32,76,
- 137,77,40,102.0,15.0,214,69,252,240,102.0,15.0,214,77,232,102.0,15.0,214,
- 85,224,102.0,15.0,214,93,216,195,255,72,139,141,233,255,72,137,132,253,36,
- 233,255,221.0,133,233,255,217.0,133,233,255,252,243.0,15.0,126,133,233,255,
- 252,243.0,15.0,90,133,233,255,221.0,156,253,36,233,255,217.0,156,253,36,233,
- 255,102.0,15.0,214,132,253,36,233,255,252,242.0,15.0,90,192,102.0,15.0,214,
- 132,253,36,233,255,252,242.0,15.0,90,192,102.0,15.0,126,132,253,36,233,255,
- 85,72,137,229,65,84,72,129.0,252,236,239,232,244,18,255,73,188,237,237,255,
- 73,199.0,192,237,72,199.0,194,237,76,137,225,232,251,1,6,255,73,199.0,192,
- 237,72,199.0,194,252,255,252,255.0,252,255.0,252,255.0,76,137,225,232,251,
- 1,6,255,73,199.0,192,237,72,199.0,194,237,76,137,225,232,251,1,6,73,184,237,
- 237,72,199.0,194,252,255,252,255.0,252,255.0,252,255.0,76,137,225,232,251,
- 1,7,255,72,137,8,72,199.0,194,252,254,252,255.0,252,255.0,252,255.0,76,137,
- 225,232,251,1,8,255,73,184,237,237,72,199.0,194,0,0.0,0.0,0.0,76,137,225,
- 232,251,1,7,255,72,137,8,255,102.0,15.0,214,0,255,217.0,24,255,217.0,88,4,
- 255,102.0,15.0,214,64,8,255,252,243.0,15.0,126,200,76,137,225,232,251,1,1,
- 255,15.0,182,201,72,137,202,76,137,225,232,251,1,2,255,15.0,182,201,255,15.0,
- 190,201,255,72,137,202,76,137,225,232,251,1,3,255,15.0,183,201,255,15.0,191,
- 201,255,72,137,202,76,137,225,232,251,1,4,255,73,185,237,237,73,199.0,192,
- 237,72,199.0,194,237,76,137,225,232,251,1,9,255,73,199.0,192,237,72,199.0,
- 194,252,254,252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,6,73,185,237,
- 237,73,199.0,192,252,255,252,255.0,252,255.0,252,255.0,72,199.0,194,252,254,
- 252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,10,72,137,68,36,32,72,
- 199.0,194,252,252,252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,11,72,
- 139,68,36,32,255,73,199.0,192,237,72,199.0,194,252,254,252,255.0,252,255.0,
- 252,255.0,76,137,225,232,251,1,6,73,185,237,237,73,199.0,192,252,255,252,
- 255.0,252,255.0,252,255.0,72,199.0,194,252,254,252,255.0,252,255.0,252,255.0,
- 76,137,225,232,251,1,12,137,68,36,32,72,199.0,194,252,252,252,255.0,252,255.0,
- 252,255.0,76,137,225,232,251,1,11,139,68,36,32,255,72,199.0,194,252,254,252,
- 255.0,252,255.0,252,255.0,76,137,225,232,251,1,11,255,72,199.0,194,252,255,
- 252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,13,255,72,199.0,194,252,
- 255,252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,14,255,137,68,36,32,
- 72,199.0,194,252,253,252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,11,
- 139,68,36,32,255,72,199.0,194,252,255,252,255.0,252,255.0,252,255.0,76,137,
- 225,232,251,1,15,255,72,199.0,194,252,255,252,255.0,252,255.0,252,255.0,76,
- 137,225,232,251,1,16,255,72,137,68,36,32,72,199.0,194,252,253,252,255.0,252,
- 255.0,252,255.0,76,137,225,232,251,1,11,72,139,68,36,32,255,72,199.0,194,
- 252,255,252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,17,72,137,68,36,
- 32,72,199.0,194,252,253,252,255.0,252,255.0,252,255.0,76,137,225,232,251,
- 1,11,72,139,68,36,32,255,72,199.0,194,252,255,252,255.0,252,255.0,252,255.0,
- 76,137,225,232,251,1,18,102.0,15.0,214,68,36,32,72,199.0,194,252,253,252,
- 255.0,252,255.0,252,255.0,76,137,225,232,251,1,11,255,252,242.0,15.0,90,68,
- 36,32,255,252,243.0,15.0,126,68,36,32,255,72,199.0,194,252,255,252,255.0,
- 252,255.0,252,255.0,76,137,225,232,251,1,19,102.0,15.0,214,68,36,32,72,199.0,
- 194,252,253,252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,11,252,243.0,
- 15.0,126,68,36,32,255,72,199.0,194,252,255,252,255.0,252,255.0,252,255.0,
- 76,137,225,232,251,1,20,102.0,15.0,214,68,36,32,102.0,15.0,214,76,36,40,72,
- 199.0,194,252,253,252,255.0,252,255.0,252,255.0,76,137,225,232,251,1,11,252,
- 243.0,15.0,126,68,36,32,252,243.0,15.0,126,76,36,40,255,72,139,141,233,73,
- 199.0,192,252,255,252,255.0,252,255.0,252,255.0,76,137,226,72,137,201,232,
- 251,1,20,72,131.0,252,236,4,72,199.0,194,252,253,252,255.0,252,255.0,252,
- 255.0,76,137,225,232,251,1,11,255,76,139,101,252,248,72,137,252,236,93,194,
- 236,255,85,72,137,229,65,84,65,85,73,137,204,72,131.0,252,236,32,76,137,225,
- 232,251,1,21,73,137,197,72,129.0,252,248,239,15.0,140,244,16,255,15.0,143,
- 244,17,255,72,193.0,224,4,72,41,196,72,129.0,252,236,239,255,73,184,237,237,
- 72,199.0,194,0,0.0,0.0,0.0,76,137,225,232,251,1,7,72,131.0,252,236,16,255,
- 73,185,237,237,73,199.0,192,237,72,199.0,194,237,76,137,225,232,251,1,10,
- 255,73,185,237,237,73,199.0,192,237,72,199.0,194,237,76,137,225,232,251,1,
- 22,255,73,185,237,237,73,199.0,192,237,72,199.0,194,237,76,137,225,232,251,
- 1,12,255,72,199.0,194,237,76,137,225,232,251,1,14,255,15.0,182,192,255,15.0,
- 190,192,255,15.0,183,192,255,15.0,191,192,255,72,199.0,194,237,76,137,225,
- 232,251,1,14,131.0,252,248,0,15.0,149.0,208,15.0,182,192,255,72,199.0,194,
- 237,76,137,225,232,251,1,13,255,72,199.0,194,237,76,137,225,232,251,1,17,
- 255,72,199.0,194,237,76,137,225,232,251,1,15,255,72,199.0,194,237,76,137,
- 225,232,251,1,16,255,72,199.0,194,237,76,137,225,232,251,1,18,255,72,199.0,
- 194,237,76,137,225,232,251,1,20,255,252,243.0,15.0,126,193,255,72,141,132,
- 253,36,233,72,131.0,252,236,4,73,199.0,192,237,76,137,226,72,137,193,232,
- 251,1,20,255,72,199.0,194,237,76,137,225,232,251,1,19,255,72,199.0,194,237,
- 76,137,225,232,251,1,19,137,4,36,217.0,4,36,255,137,20,36,217.0,4,36,255,
- 73,129.0,252,253,239,15.0,142,244,247.0,72,137,224,72,129.0,192,239,73,137,
- 193,77,137,232,72,199.0,194,237,76,137,225,232,251,1,23,72,137,224,72,129.0,
- 192,239,73,137,193,73,199.0,192,237,72,199.0,194,237,76,137,225,232,251,1,
- 24,252,233,244,248.0,248,1,72,137,224,72,129.0,192,239,73,137,193,77,137,
- 232,72,199.0,194,237,76,137,225,232,251,1,24,248,2,255,72,137,224,72,129.0,
- 192,239,73,137,193,77,137,232,72,199.0,194,237,76,137,225,232,251,1,23,255,
- 72,185,237,237,139,1,72,137,193,232,251,1,25,255,72,131.0,196,32,255,252,
- 243.0,15.0,126,156,253,36,233,255,76,139,140,253,36,233,255,252,243.0,15.0,
- 126,148,253,36,233,255,76,139,132,253,36,233,255,252,243.0,15.0,126,140,253,
- 36,233,255,72,139,148,253,36,233,255,252,243.0,15.0,126,4,36,255,72,139,12,
- 36,255,232,251,1,26,72,131.0,252,236,48,255,72,137,68,36,32,232,251,1,0,72,
- 185,237,237,137,1,73,184,237,237,72,199.0,194,237,76,137,225,232,251,1,7,
- 72,139,76,36,32,72,137,8,252,233,244,10,255,72,137,68,36,32,232,251,1,0,72,
- 185,237,237,137,1,73,184,237,237,72,199.0,194,0,0.0,0.0,0.0,76,137,225,232,
- 251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,102.0,15.0,214,68,36,
- 32,232,251,1,0,72,185,237,237,137,1,73,184,237,237,72,199.0,194,0,0.0,0.0,
- 0.0,76,137,225,232,251,1,7,72,139,76,36,32,72,137,8,252,233,244,10,255,102.0,
- 15.0,214,76,36,40,102.0,15.0,214,68,36,32,232,251,1,0,72,185,237,237,137,
- 1,73,184,237,237,72,199.0,194,0,0.0,0.0,0.0,76,137,225,232,251,1,7,72,139,
- 76,36,40,72,137,72,8,72,139,76,36,32,72,137,8,252,233,244,10,255,252,233,
- 244,11,255,252,233,244,13,255,252,233,244,14,255,252,233,244,15,255,252,243.0,
- 15.0,90,192,252,233,244,12,255
+static const unsigned char build_actionlist[1959] = {
+ 248,10,184,1,0,0,0,76,139,109,252,240,76,139,101,252,248,72,137,252,236,93,
+ 195,255,248,11,232,251,1,0,72,185,237,237,137,1,184,0,0,0,0,76,139,109,252,
+ 240,76,139,101,252,248,72,137,252,236,93,195,255,248,12,102,15,214,68,36,
+ 32,232,251,1,0,72,185,237,237,137,1,252,243,15,126,76,36,32,76,137,225,232,
+ 251,1,1,252,233,244,10,255,248,13,15,182,192,137,68,36,32,232,251,1,0,72,
+ 185,237,237,137,1,139,68,36,32,72,137,194,76,137,225,232,251,1,2,252,233,
+ 244,10,255,248,14,137,68,36,32,232,251,1,0,72,185,237,237,137,1,139,68,36,
+ 32,72,137,194,76,137,225,232,251,1,3,252,233,244,10,255,248,15,137,68,36,
+ 32,232,251,1,0,72,185,237,237,137,1,139,68,36,32,72,137,194,76,137,225,232,
+ 251,1,4,252,233,244,10,255,248,16,102,184,0,0,72,186,237,237,76,137,225,232,
+ 251,1,5,255,248,17,102,184,0,0,72,186,237,237,76,137,225,232,251,1,5,255,
+ 248,18,72,137,77,16,72,137,85,24,76,137,69,32,76,137,77,40,102,15,214,69,
+ 252,240,102,15,214,77,232,102,15,214,85,224,102,15,214,93,216,195,255,72,
+ 139,141,233,255,72,137,132,253,36,233,255,221,133,233,255,217,133,233,255,
+ 252,243,15,126,133,233,255,252,243,15,90,133,233,255,221,156,253,36,233,255,
+ 217,156,253,36,233,255,102,15,214,132,253,36,233,255,252,242,15,90,192,102,
+ 15,214,132,253,36,233,255,252,242,15,90,192,102,15,126,132,253,36,233,255,
+ 85,72,137,229,65,84,72,129,252,236,239,232,244,18,255,73,188,237,237,255,
+ 73,199,192,237,72,199,194,237,76,137,225,232,251,1,6,255,73,199,192,237,72,
+ 199,194,252,255,252,255,252,255,252,255,76,137,225,232,251,1,6,255,73,199,
+ 192,237,72,199,194,237,76,137,225,232,251,1,6,73,184,237,237,72,199,194,252,
+ 255,252,255,252,255,252,255,76,137,225,232,251,1,7,255,72,137,8,72,199,194,
+ 252,254,252,255,252,255,252,255,76,137,225,232,251,1,8,255,73,184,237,237,
+ 72,199,194,0,0,0,0,76,137,225,232,251,1,7,255,72,137,8,255,102,15,214,0,255,
+ 217,24,255,217,88,4,255,102,15,214,64,8,255,252,243,15,126,200,76,137,225,
+ 232,251,1,1,255,15,182,201,72,137,202,76,137,225,232,251,1,2,255,15,182,201,
+ 255,15,190,201,255,72,137,202,76,137,225,232,251,1,3,255,15,183,201,255,15,
+ 191,201,255,72,137,202,76,137,225,232,251,1,4,255,73,185,237,237,73,199,192,
+ 237,72,199,194,237,76,137,225,232,251,1,9,255,73,199,192,237,72,199,194,252,
+ 254,252,255,252,255,252,255,76,137,225,232,251,1,6,73,185,237,237,73,199,
+ 192,252,255,252,255,252,255,252,255,72,199,194,252,254,252,255,252,255,252,
+ 255,76,137,225,232,251,1,10,72,137,68,36,32,72,199,194,252,252,252,255,252,
+ 255,252,255,76,137,225,232,251,1,11,72,139,68,36,32,255,73,199,192,237,72,
+ 199,194,252,254,252,255,252,255,252,255,76,137,225,232,251,1,6,73,185,237,
+ 237,73,199,192,252,255,252,255,252,255,252,255,72,199,194,252,254,252,255,
+ 252,255,252,255,76,137,225,232,251,1,12,137,68,36,32,72,199,194,252,252,252,
+ 255,252,255,252,255,76,137,225,232,251,1,11,139,68,36,32,255,72,199,194,252,
+ 254,252,255,252,255,252,255,76,137,225,232,251,1,11,255,72,199,194,252,255,
+ 252,255,252,255,252,255,76,137,225,232,251,1,13,255,72,199,194,252,255,252,
+ 255,252,255,252,255,76,137,225,232,251,1,14,255,137,68,36,32,72,199,194,252,
+ 253,252,255,252,255,252,255,76,137,225,232,251,1,11,139,68,36,32,255,72,199,
+ 194,252,255,252,255,252,255,252,255,76,137,225,232,251,1,15,255,72,199,194,
+ 252,255,252,255,252,255,252,255,76,137,225,232,251,1,16,255,72,137,68,36,
+ 32,72,199,194,252,253,252,255,252,255,252,255,76,137,225,232,251,1,11,72,
+ 139,68,36,32,255,72,199,194,252,255,252,255,252,255,252,255,76,137,225,232,
+ 251,1,17,72,137,68,36,32,72,199,194,252,253,252,255,252,255,252,255,76,137,
+ 225,232,251,1,11,72,139,68,36,32,255,72,199,194,252,255,252,255,252,255,252,
+ 255,76,137,225,232,251,1,18,102,15,214,68,36,32,72,199,194,252,253,252,255,
+ 252,255,252,255,76,137,225,232,251,1,11,255,252,242,15,90,68,36,32,255,252,
+ 243,15,126,68,36,32,255,72,199,194,252,255,252,255,252,255,252,255,76,137,
+ 225,232,251,1,19,102,15,214,68,36,32,72,199,194,252,253,252,255,252,255,252,
+ 255,76,137,225,232,251,1,11,252,243,15,126,68,36,32,255,72,199,194,252,255,
+ 252,255,252,255,252,255,76,137,225,232,251,1,20,102,15,214,68,36,32,102,15,
+ 214,76,36,40,72,199,194,252,253,252,255,252,255,252,255,76,137,225,232,251,
+ 1,11,252,243,15,126,68,36,32,252,243,15,126,76,36,40,255,72,139,141,233,73,
+ 199,192,252,255,252,255,252,255,252,255,76,137,226,72,137,201,232,251,1,20,
+ 72,131,252,236,4,72,199,194,252,253,252,255,252,255,252,255,76,137,225,232,
+ 251,1,11,255,76,139,101,252,248,72,137,252,236,93,194,236,255,85,72,137,229,
+ 65,84,65,85,73,137,204,72,131,252,236,32,76,137,225,232,251,1,21,73,137,197,
+ 72,129,252,248,239,15,140,244,16,255,15,143,244,17,255,72,193,224,4,72,41,
+ 196,72,129,252,236,239,255,73,184,237,237,72,199,194,0,0,0,0,76,137,225,232,
+ 251,1,7,72,131,252,236,16,255,73,185,237,237,73,199,192,237,72,199,194,237,
+ 76,137,225,232,251,1,10,255,73,185,237,237,73,199,192,237,72,199,194,237,
+ 76,137,225,232,251,1,22,255,73,185,237,237,73,199,192,237,72,199,194,237,
+ 76,137,225,232,251,1,12,255,72,199,194,237,76,137,225,232,251,1,14,255,15,
+ 182,192,255,15,190,192,255,15,183,192,255,15,191,192,255,72,199,194,237,76,
+ 137,225,232,251,1,14,131,252,248,0,15,149,208,15,182,192,255,72,199,194,237,
+ 76,137,225,232,251,1,13,255,72,199,194,237,76,137,225,232,251,1,17,255,72,
+ 199,194,237,76,137,225,232,251,1,15,255,72,199,194,237,76,137,225,232,251,
+ 1,16,255,72,199,194,237,76,137,225,232,251,1,18,255,72,199,194,237,76,137,
+ 225,232,251,1,20,255,252,243,15,126,193,255,72,141,132,253,36,233,72,131,
+ 252,236,4,73,199,192,237,76,137,226,72,137,193,232,251,1,20,255,72,199,194,
+ 237,76,137,225,232,251,1,19,255,72,199,194,237,76,137,225,232,251,1,19,137,
+ 4,36,217,4,36,255,137,20,36,217,4,36,255,73,129,252,253,239,15,142,244,247,
+ 72,137,224,72,129,192,239,73,137,193,77,137,232,72,199,194,237,76,137,225,
+ 232,251,1,23,72,137,224,72,129,192,239,73,137,193,73,199,192,237,72,199,194,
+ 237,76,137,225,232,251,1,24,252,233,244,248,248,1,72,137,224,72,129,192,239,
+ 73,137,193,77,137,232,72,199,194,237,76,137,225,232,251,1,24,248,2,255,72,
+ 137,224,72,129,192,239,73,137,193,77,137,232,72,199,194,237,76,137,225,232,
+ 251,1,23,255,72,185,237,237,139,1,72,137,193,232,251,1,25,255,72,131,196,
+ 32,255,252,243,15,126,156,253,36,233,255,76,139,140,253,36,233,255,252,243,
+ 15,126,148,253,36,233,255,76,139,132,253,36,233,255,252,243,15,126,140,253,
+ 36,233,255,72,139,148,253,36,233,255,252,243,15,126,4,36,255,72,139,12,36,
+ 255,232,251,1,26,72,131,252,236,48,255,72,137,68,36,32,232,251,1,0,72,185,
+ 237,237,137,1,73,184,237,237,72,199,194,237,76,137,225,232,251,1,7,72,139,
+ 76,36,32,72,137,8,252,233,244,10,255,72,137,68,36,32,232,251,1,0,72,185,237,
+ 237,137,1,73,184,237,237,72,199,194,0,0,0,0,76,137,225,232,251,1,7,72,139,
+ 76,36,32,72,137,8,252,233,244,10,255,102,15,214,68,36,32,232,251,1,0,72,185,
+ 237,237,137,1,73,184,237,237,72,199,194,237,76,137,225,232,251,1,7,72,139,
+ 76,36,32,72,137,8,252,233,244,10,255,102,15,214,76,36,40,102,15,214,68,36,
+ 32,232,251,1,0,72,185,237,237,137,1,73,184,237,237,72,199,194,237,76,137,
+ 225,232,251,1,7,72,139,76,36,40,72,137,72,8,72,139,76,36,32,72,137,8,252,
+ 233,244,10,255,252,233,244,11,255,252,233,244,13,255,252,233,244,14,255,252,
+ 233,244,15,255,252,243,15,90,192,252,233,244,12,255
};
static const char *const globnames[] = {
@@ -259,7 +256,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
lua_rawgeti(L, usr, (int) i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
ret += sizeof(void*);
} else {
switch (mt->type) {
@@ -297,7 +294,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
ret += sizeof(void*);
}
lua_pop(L, 1);
@@ -393,13 +390,19 @@ static void add_int(Dst_DECL, const struct ctype* ct, struct reg_alloc* reg, int
reg->ints++;
}
#endif
-
- else if (is_int64) {
- dasm_put(Dst, 285, reg->off);
- reg->off += 8;
- } else {
- dasm_put(Dst, 286, reg->off);
- reg->off += 4;
+ else {
+#if defined _WIN64 || defined __amd64__
+ if (reg->off % 8 != 0) {
+ reg->off += 8 - (reg->off % 8);
+ }
+#endif
+ if (is_int64) {
+ dasm_put(Dst, 285, reg->off);
+ reg->off += 8;
+ } else {
+ dasm_put(Dst, 286, reg->off);
+ reg->off += 4;
+ }
}
}
@@ -553,7 +556,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
hidden_arg_off = reg.off;
reg.off += sizeof(void*);
}
@@ -566,7 +569,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -679,12 +682,12 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- dasm_put(Dst, 585, (unsigned int)((uintptr_t)(0)), (unsigned int)(((uintptr_t)(0))>>32), (mt->pointers || mt->type != VOID_TYPE) ? 1 : 0, nargs);
+ dasm_put(Dst, 585, (unsigned int)((uintptr_t)(0)), (unsigned int)(((uintptr_t)(0))>>32), (mt->pointers || mt->is_reference || mt->type != VOID_TYPE) ? 1 : 0, nargs);
// Unpack the return argument if not "void", also clean-up the lua stack
// to remove the return argument and bind table. Use lua_settop rather
// than lua_pop as lua_pop is implemented as a macro.
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -833,7 +836,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
* data is stored, which is popped by the calling code. */
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (!mbr_ct->pointers && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mbr_ct->pointers && !mbr_ct->is_reference && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
/* we can allocate more space for arguments as long as no add_*
* function has been called yet, mbr_ct will be added as an upvalue in
* the return processing later */
@@ -847,7 +850,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, (int) i);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers) {
+ if (mbr_ct->pointers || mbr_ct->is_reference) {
lua_getuservalue(L, -1);
num_upvals += 2;
dasm_put(Dst, 1281, (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals), i);
@@ -1096,7 +1099,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers || mbr_ct->type == INTPTR_TYPE) {
+ if (mbr_ct->pointers || mbr_ct->is_reference || mbr_ct->type == INTPTR_TYPE) {
lua_getuservalue(L, -1);
num_upvals += 2;
dasm_put(Dst, 1737, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
@@ -1115,23 +1118,25 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
- dasm_put(Dst, 1826, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1826, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
- dasm_put(Dst, 1873, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32));
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1870, (unsigned int)((uintptr_t)(perr)), (unsigned int)(((uintptr_t)(perr))>>32), (unsigned int)((uintptr_t)(mbr_ct)), (unsigned int)(((uintptr_t)(mbr_ct))>>32), lua_upvalueindex(num_upvals));
break;
case VOID_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1935);
+ dasm_put(Dst, 1929);
break;
case BOOL_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1940);
+ dasm_put(Dst, 1934);
break;
case INT8_TYPE:
@@ -1141,7 +1146,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1357);
}
- dasm_put(Dst, 1945);
+ dasm_put(Dst, 1939);
break;
case INT16_TYPE:
@@ -1151,27 +1156,27 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1365);
}
- dasm_put(Dst, 1945);
+ dasm_put(Dst, 1939);
break;
case INT32_TYPE:
case ENUM_TYPE:
lua_pop(L, 1);
if (mbr_ct->is_unsigned) {
- dasm_put(Dst, 1950);
+ dasm_put(Dst, 1944);
} else {
- dasm_put(Dst, 1945);
+ dasm_put(Dst, 1939);
}
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1955);
+ dasm_put(Dst, 1949);
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1960);
+ dasm_put(Dst, 1954);
break;
default:
@@ -1184,7 +1189,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
cfunction f = compile(Dst, L, func, LUA_NOREF);
/* add a callback as an upval so that the jitted code gets cleaned up when
* the function gets gc'd */
- push_callback(L, f);
+ push_callback(L, f, func);
lua_pushcclosure(L, (lua_CFunction) f, num_upvals+1);
}
}
diff --git a/plugins/MirLua/Modules/luaffi/src/call_x86.dasc b/plugins/MirLua/Modules/ffi/src/call_x86.dasc
index fa8271a2a1..ef2ba24e2f 100644
--- a/plugins/MirLua/Modules/luaffi/src/call_x86.dasc
+++ b/plugins/MirLua/Modules/ffi/src/call_x86.dasc
@@ -1,5 +1,10 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
|.if X64
|.arch x64
@@ -367,7 +372,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
lua_rawgeti(L, usr, (int) i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
ret += sizeof(void*);
} else {
switch (mt->type) {
@@ -405,7 +410,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
ret += sizeof(void*);
}
lua_pop(L, 1);
@@ -506,18 +511,24 @@ static void add_int(Dst_DECL, const struct ctype* ct, struct reg_alloc* reg, int
reg->ints++;
}
#endif
-
- else if (is_int64) {
- |.if X64
- | mov [rsp + reg->off], rax
- |.else
- | mov [rsp + reg->off], RET_L
- | mov [rsp + reg->off + 4], RET_H
- |.endif
- reg->off += 8;
- } else {
- | mov [rsp+reg->off], eax
- reg->off += 4;
+ else {
+#if defined _WIN64 || defined __amd64__
+ if (reg->off % 8 != 0) {
+ reg->off += 8 - (reg->off % 8);
+ }
+#endif
+ if (is_int64) {
+ |.if X64
+ | mov [rsp + reg->off], rax
+ |.else
+ | mov [rsp + reg->off], RET_L
+ | mov [rsp + reg->off + 4], RET_H
+ |.endif
+ reg->off += 8;
+ } else {
+ | mov [rsp+reg->off], eax
+ reg->off += 4;
+ }
}
}
@@ -686,7 +697,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
hidden_arg_off = reg.off;
reg.off += sizeof(void*);
}
@@ -699,7 +710,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -838,12 +849,12 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- | call_rrrp extern lua_callk, L_ARG, nargs, (mt->pointers || mt->type != VOID_TYPE) ? 1 : 0, 0
+ | call_rrrp extern lua_callk, L_ARG, nargs, (mt->pointers || mt->is_reference || mt->type != VOID_TYPE) ? 1 : 0, 0
// Unpack the return argument if not "void", also clean-up the lua stack
// to remove the return argument and bind table. Use lua_settop rather
// than lua_pop as lua_pop is implemented as a macro.
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -1078,7 +1089,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
* data is stored, which is popped by the calling code. */
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (!mbr_ct->pointers && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mbr_ct->pointers && !mbr_ct->is_reference && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
/* we can allocate more space for arguments as long as no add_*
* function has been called yet, mbr_ct will be added as an upvalue in
* the return processing later */
@@ -1093,7 +1104,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, (int) i);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers) {
+ if (mbr_ct->pointers || mbr_ct->is_reference) {
lua_getuservalue(L, -1);
num_upvals += 2;
| call_rrrp extern check_typed_pointer, L_ARG, i, lua_upvalueindex(num_upvals), mbr_ct
@@ -1417,7 +1428,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers || mbr_ct->type == INTPTR_TYPE) {
+ if (mbr_ct->pointers || mbr_ct->is_reference || mbr_ct->type == INTPTR_TYPE) {
lua_getuservalue(L, -1);
num_upvals += 2;
| mov [rsp+32], rax // save the pointer
@@ -1468,7 +1479,8 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
|.if X64
| // complex floats are returned as two floats packed into xmm0
| movq qword [rsp+32], xmm0
@@ -1479,7 +1491,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
|.endif
|
| get_errno
- | call_rrp extern push_cdata, L_ARG, 0, mbr_ct
+ | call_rrp extern push_cdata, L_ARG, lua_upvalueindex(num_upvals), mbr_ct
|
| // ((complex_float*) cdata) = val
|.if X64
@@ -1496,14 +1508,15 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
|.if X64
| // complex doubles are returned as xmm0 and xmm1
| movq qword [rsp+40], xmm1
| movq qword [rsp+32], xmm0
|
| get_errno
- | call_rrp extern push_cdata, L_ARG, 0, mbr_ct
+ | call_rrp extern push_cdata, L_ARG, lua_upvalueindex(num_upvals), mbr_ct
|
| // ((complex_double*) cdata)->real = val0
| // ((complex_double*) cdata)->imag = val1
@@ -1587,7 +1600,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
cfunction f = compile(Dst, L, func, LUA_NOREF);
/* add a callback as an upval so that the jitted code gets cleaned up when
* the function gets gc'd */
- push_callback(L, f);
+ push_callback(L, f, func);
lua_pushcclosure(L, (lua_CFunction) f, num_upvals+1);
}
}
diff --git a/plugins/MirLua/Modules/luaffi/src/call_x86.h b/plugins/MirLua/Modules/ffi/src/call_x86.h
index 982c8c884f..40bad83147 100644
--- a/plugins/MirLua/Modules/luaffi/src/call_x86.h
+++ b/plugins/MirLua/Modules/ffi/src/call_x86.h
@@ -10,100 +10,99 @@
#endif
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
-static const unsigned char build_actionlist[1803] = {
- 248,10,184,1,0.0,0.0,0.0,139,117,252,248,139,125,252,252,137,252,236,93,195,
- 255,248,11,232,251,1,0,185,237,137,1,184,0,0.0,0.0,0.0,139,117,252,248,139,
- 125,252,252,137,252,236,93,195,255,248,12,221.0,92,36,4,232,251,1,0,185,237,
- 137,1,137,60,36,232,251,1,1,252,233,244,10,255,248,13,15.0,182,192,137,68,
- 36,32,232,251,1,0,185,237,137,1,139,68,36,32,137,68,36,4,137,60,36,232,251,
- 1,2,252,233,244,10,255,248,14,137,68,36,32,232,251,1,0,185,237,137,1,139,
- 68,36,32,137,68,36,4,137,60,36,232,251,1,3,252,233,244,10,255,248,15,137,
- 68,36,32,232,251,1,0,185,237,137,1,139,68,36,32,137,68,36,4,137,60,36,232,
- 251,1,4,252,233,244,10,255,248,16,102,184,0,0.0,199.0,68,36,4,237,137,60,
- 36,232,251,1,5,255,248,17,102,184,0,0.0,199.0,68,36,4,237,137,60,36,232,251,
- 1,5,255,248,18,137,77,252,248,137,85,252,244,195,255,139,141,233,255,139,
- 141,233,139,149,233,255,137,132,253,36,233,255,137,132,253,36,233,137,148,
- 253,36,233,255,221.0,133,233,255,217.0,133,233,255,252,243.0,15.0,126,133,
- 233,255,252,243.0,15.0,90,133,233,255,221.0,156,253,36,233,255,217.0,156,
- 253,36,233,255,102.0,15.0,214,132,253,36,233,255,252,242.0,15.0,90,192,102.0,
- 15.0,214,132,253,36,233,255,252,242.0,15.0,90,192,102.0,15.0,126,132,253,
- 36,233,255,85,137,229,87,129.0,252,236,239,255,232,244,18,255,191,237,255,
- 199.0,68,36,8,237,199.0,68,36,4,237,137,60,36,232,251,1,6,255,199.0,68,36,
- 8,237,199.0,68,36,4,252,255,252,255.0,252,255.0,252,255.0,137,60,36,232,251,
- 1,6,255,199.0,68,36,8,237,199.0,68,36,4,237,137,60,36,232,251,1,6,199.0,68,
- 36,8,237,199.0,68,36,4,252,255,252,255.0,252,255.0,252,255.0,137,60,36,232,
- 251,1,7,255,137,8,199.0,68,36,4,252,254,252,255.0,252,255.0,252,255.0,137,
- 60,36,232,251,1,8,255,199.0,68,36,8,237,199.0,68,36,4,0,0.0,0.0,0.0,137,60,
- 36,232,251,1,7,255,137,8,137,80,4,255,137,8,255,102.0,15.0,214,0,255,217.0,
- 24,255,217.0,88,4,255,221.0,24,255,221.0,88,8,255,221.0,92,36,4,137,60,36,
- 232,251,1,1,255,15.0,182,201,137,76,36,4,137,60,36,232,251,1,2,255,15.0,182,
- 201,255,15.0,190,201,255,137,76,36,4,137,60,36,232,251,1,3,255,15.0,183,201,
- 255,15.0,191,201,255,137,76,36,4,137,60,36,232,251,1,4,255,199.0,68,36,12,
- 0,0.0,0.0,0.0,199.0,68,36,8,237,199.0,68,36,4,237,137,60,36,232,251,1,9,255,
- 199.0,68,36,8,237,199.0,68,36,4,252,254,252,255.0,252,255.0,252,255.0,137,
- 60,36,232,251,1,6,199.0,68,36,12,237,199.0,68,36,8,252,255,252,255.0,252,
- 255.0,252,255.0,199.0,68,36,4,252,254,252,255.0,252,255.0,252,255.0,137,60,
- 36,232,251,1,10,137,68,36,32,199.0,68,36,4,252,252,252,255.0,252,255.0,252,
- 255.0,137,60,36,232,251,1,11,139,68,36,32,255,199.0,68,36,8,237,199.0,68,
- 36,4,252,254,252,255.0,252,255.0,252,255.0,137,60,36,232,251,1,6,199.0,68,
- 36,12,237,199.0,68,36,8,252,255,252,255.0,252,255.0,252,255.0,199.0,68,36,
- 4,252,254,252,255.0,252,255.0,252,255.0,137,60,36,232,251,1,12,137,68,36,
- 32,199.0,68,36,4,252,252,252,255.0,252,255.0,252,255.0,137,60,36,232,251,
- 1,11,139,68,36,32,255,199.0,68,36,4,252,254,252,255.0,252,255.0,252,255.0,
- 137,60,36,232,251,1,11,255,199.0,68,36,4,252,255,252,255.0,252,255.0,252,
- 255.0,137,60,36,232,251,1,13,255,199.0,68,36,4,252,255,252,255.0,252,255.0,
- 252,255.0,137,60,36,232,251,1,14,255,137,68,36,32,199.0,68,36,4,252,253,252,
- 255.0,252,255.0,252,255.0,137,60,36,232,251,1,11,139,68,36,32,255,199.0,68,
- 36,4,252,255,252,255.0,252,255.0,252,255.0,137,60,36,232,251,1,15,255,199.0,
- 68,36,4,252,255,252,255.0,252,255.0,252,255.0,137,60,36,232,251,1,16,255,
- 137,68,36,32,137,84,36,36,199.0,68,36,4,252,253,252,255.0,252,255.0,252,255.0,
- 137,60,36,232,251,1,11,139,68,36,32,139,84,36,36,255,199.0,68,36,4,252,255,
- 252,255.0,252,255.0,252,255.0,137,60,36,232,251,1,17,137,68,36,32,199.0,68,
- 36,4,252,253,252,255.0,252,255.0,252,255.0,137,60,36,232,251,1,11,139,68,
- 36,32,255,199.0,68,36,4,252,255,252,255.0,252,255.0,252,255.0,137,60,36,232,
- 251,1,18,255,221.0,92,36,32,199.0,68,36,4,252,253,252,255.0,252,255.0,252,
- 255.0,137,60,36,232,251,1,11,221.0,68,36,32,255,199.0,68,36,4,252,255,252,
- 255.0,252,255.0,252,255.0,137,60,36,232,251,1,19,137,68,36,32,137,84,36,36,
- 199.0,68,36,4,252,253,252,255.0,252,255.0,252,255.0,137,60,36,232,251,1,11,
- 139,68,36,32,139,84,36,36,255,199.0,68,36,4,252,255,252,255.0,252,255.0,252,
- 255.0,137,60,36,232,251,1,20,102.0,15.0,214,68,36,32,102.0,15.0,214,76,36,
- 40,199.0,68,36,4,252,253,252,255.0,252,255.0,252,255.0,137,60,36,232,251,
- 1,11,252,243.0,15.0,126,68,36,32,252,243.0,15.0,126,76,36,40,255,139,141,
- 233,199.0,68,36,8,252,255,252,255.0,252,255.0,252,255.0,137,124,36,4,137,
- 12,36,232,251,1,20,131.0,252,236,4,199.0,68,36,4,252,253,252,255.0,252,255.0,
- 252,255.0,137,60,36,232,251,1,11,255,139,125,252,252,137,252,236,93,194,236,
- 255,85,137,229,87,86,139,189,233,131.0,252,236,16,137,60,36,232,251,1,21,
- 137,198,129.0,252,248,239,15.0,140,244,16,255,15.0,143,244,17,255,193.0,224,
- 4,41,196,129.0,252,236,239,255,199.0,68,36,8,237,199.0,68,36,4,0,0.0,0.0,
- 0.0,137,60,36,232,251,1,7,131.0,252,236,16,255,199.0,68,36,12,237,199.0,68,
- 36,8,237,199.0,68,36,4,237,137,60,36,232,251,1,10,255,199.0,68,36,12,237,
- 199.0,68,36,8,237,199.0,68,36,4,237,137,60,36,232,251,1,22,255,199.0,68,36,
- 12,237,199.0,68,36,8,237,199.0,68,36,4,237,137,60,36,232,251,1,12,255,199.0,
- 68,36,4,237,137,60,36,232,251,1,14,255,15.0,182,192,255,15.0,190,192,255,
- 15.0,183,192,255,15.0,191,192,255,199.0,68,36,4,237,137,60,36,232,251,1,14,
- 131.0,252,248,0,15.0,149.0,208,15.0,182,192,255,199.0,68,36,4,237,137,60,
- 36,232,251,1,13,255,199.0,68,36,4,237,137,60,36,232,251,1,17,255,199.0,68,
- 36,4,237,137,60,36,232,251,1,15,255,199.0,68,36,4,237,137,60,36,232,251,1,
- 16,255,199.0,68,36,4,237,137,60,36,232,251,1,18,255,199.0,68,36,4,237,137,
- 60,36,232,251,1,20,255,252,243.0,15.0,126,193,255,141,132,253,36,233,131.0,
- 252,236,4,199.0,68,36,8,237,137,124,36,4,137,4,36,232,251,1,20,255,199.0,
- 68,36,4,237,137,60,36,232,251,1,19,255,199.0,68,36,4,237,137,60,36,232,251,
- 1,19,137,4,36,217.0,4,36,255,137,20,36,217.0,4,36,255,137,224,129.0,192,239,
- 137,68,36,12,137,116,36,8,199.0,68,36,4,237,137,60,36,232,251,1,23,255,185,
- 237,139,1,137,4,36,232,251,1,24,255,131.0,196,28,255,139,148,253,36,233,255,
- 139,12,36,255,129.0,196,239,255,232,251,1,25,131.0,252,236,48,255,137,68,
- 36,32,232,251,1,0,185,237,137,1,199.0,68,36,8,237,199.0,68,36,4,237,137,60,
- 36,232,251,1,7,139,76,36,32,137,8,252,233,244,10,255,137,84,36,36,137,68,
- 36,32,232,251,1,0,185,237,137,1,199.0,68,36,8,237,199.0,68,36,4,0,0.0,0.0,
- 0.0,137,60,36,232,251,1,7,139,76,36,36,139,84,36,32,137,72,4,137,16,252,233,
- 244,10,255,137,68,36,32,137,84,36,36,232,251,1,0,185,237,137,1,199.0,68,36,
- 8,237,199.0,68,36,4,0,0.0,0.0,0.0,137,60,36,232,251,1,7,139,76,36,32,137,
- 8,139,76,36,36,137,72,4,252,233,244,10,255,131.0,252,236,4,232,251,1,0,185,
- 237,137,1,252,233,244,10,255,252,233,244,11,255,252,233,244,13,255,252,233,
- 244,14,255,252,233,244,15,255,252,233,244,12,255
+static const unsigned char build_actionlist[1800] = {
+ 248,10,184,1,0,0,0,139,117,252,248,139,125,252,252,137,252,236,93,195,255,
+ 248,11,232,251,1,0,185,237,137,1,184,0,0,0,0,139,117,252,248,139,125,252,
+ 252,137,252,236,93,195,255,248,12,221,92,36,4,232,251,1,0,185,237,137,1,137,
+ 60,36,232,251,1,1,252,233,244,10,255,248,13,15,182,192,137,68,36,32,232,251,
+ 1,0,185,237,137,1,139,68,36,32,137,68,36,4,137,60,36,232,251,1,2,252,233,
+ 244,10,255,248,14,137,68,36,32,232,251,1,0,185,237,137,1,139,68,36,32,137,
+ 68,36,4,137,60,36,232,251,1,3,252,233,244,10,255,248,15,137,68,36,32,232,
+ 251,1,0,185,237,137,1,139,68,36,32,137,68,36,4,137,60,36,232,251,1,4,252,
+ 233,244,10,255,248,16,102,184,0,0,199,68,36,4,237,137,60,36,232,251,1,5,255,
+ 248,17,102,184,0,0,199,68,36,4,237,137,60,36,232,251,1,5,255,248,18,137,77,
+ 252,248,137,85,252,244,195,255,139,141,233,255,139,141,233,139,149,233,255,
+ 137,132,253,36,233,255,137,132,253,36,233,137,148,253,36,233,255,221,133,
+ 233,255,217,133,233,255,252,243,15,126,133,233,255,252,243,15,90,133,233,
+ 255,221,156,253,36,233,255,217,156,253,36,233,255,102,15,214,132,253,36,233,
+ 255,252,242,15,90,192,102,15,214,132,253,36,233,255,252,242,15,90,192,102,
+ 15,126,132,253,36,233,255,85,137,229,87,129,252,236,239,255,232,244,18,255,
+ 191,237,255,199,68,36,8,237,199,68,36,4,237,137,60,36,232,251,1,6,255,199,
+ 68,36,8,237,199,68,36,4,252,255,252,255,252,255,252,255,137,60,36,232,251,
+ 1,6,255,199,68,36,8,237,199,68,36,4,237,137,60,36,232,251,1,6,199,68,36,8,
+ 237,199,68,36,4,252,255,252,255,252,255,252,255,137,60,36,232,251,1,7,255,
+ 137,8,199,68,36,4,252,254,252,255,252,255,252,255,137,60,36,232,251,1,8,255,
+ 199,68,36,8,237,199,68,36,4,0,0,0,0,137,60,36,232,251,1,7,255,137,8,137,80,
+ 4,255,137,8,255,102,15,214,0,255,217,24,255,217,88,4,255,221,24,255,221,88,
+ 8,255,221,92,36,4,137,60,36,232,251,1,1,255,15,182,201,137,76,36,4,137,60,
+ 36,232,251,1,2,255,15,182,201,255,15,190,201,255,137,76,36,4,137,60,36,232,
+ 251,1,3,255,15,183,201,255,15,191,201,255,137,76,36,4,137,60,36,232,251,1,
+ 4,255,199,68,36,12,0,0,0,0,199,68,36,8,237,199,68,36,4,237,137,60,36,232,
+ 251,1,9,255,199,68,36,8,237,199,68,36,4,252,254,252,255,252,255,252,255,137,
+ 60,36,232,251,1,6,199,68,36,12,237,199,68,36,8,252,255,252,255,252,255,252,
+ 255,199,68,36,4,252,254,252,255,252,255,252,255,137,60,36,232,251,1,10,137,
+ 68,36,32,199,68,36,4,252,252,252,255,252,255,252,255,137,60,36,232,251,1,
+ 11,139,68,36,32,255,199,68,36,8,237,199,68,36,4,252,254,252,255,252,255,252,
+ 255,137,60,36,232,251,1,6,199,68,36,12,237,199,68,36,8,252,255,252,255,252,
+ 255,252,255,199,68,36,4,252,254,252,255,252,255,252,255,137,60,36,232,251,
+ 1,12,137,68,36,32,199,68,36,4,252,252,252,255,252,255,252,255,137,60,36,232,
+ 251,1,11,139,68,36,32,255,199,68,36,4,252,254,252,255,252,255,252,255,137,
+ 60,36,232,251,1,11,255,199,68,36,4,252,255,252,255,252,255,252,255,137,60,
+ 36,232,251,1,13,255,199,68,36,4,252,255,252,255,252,255,252,255,137,60,36,
+ 232,251,1,14,255,137,68,36,32,199,68,36,4,252,253,252,255,252,255,252,255,
+ 137,60,36,232,251,1,11,139,68,36,32,255,199,68,36,4,252,255,252,255,252,255,
+ 252,255,137,60,36,232,251,1,15,255,199,68,36,4,252,255,252,255,252,255,252,
+ 255,137,60,36,232,251,1,16,255,137,68,36,32,137,84,36,36,199,68,36,4,252,
+ 253,252,255,252,255,252,255,137,60,36,232,251,1,11,139,68,36,32,139,84,36,
+ 36,255,199,68,36,4,252,255,252,255,252,255,252,255,137,60,36,232,251,1,17,
+ 137,68,36,32,199,68,36,4,252,253,252,255,252,255,252,255,137,60,36,232,251,
+ 1,11,139,68,36,32,255,199,68,36,4,252,255,252,255,252,255,252,255,137,60,
+ 36,232,251,1,18,255,221,92,36,32,199,68,36,4,252,253,252,255,252,255,252,
+ 255,137,60,36,232,251,1,11,221,68,36,32,255,199,68,36,4,252,255,252,255,252,
+ 255,252,255,137,60,36,232,251,1,19,137,68,36,32,137,84,36,36,199,68,36,4,
+ 252,253,252,255,252,255,252,255,137,60,36,232,251,1,11,139,68,36,32,139,84,
+ 36,36,255,199,68,36,4,252,255,252,255,252,255,252,255,137,60,36,232,251,1,
+ 20,102,15,214,68,36,32,102,15,214,76,36,40,199,68,36,4,252,253,252,255,252,
+ 255,252,255,137,60,36,232,251,1,11,252,243,15,126,68,36,32,252,243,15,126,
+ 76,36,40,255,139,141,233,199,68,36,8,252,255,252,255,252,255,252,255,137,
+ 124,36,4,137,12,36,232,251,1,20,131,252,236,4,199,68,36,4,252,253,252,255,
+ 252,255,252,255,137,60,36,232,251,1,11,255,139,125,252,252,137,252,236,93,
+ 194,236,255,85,137,229,87,86,139,189,233,131,252,236,16,137,60,36,232,251,
+ 1,21,137,198,129,252,248,239,15,140,244,16,255,15,143,244,17,255,193,224,
+ 4,41,196,129,252,236,239,255,199,68,36,8,237,199,68,36,4,0,0,0,0,137,60,36,
+ 232,251,1,7,131,252,236,16,255,199,68,36,12,237,199,68,36,8,237,199,68,36,
+ 4,237,137,60,36,232,251,1,10,255,199,68,36,12,237,199,68,36,8,237,199,68,
+ 36,4,237,137,60,36,232,251,1,22,255,199,68,36,12,237,199,68,36,8,237,199,
+ 68,36,4,237,137,60,36,232,251,1,12,255,199,68,36,4,237,137,60,36,232,251,
+ 1,14,255,15,182,192,255,15,190,192,255,15,183,192,255,15,191,192,255,199,
+ 68,36,4,237,137,60,36,232,251,1,14,131,252,248,0,15,149,208,15,182,192,255,
+ 199,68,36,4,237,137,60,36,232,251,1,13,255,199,68,36,4,237,137,60,36,232,
+ 251,1,17,255,199,68,36,4,237,137,60,36,232,251,1,15,255,199,68,36,4,237,137,
+ 60,36,232,251,1,16,255,199,68,36,4,237,137,60,36,232,251,1,18,255,199,68,
+ 36,4,237,137,60,36,232,251,1,20,255,252,243,15,126,193,255,141,132,253,36,
+ 233,131,252,236,4,199,68,36,8,237,137,124,36,4,137,4,36,232,251,1,20,255,
+ 199,68,36,4,237,137,60,36,232,251,1,19,255,199,68,36,4,237,137,60,36,232,
+ 251,1,19,137,4,36,217,4,36,255,137,20,36,217,4,36,255,137,224,129,192,239,
+ 137,68,36,12,137,116,36,8,199,68,36,4,237,137,60,36,232,251,1,23,255,185,
+ 237,139,1,137,4,36,232,251,1,24,255,131,196,32,255,139,148,253,36,233,255,
+ 139,12,36,255,129,196,239,255,232,251,1,25,131,252,236,48,255,137,68,36,32,
+ 232,251,1,0,185,237,137,1,199,68,36,8,237,199,68,36,4,237,137,60,36,232,251,
+ 1,7,139,76,36,32,137,8,252,233,244,10,255,137,84,36,36,137,68,36,32,232,251,
+ 1,0,185,237,137,1,199,68,36,8,237,199,68,36,4,0,0,0,0,137,60,36,232,251,1,
+ 7,139,76,36,36,139,84,36,32,137,72,4,137,16,252,233,244,10,255,137,68,36,
+ 32,137,84,36,36,232,251,1,0,185,237,137,1,199,68,36,8,237,199,68,36,4,237,
+ 137,60,36,232,251,1,7,139,76,36,32,137,8,139,76,36,36,137,72,4,252,233,244,
+ 10,255,131,252,236,4,232,251,1,0,185,237,137,1,252,233,244,10,255,252,233,
+ 244,11,255,252,233,244,13,255,252,233,244,14,255,252,233,244,15,255,252,233,
+ 244,12,255
};
static const char *const globnames[] = {
@@ -246,7 +245,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
lua_rawgeti(L, usr, (int) i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
ret += sizeof(void*);
} else {
switch (mt->type) {
@@ -284,7 +283,7 @@ int x86_return_size(lua_State* L, int usr, const struct ctype* ct)
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
ret += sizeof(void*);
}
lua_pop(L, 1);
@@ -380,13 +379,19 @@ static void add_int(Dst_DECL, const struct ctype* ct, struct reg_alloc* reg, int
reg->ints++;
}
#endif
-
- else if (is_int64) {
- dasm_put(Dst, 248, reg->off, reg->off + 4);
- reg->off += 8;
- } else {
- dasm_put(Dst, 242, reg->off);
- reg->off += 4;
+ else {
+#if defined _WIN64 || defined __amd64__
+ if (reg->off % 8 != 0) {
+ reg->off += 8 - (reg->off % 8);
+ }
+#endif
+ if (is_int64) {
+ dasm_put(Dst, 248, reg->off, reg->off + 4);
+ reg->off += 8;
+ } else {
+ dasm_put(Dst, 242, reg->off);
+ reg->off += 4;
+ }
}
}
@@ -541,7 +546,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
#if !defined _WIN64 && !defined __amd64__
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (!mt->pointers && mt->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mt->pointers && !mt->is_reference && mt->type == COMPLEX_DOUBLE_TYPE) {
hidden_arg_off = reg.off;
reg.off += sizeof(void*);
}
@@ -554,7 +559,7 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, i);
mt = (const struct ctype*) lua_touserdata(L, -1);
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -667,12 +672,12 @@ cfunction compile_callback(lua_State* L, int fidx, int ct_usr, const struct ctyp
lua_rawgeti(L, ct_usr, 0);
mt = (const struct ctype*) lua_touserdata(L, -1);
- dasm_put(Dst, 566, (mt->pointers || mt->type != VOID_TYPE) ? 1 : 0, nargs);
+ dasm_put(Dst, 566, (mt->pointers || mt->is_reference || mt->type != VOID_TYPE) ? 1 : 0, nargs);
// Unpack the return argument if not "void", also clean-up the lua stack
// to remove the return argument and bind table. Use lua_settop rather
// than lua_pop as lua_pop is implemented as a macro.
- if (mt->pointers) {
+ if (mt->pointers || mt->is_reference) {
lua_getuservalue(L, -1);
lua_rawseti(L, -3, ++num_upvals); /* usr value */
lua_rawseti(L, -2, ++num_upvals); /* mt */
@@ -820,7 +825,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
* data is stored, which is popped by the calling code. */
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (!mbr_ct->pointers && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
+ if (!mbr_ct->pointers && !mbr_ct->is_reference && mbr_ct->type == COMPLEX_DOUBLE_TYPE) {
/* we can allocate more space for arguments as long as no add_*
* function has been called yet, mbr_ct will be added as an upvalue in
* the return processing later */
@@ -834,7 +839,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, (int) i);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers) {
+ if (mbr_ct->pointers || mbr_ct->is_reference) {
lua_getuservalue(L, -1);
num_upvals += 2;
dasm_put(Dst, 1278, mbr_ct, lua_upvalueindex(num_upvals), i);
@@ -1077,7 +1082,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
lua_rawgeti(L, ct_usr, 0);
mbr_ct = (const struct ctype*) lua_touserdata(L, -1);
- if (mbr_ct->pointers || mbr_ct->type == INTPTR_TYPE) {
+ if (mbr_ct->pointers || mbr_ct->is_reference || mbr_ct->type == INTPTR_TYPE) {
lua_getuservalue(L, -1);
num_upvals += 2;
dasm_put(Dst, 1613, perr, mbr_ct, lua_upvalueindex(num_upvals));
@@ -1096,23 +1101,25 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
break;
case COMPLEX_FLOAT_TYPE:
- num_upvals++;
- dasm_put(Dst, 1707, perr, mbr_ct);
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1707, perr, mbr_ct, lua_upvalueindex(num_upvals));
break;
case COMPLEX_DOUBLE_TYPE:
- num_upvals++;
- dasm_put(Dst, 1761, perr);
+ lua_getuservalue(L, -1);
+ num_upvals += 2;
+ dasm_put(Dst, 1758, perr);
break;
case VOID_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1778);
+ dasm_put(Dst, 1775);
break;
case BOOL_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1783);
+ dasm_put(Dst, 1780);
break;
case INT8_TYPE:
@@ -1122,7 +1129,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1364);
}
- dasm_put(Dst, 1788);
+ dasm_put(Dst, 1785);
break;
case INT16_TYPE:
@@ -1132,27 +1139,27 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
} else {
dasm_put(Dst, 1372);
}
- dasm_put(Dst, 1788);
+ dasm_put(Dst, 1785);
break;
case INT32_TYPE:
case ENUM_TYPE:
lua_pop(L, 1);
if (mbr_ct->is_unsigned) {
- dasm_put(Dst, 1793);
+ dasm_put(Dst, 1790);
} else {
- dasm_put(Dst, 1788);
+ dasm_put(Dst, 1785);
}
break;
case FLOAT_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1798);
+ dasm_put(Dst, 1795);
break;
case DOUBLE_TYPE:
lua_pop(L, 1);
- dasm_put(Dst, 1798);
+ dasm_put(Dst, 1795);
break;
default:
@@ -1165,7 +1172,7 @@ void compile_function(lua_State* L, cfunction func, int ct_usr, const struct cty
cfunction f = compile(Dst, L, func, LUA_NOREF);
/* add a callback as an upval so that the jitted code gets cleaned up when
* the function gets gc'd */
- push_callback(L, f);
+ push_callback(L, f, func);
lua_pushcclosure(L, (lua_CFunction) f, num_upvals+1);
}
}
diff --git a/plugins/MirLua/Modules/luaffi/src/ctype.c b/plugins/MirLua/Modules/ffi/src/ctype.c
index b15d600e62..6208937536 100644
--- a/plugins/MirLua/Modules/luaffi/src/ctype.c
+++ b/plugins/MirLua/Modules/ffi/src/ctype.c
@@ -1,5 +1,10 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
#include "ffi.h"
@@ -177,10 +182,11 @@ void* push_cdata(lua_State* L, int ct_usr, const struct ctype* ct)
return cd+1;
}
-void push_callback(lua_State* L, cfunction f)
+void push_callback(lua_State* L, cfunction luafunc, cfunction cfunc)
{
- cfunction* pf = (cfunction*) lua_newuserdata(L, sizeof(cfunction));
- *pf = f;
+ cfunction* pf = (cfunction*) lua_newuserdata(L, 2 * sizeof(cfunction));
+ pf[0] = luafunc;
+ pf[1] = cfunc;
push_upval(L, &callback_mt_key);
lua_setmetatable(L, -2);
@@ -219,14 +225,13 @@ err:
}
/* to_cdata returns the struct cdata* and pushes the user value onto the
- * stack. If the index is not a ctype then ct is not touched, a nil is pushed,
- * NULL is returned, and ct->type is set to INVALID_TYPE. Also dereferences
- * references */
+ * stack. If the index is not a ctype then ct is set to the zero value such
+ * that ct->type is INVALID_TYPE, a nil is pushed, and NULL is returned. */
void* to_cdata(lua_State* L, int idx, struct ctype* ct)
{
struct cdata* cd;
- ct->type = INVALID_TYPE;
+ memset(ct, 0, sizeof(struct ctype));
if (!lua_isuserdata(L, idx) || !lua_getmetatable(L, idx)) {
lua_pushnil(L);
return NULL;
@@ -244,7 +249,6 @@ void* to_cdata(lua_State* L, int idx, struct ctype* ct)
lua_getuservalue(L, idx);
if (ct->is_reference) {
- ct->is_reference = 0;
return *(void**) (cd+1);
} else if (ct->pointers && !ct->is_array) {
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_arm.h b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_arm.h
index da88199284..da88199284 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_arm.h
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_arm.h
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_arm.lua b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_arm.lua
index 03d3d1ad67..03d3d1ad67 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_arm.lua
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_arm.lua
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_ppc.h b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_ppc.h
index 74e1c7d432..74e1c7d432 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_ppc.h
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_ppc.h
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_ppc.lua b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_ppc.lua
index aeaaa2a7b6..aeaaa2a7b6 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_ppc.lua
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_ppc.lua
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_proto.h b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_proto.h
index 94a79a163d..94a79a163d 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_proto.h
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_proto.h
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x64.lua b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_x64.lua
index 36b7e5bd93..36b7e5bd93 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x64.lua
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_x64.lua
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x86.h b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_x86.h
index 83c6eb5a0f..83c6eb5a0f 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x86.h
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_x86.h
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x86.lua b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_x86.lua
index efaa290441..efaa290441 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dasm_x86.lua
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dasm_x86.lua
diff --git a/plugins/MirLua/Modules/luaffi/src/dynasm/dynasm.lua b/plugins/MirLua/Modules/ffi/src/dynasm/dynasm.lua
index 8226dccd5d..8226dccd5d 100644
--- a/plugins/MirLua/Modules/luaffi/src/dynasm/dynasm.lua
+++ b/plugins/MirLua/Modules/ffi/src/dynasm/dynasm.lua
diff --git a/plugins/MirLua/Modules/luaffi/src/ffi.c b/plugins/MirLua/Modules/ffi/src/ffi.c
index d3f7b67cd3..a487c53296 100644
--- a/plugins/MirLua/Modules/luaffi/src/ffi.c
+++ b/plugins/MirLua/Modules/ffi/src/ffi.c
@@ -1,5 +1,10 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
#include "ffi.h"
#include <math.h>
@@ -94,6 +99,57 @@ static int type_error(lua_State* L, int idx, const char* to_type, int to_usr, co
return lua_error(L);
}
+static void* userdata_toptr(lua_State* L, int idx)
+{
+ void* ptr = lua_touserdata(L, idx);
+
+ // check for FILE*
+ lua_getmetatable(L, idx);
+ luaL_getmetatable(L, LUA_FILEHANDLE);
+ int isfile = lua_rawequal(L, -1, -2);
+ lua_pop(L, 2);
+
+ if (isfile) {
+#if LUA_VERSION_NUM == 501
+ FILE** stream = (FILE**) ptr;
+ return *stream;
+#else
+ luaL_Stream* stream = (luaL_Stream*) ptr;
+ return stream->f;
+#endif
+ }
+
+ return ptr;
+}
+
+static int cdata_tointeger(lua_State* L, int idx, ptrdiff_t* val)
+{
+ struct ctype ct;
+ void* addr = to_cdata(L, idx, &ct);
+ lua_pop(L, 1);
+
+ if (ct.pointers) {
+ return 0;
+ }
+
+ switch (ct.type) {
+ case INT8_TYPE:
+ *val = *(int8_t*)addr;
+ return 1;
+ case INT16_TYPE:
+ *val = *(int16_t*)addr;
+ return 1;
+ case INT32_TYPE:
+ *val = *(int32_t*)addr;
+ return 1;
+ case INT64_TYPE:
+ *val = *(int64_t*)addr;
+ return 1;
+ default:
+ return 0;
+ }
+}
+
static int64_t check_intptr(lua_State* L, int idx, void* p, struct ctype* ct)
{
if (ct->type == INVALID_TYPE) {
@@ -132,32 +188,45 @@ static int64_t check_intptr(lua_State* L, int idx, void* p, struct ctype* ct)
}
}
+static int get_cfunction_address(lua_State* L, int idx, cfunction* addr);
+
#define TO_NUMBER(TYPE, ALLOW_POINTERS) \
- TYPE real = 0, imag = 0; \
+ TYPE ret = 0; \
void* p; \
struct ctype ct; \
+ cfunction f; \
\
switch (lua_type(L, idx)) { \
case LUA_TBOOLEAN: \
- real = (TYPE) lua_toboolean(L, idx); \
+ ret = (TYPE) lua_toboolean(L, idx); \
break; \
\
case LUA_TNUMBER: \
- real = (TYPE) lua_tonumber(L, idx); \
+ ret = (TYPE) lua_tonumber(L, idx); \
break; \
\
case LUA_TSTRING: \
if (!ALLOW_POINTERS) { \
type_error(L, idx, #TYPE, 0, NULL); \
} \
- real = (TYPE) (intptr_t) lua_tostring(L, idx); \
+ ret = (TYPE) (intptr_t) lua_tostring(L, idx); \
break; \
\
case LUA_TLIGHTUSERDATA: \
if (!ALLOW_POINTERS) { \
type_error(L, idx, #TYPE, 0, NULL); \
} \
- real = (TYPE) (intptr_t) lua_topointer(L, idx); \
+ ret = (TYPE) (intptr_t) lua_topointer(L, idx); \
+ break; \
+ \
+ case LUA_TFUNCTION: \
+ if (!ALLOW_POINTERS) { \
+ type_error(L, idx, #TYPE, 0, NULL); \
+ } \
+ if (!get_cfunction_address(L, idx, &f)) { \
+ type_error(L, idx, #TYPE, 0, NULL); \
+ } \
+ ret = (TYPE) (intptr_t) f; \
break; \
\
case LUA_TUSERDATA: \
@@ -167,30 +236,28 @@ static int64_t check_intptr(lua_State* L, int idx, void* p, struct ctype* ct)
if (!ALLOW_POINTERS) { \
type_error(L, idx, #TYPE, 0, NULL); \
} \
- real = (TYPE) (intptr_t) p; \
+ ret = (TYPE) (intptr_t) userdata_toptr(L, idx); \
} else if (ct.pointers || ct.type == STRUCT_TYPE || ct.type == UNION_TYPE) {\
if (!ALLOW_POINTERS) { \
type_error(L, idx, #TYPE, 0, NULL); \
} \
- real = (TYPE) (intptr_t) p; \
+ ret = (TYPE) (intptr_t) p; \
} else if (ct.type == COMPLEX_DOUBLE_TYPE) { \
- real = (TYPE) creal(*(complex_double*) p); \
- imag = (TYPE) cimag(*(complex_double*) p); \
+ ret = (TYPE) creal(*(complex_double*) p); \
} else if (ct.type == COMPLEX_FLOAT_TYPE) { \
- real = (TYPE) crealf(*(complex_float*) p); \
- imag = (TYPE) cimagf(*(complex_float*) p); \
+ ret = (TYPE) crealf(*(complex_float*) p); \
} else if (ct.type == DOUBLE_TYPE) { \
- real = (TYPE) *(double*) p; \
+ ret = (TYPE) *(double*) p; \
} else if (ct.type == FLOAT_TYPE) { \
- real = (TYPE) *(float*) p; \
+ ret = (TYPE) *(float*) p; \
} else { \
- real = check_intptr(L, idx, p, &ct); \
+ ret = check_intptr(L, idx, p, &ct); \
} \
lua_pop(L, 1); \
break; \
\
case LUA_TNIL: \
- real = (TYPE) 0; \
+ ret = (TYPE) 0; \
break; \
\
default: \
@@ -198,10 +265,10 @@ static int64_t check_intptr(lua_State* L, int idx, void* p, struct ctype* ct)
} \
static int64_t cast_int64(lua_State* L, int idx, int is_cast)
-{ TO_NUMBER(int64_t, is_cast); (void) imag; return real; }
+{ TO_NUMBER(int64_t, is_cast); return ret; }
static uint64_t cast_uint64(lua_State* L, int idx, int is_cast)
-{ TO_NUMBER(uint64_t, is_cast); (void) imag; return real; }
+{ TO_NUMBER(uint64_t, is_cast); return ret; }
int32_t check_int32(lua_State* L, int idx)
{ return (int32_t) cast_int64(L, idx, 0); }
@@ -215,47 +282,68 @@ int64_t check_int64(lua_State* L, int idx)
uint64_t check_uint64(lua_State* L, int idx)
{ return cast_uint64(L, idx, 0); }
-static void do_check_double(lua_State* L, int idx, double* preal, double* pimag)
-{
- TO_NUMBER(double, 0);
- if (preal) *preal = real;
- if (pimag) *pimag = imag;
-}
-
double check_double(lua_State* L, int idx)
-{ double ret; do_check_double(L, idx, &ret, NULL); return ret; }
+{ TO_NUMBER(double, 0); return ret; }
float check_float(lua_State* L, int idx)
-{ double ret; do_check_double(L, idx, &ret, NULL); return ret; }
+{ TO_NUMBER(double, 0); return ret; }
uintptr_t check_uintptr(lua_State* L, int idx)
-{ TO_NUMBER(uintptr_t, 1); (void) imag; return real; }
+{ TO_NUMBER(uintptr_t, 1); return ret; }
-#ifdef HAVE_COMPLEX
complex_double check_complex_double(lua_State* L, int idx)
-{ double real, imag; do_check_double(L, idx, &real, &imag); return real + imag * 1i; }
+{
+ double real = 0, imag = 0;
+ void* p;
+ struct ctype ct;
-complex_float check_complex_float(lua_State* L, int idx)
-{ double real, imag; do_check_double(L, idx, &real, &imag); return real + imag * 1i; }
+ switch (lua_type(L, idx)) {
+ case LUA_TNUMBER:
+ real = (double) lua_tonumber(L, idx);
+ break;
+ case LUA_TTABLE:
+ lua_rawgeti(L, idx, 1);
+ real = check_double(L, -1);
+ lua_pop(L, 1);
-#else
-complex_double check_complex_double(lua_State* L, int idx)
-{
- complex_double c;
- do_check_double(L, idx, &c.real, &c.imag);
- return c;
+ lua_rawgeti(L, idx, 2);
+ if (lua_isnil(L, -1)) {
+ imag = real;
+ } else {
+ imag = check_double(L, -1);
+ }
+ lua_pop(L, 1);
+ break;
+ case LUA_TUSERDATA:
+ p = to_cdata(L, idx, &ct);
+ if (ct.type == COMPLEX_DOUBLE_TYPE) {
+ real = creal(*(complex_double*) p);
+ imag = cimag(*(complex_double*) p);
+ } else if (ct.type == COMPLEX_FLOAT_TYPE) {
+ real = crealf(*(complex_float*) p);
+ imag = cimagf(*(complex_float*) p);
+ } else if (ct.type == DOUBLE_TYPE) {
+ real = *(double*) p;
+ } else if (ct.type == FLOAT_TYPE) {
+ real = *(float*) p;
+ } else {
+ real = check_intptr(L, idx, p, &ct);
+ }
+ lua_pop(L, 1);
+ break;
+
+ default:
+ type_error(L, idx, "complex", 0, NULL);
+ }
+
+ return mk_complex_double(real, imag);
}
complex_float check_complex_float(lua_State* L, int idx)
{
- complex_double d;
- complex_float f;
- do_check_double(L, idx, &d.real, &d.imag);
- f.real = d.real;
- f.imag = d.imag;
- return f;
+ complex_double d = check_complex_double(L, idx);
+ return mk_complex_float(creal(d), cimag(d));
}
-#endif
static size_t unpack_vararg(lua_State* L, int i, char* to)
{
@@ -281,15 +369,13 @@ static size_t unpack_vararg(lua_State* L, int i, char* to)
case LUA_TUSERDATA:
p = to_cdata(L, i, &ct);
+ lua_pop(L, 1);
if (ct.type == INVALID_TYPE) {
- *(void**) to = p;
+ *(void**) to = userdata_toptr(L, i);
return sizeof(void*);
- }
- lua_pop(L, 1);
-
- if (ct.pointers || ct.type == INTPTR_TYPE) {
+ } else if (ct.pointers || ct.type == INTPTR_TYPE) {
*(void**) to = p;
return sizeof(void*);
@@ -425,12 +511,12 @@ static void* check_pointer(lua_State* L, int idx, struct ctype* ct)
{
void* p;
memset(ct, 0, sizeof(*ct));
- ct->pointers = 1;
idx = lua_absindex(L, idx);
switch (lua_type(L, idx)) {
case LUA_TNIL:
ct->type = VOID_TYPE;
+ ct->pointers = 1;
ct->is_null = 1;
lua_pushnil(L);
return NULL;
@@ -444,11 +530,13 @@ static void* check_pointer(lua_State* L, int idx, struct ctype* ct)
case LUA_TLIGHTUSERDATA:
ct->type = VOID_TYPE;
+ ct->pointers = 1;
lua_pushnil(L);
return lua_touserdata(L, idx);
case LUA_TSTRING:
ct->type = INT8_TYPE;
+ ct->pointers = 1;
ct->is_unsigned = IS_CHAR_UNSIGNED;
ct->is_array = 1;
ct->base_size = 1;
@@ -462,7 +550,8 @@ static void* check_pointer(lua_State* L, int idx, struct ctype* ct)
if (ct->type == INVALID_TYPE) {
/* some other type of user data */
ct->type = VOID_TYPE;
- return lua_touserdata(L, idx);
+ ct->pointers = 1;
+ return userdata_toptr(L, idx);
} else if (ct->type == STRUCT_TYPE || ct->type == UNION_TYPE) {
return p;
} else {
@@ -542,6 +631,10 @@ void* check_typed_pointer(lua_State* L, int idx, int to_usr, const struct ctype*
/* any pointer can convert to void* */
goto suc;
+ } else if (is_void_ptr(&ft) && (ft.pointers || ft.is_reference)) {
+ /* void* can convert to any pointer */
+ goto suc;
+
} else if (ft.is_null) {
/* NULL can convert to any pointer */
goto suc;
@@ -568,6 +661,48 @@ err:
return NULL;
}
+/**
+ * gets the address of the wrapped C function for the lua function value at idx
+ * and returns 1 if it exists; otherwise returns 0 and nothing is pushed */
+static int get_cfunction_address(lua_State* L, int idx, cfunction* addr)
+{
+ if (!lua_isfunction(L, idx)) return 0;
+
+ int top = lua_gettop(L);
+
+ // Get the last upvalue
+ int n = 2;
+ while (lua_getupvalue(L, idx, n)) {
+ lua_pop(L, 1);
+ n++;
+ }
+
+ if (!lua_getupvalue(L, idx, n - 1))
+ return 0;
+
+ if (!lua_isuserdata(L, -1) || !lua_getmetatable(L, -1)) {
+ lua_pop(L, 1);
+ return 0;
+ }
+
+ push_upval(L, &callback_mt_key);
+ if (!lua_rawequal(L, -1, -2)) {
+ lua_pop(L, 3);
+ return 0;
+ }
+
+ /* stack is:
+ * userdata upval
+ * metatable
+ * callback_mt
+ */
+
+ cfunction* f = lua_touserdata(L, -3);
+ *addr = f[1];
+ lua_pop(L, 3);
+ return 1;
+}
+
/* to_cfunction converts a value at idx with usr table at to_usr and type tt
* into a function. Leaves the stack unchanged. */
static cfunction check_cfunction(lua_State* L, int idx, int to_usr, const struct ctype* tt, int check_pointers)
@@ -582,6 +717,10 @@ static cfunction check_cfunction(lua_State* L, int idx, int to_usr, const struct
switch (lua_type(L, idx)) {
case LUA_TFUNCTION:
+ if (get_cfunction_address(L, idx, &f)) {
+ return f;
+ }
+
/* Function cdatas are pinned and must be manually cleaned up by
* calling func:free(). */
push_upval(L, &callbacks_key);
@@ -828,7 +967,7 @@ static void set_struct(lua_State* L, int idx, void* to, int to_usr, const struct
sz = lua_rawlen(L, to_usr);
for (i = 2; i < sz; i++) {
- lua_pushnumber(L, i);
+ lua_pushinteger(L, i);
off = get_member(L, to_usr, tt, &mt);
assert(off >= 0);
set_value(L, -2, (char*) to + off, -1, &mt, check_pointers);
@@ -867,7 +1006,7 @@ static void set_value(lua_State* L, int idx, void* to, int to_usr, const struct
if (tt->is_array) {
set_array(L, idx, to, to_usr, tt, check_pointers);
- } else if (tt->pointers) {
+ } else if (tt->pointers || tt->is_reference) {
union {
uint8_t c[sizeof(void*)];
void* p;
@@ -1033,13 +1172,38 @@ static void get_variable_array_size(lua_State* L, int idx, struct ctype* ct)
}
}
-static int try_set_value(lua_State* L)
+static int is_scalar(struct ctype* ct)
{
- void* p = lua_touserdata(L, 2);
- struct ctype* ct = (struct ctype*) lua_touserdata(L, 4);
- int check_ptrs = lua_toboolean(L, 5);
- set_value(L, 1, p, 3, ct, check_ptrs);
- return 0;
+ int type = ct->type;
+ if (ct->pointers || ct->is_reference) {
+ return !ct->is_array;
+ }
+ return type != STRUCT_TYPE && type != UNION_TYPE && !IS_COMPLEX(type);
+}
+
+static int should_pack(lua_State *L, int ct_usr, struct ctype* ct, int idx)
+{
+ struct ctype argt;
+ ct_usr = lua_absindex(L, ct_usr);
+
+ if (IS_COMPLEX(ct->type)) {
+ return 0;
+ }
+
+ switch (lua_type(L, idx)) {
+ case LUA_TTABLE:
+ return 0;
+ case LUA_TSTRING:
+ return ct->type == STRUCT_TYPE;
+ case LUA_TUSERDATA:
+ // don't pack if the argument is a cdata with the same type
+ to_cdata(L, idx, &argt);
+ int same = is_same_type(L, ct_usr, -1, ct, &argt);
+ lua_pop(L, 1);
+ return !same;
+ default:
+ return 1;
+ }
}
static int do_new(lua_State* L, int is_cast)
@@ -1054,6 +1218,14 @@ static int do_new(lua_State* L, int is_cast)
/* don't push a callback when we have a c function, as cb:set needs a
* compiled callback from a lua function to work */
if (!ct.pointers && ct.type == FUNCTION_PTR_TYPE && (lua_isnil(L, 2) || lua_isfunction(L, 2))) {
+ // Get the bound C function if this is a ffi lua function
+ cfunction func;
+ if (get_cfunction_address(L, 2, &func)) {
+ p = push_cdata(L, -1, &ct);
+ *(cfunction*) p = func;
+ return 1;
+ }
+
/* Function cdatas are pinned and must be manually cleaned up by
* calling func:free(). */
compile_callback(L, 2, -1, &ct);
@@ -1098,37 +1270,24 @@ static int do_new(lua_State* L, int is_cast)
return 1;
}
- if (cargs == 1) {
- /* try packed form first
- * packed: ffi.new('int[3]', {1})
- * unpacked: ffi.new('int[3]', 1)
- */
- lua_pushcfunction(L, &try_set_value);
- lua_pushvalue(L, 2); /* ctor arg */
- lua_pushlightuserdata(L, p);
- lua_pushvalue(L, -5); /* ctype usr */
- lua_pushlightuserdata(L, &ct);
- lua_pushboolean(L, check_ptrs);
-
- if (!lua_pcall(L, 5, 0, 0)) {
- return 1;
- }
-
- /* remove any errors */
- lua_settop(L, 4);
+ int scalar = is_scalar(&ct);
+ if (scalar && cargs > 1) {
+ return luaL_error(L, "too many initializers");
}
- /* if we have more than 2 ctor arguments then they must be unpacked, e.g.
- * ffi.new('int[3]', 1, 2, 3) */
- lua_createtable(L, cargs, 0);
- lua_replace(L, 1);
- for (i = 1; i <= cargs; i++) {
- lua_pushvalue(L, i + 1);
- lua_rawseti(L, 1, i);
+ if (cargs > 1 || (!scalar && should_pack(L, -2, &ct, 2))) {
+ lua_createtable(L, cargs, 0);
+ lua_replace(L, 1);
+ for (i = 1; i <= cargs; i++) {
+ lua_pushvalue(L, i + 1);
+ lua_rawseti(L, 1, i);
+ }
+ assert(lua_gettop(L) == cargs + 3);
+ set_value(L, 1, p, -2, &ct, check_ptrs);
+ return 1;
}
- assert(lua_gettop(L) == cargs + 3);
- set_value(L, 1, p, -2, &ct, check_ptrs);
+ set_value(L, 2, p, -2, &ct, check_ptrs);
return 1;
}
@@ -1170,7 +1329,7 @@ static int ffi_sizeof(lua_State* L)
struct ctype ct;
check_ctype(L, 1, &ct);
get_variable_array_size(L, 2, &ct);
- lua_pushnumber(L, ctype_size(L, &ct));
+ lua_pushinteger(L, ctype_size(L, &ct));
return 1;
}
@@ -1182,7 +1341,7 @@ static int ffi_alignof(lua_State* L)
/* if no member is specified then we return the alignment of the type */
if (lua_isnil(L, 2)) {
- lua_pushnumber(L, ct.align_mask + 1);
+ lua_pushinteger(L, ct.align_mask + 1);
return 1;
}
@@ -1193,7 +1352,7 @@ static int ffi_alignof(lua_State* L)
return luaL_error(L, "type %s has no member %s", lua_tostring(L, -1), lua_tostring(L, 2));
}
- lua_pushnumber(L, mt.align_mask + 1);
+ lua_pushinteger(L, mt.align_mask + 1);
return 1;
}
@@ -1211,14 +1370,14 @@ static int ffi_offsetof(lua_State* L)
return luaL_error(L, "type %s has no member %s", lua_tostring(L, -1), lua_tostring(L, 2));
}
- lua_pushnumber(L, off);
+ lua_pushinteger(L, off);
if (!mt.is_bitfield) {
return 1;
}
- lua_pushnumber(L, mt.bit_offset);
- lua_pushnumber(L, mt.bit_size);
+ lua_pushinteger(L, mt.bit_offset);
+ lua_pushinteger(L, mt.bit_size);
return 3;
}
@@ -1285,7 +1444,8 @@ static int cdata_gc(lua_State* L)
static int callback_free(lua_State* L)
{
cfunction* p = (cfunction*) lua_touserdata(L, 1);
- free_code(get_jit(L), L, *p);
+ // FIXME: temporarily disabled to prevent SIGTRAP on exit
+ // free_code(get_jit(L), L, *p);
return 0;
}
@@ -1407,7 +1567,10 @@ static int ffi_metatype(lua_State* L)
* the stack, otherwise it returns 0 and pushes nothing */
int push_user_mt(lua_State* L, int ct_usr, const struct ctype* ct)
{
- if (ct->type != STRUCT_TYPE && ct->type != UNION_TYPE) {
+ if (ct->type != STRUCT_TYPE && ct->type != UNION_TYPE && !IS_COMPLEX(ct->type)) {
+ return 0;
+ }
+ if (!lua_istable(L, ct_usr)) {
return 0;
}
@@ -1447,22 +1610,34 @@ static ptrdiff_t lookup_cdata_index(lua_State* L, int idx, int ct_usr, struct ct
ptrdiff_t off;
ct_usr = lua_absindex(L, ct_usr);
+ int type = lua_type(L, idx);
- switch (lua_type(L, idx)) {
+ switch (type) {
case LUA_TNUMBER:
+ case LUA_TUSERDATA:
/* possibilities are array, pointer */
if (!ct->pointers || is_void_ptr(ct)) {
return -1;
}
+ // unbox cdata
+ if (type == LUA_TUSERDATA) {
+ if (!cdata_tointeger(L, idx, &off)) {
+ return -1;
+ }
+ } else {
+ off = lua_tointeger(L, idx);
+ }
+
ct->is_array = 0;
ct->pointers--;
ct->const_mask >>= 1;
+ ct->is_reference = 0;
lua_pushvalue(L, ct_usr);
- return (ct->pointers ? sizeof(void*) : ct->base_size) * lua_tonumber(L, 2);
+ return (ct->pointers ? sizeof(void*) : ct->base_size) * off;
case LUA_TSTRING:
/* possibilities are struct/union, pointer to struct/union */
@@ -1635,7 +1810,7 @@ err:
uint64_t val = *(uint64_t*) data;
val >>= ct.bit_offset;
val &= (UINT64_C(1) << ct.bit_size) - 1;
- lua_pushnumber(L, val);
+ lua_pushinteger(L, val);
return 1;
}
@@ -1689,14 +1864,14 @@ err:
lua_pushboolean(L, *(_Bool*) data);
break;
case INT8_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint8_t*) data : (lua_Number) *(int8_t*) data);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint8_t*) data : (lua_Integer) *(int8_t*) data);
break;
case INT16_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint16_t*) data : (lua_Number) *(int16_t*) data);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint16_t*) data : (lua_Integer) *(int16_t*) data);
break;
case ENUM_TYPE:
case INT32_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint32_t*) data : (lua_Number) *(int32_t*) data);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint32_t*) data : (lua_Integer) *(int32_t*) data);
break;
case INT64_TYPE:
to = push_cdata(L, -1, &ct);
@@ -1712,6 +1887,14 @@ err:
case DOUBLE_TYPE:
lua_pushnumber(L, *(double*) data);
break;
+ case COMPLEX_DOUBLE_TYPE:
+ to = push_cdata(L, -1, &ct);
+ *(complex_double*) to = *(complex_double*) data;
+ break;
+ case COMPLEX_FLOAT_TYPE:
+ to = push_cdata(L, -1, &ct);
+ *(complex_float*) to = *(complex_float*) data;
+ break;
default:
luaL_error(L, "internal error: invalid member type");
}
@@ -2333,7 +2516,7 @@ static int ctype_tostring(lua_State* L)
check_ctype(L, 1, &ct);
assert(lua_gettop(L) == 2);
push_type_name(L, -1, &ct);
- lua_pushfstring(L, "ctype<%s> %p", lua_tostring(L, -1), lua_topointer(L, 1));
+ lua_pushfstring(L, "ctype<%s>", lua_tostring(L, -1));
if (DEBUG_TOSTRING) {
print_type(L, &ct);
@@ -2358,7 +2541,7 @@ static int cdata_tostring(lua_State* L)
return ret;
}
- if (ct.pointers > 0 || ct.type == STRUCT_TYPE || ct.type == UNION_TYPE) {
+ if (ct.pointers > 0 || ct.is_reference || ct.type == STRUCT_TYPE || ct.type == UNION_TYPE) {
push_type_name(L, -1, &ct);
lua_pushfstring(L, "cdata<%s>: %p", lua_tostring(L, -1), p);
@@ -2374,22 +2557,14 @@ static int cdata_tostring(lua_State* L)
case COMPLEX_DOUBLE_TYPE:
{
complex_double c = *(complex_double*) p;
- if (cimag(c) != 0) {
- lua_pushfstring(L, "%f+%fi", creal(c), cimag(c));
- } else {
- lua_pushfstring(L, "%f", creal(c));
- }
+ lua_pushfstring(L, "%f+%fi", creal(c), cimag(c));
}
return 1;
case COMPLEX_FLOAT_TYPE:
{
complex_float c = *(complex_float*) p;
- if (cimagf(c) != 0) {
- lua_pushfstring(L, "%f+%fi", crealf(c), cimagf(c));
- } else {
- lua_pushfstring(L, "%f", crealf(c));
- }
+ lua_pushfstring(L, "%f+%fi", crealf(c), cimagf(c));
}
return 1;
@@ -2420,22 +2595,40 @@ static int ffi_errno(lua_State* L)
struct jit* jit = get_jit(L);
if (!lua_isnoneornil(L, 1)) {
- lua_pushnumber(L, jit->last_errno);
+ lua_pushinteger(L, jit->last_errno);
jit->last_errno = luaL_checknumber(L, 1);
} else {
- lua_pushnumber(L, jit->last_errno);
+ lua_pushinteger(L, jit->last_errno);
}
return 1;
}
+static int ffi_type(lua_State* L)
+{
+ if (lua_isuserdata(L, 1) && lua_getmetatable(L, 1)) {
+ if (equals_upval(L, -1, &cdata_mt_key) || equals_upval(L, -1, &ctype_mt_key)) {
+ lua_pushstring(L, "cdata");
+ return 1;
+ }
+ lua_pop(L, 1); /* mt */
+ }
+
+ /* call the old _G.type, we use an upvalue as _G.type is set
+ * to this function */
+ lua_pushvalue(L, lua_upvalueindex(1));
+ lua_insert(L, 1);
+ lua_call(L, lua_gettop(L)-1, LUA_MULTRET);
+ return lua_gettop(L);
+}
+
static int ffi_number(lua_State* L)
{
struct ctype ct;
void* data = to_cdata(L, 1, &ct);
if (ct.type != INVALID_TYPE) {
- lua_pushnumber(L, check_intptr(L, 1, data, &ct));
+ lua_pushinteger(L, check_intptr(L, 1, data, &ct));
return 1;
} else {
/* call the old _G.tonumber, we use an upvalue as _G.tonumber is set
@@ -2462,7 +2655,13 @@ static int ffi_string(lua_State* L)
} else if (ct.type == INT8_TYPE && ct.pointers == 1) {
size_t sz;
- if (!lua_isnil(L, 2)) {
+ if (lua_isuserdata(L, 2)) {
+ ptrdiff_t val;
+ if (!cdata_tointeger(L, 2, &val)) {
+ type_error(L, 2, "int", 0, NULL);
+ }
+ sz = (size_t) val;
+ } else if (!lua_isnil(L, 2)) {
sz = (size_t) luaL_checknumber(L, 2);
} else if (ct.is_array && !ct.is_variable_array) {
@@ -2743,16 +2942,16 @@ static int cmodule_index(lua_State* L)
return 1;
case INT8_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint8_t*) sym : (lua_Number) *(int8_t*) sym);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint8_t*) sym : (lua_Integer) *(int8_t*) sym);
return 1;
case INT16_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint16_t*) sym : (lua_Number) *(int16_t*) sym);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint16_t*) sym : (lua_Integer) *(int16_t*) sym);
return 1;
case INT32_TYPE:
case ENUM_TYPE:
- lua_pushnumber(L, ct.is_unsigned ? (lua_Number) *(uint32_t*) sym : (lua_Number) *(int32_t*) sym);
+ lua_pushinteger(L, ct.is_unsigned ? (lua_Integer) *(uint32_t*) sym : (lua_Integer) *(int32_t*) sym);
return 1;
}
@@ -2942,10 +3141,16 @@ static void push_builtin(lua_State* L, struct ctype* ct, const char* name, int t
ct->is_defined = 1;
ct->is_unsigned = is_unsigned;
+ if (IS_COMPLEX(type)) {
+ lua_newtable(L);
+ } else {
+ lua_pushnil(L);
+ }
+
push_upval(L, &types_key);
- push_ctype(L, 0, ct);
+ push_ctype(L, -2, ct);
lua_setfield(L, -2, name);
- lua_pop(L, 1); /* types */
+ lua_pop(L, 2); /* types, usr table */
}
static void push_builtin_undef(lua_State* L, struct ctype* ct, const char* name, int type)
@@ -3108,9 +3313,14 @@ static int setup_upvals(lua_State* L)
ct.pointers = 1;
ct.is_null = 1;
+ /* add ffi.C.NULL */
push_cdata(L, 0, &ct);
lua_setfield(L, -2, "NULL");
+ /* add ffi.NULL */
+ push_cdata(L, 0, &ct);
+ lua_setfield(L, 1, "NULL");
+
memset(&ct, 0, sizeof(ct));
ct.type = COMPLEX_DOUBLE_TYPE;
ct.is_defined = 1;
@@ -3330,5 +3540,10 @@ int luaopen_ffi(lua_State* L)
lua_setglobal(L, "tonumber");
lua_setfield(L, -2, "number"); /* ffi.number */
+ lua_getglobal(L, "type");
+ lua_pushcclosure(L, &ffi_type, 1);
+ lua_pushvalue(L, -1);
+ lua_setglobal(L, "type");
+ lua_setfield(L, -2, "type"); /* ffi.type */
return 1;
}
diff --git a/plugins/MirLua/Modules/luaffi/src/ffi.h b/plugins/MirLua/Modules/ffi/src/ffi.h
index 7107f612ec..a66f43de4c 100644
--- a/plugins/MirLua/Modules/luaffi/src/ffi.h
+++ b/plugins/MirLua/Modules/ffi/src/ffi.h
@@ -1,28 +1,10 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
*
- * Copyright (c) 2011 James R. McKaskill
- *
- * This software is licensed under the stock MIT license:
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * ----------------------------------------------------------------------------
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
@@ -41,11 +23,15 @@
#ifdef __cplusplus
extern "C" {
-# include <lua.h>
+# include "..\..\..\..\..\libs\liblua\src\lua.h"
+# include "..\..\..\..\..\libs\liblua\src\lauxlib.h"
+# include "..\..\..\..\..\libs\liblua\src\lualib.h"
}
# define EXTERN_C extern "C"
#else
-# include <lua.h>
+# include "..\..\..\..\..\libs\liblua\src\lua.h"
+# include "..\..\..\..\..\libs\liblua\src\lauxlib.h"
+# include "..\..\..\..\..\libs\liblua\src\lualib.h"
# define EXTERN_C extern
#endif
@@ -58,11 +44,9 @@ extern "C" {
#include <sys/mman.h>
#endif
-#if __STDC_VERSION__+0 >= 199901L
-#include <complex.h>
-#define HAVE_COMPLEX
+//#include <complex.h>
+//#define HAVE_COMPLEX
#define HAVE_LONG_DOUBLE
-#endif
#ifndef NDEBUG
#define DASM_CHECKS
@@ -123,6 +107,10 @@ static char* luaL_prepbuffsize(luaL_Buffer* B, size_t sz) {
}
return luaL_prepbuffer(B);
}
+#elif LUA_VERSION_NUM == 503
+static void (lua_remove)(lua_State *L, int idx) {
+ lua_remove(L, idx);
+}
#endif
/* architectures */
@@ -177,8 +165,13 @@ static char* luaL_prepbuffsize(luaL_Buffer* B, size_t sz) {
# define EnableWrite(data, size) do {DWORD old; VirtualProtect(data, size, PAGE_READWRITE, &old);} while (0)
#else
+#ifdef OS_OSX
+# define LIB_FORMAT_1 "%s.dylib"
+# define LIB_FORMAT_2 "lib%s.dylib"
+#else
# define LIB_FORMAT_1 "%s.so"
# define LIB_FORMAT_2 "lib%s.so"
+#endif
# define LoadLibraryA(name) dlopen(name, RTLD_LAZY | RTLD_GLOBAL)
# define GetProcAddressA(lib, name) dlsym(lib, name)
# define AllocPage(size) mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0)
@@ -369,6 +362,12 @@ typedef void (*cfunction)(void);
#ifdef HAVE_COMPLEX
typedef double complex complex_double;
typedef float complex complex_float;
+static complex_double mk_complex_double(double real, double imag) {
+ return real + imag * 1i;
+}
+static complex_double mk_complex_float(double real, double imag) {
+ return real + imag * 1i;
+}
#else
typedef struct {
double real, imag;
@@ -378,6 +377,14 @@ typedef struct {
float real, imag;
} complex_float;
+static complex_double mk_complex_double(double real, double imag) {
+ complex_double ret = { real, imag };
+ return ret;
+}
+static complex_float mk_complex_float(double real, double imag) {
+ complex_float ret = { real, imag };
+ return ret;
+}
static double creal(complex_double c) {
return c.real;
}
@@ -398,7 +405,7 @@ static float cimagf(complex_float c) {
void set_defined(lua_State* L, int ct_usr, struct ctype* ct);
struct ctype* push_ctype(lua_State* L, int ct_usr, const struct ctype* ct);
void* push_cdata(lua_State* L, int ct_usr, const struct ctype* ct); /* called from asm */
-void push_callback(lua_State* L, cfunction f);
+void push_callback(lua_State* L, cfunction luafunc, cfunction cfunc);
void check_ctype(lua_State* L, int idx, struct ctype* ct);
void* to_cdata(lua_State* L, int idx, struct ctype* ct);
void* check_cdata(lua_State* L, int idx, struct ctype* ct);
diff --git a/plugins/MirLua/Modules/luaffi/src/generate_call_h.bat b/plugins/MirLua/Modules/ffi/src/generate_call_h.bat
index 294204271f..294204271f 100644
--- a/plugins/MirLua/Modules/luaffi/src/generate_call_h.bat
+++ b/plugins/MirLua/Modules/ffi/src/generate_call_h.bat
diff --git a/plugins/MirLua/Modules/ffi/src/luaffi-scm-1.rockspec b/plugins/MirLua/Modules/ffi/src/luaffi-scm-1.rockspec
new file mode 100644
index 0000000000..bb7d2d5809
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/luaffi-scm-1.rockspec
@@ -0,0 +1,34 @@
+package = "luaffi"
+version = "scm-1"
+
+source = {
+ url = "git://github.com/facebook/luaffifb.git",
+}
+
+description = {
+ summary = "FFI library for calling C functions from lua",
+ detailed = [[
+ ]],
+ homepage = "https://github.com/facebook/luaffifb",
+ license = "BSD"
+}
+
+dependencies = {
+ "lua >= 5.1",
+}
+
+build = {
+ type = "builtin",
+ modules = {
+ ['ffi'] = {
+ incdirs = {
+ "dynasm"
+ },
+ sources = {
+ "call.c", "ctype.c", "ffi.c", "parser.c",
+ }
+ },
+ ['ffi.libtest'] = 'test.c',
+ ['ffi.test'] = 'test.lua',
+ }
+}
diff --git a/plugins/MirLua/Modules/luaffi/src/msvc/inttypes.h b/plugins/MirLua/Modules/ffi/src/msvc/inttypes.h
index d7e251d1b4..d7e251d1b4 100644
--- a/plugins/MirLua/Modules/luaffi/src/msvc/inttypes.h
+++ b/plugins/MirLua/Modules/ffi/src/msvc/inttypes.h
diff --git a/plugins/MirLua/Modules/luaffi/src/msvc/stdbool.h b/plugins/MirLua/Modules/ffi/src/msvc/stdbool.h
index b6fa0603d2..b6fa0603d2 100644
--- a/plugins/MirLua/Modules/luaffi/src/msvc/stdbool.h
+++ b/plugins/MirLua/Modules/ffi/src/msvc/stdbool.h
diff --git a/plugins/MirLua/Modules/luaffi/src/msvc/stdint.h b/plugins/MirLua/Modules/ffi/src/msvc/stdint.h
index 01ca453687..01ca453687 100644
--- a/plugins/MirLua/Modules/luaffi/src/msvc/stdint.h
+++ b/plugins/MirLua/Modules/ffi/src/msvc/stdint.h
diff --git a/plugins/MirLua/Modules/luaffi/src/msvcbuild.bat b/plugins/MirLua/Modules/ffi/src/msvcbuild.bat
index 0279641c4c..0279641c4c 100644
--- a/plugins/MirLua/Modules/luaffi/src/msvcbuild.bat
+++ b/plugins/MirLua/Modules/ffi/src/msvcbuild.bat
diff --git a/plugins/MirLua/Modules/luaffi/src/parser.c b/plugins/MirLua/Modules/ffi/src/parser.c
index 59e0619f51..6dd099a9a4 100644
--- a/plugins/MirLua/Modules/luaffi/src/parser.c
+++ b/plugins/MirLua/Modules/ffi/src/parser.c
@@ -1,11 +1,17 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
#include "ffi.h"
#define IS_CONST(tok) (IS_LITERAL(tok, "const") || IS_LITERAL(tok, "__const") || IS_LITERAL(tok, "__const__"))
#define IS_VOLATILE(tok) (IS_LITERAL(tok, "volatile") || IS_LITERAL(tok, "__volatile") || IS_LITERAL(tok, "__volatile__"))
#define IS_RESTRICT(tok) (IS_LITERAL(tok, "restrict") || IS_LITERAL(tok, "__restrict") || IS_LITERAL(tok, "__restrict__"))
+#define IS_INLINE(tok) (IS_LITERAL(tok, "inline") || IS_LITERAL(tok, "__inline") || IS_LITERAL(tok, "__inline__"))
enum etoken {
TOK_NIL,
@@ -210,10 +216,12 @@ end:
return 1;
}
-static void require_token(lua_State* L, struct parser* P, struct token* tok)
+#define require_token(L, P, tok) require_token_line(L, P, tok, __FILE__, __LINE__)
+
+static void require_token_line(lua_State* L, struct parser* P, struct token* tok, const char* file, int line)
{
if (!next_token(L, P, tok)) {
- luaL_error(L, "unexpected end");
+ luaL_error(L, "unexpected end on line %s:%d", file, line);
}
}
@@ -288,14 +296,14 @@ static int parse_enum(lua_State* L, struct parser* P, struct ctype* type)
/* add the enum value to the constants table */
push_upval(L, &constants_key);
lua_pushvalue(L, -2);
- lua_pushnumber(L, value);
+ lua_pushinteger(L, value);
lua_rawset(L, -3);
lua_pop(L, 1);
assert(lua_gettop(L) == ct_usr + 1);
/* add the enum value to the enum usr value table */
- lua_pushnumber(L, value);
+ lua_pushinteger(L, value);
lua_rawset(L, ct_usr);
if (tok.type == TOK_CLOSE_CURLY) {
@@ -378,26 +386,26 @@ static void calculate_member_position(lua_State* L, struct parser* P, struct cty
*pbitfield_type = mt->align_mask;
bit_offset += mt->bit_size;
-#elif defined OS_OSX
- /* OSX doesn't use containers and bitfields are not aligned. So
- * bitfields never add any padding, except for :0 which still forces
- * an alignment based off the type used with the :0 */
- if (mt->bit_size) {
- mt->offset = ct->base_size;
- mt->bit_offset = bit_offset;
- bit_offset += mt->bit_size;
- ct->base_size += bit_offset / CHAR_BIT;
- bit_offset = bit_offset % CHAR_BIT;
- } else {
- ct->base_size += (bit_offset + CHAR_BIT - 1) / CHAR_BIT;
- ct->base_size = ALIGN_UP(ct->base_size, mt->align_mask);
- bit_offset = 0;
- }
-
- if (!mt->has_member_name) {
- /* unnamed bitfields don't update the struct alignment */
- mt->align_mask = 0;
- }
+// #elif defined OS_OSX
+// /* OSX doesn't use containers and bitfields are not aligned. So
+// * bitfields never add any padding, except for :0 which still forces
+// * an alignment based off the type used with the :0 */
+// if (mt->bit_size) {
+// mt->offset = ct->base_size;
+// mt->bit_offset = bit_offset;
+// bit_offset += mt->bit_size;
+// ct->base_size += bit_offset / CHAR_BIT;
+// bit_offset = bit_offset % CHAR_BIT;
+// } else {
+// ct->base_size += (bit_offset + CHAR_BIT - 1) / CHAR_BIT;
+// ct->base_size = ALIGN_UP(ct->base_size, mt->align_mask);
+// bit_offset = 0;
+// }
+
+// if (!mt->has_member_name) {
+// /* unnamed bitfields don't update the struct alignment */
+// mt->align_mask = 0;
+// }
#elif defined __GNUC__
/* GCC tries to pack bitfields in as close as much as possible, but
@@ -1178,11 +1186,6 @@ int parse_type(lua_State* L, struct parser* P, struct ctype* ct)
require_token(L, P, &tok);
- /* get function attributes before the return type */
- while (parse_attribute(L, P, &tok, ct, NULL)) {
- require_token(L, P, &tok);
- }
-
/* get const/volatile before the base type */
for (;;) {
if (tok.type != TOK_TOKEN) {
@@ -1192,9 +1195,15 @@ int parse_type(lua_State* L, struct parser* P, struct ctype* ct)
ct->const_mask = 1;
require_token(L, P, &tok);
- } else if (IS_VOLATILE(tok) || IS_RESTRICT(tok)) {
+ } else if (IS_VOLATILE(tok) ||
+ IS_RESTRICT(tok) ||
+ IS_LITERAL(tok, "static") ||
+ IS_INLINE(tok)) {
/* ignored for now */
require_token(L, P, &tok);
+ } else if (parse_attribute(L, P, &tok, ct, NULL)) {
+ /* get function attributes before the return type */
+ require_token(L, P, &tok);
} else {
break;
@@ -1365,7 +1374,7 @@ static void append_type_name(luaL_Buffer* B, int usr, const struct ctype* ct, en
if (type == BOTH || type == BACK) {
if (ct->is_reference) {
- luaL_addstring(B, "(&)");
+ luaL_addstring(B, " &");
}
if (ct->is_variable_array && !ct->variable_size_known) {
@@ -1660,7 +1669,7 @@ static struct ctype* parse_argument2(lua_State* L, struct parser* P, int ct_usr,
}
} else if (tok.type == TOK_REFERENCE) {
- luaL_error(L, "NYI: c++ reference types");
+ ct->is_reference = 1;
} else if (parse_attribute(L, P, &tok, ct, asmname)) {
/* parse attribute has filled out appropriate fields in type */
@@ -1998,6 +2007,36 @@ static void push_strings(lua_State* L, struct parser* P)
luaL_pushresult(&B);
}
+static void parse_constant_assignemnt(lua_State* L,
+ struct parser* P,
+ const struct ctype* type,
+ const struct token* name)
+{
+ int64_t val = calculate_constant(L, P);
+
+ check_token(L, P, TOK_SEMICOLON, "", "expected ; after constant definition on line %d", P->line);
+
+ push_upval(L, &constants_key);
+ lua_pushlstring(L, name->str, name->size);
+
+ switch (type->type) {
+ case INT8_TYPE:
+ case INT16_TYPE:
+ case INT32_TYPE:
+ if (type->is_unsigned)
+ lua_pushinteger(L, (unsigned int) val);
+ else
+ lua_pushinteger(L, (int) val);
+ break;
+
+ default:
+ luaL_error(L, "expected a valid 8-, 16-, or 32-bit signed or unsigned integer type after 'static const' on line %d", P->line);
+ }
+
+ lua_rawset(L, -3);
+ lua_pop(L, 2); /*constants and type*/
+}
+
#define END 0
#define PRAGMA_POP 1
@@ -2073,48 +2112,6 @@ static int parse_root(lua_State* L, struct parser* P)
} else if (IS_LITERAL(tok, "typedef")) {
parse_typedef(L, P);
- } else if (IS_LITERAL(tok, "static")) {
- struct ctype at;
-
- int64_t val;
- require_token(L, P, &tok);
- if (!IS_CONST(tok)) {
- luaL_error(L, "expected 'static const int' on line %d", P->line);
- }
-
- parse_type(L, P, &at);
-
- require_token(L, P, &tok);
- if (tok.type != TOK_TOKEN) {
- luaL_error(L, "expected constant name after 'static const int' on line %d", P->line);
- }
-
- check_token(L, P, TOK_ASSIGN, "", "expected = after 'static const int <name>' on line %d", P->line);
-
- val = calculate_constant(L, P);
-
- check_token(L, P, TOK_SEMICOLON, "", "expected ; after 'static const int' definition on line %d", P->line);
-
- push_upval(L, &constants_key);
- lua_pushlstring(L, tok.str, tok.size);
-
- switch (at.type) {
- case INT8_TYPE:
- case INT16_TYPE:
- case INT32_TYPE:
- if (at.is_unsigned)
- lua_pushnumber(L, (unsigned int) val);
- else
- lua_pushnumber(L, (int) val);
- break;
-
- default:
- luaL_error(L, "expected a valid 8-, 16-, or 32-bit signed or unsigned integer type after 'static const' on line %d", P->line);
- }
-
- lua_rawset(L, -3);
- lua_pop(L, 2); /*constants and type*/
-
} else {
/* type declaration, type definition, or function declaration */
struct ctype type;
@@ -2153,13 +2150,33 @@ static int parse_root(lua_State* L, struct parser* P)
lua_pop(L, 1);
- require_token(L, P, &tok);
-
- if (tok.type == TOK_SEMICOLON) {
+ if (!next_token(L, P, &tok)) {
break;
- } else if (tok.type != TOK_COMMA) {
+ }
+
+ if (tok.type == TOK_COMMA) {
+ continue;
+ }
+
+ if (tok.type == TOK_OPEN_CURLY) {
+ int line = P->line;
+ int remaining = 1;
+ while (remaining > 0 && next_token(L, P, &tok)) {
+ if (tok.type == TOK_CLOSE_CURLY) {
+ remaining--;
+ } else if (tok.type == TOK_OPEN_CURLY) {
+ remaining++;
+ }
+ }
+ if (remaining > 0) {
+ luaL_error(L, "missing closing bracket for line %d", line);
+ }
+ } else if (tok.type == TOK_ASSIGN) {
+ parse_constant_assignemnt(L, P, &type, &name);
+ } else if (tok.type != TOK_SEMICOLON) {
luaL_error(L, "missing semicolon on line %d", P->line);
}
+ break;
}
lua_pop(L, 1);
@@ -2189,6 +2206,49 @@ int ffi_cdef(lua_State* L)
* precedence and above. calculate_constant1 is the highest precedence
*/
+static int64_t string_to_int(const char* str, size_t size)
+{
+ const char* end = str + size;
+ char c = *str++;
+ if (str < end)
+ {
+ if (c == '\\') {
+ c = *str++;
+ switch (c) {
+ case '\'': c = '\''; break;
+ case '\"': c = '\"'; break;
+ case '\?': c = '\?'; break;
+ case '\\': c = '\\'; break;
+ case 'a': c = '\a'; break;
+ case 'b': c = '\b'; break;
+ case 'f': c = '\f'; break;
+ case 'n': c = '\n'; break;
+ case 'r': c = '\r'; break;
+ case 't': c = '\t'; break;
+ case 'v': c = '\v'; break;
+ case 'e': c = 27; break;
+ case 'x':
+ c = 0;
+ while (str < end) {
+ char d = *str++;
+ c *= 16;
+ if (d >= '0' && d <= '9') c += (d - '0');
+ else c += (d - 'a' + 10);
+ }
+ break;
+ default:
+ c = c - '0';
+ while (str < end) {
+ char d = *str++;
+ c = c*8 + (d - '0');
+ }
+ break;
+ }
+ }
+ }
+ return c;
+}
+
static int try_cast(lua_State* L)
{
struct parser* P = (struct parser*) lua_touserdata(L, 1);
@@ -2204,7 +2264,7 @@ static int try_cast(lua_State* L)
return luaL_error(L, "invalid cast");
}
- if (ct.pointers || ct.type != INT32_TYPE) {
+ if (ct.pointers/* || ct.type != INT32_TYPE*/) {
return luaL_error(L, "unsupported cast on line %d", P->line);
}
@@ -2264,6 +2324,12 @@ static int64_t calculate_constant1(lua_State* L, struct parser* P, struct token*
next_token(L, P, tok);
return ret;
+ } else if (tok->type == TOK_STRING) {
+ ret = string_to_int(tok->str, tok->size);
+
+ next_token(L, P, tok);
+ return ret;
+
} else {
return luaL_error(L, "unexpected token whilst parsing constant at line %d", P->line);
}
diff --git a/plugins/MirLua/Modules/luaffi/src/pretty.lua b/plugins/MirLua/Modules/ffi/src/pretty.lua
index b3746d5930..b3746d5930 100644
--- a/plugins/MirLua/Modules/luaffi/src/pretty.lua
+++ b/plugins/MirLua/Modules/ffi/src/pretty.lua
diff --git a/plugins/MirLua/Modules/luaffi/src/stdafx.cxx b/plugins/MirLua/Modules/ffi/src/stdafx.cxx
index 7b43c3cb6c..7b43c3cb6c 100644
--- a/plugins/MirLua/Modules/luaffi/src/stdafx.cxx
+++ b/plugins/MirLua/Modules/ffi/src/stdafx.cxx
diff --git a/plugins/MirLua/Modules/luaffi/src/test.c b/plugins/MirLua/Modules/ffi/src/test.c0
index fa9eed7b1d..29660e5073 100644
--- a/plugins/MirLua/Modules/luaffi/src/test.c
+++ b/plugins/MirLua/Modules/ffi/src/test.c0
@@ -1,5 +1,10 @@
/* vim: ts=4 sw=4 sts=4 et tw=78
- * Copyright (c) 2011 James R. McKaskill. See license in ffi.h
+ * Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+ * Portions copyright (c) 2011 James R. McKaskill.
+ *
+ * This source code is licensed under the BSD-style license found in the
+ * LICENSE file in the root directory of this source tree. An additional grant
+ * of patent rights can be found in the PATENTS file in the same directory.
*/
#include <stdio.h>
#include <stdint.h>
@@ -14,10 +19,8 @@
#include <errno.h>
#endif
-#if __STDC_VERSION__+0 >= 199901L
#include <complex.h>
#define HAVE_COMPLEX
-#endif
#ifdef __cplusplus
# define EXTERN_C extern "C"
@@ -125,10 +128,10 @@ PRINT(enum e16, print_e16, "d")
PRINT(enum e32, print_e32, "d")
#ifdef HAVE_COMPLEX
-EXPORT int print_dc(char* buf, double complex val);
+/*EXPORT int print_dc(char* buf, double complex val);
EXPORT int print_fc(char* buf, float complex val);
int print_dc(char* buf, double complex val) {return sprintf(buf, "%g+%gi", creal(val), cimag(val));}
-int print_fc(char* buf, float complex val) {return sprintf(buf, "%g+%gi", creal(val), cimag(val));}
+int print_fc(char* buf, float complex val) {return sprintf(buf, "%g+%gi", creal(val), cimag(val));}*/
#endif
EXPORT int print_b(char* buf, _Bool val);
@@ -675,3 +678,43 @@ EXPORT int va_list_size, va_list_align;
int va_list_size = sizeof(va_list);
int va_list_align = alignof(va_list);
+
+EXPORT char buf[512];
+char buf[512];
+
+EXPORT void test_call_echo(char* c);
+void test_call_echo(char* c)
+{
+ sprintf(buf, "%s", c);
+}
+
+EXPORT void test_call_pppppii(void* a, void* b, void* c, void* d, void* e, int f, int g);
+void test_call_pppppii(void* a, void* b, void* c, void* d, void* e, int f, int g)
+{
+ sprintf(buf, "%p %p %p %p %p %d %d", a, b, c, d, e, f, g);
+}
+
+EXPORT void test_call_pppppiiiiii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, int i3, int i4, int i5, int i6);
+void test_call_pppppiiiiii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, int i3, int i4, int i5, int i6)
+{
+ sprintf(buf, "%p %p %p %p %p %d %d %d %d %d %d", p1, p2, p3, p4, p5, i1, i2, i3, i4, i5, i6);
+}
+
+EXPORT void test_call_pppppffffff(void* p1, void* p2, void* p3, void* p4, void* p5, float f1, float f2, float f3, float f4, float f5, float f6);
+void test_call_pppppffffff(void* p1, void* p2, void* p3, void* p4, void* p5, float f1, float f2, float f3, float f4, float f5, float f6)
+{
+ sprintf(buf, "%p %p %p %p %p %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f", p1, p2, p3, p4, p5, f1, f2, f3, f4, f5, f6);
+}
+
+EXPORT void test_call_pppppiifiii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, float f3, int i4, int i5, int i6);
+void test_call_pppppiifiii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, float f3, int i4, int i5, int i6)
+{
+ sprintf(buf, "%p %p %p %p %p %d %d %0.1f %d %d %d", p1, p2, p3, p4, p5, i1, i2, f3, i4, i5, i6);
+}
+
+EXPORT void test_call_pppppiiifii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, int i3, float f4, int i5, int i6);
+void test_call_pppppiiifii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, int i3, float f4, int i5, int i6)
+{
+ sprintf(buf, "%p %p %p %p %p %d %d %d %0.1f %d %d", p1, p2, p3, p4, p5, i1, i2, i3, f4, i5, i6);
+}
+
diff --git a/plugins/MirLua/Modules/luaffi/src/test.lua b/plugins/MirLua/Modules/ffi/src/test.lua
index cc66a8b924..866fec686c 100644
--- a/plugins/MirLua/Modules/luaffi/src/test.lua
+++ b/plugins/MirLua/Modules/ffi/src/test.lua
@@ -1,22 +1,42 @@
-- vim: ts=4 sw=4 sts=4 et tw=78
--- Copyright (c) 2011 James R. McKaskill. See license in ffi.h
-
+-- Portions copyright (c) 2015-present, Facebook, Inc. All rights reserved.
+-- Portions copyright (c) 2011 James R. McKaskill.
+--
+-- This source code is licensed under the BSD-style license found in the
+-- LICENSE file in the root directory of this source tree. An additional grant
+-- of patent rights can be found in the PATENTS file in the same directory.
+--
io.stdout:setvbuf('no')
local ffi = require 'ffi'
local dlls = {}
-dlls.__cdecl = ffi.load('test_cdecl')
+local function loadlib(lib)
+ for pattern in package.cpath:gmatch('[^;]+') do
+ local path = pattern:gsub('?', lib)
+ local ok, lib = pcall(ffi.load, path)
+ if ok then
+ return lib
+ end
+ end
+ error("Unable to load", lib)
+end
+
+if _VERSION == 'Lua 5.1' then
+ dlls.__cdecl = loadlib('ffi/libtest')
+else
+ dlls.__cdecl = ffi.load(package.searchpath('ffi.libtest', package.cpath))
+end
if ffi.arch == 'x86' and ffi.os == 'Windows' then
dlls.__stdcall = ffi.load('test_stdcall')
dlls.__fastcall = ffi.load('test_fastcall')
end
-local function check(a, b)
+local function check(a, b, msg)
if a ~= b then
print('check', a, b)
end
- return _G.assert(a == b)
+ return _G.assert(a == b, msg)
end
print('Running test')
@@ -280,8 +300,8 @@ local test_values = {
uint64_t = 12345678901234,
bool = true,
_Bool = false,
- ['float complex'] = 3+4*i,
- ['double complex'] = 5+6*i,
+ ['float complex'] = 3.1+4.2*i,
+ ['double complex'] = 5.1+6.2*i,
['enum e8'] = ffi.C.FOO8,
['enum e16'] = ffi.C.FOO16,
['enum e32'] = ffi.C.FOO32,
@@ -304,10 +324,10 @@ local types = {
local buf = ffi.new('char[256]')
-local function checkbuf(type, ret)
+local function checkbuf(type, ret, msg)
local str = tostring(test_values[type]):gsub('^cdata%b<>: ', '')
- check(ffi.string(buf), str)
- check(ret, #str)
+ check(ffi.string(buf), str, msg)
+ check(ret, #str, msg)
end
local function checkalign(type, v, ret)
@@ -424,7 +444,7 @@ for convention,c in pairs(dlls) do
for suffix, type in pairs(types) do
local test = test_values[type]
--print('checkbuf', suffix, type, buf, test)
- checkbuf(type, c['print_' .. suffix](buf, test))
+ checkbuf(type, c['print_' .. suffix](buf, test), suffix)
if first then
ffi.cdef(align:gsub('SUFFIX', suffix):gsub('TYPE', type):gsub('ALIGN', 0))
@@ -466,7 +486,10 @@ for convention,c in pairs(dlls) do
end
local v = ffi.new('struct align_attr_def_' .. suffix, {0, test})
- checkalign(type, v, c['print_align_attr_def_' .. suffix](buf, v))
+ -- print(type)
+ -- print("Align " .. c['print_align_attr_def_' .. suffix](buf, v))
+ -- print(ffi.string(buf))
+ -- checkalign(type, v, c['print_align_attr_def_' .. suffix](buf, v))
end
end
@@ -714,9 +737,9 @@ if _VERSION ~= 'Lua 5.1' then
check(#vls, 5)
end
-check(tostring(1+3*i), '1+3i')
-check(tostring((1+3*i)*(2+4*i)), '-10+10i')
-check(tostring((3+2*i)*(3-2*i)), '13')
+check(tostring(1.1+3.2*i), '1.1+3.2i')
+check((1+3*i)*(2+4*i), -10+10*i)
+check((3+2*i)*(3-2*i), 13+0*i)
-- Should ignore unknown attributes
ffi.cdef [[
@@ -760,7 +783,6 @@ check(tostring(ffi.debug().functions.register_foo):match('%b<>'), '<void (*)(int
ffi.cdef [[
typedef struct __sFILE FILE;
- FILE *fopen(const char * , const char * ) __asm("_" "fopen" );
]]
assert(not ffi.istype('int', ffi.new('int*')))
@@ -848,11 +870,13 @@ assert(v.a == 1 and v.b == 2 and v.c == 3)
local tp = ffi.metatype("struct newtest",
{__pairs = function(tp) return tp.a, tp.b end, __ipairs = function(tp) return tp.b, tp.c end}
)
-local v = tp(1, 2, 3)
-x, y = pairs(v)
-assert(x == 1 and y == 2)
-x, y = ipairs(v)
-assert(x == 2 and y == 3)
+if _VERSION ~= 'Lua 5.1' then
+ local v = tp(1, 2, 3)
+ x, y = pairs(v)
+ assert(x == 1 and y == 2)
+ x, y = ipairs(v)
+ assert(x == 2 and y == 3)
+end
-- test for pointer to struct having same metamethods
local st = ffi.cdef "struct ptest {int a, b;};"
@@ -867,5 +891,88 @@ assert(c.banana == "banana") -- should have same methods
assert(#c == 3)
+ffi.cdef [[
+char buf[512];
+void test_call_echo(const char* c);
+void test_call_pppppii(void* a, void* b, void* c, void* d, void* e, int f, int g);
+void test_call_pppppiiiiii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, int i3, int i4, int i5, int i6);
+void test_call_pppppffffff(void* p1, void* p2, void* p3, void* p4, void* p5, float f1, float f2, float f3, float f4, float f5, float f6);
+void test_call_pppppiifiii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, float f3, int i4, int i5, int i6);
+void test_call_pppppiiifii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, int i3, float i4, int i5, int i6);
+]]
+
+ffi.C.test_call_echo("input")
+assert(ffi.C.buf == "input")
+
+local function ptr(x) return ffi.new('void*', x) end
+
+ffi.C.test_call_pppppii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7)
+assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7")
+
+ffi.C.test_call_pppppiiiiii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8, 9, 10, 11)
+assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8 9 10 11")
+
+ffi.C.test_call_pppppffffff(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6.5, 7.5, 8.5, 9.5, 10.5, 11.5)
+assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6.5 7.5 8.5 9.5 10.5 11.5")
+
+ffi.C.test_call_pppppiifiii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8.5, 9, 10, 11)
+assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8.5 9 10 11")
+
+ffi.C.test_call_pppppiiifii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8, 9.5, 10, 11)
+assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8 9.5 10 11")
+
+local sum = ffi.C.add_dc(ffi.new('complex', 1, 2), ffi.new('complex', 3, 5))
+assert(ffi.istype('complex', sum))
+
+sum = ffi.C.add_fc(ffi.new('complex float', 1, 2), ffi.new('complex float', 3, 5))
+assert(ffi.istype('complex float', sum))
+
+ffi.cdef [[
+struct Arrays {
+ int ints[3];
+ unsigned int uints[3];
+};
+struct ArrayOfArrays {
+ struct Arrays arrays[3];
+};
+]]
+
+local struct = ffi.new('struct Arrays')
+local structOfStructs = ffi.new('struct ArrayOfArrays')
+for i=0,2 do
+ struct.ints[i] = i
+ struct.uints[i] = i
+ structOfStructs.arrays[0].ints[i] = i
+end
+for i=0,2 do
+ assert(struct.ints[i] == i)
+ assert(struct.uints[i] == i)
+ assert(structOfStructs.arrays[0].ints[i] == i)
+end
+
+-- Test ffi.string
+local buf = ffi.new('char[5]')
+ffi.fill(buf, 4, 97)
+buf[4] = 0
+
+assert(ffi.string(buf) == 'aaaa')
+assert(ffi.string(buf, 4) == 'aaaa')
+assert(ffi.string(buf, 2) == 'aa')
+assert(ffi.string(buf, 0) == '')
+assert(ffi.string(buf, ffi.new('long long', 2)) == 'aa')
+assert(ffi.string(buf, ffi.new('int', 2)) == 'aa')
+
+-- Test io.tmpfile()
+ffi.cdef [[
+ int fprintf ( FILE * stream, const char * format, ... );
+]]
+local f = io.tmpfile()
+ffi.C.fprintf(f, "test: %s\n", "foo")
+
+f:seek("set", 0)
+local str = f:read('*l')
+assert(str == 'test: foo', str)
+f:close()
+
print('Test PASSED')
diff --git a/plugins/MirLua/Modules/ffi/src/test_includes.sh b/plugins/MirLua/Modules/ffi/src/test_includes.sh
new file mode 100644
index 0000000000..c0b9cfa1f9
--- /dev/null
+++ b/plugins/MirLua/Modules/ffi/src/test_includes.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+make test || exit
+rm -rf test_includes
+mkdir -p test_includes
+for f in /usr/include/*.h
+do
+ gcc -E -c "${f}" > tmp 2>/dev/null
+ if [ $? == 0 ]
+ then
+ echo "${f}";
+ lua -e '
+ local str = io.read("*a")
+ -- remove preprocessor commands eg line directives
+ str = str:gsub("#[^\n]*", "")
+ -- remove inline function definitions and declarations
+ str = str:gsub("extern%s+__inline__", "static")
+ str = str:gsub("extern%s+__inline", "static")
+ str = str:gsub("static[^;(]+__attribute__%s*%b()", "static ")
+ str = str:gsub("static[^;(]+__attribute__%s*%b()", "static ")
+ str = str:gsub("static[^;(]+%b()%s*%b{}", "")
+ str = str:gsub("static[^;(]+%b()%s*;", "")
+ io.write(str)' > "test_includes/`basename $f`" < tmp
+ lua -e 'ffi = require("ffi"); ffi.cdef(io.read("*a"))' < "test_includes/`basename $f`"
+ fi
+done
diff --git a/plugins/MirLua/Modules/luaffi/src/Makefile b/plugins/MirLua/Modules/luaffi/src/Makefile
deleted file mode 100644
index 8477140a05..0000000000
--- a/plugins/MirLua/Modules/luaffi/src/Makefile
+++ /dev/null
@@ -1,54 +0,0 @@
-.PHONY: all clean test
-
-PKG_CONFIG=pkg-config
-LUA=lua
-
-LUA_CFLAGS=`$(PKG_CONFIG) --cflags lua5.2 2>/dev/null || $(PKG_CONFIG) --cflags lua`
-SOCFLAGS=-fPIC
-SOCC=$(CC) -shared $(SOCFLAGS)
-CFLAGS=-fPIC -g -Wall -Werror $(LUA_CFLAGS) -fvisibility=hidden -Wno-unused-function --std=gnu99
-
-MODNAME=ffi
-MODSO=$(MODNAME).so
-
-all:
- if [ `uname` = "Darwin" ]; then $(MAKE) macosx; else $(MAKE) posix; fi
-
-test:
- if [ `uname` = "Darwin" ]; then $(MAKE) test_macosx; else $(MAKE) test_posix; fi
-
-macosx:
- $(MAKE) posix "SOCC=MACOSX_DEPLOYMENT_TARGET=10.3 $(CC) -dynamiclib -single_module -undefined dynamic_lookup $(SOCFLAGS)"
-
-test_macosx:
- $(MAKE) test_posix "SOCC=MACOSX_DEPLOYMENT_TARGET=10.3 $(CC) -dynamiclib -single_module -undefined dynamic_lookup $(SOCFLAGS)"
-
-posix: $(MODSO) test_cdecl.so
-
-clean:
- rm -f *.o *.so call_*.h
-
-call_x86.h: call_x86.dasc dynasm/*.lua
- $(LUA) dynasm/dynasm.lua -LN -o $@ $<
-
-call_x64.h: call_x86.dasc dynasm/*.lua
- $(LUA) dynasm/dynasm.lua -D X64 -LN -o $@ $<
-
-call_x64win.h: call_x86.dasc dynasm/*.lua
- $(LUA) dynasm/dynasm.lua -D X64 -D X64WIN -LN -o $@ $<
-
-%.o: %.c *.h dynasm/*.h call_x86.h call_x64.h call_x64win.h
- $(CC) $(CFLAGS) -o $@ -c $<
-
-$(MODSO): ffi.o ctype.o parser.o call.o
- $(SOCC) $^ -o $@
-
-test_cdecl.so: test.o
- $(SOCC) $^ -o $@
-
-test_posix: test_cdecl.so $(MODSO)
- LD_LIBRARY_PATH=./ $(LUA) test.lua
-
-
-
-
diff --git a/plugins/MirLua/Modules/luaffi/src/stdafx.h b/plugins/MirLua/Modules/luaffi/src/stdafx.h
deleted file mode 100644
index 0c93d400cc..0000000000
--- a/plugins/MirLua/Modules/luaffi/src/stdafx.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef _COMMON_H_
-#define _COMMON_H_
-
-#include <windows.h>
-
-# include <lua.hpp>
-
-#include <m_core.h>
-#include <m_utils.h>
-
-#include "ffi.h"
-
-
-#endif //_COMMON_H_ \ No newline at end of file