wiki:NewFrontEnd

Version 2 (modified by perost, 8 years ago) (diff)

--

New FrontEnd

This page gathers all the information about the new front-end. See also #4138

Debugging

Whether you use MDT (make sure you keep it updated) or OMEdit you need to compile the source code with CFLAGS=-g to be able to debug the compiler. Delete OMCompiler/Compiler/boot/build and then rebuild with CFLAGS=-g

Implementation details

The new frontend is divided into multiple (mostly) separate phases. The main entry point of the frontend is NFInst.instClassInProgram, which consists of four phases:

  • Lookup the class to instantiate (lookup might do some limited instantiation).
  • Instantiate the class.
  • Type the class.
  • Flatten the class.

So simply checking how far the instantiation gets in instClassInProgram will help narrow issues down considerably. We do of course want proper error messages, so feel free to add error messages, internal errors or just "IMPLEMENT ME" printouts as appropriate.

The instantiation itself is divided into three recursive phases:

  • partialInstClass (creates a scope for the class, and separates out components etc.)
  • expandClass (looks up and expands extends clauses)
  • instClass (instantiates the components)

A class only needs to be expanded for lookup to be possible, so the lookup will expand classes if necessary. There are two helper functions for this, instantiate which does all three phases and expand which only does the first two.

Something important to know about the instantiation is that InstNodes are mutable, i.e. the class or component in them are stored in an array of length 1. Without mutable nodes it would be very difficult to maintain the trees. It also means that one has to be a bit careful with how the nodes are handled.

One example of this is that expanded classes are generic, i.e. they do not have modifiers and such applied. Whenever a class is expanded, by the instantiation or the lookup, it will therefore be updated in the class tree and reused. Similarly, whenever a class is fully instantiated, e.g. when instantiating a component, it will not be updated in the class tree since a fully instantiated class is unique for each component. It will instead be cloned, fully instantiated and then stored in the component whose type it is.

Also, even though I might talk about the class tree or the instance tree they are not actually separate trees, but rather one combined tree made up of InstNodes (e.g. each component knows its parent component, each components type knows its parent class, and so on).