Bladeren bron

bytecode-generator implemented in lua

mikymod 12 jaren geleden
bovenliggende
commit
f6b2f6840a
3 gewijzigde bestanden met toevoegingen van 84 en 4 verwijderingen
  1. 4 3
      third/x86/CMakeLists.txt
  2. 3 1
      third/x86_64/CMakeLists.txt
  3. 77 0
      tools/compilers/lua/bytecode-generator.lua

+ 4 - 3
third/x86/CMakeLists.txt

@@ -5,9 +5,10 @@ install (FILES 	luajit/include/luajit-2.0/lua.hpp
 				luajit/include/luajit-2.0/lua.h
 				luajit/include/luajit-2.0/luaconf.h
 				luajit/include/luajit-2.0/luajit.h
-				luajit/include/luajit-2.0/lualib.h DESTINATION include/crown)
+				luajit/include/luajit-2.0/lualib.h DESTINATION include/crown/luajit)
 				
 install (DIRECTORY luajit/lib/lua
 				   luajit/lib/pkgconfig DESTINATION lib/crown)
-install (FILES luajit/lib/libluajit-5.1.so.2.0.1
-			   luajit/lib/libluajit-5.1.so.2 DESTINATION lib/crown)
+install (FILES luajit/lib/libluajit-5.1.so.2.0.1 DESTINATION lib/crown)
+
+install (FILES luajit/bin/luajit-2.0.1 DESTINATION bin)

+ 3 - 1
third/x86_64/CMakeLists.txt

@@ -9,4 +9,6 @@ install (FILES 	luajit/include/luajit-2.0/lua.hpp
 				
 install (DIRECTORY luajit/lib/lua
 				   luajit/lib/pkgconfig DESTINATION lib/crown)
-install (FILES luajit/lib/libluajit-5.1.so.2.0.1 DESTINATION lib/crown)
+install (FILES luajit/lib/libluajit-5.1.so.2.0.1 DESTINATION lib/crown)
+
+install (FILES luajit/bin/luajit-2.0.1 DESTINATION bin)

+ 77 - 0
tools/compilers/lua/bytecode-generator.lua

@@ -0,0 +1,77 @@
+local root_path = arg[2]
+local dest_path = arg[4]
+
+-------------------------------------------------------------
+function get_files(path)
+
+	local files = {}
+	local tmp_file = 'tmp.txt'
+
+	os.execute('ls -1 ' .. path .. '*.lua > ' .. tmp_file)
+
+	local f = io.open(tmp_file)
+	if not f then
+		return
+	end
+
+	local i = 1;
+
+	for line in f:lines() do
+		files[i] = line
+		i = i + 1
+	end
+
+	f.close()
+
+	return files
+
+end
+
+--------------------------------------------------------------
+function prepare_destination(files)
+	-- Portable bytecode
+	local ext = ".raw"
+	local raws =  {}
+
+	for i,s in ipairs(files) do
+		raws[i] = string.sub(s, 1 + string.len(root_path))
+		local len = string.len(raws[i])
+		raws[i] = string.sub(raws[i], 1, len -4)
+		raws[i] = raws[i] .. ext
+		raws[i] = dest_path .. raws[i]
+	end
+
+	return raws
+end
+
+
+
+--------------------------------------------------------------
+function generate_bytecode(src, dest)
+
+	local chunk = string.dump(loadfile(src), true)
+
+	local f,err = io.open(dest, "w")
+
+	if not f then 
+		return print(err) 
+	end
+
+	f:write(chunk)
+
+	f:close()
+
+end
+
+--------------------------------------------------------------
+
+local src  = get_files(root_path)
+
+local dest = prepare_destination(src)
+
+for i,s in ipairs(src) do
+	generate_bytecode(s, dest[i])
+end
+
+
+