[dmd-internals] Type-checked arrays!

Michel Fortin michel.fortin at michelf.com
Tue Jul 5 15:04:41 PDT 2011


I've made a new branch of the DMD compiler to replace the currently type-unsafe Array type with arrays that can be type-checked by the compiler. It's not ready for a pull request yet, but I'd like to hear some comments.

Take a look at the changes:
<https://github.com/michelf/dmd/compare/master...type-checked-arrays>

The basic goal is that you no longer have to cast to the right type when getting something out of an array (except for some exceptional cases). In arraytypes.h you define an array of the type you need using the ArrayOf macro like this:

	struct Expression;

	typedef ArrayOf(Expression) Expressions;

And voilà! you have a type-safe array-of-Expression type. Instead of accessing the 'data' member directly, you now access 'tdata()' (for typed-data) which gets you a properly typed pointer:

	Expression *e = array->tdata()[0];
	array->tdata()[0] = e;

I know it's ugly, but unfortunately C++ doesn't have properties. I'm open to suggestions.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-internals mailing list