It is a two-pass compiler. The first pass processes all global declarations and produced an intermediate file “tmp000.bak”. The intermediate file which is used by the second pass, contains only the body of code. All declarations and comments are stripped out. All global names are known by the end of the first pass. The second pass reads the intermediate file, processes the body of code and generates i-code in the memory. At the end of successful compilation, the i-code is post-processed to improve its speed of execution. The buffer is written out with a header containing information necessary for an interpreter to check the validity of the executable code. The header is 16 bytes long and has the following format :
putInt(MAGIC);where putInt writes 2 bytes binary, hi byte first, MAGIC = 0x1abc, VER = 1 for this release, csize, dsize and psize are the size of code, data and the number of process consecutively.
putInt(VER);
putInt(csize);
putInt(dsize);
putInt(psize);
putInt(0);
putInt(0);
putInt(0);
The source code of compiler contains the following parts :
lexical analyser 300 linesThe compiler on PC is compiled by Turbo C v 2.0 and it is tested to work properly under DOS, MS Windows 3.11, MS Windows 95. The version on Sun Solaris is compiled by GNU C compiler and is tested to work under Solaris 2.3. As this is a simple recursive descent compiler, the compilation speed is reasonably fast. The source code of compiler are arranged as following :
parser 850 lines
code generator 150 lines
symbol table 250 lines
others (.h etc.) 200 lines
total approx. 1800 lines
compile.c, dcl.c, expr.c, head.c, icode.c, lex.c, stmt.c, symtab.c
The compiler accepts input source file (in R1) and produces an I-code file (also produces a readable version of I-code). The command line
c> compile test.txt
produces test.out (I-code file) and test.lst (readable I-code).
interpreter 330 linesand consisted of the following files :
process 300 lines
message 230 lines
timer 150 lines
others 80 lines
total approx. 1000 lines
interp.c, message.c, process.c, timer.c
The interpreter is implemented entirely in high level language eventhough the real-time facilities required an access to low-level functions. The system time is a 32-bit counter. It is incremented through the interrupt service routine of the underlying operating system. On PC, we use the interrupt vector 0x1c which has the frequency 18.2 Hz. On Unix, we use signal() via setitimer(). The frequency of interruption can be adjusted in microsecond unit. However, the actual granuality of the resolution of alarm time on Unix is platform-dependent. If we assume the timer ticks at 20 Hz., the 32-bit system time in the interpreter will last approximately 60,000 hours or about 7 years. This should be adequate for most applications.