brombres / Rogue

Rogue programming language. Ergonomic, object-oriented, high-level, multi-platform, compiles to C.
MIT License
29 stars 8 forks source link

Consider initializing properties of default compounds #53

Open AbePralle opened 5 years ago

AbePralle commented 5 years ago

If a compound XYZ has this property definition:

PROPERTIES
  z = 1 : Int32

Then z will be initialized to 1 in these lines:

PROPERTIES
  point = XYZ()
...
local point = XYZ()

but not in these lines:

PROPERTIES
  point : XYZ
...
local point : XYZ

Consider initializing compounds as default locals, properties, and global properties. There are two different mechanisms that would need to be changed.

  1. Adding the initializations to the default constructor of the C++ struct should take care of local and global property declarations.

  2. Because objects start out as a zeroed chunk of memory that is cast to a C++ struct on property access, here we need to modify each class's init_object() method to explicitly set each property compound to a new default struct.

MurphyMc commented 5 years ago

An alternate approach would be to use C++ features to handle this (instead of init_object()), though it's probably more work (possibly a lot more) and not necessarily a clear win.