Historically, we did not support calling (register-type) within a
module--while there were instances of such calls (even in our core
library!) they were not properly handled in two ways:
1. They weren't added to the right place in the type environment.
2. Their corresponding emitted code wasn't correct.
This commit enables registering types in modules by making a few fixes:
1. Fix the logic in environment mutations -- before, adding a type to an
environment would result in traversing the environment chain
incorrectly. This is now fixed (we traverse modules and retrieve a
type environment only at the end of the traversal).
2. Fix the typedef emission for registered types--it previously emitted
the C code for the type path, not for the type definition (it called
pathToC not tyToC).
This will now allow authors of wrapper libraries to add more structure
to their Carp wrapper APIs.
This commit also adds a test to check the behavior.