Comments (10)
Implemented - let me know if there are any issues, I didn't test it too thoroughly.
from shrinko8.
I did custom names last year for my minesweeper 1k demake by not using shrinko8 renaming at all, and using sed instead:
This was clunky, and now that shrinko8 is much smarter about choosing compression-friendly names it'd be a shame to bypass the system entirely.
Is there some way I can use custom python scripts for this somehow...? Or maybe use specific easy-to-sed names like _var1_
and _var2_
in test.lua, --preserve
them during shrinko8 and then add a sed step afterwards (sounds tricky -- how would I be sure that the final name I choose hasn't been already taken by shrinko8? Also, --preserve
doesn't seem to preserve function argument names like b in function(b)
in test.lua)
from shrinko8.
Here's our previous discussion, for reference: https://discord.com/channels/215267007245975552/999490991524429895/1121957790294999071
Summary:
- What's the interface for telling shrinko8 how to rename things? (no solid answer)
thisismypassword: Basically we have 3 possible desires here:
thisismypassword: - Minifying with fixed rename instructions
thisismypassword: - Unminifying with custom rename instructions
thisismypassword: - Unminifying with the rename map generated during minify
thisismypassword: I was hoping to have one implementation doing all 3, but it doesn't seem like it'd be helpful
- maybe pico-ls for vscode can do renaming? it's still manual but might be a bit easier
from shrinko8.
Hmm - I think the only sane way to specify which local to rename is by adding a comment next to it. (Like you tried in the other issue)
E.g. I could imagine adding a comment like this:
function f(--[[rename::x]]my_param) return my_param end
That would become
function f(x) return x end
Would that be useful?
from shrinko8.
More notes:
It is a bit annoying that --[[rename::...]] would affect all usages of a var, while --[[preserve]] affects only one instance...
But I assume --[[rename::...]] is more than verbose enough, so you wouldn't want --[[rename-var::...]] or --[[rename-all:...]]
I'm semi-considering to deprecate the use of --[[preserve]] on identifiers, except I'm not sure how to call the new name for the hint - --[[preserve-occerence]] is excessive (and there is a valid usecase for --[[preserve]] on identifiers as seen in the readme)
I'd be glad to hear what you think.
from shrinko8.
Deprecating/renaming --[[preserve]]
: that sounds good. I think my misunderstanding (from #27) stemmed from the fact that --preserve
in the commandline affects all occurences, so I assumed --[[preserve]]
inside lua would act similarly.
I like the idea of renaming it; maybe --[[preserve-once]]
or --[[preserve-single]]
? In the example from the readme (tweetcart circfill/rectfill) it seems fine to me, and that specific use-case seems rare.
from shrinko8.
--[[rename::x]]
: yes, that would be excellent! I remember suggesting something like this but decided against it in discord:
maybe inline rename hints of some sort would be more natural
something like this? urg, also gross. I didn't even do the whole thing
--[[rename TILE_CHEESE]]n=5
function --[[rename make_cheese]]e(--[[rename cx]]l,--[[rename cy]]u,--[[rename tile]]t)
local --[[rename act]]e={
--[[rename kind]]l="cheese",
e=t or n,
c=l,
o=u,
u=true
}
function e:t()
local n=self.e+time()\1%2*16
local e,o=c(self)
spr(n,self.c*8+e,self.o*8+o,1,1,self.r)
end
return add(o,e)
end
I think it would be unusable if I wanted to rename every variable, but in that case maybe I should use sed
instead.
In this case and others like it (just wanting to rename a few specific things) an inline annotation would work great!
from shrinko8.
Thank you! unfortunately I have returned with some bugs:
-- > cat bug1.lua
x=0 ::loop:: --[[rename::o]] y=32 goto loop
-- > shrinko8 --minify bug1.lua - -f lua
o=0::o::o=32goto o
-- > cat bug2.lua
list={{a=1}}
for --[[rename::o]] outer in all(list) do
for inner in all(list) do
outer.a=2
end
end
-- > shrinko8 --minify bug2.lua - -f lua --no-minify-spaces
o={{o=1}}
for o in all(o) do
for o in all(o) do
o.o=2
end
end
-- > cat bug3.lua
--[[rename::a]]x=1 y=2
-- > shrinko8 --minify bug3.lua - -f lua
a=1a=2
-- > cat bug4.lua
x=1 --[[rename::a]]y=2
-- > shrinko8 --minify bug4.lua - -f lua
a=1a=2
...unless this is some sort of optimization, because it notices the variables aren't used? but bug1 and bug2 are distillations of actual bugs in my game, and adding print
s to use the vars doesn't remove the bug (I checked bug1 and bug4 only)
from shrinko8.
Whoops - I knew I didn't test it thoroughly enough 😄
Pushed a fix now, fixes the above. LMK if there are still issues.
from shrinko8.
works great! saved me 3 bytes :D
(for context, I'm at the stage where small reorderings tend to add 6~12 bytes for no apparent reason. ghosts moving between MTF and REF sections, I assume...)
from shrinko8.
Related Issues (20)
- Minification issue with peek shortcut HOT 4
- String minification with extra symbols unexpected HOT 6
- unhandled exception HOT 2
- Feature proposal: annotate source with token/character counts for functions HOT 6
- very slow compression (10s) HOT 1
- Compress fails on binary string HOT 2
- unknown expression: `x=?y`
- Reported compressed size in shrinko8 does not match pico8 HOT 6
- bug: preserve for-loop / function parameter HOT 2
- README preserve example doesnt work HOT 1
- bad output for shorthand print with `--focus-compressed --no-minify-spaces` HOT 1
- support `--label` for p8 output HOT 3
- Export sprite sheet HOT 2
- Feature Proposal: Find most token (or character) intense parts of code. HOT 2
- Feature Proposal: Constant variables. HOT 3
- -1 => 65535 HOT 1
- shorthand parser bugs in pico8
- long decimal replacements of fractions
- true/false inlining can waste chars HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shrinko8.