WIP: Parts of this repo don't work properly yet. If something is crashing dumbjs and it doesn't seem like an intentional dumbjs-originated limitation, file an issue!
- Flatten the dependency tree like browserify does, turning it into a single file so js2cpp doesn't need to care about more than one file.
- Without any name collisions, unwrap functions so as to leave no nested function.
- Separate definitions from declarations, so that var x = 3 in the global scope becomes var x; x = 3, then put every statement that performs any action (assignment or function call) in the global scope, in order, in a single function called "main", whose last statement will be "return 0".
This document has been invaluable in understanding the difficulties and nuances of implementing closures, and describes complicated problems in a way that's easily understandable.
This wikipedia article describes the main problem of implementing closures, and why you can't store functions and their closures on the stack if you want functions in your language to be first-class.