This Weekend in Meson++ (October 3rd Edition)

 I thought I might try to write a series of light blog posts on the ongoing status of Meson++, and since I'm mostly working on it in my weekend free time, It's called "This Weekend in Meson++" (I stole this name from Emma Anholt, who called their series on VC4 "This Week in VC4", so thanks Emma).

Target Linking

Since I've already gotten basic targets working, I've started pushing toward getting linking between targets working, which is more difficult than it sounds. Meson++ uses a flat IR, and relies on IR optimizations to reduce the instruction stream from the Meson DSL into a vector of Targets (and eventually tests), then the backend has the responsibility to convert that stream of Targets into a file that can be consumed by the runner tool (ninja, make, msbuild, etc). This means to take something very simple like:

project('foo', 'cpp')

lib = static_library('lib, 'lib.cpp')

executable('main.cpp', link_with : lib)  

We need to be able to link the `lib` identifiers together. To do this we need value numbering, and from an implementation point of view, constant folding. Essentially what internally this ends up looking like, is an `Executable` Object with a reference to the `StaticLibrary` object, which seems like overkill, since ninja really just needs the output name. However, as recent work in Meson itself has demonstrated, Visual Studio doesn't work that way. I'm still working on this, so I don't have much more on this yet.

Parser Improvements

After hearing that Muon could parse all of the test cases in the upstream meson repo, I had to be able to do that as well, I found some pretty interesting bugs, and some annoying cases in Meson's grammar

A number of the problems, thankfully, were rather trivial to fix. Among the simpler fixes was:

  • Implementing f-strings, which are interpolated
  • Implement foreach loops over dictionaries, which do automatic unpacking
  • Implement binary literals 0b101
  • Fixed ambiguity of the `not in` operator

Numeric Literals are also interesting, as I had a bug where 0xFF would work, but 0XFF would not, it's not documented that you can capitalize the second character of the literal, but there are tests for it.

 Most annoying, and time-consuming, was newline management. Meson uses newlines as statement terminators, but they're not significant anywhere else. That means that, for example, you don't want the lexer to tell the parser about a newline following a comment, unless it's an inline comment. They also don't matter inside braces, since statements can't appear in braces, only expressions can. It's the inline comment business that makes this awful:

if x == 2  # this newline is significant
  # this one is not
endif

Clean Patches

Up until this point I've been just running fast and dirty with commits, pushing directly to the main branch as I write patches. Now that there is something working I've added CI, and I'm using Pull requests, even for my own patches. In addition, I've wired up some github CI, so things hopefully keep working.

First External Contribution

I got my first external contribution this weekend, from the author of Muon. Nothing makes yuou feel like your project is taking off like getting a Pull Request from someone other than yourself.

Comments

Popular posts from this blog

This Weekend in Meson++ (February 6th)

Introducing Meson++

Rust in Meson — 0.57 Edition