Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.

import extensions;
 
sealed struct TinyInt : BaseNumber
{
    int value;
 
    int cast() = value;
 
    constructor(int n)
    {
        if (n <= 1 || n >= 10)
        {
            InvalidArgumentException.raise()
        };
 
        value := n
    }
 
    cast t(string s)
    {
        value := s.toInt();
 
        if (value <= 1 || value >= 10)
        {
            InvalidArgumentException.raise()
        }
    }
 
    TinyInt add(TinyInt t)
        = value + (cast int(t));
 
    TinyInt subtract(TinyInt t)
        = value - (cast int(t));
 
    TinyInt multiply(TinyInt t)
        = value * (cast int(t));
 
    TinyInt divide(TinyInt t)
        = value / (cast int(t));
 
    bool equal(TinyInt t)        
       = value == (cast int(t));
 
    bool less(TinyInt t)        
       = value == (cast int(t));
}
 
public program()
{
    TinyInt i := 4t;
    TinyInt j := i + i;
 
    try
    {
      i + j
    }
    catch(InvalidArgumentException e)
    {
        console.printLine("A value is out of range")
    }
}