Implemented stack traces

I rebased patches and refactored some files as discussed at meeting. (see also pull request at shims)

I'll be reading the code and adding inline comments/questions. @luite it would be great if you could review and post inline comments if you're not happy with some parts. It'll be easier to track changes this way.
extern cost-centres should be linked from modules they're defined in, but that part is not implemented so I'm declaring external cost-centres here.