From 990ad4ca729af2992640394e07e2fd9a9e279e79 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Wed, 12 Jul 2017 10:29:26 -0400 Subject: [PATCH] Pretty-print struct process instances --- racket/syndicate/core.rkt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/racket/syndicate/core.rkt b/racket/syndicate/core.rkt index 881fa45..4d5840b 100644 --- a/racket/syndicate/core.rkt +++ b/racket/syndicate/core.rkt @@ -69,6 +69,7 @@ (require "trie.rkt") (require "patch.rkt") (require "mux.rkt") +(require "pretty.rkt") ;; Events = Patches ∪ Messages (struct message (body) #:prefab) @@ -97,7 +98,10 @@ (struct quit (exn actions) #:prefab) ;; A Process is per-process data: (process Any Behavior Any) -(struct process (name behavior state) #:transparent) +(struct process (name behavior state) #:transparent + #:methods gen:syndicate-pretty-printable + [(define (syndicate-pretty-print proc [p (current-output-port)]) + (pretty-print-process proc p))]) ;; A PID is a Nat. ;; A Label is a PID or 'meta. @@ -238,6 +242,17 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(define (pretty-print-process proc p) + (match-define (process name behavior state) proc) + (fprintf p "PROCESS:\n") + (fprintf p " - Name: ~v\n" name) + (fprintf p " - Behavior: ~v\n" behavior) + (fprintf p " - ") + (display (indented-port-output 3 (lambda (p) (syndicate-pretty-print state p)) #:first-line? #f) p) + (newline p)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;;; Local Variables: ;;; eval: (put 'match-event 'scheme-indent-function 1) ;;; eval: (put 'match-event 'racket-indent-function 1)