Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Rethink the the parser/compiler architecture #37

Closed
rstacruz opened this Issue Jun 9, 2011 · 1 comment

Comments

Projects
None yet
2 participants
Owner

rstacruz commented Jun 9, 2011

Currently, the procedures that translate a Node into a string (for (x;y;z) { a } => x; while y; a; z) is tied too much into the procedures that transform a Node into another Node (if typeof x != 'undefined' => unless x?). I think they should be decoupled to make more optimizations easier and more maintainable.

Currently, js2coffee works like this:

  1. Ask Narcissus to build a tree of the source JS
  2. Js2coffee's Builder traverses this tree and builds a CS source from it

It should be more like:

  1. Ask Narcissus to build a tree of the source JS
  2. Transform this tree by traversing it and making optimizations along the way (+++)
  3. Js2coffee's Builder traverses this new tree and builds a CS source from it

During that transformation step, that's when the Coffee'isms like the following should be made:

  • ifs should be made unless when the condition can be negated simply
  • typeof x == 'undefined' should be made into existential checks
  • switch nodes should be ensured that there aren't unnecessary break statements
  • when A: when B: should be consolidated to a compound when A, B:
  • etc...
Contributor

michaelficarra commented Jun 9, 2011

Yep , you must separate the AST manipulation step from the compilation step. You should probably continue taking manipulation passes over the tree until you reach a fixpoint. +1.

@rstacruz rstacruz added a commit that referenced this issue Jun 10, 2011

@rstacruz rstacruz Separate the tree manipulation step from the build step. See #37. Als…
…o, fix 'x.prototype.y' to be 'x::y' instead of 'x::.y'; and omit many unneeded parentheses in certain cases.
bea11d2

@rstacruz rstacruz closed this Jun 10, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment