]> git.lizzy.rs Git - metalua.git/commitdiff
Merge commit 'origin/scoped-walk' into better-errors
authorFabien Fleutot <fabien@MacFabien.home>
Sun, 22 Feb 2009 09:35:05 +0000 (10:35 +0100)
committerFabien Fleutot <fabien@MacFabien.home>
Sun, 22 Feb 2009 09:35:05 +0000 (10:35 +0100)
src/compiler/gg.lua
src/lib/metalua/mlc_xcall.lua
src/make.sh

index afab9965042afba47315f509078d52a46a15ffc4..9a9ba2efc1a74e96df1297ec8828bb092084f8ac 100644 (file)
@@ -53,8 +53,12 @@ function parser_metatable.__call (parser, lx, ...)
       local li = lx:lineinfo_right() or { "?", "?", "?", "?" }
       local status, ast = pcall (parser.parse, parser, lx, ...)      
       if status then return ast else
+         -- Try to replace the gg.lua location, in the error msg, with
+         -- the place where the current parser started handling the
+         -- lexstream.
+         -- Since the error is rethrown, these places are stacked. 
          error (string.format ("%s\n - (l.%s, c.%s, k.%s) in parser %s", 
-                               ast:strmatch "gg.lua:%d+: (.*)" or ast,
+                               ast :strmatch "gg.lua:%d+: (.*)" or ast,
                                li[1], li[2], li[3], parser.name or parser.kind))
       end
    end
@@ -201,10 +205,14 @@ function sequence (p)
    -- Construction
    -------------------------------------------------------------------
    -- Try to build a proper name
-   if not p.name and type(p[1])=="string" then 
-      p.name = p[1].." ..." 
-      if type(p[#p])=="string" then p.name = p.name .. " " .. p[#p] end
-   else
+   if p.name then
+      -- don't touch existing name
+   elseif type(p[1])=="string" then -- find name based on 1st keyword
+      if #p==1 then p.name=p[1]
+      elseif type(p[#p])=="string" then
+         p.name = p[1] .. " ... " . p[#p]
+      else p.name = p[1] .. " ..." end
+   else -- can't find a decent name
       p.name = "<anonymous>"
    end
 
index a93744fad40f5aec485874795fa59a02538704e6..adfe673b6540b1c141a40c237ebc5a7f07d79181 100644 (file)
@@ -3,6 +3,18 @@
 
 mlc_xcall = { }
 
+
+-- This is the back-end function, called in a separate lua process
+-- by `mlc_xcall.client_*()' through `os.execute()'.
+--  * inputs:
+--     * the name of a lua source file to compile in a separate process
+--     * the name of a writable file where the resulting ast is dumped
+--       with `serialize()'.
+--  * results:
+--     * an exit status of 0 or -1, depending on whethet compilation
+--       succeeded;
+--     * the ast file filled will either the serialized ast, or the
+--       error message.
 function mlc_xcall.server (luafilename, astfilename)
 
    -- We don't want these to be loaded when people only do client-side business
@@ -10,30 +22,51 @@ function mlc_xcall.server (luafilename, astfilename)
    require 'serialize'
 
    -- compile the content of luafile name in an AST, serialized in astfilename
-   local ast = mlc.luafile_to_ast (luafilename)
+   local status, ast = pcall (mlc.luafile_to_ast, luafilename)
    local out = io.open (astfilename, 'w')
-   out:write (serialize (ast))
-   out:close ()
+   if status then -- success
+      out:write (serialize (ast))
+      out:close ()
+      os.exit (0)
+   else -- failure, `ast' is actually the error message
+      out:write (ast)
+      out:close ()
+      os.exit (-1)
+   end      
 end
 
+-- Compile the file whose name is passed as argument, in a separate process,
+-- communicating through a temporary file.
+-- returns:
+--  * true or false, indicating whether the compilation succeeded
+--  * the ast, or the error message.
 function mlc_xcall.client_file (luafile)
 
-   --printf("\n\nmlc_xcall.client_file(%q)\n\n", luafile)
+   -- printf("\n\nmlc_xcall.client_file(%q)\n\n", luafile)
 
    local tmpfilename = os.tmpname()
-   local cmd = string.format ([[lua -l metalua.mlc_xcall -e "mlc_xcall.server('%s', '%s')"]], 
-                             luafile :gsub ([[\]], [[\\]])
-                             tmpfilename :gsub([[\]], [[\\]]))
+   local cmd = string.format (
+      [=[lua -l metalua.mlc_xcall -e "mlc_xcall.server([[%s]], [[%s]])"]=]
+      luafile, tmpfilename)
 
-   --printf("os.execute [[%s]]\n\n", cmd)
+   -- printf("os.execute [[%s]]\n\n", cmd)
 
-   local ret = os.execute (cmd)
-   if ret~=0 then error "xcall failure. FIXME: transmit failure and backtrace" end
-   local ast = (lua_loadfile or loadfile) (tmpfilename) ()
+   local status = (0 == os.execute (cmd))
+   local result -- ast or error msg
+   if status then 
+      result = (lua_loadfile or loadfile) (tmpfilename) ()
+   else
+      local f = io.open (tmpfilename)
+      result = f :read '*a'
+      f :close()
+   end
    os.remove(tmpfilename)
-   return true, ast
+   return status, result
 end
 
+-- Compile a source string into an ast, by dumping it in a tmp
+-- file then calling `mlc_xcall.client_file()'.
+-- returns: the same as `mlc_xcall.client_file()'.
 function mlc_xcall.client_literal (luasrc)
    local srcfilename = os.tmpname()
    local srcfile, msg = io.open (srcfilename, 'w')
index 4d404648db97425113dd3b4b8d85112ea1267228..242ec2b1389a8f0448d39d05ff0a3e1b59d8db36 100755 (executable)
@@ -38,6 +38,10 @@ LUAC=$(which luac)
 
 # --- END OF USER-EDITABLE PART ---
 
+if [ -z ${LUA}  ] ; then echo "Error: no lua interpreter found"; fi
+if [ -z ${LUAC} ] ; then echo "Error: no lua compiler found"; fi
+
+if [ -f ~/.metaluabuildrc ] ; then . ~/.metaluabuildrc; fi
 
 echo '*** Lua paths setup ***'
 
@@ -48,7 +52,7 @@ echo '*** Create the distribution directories, populate them with lib sources **
 
 mkdir -p ${BUILD_BIN}
 mkdir -p ${BUILD_LIB}
-cp -R lib/* ${BUILD_LIB}/
+cp -Rp lib/* ${BUILD_LIB}/
 # cp -R bin/* ${BUILD_BIN}/ # No binaries provided for unix (for now)
 
 echo '*** Generate a callable metalua shell script ***'
@@ -101,12 +105,15 @@ cat > ${INSTALL_BIN}/metalua <<EOF
 METALUA_LIB=${INSTALL_LIB}
 export LUA_PATH="?.luac;?.lua;\\\${METALUA_LIB}/?.luac;\\\${METALUA_LIB}/?.lua"
 export LUA_MPATH="?.mlua;\\\${METALUA_LIB}/?.mlua"
-exec ${LUA} \\\${METALUA_LIB}/metalua.luac "\\\$@"
+exec ${LINEREADER} ${LUA} \\\${METALUA_LIB}/metalua.luac "\\\$@"
 EOF
 
 chmod a+x ${INSTALL_BIN}/metalua
 
 cp -R ${BUILD_LIB}/* ${INSTALL_LIB}/
+
+echo "metalua libs installed in ${INSTALL_LIB};"
+echo "metalua executable in ${INSTALL_BIN}."
 EOF2
 chmod a+x make-install.sh