onyx-lang / onyx

✨ The compiler and developer toolchain for Onyx

Home Page:https://onyxlang.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Parameters should actually be read-only

brendanfh opened this issue · comments

Currently, parameters are lightly assumed to be read-only by the code generator, and the code generator will make mistakes if parameters are modified. This mostly affects structs and unions passed by value, as they consume stack memory that is not handled correctly. I believe to fix the actual problems with memory corruption would be rather difficult and would not solve all of the problems.

Instead, I think parameters should be enforced as read-only. This is how most other languages operate. It also allows me to implement compiler optimizations in the future, like transparently passing a reference to a structure because I know it cannot be changed.