home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / doc / ipd237.txt < prev    next >
Text File  |  1996-12-09  |  17KB  |  529 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                  Version 9 of the Icon Compiler
  8.  
  9.                         Ralph E. Griswold
  10.     Department of Computer Science, The University of Arizona
  11.  
  12.  
  13. 1.__Introduction
  14.  
  15.    There are two forms of the implementation of Icon, an inter-
  16. preter and a compiler. The interpreter gets a program into execu-
  17. tion quickly and is recommended for program development, debug-
  18. ging, and most production situations. The compiler produces code
  19. that executes somewhat faster than interpreted code (a factor of
  20. 2 or 3 is typical), but the compiler requires a large amount of
  21. resources and is very slow in producing executable code. The com-
  22. piler is recommended only for small programs where execution
  23. speed is the paramount concern.
  24.  
  25.    In most respects, the Icon compiler is compatible with the
  26. Icon interpreter [1]. Most programs developed under the inter-
  27. preter run under the compiler with no changes.
  28.  
  29.    It takes considerably longer to compile an Icon program than
  30. it does to translate it for interpretation. In most cases, it is
  31. advisable to do program development using the interpreter and
  32. then produce a production version of the program with the com-
  33. piler.
  34.  
  35.    Since compiler support for some features of Icon makes it dif-
  36. ficult to produce fast executable code, these features are not
  37. available unless the compiler is told they are needed. This
  38. information is imparted by options to the compiler.
  39.  
  40.    The compiler performs a number of optimizations to improve
  41. run-time performance. These optimizations can be disabled.
  42.  
  43.    The Icon compiler produces C code, which is then compiled and
  44. linked to produce an executable program.  Programs produced by
  45. the compiler stand alone and do not require a separate run-time
  46. system like the interpreter.
  47.  
  48.    Only the routines needed by a compiled program are included in
  49. its executable file. Consequently, the size of a compiled program
  50. depends to a considerable extent on the range of features it
  51. uses.
  52.  
  53.    The compiler itself requires a significant amount of memory.
  54. It must read a data base into memory, maintain a representation
  55. of the entire program, and perform analyses.  Type inference in
  56. particular may require a large amount of memory, depending on the
  57. nature of the program.  Icon programs on the order of several
  58. thousand lines may require several megabytes of memory to com-
  59. pile. In case a program does not compile with type inference
  60. enabled due to memory limitations or compiles slowly due to
  61.  
  62.  
  63.  
  64. IPD237a                       - 1 -              October 31, 1995
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. excessive paging, it may compile satisfactorily with type
  74. inferencing disabled.
  75.  
  76.    The C code produced by the compiler is relatively voluminous
  77. and may require a large amount of disk space.  Disabling all
  78. optimizations typically doubles the size of the generated C code.
  79.  
  80.    Although the Icon compiler has been tested extensively at the
  81. Icon Project, it has not yet been used by a large and diverse
  82. programming community.  Further use will certainly uncover bugs.
  83. If a compiled program appears to malfunction, first be sure it
  84. works properly with the Icon interpreter.  Then try enabling
  85. optional features. Finally, try disabling all optimizations.
  86. Report bugs to the Icon Project.  Include enough information,
  87. including the program and data, so that the problem can be repli-
  88. cated.
  89.  
  90.    The next section describes how to run programs with the Icon
  91. compiler.  The last section describes differences in language
  92. features between the compiler and interpreter.
  93.  
  94.  
  95. 2.__Running_the_Compiler
  96.  
  97.    The Icon compiler is invoked with the command
  98.  
  99.         iconc [ options ] files [ -x [ args ] ]
  100.  
  101. where options can be any of the following:
  102.  
  103.   -c      stop compilation after producing C code
  104.   -e file redirect standard error output to file
  105.   -f s    enable features as indicated by the letters in s
  106.             a  - all, equivalent to delns
  107.             d  - enable debugging features, including the effect
  108.                of -f n (see below)
  109.             e  - enable error conversion
  110.             l  - enable large-integer arithmetic
  111.             n  - produce code that keeps track of line numbers
  112.                and file names in the source code
  113.             s  - enable full string invocation
  114.   -m      preprocess each source file with the m4 preprocessor
  115.                (UNIX only)
  116.   -n s    disable specific optimizations. These are indicated by the
  117.                letters in s:
  118.             a  - all, equivalent to cest
  119.             c  - control flow optimizations other than switch
  120.                statement optimizations
  121.             e  - expand operations in-line when reasonable
  122.                (keywords are always put in-line)
  123.             s  - optimize switch statements associated with
  124.             t  - type inference
  125.   -o file use file as the name of the executable file
  126.   -p arg  pass arg on to the C compiler used by iconc
  127.  
  128.  
  129.  
  130. IPD237a                       - 2 -              October 31, 1995
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.   -r path use the run-time system at path.
  140.   -s      suppress informative messages from the compiler
  141.   -t      enable debugging features as for -f d and initialize &trace to -1
  142.   -u      issue warning messages for undeclared identifiers in the program
  143.   -v i    set verbosity level of informative messages to i
  144.   -C prg  have iconc use the C compiler given by prg
  145.  
  146. File_Names
  147.  
  148.    One or more source file names must be specified. If a name has
  149. no suffix, .icn is appended. Otherwise, the name must already
  150. have a suffix of .icn. The argument ``-'' indicates that the
  151. source should be read from standard input. If the -o option is
  152. not used, the name of the executable file is constructed from the
  153. name of the first source file; stdin is used for ``-''. The com-
  154. piler produces a C program source file and a C include file as
  155. intermediate files. The names of these files are constructed from
  156. the name of the executable file.  For example,
  157.  
  158.         iconc prog.icn
  159.  
  160. creates prog.c and prog.h. These files subsequently are deleted
  161. unless the -c option is specified. In any event, any previous
  162. versions of prog.c and prog.h are overwritten.
  163.  
  164. Options
  165.  
  166.    See Section 3 for a description of features enabled by the -f
  167. options.  Use of these features may reduce the optimizations per-
  168. formed by the compiler.
  169.  
  170.    The -p option passes its argument to the C compiler. For exam-
  171. ple,
  172.  
  173.         iconc -p "-w"
  174.  
  175. might be used to suppress warning messages.  -p options accumu-
  176. late; -p "" clears the list of options, including the initial set
  177. of standard options.
  178.  
  179.    The -r option allows specification of the location of the
  180. directory that contains files needed by iconc. This overrides the
  181. default location.  The path argument must be terminated by a
  182. slash, as in
  183.  
  184.         iconc -r /usr/icon/lib/
  185.  
  186.  
  187.    The -v option controls the level of detail of iconc's informa-
  188. tive messages. -v 0 is the same as -s.  -v 1 is the default
  189. behavior.  Presently -v 2 and -v 3 only affect messages during
  190. type inferencing and are useful for monitoring its progress on
  191. large programs.  -v 2 causes a dot to be written for each itera-
  192. tion of type inferencing. -v 3 writes an indication of the amount
  193.  
  194.  
  195.  
  196. IPD237a                       - 3 -              October 31, 1995
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205. of information found in each iteration of type inferencing.
  206.  
  207.    The -C option can be used to override the default C compiler
  208. used by iconc. It is possible, although unlikely, that using a
  209. different C compiler than the one expected when iconc is built
  210. may produce code incompatibilities.
  211.  
  212.    As noted earlier, the -n t option sometimes is needed when
  213. compiling very large programs. The other -n options are used
  214. mostly for debugging the compiler.
  215.  
  216.    Disabling control-flow optimizations by -n c may result in
  217. unreachable C code and corresponding warning messages when it is
  218. compiled. Such messages may be annoying, but they can safely be
  219. ignored.  Occasionally unreachable C code may occur even with
  220. control-flow optimizations. This may indicate unreachable Icon
  221. code.
  222.  
  223. Environment_Variables
  224.  
  225.    The compiler determines the definition of a run-time operation
  226. from an operation data base. It links any needed routines from
  227. the link library associated with the data base.  The compiler
  228. supports a search chain of these data bases and libraries. When
  229. searching a chain of data bases, it uses the first definition for
  230. an operation that it encounters.  The environment variable DBLIST
  231. contains a blank separated list of data bases to be searched
  232. before the standard one.  (The standard data base can be changed
  233. with the -r option.) An alternate data base may be placed in the
  234. search chain to provide new operations or to override standard
  235. operations.
  236.  
  237.    The environment variable LPATH is used to specify paths to
  238. search for linked Icon source files. See the information on link-
  239. ing files in Section 3.
  240.  
  241. Automatic_Execution
  242.  
  243.    The -x option causes the compiled program to be executed
  244. automatically.  Arguments to the program can be specified after
  245. the -x option, which must appear last. For example,
  246.  
  247.         iconc prog -x test.log test.out
  248.  
  249. compiles and runs prog.icn with the arguments test.log and
  250. test.out.
  251.  
  252.  
  253. 3.__Differences_in_Language_Features
  254.  
  255.    The compiler is designed to be compatible with the interpreter
  256. for Version 8.10 of Icon. This goal cannot be completely realized
  257. because several features of the language make optimizations dif-
  258. ficult. Those features that cause problems and are not considered
  259.  
  260.  
  261.  
  262. IPD237a                       - 4 -              October 31, 1995
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271. essential to the language have either been removed or made avail-
  272. able only through compiler options.
  273.  
  274.    Debugging, string invocation, linking code from other Icon
  275. programs, and external functions are handled somewhat differently
  276. in the compiler from the way they are handled in the interpreter.
  277. These differences are discussed in the following sections.
  278.  
  279. Large_Integers
  280.  
  281.    The -f l option enables large integer support.  This allows
  282. the use of large integer literals and allows arithmetic expres-
  283. sions to use and produce large integer values. When this option
  284. is used, iconc produces code that is somewhat less efficient for
  285. arithmetic on ordinary integer values. This option may only be
  286. used with a run-time system that supports large integers. On most
  287. platforms, large integer support is the default; if large
  288. integers are not supported, iconc issues a warning and ignores
  289. the option.
  290.  
  291. Debugging_Features
  292.  
  293.    Several features of Icon provide debugging facilities.  These
  294. features may require the generation of additional or more complex
  295. code.  They normally are disabled, but they can be enabled by the
  296. -f d compiler option.  An attempt to use a debugging function or
  297. keyword in a program where the compiler has not generated code to
  298. support it generally results in run-time error 402, program not
  299. compiled with debugging option.
  300.  
  301.    The debugging facility in the compiler includes the printing
  302. of file names and line numbers with error messages and the print-
  303. ing of a procedure call trace-back when an error occurs. Even
  304. when a program is compiled with full debugging features enabled,
  305. there is no symbolic representation of the offending expression
  306. at the end of the trace-back.  The other operations falling under
  307. the heading of debugging features are:
  308.  
  309.         display()
  310.         name()
  311.         variable()
  312.         &level
  313.         &trace
  314.         &line
  315.         &file
  316.  
  317.  
  318.    The -f n option enables limited debugging features. These are
  319. &line, &file, and the printing of line numbers and file names in
  320. error messages.
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. IPD237a                       - 5 -              October 31, 1995
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. String_Invocation
  338.  
  339.    In the presence of string invocation, the compiler makes no
  340. attempt to infer what might be invoked. To fully support string
  341. invocation in the absence of other information, the compiler must
  342. link run-time routines for every operation.  This results in a
  343. large executable file.  String invocation is very useful in some
  344. programs, but it is not a heavily used feature. For these rea-
  345. sons, the compiler only supports string invocation to the extent
  346. explicitly requested by the programmer.
  347.  
  348.    There are two ways for the programmer to enable support for
  349. string invocation. The -f s option makes all operations available
  350. for string invocation.  Alternately, more selective control is
  351. possible using a new language feature, the invocable declaration.
  352. The syntax for this declaration is
  353.  
  354.         invocable-declaration ::= invocable operation {, operation }*
  355.  
  356.  
  357.         operation ::=string-literal  |
  358.                 string-literal : integer-literal  |
  359.                 all
  360.  
  361. Each string-literal is the string representation of an operation
  362. that might be invoked with string invocation. This may be a pro-
  363. cedure, a record constructor, a built-in function, or an opera-
  364. tor. For operators, the integer-literal indicates the number of
  365. arguments for the operator.  If it is missing, all operators
  366. using that operator symbol (typically unary and binary versions)
  367. are made available. all indicates that all operations must be
  368. available for string invocation. For example, the following
  369. declaration indicates that binary +, binary and unary -, and
  370. write may be invoked with string invocation.
  371.  
  372.         invocable "+":2, "-", "write"
  373.  
  374.  
  375.    There are some minor differences between string invocation in
  376. the compiler and in the interpreter. In the compiler, arguments
  377. to built-in operations are not automatically dereferenced, while
  378. they are in the interpreter. This means that string invocation on
  379. operations that make use of variables can produce different
  380. results in the two systems.  For example, string invocation on
  381. assignment performs the assignment in the compiler, but produces
  382. a run-time error in the interpreter.
  383.  
  384.    There are three additions to string invocation in the com-
  385. piler. The string [...] represents list creation; it takes a
  386. variable number of arguments.  The compiler treats & as an ordi-
  387. nary operator, so it is available for string invocation.  In both
  388. the interpreter and the compiler, the string ... represents the
  389. ternary operation to-by. The interpreter implements to as a
  390. short-hand notation for to-by with a third argument of 1, so
  391.  
  392.  
  393.  
  394. IPD237a                       - 6 -              October 31, 1995
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403. string invocation is not available for binary to.  The compiler,
  404. on the other hand, implements to as a separate operation, and ...
  405. can be used in string invocation on two arguments.
  406.  
  407.    If string invocation is attempted on an operation and there is
  408. no request to make it available, invocation may be unable to
  409. locate the operation and issue run-time error 106, procedure or
  410. integer expected. Because string invocation is under programmer
  411. control rather than being an Icon configuration option, it is no
  412. longer listed in &features.
  413.  
  414.    The preceding discussion of string invocation also applies to
  415. the use of the built-in function proc.
  416.  
  417. External_Functions
  418.  
  419.    A search list of data bases/libraries combined with the
  420. features of the compiler's run-time implementation language [2]
  421. make it easy to call many C functions from within Icon. All that
  422. is required is a built-in function that converts between Icon and
  423. C values, and calls the C function. The call is typically speci-
  424. fied as in-line code.  The built-in function may be given the
  425. same name as the C function.  The function is then added to a
  426. data base/library in the search list.  The external function
  427. mechanism of the interpreter is not supported.
  428.  
  429. Linking_Source_Files
  430.  
  431.    The compiler supports the link declaration, but it works dif-
  432. ferently than it does in the interpreter where it causes ucode
  433. files to be linked into the icode file. There are no ucode files
  434. in the compiler; instead the link declaration works on source
  435. files. It takes the file names from the link declaration, adds
  436. .icn suffixes, and compiles the files as if they had been speci-
  437. fied on the command line. The source files are located using
  438. paths specified with the LPATH environment variable; this is
  439. analogous to the use of the IPATH environment variable in the
  440. interpreter.
  441.  
  442. Error_Conversion
  443.  
  444.    The -f e option allows the use of &error to enable the conver-
  445. sion of run-time errors into failure. Unless -f e is specified,
  446. the value of &error has no effect, and run-time errors are not
  447. converted to failure.
  448.  
  449. References
  450.  
  451.  
  452. 1. R. E. Griswold and M. T. Griswold, The Icon Programming
  453.    Language, Prentice-Hall, Inc., Englewood Cliffs, NJ, second
  454.    edition, 1990.
  455.  
  456.  
  457.  
  458.  
  459.  
  460. IPD237a                       - 7 -              October 31, 1995
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469. 2. K. Walker, A Tutorial on Adding Functions to the Icon Run-Time
  470.    System, The Univ. of Arizona Icon Project Document IPD173,
  471.    1991.
  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. IPD237a                       - 8 -              October 31, 1995
  527.  
  528.  
  529.