How to add a new primitive type

My language should contain primitive data types, which are not part of java, for example unsigned int or bit. I added some normal concepts which extends the baselanguage Type concept. But now I want to setup the type system in MPS. I don't know how to specify a inference rule for this new types?
There are these structure nodes of type primitive datatype. But I also don't know what to do with them, since they only have a name and nothing more.
I think you should start with:
  • creating new concept for a type
  • creating new concept for a literal of this type
  • writing inference rule for literal concept saying a type of this literal is instance of type concept...

You can check IntegerConstant concept from the MPS base language.
OOps. seems like this message was already answered, but the answer is lost..
Thanks! That's what I've already done. But I still don't know what this primitive datattype nodes good for?

My current type problem is, that I've added a subtype of baselanguages IntegerType. But I want this new type to be compatible with IntegerType, too. So I could assign a normal integer literal to my own IntType without a cast. Can you please tell me the proper way to define that? I've tried several things, but all lead to errors or to a wrong behavior.
Sorry for cutting in. We are puzzled about where is your old (May 18) comment started with "Damn, I've figured it out by myself. The problem was...".
Its not here any more. Did you delete it?
No, I haven't deleted anything. I've just have a look to my mails and found this conversation with Magvay in this thread.

I definitely haven't understood all this type stuff...
I've got a declaration statement and a own type concept. For my declaration I've created this rule:
rule typeof_Declaration {      
  applicable for concept = Declaration as decl
  overrides false            
  do {            
    typeof(decl) :==: decl.type;  

And for my own type:
subtyping rule bit_extends_byte {        
  weak = false            
  applicable for concept = BitType as bit        
  rule {   
    return <byte>;        

If I create a declaration of baselanguages type int in my sandbox everything is fine, if I use bit instead I got a warning like
Type x3 was not calculated
wheras x3 seems to be a random name which can't be found in my code and changes from statement to statement.
So what else is necessary to build up a minimal surrounding for my own type? And how can I create a type which is completely independent to all java types?
Magvay @ 3:37 am
Our baseLanguage has primitive types such as byte or short. I think you can do it in the same way as in baseLanguage. Relations between this types are defined with subtyping rules (see byte_extends_short rule for example).

So I couldn't have deleted comments from other peoples.
You can check ShortType from MPS BaseLanguage. ShortType is a subtype of IntegerType and this relation is specified by the following subtyping rule for ShortType:
subtyping rule short_extends_int {
  weak = false     
  applicable for concept = ShortType as shortType
  supertypes {     
    return <int>;  
The subtype relation is not the problem. But in Java you can also write
short s = 4;
This isn't allowed in baselanguage, since 4 is of type int which is no subtype of short. So I can't see the solution to my problem in the baselanguage's code. Is there any way to allow such a relation without having a subtype loop?
I already created an issue for this problem some time ago:
I think sub-typing loop should not be a problem: you can create "weak" subtyping rule saying that IntegerLiteral with the 16-bit value is subtype of ShortType. Please try if this works in your use case.

Please sign in to leave a comment.