From 1d1fed48a002dfc0919135911057ebc255a53e0a Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Tue, 8 Dec 2009 19:49:20 +0100 Subject: [PATCH] RELEASE LuaJIT-2.0.0-beta2 --- COPYRIGHT | 56 ++++++ Makefile | 92 ++++++++-- README | 4 +- doc/api.html | 147 ++++++++++++++- doc/changes.html | 32 +++- doc/faq.html | 23 +++ doc/install.html | 59 +++--- doc/running.html | 6 +- doc/status.html | 21 ++- etc/luajit.1 | 82 +++++++++ etc/luajit.pc | 24 +++ src/Makefile | 428 +++++++++++++++++++++++++++---------------- src/Makefile.dep | 4 +- src/buildvm_asm.c | 7 +- src/buildvm_fold.c | 7 +- src/buildvm_peobj.c | 3 +- src/buildvm_x86.dasc | 111 ++++++++++- src/lib_aux.c | 96 +--------- src/lib_io.c | 9 +- src/lib_jit.c | 5 +- src/lib_math.c | 19 +- src/lib_package.c | 1 + src/lib_string.c | 7 +- src/lib_table.c | 24 +-- src/lj_api.c | 136 +++++++++++++- src/lj_asm.c | 11 +- src/lj_dispatch.c | 17 +- src/lj_err.c | 46 +++++ src/lj_errmsg.h | 4 + src/lj_func.c | 2 +- src/lj_gc.c | 3 +- src/lj_ir.c | 1 + src/lj_lib.h | 9 + src/lj_obj.h | 3 +- src/lj_opt_fold.c | 8 +- src/lj_opt_loop.c | 2 +- src/lj_opt_mem.c | 4 +- src/lj_record.c | 70 ++++++- src/lj_tab.c | 4 +- src/lj_trace.c | 82 +++++---- src/lj_trace.h | 2 +- src/lj_vm.h | 6 +- src/lua.hpp | 8 +- src/luaconf.h | 15 +- src/luajit.c | 20 +- src/luajit.h | 10 +- 46 files changed, 1289 insertions(+), 441 deletions(-) create mode 100644 COPYRIGHT create mode 100644 etc/luajit.1 create mode 100644 etc/luajit.pc diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100644 index 00000000..2a2db3dc --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1,56 @@ +=============================================================================== +LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ + +Copyright (C) 2005-2009 Mike Pall. All rights reserved. + +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. + +[ MIT license: http://www.opensource.org/licenses/mit-license.php ] + +=============================================================================== +[ LuaJIT includes code from Lua 5.1, which has this license statement: ] + +Copyright (C) 1994-2008 Lua.org, PUC-Rio. + +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. + +=============================================================================== +[ LuaJIT includes code from dlmalloc, which has this license statement: ] + +This is a version (aka dlmalloc) of malloc/free/realloc written by +Doug Lea and released to the public domain, as explained at +http://creativecommons.org/licenses/publicdomain + +=============================================================================== diff --git a/Makefile b/Makefile index 67347041..1dd0c132 100644 --- a/Makefile +++ b/Makefile @@ -12,46 +12,104 @@ # Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h ############################################################################## -BASEVER= 2.0.0 -VERSION= 2.0.0-beta1 +MAJVER= 2 +MINVER= 0 +RELVER= 0 +PREREL= -beta2 +VERSION= $(MAJVER).$(MINVER).$(RELVER)$(PREREL) +ABIVER= 5.1 +NODOTABIVER= 51 ############################################################################## # # Change the installation path as needed and modify src/luaconf.h accordingly. # Note: PREFIX must be an absolute path! # -PREFIX= /usr/local +export PREFIX= /usr/local ############################################################################## -INSTALL_BIN= $(PREFIX)/bin -INSTALL_NAME= luajit-$(VERSION) -INSTALL_T= $(INSTALL_BIN)/$(INSTALL_NAME) -INSTALL_TSYM= $(INSTALL_BIN)/luajit -INSTALL_INC= $(PREFIX)/include/luajit-$(BASEVER) -INSTALL_JITLIB= $(PREFIX)/share/luajit-$(VERSION)/jit +DPREFIX= $(DESTDIR)$(PREFIX) +INSTALL_BIN= $(DPREFIX)/bin +INSTALL_LIB= $(DPREFIX)/lib +INSTALL_SHARE= $(DPREFIX)/share +INSTALL_INC= $(DPREFIX)/include/luajit-$(MAJVER).$(MINVER) +INSTALL_JITLIB= $(INSTALL_SHARE)/luajit-$(VERSION)/jit +INSTALL_LMOD= $(INSTALL_SHARE)/lua/$(ABIVER) +INSTALL_CMOD= $(INSTALL_LIB)/lua/$(ABIVER) +INSTALL_MAN= $(INSTALL_SHARE)/man/man1 +INSTALL_PKGCONFIG= $(INSTALL_LIB)/pkgconfig + +INSTALL_TNAME= luajit-$(VERSION) +INSTALL_TSYMNAME= luajit +INSTALL_ANAME= libluajit-$(ABIVER).a +INSTALL_SONAME= libluajit-$(ABIVER).so.$(MAJVER).$(MINVER).$(RELVER) +INSTALL_SOSHORT= libluajit-$(ABIVER).so +INSTALL_DYLIBNAME= libluajit-$(NODOTABIVER).$(MAJVER).$(MINVER).$(RELVER).dylib +INSTALL_DYLIBSHORT1= libluajit-$(NODOTABIVER).dylib +INSTALL_DYLIBSHORT2= libluajit-$(NODOTABIVER).$(MAJVER).dylib +INSTALL_PCNAME= luajit.pc + +INSTALL_STATIC= $(INSTALL_LIB)/$(INSTALL_ANAME) +INSTALL_DYN= $(INSTALL_LIB)/$(INSTALL_SONAME) +INSTALL_SHORT1= $(INSTALL_LIB)/$(INSTALL_SOSHORT) +INSTALL_SHORT2= $(INSTALL_LIB)/$(INSTALL_SOSHORT) +INSTALL_T= $(INSTALL_BIN)/$(INSTALL_TNAME) +INSTALL_TSYM= $(INSTALL_BIN)/$(INSTALL_TSYMNAME) +INSTALL_PC= $(INSTALL_PKGCONFIG)/$(INSTALL_PCNAME) + +INSTALL_DIRS= $(INSTALL_BIN) $(INSTALL_LIB) $(INSTALL_INC) $(INSTALL_MAN) \ + $(INSTALL_PKGCONFIG) $(INSTALL_JITLIB) $(INSTALL_LMOD) $(INSTALL_CMOD) + +RM= rm -f MKDIR= mkdir -p -SYMLINK= ln -f -s +SYMLINK= ln -sf INSTALL_X= install -m 0755 INSTALL_F= install -m 0644 +LDCONFIG= ldconfig -n +SED_PC= sed -e "s|^prefix=.*|prefix=$(PREFIX)|" -FILES_T= luajit +FILE_T= luajit +FILE_A= libluajit.a +FILE_SO= libluajit.so +FILE_MAN= luajit.1 +FILE_PC= luajit.pc FILES_INC= lua.h lualib.h lauxlib.h luaconf.h lua.hpp luajit.h FILES_JITLIB= bc.lua v.lua dump.lua dis_x86.lua dis_x64.lua vmdef.lua +ifeq (,$(findstring Windows,$(OS))) + ifeq (Darwin,$(shell uname -s)) + INSTALL_SONAME= $(INSTALL_DYLIBNAME) + INSTALL_SHORT1= $(INSTALL_LIB)/$(INSTALL_DYLIBSHORT1) + INSTALL_SHORT2= $(INSTALL_LIB)/$(INSTALL_DYLIBSHORT2) + LDCONFIG= : + endif +endif + ############################################################################## INSTALL_DEP= src/luajit -all $(INSTALL_DEP): +default all $(INSTALL_DEP): @echo "==== Building LuaJIT $(VERSION) ====" $(MAKE) -C src @echo "==== Successfully built LuaJIT $(VERSION) ====" install: $(INSTALL_DEP) @echo "==== Installing LuaJIT $(VERSION) to $(PREFIX) ====" - $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_JITLIB) - cd src && $(INSTALL_X) $(FILES_T) $(INSTALL_T) + $(MKDIR) $(INSTALL_DIRS) + cd src && $(INSTALL_X) $(FILE_T) $(INSTALL_T) + cd src && test -f $(FILE_A) && $(INSTALL_F) $(FILE_A) $(INSTALL_STATIC) || : + $(RM) $(INSTALL_DYN) $(INSTALL_SHORT1) $(INSTALL_SHORT2) + cd src && test -f $(FILE_SO) && \ + $(INSTALL_F) $(FILE_SO) $(INSTALL_DYN) && \ + $(LDCONFIG) $(INSTALL_LIB) && \ + $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT1) && \ + $(SYMLINK) $(INSTALL_SONAME) $(INSTALL_SHORT2) || : + cd etc && $(INSTALL_F) $(FILE_MAN) $(INSTALL_MAN) + cd etc && $(SED_PC) $(FILE_PC) > $(FILE_PC).tmp && \ + $(INSTALL_F) $(FILE_PC).tmp $(INSTALL_PC) && \ + $(RM) $(FILE_PC).tmp cd src && $(INSTALL_F) $(FILES_INC) $(INSTALL_INC) cd lib && $(INSTALL_F) $(FILES_JITLIB) $(INSTALL_JITLIB) @echo "==== Successfully installed LuaJIT $(VERSION) to $(PREFIX) ====" @@ -59,7 +117,7 @@ install: $(INSTALL_DEP) @echo "Note: the beta releases deliberately do NOT install a symlink for luajit" @echo "You can do this now by running this command (with sudo):" @echo "" - @echo " $(SYMLINK) $(INSTALL_NAME) $(INSTALL_TSYM)" + @echo " $(SYMLINK) $(INSTALL_TNAME) $(INSTALL_TSYM)" @echo "" ############################################################################## @@ -77,8 +135,6 @@ cleaner: distclean: $(MAKE) -C src distclean -SUB_TARGETS= amalg clean cleaner distclean - -.PHONY: all install $(SUB_TARGETS) +.PHONY: all install amalg clean cleaner distclean ############################################################################## diff --git a/README b/README index 43caf78e..98df99af 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -README for LuaJIT 2.0.0-beta1 +README for LuaJIT 2.0.0-beta2 ----------------------------- LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language. @@ -7,7 +7,7 @@ Project Homepage: http://luajit.org/ LuaJIT is Copyright (C) 2005-2009 Mike Pall. LuaJIT is free software, released under the MIT/X license. -See full Copyright Notice in src/luajit.h +See full Copyright Notice in the COPYRIGHT file or in luajit.h. Documentation for LuaJIT is available in HTML format. Please point your favorite browser to: diff --git a/doc/api.html b/doc/api.html index 79788d95..3bb10967 100644 --- a/doc/api.html +++ b/doc/api.html @@ -100,12 +100,6 @@ These functions are typically used with the command line options Flushes the whole cache of compiled code.

-

jit.flush(tr)

-

-Flushes the code for the specified root trace and all of its -side traces from the cache. -

-

jit.on(func|true [,true|false])
jit.off(func|true [,true|false])
jit.flush(func|true [,true|false])

@@ -142,6 +136,13 @@ of a module to turn off JIT compilation for the whole module for debugging purposes.

+

status = jit.flush(tr)

+

+Tries to flush the code for the specified trace and all of its +side traces from the cache. Returns true on success. +Returns false if there are still links to this trace. +

+

jit.version

Contains the LuaJIT version string. @@ -189,6 +190,140 @@ The debug modules -jbc, -jv and -jdump make extensive use of these functions. Please check out their source code, if you want to know more.

+ +

C API extensions

+

+LuaJIT adds some extensions to the Lua/C API. The LuaJIT include +directory must be in the compiler search path (-Ipath) +to be able to include the required header for C code: +

+
+#include "luajit.h"
+
+

+Or for C++ code: +

+
+#include "lua.hpp"
+
+ +

luaJIT_setmode(L, idx, mode) +— Control VM

+

+This is a C API extension to allow control of the VM from C code. The +full prototype of LuaJIT_setmode is: +

+
+LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode);
+
+

+The returned status is either success (1) or failure (0). +The second argument is either 0 or a stack index (similar to the +other Lua/C API functions). +

+

+The third argument specifies the mode, which is 'or'ed with a flag. +The flag can be LUAJIT_MODE_OFF to turn a feature on, +LUAJIT_MODE_ON to turn a feature off, or +LUAJIT_MODE_FLUSH to flush cached code. +

+

+The following modes are defined: +

+ +

luaJIT_setmode(L, 0, LUAJIT_MODE_ENGINE|flag)

+

+Turn the whole JIT compiler on or off or flush the whole cache of compiled code. +

+ +

luaJIT_setmode(L, idx, LUAJIT_MODE_FUNC|flag)
+luaJIT_setmode(L, idx, LUAJIT_MODE_ALLFUNC|flag)
+luaJIT_setmode(L, idx, LUAJIT_MODE_ALLSUBFUNC|flag)

+

+This sets the mode for the function at the stack index idx or +the parent of the calling function (idx = 0). It either +enables JIT compilation for a function, disables it and flushes any +already compiled code or only flushes already compiled code. This +applies recursively to all subfunctions of the function with +LUAJIT_MODE_ALLFUNC or only to the subfunctions with +LUAJIT_MODE_ALLSUBFUNC. +

+ +

luaJIT_setmode(L, trace,
+  LUAJIT_MODE_TRACE|LUAJIT_MODE_FLUSH)

+

+Tries to flush the code for the specified trace and all of its +side traces from the cache. +

+ +

luaJIT_setmode(L, idx, LUAJIT_MODE_WRAPCFUNC|flag)

+

+This mode defines a wrapper function for calls to C functions. The +first time this is called with LUAJIT_MODE_ON, the stack +index at idx must be a lightuserdata object holding +a pointer to the wrapper function. All subsequently created C +functions are called through the wrapper functions. After the initial +definition idx can be left at 0 when turning the mode +on or off. +

+

+The wrapper function can be used for debugging purposes or to catch +and convert foreign exceptions. Recommended usage can be seen in this +C++ code excerpt: +

+
+#include <exception>
+#include "lua.hpp"
+
+// Catch C++ exceptions and convert them to Lua error messages.
+// Customize as needed for your own exception classes.
+static int wrap_exceptions(lua_State *L, lua_CFunction f)
+{
+  try {
+    return f(L);  // Call wrapped function and return result.
+  } catch (const char *s) {  // Catch and convert exceptions.
+    lua_pushstring(L, s);
+  } catch (std::exception& e) {
+    lua_pushstring(L, e.what());
+  } catch (...) {
+    lua_pushliteral(L, "caught (...)");
+  }
+  return lua_error(L);  // Rethrow as a Lua error.
+}
+
+static int myregister(lua_State *L)
+{
+  ...
+  // Define wrapper function and enable it.
+  lua_pushlightuserdata(L, (void *)wrap_exceptions);
+  luaJIT_setmode(L, -1, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON);
+  lua_pop(L, 1);
+  luaL_register(L, "mymodule", myfuncs);  // Pass luaL_Reg list.
+  luaJIT_setmode(L, 0, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_OFF);
+  ...
+  // Wrap some more C++ functions which might throw an exception.
+  luaJIT_setmode(L, 0, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_ON);
+  lua_pushcfunction(L, mythrowingfunc1);
+  lua_pushcclosure(L, mythrowingfunc2, 1);
+  luaJIT_setmode(L, 0, LUAJIT_MODE_WRAPCFUNC|LUAJIT_MODE_OFF);
+  ...
+}
+
+

+Note that you can only define a single global wrapper function, +so be careful when using this mechanism from multiple C++ modules. +Also note that this mechanism is not without overhead. It should only +be enabled for definitions of C++ functions that can actually throw +exceptions. If you're embedding LuaJIT into an application, only +enable it after running luaL_openlibs. +

+

+LuaJIT already intercepts exception handling for systems using +ELF/DWARF2 stack unwinding (e.g. Linux). This is a zero-cost mechanism +and always enabled. You don't need to use any wrapper functions, +except when you want to get a more specific error message than +"C++ exception". +