Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operator overloading. #5

Open
4 tasks
Dich0tomy opened this issue May 25, 2022 · 0 comments
Open
4 tasks

Add operator overloading. #5

Dich0tomy opened this issue May 25, 2022 · 0 comments

Comments

@Dich0tomy
Copy link
Collaborator

Dich0tomy commented May 25, 2022

Status

Nothing implemented yet.
Just leaving it here for further updates and notes.

TBD.

Conversion operators parse.
Started implementing them, the progress is saved on the experimental-operator-overloading branch.

Checklist

  • In-class syntax, maybe outside of classes too
  • Syntax parsing
  • Proper implementation of simple operator overloading (See Implementation idea)
  • ??? Probably template operator overloading

Syntax idea

This is how a method declaration looks right now:

class Ooga {
  fooga(arg: Int32) {
    ret 5 + 1;
  }
}

I suggest this syntax for operators:

class Ooga {
  operator ==(arg: Int32) {
    return arg == 1;
  }
}

For a differentation between prefix and postfix I suggest special keywords pre and post (the C++ approach of putting an int parameter is simply weird and misleading):

class Ooga {
  operator post ++ {
    return ;
  }
  operator pre ++ {
    return ;
  }
}

(The idea of having pre and post operators may be completely ditched)

For conversion operators this syntax has been decided upon:

class Ooga {
  operator as Int32 { return 5; }
}

Implementation idea

Every operator goes through the same function in ExpressionExecutor.
Each operator generally does some kind of preprocessing first.

I suggest that each operator does it's preprocessing and calls a special function that looks for operator overloads for a type, with the types provided by the caller.
If it fails, it throws a runtime error, if it succeeds, it returns the result of calling that function.

Syntax preview

Nothing yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant