From 1cb5929c5c0ec3a146410cc4b8edc15040da55ca Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Wed, 18 Jun 2014 12:36:50 +0200 Subject: [PATCH] Compile debug.getmetatable(). Thanks to Karel Tuma. --- src/lib_debug.c | 2 +- src/lj_ffrecord.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/lib_debug.c b/src/lib_debug.c index 97f032f1..9c1a2828 100644 --- a/src/lib_debug.c +++ b/src/lib_debug.c @@ -29,7 +29,7 @@ LJLIB_CF(debug_getregistry) return 1; } -LJLIB_CF(debug_getmetatable) +LJLIB_CF(debug_getmetatable) LJLIB_REC(.) { lj_lib_checkany(L, 1); if (!lua_getmetatable(L, 1)) { diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c index 8470dd8c..1fff4f48 100644 --- a/src/lj_ffrecord.c +++ b/src/lj_ffrecord.c @@ -1157,6 +1157,28 @@ static void LJ_FASTCALL recff_io_flush(jit_State *J, RecordFFData *rd) J->base[0] = TREF_TRUE; } +/* -- Debug library fast functions ---------------------------------------- */ + +static void LJ_FASTCALL recff_debug_getmetatable(jit_State *J, RecordFFData *rd) +{ + GCtab *mt; + TRef mtref; + TRef tr = J->base[0]; + if (tref_istab(tr)) { + mt = tabref(tabV(&rd->argv[0])->metatable); + mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_TAB_META); + } else if (tref_isudata(tr)) { + mt = tabref(udataV(&rd->argv[0])->metatable); + mtref = emitir(IRT(IR_FLOAD, IRT_TAB), tr, IRFL_UDATA_META); + } else { + mt = tabref(basemt_obj(J2G(J), &rd->argv[0])); + J->base[0] = mt ? lj_ir_ktab(J, mt) : TREF_NIL; + return; + } + emitir(IRTG(mt ? IR_NE : IR_EQ, IRT_TAB), mtref, lj_ir_knull(J, IRT_TAB)); + J->base[0] = mt ? mtref : TREF_NIL; +} + /* -- Record calls to fast functions -------------------------------------- */ #include "lj_recdef.h"