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.
We don't need to handle cost-centres here because `encodeStatic` is only used when both `-debug` and `-prof` is disabled.