🐌
Yours truly is not an expert in compilers but does enjoy diving into this topic and learning something new from time to time.

Cool 2020 is a small Scala subset with minor incompatibilities. The incompatibilities have been introduced to simplify the language. But an unfortunate side-effect is that a Cool 2020 program cannot be compiled by a Scala compiler or executed in an online Scala playground as is.

Luckily, remedying this problem is rather easy. Here’s is the Scala code that makes it possible to compile Cool 2020 sources by a Scala compiler or execute them in an online Scala playground.

class ArrayAny(len: Int) {
  var _array = new Array[Any](len);
  def length(): Int = _array.length;
  def get(i: Int): Any = _array(i);
  def set(i: Int, value: Any): Unit = _array(i) = value;
}

class IO {
  def out_string(s: String): Unit = print(s);
  def out_int(i: Int): Unit = print(i);
  def out_nl(): Unit = println();
}

object Program {
  def main(args: Array[String]): Unit = {
    new Main()
  };
}

Equipped with the code above, we can try to execute the following Cool 2020 program using Scastie (follow the link to try it yourself).

class Main() {
  {
    var io: IO = new IO();
    io.out_string("Hello, Cool 2020!");
    io.out_nl()
  };
}