charly-vm icon indicating copy to clipboard operation
charly-vm copied to clipboard

Operator overloading

Open KCreate opened this issue 3 years ago • 0 comments

  • Major operators should be overloadable to implement custom domain-specific operations
  • Some keywords should be overloadable, like await
  • Some language constructs should be overloadable
    • Index access / call operation
  • Operator functions cannot be made static
class Vec2 {
  property x
  property y

  operator +(other) {
    Vec2(x + other.x, y + other.y)
  }

  operator -(other) {
    Vec2(x - other.x, y - other.y)
  }

  operator [](index) {
    // index access
  }

  operator []=(index, value) {
    // index assignment
  }

  operator ()(args) {
    // call operator
  }
}

KCreate avatar Mar 30 '22 19:03 KCreate