I made a lot of progress implementing auto-boxing and type checking (these two features are very intertwined).
There is a new step in the compiler pipeline called CheckTypes which walks the abstract syntax tree looking for places where we should perform a type check (such as returns and assignments). It does the type check using a new TypeChecker class. This check can fail, succeed, or succeed by modifying the abstract syntax tree to insert an "auto conversion".
Basically auto conversions will include a lot of stuff like Int to Real upcasts, auto-boxing and unboxing of primitives, and Fan wrappers of arrays.
I've added support for auto-boxing and unboxing of primitives. This is represented in the AST as a standard CastExpr. The assembler code can detect this using the new Type.isRefType() method:
if (!from.isRefType() && to.isRefType()) // auto-boxing
if (from.isRefType() && !to.isRefType()) // auto-unboxing
Support for auto-conversions in method calls is more complicated, because of method overloading. When we are searching for methods that match the call arguments, we have to take into consideration that an auto-conversion might create a match. I refactored MethodResolver to use the TypeChecker code for matching and to insert the auto-conversions into the argument expressions.
I've also added two new top level tests: AutoBoxTest and CheckTypeTests.
brian Sun 18 Dec 2005
I made a lot of progress implementing auto-boxing and type checking (these two features are very intertwined).
There is a new step in the compiler pipeline called CheckTypes which walks the abstract syntax tree looking for places where we should perform a type check (such as returns and assignments). It does the type check using a new TypeChecker class. This check can fail, succeed, or succeed by modifying the abstract syntax tree to insert an "auto conversion".
Basically auto conversions will include a lot of stuff like Int to Real upcasts, auto-boxing and unboxing of primitives, and Fan wrappers of arrays.
I've added support for auto-boxing and unboxing of primitives. This is represented in the AST as a standard CastExpr. The assembler code can detect this using the new Type.isRefType() method:
Support for auto-conversions in method calls is more complicated, because of method overloading. When we are searching for methods that match the call arguments, we have to take into consideration that an auto-conversion might create a match. I refactored MethodResolver to use the TypeChecker code for matching and to insert the auto-conversions into the argument expressions.
I've also added two new top level tests: AutoBoxTest and CheckTypeTests.