nitlang / nit

Nit language
http://nitlanguage.org
Apache License 2.0
239 stars 65 forks source link

compiler: Refactored `AbstractRuntimeFunction` #2782

Closed Louis-Vincent closed 5 years ago

Louis-Vincent commented 5 years ago

Removed duplicate code across all the compiler and made AbstractRuntimeFunction implement Template Design pattern. This allows for better code reuse and easier customization.

Removed the notion of "virtual function" and unified it with the concept of thunk function. A thunk is an intermediary function between a caller and a callee whose purpose is to compute thing before or after the callee gets invoke. Currently, the only usages of thunks are to do conversions (casting) before calling the actual callee. Thunks can be created by inheriting abstract_compiler::ThunkFunction which provides a default implementation. Furthermore, this class simplify the old code of SeparateRuntimeFunction by replacing if with actual polymorphism.

Finally, thunks will be used to implement callref mechanics.

Signed-off-by: Louis-Vincent Boudreault lv.boudreault95@gmail.com