about summary refs log tree commit diff stats
path: root/client.c
blob: 915a89037ae4d90725e41a84e96435f5e59d168b (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "dwm.h"
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>

/* static */

static void
attachstack(Client *c) {
	c->snext = stack;
	stack = c;
}

static void
detachstack(Client *c) {
	Client **tc;

	for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
	*tc = c->snext;
}

static void
grabbuttons(Client *c, Bool focused) {
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);

	if(focused) {
		XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button1, MODKEY | numlockmask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button1, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);

		XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button2, MODKEY | numlockmask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button2, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);

		XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button3, MODKEY | numlockmask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button3, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
	}
	else
		XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
}

static Bool
isprotodel(Client *c) {
	int i, n;
	Atom *protocols;
	Bool ret = False;

	if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
		for(i = 0; !ret && i < n; i++)
			if(protocols[i] == wmatom[WMDelete])
				ret = True;
		XFree(protocols);
	}
	return ret;
}

static void
setclientstate(Client *c, long state) {
	long data[] = {state, None};

	XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
			PropModeReplace, (unsigned char *)data, 2);
}

static int
xerrordummy(Display *dsply, XErrorEvent *ee) {
	return 0;
}

/* extern */

void
attach(Client *c) {
	if(clients)
		clients->prev = c;
	c->next = clients;
	clients = c;
}

void
ban(Client *c) {
	if(c->isbanned)
		return;
	XUnmapWindow(dpy, c->win);
	setclientstate(c, IconicState);
	c->isbanned = True;
	c->unmapped++;
}

void
configure(Client *c) {
	XConfigureEvent ce;

	ce.type = ConfigureNotify;
	ce.display = dpy;
	ce.event = c->win;
	ce.window = c->win;
	ce.x = c->x;
	ce.y = c->y;
	ce.width = c->w;
	ce.height = c->h;
	ce.border_width = c->border;
	ce.above = None;
	ce.override_redirect = False;
	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
}

void
detach(Client *c) {
	if(c->prev)
		c->prev->next = c->next;
	if(c->next)
		c->next->prev = c->prev;
	if(c == clients)
		clients = c->next;
	c->next = c->prev = NULL;
}

void
focus(Client *c) {
	if((!c && selscreen) || (c && !isvisible(c)))
		for(c = stack; c && !isvisible(c); c = c->snext);
	if(sel && sel != c) {
		grabbuttons(sel, False);
		XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
	}
	if(c) {
		detachstack(c);
		attachstack(c);
		grabbuttons(c, True);
	}
	sel = c;
	drawstatus();
	if(!selscreen)
		return;
	if(c) {
		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
	}
	else
		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
}

void
killclient(const char *arg) {
	XEvent ev;

	if(!sel)
		return;
	if(isprotodel(sel)) {
		ev.type = ClientMessage;
		ev.xclient.window = sel->win;
		ev.xclient.message_type = wmatom[WMProtocols];
		ev.xclient.format = 32;
		ev.xclient.data.l[0] = wmatom[WMDelete];
		ev.xclient.data.l[1] = CurrentTime;
		XSendEvent(dpy, sel->win, False, NoEventMask, &ev);
	}
	else
		XKillClient(dpy, sel->win);
}

void
manage(Window w, XWindowAttributes *wa) {
	Client *c, *t = NULL;
	Window trans;
	Status rettrans;
	XWindowChanges wc;

	c = emallocz(sizeof(Client));
	c->tags = emallocz(ntags * sizeof(Bool));
	c->win = w;
	c->x = wa->x;
	c->y = wa->y;
	c->w = wa->width;
	c->h = wa->height;
	c->oldborder = wa->border_width;
	if(c->w == sw && c->h == sh) {
		c->x = sx;
		c->y = sy;
		c->border = wa->border_width;
	}
	else {
		if(c->x + c->w + 2 * c->border > wax + waw)
			c->x = wax + waw - c->w - 2 * c->border;
		if(c->y + c->h + 2 * c->border > way + wah)
			c->y = way + wah - c->h - 2 * c->border;
		if(c->x < wax)
			c->x = wax;
		if(c->y < way)
			c->y = way;
		c->border = BORDERPX;
	}
	wc.border_width = c->border;
	XConfigureWindow(dpy, w, CWBorderWidth, &wc);
	XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
	configure(c); /* propagates border_width, if size doesn't change */
	updatesizehints(c);
	XSelectInput(dpy, w,
		StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
	grabbuttons(c, False);
	updatetitle(c);
	if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
		for(t = clients; t && t->win != trans; t = t->next);
	settags(c, t);
	if(!c->isfloating)
		c->isfloating = (rettrans == Success) || c->isfixed;
	attach(c);
	attachstack(c);
	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
	setclientstate(c, IconicState);
	c->isbanned = True;
	focus(c);
	lt->arrange();
}

void
resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
	double dx, dy, max, min, ratio;
	XWindowChanges wc; 
	if(sizehints) {
		if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0) {
			dx = (double)(w - c->basew);
			dy = (double)(h - c->baseh);
			min = (double)(c->minax) / (double)(c->minay);
			max = (double)(c->maxax) / (double)(c->maxay);
			ratio = dx / dy;
			if(max > 0 && min > 0 && ratio > 0) {
				if(ratio < min) {
					dy = (dx * min + dy) / (min * min + 1);
					dx = dy * min;
					w = (int)dx + c->basew;
					h = (int)dy + c->baseh;
				}
				else if(ratio > max) {
					dy = (dx * min + dy) / (max * max + 1);
					dx = dy * min;
					w = (int)dx + c->basew;
					h = (int)dy + c->baseh;
				}
			}
		}
		if(c->minw && w < c->minw)
			w = c->minw;
		if(c->minh && h < c->minh)
			h = c->minh;
		if(c->maxw && w > c->maxw)
			w = c->maxw;
		if(c->maxh && h > c->maxh)
			h = c->maxh;
		if(c->incw)
			w -= (w - c->basew) % c->incw;
		if(c->inch)
			h -= (h - c->baseh) % c->inch;
		if(w <= 0 || h <= 0)
			return;
	}
	/* offscreen appearance fixes */
	if(x > sw)
		x = sw - w - 2 * c->border;
	if(y > sh)
		y = sh - h - 2 * c->border;
	if(x + w + 2 * c->border < sx)
		x = sx;
	if(y + h + 2 * c->border < sy)
		y = sy;
	if(c->x != x || c->y != y || c->w != w || c->h != h) {
		c->x = wc.x = x;
		c->y = wc.y = y;
		c->w = wc.width = w;
		c->h = wc.height = h;
		wc.border_width = c->border;
		XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
		configure(c);
		XSync(dpy, False);
	}
}

void
togglefloating(const char *arg) {
	if(!sel || lt->arrange == floating)
		return;
	sel->isfloating = !sel->isfloating;
	if(sel->isfloating)
		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
	lt->arrange();
}

void
unban(Client *c) {
	if(!c->isbanned)
		return;
	XMapWindow(dpy, c->win);
	setclientstate(c, NormalState);
	c->isbanned = False;
}

void
unmanage(Client *c) {
	XWindowChanges wc;

	wc.border_width = c->oldborder;
	/* The server grab construct avoids race conditions. */
	XGrabServer(dpy);
	XSetErrorHandler(xerrordummy);
	XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */
	detach(c);
	detachstack(c);
	if(sel == c)
		focus(NULL);
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
	setclientstate(c, WithdrawnState);
	free(c->tags);
	free(c);
	XSync(dpy, False);
	XSetErrorHandler(xerror);
	XUngrabServer(dpy);
	lt->arrange();
}

void
updatesizehints(Client *c) {
	long msize;
	XSizeHints size;

	if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
		size.flags = PSize;
	c->flags = size.flags;
	if(c->flags & PBaseSize) {
		c->basew = size.base_width;
		c->baseh = size.base_height;
	}
	else if(c->flags & PMinSize) {
		c->basew = size.min_width;
		c->baseh = size.min_height;
	}
	else
		c->basew = c->baseh = 0;
	if(c->flags & PResizeInc) {
		c->incw = size.width_inc;
		c->inch = size.height_inc;
	}
	else
		c->incw = c->inch = 0;
	if(c->flags & PMaxSize) {
		c->maxw = size.max_width;
		c->maxh = size.max_height;
	}
	else
		c->maxw = c->maxh = 0;
	if(c->flags & PMinSize) {
		c->minw = size.min_width;
		c->minh = size.min_height;
	}
	else if(c->flags & PBaseSize) {
		c->minw = size.base_width;
		c->minh = size.base_height;
	}
	else
		c->minw = c->minh = 0;
	if(c->flags & PAspect) {
		c->minax = size.min_aspect.x;
		c->maxax = size.max_aspect.x;
		c->minay = size.min_aspect.y;
		c->maxay = size.max_aspect.y;
	}
	else
		c->minax = c->maxax = c->minay = c->maxay = 0;
	c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
			&& c->maxw == c->minw && c->maxh == c->minh);
}

void
updatetitle(Client *c) {
	char **list = NULL;
	int n;
	XTextProperty name;

	name.nitems = 0;
	c->name[0] = 0;
	XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
	if(!name.nitems)
		XGetWMName(dpy, c->win, &name);
	if(!name.nitems)
		return;
	if(name.encoding == XA_STRING)
		strncpy(c->name, (char *)name.value, sizeof c->name - 1);
	else {
		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
		&& n > 0 && *list)
		{
			strncpy(c->name, *list, sizeof c->name - 1);
			XFreeStringList(list);
		}
	}
	c->name[sizeof c->name - 1] = '\0';
	XFree(name.value);
}
an>)) else: # no range information available: return elif n.kind in nkCallKinds and n.len == 2 and n[0].kind == nkSym and n[0].sym.magic in {mLengthOpenArray, mLengthStr, mLengthArray, mLengthSeq}: # we know it's a 'len(x)' expression and we seek to teach # Z3 that the result is >= 0 and <= high(int). doAssert n.kind in nkCallKinds doAssert n[0].kind == nkSym doAssert n.len == 2 lowBound = newIntNode(nkInt64Lit, 0) if n.typ != nil: highBound = newIntNode(nkInt64Lit, lastOrd(nil, n.typ)) else: highBound = newIntNode(nkInt64Lit, high(int64)) else: let op = n[0].typ if op != nil and op.n != nil and op.n.len > 0 and op.n[0].kind == nkEffectList and ensuresEffects < op.n[0].len: let ensures = op.n[0][ensuresEffects] if ensures != nil and ensures.kind != nkEmpty: var dummy: seq[PNode] res.add nodeToZ3(c, translateEnsures(ensures, n), dummy) return let x = newTree(nkInfix, newSymNode createMagic(c.graph, "<=", cmpOp), lowBound, n) let y = newTree(nkInfix, newSymNode createMagic(c.graph, "<=", cmpOp), n, highBound) var dummy: seq[PNode] res.add nodeToZ3(c, x, dummy) res.add nodeToZ3(c, y, dummy) proc on_err(ctx: Z3_context, e: Z3_error_code) {.nimcall.} = #writeStackTrace() let msg = $Z3_get_error_msg(ctx, e) raise newException(Z3Exception, msg) proc forall(ctx: Z3_context; vars: seq[Z3_ast]; assumption, body: Z3_ast): Z3_ast = let x = Z3_mk_implies(ctx, assumption, body) if vars.len > 0: var bound: seq[Z3_app] for v in vars: bound.add Z3_to_app(ctx, v) result = Z3_mk_forall_const(ctx, 0, bound.len.cuint, addr(bound[0]), 0, nil, x) else: result = x proc conj(ctx: Z3_context; conds: seq[Z3_ast]): Z3_ast = if conds.len > 0: result = Z3_mk_and(ctx, cuint(conds.len), unsafeAddr conds[0]) else: result = Z3_mk_true(ctx) proc proofEngineAux(c: var DrCon; assumptions: seq[PNode]; toProve: PNode): (bool, string) = c.mapping = initTable[string, Z3_ast]() let cfg = Z3_mk_config() Z3_set_param_value(cfg, "model", "true"); let ctx = Z3_mk_context(cfg) c.z3 = ctx Z3_del_config(cfg) Z3_set_error_handler(ctx, on_err) when false: Z3_set_param_value(cfg, "timeout", "1000") try: #[ For example, let's have these facts: i < 10 i > 0 Question: i + 3 < 13 What we need to produce: forall(i, (i < 10) & (i > 0) -> (i + 3 < 13)) ]# var collectedVars: seq[PNode] let solver = Z3_mk_solver(ctx) var lhs: seq[Z3_ast] for assumption in assumptions: if assumption != nil: try: let za = nodeToZ3(c, assumption, collectedVars) #Z3_solver_assert ctx, solver, za lhs.add za except CannotMapToZ3Error: discard "ignore a fact we cannot map to Z3" let z3toProve = nodeToZ3(c, toProve, collectedVars) for v in collectedVars: addRangeInfo(c, v, lhs) # to make Z3 produce nice counterexamples, we try to prove the # negation of our conjecture and see if it's Z3_L_FALSE let fa = Z3_mk_not(ctx, Z3_mk_implies(ctx, conj(ctx, lhs), z3toProve)) #Z3_mk_not(ctx, forall(ctx, collectedVars, conj(ctx, lhs), z3toProve)) #echo "toProve: ", Z3_ast_to_string(ctx, fa), " ", c.graph.config $ toProve.info Z3_solver_assert ctx, solver, fa let z3res = Z3_solver_check(ctx, solver) result[0] = z3res == Z3_L_FALSE result[1] = "" if not result[0]: let counterex = strip($Z3_model_to_string(ctx, Z3_solver_get_model(ctx, solver))) if counterex.len > 0: result[1].add "; counter example: " & counterex except ValueError: result[0] = false result[1] = getCurrentExceptionMsg() finally: Z3_del_context(ctx) proc proofEngine(graph: ModuleGraph; assumptions: seq[PNode]; toProve: PNode): (bool, string) = var c: DrCon c.graph = graph result = proofEngineAux(c, assumptions, toProve) proc translateReq(r, call: PNode): PNode = if r.kind == nkSym and r.sym.kind == skParam: if r.sym.position+1 < call.len: result = call[r.sym.position+1] else: notImplemented("no argument given for formal parameter: " & r.sym.name.s) else: result = shallowCopy(r) for i in 0 ..< safeLen(r): result[i] = translateReq(r[i], call) proc requirementsCheck(graph: ModuleGraph; assumptions: seq[PNode]; call, requirement: PNode): (bool, string) {.nimcall.} = try: let r = translateReq(requirement, call) result = proofEngine(graph, assumptions, r) except ValueError: result[0] = false result[1] = getCurrentExceptionMsg() proc compatibleProps(graph: ModuleGraph; formal, actual: PType): bool {.nimcall.} = #[ Thoughts on subtyping rules for 'proc' types: proc a(y: int) {.requires: y > 0.} # a is 'weaker' than F # 'requires' must be weaker (or equal) # 'ensures' must be stronger (or equal) # a 'is weaker than' b iff b -> a # a 'is stronger than' b iff a -> b # --> We can use Z3 to compute whether 'var x: T = q' is valid type F = proc (y: int) {.requires: y > 5.} var x: F = a # valid? ]# proc isEmpty(n: PNode): bool {.inline.} = n == nil or n.safeLen == 0 result = true if formal.n != nil and formal.n.len > 0 and formal.n[0].kind == nkEffectList and ensuresEffects < formal.n[0].len: let frequires = formal.n[0][requiresEffects] let fensures = formal.n[0][ensuresEffects] if actual.n != nil and actual.n.len > 0 and actual.n[0].kind == nkEffectList and ensuresEffects < actual.n[0].len: let arequires = actual.n[0][requiresEffects] let aensures = actual.n[0][ensuresEffects] var c: DrCon c.graph = graph c.canonParameterNames = true if not frequires.isEmpty: result = not arequires.isEmpty and proofEngineAux(c, @[frequires], arequires)[0] if result: if not fensures.isEmpty: result = not aensures.isEmpty and proofEngineAux(c, @[aensures], fensures)[0] else: # formal has requirements but 'actual' has none, so make it # incompatible. XXX What if the requirement only mentions that # we already know from the type system? result = frequires.isEmpty and fensures.isEmpty proc mainCommand(graph: ModuleGraph) = let conf = graph.config conf.lastCmdTime = epochTime() graph.proofEngine = proofEngine graph.requirementsCheck = requirementsCheck graph.compatibleProps = compatibleProps graph.config.errorMax = high(int) # do not stop after first error defineSymbol(graph.config.symbols, "nimcheck") defineSymbol(graph.config.symbols, "nimDrNim") registerPass graph, verbosePass registerPass graph, semPass compileProject(graph) if conf.errorCounter == 0: let mem = when declared(system.getMaxMem): formatSize(getMaxMem()) & " peakmem" else: formatSize(getTotalMem()) & " totmem" let loc = $conf.linesCompiled let build = if isDefined(conf, "danger"): "Dangerous Release" elif isDefined(conf, "release"): "Release" else: "Debug" let sec = formatFloat(epochTime() - conf.lastCmdTime, ffDecimal, 3) let project = if optListFullPaths in conf.globalOptions: $conf.projectFull else: $conf.projectName var output = $conf.absOutFile if optListFullPaths notin conf.globalOptions: output = output.AbsoluteFile.extractFilename rawMessage(conf, hintSuccessX, [ "loc", loc, "sec", sec, "mem", mem, "build", build, "project", project, "output", output, ]) proc prependCurDir(f: AbsoluteFile): AbsoluteFile = when defined(unix): if os.isAbsolute(f.string): result = f else: result = AbsoluteFile("./" & f.string) else: result = f proc addCmdPrefix(result: var string, kind: CmdLineKind) = # consider moving this to std/parseopt case kind of cmdLongOption: result.add "--" of cmdShortOption: result.add "-" of cmdArgument, cmdEnd: discard proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) = var p = parseopt.initOptParser(cmd) var argsCount = 1 config.commandLine.setLen 0 config.command = "check" config.cmd = cmdCheck while true: parseopt.next(p) case p.kind of cmdEnd: break of cmdLongOption, cmdShortOption: config.commandLine.add " " config.commandLine.addCmdPrefix p.kind config.commandLine.add p.key.quoteShell # quoteShell to be future proof if p.val.len > 0: config.commandLine.add ':' config.commandLine.add p.val.quoteShell if p.key == " ": p.key = "-" if processArgument(pass, p, argsCount, config): break else: processSwitch(pass, p, config) of cmdArgument: config.commandLine.add " " config.commandLine.add p.key.quoteShell if processArgument(pass, p, argsCount, config): break if pass == passCmd2: if {optRun, optWasNimscript} * config.globalOptions == {} and config.arguments.len > 0 and config.command.normalize notin ["run", "e"]: rawMessage(config, errGenerated, errArgsNeedRunOption) proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = let self = NimProg( supportsStdinFile: true, processCmdLine: processCmdLine, mainCommand: mainCommand ) self.initDefinesProg(conf, "drnim") if paramCount() == 0: helpOnError(conf) return self.processCmdLineAndProjectPath(conf) if not self.loadConfigsAndRunMainCommand(cache, conf): return if conf.hasHint(hintGCStats): echo(GC_getStatistics()) when compileOption("gc", "v2") or compileOption("gc", "refc"): # the new correct mark&sweep collector is too slow :-/ GC_disableMarkAndSweep() when not defined(selftest): let conf = newConfigRef() handleCmdLine(newIdentCache(), conf) when declared(GC_setMaxPause): echo GC_getStatistics() msgQuit(int8(conf.errorCounter > 0))