From c160c40265b5eb5670730906614997ad2545f94d Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 23 Mar 2014 17:21:35 +0100 Subject: [tool] implement good/bad directives for bisection mode --- src/luaotfload-tool.lua | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/luaotfload-tool.lua') diff --git a/src/luaotfload-tool.lua b/src/luaotfload-tool.lua index e3f4516..9529a4d 100755 --- a/src/luaotfload-tool.lua +++ b/src/luaotfload-tool.lua @@ -894,9 +894,42 @@ end bisect_set -- Prepare the next bisection step by setting high, low, and pivot to new values. + The “run” directive always picks the segment below the pivot so we + can rely on the “outcome parameter” to be referring to that. + --doc]]-- local bisect_set = function (outcome) + local status = read_bisect_status () + if not status then + return false, false + end + + local nsteps = #status + local lo, hi, pivot = unpack (status[nsteps]) + report ("info", 3, "bisect", "Previous step %d: lo=%d, hi=%d, pivot=%d.", + nsteps, lo, hi, pivot) + + if outcome == "bad" then + hi = pivot + pivot = mathfloor ((lo + hi) / 2) + report ("info", 0, "bisect", + "Continuing with the lower segment: lo=%d, hi=%d, pivot=%d.", + lo, hi, pivot) + elseif outcome == "good" then + lo = pivot + pivot = mathfloor ((lo + hi) / 2) + report ("info", 0, "bisect", + "Continuing with the upper segment: lo=%d, hi=%d, pivot=%d.", + lo, hi, pivot) + else -- can’t happen + report ("info", 0, "bisect", "What the hell?", lo, hi, pivot) + return false, false + end + + status[nsteps + 1] = { lo, hi, pivot } + write_bisect_status (status) + return true, false end --[[doc-- @@ -908,7 +941,7 @@ end local bisect_status = function () local status = read_bisect_status () if not status then - return false + return false, false end local nsteps = #status if nsteps > 1 then @@ -953,8 +986,8 @@ end local bisect_modes = { start = bisect_start, - good = function () bisect_set "good" end, - bad = function () bisect_set "bad" end, + good = function () return bisect_set "good" end, + bad = function () return bisect_set "bad" end, stop = bisect_stop, status = bisect_status, run = bisect_run, -- cgit v1.2.3