1 | # Homogeneous tree for pretty-printing data that fits an ASDL schema!
|
2 | # To avoid bootstrapping problems, it can't be pretty-printed!
|
3 | # It's generated first with a special flag.
|
4 |
|
5 | module hnode {
|
6 |
|
7 | color =
|
8 | TypeName
|
9 | | StringConst
|
10 | | OtherConst
|
11 | | UserType # e.g. for Id
|
12 | | External
|
13 |
|
14 | # hnode is our homogeneous representation
|
15 | # (Can this converge with NIL8? It's homogeneous too. With the key:value issue)
|
16 |
|
17 | # Cases:
|
18 | # - Full Record
|
19 | # - product type (Point x:4 y:5)
|
20 | # - sum type - do we need tag?
|
21 | # - Abbreviated Record
|
22 | # - Token is <Id.Lit_Chars "a">
|
23 | # - CompoundWord is (w <Id.Lit_Chars "a">)
|
24 | # - List
|
25 | # [1 2 3]
|
26 | # - List subtype, with tag
|
27 | # (Foo [1 2 3]) # uses unnamed field
|
28 | # - Dict
|
29 | # - right now this is [Dict k:v] - change it to {k: v} I think
|
30 | # {k v k2 v2}
|
31 | # - Dict subtype
|
32 | # (Foo {k v k2 v2})
|
33 | #
|
34 | # Can it be more like NIL8?
|
35 | # (Point x: 42 y: 52)
|
36 | # [a b c]
|
37 | # {k:v k2:v2}
|
38 | # (CompoundWord [1 2 3])
|
39 | # (Dict {a:1 b:2})
|
40 |
|
41 | Field = (str name, hnode val)
|
42 |
|
43 | hnode =
|
44 | # Used to prevent infinite loops. This could also be a Leaf.
|
45 | AlreadySeen(int heap_id)
|
46 |
|
47 | # String, int, float, etc. of different color
|
48 | | Leaf(str s, color color)
|
49 |
|
50 | | Array(List[hnode] children)
|
51 |
|
52 | | Record(str node_type,
|
53 | str left, str right,
|
54 | List[Field] fields,
|
55 | List[hnode]? unnamed_fields)
|
56 |
|
57 |
|
58 | # Idea for bit flags for CreateNull(). NOT part of pretty printing / hnode.
|
59 | # We just use a single param alloc_lists=True now
|
60 | alloc_members =
|
61 | List
|
62 | | Dict
|
63 | | Struct # ASDL product or sum types
|
64 | generate [bit_set]
|
65 | # Could also generate alloc_members_b::{None,All}
|
66 |
|
67 | # Related:
|
68 | # - it would be nice to have ASDL value types (pass by value),
|
69 | # e.g. val[Token] or inline[Token]
|
70 | # - we should be able to pack i8, i16, u8, u16, or even bitfields
|
71 | # Point = (int x, int y)
|
72 | # Point = (int[signed, 16] x, int[unsigned, 8] y)
|
73 | # It's not i16 and u8 because we recognize C++ implicit int conversions.
|
74 | # This is storage only.
|
75 | }
|