! Copyright (C) 2004, 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: compiler-frontend USING: compiler-backend inference kernel lists math namespaces words strings errors prettyprint kernel-internals ; : >linear ( node -- ) #! Dataflow OPs have a linearizer word property. This #! quotation is executed to convert the node into linear #! form. "linearizer" [ "No linearizer" throw ] apply-dataflow ; : (linearize) ( dataflow -- ) [ >linear ] each ; : linearize ( dataflow -- linear ) #! Transform dataflow IR into linear IR. This strips out #! stack flow information, flattens conditionals into #! jumps and labels, and turns dataflow IR nodes into #! lists where the first element is an operation, and the #! rest is arguments. [ %prologue , (linearize) ] make-list ; : linearize-simple-label ( node -- ) #! Some labels become simple labels after the optimization #! stage. dup [ node-label get ] bind %label , [ node-param get ] bind (linearize) ; #simple-label [ linearize-simple-label ] "linearizer" set-word-prop : linearize-label ( node -- ) #! Labels are tricky, because they might contain non-tail #! calls. So we push the address of the location right after #! the #label , then linearize the #label , then add a #return #! node to the linear IR. The simplifier will take care of #! this in the common case where the labelled block does #! not contain non-tail recursive calls to itself.