about summary refs log tree commit diff stats
path: root/dwm.png
blob: b1f9ba7e5f4cc7350ee2392ebcea5fcbe00fb49b (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 c0 00 00 00 50 08 02 00 00 00 c0 d8 ed .PNG........IHDR.......P........
0020 13 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 93 00 00 00 09 70 48 59 73 00 00 0b 13 00 .....bKGD..............pHYs.....
0040 00 0b 13 01 00 9a 9c 18 00 00 00 07 74 49 4d 45 07 d6 07 13 0c 31 06 de 1b 2a 10 00 00 00 1d 74 ............tIME.....1...*.....t
0060 45 58 74 43 6f 6d 6d 65 6e 74 00 43 72 65 61 74 65 64 20 77 69 74 68 20 54 68 65 20 47 49 4d 50 EXtComment.Created.with.The.GIMP
0080 ef 64 25 6e 00 00 00 d9 49 44 41 54 78 da ed dd 41 0a 80 30 0c 00 41 23 fe ff cb f1 0d 81 06 52 .d%n....IDATx...A..0..A#.......R
00a0 32 73 56 51 59 da 4b d0 c8 cc 67 92 88 28 1d 3f ed fe b7 79 bd 02 04 84 80 10 10 02 02 01 21 20 2sVQY.K...g..(.?...y..........!.
00c0 04 84 80 40 40 08 08 01 21 20 10 10 02 42 40 08 08 04 84 80 10 10 02 42 40 20 20 04 84 80 10 10 ...@@...!....B@........B@.......
00e0 08 08 01 21 20 04 04 02 a2 43 dc fe 00 d5 ef 03 75 7f 7f a8 7a 7d 2b 10 b6 30 10 10 02 42 40 08 ...!.....C......u...z}+..0...B@.
0100 08 04 84 80 10 10 02 02 01 21 20 04 84 80 40 40 1c f4 55 4f e8 fe 3f d7 b6 79 9a db e7 99 ac 40 .........!....@@..UO..?..y.....@
0120 d8 c2 10 10 02 42 40 20 20 04 84 80 10 10 08 08 01 21 20 04 04 02 42 40 8c 52 9e 07 9a 36 af d3 .....B@..........!....B@.R...6..
0140 7d 3f db e6 93 ac 40 08 08 01 21 20 10 10 02 42 40 08 08 04 84 80 10 10 02 02 01 21 20 04 c4 d5 }?....@...!....B@..........!....
0160 7e 8b c2 15 a9 b3 6f d5 23 00 00 00 00 49 45 4e 44 ae 42 60 82 ~.....o.#....IEND.B`.
ik K. Agaram <vc@akkartik.com> 2015-02-19 16:46:47 -0800 788 - reorg, showing off how tangle makes it' href='/akkartik/mu/commit/cpp/013arithmetic?h=hlt&id=8d7839b99723553c08b33c30980a001e7a3557b6'>8d7839b9 ^
42b31beb ^
fca0ebbe ^
ac0e9db5 ^

827898fc ^
0487a30e ^

827898fc ^
42b31beb ^

8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^
8d7839b9 ^
57699011 ^
8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^


8d7839b9 ^
57699011 ^
8d7839b9 ^
0487a30e ^

5497090a ^
0487a30e ^


1848b18f ^

8d7839b9 ^
42b31beb ^
8d7839b9 ^
42b31beb ^
ac0e9db5 ^
fca0ebbe ^
ac0e9db5 ^

827898fc ^
0487a30e ^

827898fc ^
42b31beb ^

8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^
8d7839b9 ^
57699011 ^
8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^


8d7839b9 ^
57699011 ^
8d7839b9 ^
0487a30e ^

5497090a ^
0487a30e ^


1848b18f ^

8d7839b9 ^
42b31beb ^
8d7839b9 ^
42b31beb ^
fca0ebbe ^
ac0e9db5 ^

827898fc ^
0487a30e ^

827898fc ^
42b31beb ^

8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^
8d7839b9 ^
57699011 ^
8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^


8d7839b9 ^
57699011 ^
8d7839b9 ^
0487a30e ^

5497090a ^
0487a30e ^


1848b18f ^

8d7839b9 ^
42b31beb ^
8d7839b9 ^
42b31beb ^
ac0e9db5 ^
fca0ebbe ^
ac0e9db5 ^

827898fc ^
0487a30e ^

827898fc ^
42b31beb ^

8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^
8d7839b9 ^
57699011 ^
8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^


8d7839b9 ^
57699011 ^
8d7839b9 ^
0487a30e ^

5497090a ^
0487a30e ^


5497090a ^

1848b18f ^

8d7839b9 ^
0b82eef7 ^
8d7839b9 ^
42b31beb ^
827898fc ^
fca0ebbe ^
0487a30e ^
5497090a ^
827898fc ^

42b31beb ^

8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^
8d7839b9 ^
57699011 ^
57699011 ^
8d7839b9 ^
88be3dbc ^
8d7839b9 ^
5497090a ^


8d7839b9 ^
57699011 ^
57699011 ^
fca0ebbe ^



5497090a ^
fca0ebbe ^

ac0e9db5 ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
                         
 
                                             
    

                                        
                                                
           
                    

                                                         
                                      

                     
                                   

        
 
                       
             
                                        
 
                              
 
               
             


                                    
 
                              
 

                        
                                                 


                              

                                             
                                        
                                     
                                                
                
                                    
                                          

                                                         
                                      

                     
                                   

        
 
                            
             
                                           
 
                             
 
                    
             


                                         
 
                               
 

                             
                                                      


                             

                                             
                                        
                                     
                                                
                
                    

                                                         
                                      

                     
                                   

        
 
                            
             
                                           
 
                             
 
                    
             


                                         
 
                              
 

                             
                                                      


                              

                                             
                                        
                                 
                                                
              
                                    
                                          

                                                         
                                      

                     
                                   

        
 
                          
             
                                         
 
                             
 
                  
             


                                       
 
                             
 

                           
                                                     


                             

                    

                                             
                                        
                                                               
                                                
                             
                                                                             
                                                                                                                                      
                     
                                            

                                      

        
 
                                         
             
                                                                  
 
                             
                             
 
                                 
             


                                                                
 
                             
                             



                                     
                                         

                               







                                              
//: Arithmetic primitives

:(before "End Primitive Recipe Declarations")
ADD,
:(before "End Primitive Recipe Numbers")
Recipe_number["add"] = ADD;
:(before "End Primitive Recipe Implementations")
case ADD: {
  double result = 0;
  for (long long int i = 0; i < SIZE(ingredients); ++i) {
    assert(scalar(ingredients.at(i)));
    result += ingredients.at(i).at(0);
  }
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario add_literal)
recipe main [
  1:number <- add 23:literal, 34:literal
]
+mem: storing 57 in location 1

:(scenario add)
recipe main [
  1:number <- copy 23:literal
  2:number <- copy 34:literal
  3:number <- add 1:number, 2:number
]
+mem: storing 57 in location 3

:(scenario add_multiple)
recipe main [
  1:number <- add 3:literal, 4:literal, 5:literal
]
+mem: storing 12 in location 1

:(before "End Primitive Recipe Declarations")
SUBTRACT,
:(before "End Primitive Recipe Numbers")
Recipe_number["subtract"] = SUBTRACT;
:(before "End Primitive Recipe Implementations")
case SUBTRACT: {
  assert(scalar(ingredients.at(0)));
  double result = ingredients.at(0).at(0);
  for (long long int i = 1; i < SIZE(ingredients); ++i) {
    assert(scalar(ingredients.at(i)));
    result -= ingredients.at(i).at(0);
  }
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario subtract_literal)
recipe main [
  1:number <- subtract 5:literal, 2:literal
]
+mem: storing 3 in location 1

:(scenario subtract)
recipe main [
  1:number <- copy 23:literal
  2:number <- copy 34:literal
  3:number <- subtract 1:number, 2:number
]
+mem: storing -11 in location 3

:(scenario subtract_multiple)
recipe main [
  1:number <- subtract 6:literal, 3:literal, 2:literal
]
+mem: storing 1 in location 1

:(before "End Primitive Recipe Declarations")
MULTIPLY,
:(before "End Primitive Recipe Numbers")
Recipe_number["multiply"] = MULTIPLY;
:(before "End Primitive Recipe Implementations")
case MULTIPLY: {
  double result = 1;
  for (long long int i = 0; i < SIZE(ingredients); ++i) {
    assert(scalar(ingredients.at(i)));
    result *= ingredients.at(i).at(0);
  }
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario multiply_literal)
recipe main [
  1:number <- multiply 2:literal, 3:literal
]
+mem: storing 6 in location 1

:(scenario multiply)
recipe main [
  1:number <- copy 4:literal
  2:number <- copy 6:literal
  3:number <- multiply 1:number, 2:number
]
+mem: storing 24 in location 3

:(scenario multiply_multiple)
recipe main [
  1:number <- multiply 2:literal, 3:literal, 4:literal
]
+mem: storing 24 in location 1

:(before "End Primitive Recipe Declarations")
DIVIDE,
:(before "End Primitive Recipe Numbers")
Recipe_number["divide"] = DIVIDE;
:(before "End Primitive Recipe Implementations")
case DIVIDE: {
  assert(scalar(ingredients.at(0)));
  double result = ingredients.at(0).at(0);
  for (long long int i = 1; i < SIZE(ingredients); ++i) {
    assert(scalar(ingredients.at(i)));
    result /= ingredients.at(i).at(0);
  }
  products.resize(1);
  products.at(0).push_back(result);
  break;
}

:(scenario divide_literal)
recipe main [
  1:number <- divide 8:literal, 2:literal
]
+mem: storing 4 in location 1

:(scenario divide)
recipe main [
  1:number <- copy 27:literal
  2:number <- copy 3:literal
  3:number <- divide 1:number, 2:number
]
+mem: storing 9 in location 3

:(scenario divide_multiple)
recipe main [
  1:number <- divide 12:literal, 3:literal, 2:literal
]
+mem: storing 2 in location 1

//: Integer division

:(before "End Primitive Recipe Declarations")
DIVIDE_WITH_REMAINDER,
:(before "End Primitive Recipe Numbers")
Recipe_number["divide-with-remainder"] = DIVIDE_WITH_REMAINDER;
:(before "End Primitive Recipe Implementations")
case DIVIDE_WITH_REMAINDER: {
  long long int quotient = ingredients.at(0).at(0) / ingredients.at(1).at(0);
  long long int remainder = static_cast<long long int>(ingredients.at(0).at(0)) % static_cast<long long int>(ingredients.at(1).at(0));
  products.resize(2);
  // very large integers will lose precision
  products.at(0).push_back(quotient);
  products.at(1).push_back(remainder);
  break;
}

:(scenario divide_with_remainder_literal)
recipe main [
  1:number, 2:number <- divide-with-remainder 9:literal, 2:literal
]
+mem: storing 4 in location 1
+mem: storing 1 in location 2

:(scenario divide_with_remainder)
recipe main [
  1:number <- copy 27:literal
  2:number <- copy 11:literal
  3:number, 4:number <- divide-with-remainder 1:number, 2:number
]
+mem: storing 2 in location 3
+mem: storing 5 in location 4

:(scenario divide_with_decimal_point)
recipe main [
  # todo: literal floats?
  1:number <- divide 5:literal, 2:literal
]
+mem: storing 2.5 in location 1

:(code)
inline bool scalar(vector<long long int>& x) {
  return SIZE(x) == 1;
}
inline bool scalar(vector<double>& x) {
  return SIZE(x) == 1;
}