From 7791f940733de4919ba928ac55ba3e7d86702f0a Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 16 Oct 2013 19:43:06 +0000 Subject: [PATCH] Lunatic: make it possible to build with LuaJIT 2.1, add -Lopts=profile there. git-svn-id: https://svn.eduke32.com/eduke32@4107 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile.common | 5 +++++ polymer/eduke32/build/include/lunatic.h | 6 +++++- polymer/eduke32/build/src/lunatic.c | 12 +++++++++--- polymer/eduke32/source/game.c | 1 + polymer/eduke32/source/lunatic/defs_common.lua | 11 ++++++++++- polymer/eduke32/source/lunatic/lunatic_game.c | 9 +++++++-- polymer/eduke32/source/lunatic/lunatic_m32.c | 6 +++++- 7 files changed, 42 insertions(+), 8 deletions(-) diff --git a/polymer/eduke32/Makefile.common b/polymer/eduke32/Makefile.common index 519379fbd..2795942ba 100644 --- a/polymer/eduke32/Makefile.common +++ b/polymer/eduke32/Makefile.common @@ -144,7 +144,9 @@ BUILD32_ON_64 ?= 0 USE_LIBPNG ?= 1 USE_LIBVPX ?= 1 NETCODE ?= 1 + LUNATIC ?= 0 +USE_LUAJIT_2_1 ?= 0 # EXPERIMENTAL, unfinished x86_64 assembly routines. DO NOT ENABLE. USE_ASM64 ?= 0 @@ -469,6 +471,9 @@ ifneq ($(LUNATIC),0) override DISABLEINLINING=1 BASECOMMONFLAGS+= -I$(MAKEFILE_COMMON_DIR)/source/lunatic -DLUNATIC + ifneq ($(USE_LUAJIT_2_1),0) + BASECOMMONFLAGS+= -DUSE_LUAJIT_2_1 + endif # Determine size of defs.ilua bytecode once. ifndef DEFS_BC_SIZE diff --git a/polymer/eduke32/build/include/lunatic.h b/polymer/eduke32/build/include/lunatic.h index d2c9b3855..dc415dbad 100644 --- a/polymer/eduke32/build/include/lunatic.h +++ b/polymer/eduke32/build/include/lunatic.h @@ -3,7 +3,11 @@ #ifndef ENGINE_LUNATIC_H_ #define ENGINE_LUNATIC_H_ -#include +#ifdef USE_LUAJIT_2_1 +# include +#else +# include +#endif typedef struct diff --git a/polymer/eduke32/build/src/lunatic.c b/polymer/eduke32/build/src/lunatic.c index 194629fe5..d5db75946 100644 --- a/polymer/eduke32/build/src/lunatic.c +++ b/polymer/eduke32/build/src/lunatic.c @@ -1,8 +1,14 @@ /* The Lunatic Interpreter, part of EDuke32. Common, engine-side stuff. */ -#include -#include -#include +#ifdef USE_LUAJIT_2_1 +# include +# include +# include +#else +# include +# include +# include +#endif #include "cache1d.h" #include "osd.h" diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 618b16118..a96124791 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -2873,6 +2873,7 @@ void G_GameExit(const char *msg) { #ifdef LUNATIC El_PrintTimes(); + El_DestroyState(&g_ElState); #endif if (*msg != 0) g_player[myconnectindex].ps->palette = BASEPAL; diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index 8f1a9f9e8..99b42af82 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -12,6 +12,7 @@ local ffiC = ffi.C local bit = require("bit") local bor = bit.bor +local pcall = pcall ffi.cdef "const char **g_argv;" @@ -22,12 +23,14 @@ ffi.cdef "const char **g_argv;" -- (env var: LUAJIT_VERBOSEFILE) -- dump: load LuaJIT's 'dump' module, printing generated IR/machine code -- (env var: LUAJIT_DUMPFILE) +-- profile: load LuaJIT's 'jit.p' module for profiling (LuaJIT 2.1 only) +-- (env var: LUAJIT_PROFILEFILE) -- strict: catch various conditions that may indicate an logical error -- TODO for strict: actor[], spriteext[], per-actor gamevars local debug_flags = {} local IS_DEBUG_FLAG = { diag=true, nojit=true, traces=true, dump=true, - strict=true, + strict=true, profile=true, } -- Handle command-line argument. (Look for -Lopts=...) @@ -64,6 +67,12 @@ if (not _LUNATIC_AUX) then elseif (debug_flags.traces) then require("v").on() end + + if (debug_flags.profile) then + if (pcall(function() require("jit.p").start() end) == false) then + print("Warning: failed enabing profiler. Running LuaJIT 2.0 build?") + end + end end local math = require("math") diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index 768f93973..f28755fe7 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -5,8 +5,13 @@ #include #include // strerror -#include -#include +#ifdef USE_LUAJIT_2_1 +# include +# include +#else +# include +# include +#endif #include "build.h" // printext256 diff --git a/polymer/eduke32/source/lunatic/lunatic_m32.c b/polymer/eduke32/source/lunatic/lunatic_m32.c index a59e8863f..ebd15a26e 100644 --- a/polymer/eduke32/source/lunatic/lunatic_m32.c +++ b/polymer/eduke32/source/lunatic/lunatic_m32.c @@ -1,6 +1,10 @@ /* The Lunatic Interpreter, part of EDuke32. Editor stuff. */ -#include +#ifdef USE_LUAJIT_2_1 +# include +#else +# include +#endif #include "lunatic_m32.h"