home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource3
/
156_01
/
c80v_2.c
< prev
next >
Wrap
Text File
|
1985-08-21
|
31KB
|
1,383 lines
/* >>>>>>> start of cc5 <<<<<<< */
/*
history...
14 Jul 84 When profiling, not generating ':'
after label equated to zero.
27 Jun 84 No longer generating ENDDATA label
at end of program (duty taken over by ZLINK).
25 Jun 84 When profiling, the equate has
the ZMAC syntax. '\l' added.
10 Oct 83 Converted DB, DW, and DS to DEFB,
DEFW, and DEFS. Added colon after ENDDATA.
1 Sept 83 calling nl() before outputting
call to ccalls().
26 Aug 83 added code to link call counts
(header, trailer)
29 Jun 83 addim() now calls outasm
rather than ot to print the literal.
7 Mar 83 prefix "&" no longer accepts function
name.
1 Feb 83 Declaring "enddata" at the end
of the allocated memory (=top of heap).
29 Jan 83 prefix "&" can return address of
function.
27 Oct 82 Generating no extra nl() after
"dstore", updating Zsp in same routines that generate
calls to floating point routines.
23 Oct 82 rewrote value-returning expr
in "fnumber".
10 Oct 82 Corrected Zsp accounting.
Moved type coersion to a subroutine. Checking operand
types for integer operations.
9 Oct 82 Automatically widening before:
+ - * / < <= == != >= >. Short-circuit evaluation of
DOUBLE tests.
6 Oct 82 Generating calls to "qfloat" rather
than "qqfloat".
11 Sept 82 Generating no POP DE instructions
for most operators.
5 Sept 82 "constant" doing explicit "dload"
for floating constants.
3 Sep 82 Accepting floating constants.
31 Aug 82 Performing monadic "-" on
floating point variables.
30 Aug 82 Automatic conversions to and
from DOUBLE on assignments. Adjusting stack after
double precision comparisons. Comparisons now yield
integers.
29 Aug 82 monadic "&" now generates
a correct variable name.
12 Aug 82 Corrected "number" to return
type correctly.
11 Aug 82 Rewrote dbltest.
9 Aug 82 Started installing floating
point comparisons.
7 Aug 82 Modified for floating point
expressions.
5 Aug 82 Converted JZ to JP Z,
Converted several calls to ot() to outasm() to
eliminate unwanted tabs. Added some comments.
3 Aug 82 Corrected immed(), removed two
unnecessary tests for >0, removed one unnecessary
8-bit mask.
1 Aug 82 generating Zilog mnemonic
output rather than Intel.
18 Jul 82 Corrected expression analyzer
per J. E. Hendrix (ddj n62 p41);
1 Jul 82 Replaced calls to "ccpchar" with
inline code, per Ron Cain, DDJ n48 p6.
Implemented backslash escape sequences for
character and string literals, per J. E. Hendrix,
DDJ n56 p6.
18 Apr 81 Preceding names by Q rather
than QZ, to shorten them.
*/
/*
** lval[0] - symbol table address, else 0 for constant
** lval[1] - type of indirect object to fetch, else 0
for static object
** lval[2] - type of pointer or array, else 0
** lval[3] - type of value calculated jrvz 8/7/82
*/
expression()
{
int lval[4]; /* jrvz 8/7/82 */
if(heir1(lval))rvalue(lval);
return lval[3]; /* return type jrvz 8/7/82 */
}
heir1(lval)
int lval[];
{
int k,lval2[4];
k=heir2(lval);
if (match("="))
{if(k==0){needlval();return 0;
}
if (lval[1])zpush();
if(heir1(lval2))rvalue(lval2);
force(lval[3],lval2[3]); /* jrvz 10/10/82 */
store(lval);
return 0;
}
else return k;
}
heir2(lval)
int lval[];
{ int k,lval2[4];
k=heir3(lval);
blanks();
if(ch()!='|')return k;
if(k)rvalue(lval);
while(1)
{if (match("|"))
{zpush();
if(heir3(lval2)) rvalue(lval2);
intcheck(lval,lval2);
/* jrvz 10/10/82 */
zor();
}
else return 0;
}
}
heir3(lval)
int lval[];
{ int k,lval2[4];
k=heir4(lval);
blanks();
if(ch()!='^')return k;
if(k)rvalue(lval);
while(1)
{if (match("^"))
{zpush();
if(heir4(lval2))rvalue(lval2);
intcheck(lval,lval2);
/* jrvz 10/10/82 */
zxor();
}
else return 0;
}
}
heir4(lval)
int lval[];
{ int k,lval2[4];
k=heir5(lval);
blanks();
if(ch()!='&')return k;
if(k)rvalue(lval);
while(1)
{if (match("&"))
{zpush();
if(heir5(lval2))rvalue(lval2);
intcheck(lval,lval2);
/* jrvz 10/10/82 */
zand();
}
else return 0;
}
}
heir5(lval)
int lval[];
{
int k,lval2[4];
k=heir6(lval);
blanks();
if((streq(line+lptr,"==")==0)&
(streq(line+lptr,"!=")==0))return k;
if(k)rvalue(lval);
while(1)
{if (match("=="))
{if(lval[3]==DOUBLE)dpush();
/* jrvz 8/9/82 */
else zpush();
if(heir6(lval2))rvalue(lval2);
if(widen(lval,lval2))
/* jrvz 10/9/82 */
{deq();
lval[3]=cint;
} /* jrvz 8/9/82 */
else zeq();
}
else if (match("!="))
{if(lval[3]==DOUBLE)dpush();
/* jrvz 8/9/82 */
else zpush();
if(heir6(lval2))rvalue(lval2);
if(widen(lval,lval2))
/* jrvz 10/9/82 */
{dne();
lval[3]=cint;
} /* jrvz 8/9/82 */
else zne();
}
else return 0;
}
}
heir6(lval)
int lval[];
{
int k,lval2[4];
k=heir7(lval);
blanks();
if((streq(line+lptr,"<")==0)&
(streq(line+lptr,">")==0)&
(streq(line+lptr,"<=")==0)&
(streq(line+lptr,">=")==0))return k;
if(streq(line+lptr,">>"))return k;
if(streq(line+lptr,"<<"))return k;
if(k)rvalue(lval);
while(1)
{if (match("<="))
{if(lval[3]==DOUBLE)dpush();
else zpush(); /* jrvz 8/9/82 */
if(heir7(lval2))rvalue(lval2);
if(widen(lval,lval2))
/* jrvz 10/9/82 */
{dle();
lval[3]=cint; continue;
}
if(lval[2]|lval2[2])
{ule();
continue;
}
if(cptr=lval2[0])
if(cptr[ident]==pointer)
{ule();
continue;
}
zle();
}
else if (match(">="))
{if(lval[3]==DOUBLE)dpush();
else zpush(); /* jrvz 8/9/82 */
if(heir7(lval2))rvalue(lval2);
if(widen(lval,lval2))
/* jrvz 10/9/82 */
{dge();
lval[3]=cint; continue;
}
if(lval[2]|lval2[2])
{uge();
continue;
}
if(cptr=lval2[0])
if(cptr[ident]==pointer)
{uge();
continue;
}
zge();
}
else if((streq(line+lptr,"<"))&
(streq(line+lptr,"<<")==0))
{inbyte();
if(lval[3]==DOUBLE)dpush();
else zpush(); /* jrvz 8/10/82 */
if(heir7(lval2))rvalue(lval2);
if(widen(lval,lval2))
/* jrvz 10/9/82 */
{dlt();
lval[3]=cint; continue;
}
if(lval[2]|lval2[2])
{ult();
continue;
}
if(cptr=lval2[0])
if(cptr[ident]==pointer)
{ult();
continue;
}
zlt();
}
else if((streq(line+lptr,">"))&
(streq(line+lptr,">>")==0))
{inbyte();
if(lval[3]==DOUBLE)dpush();
else zpush(); /* jrvz 8/10/82 */
if(heir7(lval2))rvalue(lval2);
if(widen(lval,lval2))
/* jrvz 10/9/82 */
{dgt();
lval[3]=cint; continue;
}
if(lval[2]|lval2[2])
{ugt();
continue;
}
if(cptr=lval2[0])
if(cptr[ident]==pointer)
{ugt();
continue;
}
zgt();
}
else return 0;
}
}
/* >>>>>> start of cc6 <<<<<< */
heir7(lval)
int lval[];
{
int k,lval2[4];
k=heir8(lval);
blanks();
if((streq(line+lptr,">>")==0)&
(streq(line+lptr,"<<")==0))return k;
if(k)rvalue(lval);
while(1)
{if (match(">>"))
{zpush();
if(heir8(lval2))rvalue(lval2);
zpop();
intcheck(lval,lval2);
/* jrvz 10/10/82 */
asr();
}
else if (match("<<"))
{zpush();
if(heir8(lval2))rvalue(lval2);
intcheck(lval,lval2);
/* jrvz 10/10/82 */
asl();
}
else return 0;
}
}
heir8(lval)
int lval[];
{
int k,lval2[4];
k=heir9(lval);
blanks();
if((ch()!='+')&(ch()!='-'))return k;
if(k)rvalue(lval);
while(1)
{if (match("+"))
{if(lval[3]==DOUBLE)dpush();
/* jrvz 8/7/82 */
else zpush();
if(heir9(lval2))rvalue(lval2);
if(dbltest(lval,lval2))
scale(lval[2]); /* jrvz 8/7/82 */
if(widen(lval,lval2))
/* jrvz 10/9/82 */
{dadd();
}
else /* jrvz 8/8/82 */
{zpop();if(dbltest(lval2,lval))
{if(lval2[2]!=cchar)
{swap();scale(lval2[2]);
}
}
zadd();
result(lval,lval2);
}
}
else if (match("-"))
{if(lval[3]==DOUB