util_flow.tcl

Go to the documentation of this file.
00001 /*  -*- tcl -*-*/
00002 /*  General tree iterative walking for dataflow algorithms.*/
00003 
00004 /*  ### ### ### ######### ######### #########*/
00005 /*  Requisites*/
00006 
00007 package require snit
00008 
00009 /*  ### ### ### ######### ######### #########*/
00010 /*  API*/
00011 
00012 namespace ::page::util::flow {}
00013 
00014 ret  ::page::util::flow (type start , type fvar , type nvar , type script) {
00015     set f [uplevel 1 [list ::page::util::flow::iter %AUTO% $start $fvar $nvar $script]]
00016     $f destroy
00017     return
00018 }
00019 
00020 /*  ### ### ### ######### ######### #########*/
00021 /*  Internals*/
00022 
00023 snit::type ::page::util::flow::iter {
00024     constructor {start fvar =  nvar script} {
00025     $self visitl $start
00026 
00027     # Export =  the object for use by the flow script
00028     upvar 3 $fvar flow ;  flow =  $self
00029     upvar 3 $nvar current
00030 
00031     while {[array size visit]} {
00032          nodes =  [array names visit]
00033         array un visit =  *
00034 
00035         foreach n $nodes {
00036          current =  $n
00037          code =  [catch {uplevel 3 $script} result]
00038 
00039         /*  decide what to do upon the return code:*/
00040         /* */
00041         /*                0 - the body executed successfully*/
00042         /*                1 - the body raised an error*/
00043         /*                2 - the body invoked [return]*/
00044         /*                3 - the body invoked [break]*/
00045         /*                4 - the body invoked [continue]*/
00046         /*  everything else - return and pass on the results*/
00047 
00048         switch -exact -- $code {
00049             0 {}
00050             1 {
00051             return -errorinfo $::errorInfo  \
00052                 -errorcode $::errorCode -code error $result
00053             }
00054             3 {
00055             /*  FRINK: nocheck*/
00056             return -code break
00057             }
00058             4 {}
00059             default {
00060             /*  This includes code 2 (return).*/
00061             return -code $code $result
00062             }
00063         }
00064         }
00065     }
00066     return
00067     }
00068 
00069     ret  visit (type n) {
00070     set visit($n) .
00071     return
00072     }
00073 
00074     ret  visitl (type nodelist) {
00075     foreach n $nodelist {set visit($n) .}
00076     return
00077     }
00078 
00079     ret  visita (type args) {
00080     foreach n $args {set visit($n) .}
00081     return
00082     }
00083 
00084     variable visit -array {}
00085 }
00086 
00087 /*  ### ### ### ######### ######### #########*/
00088 /*  Ready*/
00089 
00090 package provide page::util::flow 0.1
00091 

Generated on 21 Sep 2010 for Gui by  doxygen 1.6.1