From 093a3d51761fad69546ed359c9e76bbdcd956f04 Mon Sep 17 00:00:00 2001 From: Fabien Fleutot Date: Sun, 22 Feb 2009 15:46:09 +0100 Subject: [PATCH] pushed in a hurry, alimentation issue on laptop --- src/compiler/metalua.mlua | 2 +- src/compiler/mlc.mlua | 5 +++-- src/lib/metalua/mlc_xcall.lua | 8 ++++++- src/lib/metalua/walk.mlua | 41 ++++++++++++++++++++++------------- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/compiler/metalua.mlua b/src/compiler/metalua.mlua index 3c3564d..2b2f084 100644 --- a/src/compiler/metalua.mlua +++ b/src/compiler/metalua.mlua @@ -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 diff --git a/src/compiler/mlc.mlua b/src/compiler/mlc.mlua index a3eeb6f..6f82ac9 100644 --- a/src/compiler/mlc.mlua +++ b/src/compiler/mlc.mlua @@ -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 "", li[1], li[2], li[3], x)) + error (string.format ( + "Parsing error in %s line %s, column %i, char %s: \n%s", + name or "", li[1], li[2], li[3], x), 2) return nil end diff --git a/src/lib/metalua/mlc_xcall.lua b/src/lib/metalua/mlc_xcall.lua index adfe673..359bedc 100644 --- a/src/lib/metalua/mlc_xcall.lua +++ b/src/lib/metalua/mlc_xcall.lua @@ -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)) diff --git a/src/lib/metalua/walk.mlua b/src/lib/metalua/walk.mlua index b8ffca2..c94a04e 100644 --- a/src/lib/metalua/walk.mlua +++ b/src/lib/metalua/walk.mlua @@ -135,6 +135,18 @@ -- 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 -- 2.44.0