dimanche 25 janvier 2015

Managing types and conversions in a compiler


I am trying to determine how to manage types and conversions between types within a compiler that I am writing. The compiler is being written in C#.


There are a number of different kinds of types.



  1. Classes (read only / not mutable)

  2. Mutable Types (Which contain another type. Think the opposite of C++ const.)

  3. Generic Types (With constraints referring to types)

  4. etc


The problem I am trying to solve is, given two types, how can I determine whether one can be converted to the other. (eg. Allow a mutable type to be assigned to the read only version of the type)


My first thought was to use a virtual method and a visitor. However, since types can depend on others (e.g. A mutable type is a wrapper referring to another type.), this can cause the number of cases that need to be handled to balloon. I am looking for a design that keeps this to a minimum.





Aucun commentaire:

Enregistrer un commentaire