Re: [stack] Constant folding algorithm
"Daniel Ehrenberg" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
> So, I'm assuming you are hacking the compiler source code? You can > modify it slightly to detect underflow without waiting for exceptions, > which is admittedly quite ugly. No, I'm not doing anything with the compiler source code. This is a separate project and is implemented through quotation introspection. But the way that the Factor error handling system works, it is possible to trap stack underflow at runtime. Also, each word has it marked whether it's suitable for constant folding (for the compiler's use, but I can take advantage...) > That really surprise me, because I always thought that a language like > Joy or Cat (where there is only one explicit stack) was as easy to > work with as SSA. I suspect it is because Slava does his own register > allocations? > It might not be difficult to convert a stack language to SSA, but I have no idea how to change it back into a quotation. Anyway, I don't think such a transformation would work for this, since it would change the quotation in other ways. > > For example, you could tell that (+ x (* (- > > 4 5) 2)) can reduce, from the inside, to (+ x (+ -1 2)) and then to (+ > > x 1), though no further, since x is a (free) variable. But I hope I'm > > wrong and that a similarly simple, explicit algorithm is possible. > > Why not remove free variables (e.g. pass them as parameters)? It > simplifies a lot of analyses. > What do you mean? Daniel Ehrenberg