1 .TH EiC 1 "25 March 1999"
\r
4 eic - An embeddable/extensible interactive bytecode C interpreter
\r
9 \fB eic [-Ipath] [-Dname[=var]] -[hHvVcCrR] [file] [fileargs] \fP
\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
19 -h -H causes this usage to be displayed
\r
20 -v -V print EiC's Log information
\r
22 -P show path of include files
\r
23 -t -T turns trace on
\r
24 -c -C turns timer on
\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
31 -f run in script mode
\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
37 fileargs command line arguments, which get passed onto file
\r
42 To exit EiC enter `:exit', that is:
\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
53 .SH EiC's INTERACTIVE MODE
\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
63 EiC 2> "hello, world!";
\r
67 EiC 4> for(i=0;i<10;i++);
\r
71 EiC 6> struct {int a; double b[3];} ab = { 5,{0,1,2}};
\r
79 EiC 10> #include <stdio.h>
\r
81 EiC 11> printf("hello\\n");
\r
86 .SH EiC IS POINTER SAFE
\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
92 EiC 1> int a[10], *p, i;
\r
94 READ: attempted beyond allowed access area
\r
99 READ: attempted before allowed access area
\r
103 READ: attempted beyond allowed access area
\r
106 READ: attempted beyond allowed access area
\r
108 EiC 9> p = malloc(5*sizeof(int));
\r
110 READ: attempted beyond allowed access area
\r
112 EiC 11> for(i=0;i<100;i++) *p++ = i;
\r
113 WRITE: attempted beyond allowed access area
\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
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
130 .SH EiC HOUSE KEEPING COMMANDS
\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
138 .SH EiC INTERACTIVE COMMAND SUMMARY
\r
142 Append path to the include-file search list.
\r
148 Remove path from the include-file search list.
\r
151 Removes the contents of file fname from EiC.
\r
154 Terminates an EiC session.
\r
157 Display the names of all included files.
\r
159 \fB :files fname\fP
\r
160 Summarize the contents of the included file `fname'.
\r
163 Display summary of EiC commands.
\r
166 List the history of all input commands.
\r
169 Display path of include files when loaded.
\r
171 \fB :interpreter\fP
\r
172 Execute input commands. By default it is on.
\r
177 \fB :listcode <linenums>\fP
\r
178 List stack code with associated line numbers.
\r
181 Show potential memory leaks.
\r
184 Remove memory item dddd, which is a constant integer value.
\r
187 Removes f's definition from the symbol tables.
\r
190 Shows type or macro definition of `f'.
\r
193 Show input line after macro expansion.
\r
196 Display the status of the toggle switches.
\r
199 Time in seconds of execution.
\r
202 Trace function calls and line numbers during code execution.
\r
204 \fB :trace funcs\fP
\r
205 Trace function calls only during code execution.
\r
208 Display declared variables and interpreter-ed function names.
\r
210 \fB :variables tags\fP
\r
211 Display the tag identifiers.
\r
213 \fB :variables <type-name>\fP
\r
214 Display variables of type `type-name'. For example,
\r
216 EiC > :show float []
\r
218 will show all the variables that are declared to be an
\r
222 Suppresses EiC's copyright and warning messages on start up.
\r
227 .SH RUNNING EiC NON-INTERACTIVELY
\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
236 int main(int argc, char **argv)
\r
239 printf("%s\n",*argv++);
\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
250 % eic main2.c 123 hello -Dworld this.and.that
\r
258 .SH EiC's SCRIPTING LANGUAGE
\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
265 #!/usr/local/bin/eic -f
\r
268 printf(" ** Hello from EiC's script mode. **\n");
\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
277 ** Hello from EiC's script mode. **
\r
281 Another example of a more extensive EiC script is given in script1.eic:
\r
284 1 #!/usr/local/bin/eic -f
\r
285 2 #include <stdio.h>
\r
287 4 // example of control of flow
\r
289 6 int isqr(int x) { return x*x; }
\r
291 8 printf("%d^2 = %d\n",i,isqr(i));
\r
293 10 case 4: printf(" good\n\n"); break;
\r
294 11 default: printf(" bad\n\n");
\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
301 18 while((p=nxtString(fp)))
\r
302 19 printf("%s ",p);
\r
305 22 // further example of using command line args
\r
306 23 if(_Argc) { // this is always true
\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
313 30 printf("OOPS, an internal error has occurred\n");
\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
330 % script1.eic abc 123 -DHELP
\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
341 .SH EMBEDDING OR LINKING TO EiC
\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
351 % gcc embedEiC.c -L/usr/local/EiC/lib -leic -lstdClib -lm
\r
355 For communicating commands to EiC from another program there are two
\r
356 functions supplied:
\r
358 int EiC_run(int argc, char **argv);
\r
362 void EiC_parseString(char *command, ...);
\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
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
375 At present the main facility for sharing data between EiC and other
\r
376 applications is via the address operator @:
\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
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
388 void foo(void) @ dddd;
\r
390 The above defines foo to be a builtin function located at address dddd. For
\r
394 int foo[5] = {1,2,3,4,5};
\r
395 void fooey(void) {printf("fooey called\n");}
\r
397 EiC_parseString("int foo[5] @ %ld;",(long)foo);
\r
398 EiC_parseString("void fooey(void) @ %ld;",(long)fooey);
\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
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
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
414 char *argv[] = {"myfile.c", "hello", "world"};
\r
415 int argc = sizeof(argv)/sizeof(char*);
\r
416 EiC_run(argc, argv);
\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
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
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
435 Structure bit fields are not supported.
\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
445 EiC 1> struct stag {int x; double y[5];} ss;
\r
446 EiC 2> void foo(const char *fmt, ...);
\r
448 Error: passing a struct/union to variadic function foo
\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
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
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
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
476 foo() { ... } // error: missing return type
\r
477 int foo() { ... } // correct,
\r
482 In addition to function definitions and declarations with an empty
\r
483 parameter list, EiC only supports prototype declarations and
\r
487 // Empty parameter list allowed
\r
490 // Illegal: old style C declaration
\r
491 int f(value) int value { ... }
\r
493 // Allowed, prototype declaration
\r
496 // Allowed, full prototype declaration
\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
507 EiC's preprocessor lacks the #line directive.
\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
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
526 http://www.anarchos.com/eic
\r