From ecacaa16796172d82557370b9de6f312a020f4aa Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Wed, 14 Sep 2011 07:47:25 +0000
Subject: [PATCH] applied luajitbeta8 patch

Elementals are now stun/blind/confusion/knockback immune


git-svn-id: http://svn.net-core.org/repos/t-engine4@4399 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/data/general/npcs/faeros.lua    |  4 ++++
 .../modules/tome/data/general/npcs/gwelgoroth.lua |  4 ++++
 game/modules/tome/data/general/npcs/losgoroth.lua |  4 ++++
 .../modules/tome/data/general/npcs/telugoroth.lua |  4 ++++
 src/luajit2/src/buildvm_asm.c                     |  6 ++++--
 src/luajit2/src/lj_asm.c                          | 10 +++++++---
 src/luajit2/src/lj_err.c                          | 15 +++++++++++----
 src/luajit2/src/lj_ircall.h                       | 11 +++++++++--
 src/luajit2/src/lj_snap.c                         |  2 +-
 9 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/game/modules/tome/data/general/npcs/faeros.lua b/game/modules/tome/data/general/npcs/faeros.lua
index a73d01604e..4385b51176 100644
--- a/game/modules/tome/data/general/npcs/faeros.lua
+++ b/game/modules/tome/data/general/npcs/faeros.lua
@@ -45,6 +45,10 @@ newEntity{
 	no_breath = 1,
 	poison_immune = 1,
 	disease_immune = 1,
+	stun_immune = 1,
+	blind_immune = 1,
+	knockback_immune = 1,
+	confusion_immune = 1,
 	on_die = function(self, who)
 		local part = "FAEROS_ASH"
 		if game.player:hasQuest("brotherhood-of-alchemists") then
diff --git a/game/modules/tome/data/general/npcs/gwelgoroth.lua b/game/modules/tome/data/general/npcs/gwelgoroth.lua
index 09f13ed931..b95c675fac 100644
--- a/game/modules/tome/data/general/npcs/gwelgoroth.lua
+++ b/game/modules/tome/data/general/npcs/gwelgoroth.lua
@@ -45,6 +45,10 @@ newEntity{
 	no_breath = 1,
 	poison_immune = 1,
 	disease_immune = 1,
+	stun_immune = 1,
+	blind_immune = 1,
+	knockback_immune = 1,
+	confusion_immune = 1,
 }
 
 newEntity{ base = "BASE_NPC_GWELGOROTH",
diff --git a/game/modules/tome/data/general/npcs/losgoroth.lua b/game/modules/tome/data/general/npcs/losgoroth.lua
index b813d82d9f..02d4d7fbdd 100644
--- a/game/modules/tome/data/general/npcs/losgoroth.lua
+++ b/game/modules/tome/data/general/npcs/losgoroth.lua
@@ -47,6 +47,10 @@ newEntity{
 	no_breath = 1,
 	poison_immune = 1,
 	disease_immune = 1,
+	stun_immune = 1,
+	blind_immune = 1,
+	knockback_immune = 1,
+	confusion_immune = 1,
 }
 
 newEntity{ base = "BASE_NPC_LOSGOROTH",
diff --git a/game/modules/tome/data/general/npcs/telugoroth.lua b/game/modules/tome/data/general/npcs/telugoroth.lua
index 43ff2e1308..8af421aa41 100644
--- a/game/modules/tome/data/general/npcs/telugoroth.lua
+++ b/game/modules/tome/data/general/npcs/telugoroth.lua
@@ -46,6 +46,10 @@ newEntity{
 	no_breath = 1,
 	poison_immune = 1,
 	disease_immune = 1,
+	stun_immune = 1,
+	blind_immune = 1,
+	knockback_immune = 1,
+	confusion_immune = 1,
 }
 
 newEntity{ base = "BASE_NPC_TELUGOROTH",
diff --git a/src/luajit2/src/buildvm_asm.c b/src/luajit2/src/buildvm_asm.c
index 49d6ffcaea..5cfa7ae81d 100644
--- a/src/luajit2/src/buildvm_asm.c
+++ b/src/luajit2/src/buildvm_asm.c
@@ -191,7 +191,8 @@ void emit_asm(BuildCtx *ctx)
   if (ctx->mode != BUILD_machasm)
     fprintf(ctx->fp, ".Lbegin:\n");
 
-#if LJ_TARGET_ARM && defined(__GNUC__) && !defined(__symbian__)
+#if LJ_TARGET_ARM && defined(__GNUC__) && !defined(__symbian__) && \
+    !LJ_TARGET_OSX
   /* This should really be moved into buildvm_arm.dasc. */
   fprintf(ctx->fp,
 	  ".fnstart\n"
@@ -227,7 +228,8 @@ void emit_asm(BuildCtx *ctx)
 #endif
   }
 
-#if LJ_TARGET_ARM && defined(__GNUC__) && !defined(__symbian__)
+#if LJ_TARGET_ARM && defined(__GNUC__) && !defined(__symbian__) && \
+    !LJ_TARGET_OSX
   fprintf(ctx->fp,
 	  ".globl lj_err_unwind_arm\n"
 	  ".personality lj_err_unwind_arm\n"
diff --git a/src/luajit2/src/lj_asm.c b/src/luajit2/src/lj_asm.c
index b3fa773979..adb5a9ceee 100644
--- a/src/luajit2/src/lj_asm.c
+++ b/src/luajit2/src/lj_asm.c
@@ -859,19 +859,23 @@ static uint32_t ir_khash(IRIns *ir)
   return hashrot(lo, hi);
 }
 
+#if !LJ_TARGET_X86ORX64 && LJ_TARGET_OSX
+void sys_icache_invalidate(void *start, size_t len);
+#endif
+
 /* Flush instruction cache. */
 static void asm_cache_flush(MCode *start, MCode *end)
 {
   VG_INVALIDATE(start, (char *)end-(char *)start);
 #if LJ_TARGET_X86ORX64
   UNUSED(start); UNUSED(end);
-#else
-#if defined(__GNUC__)
+#elif LJ_TARGET_OSX
+  sys_icache_invalidate(start, end-start);
+#elif defined(__GNUC__)
   __clear_cache(start, end);
 #else
 #error "Missing builtin to flush instruction cache"
 #endif
-#endif
 }
 
 /* -- Allocations --------------------------------------------------------- */
diff --git a/src/luajit2/src/lj_err.c b/src/luajit2/src/lj_err.c
index 42bb87fc66..35dfeabb8f 100644
--- a/src/luajit2/src/lj_err.c
+++ b/src/luajit2/src/lj_err.c
@@ -178,7 +178,8 @@ static void *err_unwind(lua_State *L, void *stopcf, int errcode)
 
 /* -- External frame unwinding -------------------------------------------- */
 
-#if defined(__GNUC__) && !defined(__symbian__)
+#if defined(__GNUC__) && !defined(__symbian__) && \
+    !(LJ_TARGET_ARM && LJ_TARGET_OSX)
 
 #ifdef __clang__
 /* http://llvm.org/bugs/show_bug.cgi?id=8703 */
@@ -227,7 +228,9 @@ LJ_FUNCA int lj_err_unwind_dwarf(int version, _Unwind_Action actions,
     }
 #if LJ_UNWIND_EXT
     cf = err_unwind(L, cf, errcode);
-    if (cf) {
+    if ((actions & _UA_FORCE_UNWIND)) {
+      return _URC_CONTINUE_UNWIND;
+    } else if (cf) {
       _Unwind_SetGR(ctx, LJ_TARGET_EHRETREG, errcode);
       _Unwind_SetIP(ctx, (_Unwind_Ptr)(cframe_unwind_ff(cf) ?
 				       lj_vm_unwind_ff_eh :
@@ -255,8 +258,12 @@ LJ_FUNCA int lj_err_unwind_dwarf(int version, _Unwind_Action actions,
 }
 
 #if LJ_UNWIND_EXT
-/* NYI: this is not thread-safe. */
+#if LJ_TARGET_OSX
+/* Sorry, no thread safety for OSX. Complain to Apple, not me. */
 static struct _Unwind_Exception static_uex;
+#else
+static __thread struct _Unwind_Exception static_uex;
+#endif
 
 /* Raise DWARF2 exception. */
 static void err_raise_ext(int errcode)
@@ -280,7 +287,7 @@ LJ_FUNCA _Unwind_Reason_Code lj_err_unwind_arm(_Unwind_State state,
     setstrV(L, L->top++, lj_err_str(L, LJ_ERR_ERRCPP));
     return _URC_HANDLER_FOUND;
   }
-  if ((state & _US_ACTION_MASK) == _US_UNWIND_FRAME_STARTING) {
+  if ((state&(_US_ACTION_MASK|_US_FORCE_UNWIND)) == _US_UNWIND_FRAME_STARTING) {
     _Unwind_DeleteException(ucb);
     _Unwind_SetGR(ctx, 15, (_Unwind_Word)(void *)lj_err_throw);
     _Unwind_SetGR(ctx, 0, (_Unwind_Word)L);
diff --git a/src/luajit2/src/lj_ircall.h b/src/luajit2/src/lj_ircall.h
index 3b0a54b6f4..a1f0b05298 100644
--- a/src/luajit2/src/lj_ircall.h
+++ b/src/luajit2/src/lj_ircall.h
@@ -182,8 +182,6 @@ LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];
 #define softfp_f2d __aeabi_f2d
 #define softfp_d2i __aeabi_d2iz
 #define softfp_d2ui __aeabi_d2uiz
-#define softfp_d2l __aeabi_d2lz
-#define softfp_d2ul __aeabi_d2ulz
 #define softfp_d2f __aeabi_d2f
 #define softfp_i2f __aeabi_i2f
 #define softfp_ui2f __aeabi_ui2f
@@ -191,8 +189,17 @@ LJ_DATA const CCallInfo lj_ir_callinfo[IRCALL__MAX+1];
 #define softfp_ul2f __aeabi_ul2f
 #define softfp_f2i __aeabi_f2iz
 #define softfp_f2ui __aeabi_f2uiz
+#if LJ_TARGET_OSX
+#define softfp_d2l __fixdfdi
+#define softfp_d2ul __fixunsdfdi
+#define softfp_f2l __fixsfdi
+#define softfp_f2ul __fixunssfdi
+#else
+#define softfp_d2l __aeabi_d2lz
+#define softfp_d2ul __aeabi_d2ulz
 #define softfp_f2l __aeabi_f2lz
 #define softfp_f2ul __aeabi_f2ulz
+#endif
 #else
 #error "Missing soft-float definitions for target architecture"
 #endif
diff --git a/src/luajit2/src/lj_snap.c b/src/luajit2/src/lj_snap.c
index 9124b7896b..e29b535711 100644
--- a/src/luajit2/src/lj_snap.c
+++ b/src/luajit2/src/lj_snap.c
@@ -192,7 +192,7 @@ static BCReg snap_usedef(jit_State *J, uint8_t *udf,
     handle_jump: {
       BCReg minslot = bc_a(ins);
       if (op >= BC_FORI && op <= BC_JFORL) minslot += FORL_EXT;
-      else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-1])-1;
+      else if (op >= BC_ITERL && op <= BC_JITERL) minslot += bc_b(pc[-2])-1;
       else if (op == BC_UCLO) { pc += bc_j(ins); break; }
       for (s = minslot; s < maxslot; s++) DEF_SLOT(s);
       return minslot < maxslot ? minslot : maxslot;
-- 
GitLab