smalltalk-tng
view r1/boot.thing @ 321:c4a0718c2d3c
Sketch of dependencies
| author | Tony Garnock-Jones <tonygarnockjones@gmail.com> |
|---|---|
| date | Sat Oct 08 15:36:03 2011 -0400 (3 months ago) |
| parents | |
| children |
line source
1 "-*- slate -*-"
3 l@(Location traits) addGlobal: name@(Symbol traits) value: val
4 [
5 gg := Globals. "look up global 'Globals' outside the block, otherwise we deadlock"
6 gg --> [ :g | gg <-- (g withSlot: name value: val) ].
7 val
8 ].
10 "Make globals delegate to Oddball."
11 ( gg := Globals. ob := Oddball traits.
12 gg --> [ :g | gg <-- (g traits:* ob) ] ).
14 g@(Globals peek) as: _@(String traits) [ 'Globals' ].
16 val@(Root traits) ref
17 [
18 c := Cell new.
19 c <-- val.
20 c
21 ].
23 c@(Cell traits) read
24 [
25 p --> [ :v | v ]
26 ].
28 c@(Cell traits) update: block
29 [
30 c --> [ :v | c <-- (block applyWith: v) ]
31 ].
33 c@(Cell traits) push: value
34 [
35 c update: [ :cdr | value -> cdr ]
36 ].
38 block@(Block traits) fork
39 [
40 here ( here fork: block. )
41 ].
43 block@(Block traits) loop
44 [
45 loop := [ block do. loop do. ].
46 loop do.
47 ].
49 p@Nil reverse [ Nil ].
50 p@(Pair traits) reverse [
51 loop := [ :p :acc | p ifNil: [ acc ] ifNotNil: [ loop applyWith: p value with: p key -> acc ] ].
52 loop applyWith: p with: Nil
53 ].
55 n1@(Number traits) to: n2@(Number traits) do: block@(Block traits) [
56 loop := [ :n | (n <= n2) ifTrue: [ block applyWith: n. loop applyWith: n + 1 ] ].
57 loop applyWith: n1
58 ].
60 _@True ifTrue: b@(Block traits) [ b do ].
61 _@False ifTrue: b@(Block traits) [].
63 _@True ifFalse: b@(Block traits) [].
64 _@False ifFalse: b@(Block traits) [ b do ].
66 _@True ifTrue: b1@(Block traits) ifFalse: b2@(Block traits) [ b1 do ].
67 _@False ifTrue: b1@(Block traits) ifFalse: b2@(Block traits) [ b2 do ].
69 _@Nil ifNil: b1@(Block traits) ifNotNil: b2@(Block traits) [ b1 do ].
70 _@(Root traits) ifNil: b1@(Block traits) ifNotNil: b2@(Block traits) [ b2 do ].
72 _@Nil ifNil: b@(Block traits) [ b do ].
73 _@(Root traits) ifNil: b@(Block traits) [].
75 _@Nil ifNotNil: b@(Block traits) [].
76 _@(Root traits) ifNotNil: b@(Block traits) [ b do ].
78 p@Nil concatenate [ Nil ].
79 p@(Pair traits) concatenate [
80 p value
81 ifNil: [ p key ]
82 ifNotNil: [ p key, p value concatenate ]
83 ].
85 s1@(String traits) , s2@(String traits)
86 [
87 s1 primStringAppend: s2
88 ].
90 t@(Tuple traits) printString
91 [
92 p := Nil ref.
93 p push: '{'.
94 0 to: (t size - 1) do: [ :index |
95 (index = 0) ifFalse: [ p push: '. ' ].
96 p push: (t at: index) printString.
97 ].
98 p push: '}'.
99 p read reverse concatenate
100 ].
102 "I am a parallel map."
103 p@Nil map: block [ Nil ].
104 p@(Pair traits) map: block [ (block applyWith: p key) -> (p value map: block) ].
106 "I am a sequential map."
107 p@Nil mapInOrder: block [].
108 p@(Pair traits) mapInOrder: block [
109 h := (block applyWith: p key).
110 h -> (p value mapInOrder: block)
111 ].
113 "I am a sequential for-each."
114 p@Nil do: block [].
115 p@(Pair traits) do: block [ block applyWith: p key. p value do: block ].
117 "I am a parallel for-each."
118 p@Nil doInParallel: block [].
119 p@(Pair traits) doInParallel: block [ [block applyWith: p key] fork. p value doInParallel: block ].
121 p@(Pair traits) printString
122 [
123 '(', p key printString, ' -> ', p value printString, ')'
124 ].
126 s@(Symbol traits) printString [ '#', resend ].
128 _@(Globals peek) shutDownImage
129 [
130 ShutdownHooks peek do: [ :hook | hook shutDown do. ].
131 'BOOTSTRAP.image' saveImage.
132 primQuit.
133 ].
135 "---------------------------------------------------------------------------"
137 "
138 [
139 ({1. 2. 3. #four} -> ('Hello, world, from ThiNG!' -> (True -> (123 -> ((#a -> #b) -> Nil)))))
140 do: [ :each |
141 each printOn: Console.
142 Console crlf.
143 ].
144 ] fork.
145 "
147 here (
148 here addGlobal: #TraitsTraits value: (Root traits traits). "!!"
150 t := (name := 'ReplServer' traits :* TraitsTraits).
151 here addGlobal: #ReplServer value: (traits :* t serverSocket := Nil).
152 ).
154 rs0@(ReplServer traits) newOnPort: port@(Number traits)
155 [
156 rs := (rs0 serverSocket := port primListen).
157 [ rs acceptLoop ] fork.
158 ].
160 rs@(ReplServer traits) acceptLoop
161 [
162 [
163 sock := rs serverSocket accept.
164 sock ifNotNil: [ [ rs replOn: sock ] fork. ].
165 ] loop.
166 ].
168 rs@(ReplServer traits) replOn: sock
169 [ session (
170 'Welcome to ThiNG!\n' printOn: sock.
171 [
172 'ThiNG> ' printOn: sock.
173 compilationResult := sock compileOneStatement.
174 compilationResult key
175 ifTrue: [ compilationResult value do printOn: sock. ]
176 ifFalse: [
177 'PARSE ERROR\n' printOn: sock.
178 compilationResult value printOn: sock.
179 sock close.
180 session return: Nil.
181 ].
182 '\n' printOn: sock.
183 ] loop.
184 )].
186 here (
187 here addGlobal: #ShutdownHooks value: Nil ref.
188 ShutdownHooks push: (shutDown:=[] startUp:=[ ReplServer newOnPort: 4444 ]).
189 here addGlobal: #BootBlock value: [ ShutdownHooks peek do: [ :hook | hook startUp do. ] ].
190 shutDownImage.
191 ).
