Ver Fonte

bytecode-generator adapted to Compiler.py

mikymod há 12 anos atrás
pai
commit
c518aa895e

+ 1 - 0
tools/compilers/lua/CMakeLists.txt

@@ -15,3 +15,4 @@ include_directories(${CROWN_THIRD}/luajit/include/luajit-2.0)
 target_link_libraries(lua-compiler crown-compiler-utils luajit-5.1)
 
 install (TARGETS lua-compiler DESTINATION bin)
+install (FILES bytecode-generator.lua DESTINATION bin)

+ 8 - 63
tools/compilers/lua/bytecode-generator.lua

@@ -1,77 +1,22 @@
-local root_path = arg[2]
-local dest_path = arg[4]
+local src = arg[1]
+local tmp = src .. ".tmp"
 
--------------------------------------------------------------
-function get_files(path)
 
-	local files = {}
-	local tmp_file = 'tmp.txt'
+local chunk = string.dump(loadfile(src), true)
 
-	os.execute('ls -1 ' .. path .. '*.lua > ' .. tmp_file)
+local f,err = io.open(tmp, "w")
 
-	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 = ".script"
-	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
+if not f then 
+	return print(err) 
 end
 
+f:write(chunk)
 
+f:close()
 
---------------------------------------------------------------
-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