kovasb / gamma

glsl shaders made simple
Eclipse Public License 1.0
306 stars 20 forks source link

Refactor compiler #38

Open kovasb opened 7 years ago

kovasb commented 7 years ago

The compiler is too complicated for people to contribute / fix their bug.

A - Document how stuff works B - Add compiler tests for key transformations C - Refactor D - Profit

How Stuff Works

User generates gamma ast. This is a tree. Compiler gets tree. First: flatten-ast . This turns tree into a graph; we call this the 'db'. Right now all transforms operate on this graphlike 'db'. This causes complexity. ToFix.

Transformation 1: bubble-terms. This generates information needed for detecting common subexpressions. For each subexpression in the db, we traverse its parents up the tree. For each parent, we associate the start node to its meta info (:shared ) Specifically, we add it to a hashmap of { start-node times-seen } Every time a node equivalent to start-node passes though a parent on the way up, we increment this count. This principle is extended to deal with conditionals. If a node is scoped within an 'if' it will not necessarily evaluate. However we wish to propagate this information. Therefor node counts

[todo more description]