]> git.lizzy.rs Git - metalua.git/commitdiff
fixes on the compilation process separation through io.popen()
authorFabien Fleutot <fabien@MacFabien.home>
Thu, 25 Dec 2008 12:15:22 +0000 (13:15 +0100)
committerFabien Fleutot <fabien@MacFabien.home>
Thu, 25 Dec 2008 12:15:22 +0000 (13:15 +0100)
src/compiler/Makefile
src/compiler/bootstrap.lua
src/compiler/metalua.mlua
src/lib/metalua/package2.lua

index 02f1b42f523aed5d7ef293bf2fc637ab9429e2a6..2d9d88c8d4fec19397f181a3c1104d0e0eab0401 100644 (file)
@@ -50,14 +50,16 @@ mlp.luac: $(MLP_LUA)
        $(LUA_COMPILE) -o $@ bootstrap $<
 
 # Compiler/interpreter
-metalua: metalua.luac $(LIBRARIES)
+metalua: metalua.luac install-lib
        $(LUA_RUN) metalua.luac --verbose --sharpbang '#!$(TARGET_BIN_PATH)/lua' --output metalua --file metalua.mlua
 
-install: metalua $(LIBRARIES)
+install-lib: $(LIBRARIES)
+       mkdir -p $(TARGET_LUA_PATH)/metalua
+       cp $(LIBRARIES) $(TARGET_LUA_PATH)/metalua/
+
+install: install-lib metalua
        mkdir -p $(TARGET_BIN_PATH)
        cp metalua $(TARGET_BIN_PATH)/
-       mkdir -p $(TARGET_LUA_PATH)
-       cp $(LIBRARIES) $(TARGET_LUA_PATH)/
 
 .PHONY: all install
 
index 96c3d5542cf2ec7d924c7efad9219be26f52f666..507cdb813bd4e6c220ed8198c57d390854f183dc 100644 (file)
@@ -37,12 +37,17 @@ package.preload['metalua.mlc'] = function()
       f:close()
       return mlc.function_of_luastring (src, "@"..name)
    end
+
+   -- don't let require() fork a separate process for *.mlua compilations.
+   package.metalua_nopopen = true
 end
 
+package.path = '?.luac;?.lua;../lib/?.luac;../lib/?.lua'
+
 require 'verbose_require'
 require 'metalua.base'
-require 'metalua.bytecode'
-require 'metalua.mlp'
+require 'bytecode'
+require 'mlp'
 require 'metalua.package2'
 
 local function compile_file (src_filename)
index 9e1fdc38a9a1886cae2203715cecc05eb61191b4..934243504d32a873399634bfe7a1869fa822445e 100644 (file)
@@ -13,10 +13,9 @@ BYTECODE_SYNTHESE_ERROR_NUMBER  = -100
 -{ extension 'match' }
 
 function spring_pcall (f, arg, name)
-   -- FIXME: won't work if `arg' or `name' contain a backslash-escaped quot char.
-   arg  = arg  :gsub ("'", "\\'")
-   name = name :gsub ("'", "\\'")
-   local pattern = [[lua -l metalua.mlc -l serialize -e "print(serialize(%s('%s', '%s')))"]]
+   local pattern = 
+      [=[lua -l metalua.compiler -l serialize -e ]=]..
+      [=["print (serialize (%s ([[%s]], [[%s]])))"]=]
    local cmd = string.format (pattern, f, arg, name)
    --print ("Running the following process: " .. cmd)
    local fd = io.popen (cmd)
index 7ab8abc4aab62f49563d016fe88d8321d2df3990..6940ef04a4a465a4f5b9761b650a09ea2fbe6f4d 100644 (file)
@@ -43,19 +43,26 @@ function package.findfile(name, path_string)
    return false, table.concat(errors, "\n")..'\n'
 end
 
-
 ----------------------------------------------------------------------
 -- Execute a metalua module sources compilation in a separate process
+-- Sending back the bytecode directly is difficult, as some shells
+-- (at least MS-Windows') interpret some characters. So rather than
+-- base64-encoding the bytecode, AST is returned from the child
+-- process, and converted to bytecode then function in the calling
+-- process.
 ----------------------------------------------------------------------
 local function spring_load(filename)
+   -- FIXME: handle compilation errors
    local pattern = 
-      [[lua -l metalua.mlc -l -e "print(mlc.luacstring_of_luafile('%s', '%s'))"]]
-   local cmd = string.format (pattern, f, filename, filename)
-   print ("running command: ``" .. cmd .. "''")
+      [=[lua -l metalua.compiler -l serialize -e ]=]..
+      [=["print(serialize(mlc.ast_of_luafile [[%s]]))"]=]
+   local cmd = string.format (pattern, filename)
+   --print ("running command: ``" .. cmd .. "''")
    local fd = io.popen (cmd)
-   local bytecode = fd:read '*a'
+   local ast_src = fd:read '*a'
    fd:close()
-   return string.undump (bytecode)
+   local ast = lua_loadstring (ast_src) () -- much faster than loadstring()
+   return mlc.function_of_ast (ast, filename)
 end
 
 ----------------------------------------------------------------------
@@ -64,8 +71,14 @@ end
 function package.metalua_loader (name)
    local file, filename_or_msg = package.findfile (name, package.mpath)
    if not file then return filename_or_msg end
-   file:close()
-   return spring_load(filename_or_msg)
+   if package.metalua_nopopen then
+      local luastring = file:read '*a'
+      file:close()
+      return mlc.function_of_luastring (luastring, name)
+   else
+      file:close()
+      return spring_load (filename_or_msg)
+   end
 end
 
 ----------------------------------------------------------------------