Design question: resolving dependency between Ecore and builtin types [message #1858631] |
Wed, 12 April 2023 15:35 |
Simon Cockx Messages: 69 Registered: October 2021 |
Member |
|
|
I'm modelling a language with expressions and types such as `int` and `date`. Note that these types are built-in, i.e., users cannot add additional types.
These types have two representations:
1. In the language itself:
basic type int
record type date {
day: int
month: int
year: int
}
... which are represented as `BasicType` and `RecordType` classes in the ecore, e.g.,
interface Type {
String name
}
class BasicType extends Type { }
class RecordType extends Type {
contains RecordFeature[] features
}
class RecordFeature {
String name
refers Type type
}
The idea is that these types are automatically made available as a "standard library".
2. In the Java code:
public class RType {}
public class RBasicType extends RType {
public static BasicType INT = new BasicType("int");
...
}
public class RRecordType extends RType {
public static RRecordType DATE = new RRecordType("date");
...
}
The language supports these expressions:
- date construction, e.g., { day: 12, month: 4, year: 2023 }
- feature projection, e.g.,
When performing type inference, I have a rule that says "for a date construction, return `RRecordType.DATE`" and a rule that says "for a feature projection, return the type of the feature you're projecting to".
Problem: while computing the scope of a feature projection, I can compute the type of the expression I'm projecting on, but then I need some way of accessing the Ecore features of that type. For example, consider the following expression:
{ day: 12, month: 4, year: 2023 }.month
I first infer that the type of the receiving expression is `RRecordType.DATE`. Then I would like to return a list of the Ecore features of the corresponding `RecordType`, but I'm not sure how.
One thing I considered is adding a reference to `RecordType` to the class `RRecordType`, but then I cannot instantiate the static field `RRecordType.DATE` anymore, which I need when performing type inference.
Are there languages with a similar problem that came up with a solution for this? Any suggestions?
[Updated on: Fri, 21 April 2023 09:53] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03752 seconds