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]

  • If there is a function that you use only in 1 place you definitely want to use it.

    If it's used in more than one place then it depends. What I do is I do an optimized build with and without the annotation and compare the code size that is printed at the end of the build. I usually optimize for Suze because I make Datafields.

    It's also worth to look into bin/optimized/source to see what happens.

    In your example if both functions would only be used in one place then I would manually inline them. That would also eliminate adding a second function, calling a second function, creating an array, indexing the array to read the coordinates from it. This is lot of code and even some time.

  • In the whole class it's 19 for one and 47 times for the other separately and 70 times together, so inline doesn't sound like what I want. It seems that I was able to make it a little smaller by combining them into one function with an additional "op" parameter to each call to decide what to do. I'm sure the extra parameter adds bytes to each call, but not as much as I would have thought compared to the reduction in code size. I used a symbol for "op", do symbols take up less space than variables in function arguments?

  • Symbol is a Number. I guess a Boolean might use less space in the stack

  • There's five possible "op" symbols, so boolean wouldn't work. I wouldn't assume booleans are bit packed since null is a valid value for a boolean (I actually use this feature), I would assume they are 32 bits just because that would be easier to implement underneath, even though that's an obvious waste of space. I don't know how symbols are implemented in bytecode compared to variables. It seems logical that they would be handled differently, or more specifically be part of the function namespace since you have to use a symbol as a method parameter to refer to a function.

  • I think Symbol is just a typedef for Number plus some compile time magic

  • I assumed that, the magic part. Since I'm not Penn or Teller I can't say what it is.. Just don't call it victor oscar oscar delta oscar oscar or the forum police will come for you.

  • I think there's some problem after upgrading to Monkey C 1.0.11. All the editor features stopped working. The hints, clicks to go to reference, definitions, etc.

  • null is a valid value for a boolean

    No, it's not. If you put null in a variable, it's no longer holding a boolean. Remember that at runtime you can literally put any type in any variable.

    But the point is valid - all objects take up the same amount of space on the stack (or in an Array, or as a field in an Object, or a member of a Module). Some objects also take up space in the heap - eg Arrays, Longs, Doubles and Strings. But the amount of stack space it uses is fixed.

    I assume that stack slots are 4 bytes plus a type descriptor, but it's not clear how big that is. Presumably at least one byte, but looking at the layout of global objects in the .prg file, it may actually be 4.

    And symbols appear to be just a special flavor of Number - they are fully represented by their 32 bit value, and have no other heap storage associated with them.

  • I think there's some problem after upgrading to Monkey C 1.0.11

    I'm seeing the same. Even weirder, downgrading to 1.0.10 didn't fix it...

  • I'm seeing the same. Even weirder, downgrading to 1.0.10 didn't fix it.

    No, I'm just being stupid. I had added a test of the enum bug you reported to my project, and then forgotten about it. That's why the syntax hiliting wasn't working. I need to fix that one!