From: Fabien Fleutot Date: Thu, 26 Feb 2009 12:31:16 +0000 (+0100) Subject: fixes suggested by D. M. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=1a5ae8e02ecebd932bf80e13b4a34614de60316f;p=metalua.git fixes suggested by D. M. --- diff --git a/src/build-utils/bootstrap.lua b/src/build-utils/bootstrap.lua index ba13651..a4b6fa5 100644 --- a/src/build-utils/bootstrap.lua +++ b/src/build-utils/bootstrap.lua @@ -12,7 +12,7 @@ for _, a in ipairs(arg) do if var then cfg[var] = val else table.insert (cfg.inputs, a) end end --- metalua.mlc doesn't exit yet; this preload manager loads a mockup which is just +-- metalua.mlc doesn't exist yet; this preload manager loads a mockup which is just -- sufficient to compile the real mlc.mlua package.preload['metalua.mlc'] = function() diff --git a/src/compiler/gg.lua b/src/compiler/gg.lua index 0c0af63..db0d91c 100644 --- a/src/compiler/gg.lua +++ b/src/compiler/gg.lua @@ -210,7 +210,7 @@ function sequence (p) 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] + p.name = p[1] .. " ... " .. p[#p] else p.name = p[1] .. " ..." end else -- can't find a decent name p.name = "" diff --git a/src/compiler/mlp_misc.lua b/src/compiler/mlp_misc.lua index 51d180e..bfdc376 100644 --- a/src/compiler/mlp_misc.lua +++ b/src/compiler/mlp_misc.lua @@ -135,7 +135,7 @@ function id2string (id) -- That is, without sugar: return {tag="String", {tag="Index", {tag="Splice", id[1] }, {tag="Number", 1 } } } - else error ("Identifier expected: ".._G.table.tostring(id)) end + else error ("Identifier expected: ".._G.table.tostring(id, 'nohash')) end end -------------------------------------------------------------------------------- diff --git a/src/compiler/mlp_stat.lua b/src/compiler/mlp_stat.lua index 282954e..c6edad1 100644 --- a/src/compiler/mlp_stat.lua +++ b/src/compiler/mlp_stat.lua @@ -174,13 +174,15 @@ local function assign_or_call_stat_parser (lx) "separated by semicolons, or not separated at all") end if e[1].tag ~= "Call" and e[1].tag ~= "Invoke" then local typename - if e[1].tag == 'Id' then typename = "an identifier" - elseif e[1].tag == 'Op' then typename = "an arithmetic operation" - else typename = "of type '"..(e[1].tag or "".."'" end - - gg.parse_error (lx, "This expression is " .. typename .. - "; only function and method call expressions ".. - "can be used as statements"); + if e[1].tag == 'Id' then + typename = '("'..e[1][1]..'") is an identifier' + elseif e[1].tag == 'Op' then + typename = "is an arithmetic operation" + else typename = "is of type '"..(e[1].tag or "").."'" end + + gg.parse_error (lx, "This expression " .. typename .. + "; a statement was expected, and only function and method call ".. + "expressions can be used as statements"); end return e[1] end diff --git a/src/lib/strict.lua b/src/lib/strict.lua index 8ca18fa..772fc10 100644 --- a/src/lib/strict.lua +++ b/src/lib/strict.lua @@ -6,18 +6,25 @@ -- anywhere or assigned to inside a function. -- +local getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget + local mt = getmetatable(_G) if mt == nil then mt = {} setmetatable(_G, mt) end -__STRICT = true +__strict = true mt.__declared = {} +local function what () + local d = getinfo(3, "S") + return d and d.what or "C" +end + mt.__newindex = function (t, n, v) - if __STRICT and not mt.__declared[n] then - local w = debug.getinfo(2, "S").what + if __strict and not mt.__declared[n] then + local w = what() if w ~= "main" and w ~= "C" then error("assign to undeclared variable '"..n.."'", 2) end @@ -27,7 +34,7 @@ mt.__newindex = function (t, n, v) end mt.__index = function (t, n) - if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then + if __strict and not mt.__declared[n] and what() ~= "C" then error("variable '"..n.."' is not declared", 2) end return rawget(t, n) diff --git a/src/make.sh b/src/make.sh index b6e52ab..bf6cc34 100755 --- a/src/make.sh +++ b/src/make.sh @@ -9,7 +9,7 @@ BASE=${PWD} # Upon installation, everything will be moved to ${INSTALL_LIB} and ${INSTALL_BIN} if [ -z "${BUILD}" ]; then - BUILD= $(cd ../build; pwd) + BUILD=$(mkdir -p ../build; cd ../build; pwd) fi if [ -z "${BUILD_BIN}" ]; then