]> git.lizzy.rs Git - metalua.git/commitdiff
pushed in a hurry, alimentation issue on laptop
authorFabien Fleutot <fabien@MacFabien.home>
Sun, 22 Feb 2009 14:46:09 +0000 (15:46 +0100)
committerFabien Fleutot <fabien@MacFabien.home>
Sun, 22 Feb 2009 14:46:09 +0000 (15:46 +0100)
src/compiler/metalua.mlua
src/compiler/mlc.mlua
src/lib/metalua/mlc_xcall.lua
src/lib/metalua/walk.mlua

index 3c3564d0c37b167e47cf329f27cde1ae0ad92d63..2b2f08459287074b4424cecb50e270254cb04b76 100644 (file)
@@ -149,7 +149,7 @@ local function main (...)
          end
       end
       if not st then
-         printf ("Cannot compile %s: %s", table.tostring(x), ast or "no msg")
+         printf ("Cannot compile %s:\n%s", table.tostring(x), ast or "no msg")
          os.exit (AST_COMPILE_ERROR_NUMBER)
       end
       ast.origin = x
index a3eeb6f6585a9c4c8e7a68d1f82f14c982c42573..6f82ac9a8028b24a6262ae41ee1d3cbe354f8567 100644 (file)
@@ -103,8 +103,9 @@ function mlc.convert (x, src_fmt, dst_fmt, name)
       -- x = error msg; get rid of ???
       x = x:strmatch "[^:]+:[0-9]+: (.*)" or x
       local li = lx:lineinfo_left()
-      error(string.format("Parsing error in %s line %s, column %i, char %s: \n%s",
-                          name or "<nofilename>", li[1], li[2], li[3], x))
+      error (string.format (
+         "Parsing error in %s line %s, column %i, char %s: \n%s",
+         name or "<nofilename>", li[1], li[2], li[3], x), 2)
       return nil
    end
    
index adfe673b6540b1c141a40c237ebc5a7f07d79181..359bedc76a264528df7bb131adae77ac0567c99e 100644 (file)
@@ -22,7 +22,13 @@ function mlc_xcall.server (luafilename, astfilename)
    require 'serialize'
 
    -- compile the content of luafile name in an AST, serialized in astfilename
-   local status, ast = pcall (mlc.luafile_to_ast, luafilename)
+   --local status, ast = pcall (mlc.luafile_to_ast, luafilename)
+   local status, ast
+   local function compile() return mlc.luafile_to_ast (luafilename) end
+   if mlc.metabugs or true then 
+      print 'mlc_xcall.server/metabugs'
+      status, ast = xpcall (compile, debug.traceback)
+   else status, ast = pcall (compile) end
    local out = io.open (astfilename, 'w')
    if status then -- success
       out:write (serialize (ast))
index b8ffca21e058adc650ea0c2efbcf67c6c406ac92..c94a04ea0131752f48d4afd9de76523e735a276d 100644 (file)
 -- e.g. they're called after the right-hand-side has been visited in a
 -- `Local node, but before in a `Localrec node.
 --
+-- TODO: document scopes, relaxed cfg descriptions
+-- -----------------------------------------------
+--
+-- Examples of cfg structures:
+--
+-- { Id = f1, Local = f2 }
+-- f
+-- { up = f1, down = f2 }
+-- { scope = { up = f1, down = f2 }, up = f1, down = f2 }
+-- { stat = f1, expr = { up = f1 } }
+--
+--
 --------------------------------------------------------------------------------
 
 -{ extension "match" }
@@ -191,11 +203,10 @@ function walk.traverse.stat (cfg, x, ...)
                                     if #x%2 == 1 then BS(x[#x]) end
    | `Call{...}|`Invoke{...}|`Return{...} -> EL(x)
    | `Break | `Goto{ _ } | `Label{ _ }    -> -- nothing
-   | {...} if walk.tags.stat[x.tag]-> 
-      printf("Warning: walk: malformed %s stat node: %s", x.tag, table.tostring(x,80))
-   | {...} -> print("Warning: walk: unknown stat node: "..table.tostring(x,80))
-   | _     -> print("Warning: walk: unexpected stat node of type "..type(x)
-                    ..": "..table.tostring(x,80))
+   | { tag=tag, ...} if walk.tags.stat[tag]-> 
+      walk.malformed (cfg, x, unpack (log))
+   | _ ->  
+      walk.unknonw (cfg, x, unpack (log))
    end
 end
 
@@ -220,11 +231,10 @@ function walk.traverse.expr (cfg, x, ...)
          | v            -> E(v)
       end end
    |`Nil|`Dots|`True|`False|`Number{_}|`String{_}|`Id{_} -> -- nothing 
-   | {...} if walk.tags.expr[x.tag]-> 
-      printf("Warning: walk: malformed %s expr node: %s", x.tag, table.tostring(x,80))
-   | {...} -> print("Warning: walk: unknown expr node: "..table.tostring(x,80))
-   | _     -> print("Warning: walk: unexpected expr node of type "..type(x)
-                    ..": "..table.tostring(x,80))
+   | { tag=tag, ...} if walk.tags.expr[tag]-> 
+      walk.malformed (cfg, x, unpack (log))
+   | _ ->  
+      walk.unknonw (cfg, x, unpack (log))
    end
 end
 
@@ -246,9 +256,9 @@ end
 -- * if an entry is a table, look for 'up' and 'down' entries
 -- * if it is a function, consider it as a `down' traverser.
 ----------------------------------------------------------------------
-local walker_builder = |cfg_field, traverse| 
-function (cfg, x, ...)
-   local sub_cfg = type (x)=='table' and x.tag and cfg[x.tag] or cfg[cfg_field] or cfg
+local walker_builder = |cfg_field, traverse| function (cfg, x, ...)
+   local sub_cfg = type (x)=='table' and x.tag and cfg[x.tag] 
+      or cfg[cfg_field] or cfg
    local broken, down, up = false
    if type(sub_cfg)=='table' then
       down, up = sub_cfg.down, sub_cfg.up
@@ -262,14 +272,15 @@ function (cfg, x, ...)
       assert(not broken or broken=='break', 
              "Map functions must return 'break' or nil")
    end
-   if not broken then traverse (cfg, x, ...) end
+   if not broken and traverse then traverse (cfg, x, ...) end
    if up then up (x, ...) end
 end
 
 ----------------------------------------------------------------------
 -- Declare [walk.stat], [walk.expr], [walk.block] and [walk.expr_list]
 ----------------------------------------------------------------------
-for w in values{ "stat", "expr", "block", "expr_list" } do
+for w in values{ "stat", "expr", "block", "expr_list",
+   "malformed", "unknown" } do
    walk[w] = walker_builder (w, walk.traverse[w])
 end