Big update to prettier-extension-monkeyc

I've posted about prettier-extension-monkeyc before, but I've added a bunch of new features that developers will probably like (well, I've been missing them, so maybe you have too).

The new features it implements for VSCode include:

  • Goto Definition. Point at a symbol, Ctrl/Cmd click, and it will take you to the definition. Or F12
  • Goto References. Right click on a symbol and select "Goto References". It will show you all the references. Or Shift-F12
  • Peek Definition/Peek References. Same as above, but in a popup window so you don't lose your place in the original document.
  • Rename Symbol. Right click on a local, function, class or module name, and select "Rename Symbol". It will rename all the references. It doesn't yet work for class members/methods.
  • Goto Symbol. Type Ctrl/Cmd-Shift-O and pick a symbol from the drop down (which has a hierarchical view of all symbols in the current file). This also appears as an outline across the top of the file.
  • Open Symbol By Name. Type Ctrl/Cmd-T, then start typing letters from a symbol name. A drop down will be populated with all matching symbols from anywhere in your project.

Older features include a prettier based formatter for monkeyc, and a monkeyc optimizer that will build/run/export an optimized version of your project.

[edit: My last couple of replies seem to have just disappeared, and the whole conversation seems to be in a jumbled order, so tldr: there's a new test-release at https://github.com/markw65/prettier-extension-monkeyc/releases/tag/v2.0.9 which seems to work for me on linux. I'll do more verification tomorrow, and push a proper update to the vscode store once I'm sure everything is working]

  • Has anyone done a comparisons between this and the optimization in the Compiler 2 beta?  Is one better than the other? (a few byte codes really don't matter)

    The tests need to be done with a few different apps while the beta optimization as it saved some thousands of bytes for some, and < 100 bytes for others

  • for my apps beta compiler is enough, 4kb less Slight smile

    in my opinion the most important is remove const/enums from var but I don't have thousand of them so beta makes something else

  • I'm one of the people that sees small savings with the Compiler 2 beta.  But at the same time, I've been self optimizing my code for any years

  • So now you can restore all const and make code nice. :)

    BTW, I observe strange behaviour, this code

    var global_var;

    function member_func()

    {

       using global_var...
    }

    when I change  to

    function member_func()

    {

       var local_var = global_var;

       using local_var...
    }

    it saves code (I don't have time to check it but at least 50b...

    Why? Is the same with members of class?

  • And one good news.

    I've put free memory info into my WF and in sim I can see 21.9kB but 23.7 on device!!!

    Almost 2kB more memory!!! So you can increase mem in sim_device.xml :)

  • it saves code (I don't have time to check it but at least 50b...

    Why? Is the same with members of class

    Yes, and this is something my optimizer will do for you (its currently disabled by default, but can be enabled via the prettierMonkeyC.sizeBasedPRE setting in VSCode). Garmin's optimizer doesn't do it at all.

    Each reference to a non-local id (whether it's a class member implicitly (or explicitly) referenced by self, a module member, or a global) takes 8 bytes. If it needs to be qualified (ie A.B.id) then each qualifier takes an additional 6 bytes (so A.B.id takes 20).

    On the other hand, each reference to a local takes two bytes.

    So if you have two uses of global_var in your function, moving it to a local will save 2 bytes (the assignment to the local takes 8 to access the global, and 2 to write to the local, then each reference you replace saves 8-2 = 6 bytes). Each extra use saves another 6 bytes (or more if its a qualified variable).

    My optimizer does the same with literals... each literal number takes 5 bytes, so now you need to use a number at least 3 times to save anything: assigning the literal to a variable takes 7 bytes, then each reference saves 5-2=3 bytes, so if you use the same constant value 3 times in a single function, you save 2 bytes. Each extra use saves another 3.

  • it's very good solution but only for function not used frequently (like onUpdate), because assignment need processor time. But maybe access to local is faster then - tests are needed.

  • Why? Is the same with members of class?

    Each reference to a non-local id (whether it's a class member implicitly (or explicitly) referenced by self, a module member, or a global) takes 8 bytes. If it needs to be qualified (ie A.B.id) then each qualifier takes an additional 6 bytes (so A.B.id takes 20).

    On the other hand, each reference to a local takes two bytes.

    To elaborate on this, the use of a non-local variable involves a symbol lookup, but the use of a local variable does not.

  • But maybe access to local is faster then - tests are needed

    Could be, especially given that the Monkey C docs recommend using $ when you know a symbol is a global, to speed up access.

    developer.garmin.com/.../

    In some cases, it may be more efficient to search from the global namespace instead of the current scope with the bling symbol $, which refers to the global scope:

  • I don't think so because I can't see symbol for each local var.