I'm working on my first DSL in MPS and am struggling a bit with my type system, which should work like a standard Object Oriented language (e.g. Java).
My language needs to allow users to declare:
- methods which return a type and accept a collection of parameters(references to designated types)
- method calls, which pass typed references or literals to the called method
I have tried setting up a "Type" concept, which has a string property (the type's name). I have then created an interface (ITypeReference), which references a type, and a corresponding comparison rule which considers two ITypeReference nodes equal if their type strings are equivalent.
I have created my method class, which contains a list of parameters and return type, and I can create a method call, which references another method, and allows designation of ITypeReference nodes as arguments.
However, I'm having trouble figuring out the key next steps:
- How do I enforce that the each argument's type must match the called method's parameter type?
I have tried writing an inference rule, but it's clear that I'm working outside of MPS's native node-typing system, so cannot use type comparison symbols like :==:. Perhaps I'm just going about this whole thing the wrong by instituting my own types based off of string names? Is there some way to plug into MPS's internal typing system for this so that I can allow solution programmers to declare types which will extend MPS's internal type system?
It seems like there would be an example project for this, but I haven't found it yet.
- Related, how do I restrict the number of arguments which can be passed to a method to the corresponding number of parameters of the method?
For example, if a method accepts 2 parameters, someone calling that method should only be allowed to use 2 arguments. I don't seem to be able to dynamically refer to the number of arguments in the methodCall structure's declaration. Perhaps this is possible via the editor?
Hopefully this makes sense! If not, I'm happy to try providing some example syntax to clarify. Thanks in advance for any assistance!!