/* Only reachable if GUILE exits. That is an error. */
return 1;
}
-
-SCM atexit_list = SCM_EOL;
-
-LY_DEFINE (ly_atexit, "ly:atexit",
- 2, 0, 0, (SCM proc, SCM args),
- "Just before exiting, call the procedure given. "
-"If this is called multiple times, the procedures are called "
-"in LIFO order.")
-{
- atexit_list = scm_cons (scm_cons (proc, args), atexit_list);
- scm_gc_protect_object (atexit_list);
- return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_do_atexit, "ly:do-atexit",
- 0, 0, 0, (),
- "Call the atexit procedures.")
-{
- for (SCM s = atexit_list; scm_is_pair (s); s = scm_cdr (s))
- scm_apply_0 (scm_caar (s), scm_cdar (s));
- return SCM_UNSPECIFIED;
-}
(define-module (scm graphviz)
#:use-module (lily)
#:export
- (make-graph add-node add-edge add-cluster
- graph-write
- ))
+ (make-empty-graph add-node add-edge add-cluster
+ graph-write
+ ))
-(define (make-graph filename)
- #(() () () ()))
+(define graph-type (make-record-type "graph" '(nodes edges clusters name)))
+(define make-graph (record-constructor graph-type))
+(define (make-empty-graph name) (make-graph '() '() '() name))
-;; fixme: use structs/records.
-;; fixme add & use setters.
-(define (nodes g) (vector-ref g 1))
-(define (edges g) (vector-ref g 2))
-(define (clusters g) (vector-ref g 3))
+(define nodes (record-accessor graph-type 'nodes))
+(define edges (record-accessor graph-type 'edges))
+(define clusters (record-accessor graph-type 'clusters))
+(define set-nodes! (record-modifier graph-type 'nodes))
+(define set-edges! (record-modifier graph-type 'edges))
+(define set-clusters! (record-modifier graph-type 'clusters))
(define (add-cluster graph node-id cluster-name)
(let* ((cs (clusters graph))
(already-in-cluster (if cluster
(cdr cluster)
'())))
- (vector-set! graph 3 (assq-set! cs
+ (set-clusters! graph (assq-set! cs
cluster-name
(cons node-id already-in-cluster)))))
(define (add-node graph label . cluster-name)
(let* ((ns (nodes graph))
(id (length ns)))
- (vector-set! graph 1 (cons `(,id . ,label) ns))
+ (set-nodes! graph (assq-set! ns id label))
(if (and (not (null? cluster-name))
(string? (car cluster-name)))
(add-cluster graph id (car cluster-name)))
id))
(define (add-edge graph node1 node2)
- (vector-set! graph 2 (cons `(,node1 . ,node2) (edges graph))))
+ (set-edges! graph (cons `(,node1 . ,node2) (edges graph))))
(define (graph-write graph out)
(let ((ns (nodes graph))