Update the changelog
[opencv] / apps / Hawk / CVEiCL / EiC / eic.man
1 .TH EiC 1 "25 March 1999"\r
2 .SH NAME\r
3 \r
4 eic - An embeddable/extensible interactive bytecode C interpreter\r
5 \r
6 \r
7 .SH SYNOPSIS\r
8 \r
9 \fB eic [-Ipath] [-Dname[=var]] -[hHvVcCrR] [file] [fileargs] \fP\r
10 \r
11 .SS Options\r
12 \r
13 C preprocessor directives:\r
14    -Ipath      search for include files in path\r
15    -Dname      define a symbolic name to the value 1\r
16    -Dname=var  define a symbolic name to the value var\r
17                     Note, there is no spaces allowed\r
18 EiC directives:\r
19    -h -H       causes this usage to be displayed\r
20    -v -V       print EiC's Log information\r
21    -p          showline\r
22    -P          show path of include files\r
23    -t -T       turns trace on\r
24    -c -C       turns timer on\r
25    -e          echo HTML mode\r
26    -r          restart EiC. Causes EiC to be re initiated\r
27                        from the contents of EiChist.lst file\r
28   -R          same as `r', but prompts the user to accept\r
29                        or reject each input line first\r
30   -s -S       run silently\r
31   -f          run in script mode\r
32   -n          no history file\r
33   -N          don't use any startup.h files\r
34   -A          Non-interactive-mode\r
35   file        EiC will execute `file' and then stop; for example:\r
36                       % eic foo.c \r
37   fileargs    command line arguments, which get passed onto file\r
38 \r
39 \r
40 .SH BASICS\r
41 \r
42 To exit EiC enter `:exit', that is:\r
43 \r
44   EiC >  :exit\r
45 \r
46 \r
47 .SH DESCRITION\r
48 \r
49 EiC can be run in several different modes: (1) interactively, (2)\r
50 non-interactively (3) in scripting mode and (4) it can be embedded in other\r
51 systems.\r
52 \r
53 .SH EiC's INTERACTIVE MODE\r
54 \r
55 In interactive mode, the user enters commands, or immediate commands, at the\r
56 EiC prompt. Each immediate instruction produces a type, even if the type is\r
57 void; as for example, C statements, declarations etc. All resulting type\r
58 values are displayed:\r
59 \r
60 .Sx 3\r
61   EiC 1> 3*55.5;\r
62           166.5\r
63   EiC 2> "hello, world!";\r
64           hello, world!\r
65   EiC 3> int i;\r
66           (void)\r
67   EiC 4> for(i=0;i<10;i++);\r
68           (void)\r
69   EiC 5> i;\r
70           10\r
71   EiC 6> struct {int a; double b[3];} ab = { 5,{0,1,2}};\r
72           (void)\r
73   EiC 7> ab;\r
74           {5,Array}\r
75   EiC 8> ab.a = 3;\r
76           3\r
77   EiC 9> ab.b[2];\r
78           2\r
79   EiC 10> #include <stdio.h>\r
80           (void)\r
81   EiC 11> printf("hello\\n");\r
82   hello\r
83           6\r
84 .Ex\r
85 \r
86 .SH EiC IS POINTER SAFE\r
87 \r
88 EiC is also pointer safe. This means EiC catches most types of array bound\r
89 violations; for example (for brevity, some output has been deleted):\r
90 \r
91 .Sx 3\r
92    EiC 1> int a[10], *p, i;\r
93    EiC 2> a[10];\r
94    READ: attempted beyond allowed access area\r
95 \r
96    EiC 3> p = &a[5];\r
97    EiC 4> p[-5];\r
98    EiC 5> p[-6];\r
99    READ: attempted before allowed access area\r
100  \r
101    EiC 6> p[4];\r
102    EiC 7> p[5];\r
103    READ: attempted beyond allowed access area\r
104  \r
105    EiC 8> *(p+100);\r
106    READ: attempted beyond allowed access area\r
107  \r
108    EiC 9> p = malloc(5*sizeof(int));\r
109    EiC 10> *(p+100);\r
110    READ: attempted beyond allowed access area\r
111  \r
112    EiC 11> for(i=0;i<100;i++) *p++ = i;\r
113    WRITE: attempted beyond allowed access area\r
114 .Ex\r
115 \r
116 \r
117 To detect array bound violations as efficiently as possible, EiC does not\r
118 concern it self with the values held or produced by pointers, it only\r
119 worries about address values when they are either referenced or\r
120 dereferenced:\r
121 \r
122 .Sx 3\r
123     EiC 1> int a, *p;\r
124     EiC 2> p = &a;\r
125     EiC 3> p+10;    // okay, no problems\r
126     EiC 4> *(p+10); // try to read or write to the address\r
127     READ: attempted beyond allowed access area\r
128 .Ex\r
129 \r
130 .SH EiC HOUSE KEEPING COMMANDS\r
131 \r
132 Besides parsing C or C preprocessor commands, EiC has it\r
133 own house keeping commands. House keeping commands are communicated\r
134 via lines beginning with a colon:\r
135 \r
136  EiC 1> :help\r
137 \r
138 .SH  EiC INTERACTIVE COMMAND SUMMARY\r
139 \r
140 .TP \r
141 \fB:-I path\fP       \r
142 Append path to the include-file search list.\r
143 .TP\r
144 \fB:-L\fP\r
145 List search paths.\r
146 .TP\r
147 \fB:-R path \fP\r
148 Remove path from the include-file search list.\r
149 .TP\r
150 \fB:clear fname\fP\r
151 Removes the contents of file fname from EiC.\r
152 .TP\r
153 \fB :exit\fP\r
154 Terminates an EiC session.\r
155 .TP\r
156 \fB :files\fP\r
157 Display the names of all included files.\r
158 .TP\r
159 \fB :files fname\fP\r
160 Summarize the contents of the included file `fname'.\r
161 .TP\r
162 \fB :help\fP\r
163 Display summary of EiC commands.\r
164 .TP\r
165 \fB :history\fP\r
166 List the history of all input commands.\r
167 .TP\r
168 \fB :includes\fP\r
169 Display path of include files when loaded.\r
170 .TP\r
171 \fB :interpreter\fP\r
172 Execute input commands. By default it is on.\r
173 .TP\r
174 \fB :listcode\fP\r
175 List stack code.\r
176 .TP\r
177 \fB :listcode <linenums>\fP\r
178 List stack code with associated line numbers.\r
179 .TP\r
180 \fB :memdump\fP\r
181 Show potential memory leaks.\r
182 .TP\r
183 \fB :rm dddd\fP\r
184 Remove memory item dddd, which is a constant integer value.\r
185 .TP\r
186 \fB :rm f\fP\r
187 Removes f's definition from the symbol tables.\r
188 .TP\r
189 \fB :show f\fP\r
190 Shows type or  macro definition of `f'.\r
191 .TP\r
192 \fB :showline\fP\r
193 Show input line after macro expansion.\r
194 .TP\r
195 \fB :status\fP\r
196 Display the status of the toggle switches.\r
197 .TP\r
198 \fB :timer\fP\r
199 Time in seconds of execution.\r
200 .TP\r
201 \fB :trace\fP\r
202 Trace function calls and line numbers during code execution.\r
203 .TP\r
204 \fB :trace funcs\fP\r
205 Trace function calls only during code execution.\r
206 .TP\r
207 \fB :variables\fP\r
208 Display declared variables and interpreter-ed function names.\r
209 .TP\r
210 \fB :variables tags\fP\r
211 Display the tag identifiers.\r
212 .TP\r
213 \fB :variables <type-name>\fP\r
214 Display variables of type `type-name'. For example,\r
215 \r
216         EiC > :show float []\r
217 \r
218  will show all the variables that are declared to be an\r
219 array of floats\r
220 .TP\r
221 \fB :verbose\fP\r
222 Suppresses EiC's copyright and warning messages on start up.\r
223 \r
224  \r
225 \r
226 \r
227 .SH RUNNING EiC NON-INTERACTIVELY\r
228 \r
229 EiC can also be run non-interactively or in batch mode, where it is possible\r
230 to run C programs in a typical interpreter style. It can also handle\r
231 programs that accept command line arguments, as seen from the toy example in\r
232 main2.c:\r
233 \r
234 .Sx 3\r
235      #include <stdio.h>\r
236      int main(int argc, char **argv)\r
237      {\r
238          while(argc--)\r
239              printf("%s\n",*argv++);\r
240          return 0;\r
241      }\r
242 .Ex\r
243 \r
244 The first parameter, argc, holds the number of argument strings passed to\r
245 the program and is always at least one. The second parameter, argv, is an\r
246 array of unspecified size of pointers to the input strings, which the first\r
247 one will be the name of the program being executed:\r
248 \r
249 .Sx 3\r
250      % eic main2.c 123 hello -Dworld this.and.that\r
251      main2.c\r
252      123\r
253      hello\r
254      -Dworld\r
255      this.and.that\r
256 \r
257 .Ex\r
258 .SH EiC's SCRIPTING LANGUAGE\r
259 \r
260 In non-interactive mode, EiC runs generally like a typical interpreter,\r
261 accepting input from a complete C program. However, EiC is also a scripting\r
262 language. Below is an example of an EiC script, called hello.eic:\r
263 \r
264 .Sx 3\r
265      #!/usr/local/bin/eic -f\r
266 \r
267      #include <stdio.h>\r
268      printf(" ** Hello from EiC's script mode. **\n");\r
269 .Ex\r
270 \r
271 The -f command-line switch, informs EiC to run in script mode. In script\r
272 mode, EiC will treat all lines beginning with `#' and which cannot be\r
273 interpreted as a preprocessor directive as a comment. To run the above\r
274 script and assuming that it's executable (chmod +x hello.eic):\r
275 .Sx 3\r
276      % hello.eic\r
277       ** Hello from EiC's script mode. **\r
278      %\r
279 .Ex\r
280 \r
281 Another example of a more extensive EiC script is given in script1.eic:\r
282 \r
283 .Sx 3\r
284   1  #!/usr/local/bin/eic -f\r
285   2  #include <stdio.h>\r
286   3\r
287   4  // example of control of flow\r
288   5  int i;\r
289   6  int isqr(int x) { return x*x; }\r
290   7  for(i=0;i<4;i++)\r
291   8     printf("%d^2 =  %d\n",i,isqr(i));\r
292   9  switch(i) {\r
293  10     case 4: printf(" good\n\n"); break;\r
294  11     default: printf(" bad\n\n");\r
295  12  }\r
296  13  // example of some file stuff;\r
297  14  // read in some tools\r
298  15  #include "tools/nxtString.c"\r
299  16  FILE *fp = fopen(_Argv[0],"r");\r
300  17  char *p;\r
301  18  while((p=nxtString(fp)))\r
302  19          printf("%s ",p);\r
303  20  fclose(fp);\r
304  21  printf("\n\n");\r
305  22  // further example of using command line args\r
306  23  if(_Argc) { // this is always true\r
307  24     int k=0;\r
308  25     printf("Processing command line arguments\n");\r
309  26     for(k=0;k<_Argc;k++) {\r
310  27        printf("%s\n",_Argv[k]);\r
311  28     }\r
312  29  } else\r
313  30     printf("OOPS, an internal error has occurred\n");\r
314 .Ex\r
315  \r
316 An EiC shell script is interpreted from the top to the bottom. First the\r
317 code is compiled to bytecode, in its entirety, and then run. After this,\r
318 control will be parsed to the main function if it exists. However, it is not\r
319 illegal to have a script that does not include the definition of a main\r
320 function. If the EiC directive :exit, which is the directive that terminates\r
321 an EiC interactive session, is present, it will cause the interpretation of\r
322 the script to halt at the position :exit is encounted, and nothing will have\r
323 happened other than having the code up to :exit operator compiled and parsed\r
324 - but it will not have been executed. Generally, the code for a function is\r
325 not executed until it is called, see line 8. Command line arguments are\r
326 passed into to the global variables _Argc and _Argv, see lines 16 and 23 to\r
327 30. For example:\r
328 \r
329 .Sx 3\r
330      % script1.eic  abc 123 -DHELP\r
331 .Ex\r
332 \r
333 Implies that:\r
334 \r
335 .Sx 3     _Argc = 4,                 _Argv[0] = "sript1.eic"\r
336      _Argv[1] = "abc"           _Argv[2] = "123"\r
337      _Argv[3] = "-DHELP"        _Argv[4] = NULL\r
338 \r
339 .Ex 3\r
340 \r
341 .SH EMBEDDING OR LINKING TO EiC\r
342 \r
343 To Link against EiC you first need to build the source distribution. Then\r
344 linking to EiC from aother programs is done by linking against the EiC\r
345 libraries (libeic and libstdClib) in EiC/lib. In the directory\r
346 EiC/main/examples there is an example program called embedEiC.c that links\r
347 to EiC. Build and run it from the EiC/main/examples directory by entering\r
348 (assuming EiC has been installed in /usr/local/EiC):\r
349 \r
350 .Sx 3\r
351      % gcc embedEiC.c -L/usr/local/EiC/lib -leic -lstdClib -lm\r
352      % a.out\r
353 .Ex 3\r
354 \r
355 For communicating commands to EiC from another program there are two\r
356 functions supplied:\r
357 \r
358      int EiC_run(int argc, char **argv);\r
359 \r
360 and\r
361 \r
362      void EiC_parseString(char *command, ...);\r
363 \r
364 The EiC_run function is used to run C source files. The EiC_parseString\r
365 function is used to pass C or preprocessor commands to EiC via a string,\r
366 such as:\r
367 \r
368 .Sx 3\r
369      EiC_parseString("#include <stdio.h>");\r
370      EiC_parseString("int a = 10,i;");\r
371      EiC_parseString("for(i=0;i<a;i++)"\r
372                      "       printf(\\"%%d\\\\n\\",i);");\r
373 .Ex\r
374 \r
375 At present the main facility for sharing data between EiC and other\r
376 applications is via the address operator @:\r
377 \r
378      int a @ dddd;\r
379 \r
380 The above defines a to be an integer and is stored at address dddd, which\r
381 must be an integral constant. The constant address dddd is not simply an\r
382 address conjured up. Its purpose is to enable access to data, or even\r
383 functions, defined in compiled code.\r
384 \r
385 When applied to function definitions, the limitation at this stage is that\r
386 the function must take void arguments and return void:\r
387 \r
388           void foo(void) @ dddd;\r
389 \r
390 The above defines foo to be a builtin function located at address dddd. For\r
391 example:\r
392 \r
393 .Sx 3\r
394   int foo[5] = {1,2,3,4,5};\r
395   void fooey(void) {printf("fooey called\n");}\r
396           ....\r
397   EiC_parseString("int foo[5] @ %ld;",(long)foo);\r
398   EiC_parseString("void fooey(void) @ %ld;",(long)fooey);\r
399 .Ex\r
400 \r
401 Further, int foo[5] @ 1256; defines foo to be an array of 5 ints mapped at\r
402 the specified virtual address and the usual pointer safety rules apply; that\r
403 is, foo[5]; will be caught as an illegal operation.\r
404 \r
405 Also, you can pass in data to EiC via setting variables and you can get EiC\r
406 to output data to a file. In a future release of EiC, more facilities are\r
407 expected to be added for sharing data between EiC and its embedding system.\r
408 \r
409 With respect to EiC_run, to run the file "myfile.c" and pass it the command\r
410 line arguments "hello" and "world", the following sequence of commands would\r
411 be used.\r
412 \r
413 .Sx 3\r
414      char *argv[] = {"myfile.c", "hello", "world"};\r
415      int  argc = sizeof(argv)/sizeof(char*);\r
416      EiC_run(argc, argv);\r
417 .Ex\r
418 .SH EiC vs C\r
419 \r
420 Because EiC can be run interactively, it differs from C in several ways. In\r
421 this section I will outline what is currently missing from EiC and how EiC\r
422 differs from ISO C.\r
423 \r
424 Although, EiC can parse almost all of the C programming language, right up\r
425 front it is best to mention what is currently lacking or different:\r
426 \r
427 .TP\r
428 \fB1.\fP   \r
429 EiC is pointer safe. It detects many classes of memory read and write\r
430 violations. Also, to help in interfacing compiled library code to EiC,\r
431 EiC uses the optional pointer-qualifiers safe and unsafe.\r
432 \r
433 .TP\r
434 \fB4.\fP   \r
435 Structure  bit fields are not supported.\r
436 \r
437 .TP\r
438 \fB5.\fP   \r
439 While structures and unions can be returned from and passed by value to\r
440 functions, it is illegal in EiC to pass a structure or a union to a\r
441 variadic function (that is, a function that takes a variable number of\r
442 arguments):\r
443 \r
444 .Sx 3\r
445  EiC 1> struct stag {int x; double y[5];} ss;\r
446  EiC 2> void foo(const char *fmt, ...);\r
447  EiC 3> foo("",ss);\r
448  Error: passing a struct/union to variadic function foo\r
449 .Ex\r
450 \r
451 .TP\r
452 \fB6.\fP \r
453 The C concept of linkage is not supported. This is because, EiC does\r
454 not export identifiers to a linker - as does a true C compiler. EiC\r
455 works from the concept of a single translation unit.\r
456 \r
457 .TP\r
458 \fB7.\fP   \r
459 EiC does not parse preprocessor numbers , which aren't valid numeric\r
460 constants; for example, 155.6.8, which is an extended floating point\r
461 constants, will cause an error.\r
462 \r
463 .TP\r
464 \fB8.\fP   \r
465 EiC supports both standard C like comments /* ... */ and C++ style\r
466 comments. Also, when EiC is run in script mode, it treats all lines\r
467 that start with `#' and which can't be interpreted as a preprocessor\r
468 directive as a comment.\r
469 \r
470 .TP\r
471 \fB9.\fP   \r
472 There are no default type specifiers for function return values. In EiC\r
473 it is illegal to not explicitly state the return type of a function:\r
474 \r
475 .Sx 3\r
476  foo() { ... } // error: missing return type \r
477  int foo() { ... } // correct, \r
478 .Ex\r
479 \r
480 .TP\r
481 \fB10.\fP  \r
482 In addition to function definitions and declarations with an empty\r
483 parameter list, EiC only supports prototype declarations and\r
484 definitions:\r
485 \r
486 .Sx 3\r
487  // Empty parameter list allowed \r
488  int foo(); \r
489 \r
490  // Illegal: old style C declaration\r
491  int f(value) int value { ... } \r
492 \r
493  // Allowed, prototype declaration\r
494  int f(int); \r
495 \r
496  // Allowed, full prototype declaration\r
497  int f(int value); \r
498 .Ex\r
499 \r
500 .TP\r
501 \fB11.\fP  \r
502 EiC does not support trigraph sequences, wide characters or wide\r
503 strings: nor does it support the standard header <locale.h>.\r
504 \r
505 .TP\r
506 \fB12.\fP  \r
507 EiC's preprocessor lacks the #line directive.\r
508 \r
509 .TP\r
510 \fB13.\fP  \r
511 For convenience, EiC allows the #include directive to have an extra\r
512 form, which permits the parsing of a token-sequence in the form\r
513 #include filename; that is, without enclosing double quotes or angled\r
514 brackets.\r
515 \r
516 .TP\r
517 \fB14.\fP  \r
518 Besides parsing preprocessor directives or C statements, EiC also\r
519 parses its own internal house keeping language. House keeping commands\r
520 are communicated to EiC via lines that begin with a colon.\r
521 \r
522 \r
523 \r
524 .SH SEE ALSO\r
525 \r
526         http://www.anarchos.com/eic\r
527 \r
528 \r
529 \r
530 \r
531 \r
532 \r
533 \r
534 \r
535 \r