adam-mcdaniel/oakc

copy constructors and destructors

Closed this issue · 3 comments

Right now, memory management is entirely manual. With the introduction of copy constructors and destructors, memory management can be easier for the user.

A potential solution is to implement the copy and drop methods for all user types. If the user defines these functions themselves, then they will not automatically be provided. Everywhere a non-pointer object is used in an assignment (such as in a method or function call, or in a variable definition/assignment), call the copy method of the object. At the end of each function's scope, call the drop method of every non-pointer object.

This style emulates C++'s take on memory management.

Sounds great. But would that make copy and drop special functions inside a type declaration? I'm not sure I like the idea of reserving names for those methods.

The compiler would automatically add hidden copy and drop methods to all types without them, and require that all copy or drop methods have specific type signatures when defined by the user. How would you personally go about adding copy constructors and destructors without reserving special methods like this?

My point is that those 2 names would be reserved by the language. I don't know if it is an option but maybe a keyword or some variation in syntax would be a different way of implementing this. for example C++ combines the name of the class and its signature to implement these semantics. That would have my preference over never being able to implement a copy or drop method on my own types.