Commit ca6ffa975ae3ba107e1e9bf6e0c7fdfba3559450

Thomas de Grivel 2018-07-02T16:14:04

rewrite without iterate

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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
diff --git a/adams.asd b/adams.asd
index 148dee1..342f41d 100644
--- a/adams.asd
+++ b/adams.asd
@@ -33,7 +33,6 @@
 	       "cl-ppcre"
 	       "closer-mop"
 	       "ironclad"
-	       "iterate"
                "parse-number"
 	       "re"
 	       "str"
diff --git a/core/defs.lisp b/core/defs.lisp
index 2fcc89a..08d2714 100644
--- a/core/defs.lisp
+++ b/core/defs.lisp
@@ -245,16 +245,6 @@
 ;;  Operators on property lists
 
 (defmacro remf* (place indicator)
-  `(iter (while (remf ,place ,indicator))
-         (counting t)))
-
-(iterate:defmacro-clause (for* vars in list)
-  (let ((l (gensym "LIST-")))
-    `(progn
-       (with ,l = ,list)
-       (while ,l)
-       ,@(iter (for var in vars)
-               (collect `(for ,var = (if ,l
-                                         (pop ,l)
-                                         (error "~S is not congruent to ~S"
-                                                ',list ',vars))))))))
+  `(loop
+      (unless (remf ,place ,indicator)
+        (return))))
diff --git a/core/host.lisp b/core/host.lisp
index e3081be..bb895b5 100644
--- a/core/host.lisp
+++ b/core/host.lisp
@@ -149,9 +149,9 @@
   (cons :hostname (run "hostname")))
 
 (defmethod probe-boot-time ((host host) (os os-unix))
-  (iter (uptime<1> (time uptime users load1 load5 load15) in (run "uptime"))
-        (return (list :boot-time (chronicity:parse
-                                  (str uptime " seconds ago"))))))
+  (with-uptime<1> (time uptime users load1 load5 load15) (run "uptime")
+    (return (list :boot-time (chronicity:parse
+                              (str uptime " seconds ago"))))))
 
 (defmethod probe-host-user ((host host) (os os-unix))
   (list :user (first (run "whoami"))))
diff --git a/core/operation.lisp b/core/operation.lisp
index 5c8bff4..67478ff 100644
--- a/core/operation.lisp
+++ b/core/operation.lisp
@@ -38,14 +38,19 @@
   'operation)
 
 (defmethod compute-operations ((rc resource-class))
-  (iter (for class in (closer-mop:class-precedence-list rc))
-        (for direct-ops = (when (typep class 'resource-class)
-                            (direct-operations class)))
-	(dolist (op-definition direct-ops)
-	  (collect (apply #'make-instance
-			  (operation-class rc)
-			  :name
-                          op-definition)))))
+  (let ((class-precedence-list (closer-mop:class-precedence-list rc))
+        (ops))
+    (loop
+       (when (endp class-precedence-list)
+         (return))
+       (let* ((class (pop class-precedence-list))
+              (direct-ops (when (typep class 'resource-class)
+                            (direct-operations class))))
+         (dolist (op-definition direct-ops)
+           (let ((op (apply #'make-instance (operation-class rc)
+                            :name op-definition)))
+             (push op ops)))))
+    (nreverse ops)))
 
 (defmethod operation-properties ((rc resource-class))
   (let ((properties nil))
@@ -73,13 +78,22 @@
         (operations-of r)))
 
 (defmethod list-operations (res plist os)
-  (iter (for* (property value) in plist)
-        (adjoining (or (find-operation res property os)
-                       (error 'resource-operation-not-found
-                              :resource res
-                              :property property
-                              :host (current-host)
-                              :os os)))))
+  (let (operations)
+    (loop
+       (when (endp plist)
+         (return))
+       (let* ((property (pop plist))
+              (value (pop plist))
+              (op (find-operation res property os)))
+         (declare (ignore value))
+         (unless op
+           (error 'resource-operation-not-found
+                  :resource res
+                  :property property
+                  :host (current-host)
+                  :os os))
+         (push op operations)))
+    (nreverse operations)))
 
 (defun sort-operations (operations)
   (sort operations (lambda (op1 op2)
@@ -88,10 +102,14 @@
 (defmethod operate ((res resource) (plist list))
   (let* ((os (host-os (current-host)))
          (operations (list-operations res plist os))
-         (sorted-ops (sort-operations operations)))
-    (iter (for op in sorted-ops)
-          (collect (apply (operation-generic-function op)
-                          res os plist)))))
+         (sorted-ops (sort-operations operations))
+         (results))
+    (loop
+       (let* ((op (pop sorted-ops))
+              (result (apply (operation-generic-function op)
+                             res os plist)))
+         (push result results)))
+    (nreverse results)))
 
 ;;  Conditions
 
diff --git a/core/probe.lisp b/core/probe.lisp
index 91841f0..2468083 100644
--- a/core/probe.lisp
+++ b/core/probe.lisp
@@ -35,14 +35,19 @@
   'probe)
 
 (defmethod compute-probes ((rc resource-class))
-  (iter (for class in (closer-mop:class-precedence-list rc))
-        (for direct-probes = (when (typep class 'resource-class)
-			       (direct-probes class)))
-	(dolist (probe-definition direct-probes)
-	  (collect (apply #'make-instance
-			  (probe-class rc)
-			  :name
-                          probe-definition)))))
+  (let ((class-precedence-list (closer-mop:class-precedence-list rc))
+        (probes))
+    (loop
+       (when (endp class-precedence-list)
+         (return))
+       (let* ((class (pop class-precedence-list))
+              (direct-probes (when (typep class 'resource-class)
+                               (direct-probes class))))
+         (dolist (probe-definition direct-probes)
+           (let ((probe (apply #'make-instance (probe-class rc)
+                               :name probe-definition)))
+             (push probe probes)))))
+    (nreverse probes)))
 
 (defmethod probe-properties ((rc resource-class))
   (let ((properties nil))
diff --git a/core/properties.lisp b/core/properties.lisp
index 2be489f..c30dd3b 100644
--- a/core/properties.lisp
+++ b/core/properties.lisp
@@ -27,9 +27,15 @@
   (when (and (consp (first vars))
              (endp (rest vars)))
     (setq vars (first vars)))
-  `(list ,@(iter (for v in vars)
-                 (collect (make-keyword v))
-                 (collect v))))
+  (let ((properties))
+    (loop
+       (when (endp vars)
+         (return))
+       (let ((v (pop vars)))
+         (push (make-keyword v) properties)
+         (push v properties)))
+    (cons 'list
+          (nreverse properties))))
 
 (defmacro values* (&rest vars)
   (when (and (consp (first vars))
@@ -41,11 +47,16 @@
   `(getf ,properties ,property +undefined+))
 
 (defun get-properties (keys properties)
-  (iter (for k in keys)
-        (for v = (get-property k properties))
-        (unless (eq v +undefined+)
-          (collect k)
-          (collect v))))
+  (let ((plist))
+    (loop
+       (when (endp keys)
+         (return))
+       (let* ((k (pop keys))
+              (v (get-property k properties)))
+         (unless (eq v +undefined+)
+           (push v plist)
+           (push k plist))))
+    (nreverse plist)))
 
 (defmethod compare-property-values (resource property value1 value2)
   (equalp value1 value2))
@@ -75,16 +86,18 @@ Keeping old value by default."
 (defun merge-properties (resource &rest properties)
   (let* ((result (cons nil nil))
          (tail result))
-    (dolist (p properties)
-      (iter
-        (for* (key val) in p)
-        (let ((result-val (getf (cdr result) key +undefined+)))
-          (cond ((eq result-val +undefined+)
-                 (setf (cdr tail) (list key val)
-                       tail (cddr tail)))
-                ((not (equalp result-val val))
-                 (setf (getf (cdr result) key)
-                       (merge-property-values resource key result-val val)))))))
+    (loop
+       (when (endp properties)
+         (return))
+       (let* ((key (pop properties))
+              (val (pop properties))
+              (result-val (getf (cdr result) key +undefined+)))
+         (cond ((eq result-val +undefined+)
+                (setf (cdr tail) (list key val)
+                      tail (cddr tail)))
+               ((not (equalp result-val val))
+                (setf (getf (cdr result) key)
+                      (merge-property-values resource key result-val val))))))
     (cdr result)))
 
 (let ((p ()))
diff --git a/core/resource-container.lisp b/core/resource-container.lisp
index 7a343af..008f6f4 100644
--- a/core/resource-container.lisp
+++ b/core/resource-container.lisp
@@ -46,14 +46,18 @@
 		      parent)
 	child))
 
-(iterate:defmacro-clause (for-resource var in container)
+(defmacro do-resources ((var) container &body body)
   (let ((x (gensym)))
-    `(for (,x ,var) in-hashtable (resource-registry ,container))))
+    `(maphash (lambda (,x ,var)
+                (declare (ignore ,x))
+                ,@body)
+              (resource-registry ,container))))
 
 (defmethod child-resources ((res resource-container))
-  (sort (iter (for-resource child in res)
-              (collect child))
-        #'resource-before-p))
+  (let ((resources))
+    (do-resources (child) res
+      (push child resources))
+    (sort resources #'resource-before-p)))
 
 ;;  Resource container
 
diff --git a/core/resource.lisp b/core/resource.lisp
index 7bc9597..c808f3b 100644
--- a/core/resource.lisp
+++ b/core/resource.lisp
@@ -74,13 +74,18 @@
 
 (defun pprint-plist (plist &optional (stream *standard-output*))
   (pprint-logical-block (stream plist)
-    (iter (for* (k v) in plist)
-          (for first-line-p initially t then nil)
-          (unless first-line-p
-            (pprint-newline :mandatory stream))
-          (write k :stream stream)
-          (write-char #\Space stream)
-          (write v :stream stream))))
+    (let ((first-line-p t))
+      (loop
+         (when (endp plist)
+           (return))
+         (let ((k (pop plist))
+               (v (pop plist)))
+           (unless first-line-p
+             (pprint-newline :mandatory stream))
+           (setq first-line-p nil)
+           (write k :stream stream)
+           (write-char #\Space stream)
+           (write v :stream stream))))))
 
 #+nil
 (pprint-plist '(:a "aaa" :b "foo" :xyz "bar"))
@@ -102,17 +107,28 @@
       (mapcar #'resource-id value)
       value))
 
+(defun plist-keys (plist)
+  (let ((keys))
+    (loop
+       (when (endp plist)
+         (return))
+       (let ((key (pop plist))
+             (value (pop plist)))
+         (declare (ignore value))
+         (push key keys)))
+    keys))
+
+(declaim (ftype (function (list) list) plist-keys))
+
 (defmethod describe-probed% ((res resource) (out (eql :form)))
   (let* ((props (probe-all-properties res))
-         (sorted-keys (sort (iter (for* (k v) in props)
-                                  (collect k))
-                            #'string<))
-         (sorted-props (iter (for key in sorted-keys)
-                             (for value = (describe-probed-property-value
-                                           res key (get-property key props)))
-                             (when value
-                               (collect key)
-                               (collect value)))))
+         (sorted-keys (sort (plist-keys props) #'string<))
+         (sorted-props (mapcan (lambda (key)
+                                 (let ((value (describe-probed-property-value
+                                               res key (get-property key props))))
+                                   (when value
+                                     (list key value))))
+                                sorted-keys)))
     `(resource ',(class-name (class-of res))
                ,(resource-id res)
                ,@sorted-props)))
@@ -147,6 +163,25 @@
 
 ;;  Sync
 
+(defun sync-op (host res op op-keys op-plist os)
+  (let ((failed))
+    (dolist (property op-keys)
+      (let ((specified (get-property property op-plist)))
+        (when (not (eq specified +undefined+))
+          (let* ((probed (get-probed res property))
+                 (desc (describe-probed-property-value res property
+                                                       probed)))
+            (unless (match-specified-value res property specified desc)
+              (push (list property specified desc) failed))))))
+    (setq failed (nreverse failed))
+    (when failed
+      (error 'resource-operation-failed
+             :diff failed
+             :operation op
+             :os os
+             :host host
+             :resource res))))
+
 (defmethod sync ((res resource))
   (when-let ((diff (resource-diff res)))
     (let* ((plist (resource-diff-to-plist diff))
@@ -154,37 +189,26 @@
            (os (host-os host))
            (ops (list-operations res plist os))
            (sorted-ops (sort-operations ops)))
-      (iter (for op in sorted-ops)
-            (for op-keys = (operation-properties op))
-            (for op-plist = (get-properties op-keys plist))
-            (apply (operation-generic-function op)
-                   res os op-plist)
-            (clear-probed res op-keys)
-            (for failed = (iter (for property in op-keys)
-                                (for specified = (get-property property
-                                                               op-plist))
-                                (when (not (eq specified +undefined+))
-                                  (for probed = (get-probed res property))
-                                  (for desc = (describe-probed-property-value
-                                               res property probed))
-                                  (unless (match-specified-value
-                                           res property specified desc)
-                                    (collect property)
-                                    (collect specified)
-                                    (collect desc)))))
-            (when failed
-              (error 'resource-operation-failed
-                     :diff failed
-                     :operation op
-                     :os os
-                     :host host
-                     :resource res))))))
+      (loop
+         (when (endp sorted-ops)
+           (return))
+         (let* ((op (pop sorted-ops))
+                (op-keys (operation-properties op))
+                (op-plist (get-properties op-keys plist))
+                (op-fun (operation-generic-function op)))
+           (apply op-fun res os op-plist)
+           (clear-probed res op-keys)
+           (sync-op host res op op-keys op-plist os))))))
 
 (defmethod sync ((res resource-container))
   (call-next-method)
   (with-parent-resource res
-    (iter (for child in (child-resources res))
-          (sync child))))
+    (let ((child-resources (child-resources res)))
+      (loop
+         (when (endp child-resources)
+           (return))
+         (let ((child (pop child-resources)))
+           (sync child))))))
 
 (defmethod sync ((host host))
   (with-host host
diff --git a/core/spec.lisp b/core/spec.lisp
index 082c5fa..7782432 100644
--- a/core/spec.lisp
+++ b/core/spec.lisp
@@ -52,14 +52,15 @@
   res)
 
 (defmethod parse-specification ((res resource) (spec cons))
-  (iter (while spec)
-	(for next-spec = (parse-next-specification res spec))
-	(when (eq spec next-spec)
-	  (error "Invalid specification : ~S" spec))
-	(setq spec next-spec))
+  (loop
+     (when (endp spec)
+       (return))
+     (let ((next-spec (parse-next-specification res spec)))
+       (when (eq spec next-spec)
+         (error "Invalid specification : ~S" spec))
+       (setq spec next-spec)))
   res)
 
-
 #+nil
 (parse-specification *localhost*
                      '(:hostname "arrakis.lowh.net"))
@@ -115,33 +116,45 @@ Second value lists properties in line with spec. Format is
   (PROPERTY-NAME VALUE)"))
 
 (defmethod resource-diff ((res resource))
-  (iter (for* (property specified) in (specified-properties res))
-        (for probed = (get-probed res property))
-        (for desc = (describe-probed-property-value res property probed))
-        (if (match-specified-value res property specified desc)
-            (collect `(,property ,specified) into ok)
-            (collect `(,property ,specified ,desc) into diff))
-        (finally (return diff))))
+  (let ((specified-properties (specified-properties res))
+        ok diff)
+    (loop
+       (when (endp specified-properties)
+         (return))
+       (let* ((sp (pop specified-properties))
+              (property (first sp))
+              (specified (second sp))
+              (probed (get-probed res property))
+              (desc (describe-probed-property-value res property probed)))
+         (if (match-specified-value res property specified desc)
+             (push sp ok)
+             (push `(,property ,specified ,desc) diff))))
+    diff))
 
 #+nil
 (resource-diff (resource 'directory "/" :owner "root" :uid 0))
 
 (defmethod resource-diff ((res resource-container))
-  (append (call-next-method res)
-          (sort (iter (for-resource r in res)
-                      (for d = (resource-diff r))
-                      (when d
-                        (collect (cons r d))))
-                #'resource-before-p
-                :key #'first)))
+  (let ((diffs))
+    (do-resources (r) res
+      (let ((d (resource-diff r)))
+        (when d
+          (push (cons r d) diffs))))
+    (append (call-next-method res)
+            (sort diffs #'resource-before-p :key #'first))))
 
 (defmethod resource-diff ((host host))
   (with-host host
     (call-next-method)))
 
 (defun resource-diff-to-plist (diff)
-  (iter (for item in diff)
-        (for key = (first item))
-        (when (keywordp key)
-          (collect key)
-          (collect (second item)))))
+  (let ((plist))
+    (loop
+       (when (endp diff)
+         (return))
+       (let* ((item (pop diff))
+              (key (first item)))
+         (when (keywordp key)
+           (push (second item) plist)
+           (push key plist))))
+    (nreverse plist)))
diff --git a/core/syntaxes.lisp b/core/syntaxes.lisp
index c79f298..24269cb 100644
--- a/core/syntaxes.lisp
+++ b/core/syntaxes.lisp
@@ -22,36 +22,52 @@
 
 ;;  Simple regexp-based parser generator with ITERATE support
 
-(defmacro define-syntax (name vars re &body body)
-  (let ((parse-name (sym 'parse- name))
-	(doc (when (stringp (first body)) (pop body)))
-	(values (or (first (last body))
-		    `(values ,@(iter (for spec in vars)
-				     (if (consp spec)
-					 (dolist (var (cdr spec))
-					   (collect var))
-					 (collect spec)))))))
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defun collect-vars (specs)
+    (let ((vars))
+      (dolist (spec specs)
+        (if (consp spec)
+            (dolist (var (rest spec))
+              (push var vars))
+            (push spec vars)))
+      (nreverse vars))))
+
+(defmacro define-syntax (name specs re &body body)
+  (let* ((parse-name (sym 'parse- name))
+         (with-name (sym 'with- name))
+         (doc (when (stringp (first body)) (pop body)))
+         (vars (collect-vars specs))
+         (values (or (first (last body)) `(values ,@vars))))
     `(progn
        (defun ,parse-name (line)
 	 ,@(when doc (list doc))
+         (declare (type string line))
 	 (re-bind ,re ,vars line
 	   ,@(or body `(,values))))
-       (iterate:defmacro-clause (,name iter-vars in lines)
+       (defmacro ,with-name ((,@vars) lines &body with-body)
 	 ,@(when doc (list doc))
-	 (let ((line (gensym ,(format nil "~A-LINE-" (symbol-name name)))))
-	   `(progn (for ,line in ,lines)
-		   (for (values ,@iter-vars) = (,',parse-name ,line))))))))
+         `(dolist (line ,lines)
+            (declare (type string line))
+            (multiple-value-bind (,,@vars) (,',parse-name line)
+              (declare (ignorable ,,@vars))
+              ,@with-body))))))
 
 ;;  Host
 
 (defun parse-uptime (string)
-  (or (re-bind #~|^\s*([0-9]+ days,\s*)?([0-9]+):([0-9]+)\s*$| (d h m) string
-        (* 60 (+ (parse-integer m)
-                 (* 60
-                    (+ (parse-integer h)
-                       (if d
-                           (* 24 (parse-integer d :junk-allowed t))
-                           0))))))
+  (or (re-bind #~|^\s*([0-9]+ days,\s*)?([0-9]+):([0-9]+)\s*$|
+          (d h m) string
+        (let* ((im (if m (parse-integer m) 0))
+               (ih (if h (parse-integer h) 0))
+               (id (if d (parse-integer d :junk-allowed t) 0))
+               (id-hours (* 24 id))
+               (hours (+ ih id-hours))
+               (hours-minutes (* 60 hours))
+               (minutes (+ im hours-minutes))
+               (seconds (* 60 minutes)))
+          (declare (type fixnum im ih id id-hours hours
+                         hours-minutes minutes seconds))
+          seconds))
       (error "Invalid uptime ?")))
 
 (define-syntax uptime<1> ((#'chronicity:parse time)
diff --git a/unix/defs.lisp b/unix/defs.lisp
index 3ede6ef..38f4a11 100644
--- a/unix/defs.lisp
+++ b/unix/defs.lisp
@@ -76,9 +76,12 @@
 (define-resource-class file (vnode)
   ()
   ((probe-file-content :properties (:content))
-   . #.(iter (for algorithm in *cksum-algorithms*)
-	     (collect `(,(sym 'probe-file-cksum- algorithm)
-			 :properties (,algorithm))))))
+   . #.(let ((algorithms))
+         (dolist (algorithm *cksum-algorithms*)
+           (push `(,(sym 'probe-file-cksum- algorithm)
+                    :properties (,algorithm))
+                 algorithms))
+         (nreverse algorithms))))
 
 (defgeneric probe-file-content (resource os))
 
diff --git a/unix/freebsd.lisp b/unix/freebsd.lisp
index 8b3becd..8d18dad 100644
--- a/unix/freebsd.lisp
+++ b/unix/freebsd.lisp
@@ -22,9 +22,9 @@
 
 (defun get-sh-var (name file)
   (let (value)
-    (iter (sh-var (var val) in (egrep (str "^" name "=") file))
-          (when (string= name var)
-            (setq value val)))
+    (with-sh-var (var val) (egrep (str "^" name "=") file)
+      (when (string= name var)
+        (setq value val)))
     value))
 
 (defsetf get-sh-var (name file) (value)
@@ -96,14 +96,15 @@
     #~|^([-_0-9A-Za-z]+)-([_.,0-9A-Za-z]+)\s+([=<>?!])$|)
 
 (defmethod probe-host-packages ((host host) (os os-freebsd))
-  (properties :packages (iter (freebsd-pkg-version<8> (name version ensure)
-                                                      in (run "pkg version"))
-                              (when (and name version ensure)
-                                (let ((pkg (resource 'freebsd-pkg name))
-                                      (versions (list version)))
-                                  (add-probed-properties pkg (properties*
-                                                              versions ensure))
-                                  (collect pkg))))))
+  (let ((packages))
+    (with-freebsd-pkg-version<8> (name version ensure)
+        (run "pkg version")
+      (when (and name version ensure)
+        (let ((pkg (resource 'freebsd-pkg name))
+              (versions (list version)))
+          (add-probed-properties pkg (properties* versions ensure))
+          (push pkg packages))))
+    (properties :packages (nreverse packages))))
 
 (define-resource-class freebsd-pkg (pkg)
   ()
@@ -114,12 +115,11 @@
   (let ((id (resource-id pkg))
         (ensure :absent)
         versions)
-    (iter (freebsd-pkg-version<8> (name ver status) in
-                                  (run "pkg version | egrep ^"
-                                       (sh-quote id) "-"))
-          (when (equal id name)
-            (setq ensure status)
-            (push ver versions)))
+    (with-freebsd-pkg-version<8> (name ver status)
+        (run "pkg version | egrep ^" (sh-quote id) "-")
+      (when (equal id name)
+        (setq ensure status)
+        (push ver versions)))
     (properties* ensure versions)))
 
 (defmethod op-freebsd-pkg ((pkg freebsd-pkg) (os os-freebsd)
diff --git a/unix/openbsd.lisp b/unix/openbsd.lisp
index c045ea1..2aae430 100644
--- a/unix/openbsd.lisp
+++ b/unix/openbsd.lisp
@@ -33,12 +33,12 @@
 
 (defmethod probe-openbsd-pkg ((pkg openbsd-pkg) (os os-openbsd))
   (let ((id (resource-id pkg)))
-    (multiple-value-bind #1=(versions)
-      (iter (pkg_info<1> (name versions) in
-                         (run "pkg_info | egrep ~A" (sh-quote (str "^" id "-"))))
-            (when (string= id name)
-              (return (values* #1#))))
-      (properties* #1#))))
+    (multiple-value-bind (versions)
+      (with-pkg_info<1> (name versions)
+          (run "pkg_info | egrep ~A" (sh-quote (str "^" id "-")))
+        (when (string= id name)
+          (return (values versions))))
+      (properties* versions))))
 
 (defmethod merge-property-values ((pkg openbsd-pkg)
                                   (property (eql :versions))
@@ -49,11 +49,12 @@
 
 (defmethod probe-installed-packages% ((host host) (os os-openbsd))
   (with-host host
-    (iter (pkg_info<1> #1=(name versions flavors)
-                       in (run "pkg_info"))
-          (for pkg = (resource 'openbsd-pkg name))
-          (add-probed-properties pkg (properties* #1#))
-          (adjoining pkg))))
+    (let ((packages))
+      (with-pkg_info<1> (name versions) (run "pkg_info")
+        (let ((pkg (resource 'openbsd-pkg name)))
+          (add-probed-properties pkg (properties* name versions))
+          (push pkg packages)))
+      (nreverse packages))))
 
 (defun probe-installed-packages (&optional (host (current-host)))
   (probe-installed-packages% host (host-os host)))
diff --git a/unix/probes.lisp b/unix/probes.lisp
index ed3793f..a1b3beb 100644
--- a/unix/probes.lisp
+++ b/unix/probes.lisp
@@ -24,12 +24,12 @@
   (let ((id (resource-id group))
         (ensure :absent))
     (multiple-value-bind #1=(name passwd gid members)
-      (iter (group<5> #1# in (grep (str id) "/etc/group"))
-            (when (etypecase id
-                    (integer (= id gid))
-                    (string (string= id name)))
-              (setq ensure nil)
-              (return (values* #1#))))
+        (with-group<5> #1# (grep (str id) "/etc/group")
+          (when (etypecase id
+                  (integer (= id gid))
+                  (string (string= id name)))
+            (setq ensure nil)
+            (return (values* #1#))))
       (properties* (ensure . #1#)))))
 
 ;;  User
@@ -38,17 +38,17 @@
   (let ((id (resource-id user))
         (ensure :absent))
     (multiple-value-bind #1=(login pass uid gid realname home shell)
-      (iter (passwd<5> #1# in
-                       (etypecase id
-                         (integer (grep (str #\: id #\:) "/etc/passwd"))
-                         (string (egrep (str #\^ id #\:) "/etc/passwd"))))
-            (when (etypecase id
-                    (string (string= id login))
-                    (integer (= id uid)))
-              (setq ensure nil
-                    home (resource 'directory home)
-                    shell (resource 'file shell))
-              (return (values* #1#))))
+      (with-passwd<5> #1#
+          (etypecase id
+            (integer (grep (str #\: id #\:) "/etc/passwd"))
+            (string (egrep (str #\^ id #\:) "/etc/passwd")))
+        (when (etypecase id
+                (string (string= id login))
+                (integer (= id uid)))
+          (setq ensure nil
+                home (resource 'directory home)
+                shell (resource 'file shell))
+          (return (values* #1#))))
       (properties* (ensure . #1#)))))
 
 (defmethod probe-user-groups-in-/etc/group ((user user) (os os-unix))
@@ -60,13 +60,13 @@
                              (get-probed user :login)))
              (user-gid (get-probed user :gid))
              (user-group nil))
-        (setq groups (iter (group<5> (name passwd gid members)
-                                     in (grep user-login "/etc/group"))
-                           (cond ((= user-gid gid)
-                                  (setq user-group (resource 'group name)))
-                                 ((find user-login members :test #'string=)
-                                  (collect (resource 'group name)))))
-              groups (sort groups #'string< :key #'resource-id)
+        (with-group<5> (name passwd gid members)
+            (grep user-login "/etc/group")
+          (cond ((= user-gid gid)
+                 (setq user-group (resource 'group name)))
+                ((find user-login members :test #'string=)
+                 (push (resource 'group name) groups))))
+        (setq groups (sort groups #'string< :key #'resource-id)
               groups (if user-group
                          (cons user-group groups)
                          groups))))
@@ -77,53 +77,60 @@
 (defmethod probe-vnode-using-ls ((vnode vnode) (os os-unix))
   (let ((id (resource-id vnode)))
     (multiple-value-bind #1=(mode links owner group size mtime)
-      (iter (ls<1>-lT #.(cons 'name '#1#)
-                      in (ls "-ldT" id))
-            (when (string= id name)
-              (setq mode (mode (mode-permissions mode))
-                    owner (resource 'user owner)
-                    group (resource 'group group))
-              (return (values* #1#))))
+        (with-ls<1>-lT #.(cons 'name '#1#)
+            (ls "-ldT" id)
+          (when (string= id name)
+            (setq mode (mode (mode-permissions mode))
+                  owner (resource 'user owner)
+                  group (resource 'group group))
+            (return (values* #1#))))
       (properties* #1#))))
 
 (defmethod probe-vnode-using-stat ((vnode vnode) (os os-unix))
   (let ((id (resource-id vnode)))
     (multiple-value-bind #1=(dev ino mode links uid gid rdev size
                                  atime mtime ctime blksize blocks flags)
-      (iter (stat<1>-r #.(cons 'name '#1#)
-                       in (stat "-r" id))
-            (when (string= id name)
-              (setq mode (mode (mode-permissions mode)))
-              (return (values* #1#))))
-      (properties* #1#))))
+        (with-stat<1>-r #.(cons 'name '#1#)
+            (stat "-r" id)
+          (when (string= id name)
+            (setq mode (mode (mode-permissions mode)))
+            (return (values* #1#))))
+        (properties* #1#))))
 
 ;;  Regular file
 
-#.(cons 'progn
-	(iter (for algorithm in *cksum-algorithms*)
-	      (for name = (sym 'probe-file-cksum- algorithm))
-              (for legacy = (member algorithm *cksum-legacy-algorithms*))
-              (for iterator = (if legacy
-                                  'cksum<1>-legacy
-                                  'cksum<1>))
-              (for vars = (if legacy
-                              '(sum size name)
-                              '(algo name sum)))
-              (for cmd = (str "cksum -a " algorithm " "))
-              (for match-p = (if legacy
-                                 `(string= id name)
-                                 `(and (string= ,algorithm algo)
-                                       (string= id name))))
-              (for var = (sym algorithm))
-	      (collect `(defgeneric ,name (file os)))
-	      (collect `(defmethod ,name ((file file) (os os-unix))
-			  (let* ((id (resource-id file))
-                                 (,var (iter (,iterator ,vars
-                                                        in (run ,cmd
-                                                                (sh-quote id)))
-                                             (when ,match-p
-                                               (return sum)))))
-                            (properties* ,var))))))
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defparameter *cksum-defs* nil))
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (defun cksum-defs ()
+    (dolist (algorithm *cksum-algorithms*)
+      (declare (type symbol algorithm))
+      (let* ((name (sym 'probe-file-cksum- algorithm))
+             (legacy (member algorithm *cksum-legacy-algorithms*))
+             (iterator (if legacy 'with-cksum<1>-legacy
+                           'with-cksum<1>))
+             (vars (if legacy '(sum size name) '(algo name sum)))
+             (cmd (str "cksum -a " algorithm " "))
+             (match-p (if legacy
+                          `(string= id name)
+                          `(and (string= ,algorithm algo)
+                                (string= id name))))
+             (var (sym algorithm)))
+        (push `(defmethod ,name ((file file) (os os-unix))
+                 (let* ((id (resource-id file))
+                        (,var (,iterator ,vars
+                                         (run ,cmd (sh-quote id)))
+                          (when ,match-p
+                            (return sum))))
+                   (properties* ,var)))
+              *cksum-defs*)
+        (push `(defgeneric ,name (file os)) *cksum-defs*)))
+    (setf *cksum-defs* (nreverse *cksum-defs*))
+    (push 'progn *cksum-defs*)))
+
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  #.(cksum-defs))
 
 (defmethod probe-file-content ((file file) (os os-unix))
   (let* ((size (get-probed file :size))
@@ -147,12 +154,11 @@
 (defmethod probe-mount ((m mount) (os os-unix))
   (let ((id (resource-id m)))
     (multiple-value-bind (dev mp fstype options)
-        (iter (mount<8> (dev mp fstype options)
-                        in (run "mount | grep "
-                                (sh-quote (str id " "))))
-              (when (or (string= id dev)
-                        (string= id mp))
-                (return (values dev mp fstype options))))
+        (with-mount<8> (dev mp fstype options)
+            (run "mount | grep " (sh-quote (str id " ")))
+          (when (or (string= id dev)
+                    (string= id mp))
+            (return (values dev mp fstype options))))
       (properties :mounted-device dev
                   :mounted-mount-point mp
                   :mounted-fstype fstype
@@ -161,13 +167,11 @@
 (defmethod probe-fstab ((m mount) (os os-unix))
   (let ((id (resource-id m)))
     (multiple-value-bind (dev mp fstype options freq passno)
-        (iter (fstab<5> (dev mp fstype options freq passno)
-                        in (run "grep "
-                                (sh-quote (str id " "))
-                                " /etc/fstab"))
-              (when (or (string= id dev)
-                        (string= id mp))
-                (return (values dev mp fstype options freq passno))))
+        (with-fstab<5> (dev mp fstype options freq passno)
+            (run "grep " (sh-quote (str id " ")) " /etc/fstab")
+          (when (or (string= id dev)
+                    (string= id mp))
+            (return (values dev mp fstype options freq passno))))
       (properties :fstab-device dev
                   :fstab-mount-point mp
                   :fstab-fstype fstype
@@ -183,16 +187,16 @@
 (defmethod probe-ps-auxww ((process process) (os os-unix))
   (let ((id (resource-id process)))
     (multiple-value-bind #1=(user pid cpu mem vsz rss tt state start time cmd)
-        (iter (ps<1>-u #1# in (run "ps auxww | grep " (sh-quote id)))
-              (print #.(cons 'list '#1#))
-              (when (typecase id
-                      (integer (= id pid))
-                      (string (and (<= (length id) (length cmd))
-                                   (string= id cmd :end2 (length id))
-                                   (or (= (length id) (length cmd))
-                                       (char= #\Space (char cmd (length id)))))))
-                (return (values* #1#))))
-      (properties* #1#))))
+        (with-ps<1>-u #1# (run "ps auxww | grep " (sh-quote id))
+          (print #.(cons 'list '#1#))
+          (when (typecase id
+                  (integer (= id pid))
+                  (string (and (<= (length id) (length cmd))
+                               (string= id cmd :end2 (length id))
+                               (or (= (length id) (length cmd))
+                                   (char= #\Space (char cmd (length id)))))))
+            (return (values* #1#))))
+        (properties* #1#))))
 
 #+nil
 (probe-all-properties (resource 'process "svscan"))
diff --git a/unix/syntaxes.lisp b/unix/syntaxes.lisp
index 8dd14a8..24d077e 100644
--- a/unix/syntaxes.lisp
+++ b/unix/syntaxes.lisp
@@ -73,13 +73,19 @@
   "Syntax for /etc/fstab, see fstab(5)."
   (values device mp type
           (re-matches #~|[^,]+| options)
-          (parse-integer freq)
-          (parse-integer passno)))
+          (when freq (parse-integer freq))
+          (when passno (parse-integer passno))))
 
 (defun parse-ps-time (string)
   (or (re-bind #~|^\s*([0-9]+):([0-9]*\.[0-9]*)$| (d h) string
-        (+ (* 3600 24 (the non-negative-fixnum (parse-integer d)))
-           (truncate (* 3600 (parse-number h)))))
+        (let* ((id (if d (parse-integer d) 0))
+               (nh (if h (parse-number h) 0))
+               (id-sec (* 3600 24 id))
+               (nh-sec (* 3600 nh))
+               (ih-sec (truncate nh-sec))
+               (sec (+ id-sec ih-sec)))
+          (declare (type fixnum id nh id-sec nh-sec sec))
+          sec))
       (error "Invalid ps(1) time ?")))
 
 (define-syntax ps<1>-u (user
@@ -107,28 +113,25 @@
   (find char +sh-word-delimiters+ :test #'eq))
 
 (defun parse-sh-var-value (string)
+  (declare (type string string))
   (with-output-to-string (out)
-    (iter (with quote = nil)
-          (with backslash = nil)
-          (for i below (length string))
-          (for c = (char string i))
-          (cond
-            (backslash
-             (setq backslash nil)
-             (write-char c out))
-            ((and (eq #\\ c) (not (eq #\' quote)))
-             (setq backslash t))
-            ((eq quote c)
-             (setq quote nil))
-            ((and (null quote) (or (eq #\" c) (eq #\' c)))
-             (setq quote c))
-            ((and (null quote) (sh-word-delimiter-p c))
-             (finish))
-            (:otherwise
-             (write-char c out)))
-          (finally
-           (when (or quote backslash)
-             (error "Unmatched quote"))))))
+    (let ((quote)
+          (backslash)
+          (i 0))
+      (declare (type fixnum i))
+      (loop
+         (unless (< i (length string))
+           (return))
+         (let ((c (char string i)))
+           (cond
+             (backslash (setq backslash nil) (write-char c out))
+             ((and (eq #\\ c) (not (eq #\' quote))) (setq backslash t))
+             ((eq quote c) (setq quote nil))
+             ((and (null quote) (or (eq #\" c) (eq #\' c))) (setq quote c))
+             ((and (null quote) (sh-word-delimiter-p c)) (return))
+             (:otherwise (write-char c out)))))
+      (when (or quote backslash)
+        (error "Unmatched quote")))))
 
 (define-syntax sh-var (var (#'parse-sh-var-value value))
     #~|^\s*(\w*)=(.*)|)