whitequark / ast

A library for working with Abstract Syntax Trees.
MIT License
195 stars 25 forks source link

process context #9

Closed rubydesign closed 9 years ago

rubydesign commented 9 years ago

So, i am moving on to processing the ast with the Processor. Alas, in my current compiler, i use a context that is passed to the transformation, for side effects.

Basically whatever i pass to the process method as a second parameter, ie

process(node , context)

i would need to be passed through to the on_xx as the second parameter, eg

on_xxx(node , context)

The process function could have the context = nil default and if nil, the nil would not be passed on to the on_xx. That way existing code wouldn't break.

Also, i think one arg will be the extent of the change, as one can always use a hash or something if one actually needs more.

Any chance you would accept a pull for this, or shall i just stick with my own processor.

whitequark commented 9 years ago

Use an instance variable.

rubydesign commented 9 years ago

in some calls i change the context. In essence i need a stack, and the call stack provides it. I do believe a context is quite a general thing in compiling / processing ast's .

But i did mean to ask, because what i pick up from this kind of terse comment is off course that i am intruding. So the question is, do you want to improve this gem for more general (outside your own) usage ? Because there are likely to be more of these, and i don't want to intrude. I can easily keep my code to myself.

whitequark commented 9 years ago

If you need a stack, use a stack in an instance variable... different processors need wildly different management of context (in my experience you need many contexts, e.g. fifteen in this one: https://github.com/m-labs/artiq/blob/new-py2llvm/artiq/compiler/transforms/artiq_ir_generator.py#L73-L88) and a single argument is a very narrow solution anyway.

whitequark commented 9 years ago

It's OK that you open these issues, just please keep in mind that I am aiming only for most general features to go into ast. Your inspect PR is certainly very useful!

rubydesign commented 9 years ago

fair enough, i'll try the instance