forked from newspeaklanguage/newspeak
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugging.ns
More file actions
632 lines (619 loc) · 17.9 KB
/
Debugging.ns
File metadata and controls
632 lines (619 loc) · 17.9 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
Newspeak3
'Root'
class Debugging usingPlatform: platform ide: ide = (
(* UI for the Web debugger. *)
|
private List = platform collections List.
private Map = platform collections Map.
private JSObject = platform js global at: 'Object'.
private Color = platform graphics Color.
private ObjectMirror = platform mirrors ObjectMirror.
private Gradient = platform hopscotch Gradient.
private Subject = platform hopscotch Subject.
private TextEditorFragment = platform hopscotch TextEditorFragment.
private EvaluationViewState = ide browsing EvaluationViewState.
private ProgrammingPresenter = ide browsing ProgrammingPresenter.
private EvaluatorSubject = ide browsing EvaluatorSubject.
private SlotSubject = ide browsing SlotSubject.
private ObjectSubject = ide browsing ObjectSubject.
private Utilities = ide browsing Utilities.
ide = ide.
private styleButtonSize <Float> = 30.
|
) (
class ActivationPresenter onSubject: s <ActivationSubject> = ProgrammingPresenter onSubject: s (
|
slots <PresenterList>
editor <CodeMirrorFragment>
mustBeExpanded ::= false. (* See isExpanded for a discussion of this slot's purpose *)
|
) (
acceptResponse ^ <[:CodeMirrorFragment :Event]> = (
^ [:ed <CodeMirrorFragment> :event <Event> |
updateGUI: [respondToSourceAccept: ed].
ed editor focus.
]
)
changeResponse ^ <[:CodeMirrorFragment :Event]> = (
^[:ed <CodeMirrorFragment> :event <Event> | | cp <Integer> |
ed updateEditState.
]
)
public collapse = (
substance collapse.
)
computeSlotPresenters = (
^subject slots collect:
[:slot <LocalSubject> | slot presenter].
)
public definition ^ <Fragment> = (
^collapsed: [definitionForHeader] expanded: [column: {
definitionForHeader.
definitionForControls.
(row: {
definitionForSource width: 0 elasticity: 1.6 asFloat.
smallBlank.
definitionForState width: 0 elasticity: 1.
}) crossAxisAlignToStart.
}]
)
definitionForControls = (
^row: {
button: 'into' action: [respondToStepInto].
smallBlank.
button: 'into closure' action: [respondToStepIntoClosure].
smallBlank.
button: 'over' action: [respondToStepOver].
smallBlank.
button: 'out' action: [respondToStepOut].
smallBlank.
button: '^self' action: [respondToReturnSelf].
smallBlank.
button: '^nil' action: [respondToReturnNil].
smallBlank.
button: '^false' action: [respondToReturnFalse].
smallBlank.
button: '^true' action: [respondToReturnTrue].
filler.
button: 'restart' action: [respondToRestart].
smallBlank.
}
)
definitionForSource = (
editor:: codeMirror: subject source.
editor acceptResponse: acceptResponse; changeResponse: changeResponse.
highlightSourceRange.
^editor
)
public expand = (
substance expand.
)
messagesMenu = (
| messagesAndActions messageItems classItems |
messagesAndActions:: List new.
messagesAndActions add:
{subject name. [browseSelector: subject name]}.
messageItems:: referencesMenuMessageItems.
messageItems isEmpty not ifTrue:
[messagesAndActions
add: #separator;
addAll: messageItems].
^menuWithLabelsAndActions: messagesAndActions
)
highlightSourceRange = (
| source range style |
source:: subject source.
nil = source ifTrue: [editor text: '<no source>'. ^self].
editor text: source.
range:: subject sourceRange.
nil = range ifTrue: [^self].
style:: JSObject new.
style at: 'css' put: 'color:blue; font-weight:bold; text-decoration: underline'.
editor style: style from: range start to: range stop.
)
public isKindOfActivationPresenter ^ <Boolean> = (
^true
)
isMyKind: f <Fragment> ^ <Boolean> = (
^f isKindOfActivationPresenter
)
public refresh = (
nil = slots ifFalse:
[slots setPresenters: computeSlotPresenters].
nil = editor ifFalse:
[highlightSourceRange].
)
refreshThreadPresenter = (
| ancestor ::= parent. |
[nil = ancestor] whileFalse:
[ancestor isKindOfThreadPresenter ifTrue:
[^ancestor refresh].
ancestor:: ancestor parent].
)
respondToInspectMirror = (
inspectObject: subject activationMirror.
)
respondToRestart = (
updateGUI: [subject restart].
)
respondToReturnFalse = (
updateGUI: [subject returnFalse].
)
respondToReturnNil = (
updateGUI: [subject returnNil].
)
respondToReturnSelf = (
updateGUI: [subject returnSelf].
)
respondToReturnTrue = (
updateGUI: [subject returnTrue].
)
respondToStepInto = (
updateGUI: [subject stepInto].
)
respondToStepIntoClosure = (
updateGUI: [subject stepThrough].
)
respondToStepOut = (
updateGUI: [subject stepOut].
)
respondToStepOver = (
updateGUI: [subject stepOver].
)
public tag ^ <String> = (
^subject title
)
public isExpanded: b <Boolean> = (
(* Called by the thread presenter to indicate this activation should be expanded.
Calling expand is inappropriate, because at the time the thread presenter definition is
computed, no visual has been computed yet. Instead, this method is used to indicate
that the substance should be expanded when it has a visual. See also the comment in
#updateVisualsFromSameKind:.
*)
mustBeExpanded: true.
substance isExpanded: b.
)
updateVisualsFromSameKind: oldPresenter <Self> ^ <Alien[Element]> = (
(* We override this method because we need to ensure that the topmost activation on the stack
is open, even if it was closed before. ThreadPresenter tells the topmost activation to be open.
However, the process of updating the visuals to reflect the state of the frames may close the frame
again (for example, when returning from an activation, if the calling frame was closed prior to
returning). Also see the comment in #isExpanded:.
*)
super updateVisualsFromSameKind: oldPresenter.
mustBeExpanded ifTrue: [substance expand].
^substance visual
)
respondToCreateMissingSlot = (
| receiverClass = subject activationMirror receiver getClass reflectee. |
browseClass: receiverClass.
)
actionsMenu = (
^menuWithLabelsAndActions: {
{'Inspect Mirror'. [respondToInspectMirror]}.
{'Inspect Presenter'. [respondToInspectPresenter]}.
},
(subject isMessageNotUnderstood ifTrue: [
{{'Create missing method ', subject notUnderstoodMessage selector. [respondToCreateMissingMethod].}},
((subject notUnderstoodMessage arguments isEmpty and: [subject activationMirror receiver getClass isMeta not]) ifTrue: [
{{ 'Create missing class ', subject notUnderstoodMessage selector. [respondToCreateMissingClass]}.
{'Create missing slot ', subject notUnderstoodMessage selector. [respondToCreateMissingSlot]}.
}] ifFalse: [{}]
)] ifFalse: [{}])
)
definitionForState = (
^column: {
subject evaluator presenter.
link: 'self' action: [enterSubject: subject receiver].
slots:: column: computeSlotPresenters.
}
)
respondToCreateMissingMethod = (
|
receiverClassMirror <ClassMirror> = subject activationMirror receiver getClass.
receiverClass <Class> = receiverClassMirror reflectee.
targetPresenter <MethodGroupPresenter>
|
browseClass: receiverClass.
targetPresenter:: receiverClassMirror isMeta
ifFalse: [shell currentPresenter instanceMethodsPresenter]
ifTrue: [shell currentPresenter classMethodsPresenter].
targetPresenter addNewItemTemplate: subject proposedMissingMessageSource.
)
respondToCreateMissingClass = (
| receiverClass = subject activationMirror receiver getClass reflectee. |
browseClass: receiverClass.
shell currentPresenter nestedClassesPresenter addNewItemTemplate: subject proposedMissingClassSource
)
referencesMenuMessageItems = (
| items sortedMessages|
items:: List new.
sortedMessages:: subject messages sort: [:m1 :m2 |
Utilities lexicallyLessOrEqual: m1 than: m2
].
sortedMessages do:
[:selector |
selector == subject name ifFalse:
[items add:
{selector. [browseSelector: selector]}]].
^items
)
definitionForHeader = (
| qualification |
qualification:: subject receiverMixin = subject methodMixin
ifTrue:
[{}]
ifFalse:
[{
(label: ' ( ')
color: tertiaryTextColor.
(link: subject methodMixin name action: [browseMixinMirror: subject methodMixin])
color: secondaryTextColor.
(label: ' )')
color: tertiaryTextColor.
}].
^row: {
image: (iconForAccessModifier: subject activationMirror method accessModifier) size: styleButtonSize.
blank: 3.
(link: subject name action: [substance toggle])
color: actionLinkColor.
(label: ' in ')
color: tertiaryTextColor.
(link: subject receiverMixin name action: [browseMixinMirror: subject receiverMixin])
color: secondaryTextColor.
} , qualification , {
filler.
dropDownMenu: [messagesMenu] image: ide images itemReferencesImage.
dropDownMenu: [actionsMenu].
}
)
respondToSourceAccept: editor <CodeMirrorFragment> = (
subject
installNewSource: editor textBeingAccepted
ifSuccess: [editor leaveEditState]
ifFailure: [:msg | editor showMessage: msg].
)
) : (
)
class ActivationSubject onModel: m <ActivationMirror> in: t <ThreadSubject> = Subject onModel: m (
|
protected threadSubject <ThreadSubject> = t.
public evaluator <EvaluationViewState> = EvaluatorSubject onModel: (EvaluationViewState onModel: activationMirror).
slotMap <Map[Symbol, SlotSubject]> ::= Map new.
|
) (
public = other <Object> ^<Boolean> = (
(* no need for hash - superclass version is fine *)
other isKindOfActivationSubject ifFalse: [^false].
^activationMirror = other activationMirror
)
public activationMirror ^<ActivationMirror> = (
^model
)
public className = (
^nil
)
public createPresenter = (
^ActivationPresenter onSubject: self
)
public evaluate: expression <String> ^<ThreadMirror> = (
^activationMirror evaluate: expression
)
public homeMirror ^<ActivationMirror> = (
| result ::= activationMirror. |
[nil = result closure] whileFalse: [result:: result enclosingActivation].
^result
)
public isKindOfActivationSubject ^<Boolean> = (
^true
)
isMyKind: s <Subject> ^ <Boolean> = (
^s isKindOfActivationSubject
)
public messages ^ <List[Symbol]> = (
^activationMirror method selectors
)
public methodMixin ^<MixinMirror> = (
^activationMirror method definingMixin
)
public name ^<String> = (
| n enclosing |
n:: activationMirror method name.
enclosing:: activationMirror enclosingActivation.
[nil = enclosing] whileFalse:
[n:: '[] in ', n.
enclosing:: enclosing enclosingActivation].
^n
)
public receiverMixin ^<MixinMirror> = (
^activationMirror receiver getClass mixin
)
public restart = (
activationMirror restart.
)
public returnFalse = (
activationMirror return: (ObjectMirror reflecting: false).
)
public returnNil = (
activationMirror return: (ObjectMirror reflecting: nil).
)
public returnSelf = (
activationMirror return: model receiver.
)
public returnTrue = (
activationMirror return: (ObjectMirror reflecting: true).
)
public slots = (
|
newMap <Map[Symbol, SlotSubject]> = Map new.
slotList<List[SlotSubject]> = activationMirror slots collect: [:slot <LocalSlotMirror> |
newMap at: slot name put: (slotSubjectFor: slot)
].
|
slotMap:: newMap.
^slotList
)
public source ^<String> = (
| s = activationMirror method source. |
nil = s ifTrue: [^'<source unavailable>'].
^s
)
public sourceRange ^<Interval> = (
^activationMirror sourceRange
)
public stepInto = (
activationMirror stepInto.
)
public stepOut = (
activationMirror stepOut.
)
public stepOver = (
activationMirror stepOver.
)
public stepThrough = (
activationMirror stepThrough.
)
public title ^<String> = (
^name , ' in ' , receiverMixin name , '(', methodMixin name , ')'.
)
public receiver ^ <ObjectSubject> = (
^ObjectSubject onModel: activationMirror receiver
)
public isMessageNotUnderstood ^ <Boolean> = (
^selector = #doesNotUnderstand:
)
public selector = (
^activationMirror method name
)
public notUnderstoodMessage ^ <Message> = (
isMessageNotUnderstood ifFalse: [^halt].
^threadSubject threadMirror result reflectee message
)
public proposedMissingMessageSource ^ <String> = (
^messageHeaderSource, ' = (
)'
)
messageHeaderSource ^ <String> = (
| message |
isMessageNotUnderstood ifFalse: [^''].
message:: notUnderstoodMessage.
message arguments isEmpty ifTrue: [^message selector].
message arguments size = 1 ifTrue: [^message selector, 'arg' ].
)
public proposedMissingClassSource ^ <String> = (
| message |
isMessageNotUnderstood ifFalse: [^''].
message:: notUnderstoodMessage.
assert: [message arguments isEmpty] message: 'Cannot define non-unary class accessor'.
^'class ', messageHeaderSource, ' = ()( )'
)
slotSubjectFor: slot <LocalSlotMirror> ^ <SlotSubject> = (
|
val <ObjectMirror> = slot value.
entry <SlotSubject> ::= slotMap at: slot name ifAbsent: [
SlotSubject name: slot name value: val
].
|
val = entry objectMirror ifFalse: [
entry:: SlotSubject name: slot name value: val
].
^entry
)
public installNewSource: newSource <String> ifSuccess: onSuccess <[]> ifFailure: onFailure <[:String]> = (
| home builder newMethod |
(threadSubject includesActivation: activationMirror) ifFalse:
[^onFailure value: 'Activation is not in thread'].
home:: homeMirror.
(threadSubject includesActivation: home) ifFalse:
[^onFailure value: 'Closure''s method is not in thread'].
builder:: activationMirror method definingMixin asBuilder.
[newMethod:: builder methods addFromSource: newSource]
on: Exception
do: [:compileError | ^onFailure value: compileError printString].
newMethod name = activationMirror method name ifFalse:
[^onFailure value: 'Selector changed'].
ide installFromBuilders: {builder declaration}.
[home restartWithLookup]
on: Exception
do: [:restartError | ^onFailure value: restartError printString].
^onSuccess value
)
) : (
)
class ThreadPresenter onSubject: s <ThreadSubject> = ProgrammingPresenter onSubject: s (
|
activations <PresenterList>
|
) (
actionsMenu = (
^menuWithLabelsAndActions: {
{'Inspect Mirror'. [respondToInspectMirror]}.
{'Inspect Presenter'. [respondToInspectPresenter]}.
}
)
definition = (
^column: {
definitionForHeading.
smallBlank.
definitionForResult.
definitionForActivations.
}
)
definitionForActivations = (
subject canResume ifFalse: [^nothing].
^column: {
minorHeadingBlock: (row: {
label: 'Activations'.
filler.
expandButtonWithAction: [respondToExpandAll].
blank: 3.
collapseButtonWithAction: [respondToCollapseAll].
}).
smallBlank.
definitionForActivationsList.
largeBlank.
}
)
failureHeadingColor = (
^Gradient from: (Color h: 0 s: 0.5 v: 0.8) to: (Color h: 0 s: 0.5 v: 0.6)
)
public isKindOfThreadPresenter ^<Boolean> = (
^true
)
isMyKind: f <Fragment> ^ <Boolean> = (
^f isKindOfThreadPresenter
)
mainHeadingBlock: body = (
^(padded: body with: {10. 10. 0. 10.})
color: (subject isFulfilled ifTrue: [successHeadingColor] ifFalse: [failureHeadingColor])
)
respondToCollapseAll = (
activations childrenDo: [:activation <ActivationPresenter> | activation collapse].
)
respondToContinue = (
updateGUI: [subject resume].
(*refresh.*)
)
respondToExpandAll = (
activations childrenDo: [:activation <ActivationPresenter> | activation expand].
)
respondToInspectMirror = (
inspectObject: subject threadMirror.
)
respondToTerminate = (
updateGUI: [subject terminate].
(* refresh *)
)
successHeadingColor = (
^Gradient from: (Color h: 120 s: 0.5 v: 0.7) to: (Color h: 120 s: 0.5 v: 0.5)
)
definitionForHeading = (
^mainHeadingBlock: (column: {
row: {
(label: 'Thread: ', subject stateName) color: Color white.
filler.
dropDownMenu: [actionsMenu].
}.
mediumBlank.
row: {
filler.
(button: 'Continue' action: [respondToContinue]) enabled: subject canResume.
largeBlank.
(button: 'Terminate' action: [respondToTerminate]) enabled: subject canResume.
filler.
}.
})
)
definitionForActivationsList = (
activations:: toggleList: (subject refreshActivationChain collect: [:s | s presenter]).
activations childrenDo: [:first | first isExpanded: true. ^activations].
^activations
)
definitionForResult ^ <SlotPresenter | BlankFragment> = (
| result <SlotSubject | Nil> = subject resultAsSlot. |
nil = result ifTrue: [^nothing].
^result presenter
)
) : (
)
public class ThreadSubject onModel: m <ThreadMirror> = Subject onModel: m (
|
protected storedActivations <List[ActivationSubject]> ::= List new.
resultSlot
|
) (
public = other <Object> ^<Boolean> = (
other isKindOfThreadSubject ifFalse: [^false].
^model = other model
)
public canResume = (
^(nil = model suspendedActivation) not
)
public createPresenter = (
^ThreadPresenter onSubject: self
)
public includesActivation: activation <ActivationMirror> = (
| a |
a:: threadMirror suspendedActivation.
[nil = a] whileFalse:
[a = activation ifTrue: [^true].
a:: a sender].
^false
)
public isFulfilled = (
^model isFulfilled
)
public isKindOfThreadSubject ^<Boolean> = (
^true
)
isMyKind: s <Subject> ^ <Boolean> = (
^s isKindOfThreadSubject
)
public refreshActivationChain ^<List[ActivationSubject]> = (
| oldActivations newActivations activation overlapSize |
oldActivations:: storedActivations.
newActivations:: List new.
activation:: model suspendedActivation.
[nil = activation] whileFalse:
[newActivations add: (ActivationSubject onModel: activation in: self).
activation:: activation sender].
replaceCommonSuffixFrom: oldActivations to: newActivations.
^storedActivations:: newActivations.
)
replaceCommonSuffixFrom: oldList to: newList = (
0 to: (newList size min: oldList size) - 1 do: [:offset |
|
newIndex = newList size - offset.
oldIndex = oldList size - offset.
|
(oldList at: oldIndex) = (newList at: newIndex)
ifTrue: [newList at: newIndex put: (oldList at: oldIndex)]
ifFalse: [^self]].
)
public resume = (
model resume.
)
public stateName ^<String> = (
model isFulfilled ifTrue: [^'Fulfilled'].
model isBroken ifTrue: [^'Broken'].
model isSuspended ifTrue: [^'Suspended'].
model isTerminated ifTrue: [^'Terminated'].
^'Unknown'
)
public terminate = (
model terminate.
)
public threadMirror ^<ThreadMirror> = (
^model
)
public resultAsSlot ^ <SlotSubject | Nil> = (
| r <ObjectMirror> = model result. |
nil = r ifTrue: [resultSlot:: nil. ^nil].
(resultSlot isNil or: [r ~= resultSlot objectMirror])
ifTrue: [resultSlot:: SlotSubject name: 'result' value: r].
^resultSlot
)
) : (
)
) : (
)