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
|
c{0: 0 (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) -- nil
c{0: 1 (((s string-address)) <- ((new)) foo) -- nil
c{0: 2 (((x keyboard-address)) <- ((init-keyboard)) ((s string-address))) -- nil
c{0: 3 (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address))) -- nil
c{0: 4 (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address))) -- nil
c{1: 0 ✓ (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
c{1: 1 ✓ (((s string-address)) <- ((new)) foo)
c{1: 2 ✓ (((x keyboard-address)) <- ((init-keyboard)) ((s string-address)))
c{1: 3 ✓ (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address)))
c{1: 4 ✓ (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address)))
cn0: convert-names in main
cn0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal))) nil nil
cn0: checking arg ((space literal))
cn0: checking arg ((30 literal))
cn0: checking oarg ((default-space space-address))
maybe-add: ((default-space space-address))
cn0: (((s string-address)) <- ((new)) foo) nil nil
cn0: checking arg foo
cn0: checking oarg ((s string-address))
maybe-add: ((s string-address))
cn0: location for oarg ((s string-address)): 1
cn0: (((x keyboard-address)) <- ((init-keyboard)) ((s string-address))) ((s 1)) nil
cn0: checking arg ((s string-address))
maybe-add: ((s string-address))
cn0: checking oarg ((x keyboard-address))
maybe-add: ((x keyboard-address))
cn0: location for oarg ((x keyboard-address)): 2
cn0: (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address))) ((s 1) (x 2)) nil
cn0: checking arg ((x keyboard-address))
maybe-add: ((x keyboard-address))
cn0: checking oarg ((1 character-address) (raw))
maybe-add: ((1 character-address) (raw))
cn0: (((1 character-address) (raw)) <- ((read-key)) ((x keyboard-address))) ((s 1) (x 2)) nil
cn0: checking arg ((x keyboard-address))
maybe-add: ((x keyboard-address))
cn0: checking oarg ((1 character-address) (raw))
maybe-add: ((1 character-address) (raw))
cn1: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
cn1: (((1 string-address)) <- ((new)) foo)
cn1: (((2 keyboard-address)) <- ((init-keyboard)) ((1 string-address)))
cn1: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address)))
cn1: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address)))
schedule: main
run: main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: main 0: 1000 => ((default-space space-address))
run: main 1: (((1 string-address)) <- ((new)) foo)
run: main 1: 1031 => ((1 string-address))
mem: ((1 string-address)): 1002 <= 1031
run: main 2: (((2 keyboard-address)) <- ((init-keyboard)) ((1 string-address)))
mem: ((1 string-address)) => 1031
run: init-keyboard/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: init-keyboard/main 0: 1035 => ((default-space space-address))
run: init-keyboard/main 1: (((1 keyboard-address)) <- ((new)) ((keyboard literal)))
run: init-keyboard/main 1: 1066 => ((1 keyboard-address))
mem: ((1 keyboard-address)): 1037 <= 1066
run: init-keyboard/main 2: (((2 string-address-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((1 offset)))
run: init-keyboard/main 2: 1067 => ((2 string-address-address))
mem: ((2 string-address-address)): 1038 <= 1067
run: init-keyboard/main 3: (((2 string-address-address) (deref)) <- ((next-input)))
arg: nil 0 (1031)
run: init-keyboard/main 3: 1031 => ((2 string-address-address) (deref))
mem: ((2 string-address-address) (deref)): 1067 <= 1031
run: init-keyboard/main 4: (((3 integer-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((0 offset)))
run: init-keyboard/main 4: 1066 => ((3 integer-address))
mem: ((3 integer-address)): 1039 <= 1066
run: init-keyboard/main 5: (((3 integer-address) (deref)) <- ((copy)) ((0 literal)))
run: init-keyboard/main 5: 0 => ((3 integer-address) (deref))
mem: ((3 integer-address) (deref)): 1066 <= 0
run: init-keyboard/main 6: (((reply)) ((1 keyboard-address)))
mem: ((1 keyboard-address)) => 1066
run: main 2: 1066 => ((2 keyboard-address))
mem: ((2 keyboard-address)): 1003 <= 1066
run: main 3: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address)))
mem: ((2 keyboard-address)) => 1066
run: read-key/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: read-key/main 0: 1068 => ((default-space space-address))
run: read-key/main 1: (((1 keyboard-address)) <- ((next-input)))
arg: nil 0 (1066)
run: read-key/main 1: 1066 => ((1 keyboard-address))
mem: ((1 keyboard-address)): 1070 <= 1066
run: read-key/main 2: (((2 terminal-address)) <- ((next-input)))
arg: nil 1 (1066)
run: read-key/main 2: nil => ((2 terminal-address))
mem: ((2 terminal-address)): 1071 <= nil
run: read-key/main 3: (((jump-unless)) ((1 keyboard-address)) ((9 offset)))
mem: ((1 keyboard-address)) => 1066
run: read-key/main 4: (((3 integer-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((0 offset)))
run: read-key/main 4: 1066 => ((3 integer-address))
mem: ((3 integer-address)): 1072 <= 1066
run: read-key/main 5: (((4 string-address)) <- ((get)) ((1 keyboard-address) (deref)) ((1 offset)))
mem: ((1067 string-address) (raw)) => 1031
run: read-key/main 5: 1031 => ((4 string-address))
mem: ((4 string-address)): 1073 <= 1031
run: read-key/main 6: (((5 integer)) <- ((length)) ((4 string-address) (deref)))
array-len: ((4 string-address) (deref))
mem: ((1031 integer) (raw)) => 3
run: read-key/main 6: 3 => ((5 integer))
mem: ((5 integer)): 1074 <= 3
run: read-key/main 7: (((6 boolean)) <- ((greater-or-equal)) ((3 integer-address) (deref)) ((5 integer)))
mem: ((3 integer-address) (deref)) => 0
mem: ((5 integer)) => 3
run: read-key/main 7: nil => ((6 boolean))
mem: ((6 boolean)): 1075 <= nil
run: read-key/main 8: (((jump-unless)) ((6 boolean)) ((1 offset)))
mem: ((6 boolean)) => nil
run: read-key/main 10: (((7 character)) <- ((index)) ((4 string-address) (deref)) ((3 integer-address) (deref)))
mem: ((3 integer-address) (deref)) => 0
array-len: ((1031 string) (raw))
mem: ((1031 integer) (raw)) => 3
mem: ((1032 byte) (raw)) => f
run: read-key/main 10: #\f => ((7 character))
mem: ((7 character)): 1076 <= #\f
run: read-key/main 11: (((3 integer-address) (deref)) <- ((add)) ((3 integer-address) (deref)) ((1 literal)))
mem: ((3 integer-address) (deref)) => 0
run: read-key/main 11: 1 => ((3 integer-address) (deref))
mem: ((3 integer-address) (deref)): 1066 <= 1
run: read-key/main 12: (((reply)) ((7 character)))
mem: ((7 character)) => f
run: main 3: #\f => ((1 character-address) (raw))
mem: ((1 character-address) (raw)): 1 <= #\f
run: main 4: (((1 character-address) (raw)) <- ((read-key)) ((2 keyboard-address)))
mem: ((2 keyboard-address)) => 1066
run: read-key/main 0: (((default-space space-address)) <- ((new)) ((space literal)) ((30 literal)))
run: read-key/main 0: 1099 => ((default-space space-address))
run: read-key/main 1: (((1 keyboard-address)) <- ((next-input)))
arg: nil 0 (1066)
run: read-key/main 1: 1066 => ((1 keyboard-address))
mem: ((1 keyboard-address)): 1101 <= 1066
run: read-key/main 2: (((2 terminal-address)) <- ((next-input)))
arg: nil 1 (1066)
run: read-key/main 2: nil => ((2 terminal-address))
mem: ((2 terminal-address)): 1102 <= nil
run: read-key/main 3: (((jump-unless)) ((1 keyboard-address)) ((9 offset)))
mem: ((1 keyboard-address)) => 1066
run: read-key/main 4: (((3 integer-address)) <- ((get-address)) ((1 keyboard-address) (deref)) ((0 offset)))
run: read-key/main 4: 1066 => ((3 integer-address))
mem: ((3 integer-address)): 1103 <= 1066
run: read-key/main 5: (((4 string-address)) <- ((get)) ((1 keyboard-address) (deref)) ((1 offset)))
mem: ((1067 string-address) (raw)) => 1031
run: read-key/main 5: 1031 => ((4 string-address))
mem: ((4 string-address)): 1104 <= 1031
run: read-key/main 6: (((5 integer)) <- ((length)) ((4 string-address) (deref)))
array-len: ((4 string-address) (deref))
mem: ((1031 integer) (raw)) => 3
run: read-key/main 6: 3 => ((5 integer))
mem: ((5 integer)): 1105 <= 3
run: read-key/main 7: (((6 boolean)) <- ((greater-or-equal)) ((3 integer-address) (deref)) ((5 integer)))
mem: ((3 integer-address) (deref)) => 1
mem: ((5 integer)) => 3
run: read-key/main 7: nil => ((6 boolean))
mem: ((6 boolean)): 1106 <= nil
run: read-key/main 8: (((jump-unless)) ((6 boolean)) ((1 offset)))
mem: ((6 boolean)) => nil
run: read-key/main 10: (((7 character)) <- ((index)) ((4 string-address) (deref)) ((3 integer-address) (deref)))
mem: ((3 integer-address) (deref)) => 1
array-len: ((1031 string) (raw))
mem: ((1031 integer) (raw)) => 3
mem: ((1033 byte) (raw)) => o
run: read-key/main 10: #\o => ((7 character))
mem: ((7 character)): 1107 <= #\o
run: read-key/main 11: (((3 integer-address) (deref)) <- ((add)) ((3 integer-address) (deref)) ((1 literal)))
mem: ((3 integer-address) (deref)) => 1
run: read-key/main 11: 2 => ((3 integer-address) (deref))
mem: ((3 integer-address) (deref)): 1066 <= 2
run: read-key/main 12: (((reply)) ((7 character)))
mem: ((7 character)) => o
run: main 4: #\o => ((1 character-address) (raw))
mem: ((1 character-address) (raw)): 1 <= #\o
schedule: done with routine nil
'/akkartik/mu/blame/cpp/000organization?h=hlt&id=e26a1c859352421eaa7232987739ed5e8c79ce3f'>^
|
|
//: You guessed right: the '000' prefix means you should start reading here.
//:
//: This project is set up to load all files with a numeric prefix. Just
//: create a new file and start hacking.
//:
//: The first few files (00*) are independent of what this program does, an
//: experimental skeleton that will hopefully make it both easier for others to
//: understand and more malleable, easier to rewrite and remould into radically
//: different shapes without breaking in subtle corner cases. The premise is
//: that understandability and rewrite-friendliness are related in a virtuous
//: cycle. Doing one well makes it easier to do the other.
//:
//: Lower down, this file contains a legal, bare-bones C++ program. It doesn't
//: do anything yet; subsequent files will contain :(...) directives to insert
//: lines into it. For example:
//: :(after "more events")
//: This directive means: insert the following lines after a line in the
//: program containing the words "more events".
//:
//: A simple tool is included to 'tangle' all the files together in sequence
//: according to their directives into a single source file containing all the
//: code for the project, and then feed the source file to the compiler.
//: (It'll drop these comments starting with a '//:' prefix that only make
//: sense before tangling.)
//:
//: Directives free up the programmer to order code for others to read rather
//: than as forced by the computer or compiler. Each individual feature can be
//: organized in a self-contained 'layer' that adds code to many different data
//: structures and functions all over the program. The right decomposition into
//: layers will let each layer make sense in isolation.
//:
//: "If I look at any small part of it, I can see what is going on -- I don't
//: need to refer to other parts to understand what something is doing.
//:
//: If I look at any large part in overview, I can see what is going on -- I
//: don't need to know all the details to get it.
//:
//: Every level of detail is as locally coherent and as well thought-out as
//: any other level."
//:
//: -- Richard Gabriel, "The Quality Without A Name"
//: (http://dreamsongs.com/Files/PatternsOfSoftware.pdf, page 42)
//:
//: Directives are powerful; they permit inserting or modifying any point in
//: the program. Using them tastefully requires mapping out specific lines as
//: waypoints for future layers to hook into. Often such waypoints will be in
//: comments, capitalized to hint that other layers rely on their presence.
//:
//: A single waypoint might have many different code fragments hooking into
//: it from all over the codebase. Use 'before' directives to insert
//: code at a location in order, top to bottom, and 'after' directives to
//: insert code in reverse order. By convention waypoints intended for insertion
//: before begin with 'End'. Notice below how the layers line up above the "End
//: Foo" waypoint.
//:
//: File 001 File 002 File 003
//: ============ =================== ===================
//: // Foo
//: ------------
//: <---- :(before "End Foo")
//: ....
//: ...
//: ------------
//: <---------------------------- :(before "End Foo")
//: ....
//: ...
//: // End Foo
//: ============
//:
//: Here's part of a layer in color: http://i.imgur.com/0eONnyX.png. Directives
//: are shaded dark.
//:
//: Layers do more than just shuffle code around. In a well-organized codebase
//: it should be possible to stop loading after any file/layer, build and run
//: the program, and pass all tests for loaded features. (Relevant is
//: http://youtube.com/watch?v=c8N72t7aScY, a scene from "2001: A Space
//: Odyssey".) Get into the habit of running the included script called
//: 'test_layers' before you commit any changes.
//:
//: This 'subsetting guarantee' ensures that this directory contains a
//: cleaned-up narrative of the evolution of this codebase. Organizing
//: autobiographically allows a newcomer to rapidly orient himself, reading the
//: first few files to understand a simple gestalt of a program's core purpose
//: and features, and later gradually working his way through other features as
//: the need arises.
//:
//: Programmers shouldn't need to understand everything about a program to hack
//: on it. But they shouldn't be prevented from a thorough understanding of
//: each aspect either. The goal of layers is to reward curiosity.
// Includes
// End Includes
// Types
// End Types
// Prototypes are auto-generated in the 'build' script; define your functions
// in any order. Just be sure to declare each function header all on one line.
// Our auto-generation scripts are too minimal and simple-minded to handle
// anything else.
#include "function_list" // by convention, files ending with '_list' are auto-generated
// Globals
//
// All statements in this section should always define a single variable on a
// single line. The 'build' script will simple-mindedly auto-generate extern
// declarations for them. Don't forget to define (not just declare) constants
// with extern linkage in this section, since C++ global constants have
// internal linkage by default.
//
// End Globals
int main(int argc, char* argv[]) {
atexit(teardown);
// End One-time Setup
// Commandline Parsing
// End Commandline Parsing
return 0; // End Main
}
// Unit Tests
// End Unit Tests
//: our first directive; will move the include above the program
:(before "End Includes")
#include <stdlib.h>
//: Without directives or with the :(code) directive, lines get added at the
//: end.
:(code)
void setup() {
// End Setup
}
void teardown() {
// End Teardown
}
|