dodebug.icl 6.44 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
1
2
3
4
implementation module dodebug

import StdEnv,StdPictureDef
from	quickdraw import QGetPort, :: GrafPtr
5
import Platform
Diederik van Arkel's avatar
Diederik van Arkel committed
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

assert :: {#.Char} !.(.a -> (.Bool,.b)) .a -> .b
assert txt test env
	# (ok,env)	= test env
	| ok = env
	= abort txt

import osrgn,StdDebug

abort` :: !a -> .b	| toString a	// stop reduction and print argument
abort` a = abort (toString a)

abort`` :: !.a !b -> .a | toString b
abort`` a b = abort (toString b)

trace_l :: ![a] .b -> .b | toString a
trace_l [] e = e
trace_l [h:t] e
	#! e = trace_n h e
	= trace_l t e

trace_rgn :: !{#.Char} !Int -> Int
trace_rgn txt rgn
	# (isRect,rct,_)= osgetrgnbox rgn OSNewToolbox
	# rgn			= trace_n (txt+++xxx rct isRect) rgn
	= rgn
where
	xxx {rleft,rtop,rright,rbottom} isRect =
			"[("+++toString rleft+++
			","+++toString rtop +++
			"),("+++toString rright+++
			","+++toString rbottom+++
			")] "+++toString isRect

trace_col :: !{#.Char} !Colour -> Colour
trace_col txt col
	= trace_n (txt+++xxx col) col
where
	xxx colour = case colour of
							Black	-> "BlackColor"
							White	-> "WhiteColor"
							Red		-> "RedColor"
							Green	-> "GreenColor"
							Blue	-> "BlueColor"
							Cyan	-> "CyanColor"
							Magenta	-> "MagentaColor"
							Yellow	-> "YellowColor"
							RGB rgb		-> "rgb"
							DarkGrey	-> "DarkGrey"
							Grey		-> "Grey"
							LightGrey	-> "LightGrey"


assertPort :: !Int !*OSToolbox -> (!Bool,!*OSToolbox)
assertPort p tb
	# (q,tb)	= QGetPort tb
	= (p==q,tb)
		
instance toString OSRect
where
	toString {rleft,rtop,rright,rbottom} = "{("+++toString rleft+++","+++toString rtop+++"),("+++toString rright+++","+++toString rbottom+++")}"

instance toString (l,r) | toString l & toString r
where
	toString (l,r) = "("+++toString l+++","+++toString r+++")"

instance toString (a,b,c) | toString a & toString b & toString c
where
	toString (a,b,c) = "("+++toString a+++","+++toString b+++","+++toString c+++")"

instance toString (a,b,c,d) | toString a & toString b & toString c & toString d
where
	toString (a,b,c,d) = "("+++toString a+++","+++toString b+++","+++toString c+++","+++toString d+++")"

instance toString (a,b,c,d,e) | toString a & toString b & toString c & toString d & toString e
where
	toString (a,b,c,d,e) = "("+++toString a+++","+++toString b+++","+++toString c+++","+++toString d+++","+++toString e+++")"

instance toString (a,b,c,d,e,f) | toString a & toString b & toString c & toString d & toString e & toString f
where
	toString (a,b,c,d,e,f) = "("+++toString a+++","+++toString b+++","+++toString c+++","+++toString d+++","+++toString e+++","+++toString f+++")"

instance toString Colour where
	toString (RGB rgb)	=  "(RGB "+++toString rgb+++")"
	toString Black		= "Black"
	toString White		= "White"
	toString DarkGrey	= "DarkGrey"
	toString Grey		= "Grey"
	toString LightGrey	= "LightGrey"
	toString Red		= "Red"
	toString Green		= "Green"
	toString Blue		= "Blue"
	toString Cyan		= "Cyan"
	toString Magenta	= "Magenta"
	toString Yellow		= "Yellow"

instance toString RGBColour where
	toString {r,g,b}	= "{"+++ (itemsList "," (map recordFieldtoString [("r",r),("g",g),("b",b)]))+++"}"

itemsList :: !String ![String] -> String
itemsList separator [x:xs]
	= x+++itemsList` xs
where
	itemsList` [x:xs]	= separator+++x+++itemsList` xs
	itemsList` _		= ""
itemsList _ _
	= ""

curlify  x = "{"+++x+++"}"
brackify x = "("+++x+++")"
squarify x = "["+++x+++"]"

recordFieldtoString :: (String,a) -> String | toString a
recordFieldtoString (field,value) = field+++"="+++toString value

pretty :: ![a] -> String | toString a
pretty l = brackify (itemsList "," (map toString l))

import StdMaybe

instance toString (Maybe a) | toString a
where
	toString Nothing = "Nothing"
	toString (Just a) = "Just "+++.toString a

import deviceevents

instance toString MsgEvent
where
	toString (QASyncMessage msg)	= "QASyncMessage"
	toString (ASyncMessage msg)		= "ASyncMessage"
	toString (SyncMessage msg)		= "SyncMessage"

instance toString ControlUpdateInfo
where
	toString
		{	cuItemNr			//:: !Int						// The wItemNr of the control
		,	cuItemPtr			//:: !OSWindowPtr				// The wItemPtr to the control (can be OSNoWindowPtr)
		,	cuArea				//:: !OSRect					// The update area of the control (in window coordinates)
		} = "{"+++toString cuItemNr +:+ toString cuItemPtr +:+ toString cuArea+++"}"

(+:+) infixr 5 :: String String -> String
(+:+) l r = l +++ ","+++ r

instance toString DeviceEvent where
	toString (MenuTraceEvent _)			= "MenuTraceEvent"
	toString (ToolbarSelection _)		= "ToolbarSelection"
	toString (ReceiverEvent _)			= "ReceiverEvent"
	toString (InternetEvent _)				= "InternetEvent"
	toString (TimerEvent _)				= "TimerEvent"
	toString (CompoundScrollAction _)	= "CompoundScrollAction"
	toString (ControlGetKeyFocus _)		= "ControlGetKeyFocus"
	toString (ControlKeyboardAction _)	= "ControlKeyboardAction"
	toString (ControlLooseKeyFocus _)	= "ControlLooseKeyFocus"
	toString (ControlMouseAction _)		= "ControlMouseAction"
	toString (ControlSelection _)		= "ControlSelection"
	toString (ControlSliderAction _)	= "ControlSliderAction"
	toString (WindowActivation _)		= "WindowActivation"
	toString (WindowCANCEL _)			= "WindowCANCEL"
	toString (WindowDeactivation _)		= "WindowDeactivation"
	toString (WindowInitialise _)		= "WindowInitialise"
	toString (WindowKeyboardAction _)	= "WindowKeyboardAction"
	toString (WindowMouseAction _)		= "WindowMouseAction"
	toString (WindowOK _)				= "WindowOK"
	toString (WindowRequestClose _)		= "WindowRequestClose"
	toString (WindowScrollAction _)		= "WindowScrollAction"
	toString (WindowSizeAction _)		= "WindowSizeAction"
	toString (WindowUpdate _)			= "WindowUpdate"
	toString ProcessRequestClose		= "ProcessRequestClose"
	toString (ProcessRequestOpenFiles _)= "ProcessRequestOpenFiles"
	toString ProcessRequestClipboardChanged		= "ProcessRequestClipboardChanged"

instance toString SchedulerEvent
where
	toString (ScheduleOSEvent event=:(a,b,c,d,e,f,g) list)
		= "ScheduleOSEvent: " +++ toString (a,b,c) +++ toString (d,e,f,g)
	toString (ScheduleMsgEvent event)		= "ScheduleMsgEvent"
	toString (ScheduleTimerEvent event)		= "ScheduleTimerEvent"

DebugStr :: !String !.a -> .a
DebugStr s a
	| onOSX
		# s = {toChar (size s)} +++ s
		| 42 == DebugStr s 42 = a
		= a
	= trace_n s a
where
	DebugStr :: !String !*Int -> *Int
	DebugStr _ _ = code {
		ccall DebugStr "Ps:V:I"
		}

trace_n` :: !msg .a -> .a | toString msg	// write toString msg and newline to stderr
										// before evaluating a
trace_n` m a
	= DebugStr (toString m) a
//	= trace_n m a

DebugStr` :: !msg !.a -> .a | toString msg
DebugStr` msg a
	= DebugStr (toString msg) a