Comments (2)
About the bug - yeah, it's the same issue as in #38 - I'll probably fix it by avoiding doing const replacement in focus-chars mode if the result is longer than the original tokens (though there are edge cases relating to const vars and to the possibility that even though parts of an expression are longer in constant form, the whole expression is shorter in constant form)
About the feature - hmm... So far I never adding tokens as part of minification, and I'm not sure that would be expected, even though --focus-tokens isn't provided. Maybe under some kind of --ignore-tokens option?
Do you know other such save-chars-at-the-cost-of-tokens tricks?
from shrinko8.
avoiding doing const replacement in focus-chars mode if the result is longer than the original tokens
Perfect, focus-chars-only is exactly what I would expect here
Oh, true
=>0<1
adds extra tokens! very true and not good; I didn't even think about that haha (I've been in character-counting mode for the last few weeks). maybe only do this replacement iff the user asked for --focus-chars
but did not ask for --focus-tokens
? bah, it feels like a gross mess that users wouldn't be able to predict.
An alternate idea might be a new pause/unpause directive; something like: a=--[[shrinko8-pause]]0<1--[[shrinko8-unpause]]
. Some sort of fined-grain control like this, although this exact suggestion feels a bit lacking, since it would only(?) work to prevent constant inlining...
> Do you know other such save-chars-at-the-cost-of-tokens tricks?
This was a fun exercise to think through! Here's a few I came up with just now:
1
if(not x)
=> if(x==a)
saves one character, if a is unassigned/nil and the programmer is intending to only check for nil (i.e. they know x won't be false
)
2
any output of my constant companion tool, e.g. replacing 0x6000
with ◆-♥
, or replacing 0x7fff.ffff
with 1/0
. Or replacing 0xffff.ffff
with ~0
3
I just thought up this toy example, probably not useful to you tho:
--28 tokens, 55 chars
function f(x) return x*2*3*4*5*6*7 end
a=f(10)
b=f(20)
--30 tokens, 33 chars
a=10*2*3*4*5*6*7
b=20*2*3*4*5*6*7
4
I suppose the tweetcart standard of using ::_::cls() flip()goto _
instead of using function _draw() end
is another example (even when using the p8scii version of flip()cls()
)
5
similar to 3 but maybe more useful for shrinko8: creating an alias for an often-used variable or constant: u=unpack ... x=u(c) ... y=u(c)
or e=128 .... rect(0,0,e,e) ...
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
- choosing varnames in output HOT 10
- 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
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.