julelang / jule

Effective programming language to build efficient, fast, reliable and safe software while maintaining simplicity
https://jule.dev
BSD 3-Clause "New" or "Revised" License
128 stars 13 forks source link

jule: reimplement traits and functions #102

Closed mertcandav closed 5 months ago

mertcandav commented 5 months ago

Description

This PR reimplements traits and functions.

The old trait implementation uses C++ classes and abstraction. This new implementation uses its own abstraction implementation. Therefore, it's more open to change and manipulating than C++ abstractions.

The old function implementation uses C++ methods for structures. This new implementation uses its own implementation. Actually, all methods implemented as explicit functions. All method calls are forwarded to relevant functions with receiver parameter. If there is no abstraction like traits, there is no additional runtime cost for forwarding. If method calling from trait, implementation will use table to access wrapper function with additional minimal runtime cost. Also old implementation checks nil status for smart pointer receivers, the new implementation just passes receiver to function without any nil check.

The new implementation is not comes with huge effects on efficiency and performance as far as I tested. It uses table for relevant wrapper functions to call actual type's functions which is common method to achieve this.

Additional