aboutsummaryrefslogtreecommitdiffstats
path: root/hobbit.texi
blob: 1afa9c42c4d04d9cb2048ead6dd9ae0a82a248f9 (plain)
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
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
\input texinfo @c -*-texinfo-*-
@c %**start of header
@setfilename hobbit.info
@settitle hobbit
@include version.txi
@setchapternewpage on
@c Choices for setchapternewpage are {on,off,odd}.
@paragraphindent 0
@c %**end of header

@dircategory The Algorithmic Language Scheme
@direntry
* hobbit: (hobbit).   SCM Compiler.
@end direntry

@iftex
@finalout
@c DL: lose the egregious vertical whitespace, esp. around examples
@c but paras in @defun-like things don't have parindent
@parskip 4pt plus 1pt
@end iftex

@titlepage
@title Hobbit
@subtitle SCM Compiler
@subtitle Version @value{SCMVERSION}
@author by Tanel Tammet
@author Department of Computing Science
@author Chalmers University of Technology
@author University of Go"teborg
@author S-41296 Go"teborg Sweden

@page
This Hobbit documentation was converted to texinfo format by Aubrey
Jaffer; and released as part of the SCM @value{SCMVERSION} distribution
@value{SCMDATE}.

@vskip 0pt plus 1filll
Copyright @copyright{} 1990-1999, 2002 Free Software Foundation

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the author.
@end titlepage

@node Top, Introduction, (dir), (dir)

@ifinfo
Hobbit is an optimizing R4RS-Scheme to C compiler written by Tanel
Tammet.

@menu
* Introduction::                
* Compiling with Hobbit::       
* The Language Compiled::       
* Performance of Compiled Code::  
* Principles of Compilation::   
* About Hobbit::                
* Index::                       
@end menu

Copyright (C) 1990-1999, 2002 Free Software Foundation

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).

@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the author.
@end ifinfo


@node Introduction, Compiling with Hobbit, Top, Top
@chapter Introduction

Hobbit is a small optimizing scheme-to-C compiler written in Report 4
scheme and intended for use together with the SCM scheme interpreter of
A. Jaffer.  Hobbit compiles full Report 4 scheme, except that:

@itemize @bullet
@item
It does not fully conform to the requirement of being properly
tail-recursive: non-mutual tailrecursion is detected, but mutual
tailrecursion is not.
@item
Macros from the Report 4 appendix are not supported (yet):
only the common-lisp-like defmacro is supported.
@end itemize

Hobbit treats SCM files as a C library and provides integration of
compiled procedures and variables with the SCM interpreter as new
primitives.

Hobbit compiles scheme files to C files and does not provide anything
else by itself (eg. calling the C compiler, dynamic loading).  Such
niceties are described in the next chapter @ref{Compiling And Linking}.

Hobbit (derived from hobbit5x) is now part of the SCM Scheme
implementation.  The most recent information about SCM can be found on
SCM's @dfn{WWW} home page:

@center @url{http://swiss.csail.mit.edu/~jaffer/SCM}

Hobbit4d has also been ported to the Guile Scheme implementation:

@center @url{http://www.gnu.org/software/guile/anon-cvs.html}


@node Compiling with Hobbit, The Language Compiled, Introduction, Top
@chapter Compiling with Hobbit

@menu
* Compiling And Linking::       
* Error Detection::             
* Hobbit Options::              
* CC Optimizations::            
@end menu

@node Compiling And Linking, Error Detection, Compiling with Hobbit, Compiling with Hobbit
@section Compiling And Linking

@code{(require 'compile)}

@defun hobbit name1.scm name2.scm @dots{}
Invokes the HOBBIT compiler to translate Scheme files
@file{@var{name1}.scm}, @file{@var{name2}.scm}, @dots{} to C files
@file{@var{name1}.c} and @file{@var{name1}.h}.
@end defun

@defun compile-file name1.scm name2.scm @dots{}
Compiles the HOBBIT translation of @var{name1}.scm, @var{name2}.scm,
@dots{} to a dynamically linkable object file
@var{name1}<object-suffix>, where <object-suffix> is the object file
suffix for your computer (for instance, @file{.so}).  @var{name1}.scm
must be in the current directory; @var{name2}.scm, @dots{} may be in
other directories.

If a file named @file{@var{name1}.opt} exists, then its options are
passed to the @code{build} invocation which compiles the @code{c}
files.
@end defun

@example
cd ~/scm/
scm -rcompile -e'(compile-file "example.scm")'

Starting to read example.scm

Generic (slow) arithmetic assumed: 1.0e-3 found.

** Pass 1 completed **
** Pass 2 completed **
** Pass 3 completed **
** Pass 4 completed **
** Pass 5 completed **
** Pass 6 completed **

C source file example.c is built.
C header file example.h is built.

These top level higher order procedures are not clonable (slow):
(nonkeyword_make-promise map-streams generate-vector runge-kutta-4)
These top level procedures create non-liftable closures (slow):
(nonkeyword_make-promise damped-oscillator map-streams scale-vector elementwise runge-kutta-4 integrate-system)

; Scheme (linux) script created by SLIB/batch Sun Apr  7 22:49:49 2002
; ================ Write file with C defines
(delete-file "scmflags.h")
(call-with-output-file
  "scmflags.h"
  (lambda (fp)
    (for-each
      (lambda (string) (write-line string fp))
      '("#define IMPLINIT \"Init@value{SCMVERSION}.scm\""
        "#define BIGNUMS"
        "#define FLOATS"
        "#define ARRAYS"
        "#define DLL"))))
; ================ Compile C source files
(system "gcc -O2 -fpic -c -I/usr/local/lib/scm/ example.c")
(system "gcc -shared -o example.so example.o -lm -lc")
(delete-file "example.o")
; ================ Link C object files
(delete-file "slibcat")

Compilation finished at Sun Apr  7 22:49:50
@end example

@defun compile->executable exename name1.scm name2.scm @dots{}
Compiles and links the HOBBIT translation of @var{name1}.scm,
@var{name2}.scm, @dots{} to a SCM executable named @var{exename}.
@var{name1}.scm must be in the current directory; @var{name2}.scm,
@dots{} may be in other directories.

If a file named @file{@var{exename}.opt} exists, then its options are
passed to the @code{build} invocation which compiles the @code{c}
files.
@end defun

@example
cd ~/scm/
scm -rcompile -e'(compile->executable "exscm" "example.scm")'

Starting to read example.scm

Generic (slow) arithmetic assumed: 1.0e-3 found.

** Pass 1 completed **
** Pass 2 completed **
** Pass 3 completed **
** Pass 4 completed **
** Pass 5 completed **
** Pass 6 completed **

C source file example.c is built.
C header file example.h is built.

These top level higher order procedures are not clonable (slow):
(nonkeyword_make-promise map-streams generate-vector runge-kutta-4)
These top level procedures create non-liftable closures (slow):
(nonkeyword_make-promise damped-oscillator map-streams scale-vector elementwise runge-kutta-4 integrate-system)

; Scheme (linux) script created by SLIB/batch Sun Apr  7 22:46:31 2002
; ================ Write file with C defines
(delete-file "scmflags.h")
(call-with-output-file
  "scmflags.h"
  (lambda (fp)
    (for-each
      (lambda (string) (write-line string fp))
      '("#define IMPLINIT \"Init@value{SCMVERSION}.scm\""
        "#define COMPILED_INITS init_example();"
        "#define CCLO"
        "#define FLOATS"))))
; ================ Compile C source files
(system "gcc -O2 -c continue.c scmmain.c findexec.c script.c time.c repl.c scl.c eval.c sys.c subr.c debug.c unif.c rope.c example.c scm.c")
; ================ Link C object files
(system "gcc -rdynamic -o exscm continue.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o debug.o unif.o rope.o example.o scm.o -L/usr/local/lib/scm/ -lm -lc")

Compilation finished at Sun Apr  7 22:46:44
@end example

@emph{Note Bene:} @samp{#define CCLO} must be present in @file{scmfig.h}.

In order to see calls to the C compiler and linker, do

@example
(verbose 3)
@end example

before calling these functions.


@node Error Detection, Hobbit Options, Compiling And Linking, Compiling with Hobbit
@section Error Detection

Error detection during compilation is minimal.  In case your scheme code
is syntactically incorrect, hobbit may crash with no sensible error
messages or it may produce incorrect C code.

Hobbit does not insert any type-checking code into the C output it
produces.  Eg, if a hobbit-compiled program applies @samp{car} to a
number, the program will probably crash with no sensible error messages.

Thus it is strongly suggested to compile only throughly debugged
scheme code.

Alternatively, it is possible to compile all the primitives into
calls to the SCM procedures doing type-checking.  Hobbit will do
this if you tell it to assume that all the primitives may be
redefined.  Put

@example
(define compile-all-proc-redefined #t)
@end example

anywhere in top level of your scheme code to achieve this.

@emph{Note Bene:} The compiled code using

@example
(define compile-all-proc-redefined #t)
@end example

will typically be much slower than one produced without using

@example
(define compile-all-proc-redefined #t).
@end example

All errors caught by hobbit will generate an error message

@example
@group
COMPILATION ERROR:
@r{<description of the error>}
@end group
@end example

and hobbit will immediately halt compilation.


@node Hobbit Options, CC Optimizations, Error Detection, Compiling with Hobbit
@section Hobbit Options

@enumerate
@item
Selecting the type of arithmetics.

By default hobbit assumes that only immediate (ie small, up to 30 bits)
integers are used.  It will automatically assume general arithmetics in
case it finds any non-immediate numbers like 1.2 or 10000000000000 or
real-only procedures like @t{$sin} anywhere in the source.

Another way to make Hobbit assume that generic arithmetic supported
by SCM (ie exact and/or inexact reals, bignums) is also used, is to
put the following line somewhere in your scheme source file:

@example
(define compile-allnumbers @var{t})
@end example

where @var{t} is arbitrary.

In that case all the arithmetic primitives in all the given source
files will be assumed to be generic.  This will make operations
with immediate integers much slower.  You can use the special
immediate-integer-only forms of arithmetic procedures to recover:

@example
@group
%negative?  %number?    %>      %>=     %=      %<=     %<
%positive?  %zero?      %eqv?   %+      %-      %*      %/
@end group
@end example

See @ref{The Language Compiled}.

@item
Redefinition of procedures.

By default hobbit assumes that neither primitives nor compiled
procedures are redefined, neither before the compiled program is
initialized, during its work or later via the interpreter.

Hobbit checks the compiled source and whenever some variable bar is
defined as a procedure, but is later redefined, or @t{set!}  is applied
to bar, then hobbit assumes thas this particular variable bar is
redefinable.  bar may be a primitive (eg @samp{car}) or a name of a
compiled procedure.


@emph{Note Bene:}
According to the Report 4 it is @b{NOT} allowed to use scheme
keywords as variables (you may redefine these as macros defined by
defmacro, though):

@example
@group
=> and begin case cond define delay do else if lambda
let let letrec or quasiquote quote set! unquote unquote-splicing
@end group
@end example

If you want to be able to redefine some procedures, eg. @samp{+} and
@samp{baz}, then put both

@example
@group
(set! + +)
(set! baz baz)
@end group
@end example

somewhere into your file.

As a consequence hobbit will generate code for @samp{+} and @samp{baz}
using the run-time values of these variables.  This is generally much
slower than using non-redefined @samp{+} and @samp{baz} (especially for
@samp{+}).

If you want to be able to redefine all the procedures, both primitives
(eg @samp{car}) and the compiled procedures, then put the following into
the compiled file:

@example
(define compile-all-proc-redefined @var{t})
@end example

where @var{t} is arbitrary.

If you want to be able to redefine all the compiled procedures, but not
the scheme primitives, then put the following into the compiled file:

@example
(define compile-new-proc-redefined @var{t})
@end example

where @var{t} is arbitrary.

Again, remember that redefinable procedures will be typically much
slower than  non-redefinable procedures.


@item
Inlined variables and procedures.

You may inline top-level-defined variables and procedures.
Notice that inlining is DIFFERENT for variables and procedures!

NEVER inline variables or procedures which are @t{set!} or redefined
anywhere in you program: this will produce wrong code.

@itemize @bullet
@item
You may declare certain top-level defined variables to be inlined.
For example, if the following variable foo is declared to be inlined
@end itemize

@example
(define foo 100)
@end example

then @samp{foo} will be everywhere replaced by @samp{100}.

To declare some variables foo and bar to be inlined, put a following
definition anywhere into your file:

@example
(define compile-inline-vars '(foo bar))
@end example

Usually it makes sense to inline only these variables whose value
is either a small integer, character or a boolean.


@emph{Note Bene:}
Do not use this kind of inlining for inlining procedures!
Use the following for procedures:

@itemize @bullet
@item
You may declare certain procedures to be inlined.  For example, if
the following foo is declared to be inlined
@end itemize

@example
(define (foo x) (+ x 2))
@end example

then any call

@example
(foo @var{something})
@end example

will be replaced by

@example
(+ @var{something} 2)
@end example

Inlining is @b{NOT} safe for variable clashes -- in other words, it is
not "hygienic".

Inlining is @b{NOT} safe for recursive procedures -- if the set of
inlined procedures contains either immediate or mutual (foo calling
bar, bar calling foo) recursion, the compiler will not terminate.
To turn off full inlining (harmful for recursive funs), change
the definition of the *full-inlining-flag* in the section
"compiler options" to the value #f instead of #t.

To declare some procedures foo and bar to be inlined, put a following
definition anywhere into your file:

@example
(define compile-inline '(foo bar))
@end example

@item
Speeding up vectors:

Put

@example
(define compile-stable-vectors '(baz foo))
@end example

into your file to declare that baz and foo are vector names defined once
on the top level, and @t{set!} is never applied to them (@t{vector-set!}
is, of course, allowed).  This speeds up vector reference to those
vectors by precomputing their location.

@item
Speeding up and hiding certain global variables:

Put

@example
(define compile-uninterned-variables '(bazvar foovar))
@end example

into your file to declare that bazvar and foovar are defined on the top
level and they do always have an immediate value, ie a boolean,
immediate (30-bit) integer or a character.  Then bazvar and foovar will
@b{NOT} be accessible from the interpreter.  They'll be compiled directly
into static C vars and used without an extra C *-operation prefixed to
other global scheme variables.

@item
Intermediate files

To see the output of compiler passes, change the following
definition in @file{hobbit.scm}.

@example
(define *build-intermediate-files* #f)
@end example

to:

@example
(define *build-intermediate-files* #t)
@end example

@item
Name clashes

It may happen that several originally different scheme variable
names are represented by one and the same C variable.  This will
happen, for example, if you have separate variables a-1 and a_1.

If such (or any other) name clashes occur you may
need to change some control variables in the first sections
of @file{hobbit.scm} (up to the section "global variable defs") or just
rename some variables in your scheme program.

@item
Other options

See various control variables in the first sections of @file{hobbit.scm}
(up to section "global variable defs").
@end enumerate



@node CC Optimizations,  , Hobbit Options, Compiling with Hobbit
@section CC Optimizations

When using the C compiler to compile the C code output by hobbit, always
use strong optimizations (eg. @samp{cc -xO3} for cc on Sun, @samp{gcc
-O2} or @samp{gcc -O3} for gcc).  Hobbit does not attempt to do
optimizations of the kind we anticipate from the C compiler, therefore
it often makes a serious difference whether the C compiler is run with a
strong optimization flag or not.

For the final and fast version of your program you may want to first
recompile the whole scm (scmlit for the version scm4e2) using the
@samp{-DRECKLESS} flag suppressing error checking: the hobbit-compiled
code uses some SCM primitives in the compiled files with the suffix .o,
and a number of these primitives become faster when error checking is
disabled by @samp{-DRECKLESS}.  Notice that hobbit never inserts error
checking into the code it produces.



@node The Language Compiled, Performance of Compiled Code, Compiling with Hobbit, Top
@chapter The Language Compiled

Calls to @code{load} or @code{require} occurring at the top level of a
file being compiled are ignored.  Calls to @code{load} or @code{require}
within a procedure are compiled to call (interpreted) @code{load} or
@code{require} as appropriate.

Several SCM and SLIB extensions to the Scheme report are recognized by
hobbit as Scheme primitives.

@menu
* Macros::                      
* SCM Primitive Procedures::    
* SLIB Logical Procedures::     
* Fast Integer Calculations::   
* Force and Delay::             
* Suggestions for writing fast code::  
@end menu


@node Macros, SCM Primitive Procedures, The Language Compiled, The Language Compiled
@section Macros
@c @heading The SCM macro-facility and the SCM extra syntactic form

The Common-lisp style defmacro implemented in SCM is recognized and
procedures defined by defmacro are expanded during compilation.

@emph{Note Bene:} any macro used in a compiled file must be also defined
in one of the compiled files.

@samp{#.@var{<expression>}} is read as the object resulting from the
evaluation of @var{<expression>}.  The calculation is performed during
compile time.  Thus @var{<expression>} must not contain variables
defined or @t{set!} in the compiled file.


@node SCM Primitive Procedures, SLIB Logical Procedures, Macros, The Language Compiled
@section SCM Primitive Procedures
@c @heading The SCM extra primitives

Real-only versions of transcedental procedures (warning: these
procedures are not compiled directly into the corresponding C library
procedures, but a combination of internal SCM procedures, guaranteeing exact
correspondence with the SCM interpreter while hindering the speed):

@example
@group
$sqrt $abs $exp $log $sin $cos $tan $asin $acos
$atan $sinh $cosh $tanh $asinh $acosh $atanh $expt
@end group
@end example

@emph{Note Bene:} These procedures are compiled to faster code than the
corresponding generic versions @t{sqrt}, @t{abs}, @dots{} @t{expt}.

A selection of other extra primitives in SCM is also recognized as
primitives. eg. @t{get-internal-run-time}, @t{quit}, @t{abort},
@t{restart}, @t{chdir}, @t{delete-file}, @t{rename-file}.


@node SLIB Logical Procedures, Fast Integer Calculations, SCM Primitive Procedures, The Language Compiled
@section SLIB Logical Procedures
@c @heading Bitwise logical procedures from the scheme library

The following bitwise procedures in the scheme library file
@file{logical.scm} are compiled directly to fast C operations on
immediate integers (small 30-bit integers) (Scheme library funs in the
upper row, C ops below):

@example
@group
   logand logior logxor lognot logsleft logsright
      &      |     ^      ~       <<        >>
@end group
@end example

The following alternative names @t{logical:logand},
@t{logical:logior}, @t{logical:logxor}, @t{logical:lognot}, and
@t{ash} are compiled for the generic case, not immediate-integers-only
and are thus much slower.

Notice that the procedures @t{logsleft}, @t{logsright} are @b{NOT} in
the the library file @file{logical.scm:} the universal procedure
@t{ash} is instead.  Procedures @t{ash}, @t{logcount},
@t{integer-length}, @t{integer-expt}, @t{bit-extract},
@t{ipow-by-squaring}, in @file{logical.scm} are not primtives and they
are all compiled into calls to interpreted code.

@t{logsleft} and @t{logsright} are defined for non-compiled use in the
file @file{scmhob.scm} included in the SCM distribution.


@node Fast Integer Calculations, Force and Delay, SLIB Logical Procedures, The Language Compiled
@section Fast Integer Calculations
@c @heading Immediate (fast) arithmetics

The following primitives are for immediate (30-bit) integer-only
arithmetics.  The are compiled directly into the corresponding C
operations plus some bitshifts if necessary.  They are good for speed in
case the compiled program uses BOTH generic arithmetics (reals, bignums)
and immediate (30-bit) integer arithmetics.  These procedures are much
faster than corresponding generic procedures taking also reals and
bignums.  There is no point in using these unless the program as a whole
is compiled using generic arithmetics, since otherwise all the
arithmetics procedures are compiled directly into corresponding C
operations anyway.

@emph{Note Bene:} These primitives are @b{NOT} defined in SCM or its
libraries.  For non-compiled use they are defined in the file
@file{scmhob.scm} included in the SCM distribution.

@example
@group
%negative?  %number?    %>      %>=     %=      %<=     %<
%positive?  %zero?      %eqv?   %+      %-      %*      %/
@end group
@end example

@node Force and Delay, Suggestions for writing fast code, Fast Integer Calculations, The Language Compiled
@section Force and Delay

The nonessential procedure @code{force} and syntax @code{delay} are
implemented exactly as suggested in the report 4.  This implementation
deviates internally from the implementation of @code{force} and
@code{delay} in the SCM interpeter, thus it is incorrect to pass a
promise created by @code{delay} in the compiled code to the @code{force}
used by interpreter, and vice-versa for the promises created by the
interpreter.



@node Suggestions for writing fast code,  , Force and Delay, The Language Compiled
@section Suggestions for writing fast code

The following suggestions may help you to write well-optimizable and
fast code for the hobbit-scm combination.  Roughly speaking, the main
points are:

@itemize
@item
minimizing consing and creation of new vectors and strings
in speed-critical parts,

@item
minimizing the use of generic (non-integer) arithmetics
in speed-critical parts,

@item
minimizing the usage of procedures as first-class
objects (very roughly speaking, explicit lambda-terms
and call/cc) in speed-critical parts,

@item
using special options and fast-compiled primitives of the compiler.
@end itemize

Here come the details.

@enumerate
@item
Immediate arithmetics (ie using small, up to 30 bits integers) is much
faster than generic (reals and bignums) arithmetics.  If you have to use
generic arithmetic in your program, then try to use special immediate
arithmetics operations @code{%=}, @code{%<=}, @code{%+}, @code{%*},
@dots{} for speed-critical parts of the program whenever possible.

Also, if you use bitwise logical operations, try to use the
immediate-integer-only versions

@example
logand logior logxor lognot logsleft logsright
@end example

and not @code{logical:logand} or @code{ash}, for example.

@item
Due to its inner stack-based architecture, the generic (not escape-only)
continuations are very slow in SCM.  Thus they are also slow in
compiled code.  Try to avoid continuations  (calls to the procedure
call-with-current-continuation and calls to the  continuations it
produces) in speed-critical parts.

@item
In speed-critical parts of your program try to avoid using procedures
which are redefined or defined by @t{set!}:

@example
@group
(set! bar +)
(set! f (lambda (x) (if (zero? x) 1 (* x (f (- x 1))))))
@end group
@end example

anywhere in the compiled program.  Avoid using compiler flags
(@pxref{Hobbit Options}):

@example
@group
(define compile-all-proc-redefined @var{t})
(define compile-new-proc-redefined @var{t})
@end group
@end example

@item
Do not use complicated higher-order procedures in speed-critical
parts.  By @dfn{complicated} we mean @dfn{not clonable}, where clonability
is defined in the following way (@emph{Note Bene:} the primitives
@samp{map} and @samp{for-each} are considered clonable and do not
inflict a speed penalty).

A higher-order procedure (HOP for short) is defined as a procedure
with some of its formal arguments occuring in the procedure body in
a function position, that is, as a first element of a list.  Such
an argument is called a @dfn{higher-order argument}.

A HOP @samp{bar} is clonable iff it satisfies the following four
conditions:

@enumerate
@item
@samp{bar} is defined as

@example
(define bar (lambda @dots{}))
@end example

or

@example
(define (bar @dots{}) @dots{})
@end example

on top level and bar is not redefined anywhere.

@item
the name @samp{bar} occurs inside the body of bar only in a function position
and not inside an internal lambda-term.

@item
Let f be a higher-order argument of bar.
Any occurrence of f in bar has one of the following two forms:

@itemize @bullet
@item
f occurs in a function position,
@item
f is passed as an argument to bar and in the call it occurs in the same
position as in the argument list.
@end itemize

@item
Let f be a higher-order argument of bar.  f does not occur inside a
lambda-term occurring in bar.

Examples:

If @samp{member-if} is defined on top level and is not redefined
anywhere, then @samp{member-if} is a clonable HOP:

@example
@group
(define (member-if fn lst)
   (if (fn (car lst))
       lst
       (member-if fn (cdr lst)) ))
@end group
@end example

member-if-not is not a clonable HOP (fn occurs in a lambdaterm):

@example
@group
(define (member-if-not fn lst)
  (member (lambda (x) (not (fn x))) lst) )
@end group
@end example

show-f is not a clonable HOP (fn occurs in a non-function position
in (display fn)):

@example
@group
(define (show-f fn x)
    (set! x (fn x))
    (display fn)
    x)
@end group
@end example

@item
In speed-critical parts avoid using procedures which return procedures.

Eg, a procedure

@example
@group
(define plus
  (lambda (x)
     (lambda (y) (+ y x)) ))
@end group
@end example

returns a procedure.

@item
A generalisation of the previous case 5:

In speed-critical parts avoid using lambda-terms except in non-@t{set!}
function definitions like

@example
@group
(define foo (lambda @dots{})),
(let ((x 1) (f (lambda @dots{}))) @dots{})
(let* ((x 1) (f (lambda @dots{}))) @dots{})
(let name ((x 1) (f (lambda @dots{}))) @dots{})
(letrec ((f (lambda @dots{})) (g (lambda @dots{}))) @dots{})
@end group
@end example

or as arguments to clonable HOP-s or primitives @t{map} and
@t{for-each}, like

@example
@group
(let ((x 0)) (map (lambda (y) (set! x (+ 1 x)) (cons x y)) @var{list}))
(member-if (lambda (x) (< x 0)) @var{list})
@end group
@end example

where member-if is a clonable HOP.

Also, avoid using variables with a procedural value anywhere
except in a function position (first element of a list) or
as an argument to a clonable HOP, @t{map} or @t{for-each}.

Lambda-terms conforming to the current point are said to be liftable.

Examples:

@example
(define (bar x) (let ((f car)) (f (f x))))
@end example

has @samp{car} in a non-function and non-HOP-argument position in
@code{(f car)}, thus it is slower than

@example
(define (bar x) (let ((f 1)) (car (car x))))
@end example

Similarly,

@example
@group
(define (bar y z w)
  (let ((f (lambda (x) (+ x y))))
     (set! w f)
     (cons (f (car z))
           (map f z) )))
@end group
@end example

has @samp{f} occurring in a non-function position in @code{(set! w f)},
thus the lambda-term @code{(lambda (x) (+ x y))} is not liftable and the
upper @samp{bar} is thus slower than the following equivalent @samp{bar}
with a liftable inner lambda-term:

@example
@group
(define (bar y z w)
  (let ((f (lambda (x) (+ x y))))
     (set! w 0)
     (cons (f (car z))
           (map f z) )))
@end group
@end example

Using a procedure bar defined as

@example
(define bar (let ((x 1)) (lambda (y) (set! x y) (+ x y))))
@end example

is slower than using a procedure bar defined as

@example
@group
(define *bar-x* 1)
(define bar (lambda (y) (set! *bar-x* y) (+ *bar-x* y)))
@end group
@end example

since the former definition contains a non-liftable lambda-term.

@item
Try to minimize the amount of consing in the speed-critical program
fragments, that is, a number of applications of cons, list, @t{map},
quasiquote (`) and vector->list during the time program is running.
@samp{cons} (called also by @samp{list}, @samp{map} and
@samp{quasiquote}) is translated into a C call to an internal cons
procedure of the SCM interpreter.  Excessive consing also means that the
garbage collection happens more often.  Do @code{(verbose 3)} to see the
amount of time used by garbage collection while your program is running.

Try to minimize the amount of creating new vectors, strings and symbols
in the speed-critical program frgaments, that is, a number of
applications of @t{make-vector}, @t{vector}, @t{list->vector},
@t{make-string}, @t{string-append}, *@t{->string}, @t{string->symbol}.
Creating such objects takes typically much more time than consing.

@item
The Scheme iteration construction @samp{do} is compiled directly into
the C iteration construction @samp{for}.  We can expect that the C compiler
has some knowledge about @samp{for} in the optimization stage, thus it is
probably faster to use @samp{do} for iteration than non-mutual tailrecursion
(which is recognized by hobbit as such and is compiled into a jump to a
beginning of a procedure) and certainly much faster than
non-tail-recursion or mutual tailrecursion (the latter is not recognized
by hobbit as such).

@item
Declare small nonrecursive programs which do not contain
let-s or lambdaterms as being inlinable.

Declare globally defined variables which are never @t{set!} or redefined
and whose value is a small integer, character or a boolean,
as being inlinable.  @xref{Hobbit Options}.

@item
If possible, declare vectors as being stable.
@xref{Hobbit Options, Speeding up vectors}.
This gives a minor improvement in speed.

@item
If possible, declare critical global vars as being uninterned.
@xref{Hobbit Options, Speeding up and hiding certain global variables}.
This gives a minor improvement in speed.  Declare the global variables
which are never @t{set!} and have an (unchanged) numeric or boolean
value as being inlined.  @xref{Hobbit Options}.
@end enumerate

In addition, take the following into account:

@itemize @bullet
@item
When using the C compiler to compile the C code output by hobbit, always
use strong optimizations (eg. @samp{cc -xO3} for cc on Sun, @samp{gcc
-O2} or @samp{gcc -O3} for gcc).  Hobbit does not attempt to do
optimizations of the kind we anticipate from the C compiler, therefore
it often makes a big difference if the C compiler is run with a strong
optimization flag or not.

@item
hobbit does not give proper tailrecursion behaviour for mutual
tailrecursion (foo calling bar, bar calling foo tailrecursively).

Hobbit guarantees proper tailrecursive behaviour for non-mutual
tailrecursion (foo calling foo tailrecursively), provided that
foo is not redefined anywhere and that foo is not a local function which
occurs also in a non-function and non-clonable-HOP-argument position
(i.e. cases 3 and 6 above).
@end itemize
@end enumerate



@node Performance of Compiled Code, Principles of Compilation, The Language Compiled, Top
@chapter Performance of Compiled Code


@menu
* Gain in Speed::               
* Benchmarks::                  
* Benchmark Sources::           
@end menu

@node Gain in Speed, Benchmarks, Performance of Compiled Code, Performance of Compiled Code
@section Gain in Speed

The author has so far compiled and tested a number of large programs
(theorem provers for various logics and hobbit itself).

The speedup for the provers was between 25 and 40 times for various
provable formulas.  Comparison was made between the provers being
interpreted and compiled with @samp{gcc -O2 -DRECKLESS} on Sparcstation
ELC in both cases.

The provers were written with care to make the compiled version run fast.
They do not perform excessive consing and they perform very little
arithmetic.

According to experiments made by A. Jaffer, the compiled form of the
example program @file{pi.scm} was approximately 11 times faster than the
interpreted form.

As a comparison, his hand-coded C program for the same algorithm of
computing pi was about 12 times faster than the interpreted form.
@file{pi.scm} spends most of of its time in immediate arithmetics,
@t{vector-ref} and @t{vector-set!}.

P. Kelloma"ki has reported a 20-fold speedup for his generic scheme
debugger.  T. Moore has reported a 16-fold speedup for a large gate-level
IC optimizer.

Self-compilation speeds Hobbit up only ca 10 times.

However, there are examples where the code compiled by hobbit
runs actually slower than the same code running under interpreter:
this may happen in case the speed of the code relies on non-liftable
closures and proper mutual tailrecursion.  See for example the
closure-intensive benchmark CPSTAK in the following table.

@page
@node Benchmarks, Benchmark Sources, Gain in Speed, Performance of Compiled Code
@section Benchmarks

We will present a table with the performance of three scheme systems on
a number of benchmarks: interpreted SCM, byte-compiled VSCM and
hobbit-compiled code.  The upper 13 benchmarks of the table are the
famous Gabriel benchmarks (originally written for lisp) modified for
scheme by Will Clinger.  The lower five benchmarks of the table are
proposed by other people.  @dfn{Selfcompile} is the self-compile time
of Hobbit.


Hobbit performs well on most of the benchmarks except
CPSTAK and CTAK: CPSTAK is a closure-intensive tailrecursive
benchmark and CTAK is a continuations-intensive benchmark.
Hobbit performs extremely well on these benchmarks which essentially
satisfy the criterias for well-optimizable code outlined in the
section 6 above.

FFT is real-arithmetic-intensive.

All times are in seconds.

SCM 4c0(U) and 1.1.5*(U) (the latter is the newest version of VSCM)
are compiled and run by Matthias Blume on a DecStation 5000 (Ultrix).
VSCM is a bytecode-compiler using continuation-passing style, and is well
optimized for continuations and closures.

SCM 4e2(S) and Hobbit4b(S) compiled (with @samp{cc -xO3}) and run by
Tanel Tammet on a Sun SS10 (lips.cs.chalmers.se).  Hobbit is a
Scheme-to-C compiler for SCM, the code it produces does not do any
checking.  SCM and hobbit are not optimized for continuations.  Hobbit
is not optimized for closures and proper mutual tailrecursion.

SCM and Hobbit benchmarks were run giving ca 8 MB of free heap space
before each test.

@example
@group
Benchmark       |SCM 4c0(U) 1.1.5*(U)| SCM 4e2(S)  Hobbit4b(S)
----------------|------------------------------------------------
Deriv           | 3.40      3.86     |  2.9            0.18
Div-iter        | 3.45      2.12     |  2.6            0.083
Div-rec         | 3.45      2.55     |  3.5            0.42
TAK             | 1.81      1.71     |  1.4            0.018
TAKL            |14.50     11.32     | 13.8(1.8 in gc) 0.13
TAKR            | 2.20      1.64     |  1.7 1.5        0.018
Destruct        | ?          ?       |  7.4(1.8 in gc) 0.18
Boyer           | ?          ?       | 27.(3.8 in gc)  1.9
CPSTAK          | 2.72      2.64     |  2.0 1.92       3.46(2.83 in gc)
CTAK            |31.0       4.11     | memory          memory
CTAK(7 6 1)     | ?          ?       |  0.83           0.74
FFT             |12.45     15.7      | 11.4 10.8       1.0
Puzzle          | 0.28      0.41     |  0.46(0.22 gc)  0.03
----------------------------------------------------------------
(recfib 25)     | ?          ?       |  4.1            0.079
(recfib 30)     | ?          ?       | 55. (10.in gc)  0.87
(pi 300 3)      | ?          ?       |  7.4            0.46
(hanoi 15)      | ?          ?       |  0.68           0.007
(hanoi 20)      | ?          ?       | 31. (9. in gc)  0.2
----------------------------------------------------------------
@end group
@end example

@page
@node Benchmark Sources,  , Benchmarks, Performance of Compiled Code
@section Benchmark Sources
@subheading A selection of (smaller) benchmark sources

@menu
* Destruct::                    
* Recfib::                      
* div-iter and div-rec::        
* Hanoi::                       
* Tak::                         
* Ctak::                        
* Takl::                        
* Cpstak::                      
* Pi::                          
@end menu

@node Destruct, Recfib, Benchmark Sources, Benchmark Sources
@subsection Destruct

@example
@group
;;;; Destructive operation benchmark
(define (destructive n m)
  (let ((l (do ((i 10 (- i 1))
                (a '() (cons '() a)))
               ((= i 0) a))))
    (do ((i n (- i 1)))
        ((= i 0))
      (if (null? (car l))
          (do ((l l (cdr l)))
              ((null? l))
            (or (car l) (set-car! l (cons '() '())))
            (append! (car l) (do ((j m (- j 1))
                                  (a '() (cons '() a)))
                                 ((= j 0) a))))
          (do ((l1 l (cdr l1))
               (l2 (cdr l) (cdr l2)))
              ((null? l2))
            (set-cdr! (do ((j (quotient (length (car l2)) 2) (- j 1))
                           (a (car l2) (cdr a)))
                          ((zero? j) a)
                        (set-car! a i))
                      (let ((n (quotient (length (car l1)) 2)))
                        (cond ((= n 0) (set-car! l1 '()) (car l1))
                              (else (do ((j n (- j 1))
                                         (a (car l1) (cdr a)))
                                        ((= j 1)
                                         (let ((x (cdr a)))
                                           (set-cdr! a '()) x))
                                      (set-car! a i)))))))))))
;; call:  (destructive 600 50)
@end group
@end example

@need 1500
@node Recfib, div-iter and div-rec, Destruct, Benchmark Sources
@subsection Recfib

@example
@group
(define (recfib x)
  (if (< x 2)
      x
      (+ (recfib (- x 1))
         (recfib (- x 2)))))
@end group
@end example

@need 4000
@node div-iter and div-rec, Hanoi, Recfib, Benchmark Sources
@subsection div-iter and div-rec

@example
@group
;;;; Recursive and iterative benchmark divides by 2 using lists of ()'s.
(define (create-n n)
  (do ((n n (- n 1))
       (a '() (cons '() a)))
      ((= n 0) a)))
(define *ll* (create-n 200))
(define (iterative-div2 l)
  (do ((l l (cddr l))
       (a '() (cons (car l) a)))
      ((null? l) a)))
(define (recursive-div2 l)
  (cond ((null? l) '())
        (else (cons (car l) (recursive-div2 (cddr l))))))
(define (test-1 l)
  (do ((i 300 (- i 1))) ((= i 0))
    (iterative-div2 l)
    (iterative-div2 l)
    (iterative-div2 l)
    (iterative-div2 l)))
(define (test-2 l)
  (do ((i 300 (- i 1))) ((= i 0))
    (recursive-div2 l)
    (recursive-div2 l)
    (recursive-div2 l)
    (recursive-div2 l)))
;; for the iterative test call: (test-1 *ll*)
;; for the recursive test call: (test-2 *ll*)
@end group
@end example

@need 1000
@node Hanoi, Tak, div-iter and div-rec, Benchmark Sources
@subsection Hanoi

@example
@group
;;; C optimiser should be able to remove the first recursive call to
;;; move-them.  But Solaris 2.4 cc, gcc 2.5.8, and hobbit don't.
(define (hanoi n)
  (letrec ((move-them
            (lambda (n from to helper)
              (if (> n 1)
                  (begin
                    (move-them (- n 1) from helper to)
                    (move-them (- n 1) helper to from))))))
    (move-them n 0 1 2)))
@end group
@end example

@page
@node Tak, Ctak, Hanoi, Benchmark Sources
@subsection Tak

@example
@group
;;;; A vanilla version of the TAKeuchi function
(define (tak x y z)
  (if (not (< y x))
      z
      (tak (tak (- x 1) y z)
           (tak (- y 1) z x)
           (tak (- z 1) x y))))
;; call: (tak 18 12 6)
@end group
@end example

@need 2000
@node Ctak, Takl, Tak, Benchmark Sources
@subsection Ctak

@example
@group
;;;; A version of the TAK function that uses continuations
(define (ctak x y z)
  (call-with-current-continuation
   (lambda (k)
     (ctak-aux k x y z))))

(define (ctak-aux k x y z)
  (cond ((not (< y x)) (k z))
        (else (call-with-current-continuation
               (ctak-aux
                k
                (call-with-current-continuation
                 (lambda (k) (ctak-aux k (- x 1) y z)))
                (call-with-current-continuation
                 (lambda (k) (ctak-aux k (- y 1) z x)))
                (call-with-current-continuation
                 (lambda (k) (ctak-aux k (- z 1) x y))))))))

(define (id x) x)

(define (mb-test r x y z)
  (if (zero? r)
      (ctak x y z)
      (id (mb-test (- r 1) x y z))))
;;; call: (ctak 18 12 6)
@end group
@end example

@need 2000
@node Takl, Cpstak, Ctak, Benchmark Sources
@subsection Takl

@example
@group
;;;; The TAKeuchi function using lists as counters.
(define (listn n)
  (if (not (= 0 n))
      (cons n (listn (- n 1)))
      '()))

(define l18 (listn 18))
(define l12 (listn 12))
(define l6 (listn 6))

(define (mas x y z)
  (if (not (shorterp y x))
      z
      (mas (mas (cdr x) y z)
           (mas (cdr y) z x)
           (mas (cdr z) x y))))

(define (shorterp x y)
  (and (pair? y) (or (null? x) (shorterp (cdr x) (cdr y)))))
;; call: (mas l18 l12 l6)
@end group
@end example

@need 2000
@node Cpstak, Pi, Takl, Benchmark Sources
@subsection Cpstak

@example
@group
;;;; A continuation-passing version of the TAK benchmark.
(define (cpstak x y z)
  (define (tak x y z k)
    (if (not (< y x))
        (k z)
        (tak (- x 1)
             y
             z
             (lambda (v1)
               (tak (- y 1)
                    z
                    x
                    (lambda (v2)
                      (tak (- z 1)
                           x
                           y
                           (lambda (v3)
                             (tak v1 v2 v3 k)))))))))
  (tak x y z (lambda (a) a)))
;;; call: (cpstak 18 12 6)
@end group
@end example

@need 4000
@node Pi,  , Cpstak, Benchmark Sources
@subsection Pi

@example
@group
(define (pi n  . args)
      (let* ((d (car args))
             (r (do ((s 1 (* 10 s))
                     (i 0 (+ 1 i)))
                    ((>= i d) s)))
             (n (+ (quotient n d) 1))
             (m (quotient (* n d 3322) 1000))
             (a (make-vector (+ 1 m) 2)))
        (vector-set! a m 4)
        (do ((j 1 (+ 1 j))
             (q 0 0)
             (b 2 (remainder q r)))
            ((> j n))
          (do ((k m (- k 1)))
              ((zero? k))
            (set! q (+ q (* (vector-ref a k) r)))
            (let ((t (+ 1 (* 2 k))))
              (vector-set! a k (remainder q t))
              (set! q (* k (quotient q t)))))
          (let ((s (number->string (+ b (quotient q r)))))
            (do ((l (string-length s) (+ 1 l)))
                ((>= l d) (display s))
              (display #\0)))
          (if (zero? (modulo j 10)) (newline) (display #\ )))
        (newline)))
@end group
@end example


@node Principles of Compilation, About Hobbit, Performance of Compiled Code, Top
@chapter Principles of Compilation

@menu
* Macro-Expansion and Analysis::  Pass 1
* Building Closures::           Pass 2
* Lambda-lifting::              Pass 3
* Statement-lifting::           Pass 4
* Higher-order Arglists::       Pass 5
* Typing and Constants::        Pass 6
@end menu

@node Macro-Expansion and Analysis, Building Closures, Principles of Compilation, Principles of Compilation
@section Expansion and Analysis


@enumerate
@item
Macros defined by defmacro and all the quasiquotes
are expanded and compiled into equivalent form without macros
and quasiquotes.

For example, `(a , x) will be converted to (cons 'a (cons x '())).

@item
Define-s with the nonessential syntax like

@example
(define (foo x) @dots{})
@end example

are converted to @t{define}s with the essential syntax

@example
(define foo (lambda (x) @dots{}))
@end example

Non-top-level @t{define}s are converted into equivalent
@t{letrec}-s.

@item
Variables are renamed to avoid name clashes, so that any local
variable may have a whole procedure as its scope.  This renaming
also converts let-s to let*-s.  Variables which do not introduce
potential name clashes are not renamed.  For example,

@example
@group
(define (foo x y)
   (let ((x y)
         (z x))
     (let* ((x (+ z x)))
       x)))
@end group
@end example

is converted to

@example
@group
(define foo
  (lambda (x y)
    (let* ((x__1 y)
           (z x)
           (x__2 (+ z x__1)))
       x__2)))
@end group
@end example

@item
In case the set of procedures defined in one @t{letrec} is actually not
wholly mutually recursive (eg, f1 calls f2, but f2 does not call f1, or
there are three procedures, f1, f2, f3 so that f1 and f2 are mutually
recursive but f3 is not called from f1 or f2 and it does not call them,
etc), it is possible to minimize the number of additional variables
passed to procedures.

Thus @t{letrec}-s are split into ordered chunks using dependency
analysis and topological sorting, to reduce the number of mutually
passed variables.  Wherever possible, @t{letrec}-s are replaced by
@t{let*}-s inside these chunks.


@item
Normalization is performed.  This converts a majority of scheme
control procedures like @code{cond}, @code{case}, @code{or},
@code{and} into equivalent terms using a small set of primitives.  New
variables may be introduced in this phase.

In case a procedure like @code{or} or @code{and} occurs in the place
where its value is treated as a boolean (eg. first argument of
@code{if}), it is converted into an analogous boolean-returning
procedure, which will finally be represented by an analogous C
procedure (eg. || or &&).

Associative procedures are converted into structures of corresponding
nonassociative procedures.  List is converted to a structure of cons-s.

Map and @t{for-each} with more than two arguments are converted into an
equivalent do-cycle.  @t{map}-s and @t{for-each}-s with two arguments are
treated as if they were defined in the compiled file -- the definitions
@t{map1} and @t{for-each1} are automatically included, if needed.

There is an option in @file{hobbit.scm} to make all @t{map}-s and
@t{for-each}-s be converted into equivalent do-loops, avoiding the use
of @t{map1} and/or @t{for-each1} altogether.


@item
Code is analysed for determining which primitive names and
compiled procedure names are assumed to be redefinable.

@item
Analysing HOP clonability: hobbit will find a list of clonable
HOP-s with information about higher-order arguments.

Criterias for HOP clonability are given in the section 6.4.


@item
Analysis of liftability: hobbit will determine which lambda-terms
have to be built as real closures (implemented as a vector where the
first element is a pointer to a function and the rest contain values
of environment variables or environment blocks of surrounding code)
and which lambda-terms are liftable.

Liftability analysis follows the criterias given in section 6.5 and
6.6.
@end enumerate


@node Building Closures, Lambda-lifting, Macro-Expansion and Analysis, Principles of Compilation
@section Building Closures


Here Hobbit produces code for creating real closures for all the
lambda-terms which are not marked as being liftable by the previous
liftability analysis.

Global variables (eg x-glob) are translated as pointers (locations) to
SCM objects and used via a fetch: *x_glob (or a fetch
macro GLOBAL(x-glob) which translates to *x_glob).

While producing closures hobbit tries to minimize the indirection
levels necessary.  Generally a local variable x may have to be translated
to an element of a vector of local variables built in the procedure
creating x.  If x occurs in a non-liftable closure, the whole vector
of local variables is passed to a closure.

Such a translation using a local vector will only take place if either x
is @t{set!} inside a non-liftable lambda-term or x is a name of a
recursively defined non-liftable function, and the definition of x is
irregular.  The definition of x is irregular if x is given the
non-liftable recursive value @var{t} by extra computation, eg as

@example
(set! x (let ((u 1)) (lambda (y) (display u) (x (+ u 1)))))
@end example

and not as a simple lambdaterm:

@example
(set! x (lambda (y) (display x) (x (+ y 1))))
@end example

In all the other cases a local scheme variable x is translated
directly to a local C variable x having the type SCM (a 32-bit
integer).  If such an x occurs in a non-liftable closure, then
only its value is passed to a closure via the closure-vector.
In case the directly-translated variable x is passed to a liftable
lambda-term where it is @t{set!}, then x is passed indirectly by
using its address &x.  In the lifted lambda-term it is then accessed via *.

If all the variables x1, @dots{}, xn created in a procedure can be
translated directly as C variables, then the procedure does not create a
special vector for (a subset of) local variables.

An application (foo @dots{}) is generally translated to C by an internal
apply of the SCM interpreter:
apply(GLOBAL(foo), @dots{}).  Using an internal apply is much slower than
using direct a C function call, since:

@itemize @bullet
@item
there is an extra fetch by GLOBAL(foo),
@item
internal apply performs some computations,
@item
the arguments of foo are passed as a list constructed during
    application: that is, there is a lot of expensive consing every
    time foo is applied via an internal apply.
@end itemize

However, in case foo is either a name of a non-redefined primitive or a
name of a non-redefined liftable procedure, the application is
translated to C directly without the extra layer of calling apply:
foo(@dots{}).

Sometimes lambda-lifting generates the case that some variable
x is accessed not directly, but by *x.  See the next section.

Undefined procedures are assumed to be defined via interpreter
and are called using an internal apply.

@node Lambda-lifting, Statement-lifting, Building Closures, Principles of Compilation
@section Lambda-lifting


When this pass starts, all the real (nonliftable) closures have been
translated to closure-creating code.  The remaining lambda-terms
are all liftable.

Lambda-lifting is performed.  That is, all procedures defined inside
some other procedure (eg. in @t{letrec}) and unnamed lambda-terms are
made top-level procedure definitions.  Any N variables not bound in such
procedures which were bound in the surrounding procedure are given as
extra N first parameters of the procedure, and whenever the procedure is
called, the values of these variables are given as extra N first
arguments.

For example:

@example
@group
(define foo
  (lambda (x y)
     (letrec ((bar (lambda (u) (+ u x))))
        (bar y) )))
@end group
@end example

is converted to

@example
@group
(define foo
  (lambda (x y)
    (foo-fn1 x y) ))

(define foo-fn1
  (lambda (x u)
    (+ u x) ))
@end group
@end example

The case of mutually recursive definitions in @t{letrec} needs special
treatment -- all free variables in mutually recursive funs have, in
general, to be passed to each of those funs.  For example, in

@example
@group
(define (foo x y z i)
  (letrec ((f1 (lambda (u) (if x (+ (f2 u) 1))))
           (f2 (lambda (v) (if (zero? v) 1 (f1 z)))) )
    (f2 i) ))
@end group
@end example

the procedure f1 contains a free variable x and the procedure f2
contains a free variable z.  Lambda-lifted f1 and f2 must
each get both of these variables:

@example
@group
(define (foo x y z i)
   (foo-fn2 x z i) )

(define foo-fn1
  (lambda (x z u) (if x (+ (foo-fn2 x z u) 1))) )

(define foo-fn2
  (lambda (x z v) (if (zero? v) 1 (foo-fn1 x z z))) )
@end group
@end example

Recall that hobbit has already done dependency analysis and has
split the original @t{letrec} into smaller chunks according to this
analysis: see pass 1.

Whenever the value of some free variable is modified by @t{set!} in
the procedure, this variable is passed by reference instead.
This is not directly possible in scheme, but it is possible in C.

@example
@group
(define foo
  (lambda (x y z)
     (letrec ((bar (lambda (u) (set! z (+ u x z)))))
        (bar y)
        z)))
@end group
@end example

is converted to incorrect scheme:

@example
@group
(define foo
  (lambda (x y z)
    (foo-fn1 x (**c-adr** z) y)
    z))

(define foo-fn1
  (lambda (x (**c-adr** z) u)
    (set! (**c-fetch** z) (+ u x (**c-fetch** z))) ))
@end group
@end example

The last two will finally be compiled into correct C as:

@example
@group
SCM foo(x, y, z)
SCM x, y, z;
@{
  foo_fn1(x, &z, y);
  return z;
@}

SCM foo_fn1(x, z, u)
SCM x, u;
SCM *z;
@{
  return (*z =  (u + x) + *z);
@}
@end group
@end example



@node Statement-lifting, Higher-order Arglists, Lambda-lifting, Principles of Compilation
@section Statement-lifting

As the scheme do-construction is compiled into C for, but for cannot
occur in all places in C (it is a statement), then if the do in a
scheme procedure occurs in a place which will not be a statement
in C, the whole do-term is lifted out into a new top-level
procedure analogously to lambda-lifting.  Any statement-lifted
parts of some procedure foo are called foo_aux@var{n}, where @var{n}
is a number.

The special C-ish procedure **return** is pushed into a scheme term as far
as possible to extend the scope of statements in the resulting
C program.  For example,

@example
@group
(define foo
  (lambda (x y)
      (if x (+ 1 y) (+ 2 y)) ))
@end group
@end example

is converted to

@example
@group
(define foo
   (lambda (x y)
     (if x (**return** (+ 1 y)) (**return** (+ 2 y))) ))
@end group
@end example

Immediate tailrecursion (foo calling foo tailrecursively) is
recognized and converted into an assignment of new values to args and
a jump to the beginning of the procedure body.


@node Higher-order Arglists, Typing and Constants, Statement-lifting, Principles of Compilation
@section Higher-order Arglists

All procedures taking a list argument are converted into ordinary
non-list taking procedures and they are called with the list-making
calls inserted.  For example,

@example
@group
(define foo
  (lambda (x . y)
    (cons x (reverse y)) ))
@end group
@end example

is converted to

@example
@group
(define foo
  (lambda (x y)
    (cons x (reverse y)) ))
@end group
@end example

and any call to foo will make a list for a variable y.  For example,

@example
(foo 1 2 3)
@end example

is converted to

@example
(foo 1 (cons 2 (cons 3 '()))).
@end example

All higher-order procedure calls where an argument-term contains
unbound variables will generate a new instance (provided it
has not been created already) of this higher-order procedure,
carrying the right amount of free variables inside to right
places.

For example, if there is a following definition:

@example
@group
(define (member-if fn lst)
   (if (fn (car lst))
       lst
       (member-if fn (cdr lst)) ))
@end group
@end example

and a call

@example
(member-if (lambda (x) (eq? x y)) lst),
@end example

a new instance of member-if is created (if an analogous one
has not been created before):

@example
@group
(define (member-if_inst1 tmp fn lst)
   (if (fn tmp (car lst))
       lst
       (member-if_inst1 tmp fn (cdr lst)) ))
@end group
@end example

and the call is converted to

@example
(member-if_inst1 y foo lst)
@end example

and a top-level @t{define}

@example
(define (foo y x) (eq? x y))
@end example

In addition, if the higher-order procedure is to be exported,
an additional instance is created, which uses apply to
call all argument-procedures, assuming they are defined via interpreter.
The exportable higher-order procedure will have a name @var{fun}_exporthof,
where @var{fun} is the name of the original procedure.


@node Typing and Constants,  , Higher-order Arglists, Principles of Compilation
@section Typing and Constants

All C<->Scheme conversions for immediate objects like numbers,
booleans and characters are introduced.  Internal apply
is used for undefined procedures.  Some optimizations are performed
to decrease the amount of C<->Scheme object conversions.

All vector, pair and string constants are replaced by new
variables.  These variables are instantiated to the right
values by init_@var{foo*}.

Procedures foo which are to be exported (made accesible to the
interpreter), and which have an arity different from one of the
following five templates: x, (), (x), (x y), (x y z), are made
accessible via an additional procedure foo_wrapper taking a single
list argument.

@subheading C Code Generation

More or less straightforward.

The type conversion between C objects and immediate Scheme objects of
the type boolean, char and num is performed by macros.  The scheme
object @t{'()} is represented by the macro object EOL.

@subheading  Intermediate files

Experiment yourself by defining:

@example
(define *build-intermediate-files* #t)
@end example

instead of the default:

@example
(define *build-intermediate-files* #f).
@end example


@node About Hobbit, Index, Principles of Compilation, Top
@chapter About Hobbit

@menu
* The Aims of Developing Hobbit::  
* Manifest::                    
* Author and Contributors::     
* Future Improvements::         
* Release History::             
@end menu

@node The Aims of Developing Hobbit, Manifest, About Hobbit, About Hobbit
@section The Aims of Developing Hobbit

@enumerate
@item
Producing maximally fast C code from simple scheme code.

By @dfn{simple} we mean code which does not rely on procedures
returning procedures (closures) and nontrivial forms of
higher-order procedures.  All the latter are also compiled,
but the optimizations specially target simple code fragments.
Hobbit performs global optimization in order to locate such fragments.

@item
Producing C code which would preserve as much original scheme
code structure as possible, to enable using the output C code
by a human programmer (eg. for introducing special optimizations
possible in C).  Also, this will hopefully help the C compiler
to find better optimizations.
@end enumerate


@node Manifest, Author and Contributors, The Aims of Developing Hobbit, About Hobbit
@section Manifest

@multitable @columnfractions .2 .8
@item @file{hobbit.scm}
@tab the hobbit compiler.
@item @file{scmhob.scm}
@tab  the file defining some additional procedures recognized
by hobbit as primitives.  Use it with the interpreter only.
@item @file{scmhob.h}
@tab the common headerfile for hobbit-compiled C files.
@item @file{hobbit.texi}
@tab documentation for hobbit.
@end multitable


@node Author and Contributors, Future Improvements, Manifest, About Hobbit
@section Author and Contributors

@quotation
Tanel Tammet@*
Department of Computing Science@*
Chalmers University of Technology@*
University of Go"teborg@*
S-41296 Go"teborg Sweden
@end quotation

A. Jaffer (agj @@ alum.mit.edu), the author of SCM, has been of major
help with a number of suggestions and hacks, especially concerning the
interface between compiled code and the SCM interpreter.

Several people have helped with suggestions and detailed bug reports,
e.g. David J. Fiander (davidf@@mks.com), Gordon Oulsnam
(STCS8004@@IRUCCVAX.UCC.IE), Pertti Kelloma"ki (pk@@cs.tut.fi),
Dominique de Waleffe (ddw2@@sunbim.be) Terry Moore (tmm@@databook.com),
Marshall Abrams (ab2r@@midway.uchicago.edu).  Georgy K. Bronnikov
(goga@@bronnikov.msk.su), Bernard Urban (Bernard.URBAN@@meteo.fr),
Charlie Xiaoli Huang, Tom Lord (lord@@cygnus.com),
NMICHAEL@@us.oracle.com, Lee Iverson (leei@@ai.sri.com), Burt
Leavenworth (EDLSOFT@@aol.com).


@page
@node Future Improvements, Release History, Author and Contributors, About Hobbit
@section Future Improvements

@enumerate
@item
Optimisations:

@itemize
@item
the calls to internal apply: we'd like to avoid the excessive consing of
always building the list of arguments.
@item
speeding up the creation of a vector for assignable closure-variables
@item
several peephole optimisations.
@end itemize

@item
Improve Variable creation and naming to avoid C function name clashes.

@item
Report 4 macros.

@item
Better error-checking.

@item
Better liftability analysis.

@item
More tailrecursion recognition.

@item
Better numeric optimizations.

@item
Fast real-only arithmetics: $eqv, $=, $>, $+, $*, etc.
@end enumerate


@node Release History,  , Future Improvements, About Hobbit
@section Release History

@quotation
[In February 2002, hobbit5x was integrated into the SCM distribution.
Changes since then are recorded in @file{scm/ChangeLog}.]
@end quotation

@table @asis
@item hobbit4d:
@itemize @bullet
@item
the incorrect translation of char>?, char-ci>?, char>=?, char-ci>=?
string>?, string-ci>?, string-ci>=?, string>=? reported by
Burt Leavenworth (EDLSOFT@@aol.com) was fixed.
@item
the name clash bug for new variables new_varN occurring in
non-liftable closures (reported by Lee Iverson (leei@@ai.sri.com))
was fixed.
@item
the major COPYRIGHT change: differently from all the previous
versions of Hobbit, hobbit4d is Free Software.
@end itemize

@item hobbit4c:
@itemize @bullet
@item
a liftability-analysis bug for @t{for-each} and @t{map} reported
by Lee Iverson (leei@@ai.sri.com) has been fixed.
@item
The output C code does not contain the unnecessary ;-s on
separate lines any more.
@end itemize

@item hobbit4b:
The following bugs have been fixed:
@itemize @bullet
@item
Erroneous treatment of [ and ] inside symbols,
reported by A. Jaffer (agj @@ alum.mit.edu).
@item
A bug in the liftability analysis,
reported by A. Jaffer (agj @@ alum.mit.edu).
@item
A bug occurring in case arguments are evaluated right-to-left,
which happens with Hobbit compiled by gcc on Linux.
Reported and patched by George K. Bronnikov (goga@@bronnikov.msk.su)
@item
A closure-building bug sometimes leading to a serious loss of
efficiency (liftability not recognized),
reported by NMICHAEL@@us.oracle.com.
@item
A bug in the liftability analysis (non-liftable lambda-term
inside a liftable lambda-term)
reported by Lee Iverson (leei@@ai.sri.com)
@end itemize

@item hobbit4a:
Several bugs found in version4x are fixed.

@item hobbit4x (not public):
@itemize @bullet
@item
A major overhaul: Hobbit is now able to compile full scheme,
not just the fast liftable-clonable fragment.

The optimizations done by the earlier versions are preserved.

@item
Numerous bugs found in earlier versions have been fixed.
@end itemize

@item hobbit3d:
bugs found in the version 3c are fixed.

@item hobbit3c:
@itemize @bullet
@item
the form

@example
(define foo (let ((x1 <t1>) @dots{} (xn <tn>)) (lambda @dots{})))
@end example

is now supported for all terms <ti> except procedures defined
in the compiled files.
@item
macros are partially supported by doing a preprocessing pass using the
procedures pprint-filter-file and defmacro:expand* defined
in slib.
@item
the file @file{scmhob.scm} defining hobbit-recognized nonstandard
procedures is created.
@item
the documentation is improved (thanks go to Aubrey for suggestions).
@end itemize

@item hobbit3b:
@itemize @bullet
@item
Aubrey fixed some problems with the version 3.
@item
It is now OK to define procedures "by name" on top level.
@item
It is now OK to apply "apply", etc to procedures defined
in the compiled file.  Compiled procedures may now be passed
to procedures not defined but still called in the compiled files.
@end itemize

@item hobbit3:
@itemize @bullet
@item
Generic arithmetic supported by SCM (exact and inexact reals,
bignums) is made available.
@item
The #. special syntactic form of SCM is made available.
@item
Procedures with chars are compiled open-coded, making them faster.
@item
The bug concerning strings containing an embedded \nl char
is corrected (thanks to Terry Moore, (tmm@@databook.com)).
@item
The special declaration compile-stable-vectors for optimizing
vector access is introduced.
@item
Source code may contain top-level computations, top-level
loads are ignored.
@item
The bug causing "or" to (sometimes) lose tailrecursiveness is corrected.
@item
Hobbit now allows the following very special form:

@example
(define foo (let ((bar bar)) (lambda @dots{})))
@end example

Notice @code{(bar bar)}.  See the section 5 above.  It will produce wrong
code if bar is redefined.

There were several versions of the 2-series, like 2.x, which were
not made public.  The changes introduced are present in the version 3.
@end itemize

@item hobbit2:
@itemize @bullet
@item
The following bitwise procedures in the scheme library file
@file{logical.scm} are compiled directly to C
(Scheme library funs in the upper row, C ops below):

@example
@group
logand logior logxor lognot logsleft logsright
   &      |     ^      ~       <<        >>
@end group
@end example

Notice that the procedures @t{logsleft}, @t{logsright} are @b{NOT} in
the the library file @file{logical.scm}: the universal procedure @t{ash}
is instead.  Procedures @t{ash}, @t{logcount}, @t{integer-length},
@t{integer-expt}, @t{bit-extract} in @file{logical.scm} are not
recognized by hobbit.
@end itemize

@item hobbit1a3 (not public):
@itemize @bullet
@item
the @t{letrec}-sorting bug often resulting in not recognizing procedures
defined in @t{letrec} (or local @t{define}s) has been corrected.
@item
the primitives @t{string} and @t{vector} are now compiled correctly.
@end itemize

@item hobbit1a2 (not public):
@itemize @bullet
@item
any fixed arity procedure (including primitives) may be passed to any
higher-order procedure by name.  Variable arity procedures (eg
primitives @t{list}, @t{+}, @t{display} and defined funs like
@code{(define (foo x . y) x)}) must not be passed to new defined
higher-order funs.
@item
some optimizations have been introduced for calls to @t{map}
and @t{for-each}.
@item
(map list x y) bug has been corrected.
@item
Corrected self-compilation name clash between call_cc and call-cc.
@end itemize

@item hobbit1a1 (not public):
@itemize @bullet
@item
named let is supported.
@item
the inlining bug is fixed: all procedures declared to be
inlined are fully inlined, except when the flag
*full-inlining-flag* is defined as #f.
@item
the @t{letrec} (or in-procedure define) bug where local procedure
names were not recognized, is fixed.
@item
documentation says explicitly that definitions like

@example
(define foo (let ((x 0)) (lambda (y) @dots{})))
@end example

are assumed to be closure-returning procedures and are prohibited.
@item
documentation allows more liberty with passing procedures to
higher-order funs by dropping the general requirement that only unnamed
lambda-terms may be passed.  Still, primitives and list-taking
procedures may not be passed by name.
@item
documentation prohibits passing lambda-terms with free variables to
recursive calls of higher-order procedures in the definition of a
higher-order procedure.
@end itemize

@item hobbit1:
the first release
@end table


@node Index,  , About Hobbit, Top
@unnumbered Index

@printindex fn

@contents
@bye