]> git.lizzy.rs Git - metalua.git/commitdiff
changed package loader and metalua compiler: instead of running compilations in separ...
authorunknown <Fabien@.(none)>
Thu, 18 Dec 2008 14:45:12 +0000 (15:45 +0100)
committerunknown <Fabien@.(none)>
Thu, 18 Dec 2008 14:45:12 +0000 (15:45 +0100)
src/compiler/metalua.mlua
src/lib/metalua/package2.lua

index 68e63ffa80b93e72010be1bd30c578783a6c87c7..265f06b8e79f37c80bccea964c2a397a89a44955 100644 (file)
@@ -4,25 +4,7 @@
 
 require 'metalua.compiler'
 require 'metalua.clopts'
-
-do
-   local mfast = os.getenv 'LUA_NOSPRINGS'
-   local has_springs = mfast~='yes' and mfast~='true' and pcall(require, 'springs')
-   if has_springs then
-      function spring_pcall(...)
-       local ring = springs.new()
-       ring:dostring (INIT_COMPILATION_RING)
-       st, ast = ring:pcall(...)
-       ring:close()
-       return st, ast
-      end
-   else
-      function spring_pcall(f, ...)
-         if type(f)=='string' then f = loadstring("return "..f)() end
-                return pcall(f, ...)
-         end
-   end
-end
+require 'serialize'
 
 AST_COMPILE_ERROR_NUMBER        = -1
 RUNTIME_ERROR_NUMBER            = -3
@@ -30,12 +12,27 @@ 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 cmd = string.format (pattern, f, arg, name)
+   --print ("Running the following process: " .. cmd)
+   local fd = io.popen (cmd)
+   local data = fd:read '*a'
+   fd:close()
+   --print (data)
+   local ast_builder, msg = lua_loadstring(data)
+   if not ast_builder then error ("can't compile data: "..msg) end
+   local ast = ast_builder()
+   return true, ast
+end
+
 local chunks  = { }
 local runargs = { }
 
-local acc_chunk = |kind| function (arg)
-   table.insert (chunks, { tag=kind, arg })
-end
+local acc_chunk = |kind| |arg| table.insert (chunks, { tag=kind, arg })
 
 parser = clopts {
    -- Chunk loading
@@ -102,9 +99,6 @@ flags lack, metalua tries to adopt a "Do What I Mean" approach:
   forbids it.
 ]]}
 
-
-INIT_COMPILATION_RING = [[require 'metalua.compiler']]
-
 local function main (...)
 
    local cfg = parser(...)
@@ -169,7 +163,7 @@ local function main (...)
          end
       end
       if not st then
-         printf ("Cannot compile %s: %s", table.tostring(x), ast)
+         printf ("Cannot compile %s: %s", table.tostring(x), ast or "no msg")
          os.exit (AST_COMPILE_ERROR_NUMBER)
       end
       ast.origin = x
@@ -252,9 +246,6 @@ local function main (...)
       verb_print "Starting REPL loop"
       require 'metalua.metaloop'
       metaloop.run()
---       print ("*":rep(70))
---       print "*** !!! Interactive loop not implemented !!!"
---       print ("*":rep(70))
    end
 
    verb_print "Done"
index abd691162cbdffc292081e50f321337fbfa57cb6..7ab8abc4aab62f49563d016fe88d8321d2df3990 100644 (file)
@@ -45,22 +45,17 @@ end
 
 
 ----------------------------------------------------------------------
--- Execute a metalua module sources compilation in a separate ring.
+-- Execute a metalua module sources compilation in a separate process
 ----------------------------------------------------------------------
 local function spring_load(filename)
-   local env_fast = os.getenv 'LUA_NOSPRINGS'
-   local try_springs = env_fast=='yes' or env_fast=='true'
-   local has_springs = try_springs and pcall(require, 'springs')
-   if has_springs then
-      local r = springs.new()
-      r:dostring [[require 'metalua.compiler']]
-      local f = r:call('mlc.function_of_luafile', filename)
-      r:close()
-      return f
-   else
-      --print "LUA_NOSPRINGS mode"
-      return mlc.function_of_luafile(filename)
-   end
+   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 .. "''")
+   local fd = io.popen (cmd)
+   local bytecode = fd:read '*a'
+   fd:close()
+   return string.undump (bytecode)
 end
 
 ----------------------------------------------------------------------