Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added annotations to individual fields in a struct #347

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM alpine:edge

RUN apk update && apk add git clang-dev clang-libs clang-static llvm7 llvm7-dev llvm7-libs llvm7-static libexecinfo libexecinfo-dev libffi-dev zlib-dev cmake make build-base

WORKDIR /terra/build

COPY . /terra

RUN cmake -d .. && make clean && make && make test

FROM alpine:latest

RUN apk add zlib zlib-dev libffi libffi-dev libexecinfo libexecinfo-dev libstdc++ libc-dev build-base

COPY --from=0 /terra/build/bin/terra /usr/bin/terra
COPY --from=0 /terra/build/include /usr/include
COPY --from=0 /terra/build/lib /usr/lib
COPY --from=0 /terra/tests /usr/share/terra/tests

CMD terra
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ endif

# llvm sometimes requires ncurses and libz, check if they have the symbols, and add them if they do
ifeq ($(shell nm $(LLVM_PREFIX)/lib/libLLVMSupport.a | grep setupterm >/dev/null 2>&1; echo $$?), 0)
SUPPORT_LIBRARY_FLAGS += -lcurses
SUPPORT_LIBRARY_FLAGS += -lcurses
endif
ifeq ($(shell nm $(LLVM_PREFIX)/lib/libLLVMSupport.a | grep compress2 >/dev/null 2>&1; echo $$?), 0)
SUPPORT_LIBRARY_FLAGS += -lz
Expand All @@ -143,7 +143,7 @@ PACKAGE_DEPS += $(LUAJIT_LIB)

#makes luajit happy on osx 10.6 (otherwise luaL_newstate returns NULL)
ifeq ($(UNAME), Darwin)
LFLAGS += -pagezero_size 10000 -image_base 100000000
LFLAGS += -pagezero_size 10000 -image_base 100000000
endif

CLANG_RESOURCE_DIRECTORY=$(CLANG_PREFIX)/lib/clang/$(LLVM_VERSION_NUM)
Expand All @@ -158,7 +158,7 @@ FLAGS += -DTERRA_LLVM_HEADERS_HAVE_NDEBUG
endif

LIBOBJS = tkind.o tcompiler.o tllvmutil.o tcwrapper.o tinline.o terra.o lparser.o lstring.o lobject.o lzio.o llex.o lctype.o treadnumber.o tcuda.o tdebug.o tinternalizedfiles.o lj_strscan.o
LIBLUA = terralib.lua strict.lua cudalib.lua asdl.lua
LIBLUA = terralib.lua strict.lua cudalib.lua asdl.lua terralist.lua

EXEOBJS = main.o linenoise.o

Expand Down Expand Up @@ -213,15 +213,15 @@ build/lib/libluajit-5.1.a: build/$(LUAJIT_TAR)
# MACOSX_DEPLOYMENT_TARGET is a workaround for https://github.com/LuaJIT/LuaJIT/issues/484
(cd $(LUAJIT_DIR); $(MAKE) install PREFIX=$(realpath build) CC=$(CC) STATIC_CC="$(CC) -fPIC" MACOSX_DEPLOYMENT_TARGET=10.6)

release/include/terra/%.h: $(LUAJIT_INCLUDE)/%.h $(LUAJIT_LIB)
release/include/terra/%.h: $(LUAJIT_INCLUDE)/%.h $(LUAJIT_LIB)
cp $(LUAJIT_INCLUDE)/$*.h $@

build/llvm_objects/llvm_list: $(addprefix build/, $(LIBOBJS) $(EXEOBJS))
mkdir -p build/llvm_objects/luajit
$(CXX) -o /dev/null $(addprefix build/, $(LIBOBJS) $(EXEOBJS)) $(LLVM_LIBRARY_FLAGS) $(SUPPORT_LIBRARY_FLAGS) $(LFLAGS) -Wl,-t 2>&1 | egrep "lib(LLVM|clang)" > build/llvm_objects/llvm_list
# extract needed LLVM objects based on a dummy linker invocation
< build/llvm_objects/llvm_list $(LUAJIT) src/unpacklibraries.lua build/llvm_objects
# include all luajit objects, since the entire lua interface is used in terra
# include all luajit objects, since the entire lua interface is used in terra


build/lua_objects/lj_obj.o: $(LUAJIT_LIB)
Expand All @@ -245,7 +245,7 @@ $(LIBRARY_NOLUA_NOLLVM): $(RELEASE_HEADERS) $(addprefix build/, $(LIBOBJS))
$(AR) -cq $@ $(addprefix build/, $(LIBOBJS))

$(DYNLIBRARY): $(LIBRARY)
$(CXX) $(DYNFLAGS) $(TERRA_STATIC_LIBRARY) $(SUPPORT_LIBRARY_FLAGS) -o $@
$(CXX) $(DYNFLAGS) $(TERRA_STATIC_LIBRARY) $(SUPPORT_LIBRARY_FLAGS) -o $@

$(EXECUTABLE): $(addprefix build/, $(EXEOBJS)) $(LIBRARY)
mkdir -p release/bin release/lib
Expand All @@ -264,12 +264,12 @@ build/%.h: build/%.bc $(PACKAGE_DEPS)

#run clang on a C file to extract the header search paths for this architecture
#genclangpaths.lua find the path arguments and formats them into a C file that is included by the cwrapper
#to configure the paths
#to configure the paths
build/clangpaths.h: src/dummy.c $(PACKAGE_DEPS) src/genclangpaths.lua
$(LUAJIT) src/genclangpaths.lua $@ $(CLANG) $(CUDA_INCLUDES)

build/internalizedfiles.h: $(PACKAGE_DEPS) src/geninternalizedfiles.lua lib/std.t lib/parsing.t
$(LUAJIT) src/geninternalizedfiles.lua $@ $(CLANG_RESOURCE_DIRECTORY) "%.h$$" $(CLANG_RESOURCE_DIRECTORY) "%.modulemap$$" lib "%.t$$"
$(LUAJIT) src/geninternalizedfiles.lua $@ $(CLANG_RESOURCE_DIRECTORY) "%.h$$" $(CLANG_RESOURCE_DIRECTORY) "%.modulemap$$" lib "%.t$$"

clean:
rm -rf build/*.o build/*.d $(GENERATEDHEADERS)
Expand Down Expand Up @@ -298,7 +298,7 @@ build/%.d: src/%.cpp $(PACKAGE_DEPS) $(GENERATEDHEADERS)
build/%.d: src/%.c $(PACKAGE_DEPS) $(GENERATEDHEADERS)
@$(CC) $(FLAGS) -w -MM -MT '$@ $(@:.d=.o)' $< -o $@

#if we are cleaning, then don't include dependencies (which would require the header files are built)
#if we are cleaning, then don't include dependencies (which would require the header files are built)
ifeq ($(findstring $(MAKECMDGOALS),download purge clean release),)
-include $(DEPENDENCIES)
endif
18 changes: 18 additions & 0 deletions dockerfiles/terra-bin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ubuntu:16.04

RUN apt-get update
RUN apt-get install -y curl zip

WORKDIR /terra

RUN curl -L https://github.com/zdevito/terra/releases/download/release-1.0.0-beta1/terra-Linux-x86_64-2e2032e.zip -o /terra/terra.zip

RUN unzip terra.zip

CMD ["bash"]

FROM ubuntu:16.04

COPY --from=0 /terra/terra-Linux-x86_64-2e2032e/ /

ENTRYPOINT [ "/bin/terra" ]
9 changes: 5 additions & 4 deletions msvc/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Edit these three paths to your
# Edit these three paths to your
# (1) LLVM install (should have bin/ include/ and lib/ directories)
# (2) LuaJIT 2.0.5 download directory (does not need to be built)
# (3) directory where you downloaded the Terra source
Expand Down Expand Up @@ -115,8 +115,9 @@ $(LUAJIT) $(TERRA_DIR)\release\include\terra\lua.h: $(LUAJIT_DIR)\src\luajit.c
copy lauxlib.h $(TERRA_DIR)\release\include\terra
copy luaconf.h $(TERRA_DIR)\release\include\terra

$(BUILD)\terralib.h $(BUILD)\strict.h $(BUILD)\cudalib.h: $(SRC)\terralib.lua $(SRC)\strict.lua $(SRC)\cudalib.lua $(LUAJIT) $(TERRA_DIR)\release\include\terra\lua.h
$(BUILD)\terralist.h $(BUILD)\terralib.h $(BUILD)\strict.h $(BUILD)\cudalib.h: $(SRC)\terralist.lua $(SRC)\terralib.lua $(SRC)\strict.lua $(SRC)\cudalib.lua $(LUAJIT) $(TERRA_DIR)\release\include\terra\lua.h
set LUA_PATH=$(LUAJIT_DIR)\src\?.lua
$(LUAJIT) -bg $(SRC)\terralist.lua $(BUILD)\terralist.h
$(LUAJIT) -bg $(SRC)\terralib.lua $(BUILD)\terralib.h
$(LUAJIT) -bg $(SRC)\strict.lua $(BUILD)\strict.h
$(LUAJIT) -bg $(SRC)\cudalib.lua $(BUILD)\cudalib.h
Expand All @@ -128,11 +129,11 @@ $(BUILD)\clangpaths.h: $(LUAJIT) $(SRC)\genclangpaths.lua

$(BUILD)\internalizedfiles.h: $(LUAJIT) $(SRC)\geninternalizedfiles.lua
cd $(TERRA_DIR)
$(LUAJIT) src\geninternalizedfiles.lua build\internalizedfiles.h $(CLANG_RESOURCE_DIRECTORY) "%.h$$" $(CLANG_RESOURCE_DIRECTORY) "%.modulemap$$" $(TERRA_DIR)\lib "%.t$$"
$(LUAJIT) src\geninternalizedfiles.lua build\internalizedfiles.h $(CLANG_RESOURCE_DIRECTORY) "%.h$$" $(CLANG_RESOURCE_DIRECTORY) "%.modulemap$$" $(TERRA_DIR)\lib "%.t$$"

EXPORTS = /EXPORT:terra_init /EXPORT:terra_initwithoptions /EXPORT:terra_load /EXPORT:terra_loadfile /EXPORT:terra_loadbuffer /EXPORT:terra_loadstring /EXPORT:terra_llvmshutdown

$(BUILD)\terra.obj: $(BUILD)\clangpaths.h $(BUILD)\internalizedfiles.h $(BUILD)\terralib.h $(BUILD)\strict.h $(BUILD)\cudalib.h $(TERRALIB_SRC)
$(BUILD)\terra.obj: $(BUILD)\clangpaths.h $(BUILD)\internalizedfiles.h $(BUILD)\terralist.h $(BUILD)\terralib.h $(BUILD)\strict.h $(BUILD)\cudalib.h $(TERRALIB_SRC)
cd $(BUILD)
$(CPP) $(CPPFLAGS) /c $(TERRALIB_SRC)

Expand Down
7 changes: 7 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_custom_command(
)

list(APPEND TERRA_LIB_LUA_SRC
terralist.lua
terralib.lua
strict.lua
cudalib.lua
Expand Down Expand Up @@ -280,6 +281,12 @@ elseif(UNIX)
${ALL_LLVM_LIBRARIES}
${LLVM_SYSTEM_LIBRARIES}
)
if(EXISTS /usr/lib/libexecinfo.a) # on musl-libc systems like alpine, this is a separate Library
target_link_libraries(TerraExecutable
PRIVATE
-lexecinfo
)
endif()
else()
target_link_libraries(TerraExecutable
PRIVATE
Expand Down
68 changes: 16 additions & 52 deletions src/asdl.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,4 @@
local List = {}
List.__index = List
for k,v in pairs(table) do
List[k] = v
end
setmetatable(List, { __call = function(self, lst)
if lst == nil then
lst = {}
end
return setmetatable(lst,self)
end})
function List:map(fn,...)
local l = List()
if type(fn) == "function" then
for i,v in ipairs(self) do
l[i] = fn(v,...)
end
else
for i,v in ipairs(self) do
local sel = v[fn]
if type(sel) == "function" then
l[i] = sel(v,...)
else
l[i] = sel
end
end
end
return l
end
function List:insertall(elems)
for i,e in ipairs(elems) do
self:insert(e)
end
end
function List:isclassof(exp)
return getmetatable(exp) == self
end
local List = require 'terralist'

local Context = {}
function Context:__index(idx)
Expand Down Expand Up @@ -98,12 +62,12 @@ local function parseAll(text)
next()
return v
end

local namespace = ""
local function parseDefinedName()
return namespace..expect("Ident")
end

local function parseField()
local f = {}
f.type = expect("Ident")
Expand Down Expand Up @@ -150,7 +114,7 @@ local function parseAll(text)
until not nextif("|")
if nextif("attributes") then
local attributes = parseFields()
for i,ctor in ipairs(sum.constructors) do
for i,ctor in ipairs(sum.constructors) do
ctor.fields = ctor.fields or List()
for i,a in ipairs(attributes) do
ctor.fields:insert(a)
Expand All @@ -159,7 +123,7 @@ local function parseAll(text)
end
return sum
end

local function parseType()
if cur == "(" then
return parseProduct()
Expand Down Expand Up @@ -239,7 +203,7 @@ local function checkuniquelist(checkt,listcache)
end
end

local defaultchecks = {}
local defaultchecks = {}
for i in string.gmatch("nil number string boolean table thread userdata cdata function","(%S+)") do
defaultchecks[i] = checkbuiltin(i)
end
Expand Down Expand Up @@ -299,15 +263,15 @@ end
function Context:DefineClass(name,unique,fields)
local mt = {}
local class = self.definitions[name]

if fields then
for _,f in ipairs(fields) do
for _,f in ipairs(fields) do
if f.namespace then -- resolve field type to fully qualified name
local fullname = f.namespace..f.type
if self.definitions[fullname] then
f.type = fullname
end
f.namespace = nil
f.namespace = nil
end
end
class.__fields = fields -- for reflection in user-defined behavior
Expand All @@ -319,16 +283,16 @@ function Context:DefineClass(name,unique,fields)
tns:insert(f.list and f.type.."*" or f.type)
checks:insert(self:GetCheckForField(unique,f))
end

if unique then
function mt:__call(...)
local node,key = self,"cache"
local obj = {}
for i = 1, #names do
local v = select(i,...)
local c,l = checks[i](v)
if not c then
reporterr(i,name,tns[i],v,l)
if not c then
reporterr(i,name,tns[i],v,l)
end
v = l or v -- use memoized list if it exists
obj[names[i]] = v
Expand Down Expand Up @@ -356,8 +320,8 @@ function Context:DefineClass(name,unique,fields)
for i = 1, #names do
local v = select(i,...)
local c,ii = checks[i](v)
if not c then
reporterr(i,name,tns[i],v,ii)
if not c then
reporterr(i,name,tns[i],v,ii)
end
obj[names[i]] = v
end
Expand Down Expand Up @@ -423,7 +387,7 @@ function Context:Define(text)
local parent = self:DefineClass(d.name,false,nil)
for i,c in ipairs(d.type.constructors) do
local child = self:DefineClass(c.name,c.unique,c.fields)
parent.members[child] = true --mark that any subclass is a member of its parent
parent.members[child] = true --mark that any subclass is a member of its parent
child.kind = basename(c.name)
if not c.fields then --single value, just create it
self:_SetDefinition(c.name, setmetatable({},child))
Expand All @@ -434,4 +398,4 @@ function Context:Define(text)
end
end
end
package.loaded["asdl"] = { NewContext = NewContext, List = List }
package.loaded["asdl"] = { NewContext = NewContext, List = List }
Loading