summaryrefslogtreecommitdiff
path: root/src/lj_crecord.c
diff options
context:
space:
mode:
authorMike Pall <mike>2012-10-10 18:16:18 +0200
committerMike Pall <mike>2012-10-10 18:16:18 +0200
commit1c626112a06f1f69d3c22771c62d4ced1cfee356 (patch)
tree6045efeabcc77b7a0351a65161e1d456bb635752 /src/lj_crecord.c
parent4a97faef7ef7e9b12235adcb98e3e591b0db7122 (diff)
downloadluajit2-1c626112a06f1f69d3c22771c62d4ced1cfee356.tar.gz
FFI: Compile ffi.sizeof(), ffi.alignof() and ffi.offsetof().
Diffstat (limited to 'src/lj_crecord.c')
-rw-r--r--src/lj_crecord.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index 6a22544a..f9220322 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -20,6 +20,7 @@
#include "lj_cconv.h"
#include "lj_clib.h"
#include "lj_ccall.h"
+#include "lj_ff.h"
#include "lj_ir.h"
#include "lj_jit.h"
#include "lj_ircall.h"
@@ -1587,7 +1588,27 @@ void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd)
emitir(IRTG(IR_EQ, IRT_STR), J->base[0], lj_ir_kstr(J, strV(&rd->argv[0])));
J->postproc = LJ_POST_FIXBOOL;
J->base[0] = TREF_TRUE;
- } /* else: interpreter will throw. */
+ } else {
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ }
+}
+
+/* Record ffi.sizeof(), ffi.alignof(), ffi.offsetof(). */
+void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd)
+{
+ CTypeID id = argv2ctype(J, J->base[0], &rd->argv[0]);
+ if (rd->data == FF_ffi_sizeof) {
+ CType *ct = lj_ctype_rawref(ctype_ctsG(J2G(J)), id);
+ if (ctype_isvltype(ct->info))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ } else if (rd->data == FF_ffi_offsetof) { /* Specialize to the field name. */
+ if (!tref_isstr(J->base[1]))
+ lj_trace_err(J, LJ_TRERR_BADTYPE);
+ emitir(IRTG(IR_EQ, IRT_STR), J->base[1], lj_ir_kstr(J, strV(&rd->argv[1])));
+ rd->nres = 3; /* Just in case. */
+ }
+ J->postproc = LJ_POST_FIXCONST;
+ J->base[0] = J->base[1] = J->base[2] = TREF_NIL;
}
/* -- Miscellaneous library functions ------------------------------------- */