First Cut at Physical Units

Recently we have implemented the first version of physical units. This is an important aspect in embedded systems and comprises an enhanced type checker plus some tweaks to the code generator (as of now, we only implemented the type checking). The feature consists of two parts. First, we have implemented the seven SI base units as built-in types. We have then created a facility for users to define arbitrary derived units. The following screenshot shows an example.

These types, as well as the SI base units can then be used to annotate types and literals as shown in the next screenshot. We have implemented a restriction that allows only numeric types and the corresponding literals to be annotated with units. Note how the type checker performs unit computations for multiplication and division and reports errors if you try to add “apples and oranges”.

What makes this feature remarkable is this: no change to the C base language was necessary. Everything described above is completely additive and packaged into a separate language module that can be used in programs optionally. Also, the total effort was under two days!

Once again, this brought smiles to Bernd’s and Markus’ faces: MPS really is a terrific tool for language engineering!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s