33Algebraic Data Types (ADT) is used to represent two kinds of things:
44
551. A discrimintated union of types, called sum
6- 2. A combination of some types, called product.
6+ 2. A combination of ADT types, called product.
77
88# Sum types
99
10- Sum types represents a concept of generalizing. For example,
10+ Sum types represent a concept of generalizing. For example,
1111on ARM R0 and R1 are all general purpose registers (GPR). Also on ARM
1212we have Condition Code registers (CCR) :
1313
@@ -48,10 +48,10 @@ class ADT(object):
4848 """ Algebraic Data Type.
4949
5050 This is a base class for all ADTs. ADT represented by a tuple of arguments,
51- stored in a val field. Arguments should be instances of ADT class, or numbers,
51+ stored in a `arg` field. Arguments should be instances of ADT class, or numbers,
5252 or strings. Empty set of arguments is permitted.
5353 A one-tuple is automatically untupled, i.e., `Int(12)` has value `12`, not `(12,)`.
54- For convenience, a name of the constructor is provided in `name ` field.
54+ A name of the constructor is stored in the `constr ` field
5555
5656 A structural comparison is provided.
5757
@@ -115,7 +115,7 @@ def run(self, adt):
115115
116116 Otherwise, for an ADT of type C the method `visit_C` is looked up in the
117117 visitors methods dictionary. If it doesn't exist, then `visit_B` is
118- looked up, where `D ` is the base class of `C`. The process continues,
118+ looked up, where `B ` is the base class of `C`. The process continues,
119119 until the method is found. This is guaranteed to terminate,
120120 since visit_ADT method is defined.
121121
@@ -124,8 +124,8 @@ def run(self, adt):
124124 Once the method is found it is called. It is the method's responsiblity
125125 to recurse into sub-elements, e.g., call run method.
126126
127- For example, suppose that we want to count negative values in a given
128- BIL expression:
127+ For example, suppose that we want to count negative values in
128+ some BIL expression:
129129
130130 class CountNegatives(Visitor):
131131 def __init__(self):
@@ -148,7 +148,7 @@ def visit_NEG(self, op):
148148 visit_Int for Int constructor and visit_NEG for counting unary minuses.
149149 (Actually we should count for bitwise NOT operation also, since it will
150150 change the sign bit also, but lets forget about it for the matter of the
151- excercise (and it can be easily fixed just by matching visit_UnOp)).
151+ exercise (and it can be easily fixed just by matching visit_UnOp)).
152152
153153 When we hit visit_NEG we toggle current sign, storing its previous value
154154 and recurse into the operand. After we return from the recursion, we restore
0 commit comments