Coder Social home page Coder Social logo

pico-8-token-optimizations's Issues

Is this correct at all?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.