Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Lawrence R. Rogers
Tue, 18 Aug 1992 04:39
Unaligned access on DECStation under Ultrix 4.2A
Author: Lawrence R. Rogers
Date: Tue, 18 Aug 1992 04:39
Date: Tue, 18 Aug 1992 04:39
2968 lines
31687 bytes
31687 bytes
% gcc -v
Reading specs from /usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/specs
gcc version 2.2.1
configure run with decstation-ultrix4.2 as the argument.
No modifications to the source. Everything installed in
/usr/princeton/lib instead of the standard locations. Works fine on
other architectures (sun3, sun4) also installed in the same locations.
I get the following compiling the public domain ksh under ultrix:
gcc -g -O -g -O -D_BSD -I../std/h -c expr.c
pid 11630 (cc1) was killed on an unaligned access, at pc 0x46e32c
gcc: Internal compiler error: program cc1 got fatal signal 10
Here is the output of gcc -E -D_BSD -I../std/h -c expr.c
# 1 "expr.c"
static char *RCSid = "$Id: expr.c,v 1.2 1992/04/25 08:33:28 sjg Exp $";
# 1 "stdh.h" 1
# 1 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/stdio.h" 1 3
# 1 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 1 3
# 116 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 3
# 89 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/stdio.h" 2 3
typedef unsigned int size_t;
extern struct _iobuf {
int _cnt;
char *_ptr;
char *_base;
int _bufsiz;
short _flag;
short _file;
} _iob[3 ];
typedef struct _iobuf FILE;
typedef long fpos_t;
extern int getc( FILE *__stream );
extern int getchar( void );
extern int putc( int __c, FILE *__stream);
extern int putchar( int __c);
extern int feof( FILE *__stream );
extern int ferror( FILE *__stream );
extern int fileno( FILE *__stream );
extern int _filbuf( FILE *p);
extern int _flsbuf( unsigned char x , FILE *p);
typedef char *va_list;
extern void clearerr( FILE *__stream);
extern int fclose( FILE *__stream );
extern FILE * fdopen( int __filedes, char *__type );
extern int fflush( FILE *__stream );
extern int fgetc( FILE *__stream );
extern int fgetpos( FILE *__stream, fpos_t *__pos );
extern char * fgets( char *__s, int __n, FILE *__stream );
extern FILE * fopen( const char *__filename, const char *__type );
extern int fprintf( FILE *__stream, const char *__format, ... );
extern int fputc( int __c, FILE *__stream );
extern int fputs( const char *__s, FILE *__stream );
extern size_t fread( void *__ptr, size_t __size,
size_t __nitems, FILE *__stream );
extern FILE * freopen( const char *__filename, const char *__type,
FILE *__stream );
extern int fscanf( FILE *__stream, const char *__format, ... );
extern int fseek( FILE *__stream, long __offset, int __ptrname );
extern int fsetpos( FILE *__stream, const fpos_t *__pos );
extern long ftell( FILE *__stream );
extern size_t fwrite( const void *__ptr, size_t __size,
size_t __nitems, FILE *__stream );
extern char * gets( char *__s );
extern void perror( const char *__s );
extern FILE * popen(const char *__command, const char *__type );
extern int printf( const char *__format, ... );
extern int puts( const char *__s );
extern int remove( const char *__filename );
extern int rename( const char *__from, const char *__to );
extern void rewind( FILE *__stream );
extern int scanf( const char *__format, ... );
extern void setbuf( FILE *__stream, char *__buf );
extern int setvbuf( FILE *__stream, char *__buf,
int __type, size_t __size );
extern int sscanf( const char *__s, const char *__format, ... );
extern FILE * tmpfile( void );
extern char * tmpnam( char *__s );
extern int ungetc( int __c, FILE *__stream );
extern int vfprintf( FILE *__stream, const char *__format, va_list __ap );
extern int vprintf( const char *__format, va_list __ap );
extern int vsprintf( char *__s, const char *__format, va_list __ap);
extern char * tempnam( const char *__dir, const char *__pfx);
extern int putw( int __w, FILE *__stream );
extern int getw(FILE *__stream);
extern int pclose( FILE *__stream );
# 299 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/stdio.h" 3
extern int sprintf( char *__s, const char *__format, ... );
# 39 "stdh.h" 2
# 1 "../std/h/stddef.h" 1 3
# 28 "../std/h/stddef.h" 3
extern int errno;
# 44 "stdh.h" 2
# 1 "../std/h/stdlib.h" 1 3
# 1 "../std/h/stddef.h" 1 3
# 45 "../std/h/stddef.h" 3
# 8 "../std/h/stdlib.h" 2 3
double atof (const char *s) ;
int atoi (const char *s) ;
long atol (const char *s) ;
double strtod (const char *s, char **) ;
long strtol (const char *s, char **, int base) ;
unsigned long strtoul (const char *s, char **, int base) ;
int rand (void) ;
void srand (unsigned int seed) ;
void *malloc (size_t size) ;
void *realloc (void *ptr, size_t size) ;
void *calloc (size_t n, size_t size) ;
void free (void *ptr) ;
void abort (void) ;
int atexit (void (*func)(void)) ;
void exit (int status) ;
char *getenv (const char *name) ;
int system (const char *cmd) ;
void *bsearch (const void *key, const void *base, size_t n, size_t size,
int (*compar)(const void *, const void *)) ;
void *qsort (const void *base, size_t n, size_t size,
int (*compar)(const void *, const void *)) ;
# 45 "stdh.h" 2
# 1 "../std/h/string.h" 1 3
# 1 "../std/h/stddef.h" 1 3
# 45 "../std/h/stddef.h" 3
# 7 "../std/h/string.h" 2 3
void *memmove (void *s1, const void *s2, size_t) ;
void *memchr (const void *s, int c, size_t) ;
void *memset (void *s, int c, size_t) ;
char *strcpy (char *s1, const char *s2) ;
char *strncpy (char *s1, const char *s2, size_t) ;
char *strcat (char *s1, const char *s2) ;
char *strncat (char *s1, const char *s2, size_t) ;
int strcmp (const char *s1, const char *s2) ;
int strncmp (const char *s1, const char *s2, size_t) ;
char *strchr (const char *s1, int c) ;
char *strrchr (const char *s1, int c) ;
size_t strspn (const char *s1, const char *s2) ;
size_t strcspn (const char *s1, const char *s2) ;
char *strpbrk (const char *s1, const char *s2) ;
char *strstr (const char *s1, const char *s2) ;
char *strtok (char *s1, const char *s2) ;
char *strerror (int errno) ;
# 46 "stdh.h" 2
# 1 "../std/h/sys/types.h" 1 3
# 1 "../std/h/stddef.h" 1 3
# 45 "../std/h/stddef.h" 3
# 4 "../std/h/sys/types.h" 2 3
# 1 "../std/h/time.h" 1 3
# 1 "../std/h/stddef.h" 1 3
# 45 "../std/h/stddef.h" 3
# 7 "../std/h/time.h" 2 3
typedef long time_t;
typedef long clock_t;
struct tm {
int tm_sec, tm_min, tm_hour;
int tm_mday, tm_mon, tm_year, tm_wday, tm_yday;
int tm_isdst;
long tm_gmtoff;
char *tm_zone;
};
clock_t clock (void) ;
time_t time (time_t *tp) ;
time_t mktime (struct tm *tmp) ;
char *asctime (const struct tm *tmp) ;
char *ctime (const time_t *tp) ;
struct tm *gmtime (const time_t *tp) ;
struct tm *localtime (const time_t *tp) ;
size_t strftime (char *buf, size_t len, const char *fmt, const struct tm *tmp) ;
# 5 "../std/h/sys/types.h" 2 3
# 1 "/./usr/include/sys/types.h" 1
# 1 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 1 3
# 116 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 3
# 79 "/./usr/include/sys/types.h" 2
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned int uint;
typedef unsigned long u_long;
typedef unsigned short ushort;
typedef volatile char v_char;
typedef volatile short v_short;
typedef volatile long v_long;
typedef volatile unsigned char vu_char;
typedef volatile unsigned short vu_short;
typedef volatile unsigned long vu_long;
typedef
signed
char s_char;
typedef struct _physadr { int r[1]; } *physadr;
typedef struct label_t {
int val[12];
} label_t;
typedef struct _quad { long val[2]; } quad;
typedef long daddr_t;
typedef char * caddr_t;
typedef u_long gno_t;
typedef short cnt_t;
typedef long swblk_t;
typedef long paddr_t;
typedef long audit_ID_t;
typedef short dev_t;
typedef short gid_t;
typedef unsigned long ino_t;
typedef unsigned short mode_t;
typedef short nlink_t;
typedef int off_t;
typedef int pid_t;
typedef short uid_t;
typedef int _time_t ;
typedef int _clock_t ;
typedef long key_t;
typedef long fd_mask;
typedef struct fd_set {
fd_mask fds_bits[(((4096 )+(( (sizeof(fd_mask) * 8 ) )-1))/( (sizeof(fd_mask) * 8 ) )) ];
} fd_set;
# 11 "../std/h/sys/types.h" 2 3
# 47 "stdh.h" 2
# 80 "stdh.h"
# 9 "expr.c" 2
# 1 "/usr/include/errno.h" 1 3
extern int errno;
# 10 "expr.c" 2
# 1 "/usr/include/setjmp.h" 1 3
# 1 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 1 3
# 116 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 3
# 2 "/usr/include/setjmp.h" 2 3
# 47 "/usr/include/setjmp.h" 3
typedef int jmp_buf[(34+1+48) ];
typedef int sigjmp_buf[(34+1+48) ];
extern void longjmp( jmp_buf __env, int __val );
extern int setjmp( jmp_buf __env );
extern int sigsetjmp(sigjmp_buf __env, int __savemask);
extern void siglongjmp(const sigjmp_buf __env, int __val);
# 11 "expr.c" 2
# 1 "sh.h" 1
# 1 "config.h" 1
# 1 "/usr/include/signal.h" 1 3
# 1 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 1 3
# 116 "/usr/princeton/lib/gnu/gcc-lib/decstation-ultrix4.2/2.2.1/include/ansi_compat.h" 3
# 74 "/usr/include/signal.h" 2 3
typedef long sig_atomic_t;
typedef int sigset_t;
struct sigvec {
void (*sv_handler)();
sigset_t sv_mask;
int sv_flags;
};
struct sigaction {
void (*sa_handler)();
sigset_t sa_mask;
int sa_flags;
};
struct sigstack {
char *ss_sp;
int ss_onstack;
};
struct sigcontext {
int sc_onstack;
int sc_mask;
int sc_pc;
int sc_regs[32];
int sc_mdlo;
int sc_mdhi;
int sc_ownedfp;
int sc_fpregs[32];
int sc_fpc_csr;
int sc_fpc_eir;
int sc_cause;
int sc_badvaddr;
int sc_badpaddr;
};
extern void (*signal(int __sig, void(*__func)(int)))(int);
int raise( int __sig );
int kill( pid_t __pid, int __sig );
int sigemptyset( sigset_t *__set );
int sigfillset( sigset_t *__set );
int sigaddset( sigset_t *__set, int __signo );
int sigdelset( sigset_t *__set, int __signo );
int sigismember( const sigset_t *__set, int __signo );
int sigaction( int __sig, const struct sigaction *__act,
struct sigaction *__oact );
int sigprocmask( int __how, const sigset_t *__set, sigset_t *__oset );
int sigpending( sigset_t *__set );
int sigsuspend( const sigset_t *__sigmask );
# 19 "config.h" 2
# 7 "sh.h" 2
typedef int bool_t;
extern int kshpid;
extern int exstat;
extern int async;
extern volatile int sigchld_caught;
typedef struct Area {
struct Block *free;
} Area;
extern Area aperm;
extern struct env {
int type;
Area area;
struct block *loc;
short *savefd;
struct env *oenv;
jmp_buf jbuf;
int interactive;
struct temp *temps;
} e;
extern char flag [32 ];
int option (const char *name) ;
char *getoptions (void) ;
void printoptions (void) ;
extern char null [];
char * substitute (char const *, int) ;
char *search();
struct tbl *findcom();
char *strsave (char *, Area *) ;
char *ulton (unsigned long n, int base) ;
int xstrcmp();
void qsortp (void **base, size_t n, int (*compare)(void *, void *)) ;
long evaluate (const char *expr) ;
void resetopts();
void histsave();
void histlist();
void j_init (void) ;
void j_exit (void) ;
void j_notify (void) ;
void j_kill (int job, int sig) ;
void j_change (void) ;
int j_resume (int job, int bg) ;
void leave();
typedef void (*handler_t)();
struct temp {
struct temp * next;
char *name;
};
struct temp *maketemp (Area *ap) ;
extern FILE * shf [10 ];
void fopenshf();
void flushshf();
int shellf (const char *fmt, ...) ;
int errorf (const char *fmt, ...) ;
extern int ttyfd;
int savefd (int fd) ;
void restfd (int fd, int ofd) ;
void openpipe (int [2]) ;
void closepipe (int [2]) ;
typedef struct trap {
int signal;
char *name;
char *mess;
char *trap;
int volatile set;
int ourtrap;
int sig_dfl;
} Trap;
extern struct sigaction Sigact, Sigact_dfl, Sigact_ign, Sigact_trap;
extern int volatile trap;
extern Trap sigtraps[32 ];
Trap *gettrap (char *) ;
void trapsig (int sig) ;
extern char ctypes [];
# 1 "table.h" 1
struct table {
Area *areap;
int size, free;
struct tbl **tbls;
};
struct tbl {
int flag;
int type;
union {
char *s;
long i;
int (*f) (char**) ;
struct op *t;
} val;
char name[4];
};
void tinit (struct table *, Area *) ;
unsigned int hash();
struct tbl *tsearch();
struct tbl *tenter();
void tdelete();
void twalk();
struct tbl *tnext();
struct tbl **tsort();
struct block {
Area area;
int argc;
char ** argv;
struct table vars;
struct table funs;
char * error;
char * exit;
struct block *next;
};
extern struct block globals;
extern struct table commands;
extern struct table builtins;
extern struct table lexicals;
extern struct table homedirs;
struct builtin {
char *name;
int (*func)();
};
extern const struct builtin shbuiltins [], kshbuiltins [];
extern Area *lastarea;
extern char *path;
extern char *prompt;
void newblock();
void popblock();
struct tbl *global( );
struct tbl *local( );
struct tbl *typeset( );
struct tbl *setvar( );
struct tbl *strint( );
long intval( );
void setint( );
char *strval( );
void setstr( );
void unset( );
int import( );
char **makenv();
int isassign( );
# 261 "sh.h" 2
# 1 "tree.h" 1
struct op {
int type;
char **args;
char **vars;
struct ioword **ioact;
struct op *left, *right;
char *str;
};
struct ioword {
int unit;
int flag;
char *name;
};
# 116 "tree.h"
# 262 "sh.h" 2
# 1 "lex.h" 1
typedef struct source Source;
struct source {
char *str;
int type;
union {
char **strv;
FILE *file;
struct tbl *tblp;
} u;
int line;
char *file;
int echo;
Source *next;
};
Source *pushs (int stype) ;
struct op *compile (Source *s) ;
extern int multiline;
typedef union {
int i;
char *cp;
char **wp;
struct op *o;
struct ioword *iop;
} YYSTYPE;
extern char line [256 +1];
extern Source *source;
extern YYSTYPE yylval;
extern int yynerrs;
extern struct ioword *heres [10 ], **herep;
extern char ident [64 +1];
extern int yylex (int flags) ;
extern void yyerror (const char *msg) ;
extern char *history [100 ];
extern char **histptr;
extern int histpush;
extern char **histget();
extern char **histpos();
extern int histnum();
extern char *findhist();
extern int histN();
extern void x_init (void) ;
extern void x_init_emacs (void) ;
extern void x_emacs_keys ();
extern void x_bind();
extern int x_read (int fd, char *buf, size_t len) ;
extern int x_emacs (char *buf, size_t len) ;
extern int x_vi (char *buf, size_t len) ;
extern bool_t x_mode (bool_t) ;
extern int x_getc();
extern void x_flush(), x_putc(), x_puts();
extern int x_cols;
# 263 "sh.h" 2
# 1 "proto.h" 1
Area * ainit (Area *ap) ;
void afreeall (Area *ap) ;
void * alloc (size_t size, Area *ap) ;
void * aresize (void *ptr, size_t size, Area *ap) ;
void afree (void *ptr, Area *ap) ;
int c_hash (char **wp) ;
int c_cd (char **wp) ;
int c_print (char **wp) ;
int c_whence (char **wp) ;
int c_typeset (char **wp) ;
int c_alias (char **wp) ;
int c_unalias (char **wp) ;
int c_let (char **wp) ;
int c_jobs (char **wp) ;
int c_fgbg (char **wp) ;
int c_kill (char **wp) ;
int c_bind (char **wp) ;
int c_label (char **wp) ;
int c_shift (char **wp) ;
int c_umask (char **wp) ;
int c_dot (char **wp) ;
int c_wait (char **wp) ;
int c_read (char **wp) ;
int c_eval (char **wp) ;
int c_trap (char **wp) ;
void setsig (struct trap *p, void (*f)()) ;
int c_return (char **wp) ;
int c_brkcont (char **wp) ;
int c_exit (char **wp) ;
int c_set (char **wp) ;
int c_unset (char **wp) ;
int c_ulimit (char **wp) ;
int c_times (char **wp) ;
int timex (struct op *t, int f) ;
int c_exec (char **wp) ;
int c_builtin (char **wp) ;
int c_test (char **wp) ;
int oexpr (int n) ;
int aexpr (int n) ;
int nexpr (int n) ;
int primary (int n) ;
int filstat (char *nm, int mode) ;
int t_lex (char *s) ;
int newerf (char *f1, char *f2) ;
int olderf (char *f1, char *f2) ;
int equalf (char *f1, char *f2) ;
int do_ulimit (char *a1, char *a2) ;
int x_read (int fd, char *buf, size_t len) ;
int x_getc (void) ;
void x_flush (void) ;
void x_adjust (void) ;
void x_putc (int c) ;
void x_puts (char *s) ;
void x_init (void) ;
bool_t x_mode (bool_t onoff) ;
int promptlen (char *cp) ;
int init_editmode (void) ;
int x_emacs (char *buf, size_t len) ;
void x_redraw (int limit) ;
void x_bind (char *a1, char *a2, int macro) ;
void x_init_emacs (void) ;
void x_emacs_keys (int erase, int kill, int werase, int intr, int quit) ;
char * x_lastcp (void) ;
char * substitute (char const *cp, int f) ;
char ** eval (char **ap, int f) ;
char * evalstr (char *cp, int f) ;
int execute (struct op *t, volatile int flags) ;
int shcomexec (char **wp) ;
int define (char *name, struct op *t) ;
int builtin (char *name, int (*func)()) ;
struct tbl * findcom (char *name, int insert) ;
int flushcom (int all) ;
char * search (char *name, char *path, int mode) ;
void evalerr (char *err) ;
long evaluate (const char *expr) ;
void resetopts (void) ;
int c_getopts (char **wp) ;
int c_fc (register char **wp) ;
void histbackup (void) ;
void histsave (char *cmd) ;
char ** histget (char *str) ;
char * histrpl (char *s, char *pat, char *rep, int global) ;
void hist_init (Source *s) ;
void hist_finish (void) ;
char ** histpos (void) ;
int histN (void) ;
int histnum (int n) ;
char * findhist (int start, int fwd, char *str) ;
int errorf (const char *fmt, ...) ;
int shellf (const char *fmt, ...) ;
void fopenshf (int fd) ;
void flushshf (int fd) ;
int savefd (int fd) ;
void restfd (int fd, int ofd) ;
void openpipe (int *pv) ;
void closepipe (int *pv) ;
struct temp * maketemp (Area *ap) ;
void j_init (void) ;
void j_exit (void) ;
void j_change (void) ;
int exchild (struct op *t, int flags) ;
int waitlast (void) ;
int j_reapchld (void) ;
int j_reap (void) ;
int waitfor (int job) ;
void j_kill (int job, int sig) ;
int j_resume (int job, int bg) ;
void j_jobs (void) ;
void j_notify (void) ;
int j_lookup (char *cp) ;
int j_stopped (void) ;
int yylex (int cf) ;
int gethere (void) ;
void yyerror (const char *msg) ;
Source * pushs (int type) ;
int pprompt (char *cp) ;
void mcheck (void) ;
void mbset (char *p) ;
void mpset (char *mptoparse) ;
void mprint (void) ;
int main (int argc, char **argv, char **envp) ;
int include (char *name) ;
int shell (Source *s) ;
void leave (int rv) ;
int error (void) ;
int unwind (void) ;
int newenv (int type) ;
int quitenv (void) ;
void aerror (Area *ap, const char *msg) ;
void setctypes ( char *s, int t) ;
void initctypes (void) ;
char * ulton (unsigned long n, int base) ;
char * strsave (char *s, Area *ap) ;
int option (const char *n) ;
char * getoptions (void) ;
void printoptions (void) ;
int getn (char *as) ;
char * strerror (int i) ;
int gmatch (char *s, char *p) ;
void qsortp (void **base, size_t n, int (*f)()) ;
int qsort1 (void **base, void **lim, int (*f)()) ;
int xstrcmp (void *p1, void *p2) ;
void cleanpath (char *pwd, char *dir, char *clean) ;
int yyparse (void) ;
int keywords (void) ;
struct op * compile (Source *s) ;
unsigned int hash (char *n) ;
void tinit (struct table *tp, Area *ap) ;
struct tbl * tsearch (struct table *tp, char *n, unsigned int h) ;
struct tbl * tenter (struct table *tp, char *n, unsigned int h) ;
void tdelete (struct tbl *p) ;
void twalk (struct table *tp) ;
struct tbl * tnext (void) ;
struct tbl ** tsort (struct table *tp) ;
Trap * gettrap (char *name) ;
void trapsig (int i) ;
int runtraps (void) ;
int runtrap (Trap *p) ;
int cleartraps (void) ;
int ignoresig (int i) ;
int restoresigs (void) ;
void ptree (struct op *t, FILE *f) ;
int pioact (FILE *f, struct ioword *iop) ;
int fptreef (FILE *f, char *fmt, ...) ;
int snptreef (char *s, int n, char *fmt, ...) ;
struct op * tcopy (struct op *t, Area *ap) ;
char * wdcopy (char *wp, Area *ap) ;
char * wdscan (char *wp, int c) ;
void tfree (struct op *t, Area *ap) ;
void newblock (void) ;
void popblock (void) ;
struct tbl * global (char *n) ;
struct tbl * local (char *n) ;
char * strval (struct tbl *vp) ;
long intval (struct tbl *vp) ;
void setstr (struct tbl *vq, char *s) ;
struct tbl * strint (struct tbl *vq, struct tbl *vp) ;
void setint (struct tbl *vq, long n) ;
int import (char *thing) ;
struct tbl * typeset (char *var, int set, int clr) ;
void unset (struct tbl *vp) ;
int isassign (char *s) ;
char ** makenv (void) ;
void vi_reset (char *buf, int len) ;
int vi_hook (int ch) ;
int save_cbuf (void) ;
int restore_cbuf (void) ;
int x_vi (char *buf, size_t len) ;
int getch (void) ;
char ** globstr (char *stuff) ;
# 264 "sh.h" 2
# 1 "trace.h" 1
# 57 "trace.h"
# 86 "trace.h"
# 270 "sh.h" 2
# 12 "expr.c" 2
static const char *expression;
static const char *tokp;
static int tok;
static struct tbl *val;
static struct tbl *asn (void) ;
static struct tbl *e6 (void) ;
static struct tbl *e5 (void) ;
static struct tbl *e3 (void) ;
static struct tbl *e2 (void) ;
static struct tbl *e0 (void) ;
static void token (void) ;
static struct tbl *tempvar (void) ;
static struct tbl *intvar (struct tbl *vp) ;
void
evalerr(err)
char *err;
{
errorf("%s: %s\n", expression, err);
}
long
evaluate(expr)
const char *expr;
{
struct tbl *v;
expression = tokp = expr;
token();
v = intvar(asn());
if (!(tok == 0))
evalerr("bad expression");
return v->val.i;
}
static struct tbl *
asn()
{
register struct tbl *vl, *vr;
vr = vl = e6();
if ((tok == '=')) {
Area * olastarea = lastarea;
token();
if ((vl->flag&(1<<(8)) ))
evalerr("bad assignment");
vr = intvar(asn());
lastarea = olastarea;
setint(vl, vr->val.i);
if ((vl->flag&(1<<(4)) ) && vl->type == 0)
vl->type = vr->type;
}
return vr;
}
static struct tbl *
e6()
{
register struct tbl *vl, *vr;
vl = e5();
while ((tok == 0x03 ) || (tok == 0x04 )) {
int op = tok;
token();
vl = intvar(vl);
vr = intvar(e5());
vl->val.i = vl->val.i == vr->val.i;
if (op == 0x04 )
vl->val.i = ! vl->val.i;
}
return vl;
}
static struct tbl *
e5()
{
register struct tbl *vl, *vr;
vl = e3();
while ((tok == 0x05 ) || (tok == '<') || (tok == '>') || (tok == 0x06 )) {
int op = tok;
token();
vl = intvar(vl);
vr = intvar(e3());
if (op == 0x05 )
vl->val.i = vl->val.i <= vr->val.i;
else if (op == '<')
vl->val.i = vl->val.i < vr->val.i;
else if (op == 0x06 )
vl->val.i = vl->val.i >= vr->val.i;
else if (op == '>')
vl->val.i = vl->val.i > vr->val.i;
}
return vl;
}
static struct tbl *
e3()
{
register struct tbl *vl, *vr;
vl = e2();
while ((tok == '+') || (tok == '-')) {
int op = tok;
token();
vl = intvar(vl);
vr = intvar(e2());
if (op == '+')
vl->val.i += vr->val.i;
else if (op == '-')
vl->val.i -= vr->val.i;
}
return vl;
}
static struct tbl *
e2()
{
register struct tbl *vl, *vr;
vl = e0();
while ((tok == '*') || (tok == '/') || (tok == '%')) {
int op = tok;
token();
vl = intvar(vl);
vr = intvar(e0());
if (op != '*' && vr->val.i == 0)
evalerr("zero divisor");
if (op == '*')
vl->val.i *= vr->val.i;
else if (op == '/')
vl->val.i /= vr->val.i;
else if (op == '%')
vl->val.i %= vr->val.i;
}
return vl;
}
static struct tbl *
e0()
{
register struct tbl *v;
if ((tok == '!') || (tok == '-')) {
int op = tok;
token();
v = intvar(e0());
if (op == '!')
v->val.i = !v->val.i;
else if (op == '-')
v->val.i = -v->val.i;
} else
if ((tok == '(')) {
token();
v = asn();
if (!(tok == ')'))
evalerr("missing )");
token();
} else
if ((tok == 0x01 ) || (tok == 0x02 )) {
v = val;
token();
} else
evalerr("bad expression");
return v;
}
static void
token()
{
register char *cp = (char *) tokp;
register int c, c2;
do c = *cp++; while (c != '\0' && (c == ' ' || c == '\t'));
tokp = cp-1;
if (!!(ctypes[(unsigned char)(c)]&( 0x01 )) ) {
for (; !!(ctypes[(unsigned char)(c)]&( 0x01 |0x02 )) ; c = *cp++)
;
c = *--cp;
*cp = 0;
val = global(tokp);
*cp = c;
tok = 0x01 ;
} else
if (!!(ctypes[(unsigned char)(c)]&( 0x02 )) ) {
for (; !!(ctypes[(unsigned char)(c)]&( 0x01 |0x02 )) || c == '#'; c = *cp++)
;
c = *--cp;
*cp = 0;
val = tempvar();
setstr(val, tokp);
val->flag |= (1<<(8)) ;
*cp = c;
tok = 0x02 ;
} else {
c2 = *cp++;
if (c == '=' && c2 == '=')
c = 0x03 ;
else if (c == '!' && c2 == '=')
c = 0x04 ;
else if (c == '<' && c2 == '=')
c = 0x05 ;
else if (c == '>' && c2 == '=')
c = 0x06 ;
else
cp--;
tok = c;
}
tokp = cp;
}
static struct tbl *
tempvar()
{
register struct tbl *vp;
vp = (struct tbl*) alloc(sizeof(struct tbl), &e.area );
lastarea = &e.area ;
vp->flag = (1<<(2)) |(1<<(4)) ;
vp->type = 0;
vp->name[0] = '\0';
return vp;
}
static struct tbl *
intvar(vp)
register struct tbl *vp;
{
register struct tbl *vq;
vq = tempvar();
vq->type = 10;
if (strint(vq, vp) == 0 ) {
if ((vp->flag&(1<<(2)) ) && vp->val.s && *(vp->val.s)) {
evalerr("bad number");
} else {
vq->flag |= ((1<<(2)) |(1<<(4)) );
vq->type = 10;
vq->val.i = 0;
}
}
return vq;
}
===== ======= ======= Larry Rogers
= = = = Manager, UNIX Systems
= = = Princeton University
= = = 87 Prospect Street, Room 201
= = = Princeton, NJ 08544
= = = lrr@Princeton.EDU, princeton!lrr
= = = = Phone: 609-258-6483/6000
===== ======= = FAX: 609-258-1069/3943
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads