Commits

Pjotr Kourzanov committed 82b557a

more refactoring

Comments (0)

Files changed (3)

src/sequel/beseq.nw

 <<process>>=
 (define (gxf:handle-endpoint sxml i p) (begin ;(debug i p)
     `((,i ,(car (gxf:handle-port (Xs sxml "gxf/node[id=$n]/port[id=$p]"
-				     where [$n = (Xs sxml "gxf/node[id=$n]/stereo-type/text()"
-						     where [$n = i])]
-				     [$p = p])))))))
+				  where [$n = (gxf:super-node sxml i)]
+				  [$p = p])))))))
 
 @ The function to retrieve unconnected ports for a graph
 
 		`(nodetype ,@(forall ([ni <- x])
 			      return (list (X ni id)
 					   (car (Xs sxml "gxf/node[id=$n]"
-						    where [$n = (cadr (cadddr ni))]))))
+						 where [$n = (cadr (cadddr ni))]))))
 			   )))
 	  ; Retrieve all input (and output) ports for each type node
 	  (nodetype     . ,(lambda (t . x) <<retrieve input and output ports>>))
 	    ;(debug schedule)
    ;(debug edge-names edge-conns edge-occs)
    (forall ([x <- edge-occs])
-	   do (out "char" (car x)
-		   (cat "[" (%cadddr x)
-			"+" (%caddddr x)
-			"];")))
+    do (out "char" (car x)
+	    (cat "[" (%cadddr x)
+		 "+" (%caddddr x)
+		 "];")))
    (out tail:"" schedule)))))
 
 @ This code snippet returns an association between the edge and corresponding (generated) variable name.
 ((zip2-with cons)
  (map car edge-names)
  (forall ([y <- (map car (array->list mb))])
-	 return (cons 0 (cons 0 (cons y (cons 0 #f))))))
+  return (cons 0 (cons 0 (cons y (cons 0 #f))))))
 
 @ This returns a ``database'' of all edges and rates, indexed by the node/port pair. Note
   that the rates have to be calculated using type information right here.
 
 <<activate sub-nodes>>=
 (forall ([n <- (Xs in "gxf/node[id=$n]/node"
-		      where [$n = (Xs in "gxf/node[id=$n]/stereo-type/text()"
-				      where [$n = ($ N)])])])
+		where [$n = (gxf:super-node in ($ N))])])
  do (let ([spill `(,empty . ,empty)]
 	  [prod-spill empty])
        (return (out "\n/* activating sub-node" (X n id) "of node" ($ N) "*/\n"
 		(car spill)
-		nl
 		(cat ($ N) "_" (X n id)) "(" (outs (out-list args)) ");"
 		(cdr spill))
         where [args = (gxf:argument-list N n edge-conns edge-occs spill)])))
 
 <<activate sub-codes>>=
 (forall ([n <- (Xs in "gxf/node[id=$n and meta/code[@context='iterative']]"
-			 where [$n = (Xs in "gxf/node[id=$n]/stereo-type/text()"
-				      where [$n = ($ N)])])])
+		where [$n = (gxf:super-node in ($ N))])])
  do (let ([spill `(,empty . ,empty)]
 	  [ports (Xs n '(port id *text*))])
-       (return (out "\n/* activating node" (X n id) "*/"
+       (return (out "\n/* activating node" (X n id) "*/\n"
 		    (car spill)
-		    (lfold< cat nl ((zip2-with (lambda (v b) (cat "#define " v " " b nl)))
+		    (lfold< cat "" ((zip2-with (lambda (v b) (cat "#define " v " " b nl)))
 				    ports
 				    args
 				    ))
     (let* ([adm (or (assq buf edge-occs) `(foo none0 none1 none2 . none3))]
 	   [old-rp (cadr adm)]
 	   [old-wp (caddr adm)]
+	   [bufsize (cadddr adm)]
+	   [old-spill (car (cddddr adm))]
+	   [full (cdr (cddddr adm))]
+	   [avail (+ (- old-wp old-rp) (if [or (< old-wp old-rp) full] bufsize 0))]
+       	   [free  (+ (- old-rp old-wp) (if [or (> old-rp old-wp) full] 0 bufsize))]	   
 	   [new-rp (+ old-rp (if [is-prod p] 0 rate))]
 	   [new-wp (+ old-wp (if [is-cons p] 0 rate))]
-	   [bufsize (cadddr adm)]
 	   [nrp (modulo new-rp bufsize)]
 	   [nwp (modulo new-wp bufsize)]	   	   
-	   [old-spill (car (cddddr adm))]
-	   [full (cdr (cddddr adm))]
 	   [new-spill (- (if [is-cons p] new-rp new-wp) bufsize)]
-	   [new-adm (cons nrp
-			  (cons nwp
-				(cons bufsize
-				      (cons (max old-spill new-spill)
-					    (if [is-cons p]
-						#f;(not (= nrp nwp))
-						(= nrp nwp))))))]
-	   [avail (+ (- old-wp old-rp) (* bufsize (if [or (< old-wp old-rp) full] 1 0)))]
-       	   [free  (+ (- old-rp old-wp) (* bufsize (if [or (> old-rp old-wp) full] 0 1)))])
+	   [new-adm (cons nrp (cons nwp (cons bufsize
+			(cons (max old-spill new-spill)
+			      (if [is-cons p] #f
+				  (= nrp nwp))))))])
        ;(debug new-spill)
-       (if [> new-rp bufsize]
-	   (set-car! spill (cat nl
+       (if [> new-rp bufsize] (set-car! spill (cat 
 				 (car spill)
 				 "memcpy("
 				 "&" buf "[" (% bufsize) "],"
 				 "&" buf "[0],"
 				 (% new-spill)				 
-				 ");")))
-       (if [> new-wp bufsize]
-	   (set-cdr! spill (cat nl
+				 ");"
+				 nl)))
+       (if [> new-wp bufsize] (set-cdr! spill (cat
+				 nl
 				 (cdr spill)
 				 "memcpy("
 				 "&" buf "[0],"
 				 ");")))
        (set-cdr! adm new-adm)
        (if [is-cons p]
-	   (begin (if [> rate avail] (error "gxf:access-pointer" "underflow" `(> ,rate ,avail ,p)))
+	   (begin ;(if [> rate avail] (error "gxf:access-pointer" "underflow" `(> ,rate ,avail ,p)))
 	      old-rp)
-	   (begin (if [> rate free] (error "gxf:access-pointer" "overflow" `(> ,rate ,free ,p)))
+	   (begin ;(if [> rate free] (error "gxf:access-pointer" "overflow" `(> ,rate ,free ,p)))
 	      old-wp)))))
 
 @ A version using one less element in each \mac{FIFO} buffer.

src/sequel/common.nw

 (define is-cons (lambda (p) (pair? ((sxpath '(const)) p))))
 (define is-prod (lambda (p) (null? ((sxpath '(const)) p))))
 
+@ Find the super-node (a node that defines the class, i.e., all ports and sub-nodes)
+  given a node [[N]]
+
+<<Miscellaneous>>=
+(define (gxf:super-node sxml N)
+   (Xs sxml "gxf/node[id=$n]/stereo-type/text()"
+    where [$n = N]))
+
 @ \subsection{GXF preprocessing}\label{ssec:preproc}
 
 @ Dump the \mac{GXF} to the filesystem...

src/sequel/sequel.nw

 	      (gxf:handle-port (Xs sxml "gxf/node[id=$n]/port[id=$p]"
 				   where [$n = (Xs sxml "gxf/node[id=$n]/stereo-type/text()"
 						   where [$n = i])]
-				   [$p = p]))));$
+				   [$p = p]))))
 
 @ This function retrieves the instantiation list from the \mac{SXML} representation of the graph. It supports instances and uses edges themselves to get to the ports.