Simon's Musings

April 4, 2008

Thoughts from the train 2: References and Mutations

Filed under: Uncategorized — sxw @ 10:49 am
Tags: ,

Another thought from the train journey back from UKUUG. The real work here is Stephen’s, I’m just trying to jot down some background so we remember how we go there!

The LCFG compiler currently supports a number of data operations, which were independently developed, and which don’t necessarily nicely fit together. For the purposes of this discussion, these are:

Mutations Operations (like mADD, mREMOVE, mEXTRA, mSET) which take an existing value, and change it in a way that depends upon their parameters.

Early references A reference to the value of another resource. This is evaluated immediately it is encountered, and is set to the current value of the resource.

Late references Also a reference to the value of another resource. However, a late reference is evaluated once compilation is complete (and after all mutations have been computed), and is set to the final value of the resource

Stephen suggested that we handle mutations by holding a list of mutations, rather than the current value, within the parse tree. Then all of the mutations are applied in the final linking step (which is also responsible for reference evaluation). This allows us to optimise our mutation handling, as well as permitting the production of more specific derivation information.

In order to handle early references, we need to store an additional piece of information. When an early reference is encountered, we must store both the resource being referenced, and the current depth of that resource’s mutation list. This means we can mimic the ‘early’ behaviour and still leave reference processing to the linker.


  1. Just to clarify this slightly, we can’t just store a list of mutations. It is necessary to store which header/source file each mutation came from and which line within that file. Without this the proper reporting of any errors at the time of mutation would be impossible.

    Comment by squinney — April 5, 2008 @ 10:19 am

  2. You actually have preprocessor #defines as well which act like yet another kind of reference ….

    Comment by dcspaul — April 8, 2008 @ 12:44 pm

  3. If you want some more brain exercise, you can also think about how references should interact with things like contexts …

    Comment by dcspaul — April 8, 2008 @ 12:45 pm

RSS feed for comments on this post.

Theme: Rubric.