-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbf_opt.lpp.lua
34 lines (33 loc) · 1.09 KB
/
bf_opt.lpp.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|>
---effectively separates code into chunks during optimization
bf_opt_boundary = "_opt_boundary_"
postprocess.optimize_bf = function(code, bf_opt_assume)
local ass = bf_opt_assume or _G.bf_opt_assume or { all = true }
local replacement_table = {
"<>",
"><",
"%+%-",
"%-%+",
(ass.all or ass.no_inf_loop) and "%[%]",
(ass.all or ass.zeroed_cells) and "^%[.-%]",
(ass.all or ass.bits_8) and ("%-"):rep(256),
(ass.all or ass.bits_8) and ("%+"):rep(256),
(ass.all or ass.move_is_noop) and "(<+)$",
(ass.all or ass.move_is_noop) and "(>+)$",
}
while true do
local replacements = 0
for _, v in ipairs(replacement_table) do
if type(v) == "string" then
local _code, count = code:gsub(v, "")
replacements = replacements + count
code = _code
end
end
if (replacements == 0) or (#code == 0) then
--TODO optimize + > 128 and - > 128 if bf_opt_assume.bits_8
return code:gsub(bf_opt_boundary, "")
end
end
end
<|