-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better minifier #2
Comments
Wait I have an idea. I can write the full algorithm in TypeScript, then you manually transpile it to Go. What do you think? |
Thank you for your comments, I'm kinda busy right now, will definitely look into this tomorrow. |
Hey @Rudxain, just read your comments, took a look at the brnfckr repo and read the linked stackexchange page. Seems like all solutions you mentioned can be implemented. To start off the feature, a reasonable approach would be adding the optimizations to /bffmt/minify.go under and we can wrap this line with a minified := minify(readcode.ReadBrainfuck(f)) This function (and PS |
Thank you for the info! I've been considering learning some Go, and I could use the official VSCode Golang extension for faster development. So that's fine for me! But it'll take some time, please be patient (I'm slow) |
Great, make sure you open a pull request when you're ready and keep me updated |
Ok 👍 |
VSCode says "Error: there is no registered task type 'cppbuild'. Did you miss installing an extension that provides a corresponding task provider?". It seems |
Yeah, tasks.json wasn't supposed to be there anyways, we can remove it |
I want to open a PR to improve the minifier, but I'll need to learn more Golang (my main langs are Rust and JS). I suggest the following optimizations:
Return an empty string if the input doesn't containNo, this is unsafe! Infinite loops aren't "output", but still count as "behavior". Link to commit that removed the bug. Instead, remove all ops after last.
..
, only if.
isn't followed by]
or,
anywhere.+
or-
(because ofmod 256
wrap-around)+
or-
followed by its opposite, same for<
and>
)+
or-
if an equivalent sequence of opposite op does the same thing (replace 129 (or more) by a smaller sequence, exploitingmod 256
). For example, if we add 255 times (+
* 0xff), it does the same as subtract once (-
).[-]
and even-count by[--]
(this exploitsmod 2^n
arithmetic)+++[-]
->[-]
[.-.]...[foobar]
can be turned into[.-.]...
. The 1st loop can contain arbitrary code, iff the opcodes between both loops are dots (or no-op). This can be extended indefinitely[foo][foo][foo][foo][foo]
->[foo]
[-]
by[+]
and vice-versa (frequency analysis for "compressor-friendly" output)+
and-
. This is very hard to implement (halting problem), so I won't do it. It's hard because it requires knowing the exact value of adjacent cells, to safely use them as temporary registers. Example>++++++++++++<
->+++[->++++<]
(add 12 to M1 while M0 is 0). If done wrong, it can increase the size of output,>++<
->++[->+<]
, so it's another reason to avoid that risk.The text was updated successfully, but these errors were encountered: