Skip to content

Commit

Permalink
Merge terralist.lua from the develop branch (#409)
Browse files Browse the repository at this point in the history
* Merge terralist.lua from the develop branch.

* Fix Windows build.
  • Loading branch information
elliottslaughter authored Oct 8, 2019
1 parent 39764e6 commit 984a546
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion msvc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ $(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)\terralib.h" "$(BUILD)\strict.h" "$(BUILD)\cudalib.h" "$(BUILD)\asdl.h" "$(BUILD)\terralist.h": "$(SRC)\terralib.lua" "$(SRC)\strict.lua" "$(SRC)\cudalib.lua" "$(SRC)\asdl.lua" "$(SRC)\terralist.lua" $(LUAJIT) "$(TERRA_DIR)\release\include\terra\lua.h"
set LUA_PATH=$(LUAJIT_DIR)\src\?.lua
$(LUAJIT) -bg "$(SRC)\terralib.lua" "$(BUILD)\terralib.h"
$(LUAJIT) -bg "$(SRC)\strict.lua" "$(BUILD)\strict.h"
$(LUAJIT) -bg "$(SRC)\cudalib.lua" "$(BUILD)\cudalib.h"
$(LUAJIT) -bg "$(SRC)\asdl.lua" "$(BUILD)\asdl.h"
$(LUAJIT) -bg "$(SRC)\terralist.lua" "$(BUILD)\terralist.h"

"$(BUILD)\clangpaths.h": $(LUAJIT) "$(SRC)\genclangpaths.lua"
cd "$(TERRA_DIR)"
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ list(APPEND TERRA_LIB_LUA_SRC
strict.lua
cudalib.lua
asdl.lua
terralist.lua
)

foreach(LUA_SRC ${TERRA_LIB_LUA_SRC})
Expand Down
38 changes: 1 addition & 37 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
2 changes: 2 additions & 0 deletions src/terra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ int terra_lualoadstring(lua_State * L) {
#include "terralib.h"
#include "strict.h"
#include "asdl.h"
#include "terralist.h"

int terra_loadandrunbytecodes(lua_State * L, const unsigned char * bytecodes, size_t size, const char * name) {
return luaL_loadbuffer(L, (const char *)bytecodes, size, name)
Expand Down Expand Up @@ -245,6 +246,7 @@ int terra_initwithoptions(lua_State * L, terra_Options * options) {
return err;
}
err = terra_loadandrunbytecodes(T->L,(const unsigned char*)luaJIT_BC_strict,luaJIT_BC_strict_SIZE, "strict.lua")
|| terra_loadandrunbytecodes(T->L,(const unsigned char*)luaJIT_BC_terralist,luaJIT_BC_terralist_SIZE, "terralist.lua")
|| terra_loadandrunbytecodes(T->L,(const unsigned char*)luaJIT_BC_asdl,luaJIT_BC_asdl_SIZE, "asdl.lua")
#ifndef TERRA_EXTERNAL_TERRALIB
|| terra_loadandrunbytecodes(T->L,(const unsigned char*)luaJIT_BC_terralib,luaJIT_BC_terralib_SIZE, "terralib.lua");
Expand Down
Loading

0 comments on commit 984a546

Please sign in to comment.