ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:70505] [CommonRuby - Feature #11475] [Open] AST transforms
       [not found] <redmine.issue-11475.20150821090108@ruby-lang.org>
@ 2015-08-21  9:01 ` ml
  2015-08-21 10:45 ` [ruby-core:70511] [Ruby trunk - Feature #11475] " nobu
  2015-08-21 11:14 ` [ruby-core:70513] " me
  2 siblings, 0 replies; 3+ messages in thread
From: ml @ 2015-08-21  9:01 UTC (permalink / raw
  To: ruby-core

Issue #11475 has been reported by Josep M. Bach.

----------------------------------------
Feature #11475: AST transforms
https://bugs.ruby-lang.org/issues/11475

* Author: Josep M. Bach
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Even though Ruby is in many ways an acceptable Lisp, extending the language itself is a hard endeavour. By using reflection/meta-programming and taking advantage of its rich grammar, it's certainly possible to bend the language in extreme ways (believe me, I've done it), but there are a couple of serious limitations:

* Everything must be done at run-time, incurring in necessary overhead, sometimes unacceptably so.
* The resulting code must be valid Ruby not only syntactically, but also semantically. That forbids the introduction of new semantic constructs by users themselves.

Now, some people might argue in favour of a special DSL for compile-time macro-building, possibly augmenting the grammar and introduce all sorts of new tricks to do that. But I think that wouldn't be the most general solution, nor the most desirable. The alternative: a simple, object-oriented AST transforms API.

By building an AST transforms API and making it available to users, I argue that we could kill many birds with one stone:

* A rich macro system (or many!) could be implemented as a simple library, with no changes to core ruby.
* Some micro-optimizations could be implemented as a library, which may find their way into core ruby later.
* Experimental, new semantic constructs could be made available to users through simple libraries, and when time has proven their usefulness, maybe they could be implemented natively, if needed.

I'd be up for the task if there is enough interest -- what are people's thoughts on this?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:70511] [Ruby trunk - Feature #11475] AST transforms
       [not found] <redmine.issue-11475.20150821090108@ruby-lang.org>
  2015-08-21  9:01 ` [ruby-core:70505] [CommonRuby - Feature #11475] [Open] AST transforms ml
@ 2015-08-21 10:45 ` nobu
  2015-08-21 11:14 ` [ruby-core:70513] " me
  2 siblings, 0 replies; 3+ messages in thread
From: nobu @ 2015-08-21 10:45 UTC (permalink / raw
  To: ruby-core

Issue #11475 has been updated by Nobuyoshi Nakada.

Project changed from CommonRuby to Ruby trunk

Do you have any ideas for the API?

----------------------------------------
Feature #11475: AST transforms
https://bugs.ruby-lang.org/issues/11475#change-53912

* Author: Josep M. Bach
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Even though Ruby is in many ways an acceptable Lisp, extending the language itself is a hard endeavour. By using reflection/meta-programming and taking advantage of its rich grammar, it's certainly possible to bend the language in extreme ways (believe me, I've done it), but there are a couple of serious limitations:

* Everything must be done at run-time, incurring in necessary overhead, sometimes unacceptably so.
* The resulting code must be valid Ruby not only syntactically, but also semantically. That forbids the introduction of new semantic constructs by users themselves.

Now, some people might argue in favour of a special DSL for compile-time macro-building, possibly augmenting the grammar and introduce all sorts of new tricks to do that. But I think that wouldn't be the most general solution, nor the most desirable. The alternative: a simple, object-oriented AST transforms API.

By building an AST transforms API and making it available to users, I argue that we could kill many birds with one stone:

* A rich macro system (or many!) could be implemented as a simple library, with no changes to core ruby.
* Some micro-optimizations could be implemented as a library, which may find their way into core ruby later.
* Experimental, new semantic constructs could be made available to users through simple libraries, and when time has proven their usefulness, maybe they could be implemented natively, if needed.

I'd be up for the task if there is enough interest -- what are people's thoughts on this?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:70513] [Ruby trunk - Feature #11475] AST transforms
       [not found] <redmine.issue-11475.20150821090108@ruby-lang.org>
  2015-08-21  9:01 ` [ruby-core:70505] [CommonRuby - Feature #11475] [Open] AST transforms ml
  2015-08-21 10:45 ` [ruby-core:70511] [Ruby trunk - Feature #11475] " nobu
@ 2015-08-21 11:14 ` me
  2 siblings, 0 replies; 3+ messages in thread
From: me @ 2015-08-21 11:14 UTC (permalink / raw
  To: ruby-core

Issue #11475 has been updated by Josep M. Bach.


Nobuyoshi Nakada wrote:
> Do you have any ideas for the API?

My API idea is loosely based on the Rubinius' transform API, but without explicitly generating bytecode in the transform (that wouldn't be very portable, and it makes transforms hard to compose). Instead, the `#transform` method returns a new, immutable AST node. Here's how a user would implement their own transform:

```ruby
class MyTransform
  def matches?(ast_node)
    # return boolean indicating whether this particular AST node is targeted by our transform
  end

  def transform(ast_node)
    # return new, transformed ast node
  end
end

Compiler.add_transform(MyTransform.new)
```

Note that the AST nodes should be simple immutable values, such as the ones from whitequark's ast gem.

The semantics of Compiler.add_transform would be that, from that moment on, the parser stage of the compiler applies the transform. That means any subsequent `load`, `require` or `eval` calls would run the transform.

A side benefit of that is that transforms could be stacked in load order, and refine the AST progressively. Or another option is to have explicit order, a la Rack middleware, and be able to decide which transforms run before which.


----------------------------------------
Feature #11475: AST transforms
https://bugs.ruby-lang.org/issues/11475#change-53914

* Author: Josep M. Bach
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Even though Ruby is in many ways an acceptable Lisp, extending the language itself is a hard endeavour. By using reflection/meta-programming and taking advantage of its rich grammar, it's certainly possible to bend the language in extreme ways (believe me, I've done it), but there are a couple of serious limitations:

* Everything must be done at run-time, incurring in necessary overhead, sometimes unacceptably so.
* The resulting code must be valid Ruby not only syntactically, but also semantically. That forbids the introduction of new semantic constructs by users themselves.

Now, some people might argue in favour of a special DSL for compile-time macro-building, possibly augmenting the grammar and introduce all sorts of new tricks to do that. But I think that wouldn't be the most general solution, nor the most desirable. The alternative: a simple, object-oriented AST transforms API.

By building an AST transforms API and making it available to users, I argue that we could kill many birds with one stone:

* A rich macro system (or many!) could be implemented as a simple library, with no changes to core ruby.
* Some micro-optimizations could be implemented as a library, which may find their way into core ruby later.
* Experimental, new semantic constructs could be made available to users through simple libraries, and when time has proven their usefulness, maybe they could be implemented natively, if needed.

I'd be up for the task if there is enough interest -- what are people's thoughts on this?



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-21 10:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-11475.20150821090108@ruby-lang.org>
2015-08-21  9:01 ` [ruby-core:70505] [CommonRuby - Feature #11475] [Open] AST transforms ml
2015-08-21 10:45 ` [ruby-core:70511] [Ruby trunk - Feature #11475] " nobu
2015-08-21 11:14 ` [ruby-core:70513] " me

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).