Inline-Lua
view release on metacpan or search on metacpan
ffi/target/release/build/mlua-sys-6a99a2ae50f12319/out/luajit-build/build/dynasm/dynasm.lua view on Meta::CPAN
end
if mac_capture then wfatal("recursive macro definition") end
-- Enable statement capture.
local lines = {}
mac_lineno = g_lineno
mac_name = name
mac_capture = function(stmt) -- Statement capture function.
-- Stop macro definition with .endmacro pseudo-opcode.
if not match(stmt, "^%s*.endmacro%s*$") then
lines[#lines+1] = stmt
return
end
mac_capture = nil
mac_lineno = nil
mac_name = nil
mac_list[#mac_list+1] = opname
-- Add macro-op definition.
map_op[opname] = function(params)
if not params then return mparams, lines end
-- Protect against recursive macro invocation.
if mac_active[opname] then wfatal("recursive macro invocation") end
mac_active[opname] = true
-- Setup substitution map.
local subst = {}
for i,mp in ipairs(mparams) do subst[mp] = params[i] end
local mcom
if g_opt.maccomment and g_opt.comment then
mcom = " MACRO "..name.." ("..#mparams..")"
wcomment("{"..mcom)
end
-- Loop through all captured statements
for _,stmt in ipairs(lines) do
-- Substitute macro parameters.
local st = gsub(stmt, "[%w_]+", subst)
st = definesubst(st)
st = gsub(st, "%s*%.%.%s*", "") -- Token paste a..b.
if mcom and sub(st, 1, 1) ~= "|" then wcomment(st) end
-- Emit statement. Use a protected call for better diagnostics.
local ok, err = pcall(dostmt, st)
if not ok then
-- Add the captured statement to the error.
wprinterr(err, "\n", g_indent, "| ", stmt,
"\t[MACRO ", name, " (", #mparams, ")]\n")
end
end
if mcom then wcomment("}"..mcom) end
mac_active[opname] = nil
end
end
end
-- An .endmacro pseudo-opcode outside of a macro definition is an error.
map_coreop[".endmacro_0"] = function(params)
wfatal(".endmacro without .macro")
end
-- Dump all macros and their contents (with -PP only).
local function dumpmacros(out, lvl)
sort(mac_list)
out:write("Macros:\n")
for _,opname in ipairs(mac_list) do
local name = sub(opname, 1, -3)
local params, lines = map_op[opname]()
out:write(format(" %-20s %s\n", name, concat(params, ", ")))
if lvl > 1 then
for _,line in ipairs(lines) do
out:write(" |", line, "\n")
end
out:write("\n")
end
end
out:write("\n")
end
-- Check for unfinished macro definitions.
local function checkmacros()
if mac_capture then
wprinterr(g_fname, ":", mac_lineno,
": error: unfinished .macro `", mac_name ,"'\n")
end
end
------------------------------------------------------------------------------
-- Support variables for captures.
local cap_lineno, cap_name
local cap_buffers = {}
local cap_used = {}
-- Start a capture.
map_coreop[".capture_1"] = function(params)
if not params then return "name" end
wflush()
local name = params[1]
if not match(name, "^[%a_][%w_]*$") then
wfatal("bad capture name `"..name.."'")
end
if cap_name then
wfatal("already capturing to `"..cap_name.."' since line "..cap_lineno)
end
cap_name = name
cap_lineno = g_lineno
-- Create or continue a capture buffer and start the output line capture.
local buf = cap_buffers[name]
if not buf then buf = {}; cap_buffers[name] = buf end
g_capbuffer = buf
g_synclineno = 0
end
-- Stop a capture.
map_coreop[".endcapture_0"] = function(params)
wflush()
if not cap_name then wfatal(".endcapture without a valid .capture") end
cap_name = nil
cap_lineno = nil
g_capbuffer = nil
g_synclineno = 0
end
-- Dump a capture buffer.
( run in 0.721 second using v1.01-cache-2.11-cpan-39bf76dae61 )