From bd04ef6262b2875351519ef899e8795408ee15b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Tue, 17 Jan 2017 19:12:51 +0100 Subject: [PATCH] Printing bug when printing the set. --- Graph-notes-copy2.vue | 55 +- Graph-notes.mm | 50 - Graph-notes.vue | 1064 -------------------- graph-info.hl.rkt | 273 ++++- graph-type.hl.rkt | 91 ++ graph.hl.rkt | 12 +- scribblings/phc-graph-implementation.scrbl | 5 +- test/adt-pre-declarations.rkt | 8 + test/test-graph-type.rkt | 16 + 9 files changed, 414 insertions(+), 1160 deletions(-) delete mode 100644 Graph-notes.mm delete mode 100644 Graph-notes.vue create mode 100644 graph-type.hl.rkt create mode 100644 test/test-graph-type.rkt diff --git a/Graph-notes-copy2.vue b/Graph-notes-copy2.vue index fc34995..bf02533 100644 --- a/Graph-notes-copy2.vue +++ b/Graph-notes-copy2.vue @@ -1,14 +1,14 @@ - + - Graph-notes-copy2.vue @@ -3778,12 +3778,59 @@ 540 542 + + #F2AE45 + #776D6D + #000000 + SansSerif-plain-12 + http://vue.tufts.edu/rdf/resource/a68081d4c0a801286ae39894efbfa682 + + + + #404040 + #404040 + SansSerif-plain-11 + http://vue.tufts.edu/rdf/resource/a68081d5c0a801286ae398949e441433 + + + 357 + 544 + + + #F2AE45 + #776D6D + #000000 + SansSerif-plain-12 + http://vue.tufts.edu/rdf/resource/a68081d5c0a801286ae398942effba1f + + + + #404040 + #404040 + SansSerif-plain-11 + http://vue.tufts.edu/rdf/resource/a68081d6c0a801286ae398944c00f8fa + + + 544 + 546 + http://vue.tufts.edu/rdf/resource/6dbf6b15c0a80026548592b8d2f3fee2 - 1.0 - + 0.75 + #FFFFFF - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Graph-notes.vue b/Graph-notes.vue deleted file mode 100644 index 5ea38dd..0000000 --- a/Graph-notes.vue +++ /dev/null @@ -1,1064 +0,0 @@ - - - - - - - - - Graph-notes.vue - - - #FFFFFF - #404040 - #000000 - SansSerif-plain-14 - http://vue.tufts.edu/rdf/resource/6dbf6af7c0a80026548592b8dffca40a - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6afcc0a80026548592b833e3a781 - - - - #8AEE95 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6afec0a80026548592b88abb8384 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6affc0a80026548592b80b4ee7cc - - - 6 - 7 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b00c0a80026548592b8a0766ac6 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b01c0a80026548592b8a5bb4d0a - - - 7 - 9 - - - #8AEE95 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b03c0a80026548592b81914701e - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b04c0a80026548592b8c27d0837 - - - 6 - 11 - - - #8AEE95 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b05c0a80026548592b80343782b - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b06c0a80026548592b870fb7c6a - - - 6 - 13 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b07c0a80026548592b8f5e19e10 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b08c0a80026548592b840ee8fa0 - - - 6 - 15 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b09c0a80026548592b8217a1807 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b09c0a80026548592b8dfab693e - - - 13 - 17 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b0ac0a80026548592b87ee8d14b - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b11c0a80026548592b89f9e9272 - - - 13 - 19 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b12c0a80026548592b83be06baa - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b13c0a80026548592b8f03d2a45 - - - 13 - 21 - - - #8AEE95 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dbf6b14c0a80026548592b8bc35fbb9 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dbf6b14c0a80026548592b87410806e - - - 15 - 23 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dc1a307c0a80026548592b8c2af76c4 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dc1a307c0a80026548592b8a04c0bf0 - - - 11 - 25 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dc1a308c0a80026548592b8ff6b1596 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dc1a308c0a80026548592b8be3bbbf2 - - - 25 - 27 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dc1a309c0a80026548592b84e893214 - - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dc1a30ac0a80026548592b8ea42a1af - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dc1a30ac0a80026548592b87117f4c4 - - - 25 - 33 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dc1a30bc0a80026548592b83098fe4a - - - 33 - 29 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dc1a30bc0a80026548592b8e12add9f - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dc1a30cc0a80026548592b879e5ac96 - - - 33 - 36 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dc99799c0a80026548592b87d2d4299 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dc99799c0a80026548592b80979537c - - - 25 - 42 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcae10dc0a80026548592b847b6398e - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcae10dc0a80026548592b8f409d90b - - - 25 - 44 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcc34bcc0a80026548592b8808f2759 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcc34bcc0a80026548592b8748a3e11 - - - 17 - 46 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcc34bcc0a80026548592b879d2f6dd - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcc34bcc0a80026548592b88a1654a6 - - - 17 - 48 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcc34bcc0a80026548592b822f951f1 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcc34bcc0a80026548592b83b7795c3 - - - 17 - 50 - - - #BDE5F2 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcc935cc0a80026548592b89128dae1 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcc935cc0a80026548592b8c6445100 - - - 50 - 52 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcfe7a9c0a80026548592b81207b1b5 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcfe7a9c0a80026548592b8e2e22006 - - - 19 - 54 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcfe7a9c0a80026548592b89d70c39f - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcfe7aac0a80026548592b8bb000cae - - - 19 - 56 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcfe7aac0a80026548592b8b15cb8ab - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcfe7aac0a80026548592b8be3b9e4e - - - 21 - 58 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dcfe7aac0a80026548592b87a0fd91a - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dcfe7aac0a80026548592b8c1f4be82 - - - 21 - 60 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd2c0a80026548592b8b52eab6a - - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd2c0a80026548592b8d3f60760 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd2c0a80026548592b834c49dca - - - 50 - 68 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd2c0a80026548592b860a16421 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd3c0a80026548592b87d773be5 - - - 46 - 72 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd3c0a80026548592b8fba10e52 - - - 48 - 72 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd3c0a80026548592b8c655a6f4 - - - 72 - 65 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd3c0a80026548592b8aea1a2b1 - - - 72 - 68 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd3c0a80026548592b8f8515bcf - - - 56 - 65 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd3c0a80026548592b8b0891c54 - - - 56 - 68 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd4c0a80026548592b8c0ff55ee - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd4c0a80026548592b83f26b2af - - - 58 - 85 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd4c0a80026548592b8b1599cbd - - - 60 - 85 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd4c0a80026548592b8dae1d183 - - - 85 - 65 - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd4c0a80026548592b8d155bae3 - - - 85 - 68 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd4c0a80026548592b8697d13c4 - - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd4c0a80026548592b8efc854fb - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd5c0a80026548592b80278dac6 - - - 60 - 92 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd5c0a80026548592b8d0bf4afd - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd5c0a80026548592b8f824e3b9 - - - 58 - 94 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd5c0a80026548592b8dfa424c8 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd5c0a80026548592b8d9e35c75 - - - 68 - 101 - - - #FEFEC9 - #EA2218 - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd5c0a80026548592b8ddb5b6c7 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd5c0a80026548592b81da96232 - - - 90 - 103 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd6c0a80026548592b853276e56 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd6c0a80026548592b89262c338 - - - 90 - 105 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dd89bd6c0a80026548592b8c817c8d9 - - - - #404040 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dd89bd6c0a80026548592b88ac312bd - - - 90 - 107 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dda878ec0a80026548592b8416c8f4f - - - - #000000 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dda878ec0a80026548592b8d9e1112c - - - 107 - 109 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dda878ec0a80026548592b89f2f02ff - - - - #000000 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dda878ec0a80026548592b8274c2ea3 - - - 107 - 111 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dda878ec0a80026548592b8a59d8be9 - - - - #000000 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dda878ec0a80026548592b86e86d9d7 - - - 111 - 113 - - - #F2AE45 - #776D6D - #000000 - Arial-plain-12 - http://vue.tufts.edu/rdf/resource/6dda878fc0a80026548592b8d8c09cc8 - - - - #000000 - #404040 - Arial-plain-11 - http://vue.tufts.edu/rdf/resource/6dda878fc0a80026548592b84916a321 - - - 111 - 115 - - - http://vue.tufts.edu/rdf/resource/6dbf6b15c0a80026548592b8d2f3fee2 - - 1.2621478010021852 - - #FFFFFF - - - #B3993333 - #000000 - SansSerif-plain-14 - http://vue.tufts.edu/rdf/resource/6dbf6b16c0a80026548592b8204729d3 - - #000000 - #404040 - #000000 - SansSerif-plain-14 - http://vue.tufts.edu/rdf/resource/6dbf6b16c0a80026548592b817230376 - - #404040 - #FFFFFF - Gill Sans-plain-36 - http://vue.tufts.edu/rdf/resource/6dbf6b17c0a80026548592b88a8fba25 - - - - #404040 - #FFFFFF - Gill Sans-plain-22 - http://vue.tufts.edu/rdf/resource/6dbf6b17c0a80026548592b8c426a9c8 - - - - #404040 - #B3BFE3 - Gill Sans-plain-18 - http://vue.tufts.edu/rdf/resource/6dbf6b18c0a80026548592b8ea0d19d7 - - - - - - 2016-11-16 - 6 - /home/georges/phc/racket-packages/phc-graph - /home/georges/phc/racket-packages/phc-graph/Graph-notes.vue - diff --git a/graph-info.hl.rkt b/graph-info.hl.rkt index f108af9..35691ff 100644 --- a/graph-info.hl.rkt +++ b/graph-info.hl.rkt @@ -1,43 +1,236 @@ -#lang racket +#lang hyper-literate racket #:no-auto-require -(provide (struct-out graph-info) - (struct-out node-info) - (struct-out field-info) - (struct-out rich-graph-info) - (struct-out rich-mapping-info)) +@require[scribble-math + scribble-enhanced/doc + "notations.rkt" + (for-label racket)] -(struct graph-info (name - multi-constructor - root - node-order - nodes)) -(struct node-info (constructor - predicate? - field-order - fields - promise-type - make-incomplete-type ;; may be removed later - incomplete-type - make-placeholder-type ;; may be removed later. - placeholder-type)) -(struct field-info (type - incomplete-type)) +@title[#:style (with-html5 manual-doc-style) + #:tag "graph-info" + #:tag-prefix "phc-graph/graph-info"]{Compile-time graph metadata} -(struct rich-graph-info (name - multi-constructor - root-node - root-mapping - node-order - nodes - mapping-order - mappings)) -(struct rich-mapping-info (constructor - ;predicate? - ;field-order - ;fields - with-promises-type - ;make-incomplete-type ;; may be removed later - ;incomplete-type - ;make-placeholder-type ;; may be removed later. - ;placeholder-type - )) \ No newline at end of file +@(chunks-toc-prefix + '("(lib phc-graph/scribblings/phc-graph-implementation.scrbl)" + "phc-graph/graph-info")) + +We define here the compile-time metadata describing a graph type. + +@section{Graph type information} + +@chunk[ + (struct+/contract graph-info + ([name identifier?] + [tvars (listof identifier?)] + [root-node identifier?] + [node-order (listof identifier?)] + [nodes (hash/c symbol? node-info? #:immutable #t)] + [invariants (set/c invariant-info? #:kind 'immutable)]) + #:transparent + #:methods gen:custom-write + [(define write-proc (struct-printer 'graph-info))] + #:property prop:custom-print-quotable 'never)] + +@section{Graph builder information} + +@chunk[ + (struct+/contract graph-builder-info graph-info + ([name identifier?] + [tvars (listof identifier?)] + [root-node identifier?] + [node-order (listof identifier?)] + [nodes (hash/c symbol? node-info? #:immutable #t)] + [invariants (set/c invariant-info? #:kind 'immutable)]) + ([multi-constructor identifier?] + [root-mapping identifier?] + [mapping-order (listof identifier?)] + [mappings (hash/c symbol? mapping-info? #:immutable #t)] + [dependent-invariants (set/c dependent-invariant-info?)]) + #:transparent + #:methods gen:custom-write + [(define write-proc (struct-printer 'graph-builder-info))] + #:property prop:custom-print-quotable 'never)] + +@section{Node information} + +@chunk[ + (struct+/contract node-info + ([predicate? identifier?] + [field-order (listof identifier?)] + [fields (hash/c symbol? field-info? #:immutable #t)] + [promise-type identifier?] + [make-incomplete-type identifier?] + [incomplete-type identifier?]) + #:transparent + #:methods gen:custom-write + [(define write-proc (struct-printer 'node-info))] + #:property prop:custom-print-quotable 'never)] + +@section{Field information} + +A field has a type. + +@chunk[ + (struct+/contract field-info + ([type identifier?]) + #:transparent + #:methods gen:custom-write + [(define write-proc (struct-printer 'field-info))] + #:property prop:custom-print-quotable 'never)] + +@;[incomplete-type identifier?] + +@section{Invariant information} + +@chunk[ + (struct+/contract invariant-info + ([predicate identifier?] ; (→ RootNode Boolean : +witness-type) + [witness-type identifier?]) + #:transparent + #:methods gen:custom-write + [(define write-proc (struct-printer 'invariant-info))] + #:property prop:custom-print-quotable 'never)] + +@section{Dependent invariant information} + +The invariants described in the previous section assert properties of a graph +instance in isolation. It is however desirable to also describe invariants +which relate the old and the new graph in a graph transformation. + +@chunk[ + (struct+/contract dependent-invariant-info + ([checker identifier?] ; (→ RootMappingArguments… NewGraphRoot Boolean) + [name identifier?]) + #:transparent + #:methods gen:custom-write + [(define write-proc (struct-printer 'dependent-invariant-info))] + #:property prop:custom-print-quotable 'never)] + +@section{Mapping information} + +@chunk[ + (struct+/contract mapping-info + ([mapping-function identifier?] + [with-promises-type identifier?] + [make-placeholder-type identifier?] + [placeholder-type identifier?]) + #:transparent + #:methods gen:custom-write + [(define write-proc (struct-printer 'mapping-info))] + #:property prop:custom-print-quotable 'never)] + +@section{Printing} + +It is much easier to debug graph information if it is free from the visual +clutter of printed syntax objects (which waste most of the screen real estate +printing @tt{# + (define (to-datum v) + (syntax->datum (datum->syntax #f v))) + + (define (struct-printer2 ctor) + (make-constructor-style-printer + (λ (v) ctor) + (λ (v) (map to-datum (struct->list v))))) + + (define ((struct-printer ctor) st port mode) + (match-define (vector name fields ...) (struct->vector st)) + (define-values (info skipped?) (struct-info st)) + (define-values (-short-name _2 _3 _4 _5 _6 _7 _8) + (struct-type-info info)) + (define short-name (or ctor -short-name)) + (define (to-datum v) + (syntax->datum (datum->syntax #f v))) + (case mode + [(#t) + (display "#(~#t~" port) + (display name port) + (for-each (λ (f) + (display " " port) + (write (to-datum f) port)) + fields) + (display ")" port)] + [(#f) + (display "#(~#f~" port) + (display name port) + (for-each (λ (f) + (display " " port) + (display (to-datum f) port)) + fields) + (display ")" port)] + [(0) + (display "(" port) + (display short-name port) + (for-each (λ (f) + (display " " port) + ;; Circumvent the undocumented(?) autodetection of + ;; print which changes the behaviour if objects which + ;; are not eq? to the original fields are directly + ;; printed to the port. + (let ([str (with-output-to-string + (λ () + (print (to-datum f) (current-output-port) 0)))]) + (display (string-append str " ") port))) + fields) + (display ")" port)] + [(1) + (display "#(" port) + (display name port) + (for-each (λ (f) + (display " " port) + (display + ;; Circumvent the undocumented(?) autodetection of + ;; print which changes the behaviour if objects which + ;; are not eq? to the original fields are directly + ;; printed to the port. + #;(with-output-to-string + (λ () + (print (to-datum f) (current-output-port) 1))) + "abab" + port)) + fields) + (display ")" port)]))] + +@CHUNK[<*> + (require phc-toolkit/untyped + racket/struct + (for-syntax phc-toolkit/untyped + syntax/parse + syntax/parse/experimental/template)) + (define-syntax/parse + (struct+/contract name {~optional parent} + {~optional ([parent-field parent-contract] ...)} + ([field contract] ...) + {~optional {~and transparent #:transparent}} + (~and {~seq methods+props ...} + (~seq (~maybe #:methods + {~literal gen:custom-write} + _) + (~maybe #:property + {~literal prop:custom-print-quotable} + _)))) + (quasisyntax/top-loc this-syntax + #,(template + (begin + (struct name (?? parent) (field ...) + (?? transparent) + methods+props ...) + (provide (contract-out (struct (?? (name parent) name) + ((?? (?@ [parent-field parent-contract] + ...)) + [field contract] + ...)))))))) + + + + + + + + + + ] diff --git a/graph-type.hl.rkt b/graph-type.hl.rkt new file mode 100644 index 0000000..a6b463d --- /dev/null +++ b/graph-type.hl.rkt @@ -0,0 +1,91 @@ +#lang hyper-literate typed/racket #:no-auto-require + +@require[scribble-math + scribble-enhanced/doc + "notations.rkt" + (for-label racket)] + +@title[#:style (with-html5 manual-doc-style) + #:tag "graph-type" + #:tag-prefix "phc-graph/graph-type"]{Declaring graph types} + +@(chunks-toc-prefix + '("(lib phc-graph/scribblings/phc-graph-implementation.scrbl)" + "phc-graph/graph-type")) + +@CHUNK[ + (begin-for-syntax + (define-syntax-class signature + #:datum-literals (∈ ∋ ≡ ≢ ∉) + #:literals (:) + (pattern (name + {~maybe #:∀ (tvar …)} + (~and {~seq [nodeᵢ:id [fieldᵢⱼ:id : τ] …] …} + {~seq [root-node . _] _ …}) + {~seq #:invariant a {~and op {~or ∈ ∋ ≡ ≢ ∉}} b} … + {~seq #:invariant p} …)))) + + (define-syntax/parse (define-graph-type . :signature) + (define gi ) + (local-require racket/pretty) + (pretty-print gi (current-output-port) 0) + #`(begin + (define-syntax name #,gi)))] + +@chunk[ + (graph-info #'name + (syntax->list (if (attribute tvar) #'(tvar …) #'())) + #'root-node + (syntax->list #'(nodeᵢ …)) + (make-immutable-hash + (map cons + (stx-map syntax-e #'(nodeᵢ …)) + (stx-map (λ/syntax-case (nodeᵢ [fieldᵢⱼ τᵢⱼ] …) () + ) + #'([nodeᵢ [fieldᵢⱼ τᵢⱼ] …] …)))) + (list->set + (append + (stx-map (λ/syntax-case (op a b) () ) + #'([op a b] …)) + (stx-map (λ/syntax-case p () ) + #'(p …)))))] + +@chunk[ + (node-info (meta-struct-predicate + (check-remembered-node! #'(nodeᵢ fieldᵢⱼ …))) + (syntax->list #'(fieldᵢⱼ …)) + (make-immutable-hash + (map cons + (stx-map syntax-e #'(fieldᵢⱼ …)) + (stx-map (λ/syntax-case (fieldᵢⱼ τᵢⱼ) () + ) + #'([fieldᵢⱼ τᵢⱼ] …)))) + (check-remembered-node! #'(nodeᵢ fieldᵢⱼ …)) + (meta-struct-constructor + (check-remembered-tagged! #'(node-incompleteᵢ fieldᵢⱼ …))) + (check-remembered-tagged! #'(node-incompleteᵢ fieldᵢⱼ …)))] + +@chunk[ + (field-info #'τᵢⱼ)] + +@chunk[ + (invariant-info #'predicateTODO + #'witnessTODO)] + +@chunk[ + (invariant-info #'predicateTODO + #'witnessTODO)] + +@chunk[<*> + (require racket/require + phc-toolkit + (lib "phc-adt/tagged-structure-low-level.hl.rkt") + (for-syntax "graph-info.hl.rkt" + phc-toolkit/untyped + (subtract-in syntax/parse phc-graph/subtemplate) + racket/set + phc-graph/subtemplate)) + + (provide define-graph-type) + + ] \ No newline at end of file diff --git a/graph.hl.rkt b/graph.hl.rkt index 792d757..649deb7 100644 --- a/graph.hl.rkt +++ b/graph.hl.rkt @@ -1,5 +1,6 @@ #lang hyper-literate typed/racket/base #:no-auto-require -@(require racket/require +@(require scribble-math + racket/require scribble-enhanced/doc racket/require hyper-literate @@ -20,6 +21,15 @@ (require (for-label (submod "..")))) @doc-lib-setup +@title[#:style (with-html5 manual-doc-style) + #:tag "graph-impl" + #:tag-prefix "phc-graph/graph-impl"]{Implementation of the graph macro} + +@(chunks-toc-prefix + '("(lib phc-graph/scribblings/phc-graph-implementation.scrbl)" + "phc-graph/graph-impl")) + + @chunk[ (define-syntax define-graph (syntax-parser diff --git a/scribblings/phc-graph-implementation.scrbl b/scribblings/phc-graph-implementation.scrbl index fd383dd..6c32fec 100644 --- a/scribblings/phc-graph-implementation.scrbl +++ b/scribblings/phc-graph-implementation.scrbl @@ -13,4 +13,7 @@ the @other-doc['(lib "phc-graph/scribblings/phc-graph.scrbl")] document. @include-section[(submod "../traversal.hl.rkt" doc)] @include-section[(submod "../flexible-with.hl.rkt" doc)] -@include-section[(submod "../invariants-phantom.hl.rkt" doc)] \ No newline at end of file +@include-section[(submod "../invariants-phantom.hl.rkt" doc)] +@include-section[(submod "../graph-info.hl.rkt" doc)] +@include-section[(submod "../graph-type.hl.rkt" doc)] +@include-section[(submod "../graph.hl.rkt" doc)] \ No newline at end of file diff --git a/test/adt-pre-declarations.rkt b/test/adt-pre-declarations.rkt index e2d73e5..a8ac74a 100644 --- a/test/adt-pre-declarations.rkt +++ b/test/adt-pre-declarations.rkt @@ -2,3 +2,11 @@ (remembered! tagged-structure (tg a b)) (remembered! tagged-structure (tg a c)) (remembered! tagged-structure (t0)) +(remembered! tagged-structure (City citizens name streets)) +(remembered! tagged-structure (Street houses name)) +(remembered! tagged-structure (House owner)) +(remembered! tagged-structure (Person name)) +(remembered! tagged-structure (node-incompleteᵢ citizens name streets)) +(remembered! tagged-structure (node-incompleteᵢ houses name)) +(remembered! tagged-structure (node-incompleteᵢ owner)) +(remembered! tagged-structure (node-incompleteᵢ name)) diff --git a/test/test-graph-type.rkt b/test/test-graph-type.rkt new file mode 100644 index 0000000..6a08b80 --- /dev/null +++ b/test/test-graph-type.rkt @@ -0,0 +1,16 @@ +#lang typed/racket + +(require phc-adt + (lib "phc-graph/graph-type.hl.rkt")) +(adt-init) + +(define-graph-type g1 + [City [name : String] + [streets : (Listof Street)] + [citizens : (Listof Person)]] + [Street [name : String] + [houses : (Listof House)]] + [House [owner : Person]] + [Person [name : String]] + #:invariant City.citizens._ ∈ City.streets._.houses._.owner + #:invariant City.citizens._ ∋ City.streets._.houses._.owner) \ No newline at end of file