seleb / pico-8-token-optimizations Goto Github PK
View Code? Open in Web Editor NEWA list of general purpose tricks and techniques for saving tokens in PICO-8.
A list of general purpose tricks and techniques for saving tokens in PICO-8.
Either my knowledge how formal automatons and parsers/lexers work or lot of these optimizations are worse than unoptimized versions? For instance:
var1,var2 = value1,value2
vs
var1 = value1
var2 = value2
First, optimized version, has 4(n-1)+3 tokens (var1, comma, value1, comma; var2, value2; equals) while unoptimized, since newlines do not count as tokens, has only 3n tokens? In two line example optimized version is 7 tokens (4*1 + 3) and unoptimized is 6 tokens?
Vector Dimensions as Properties Instead of Array Elements
a lot of mistakes, for instance it's not 9 but 11 tokens to create point={x=x,y=y}
(point, equals, left curly, x, equals, x, comma, y, equals, y, right curly). point[1]
is 4 tokens and point.x
is three tokens as well...
Also string literals should be parsed as three tokens, not 1 as it is implied... "foo" should be double quote, string literal, double quote. Even if literal part is not somehow a token, that is still two tokens per string literal. Which can make repeating strings way more tokens than declaring it as constant (for Replace Constant Variables with Literals) and Calling Functions with Strings or Tables which makes only sense if your argument is string literal, otherwise you lose tokens: foo"hello"
is 4 tokens and foo("hello")
is 6 tokens but converting number never makes sense because foo"6"
should be the same as foo(6)
and you lose tokens in int->string conversion. Now, lua can be parsing string as one token internally during token stream creation so this point might be moot and subsequent points as well.
Replace Table Elements with Separate Variables
section has bad token reduction. player.x
vs player_x
is two tokens down (dot is another token) so gains there could be very high especially with nested tables. So it's 2 tokens instead of 1. Replace Multiple Table Accesses with Local Variables
same issue, it's n-2
not n-1
and to create it's 3+n.
Prefer Property Access to Array Indexing
makes wrong assumption about string being one token so it saves more tokens than declared.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.