From f4cf845f255cf55aaea1a0f3a94256a89c43247a Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Fri, 16 Nov 2018 09:45:13 -0800 Subject: [PATCH] Fall back to tonumber for uniquely identifying types in LuaJIT. --- src/asdl.lua | 2 +- src/terralib.lua | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/asdl.lua b/src/asdl.lua index 558c4fa8..23d7f847 100644 --- a/src/asdl.lua +++ b/src/asdl.lua @@ -457,4 +457,4 @@ function Context:Define(text) end end end -package.loaded["asdl"] = { NewContext = NewContext, List = List, iscdata = iscdata } +package.loaded["asdl"] = { NewContext = NewContext, List = List, isluajit = isluajit, iscdata = iscdata } diff --git a/src/terralib.lua b/src/terralib.lua index 9efbe754..4c881b89 100644 --- a/src/terralib.lua +++ b/src/terralib.lua @@ -3,6 +3,7 @@ local ffi = require("ffi") local asdl = require("asdl") local List = asdl.List +local isluajit = asdl.isluajit local iscdata = asdl.iscdata -- LINE COVERAGE INFORMATION, must run test script with luajit and not terra to avoid overwriting coverage with old version @@ -1445,10 +1446,14 @@ do --create a map from this ctype to the terra type to that we can implement terra.typeof(cdata) local ctype = ffi.typeof(self.cachedcstring) - types.ctypetoterra[tostring(ctype)] = self - -- FIXME: This is unimplemented in FFI wrapper for Lua - -- local rctype = ffi.typeof(self.cachedcstring.."&") - -- types.ctypetoterra[tostring(rctype)] = self + -- tonumber(ctype) is LuaJIT-only, so rely on printed representation in PUC Lua + local ctype_key = tonumber(ctype) or tostring(ctype) + types.ctypetoterra[ctype_key] = self + if isluajit() then + local rctype = ffi.typeof(self.cachedcstring.."&") + local rctype_key = tonumber(rctype) or tostring(rctype) + types.ctypetoterra[rctype_key] = self + end if self:isstruct() then local function index(obj,idx)