home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
156_01
/
c80v.c
< prev
next >
Wrap
Text File
|
1985-08-21
|
40KB
|
1,636 lines
/************************************************/
/* */
/* small-c compiler */
/* */
/* by Ron Cain */
/* and James Van Zandt */
/* */
/************************************************/
#define VERSION " 2 August 1984"
/* history...
2 Aug 84 Allocating symbol table and literal
pool from heap.
31 Jul 84 No GLOBAL directives for macros.
30 Jul 84 Input file extension capitalized.
29 Jul 84 Displaying input file names.
28 Jul 84 Getting file names and options from
command line.
14 Jul 84 outdec() is now recursive & smaller.
raise() not called, since ZMAC converts
to upper case. When profiling, the
appropriate GLOBAL statements are
automagically emitted.
28 Jun 84 Adding CR after GLOBAL statement.
25 Jun 84 In addglb(), generating GLOBAL
statement. Generating 9 character labels (so 1st 8
characters in a c symbol name are significant).
Allowing 800 bytes of literals per function.
2 Sept 83 In doreturn(), changed 'ccleavin'
to 'ccleavi'. Introduced 'leave'. 'numeric' &
'outbyte' optimized. Optimized: 'nch', 'gch', 'keepch',
'streq', 'astreq', 'raise'.
1 Sept 83 Initializing firstfct & lastfct
after calling ask(). Trace & profile enabled together.
27 Aug 83 Allowing 3 bytes for call count.
26 Aug 83 renamed: leaving => ccleavi,
registe => ccregis. Added code to link the call count
cells (main, header, trailer, newfunction).
22 Aug 83 converted "," to "'", corrected
loading of name pointer.
21 Aug 83 Trace and profile are available.
Using clibv.h & a:float.h
1 Aug 83 6 function names are now
"nospread", A now set to # words on stack rather
than adding another parameter.
29 Mar 83 "callfunction" now reserves
symsize bytes rather than namesize bytes for sym.
When "printf" is called, the top word on the stack
points to the first argument.
7 Mar 83 "callfunction" now adds pointer
to first argument for nospread functions. "nospread"
introduced (returns true only for "printf").
10 Nov 82 Rewrote "an" for speed.
24 Oct 82 In "preprocess", searching macro
table only with strings beginning with alpha. (Allows
long numeric literals.) Rewrote "alpha" for speed.
10 Oct 82 Updated date in signon message.
Coersing function values to proper type.
4 Sept 82 Generating colons again.
3 Sep 82 "#includ"ing floating point
library.
30 Aug 82 Changed "number" calling sequence
back. Colons are optional.
12 Aug 82 Changed "number" calling sequence.
11 Aug 82 Allowing typed function
declarations.
7 Aug 82 Correct length of double in
local variables, preserving calling addr when
calling through TOS & using double argument.
5 Aug 82 Started installing floating point
3 Aug 82 generating no colons
after labels. Generating only 7 character labels.
20 Jul 82 Removed the unused
variable "iptr".
18 Jul 82 Changed comment
recognizer per J. E. Hendrix (ddj n56 p6).
17 Jul 82 Implemented \" and
\' sequences. Corrected newfunc & getarg per
P. L. Woods (ddj n52 p32) & J. E. Hendrix (ddj n56 p6).
14 Jul 82 "#include"ing
clibv.asm & c80v-2.c
28 Jun 82 Skipping first byte
in macro table, so index won't be zero.
27 Jun 82 Masking out high
order bits of characters extracted from
a symbol table entry.
21 Jun 82 Dumping literals
at end of each function, per Rodney Black
(DDJ n61 p51).
19 Jun 82 Updated symtabsiz.
Updated dumpglbs to handle new symbol table.
Placing macro names in global symbol table,
using smaller macro table.
16 Jun 82 using hash table
for global symbols.
18 Apr 81 Changed names so
first 5 characters are unique:
heir10 => heira heir11 => heirb
input2 => inpt2 errorsum => errsum
*/
#include iolib.h
#include float.h
#define BANNER "* * * Small-C V1.2 * * *"
#define AUTHOR " By Ron Cain and James Van Zandt"
/* Define system dependent parameters */
/* Stand-alone definitions */
#define NULL 0
#define EOL 13
/* UNIX definitions (if not stand-alone) */
/* #include <stdio.h> */
/* #define EOL 10 */
/* Define the symbol table parameters */
#define SYMSIZ 14
#define SYMTBSZ 8008
/* =14*(NUMGLBS+60) */
#define NUMGLBS 512
#define MASKGLBS 511
/* formerly 300 globals */
#define STARTGLB symtab
#define ENDGLB STARTGLB+NUMGLBS*SYMSIZ
#define STARTLOC ENDGLB+SYMSIZ
#define ENDLOC symtab+SYMTBSZ-SYMSIZ
/* Define symbol table entry format */
#define name 0
#define ident 9
#define type 10
#define storage 11
#define offset 12
/* System wide name size (for symbols) */
#define namesize 9
#define namemax 8
/* Define possible entries for "ident" */
#define variable 1
#define array 2
#define pointer 3
#define function 4
#define MACRO 5
/* added 6/19/82, JRVZ */
/* Define possible entries for "type" */
#define cchar 1
#define cint 2
#define DOUBLE 3
/* Define possible entries for "storage" */
#define statik 1
#define stkloc 2
/* Define the "while" statement queue */
#define wqtabsz 100
#define wqsiz 4
#define wqmax wq+wqtabsz-wqsiz
/* Define entry offsets in while queue */
#define wqsym 0
#define wqsp 1
#define wqloop 2
#define wqlab 3
/* Define the literal pool */
#define litabsz 1000
/* formerly 2000 */
#define litmax litabsz-1
/* Define the input line */
#define linesize 80
#define linemax linesize-1
#define mpmax linemax
/* Define the macro (define) pool */
#define macqsize 500
/* formerly 1000 JRVZ 6/19/82 */
#define macmax macqsize-1
/* Define statement types (tokens) */
#define stif 1
#define stwhile 2
#define streturn 3
#define stbreak 4
#define stcont 5
#define stasm 6
#define stexp 7
/* Define how to carve up a name too long for the assembler */
#define ASMPREF 8
#define ASMSUFF 0
/* Now reserve some storage words */
char *symtab; /* symbol table */
char *glbptr,*locptr; /* ptrs to next entries */
int wq[wqtabsz]; /* while queue */
int *wqptr; /* ptr to next entry */
char *litq; /* literal pool */
int litptr; /* ptr to next entry */
char macq[macqsize]; /* macro string buffer */
int macptr; /* and its index */
char line[linesize]; /* parsing buffer */
char mline[linesize]; /* temp macro buffer */
int lptr,mptr; /* ptrs into each */
/* Misc storage */
int nxtlab, /* next avail label # */
litlab, /* label # assigned to literal pool */
Zsp, /* compiler relative stk ptr */
undeclared, /* # function arguments
not yet declared jrvz 8/6/82 */
ncmp, /* # open compound statements */
errcnt, /* # errors in compilation */
errstop, /* stop on error gtf 7/17/80 */
eof, /* set non-zero on final input eof */
input, /* iob # for input file */
output, /* iob # for output file (if any) */
inpt2, /* iob # for "include" file */
glbflag, /* non-zero if internal globals */
ctext, /* non-zero to intermix c-source */
cmode, /* non-zero while parsing c-code */
/* zero when passing assembly code */
lastst, /* last executed statement type */
mainflg, /* output is to be first asm filegtf 4/9/80 */
saveout, /* holds output ptr when diverted to console */
/* gtf 7/16/80 */
fnstart, /* line# of start of current fn.gtf 7/2/80 */
lineno, /* line# in current file gtf 7/2/80 */
infunc, /* "inside function" flag gtf 7/2/80 */
savestart, /* copy of fnstart " " gtf 7/16/80 */
saveline, /* copy of lineno " " gtf 7/16/80 */
saveinfn, /* copy of infunc " " gtf 7/16/80 */
trace, /* nonzero if traceback info needed
jrvz 8/21/83 */
profile, /* nonzero if profile needed */
caller, /* stack offset for caller links...
local[caller] points to name of current fct
local[caller-1] points to link for calling fct,
where local[0] is 1st word on stack after ret addr */
firstfct, /* label for 1st function */
lastfct, /* label for most recent fct jrvz 8/83 */
fname; /* label for name of current fct */
char *currfn, /* ptr to symtab entry for current fn. gtf 7/17/80 */
*savecurr; /* copy of currfn