Thursday, January 4, 2024

Emitting a Graph

I've been examining a new emitter that involves rewriting directed acyclic graphs (DAGs). Specifically, when Egel rewrites a combinator, the bytecode of the combinator needs to produce another segment of the DAG.

In light of this, I've been sketching out an algorithm to address this requirement. Below is an example of a new graph that could be the outcome of rewriting a combinator node.


In the representation, solid lines indicate constants, and dotted lines point to redexes that must be rewritten in a particular sequence. Exception handlers are omitted for clarity.

As the rewritten graph node serves as the apex of a DAG, it seems likely that I'll need some form of stack to systematically process AST nodes in a specific order. This processing order is crucial for generating bytecode that effectively constructs the desired graph.

It's a neat puzzle.

1 comment:

  1. Hoisting out redexes prior to bytecode generation seems the most sensible thing to do.

    ReplyDelete