From 22df891893d30e9906d0b14fc3ae5d8e67d500b2 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 3 Oct 2026 14:03:48 -0700 Subject: Chapter renumber, and split ch 17 Renumber chapters 10a, 10b, 11, 12, 13, 14 -> 10, 11, 13, 12, [11,14]. Split ch 17 into a 17a and 17b; shuffle around im/mutable syntax to be consistent, and present it more slowly. THe new immutable syntax is pushed through all later chapters --- chapter12/docs/12-grammar.md | 10 +- chapter12/docs/lattice.gv | 154 --------- chapter12/docs/lattice.svg | 732 ------------------------------------------- 3 files changed, 5 insertions(+), 891 deletions(-) delete mode 100644 chapter12/docs/lattice.gv delete mode 100644 chapter12/docs/lattice.svg (limited to 'chapter12/docs') diff --git a/chapter12/docs/12-grammar.md b/chapter12/docs/12-grammar.md index 4c071a98..24199ede 100644 --- a/chapter12/docs/12-grammar.md +++ b/chapter12/docs/12-grammar.md @@ -11,21 +11,21 @@ statement : returnStatement | structDeclaration | declStatement - | blockStatment + | blockStatement | expressionStatement | ifStatement | whileStatement | breakStatement - | continueStatment + | continueStatement ; PRIMTYPE : 'int' - | 'flt' ; field : PRIMTYPE IDENTIFIER ';' + | structName ('?')? IDENTIFIER ';' ; fields @@ -102,7 +102,7 @@ newExpression ; fieldExpression - : primaryExpresson '.' IDENTIFIER + : primaryExpression '.' IDENTIFIER ; primaryExpression @@ -122,7 +122,7 @@ INTEGER_LITERAL ; IDENTIFIER - : NON_DIGIT (NON_DIGIT | DIGIT)* + : NON_DIGIT (NON_DIGIT | DEC_DIGIT)* ; NON_DIGIT: [a-zA-Z_]; diff --git a/chapter12/docs/lattice.gv b/chapter12/docs/lattice.gv deleted file mode 100644 index e8631cd5..00000000 --- a/chapter12/docs/lattice.gv +++ /dev/null @@ -1,154 +0,0 @@ -digraph Lattice { - rankdir=TB; - newrank=true; - // Preserve the same-rank ordering edges through cluster layout. - remincross=false; - nodesep=0.22; - ranksep=0.65; - node [shape=ellipse, style=filled, fontname="DejaVu Sans", fontsize=13]; - edge [color="#555555", arrowsize=0.6]; - - // These arrows are lattice-order edges, not use/definition edges. - TOP [label="⊤", fillcolor=black, fontcolor=white]; - BOT [label="⊥", fillcolor=black, fontcolor=white]; - - subgraph cluster_control { - label="Control"; fontname="Arial"; color="#cccccc"; - node [fillcolor="#ffff00"]; - XCTRL [label="⊤:ctrl"]; - CTRL [label="⊥:ctrl"]; - XCTRL -> CTRL; - } - - subgraph cluster_integer { - label="Integer"; fontname="Arial"; color="#cccccc"; - node [fillcolor="#add8e6"]; - INT_TOP [label="⊤:int"]; - INT_BOT [label="⊥:int"]; - INT_NEG [label="… −2, −1"]; - INT_ZERO [label="0"]; - INT_POS [label="1, 2, …"]; - {rank=same; INT_NEG; INT_ZERO; INT_POS;} - INT_NEG -> INT_ZERO -> INT_POS [style=invis]; - INT_TOP -> {INT_NEG INT_ZERO INT_POS}; - {INT_NEG INT_ZERO INT_POS} -> INT_BOT; - } - - subgraph cluster_float { - label="Float"; fontname="Arial"; color="#cccccc"; - FLT_TOP [label=<⊤:flt>, fillcolor=aqua, shape=oval]; - FLT_BOT [label=<⊥:flt>, fillcolor=aqua, shape=oval]; - - FLT_MINDOTS [label="… negative constants", fillcolor=aqua, shape=oval]; - FLT_ZERO [label="0.0" , fillcolor=aqua]; - FLT_MAXDOTS [label="positive constants …", fillcolor=aqua, shape=oval]; - - FLT_TOP -> FLT_MINDOTS; - FLT_TOP -> FLT_ZERO; - FLT_TOP -> FLT_MAXDOTS; - FLT_MINDOTS -> FLT_BOT; - FLT_ZERO -> FLT_BOT; - FLT_MAXDOTS -> FLT_BOT; - - FLT_MINDOTS -> FLT_ZERO -> FLT_MAXDOTS [style=invis]; - - {rank=same; FLT_MINDOTS; FLT_ZERO; FLT_MAXDOTS;} - } - - subgraph cluster_pointer { - label="Pointer = nullability × struct type"; - fontname="Arial"; color="#cccccc"; - node [fillcolor="#008000", fontcolor=white]; - PTR_TOP [label="⊤:ptr\n[*⊤:struct]"]; - PTR_BOT [label="⊥:ptr\n[*⊥:struct?]"]; - PTR_NULL [label="null"]; - PTR_ANY [label="*⊥:struct\n[ptr any struct]"]; - PTR_PERSON [label="*Person"]; - PTR_S1 [label="*s1"]; - PTR_MORE [label="*s2, …"]; - PTR_PERSON_NIL [label="*Person?"]; - PTR_S1_NIL [label="*s1?"]; - PTR_MORE_NIL [label="*s2?, …"]; - {rank=same; PTR_PERSON; PTR_S1; PTR_MORE; PTR_NULL;} - {rank=same; PTR_ANY; PTR_PERSON_NIL; PTR_S1_NIL; PTR_MORE_NIL;} - PTR_PERSON -> PTR_S1 -> PTR_MORE -> PTR_NULL [style=invis]; - PTR_ANY -> PTR_PERSON_NIL -> PTR_S1_NIL -> PTR_MORE_NIL [style=invis]; - PTR_TOP -> {PTR_PERSON PTR_S1 PTR_MORE PTR_NULL}; - {PTR_PERSON PTR_S1 PTR_MORE} -> PTR_ANY; - PTR_PERSON -> PTR_PERSON_NIL; - PTR_S1 -> PTR_S1_NIL; - PTR_MORE -> PTR_MORE_NIL; - PTR_NULL -> {PTR_PERSON_NIL PTR_S1_NIL PTR_MORE_NIL}; - {PTR_ANY PTR_PERSON_NIL PTR_S1_NIL PTR_MORE_NIL} -> PTR_BOT; - } - - subgraph cluster_struct { - label="Struct\nnamed collection of named scalar types"; - fontname="Arial"; color="#cccccc"; - node [fillcolor="#90ee90"]; - STRUCT_TOP [label="⊤:struct\n[struct top]"]; - STRUCT_BOT [label="⊥:struct\n[struct bottom]"]; - STRUCT_PERSON [label="Person\nage: int", shape=box]; - STRUCT_S1 [label="s1\nx: int", shape=box]; - STRUCT_S2 [label="s2\nx: int, y: flt", shape=box]; - STRUCT_MORE [label="…", shape=box]; - {rank=same; STRUCT_PERSON; STRUCT_S1; STRUCT_S2; STRUCT_MORE;} - STRUCT_PERSON -> STRUCT_S1 -> STRUCT_S2 -> STRUCT_MORE [style=invis]; - STRUCT_TOP -> {STRUCT_PERSON STRUCT_S1 STRUCT_S2 STRUCT_MORE}; - {STRUCT_PERSON STRUCT_S1 STRUCT_S2 STRUCT_MORE} -> STRUCT_BOT; - } - - subgraph cluster_memory { - label="Memory\nprecise alias slices"; fontname="Arial"; color="#cccccc"; - node [fillcolor="#00008b", fontcolor=white]; - MEM_TOP [label="⊤:mem"]; - MEM_BOT [label="⊥:mem"]; - MEM_ALIAS2 [label="MEM#2"]; - MEM_ALIAS3 [label="MEM#3"]; - MEM_MORE [label="…"]; - {rank=same; MEM_ALIAS2; MEM_ALIAS3; MEM_MORE;} - MEM_ALIAS2 -> MEM_ALIAS3 -> MEM_MORE [style=invis]; - MEM_TOP -> {MEM_ALIAS2 MEM_ALIAS3 MEM_MORE}; - {MEM_ALIAS2 MEM_ALIAS3 MEM_MORE} -> MEM_BOT; - } - - subgraph cluster_tuple { - label="Tuple\ncollection of types"; - fontname="Arial"; color="#cccccc"; - node [fillcolor="#ffc0cb"]; - TUPLE_TOP [label="⊤:tuple"]; - TUPLE_BOT [label="⊥:tuple"]; - // Each black element stands for a recursively nested type lattice. - TUPLE1 [shape=plain, label=< - - - -
tuple
type
- >]; - TUPLE2 [shape=plain, label=< - - - - -
tuple
type
type
- >]; - TUPLEN [shape=plain, label=< - - - - - -
tuple
type
…
type
- >]; - {rank=same; TUPLE1; TUPLE2; TUPLEN;} - TUPLE1 -> TUPLE2 -> TUPLEN [style=invis]; - TUPLE_TOP -> {TUPLE1 TUPLE2 TUPLEN}; - {TUPLE1 TUPLE2 TUPLEN} -> TUPLE_BOT; - } - - TOP -> {XCTRL INT_TOP FLT_TOP PTR_TOP STRUCT_TOP MEM_TOP TUPLE_TOP}; - {CTRL INT_BOT FLT_BOT PTR_BOT STRUCT_BOT MEM_BOT TUPLE_BOT} -> BOT; - {rank=same; XCTRL; INT_TOP; FLT_TOP; PTR_TOP; STRUCT_TOP; MEM_TOP; TUPLE_TOP;} - {rank=same; CTRL; INT_BOT; FLT_BOT; PTR_BOT; STRUCT_BOT; MEM_BOT; TUPLE_BOT;} - XCTRL -> INT_TOP -> FLT_TOP -> PTR_TOP -> STRUCT_TOP -> MEM_TOP -> TUPLE_TOP [style=invis]; -} diff --git a/chapter12/docs/lattice.svg b/chapter12/docs/lattice.svg deleted file mode 100644 index 41804d92..00000000 --- a/chapter12/docs/lattice.svg +++ /dev/null @@ -1,732 +0,0 @@ - - - - - - -Lattice - - -cluster_control - -Control - - -cluster_integer - -Integer - - -cluster_float - -Float - - -cluster_pointer - -Pointer = nullability × struct type - - -cluster_struct - -Struct -named collection of named scalar types - - -cluster_memory - -Memory -precise alias slices - - -cluster_tuple - -Tuple -collection of types - - - -TOP - -⊤ - - - -XCTRL - -⊤:ctrl - - - -TOP->XCTRL - - - - - -INT_TOP - -⊤:int - - - -TOP->INT_TOP - - - - - -FLT_TOP - -⊤ -:flt - - - -TOP->FLT_TOP - - - - - -PTR_TOP - -⊤:ptr -[*⊤:struct] - - - -TOP->PTR_TOP - - - - - -STRUCT_TOP - -⊤:struct -[struct top] - - - -TOP->STRUCT_TOP - - - - - -MEM_TOP - -⊤:mem - - - -TOP->MEM_TOP - - - - - -TUPLE_TOP - -⊤:tuple - - - -TOP->TUPLE_TOP - - - - - -BOT - -⊥ - - - -CTRL - -⊥:ctrl - - - -XCTRL->CTRL - - - - - - -CTRL->BOT - - - - - -INT_NEG - -… −2, −1 - - - -INT_TOP->INT_NEG - - - - - -INT_ZERO - -0 - - - -INT_TOP->INT_ZERO - - - - - -INT_POS - -1, 2, … - - - -INT_TOP->INT_POS - - - - - - -INT_BOT - -⊥:int - - - -INT_BOT->BOT - - - - - -INT_NEG->INT_BOT - - - - - - -INT_ZERO->INT_BOT - - - - - - -INT_POS->INT_BOT - - - - - -FLT_MINDOTS - -… negative constants - - - -FLT_TOP->FLT_MINDOTS - - - - - -FLT_ZERO - -0.0 - - - -FLT_TOP->FLT_ZERO - - - - - -FLT_MAXDOTS - -positive constants … - - - -FLT_TOP->FLT_MAXDOTS - - - - - - -FLT_BOT - -⊥ -:flt - - - -FLT_BOT->BOT - - - - - -FLT_MINDOTS->FLT_BOT - - - - - - -FLT_ZERO->FLT_BOT - - - - - - -FLT_MAXDOTS->FLT_BOT - - - - - -PTR_NULL - -null - - - -PTR_TOP->PTR_NULL - - - - - -PTR_PERSON - -*Person - - - -PTR_TOP->PTR_PERSON - - - - - -PTR_S1 - -*s1 - - - -PTR_TOP->PTR_S1 - - - - - -PTR_MORE - -*s2, … - - - -PTR_TOP->PTR_MORE - - - - - - -PTR_BOT - -⊥:ptr -[*⊥:struct?] - - - -PTR_BOT->BOT - - - - - -PTR_PERSON_NIL - -*Person? - - - -PTR_NULL->PTR_PERSON_NIL - - - - - -PTR_S1_NIL - -*s1? - - - -PTR_NULL->PTR_S1_NIL - - - - - -PTR_MORE_NIL - -*s2?, … - - - -PTR_NULL->PTR_MORE_NIL - - - - - -PTR_ANY - -*⊥:struct -[ptr any struct] - - - -PTR_ANY->PTR_BOT - - - - - - -PTR_PERSON->PTR_ANY - - - - - - -PTR_PERSON->PTR_PERSON_NIL - - - - - -PTR_S1->PTR_ANY - - - - - - -PTR_S1->PTR_S1_NIL - - - - - - -PTR_MORE->PTR_ANY - - - - - -PTR_MORE->PTR_MORE_NIL - - - - - -PTR_PERSON_NIL->PTR_BOT - - - - - - -PTR_S1_NIL->PTR_BOT - - - - - - -PTR_MORE_NIL->PTR_BOT - - - - - -STRUCT_PERSON - -Person -age: int - - - -STRUCT_TOP->STRUCT_PERSON - - - - - -STRUCT_S1 - -s1 -x: int - - - -STRUCT_TOP->STRUCT_S1 - - - - - -STRUCT_S2 - -s2 -x: int, y: flt - - - -STRUCT_TOP->STRUCT_S2 - - - - - -STRUCT_MORE - -… - - - -STRUCT_TOP->STRUCT_MORE - - - - - - -STRUCT_BOT - -⊥:struct -[struct bottom] - - - -STRUCT_BOT->BOT - - - - - -STRUCT_PERSON->STRUCT_BOT - - - - - - -STRUCT_S1->STRUCT_BOT - - - - - - -STRUCT_S2->STRUCT_BOT - - - - - - -STRUCT_MORE->STRUCT_BOT - - - - - -MEM_ALIAS2 - -MEM#2 - - - -MEM_TOP->MEM_ALIAS2 - - - - - -MEM_ALIAS3 - -MEM#3 - - - -MEM_TOP->MEM_ALIAS3 - - - - - -MEM_MORE - -… - - - -MEM_TOP->MEM_MORE - - - - - - -MEM_BOT - -⊥:mem - - - -MEM_BOT->BOT - - - - - -MEM_ALIAS2->MEM_BOT - - - - - - -MEM_ALIAS3->MEM_BOT - - - - - - -MEM_MORE->MEM_BOT - - - - - -TUPLE1 - - - -tuple - - -type - - - -TUPLE_TOP->TUPLE1 - - - - - -TUPLE2 - - - -tuple - - -type - - -type - - - -TUPLE_TOP->TUPLE2 - - - - - -TUPLEN - - - -tuple - - -type - - -… - - -type - - - -TUPLE_TOP->TUPLEN - - - - - -TUPLE_BOT - -⊥:tuple - - - -TUPLE_BOT->BOT - - - - - -TUPLE1->TUPLE_BOT - - - - - - -TUPLE2->TUPLE_BOT - - - - - - -TUPLEN->TUPLE_BOT - - - - - -- cgit v1.2.3