made to work; contained too many dependencies on word/pointer size
This commit is contained in:
parent
5c508b566f
commit
ca51618fe9
8 changed files with 52 additions and 40 deletions
|
@ -43,11 +43,11 @@ void init_builtins()
|
||||||
insert("input", T_CHAN|T_BUILTIN, 1, &info);
|
insert("input", T_CHAN|T_BUILTIN, 1, &info);
|
||||||
|
|
||||||
info.vc.st.builtin=file;
|
info.vc.st.builtin=file;
|
||||||
info.vc.offset=wz+pz;
|
info.vc.offset=wz+vz;
|
||||||
insert("output", T_CHAN|T_BUILTIN, 1, &info);
|
insert("output", T_CHAN|T_BUILTIN, 1, &info);
|
||||||
|
|
||||||
info.vc.st.builtin=file;
|
info.vc.st.builtin=file;
|
||||||
info.vc.offset=2*(wz+pz);
|
info.vc.offset=2*(wz+vz);
|
||||||
insert("error", T_CHAN|T_BUILTIN, 1, &info);
|
insert("error", T_CHAN|T_BUILTIN, 1, &info);
|
||||||
|
|
||||||
/* DEF EOF= -1, TEXT= -2, RAW= -3: */
|
/* DEF EOF= -1, TEXT= -2, RAW= -3: */
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
int wz = 4, pz = 4, vz = 4;
|
int wz = 4, pz = 4, vz = 4;
|
||||||
int Lflag;
|
int Lflag;
|
||||||
static Lab=0;
|
static Lab=0;
|
||||||
char *malloc();
|
char *Malloc();
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ void meswp()
|
||||||
void maxdes()
|
void maxdes()
|
||||||
{
|
{
|
||||||
C_df_dnam("maxcdes");
|
C_df_dnam("maxcdes");
|
||||||
rom(wz, 0L); rom(wz, -1L); rom(wz, (long) (wz+pz));
|
rom(wz, 0L); rom(wz, -1L); rom(wz, (long) (wz+vz));
|
||||||
C_df_dnam("maxwdes");
|
C_df_dnam("maxwdes");
|
||||||
rom(wz, 0L); rom(wz, -1L); rom(wz, (long) vz);
|
rom(wz, 0L); rom(wz, -1L); rom(wz, (long) vz);
|
||||||
C_df_dnam("maxbdes");
|
C_df_dnam("maxbdes");
|
||||||
|
@ -82,7 +82,7 @@ char *proc_label(L, name) register L; register char *name;
|
||||||
|
|
||||||
if (lab!=nil) free(lab);
|
if (lab!=nil) free(lab);
|
||||||
|
|
||||||
lab=malloc(strlen(name)+(1+sizeof(int)*3+1));
|
lab=Malloc(strlen(name)+(1+sizeof(int)*3+1));
|
||||||
/* That is: P<L><name>\0 */
|
/* That is: P<L><name>\0 */
|
||||||
|
|
||||||
sprint(lab, "P%d", L);
|
sprint(lab, "P%d", L);
|
||||||
|
@ -412,8 +412,8 @@ int set_file(f) char *f;
|
||||||
apf= cmp<0 ? &pf->left : &pf->right;
|
apf= cmp<0 ? &pf->left : &pf->right;
|
||||||
|
|
||||||
if (pf==nil) {
|
if (pf==nil) {
|
||||||
*apf= pf= (struct ftree *) malloc(sizeof *pf);
|
*apf= pf= (struct ftree *) Malloc(sizeof *pf);
|
||||||
pf->file=strcpy(malloc(strlen(f)+1), f);
|
pf->file=strcpy(Malloc(strlen(f)+1), f);
|
||||||
pf->lab=0;
|
pf->lab=0;
|
||||||
pf->left=pf->right=nil;
|
pf->left=pf->right=nil;
|
||||||
}
|
}
|
||||||
|
@ -438,7 +438,7 @@ void par_fork(NONZERO) int *NONZERO;
|
||||||
{
|
{
|
||||||
C_zer((arith) pz);
|
C_zer((arith) pz);
|
||||||
C_cal("pc_fork");
|
C_cal("pc_fork");
|
||||||
C_asp(pz);
|
C_asp((arith) pz);
|
||||||
C_lfr((arith) wz);
|
C_lfr((arith) wz);
|
||||||
C_zne((label) new_label(NONZERO));
|
C_zne((label) new_label(NONZERO));
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
static void rvalue(), assignable(), inputable(), outputable(), subscriptable();
|
static void rvalue(), assignable(), inputable(), outputable(), subscriptable();
|
||||||
static void assigned();
|
static void assigned();
|
||||||
|
char *Malloc();
|
||||||
|
|
||||||
/* The new_* functions make use of the used() and assinged() functions to
|
/* The new_* functions make use of the used() and assinged() functions to
|
||||||
* make known what is done to a variable.
|
* make known what is done to a variable.
|
||||||
|
@ -89,7 +90,7 @@ struct expr *new_node(op, left, right, byte)
|
||||||
subscriptable(left, right, byte, &type, &arr_siz);
|
subscriptable(left, right, byte, &type, &arr_siz);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pe= (struct expr *) malloc(sizeof *pe);
|
pe= (struct expr *) Malloc(sizeof *pe);
|
||||||
|
|
||||||
pe->kind=E_NODE;
|
pe->kind=E_NODE;
|
||||||
pe->type=type;
|
pe->type=type;
|
||||||
|
@ -110,7 +111,7 @@ struct expr *new_var(var)
|
||||||
{
|
{
|
||||||
register struct expr *pe;
|
register struct expr *pe;
|
||||||
|
|
||||||
pe= (struct expr *) malloc(sizeof *pe);
|
pe= (struct expr *) Malloc(sizeof *pe);
|
||||||
|
|
||||||
pe->kind=E_VAR;
|
pe->kind=E_VAR;
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ struct expr *new_const(const)
|
||||||
{
|
{
|
||||||
register struct expr *pe;
|
register struct expr *pe;
|
||||||
|
|
||||||
pe= (struct expr *) malloc(sizeof *pe);
|
pe= (struct expr *) Malloc(sizeof *pe);
|
||||||
|
|
||||||
pe->kind=E_CONST;
|
pe->kind=E_CONST;
|
||||||
pe->type=T_VALUE;
|
pe->type=T_VALUE;
|
||||||
|
@ -152,7 +153,7 @@ struct expr *new_table(kind, tab)
|
||||||
{
|
{
|
||||||
register struct expr *pe;
|
register struct expr *pe;
|
||||||
|
|
||||||
pe= (struct expr *) malloc(sizeof *pe);
|
pe= (struct expr *) Malloc(sizeof *pe);
|
||||||
|
|
||||||
pe->kind=kind;
|
pe->kind=kind;
|
||||||
pe->type=T_VALUE|T_ARR;
|
pe->type=T_VALUE|T_ARR;
|
||||||
|
@ -167,7 +168,7 @@ struct expr *new_table(kind, tab)
|
||||||
|
|
||||||
tab=tab->next;
|
tab=tab->next;
|
||||||
pe->arr_siz++;
|
pe->arr_siz++;
|
||||||
free(junk);
|
free((char *)junk);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pe;
|
return pe;
|
||||||
|
@ -180,7 +181,7 @@ struct expr *copy_const(e) struct expr *e;
|
||||||
{
|
{
|
||||||
register struct expr *c;
|
register struct expr *c;
|
||||||
|
|
||||||
c= (struct expr *) malloc(sizeof *c);
|
c= (struct expr *) Malloc(sizeof *c);
|
||||||
|
|
||||||
*c= *e;
|
*c= *e;
|
||||||
return c;
|
return c;
|
||||||
|
@ -191,7 +192,7 @@ struct expr *new_now()
|
||||||
{
|
{
|
||||||
register struct expr *pe;
|
register struct expr *pe;
|
||||||
|
|
||||||
pe= (struct expr *) malloc(sizeof *pe);
|
pe= (struct expr *) Malloc(sizeof *pe);
|
||||||
|
|
||||||
pe->kind=E_NOW;
|
pe->kind=E_NOW;
|
||||||
pe->type=T_VALUE;
|
pe->type=T_VALUE;
|
||||||
|
@ -213,7 +214,7 @@ struct expr *new_io(out, chan, args)
|
||||||
report("channel variable expected");
|
report("channel variable expected");
|
||||||
used(chan);
|
used(chan);
|
||||||
|
|
||||||
pe= (struct expr *) malloc(sizeof *pe);
|
pe= (struct expr *) Malloc(sizeof *pe);
|
||||||
|
|
||||||
pe->kind=E_IO;
|
pe->kind=E_IO;
|
||||||
pe->type=T_VOID;
|
pe->type=T_VOID;
|
||||||
|
@ -234,7 +235,7 @@ struct expr *new_call(proc, args)
|
||||||
{
|
{
|
||||||
register struct expr *pe;
|
register struct expr *pe;
|
||||||
|
|
||||||
pe= (struct expr *) malloc(sizeof *pe);
|
pe= (struct expr *) Malloc(sizeof *pe);
|
||||||
|
|
||||||
used(proc);
|
used(proc);
|
||||||
|
|
||||||
|
@ -253,7 +254,7 @@ void table_add(aapt, val) register struct table ***aapt; long val;
|
||||||
{
|
{
|
||||||
register struct table *pt;
|
register struct table *pt;
|
||||||
|
|
||||||
pt= (struct table *) malloc(sizeof *pt);
|
pt= (struct table *) Malloc(sizeof *pt);
|
||||||
|
|
||||||
pt->val=val;
|
pt->val=val;
|
||||||
pt->next= **aapt;
|
pt->next= **aapt;
|
||||||
|
@ -269,7 +270,7 @@ void expr_list_add(aaelp, arg)
|
||||||
{
|
{
|
||||||
register struct expr_list *elp;
|
register struct expr_list *elp;
|
||||||
|
|
||||||
elp= (struct expr_list *) malloc(sizeof *elp);
|
elp= (struct expr_list *) Malloc(sizeof *elp);
|
||||||
|
|
||||||
elp->arg=arg;
|
elp->arg=arg;
|
||||||
elp->next= **aaelp;
|
elp->next= **aaelp;
|
||||||
|
@ -466,11 +467,11 @@ void destroy(e) register struct expr *e;
|
||||||
destroy(elp->arg);
|
destroy(elp->arg);
|
||||||
junk=elp;
|
junk=elp;
|
||||||
elp=elp->next;
|
elp=elp->next;
|
||||||
free(junk);
|
free((char *)junk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(e);
|
free((char *)e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,10 @@ char *lowerupper(str) register char *str;
|
||||||
register char *key=keyword;
|
register char *key=keyword;
|
||||||
|
|
||||||
if (islower(*str)) {
|
if (islower(*str)) {
|
||||||
do
|
do {
|
||||||
*key++ = toupper(*str++);
|
*key++ = toupper(*str);
|
||||||
while (key<keyword+MAXKEYLEN && islower(*str));
|
str++;
|
||||||
|
} while (key<keyword+MAXKEYLEN && islower(*str));
|
||||||
} else {
|
} else {
|
||||||
do
|
do
|
||||||
*key++ = *str++;
|
*key++ = *str++;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
# define TABSTOP(ind) (((ind)+TAB)&(~(TAB-1)))
|
# define TABSTOP(ind) (((ind)+TAB)&(~(TAB-1)))
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
char *malloc(), *strcpy();
|
char *Malloc(), *strcpy();
|
||||||
|
|
||||||
struct token token;
|
struct token token;
|
||||||
int ind=0; /* Indentation level of current line */
|
int ind=0; /* Indentation level of current line */
|
||||||
|
@ -72,7 +72,7 @@ int included=0; /* Is current file included? */
|
||||||
register key;
|
register key;
|
||||||
|
|
||||||
if ((key=keyword(yytext))==IDENTIFIER)
|
if ((key=keyword(yytext))==IDENTIFIER)
|
||||||
token.t_sval=strcpy(malloc(yyleng+1), yytext);
|
token.t_sval=strcpy(Malloc(yyleng+1), yytext);
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ char *tokenname(tk, inst) register tk, inst;
|
||||||
case IDENTIFIER:
|
case IDENTIFIER:
|
||||||
if (inst) {
|
if (inst) {
|
||||||
sprint(fake_id, "_%d", ++fake_cnt);
|
sprint(fake_id, "_%d", ++fake_cnt);
|
||||||
token.t_sval=strcpy(malloc(strlen(fake_id)+1),
|
token.t_sval=strcpy(Malloc(strlen(fake_id)+1),
|
||||||
fake_id);
|
fake_id);
|
||||||
return "IDENTIFIER";
|
return "IDENTIFIER";
|
||||||
} else
|
} else
|
||||||
|
@ -300,7 +300,7 @@ char *tokenname(tk, inst) register tk, inst;
|
||||||
return "NUMBER";
|
return "NUMBER";
|
||||||
case STRING:
|
case STRING:
|
||||||
if (inst) {
|
if (inst) {
|
||||||
token.t_sval=malloc(1);
|
token.t_sval=Malloc(1);
|
||||||
token.t_sval[0]=0;
|
token.t_sval[0]=0;
|
||||||
} else
|
} else
|
||||||
free(token.t_sval);
|
free(token.t_sval);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
static void nonconst(), nonpositive(), rep_cleanup(), check_assoc();
|
static void nonconst(), nonpositive(), rep_cleanup(), check_assoc();
|
||||||
void init_builtins();
|
void init_builtins();
|
||||||
|
char *strcpy();
|
||||||
|
|
||||||
extern int yylineno, LLsymb;
|
extern int yylineno, LLsymb;
|
||||||
union type_info info, none;
|
union type_info info, none;
|
||||||
|
@ -282,7 +283,7 @@ subscript(register *byte; register struct expr **e; )
|
||||||
} else
|
} else
|
||||||
if (e1->u.const<=0)
|
if (e1->u.const<=0)
|
||||||
nonpositive(siz);
|
nonpositive(siz);
|
||||||
*e=new_node(FOR, *e, e1);
|
*e=new_node(FOR, *e, e1, *byte);
|
||||||
slice=1;
|
slice=1;
|
||||||
}
|
}
|
||||||
]?
|
]?
|
||||||
|
@ -499,7 +500,7 @@ item(register struct expr **e;)
|
||||||
{ if (!subs_call && var_proc(var)) {
|
{ if (!subs_call && var_proc(var)) {
|
||||||
if (pars!=nil)
|
if (pars!=nil)
|
||||||
report("no actual parameters");
|
report("no actual parameters");
|
||||||
*e=new_call(*e, nil);
|
*e=new_call(*e, (char *)nil);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
| vector_constant(e)
|
| vector_constant(e)
|
||||||
|
@ -515,7 +516,7 @@ statement(register struct expr **e;)
|
||||||
}:
|
}:
|
||||||
item(e)
|
item(e)
|
||||||
[ AS expression(&e1)
|
[ AS expression(&e1)
|
||||||
{ *e=new_node(AS, *e, e1); }
|
{ *e=new_node(AS, *e, e1, 0); }
|
||||||
| [
|
| [
|
||||||
'?' { out=0; }
|
'?' { out=0; }
|
||||||
| '!' { out=1; }
|
| '!' { out=1; }
|
||||||
|
@ -608,10 +609,10 @@ expression(register struct expr **e;)
|
||||||
op=LLsymb;
|
op=LLsymb;
|
||||||
}
|
}
|
||||||
operator element(&e1)
|
operator element(&e1)
|
||||||
{ *e=new_node(op, *e, e1); }
|
{ *e=new_node(op, *e, e1, 0); }
|
||||||
]*
|
]*
|
||||||
| monadic_op(&op) element(&e1)
|
| monadic_op(&op) element(&e1)
|
||||||
{ *e=new_node(op, e1, nil); }
|
{ *e=new_node(op, e1, (char *)nil, 0); }
|
||||||
;
|
;
|
||||||
|
|
||||||
val_expr(register struct expr **e;) :
|
val_expr(register struct expr **e;) :
|
||||||
|
@ -747,4 +748,9 @@ static void check_assoc(prev_op, op) register prev_op, op;
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
No_Mem()
|
||||||
|
{
|
||||||
|
fatal("out of memory");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
extern int err, yylineno;
|
extern int err, yylineno;
|
||||||
extern char *curr_file;
|
extern char *curr_file;
|
||||||
|
|
||||||
|
/*VARARGS1*/
|
||||||
report(fmt, arg1, arg2, arg3) char *fmt;
|
report(fmt, arg1, arg2, arg3) char *fmt;
|
||||||
{
|
{
|
||||||
fprint(STDERR, "%s (%d) F: ", curr_file, yylineno);
|
fprint(STDERR, "%s (%d) F: ", curr_file, yylineno);
|
||||||
|
@ -16,6 +17,7 @@ report(fmt, arg1, arg2, arg3) char *fmt;
|
||||||
err=1;
|
err=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*VARARGS1*/
|
||||||
warning(fmt, arg1, arg2, arg3) char *fmt, *arg1;
|
warning(fmt, arg1, arg2, arg3) char *fmt, *arg1;
|
||||||
{
|
{
|
||||||
fprint(STDERR, "%s (%d) E: ", curr_file, yylineno);
|
fprint(STDERR, "%s (%d) E: ", curr_file, yylineno);
|
||||||
|
@ -23,6 +25,7 @@ warning(fmt, arg1, arg2, arg3) char *fmt, *arg1;
|
||||||
fprint(STDERR,"\n");
|
fprint(STDERR,"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*VARARGS1*/
|
||||||
fatal(fmt, arg1, arg2, arg3) char *fmt, *arg1;
|
fatal(fmt, arg1, arg2, arg3) char *fmt, *arg1;
|
||||||
{
|
{
|
||||||
fprint(STDERR, "%s (%d) X: ", curr_file, yylineno);
|
fprint(STDERR, "%s (%d) X: ", curr_file, yylineno);
|
||||||
|
|
|
@ -13,7 +13,7 @@ int min_offset=0; /* Minimum of all offsets within current level */
|
||||||
|
|
||||||
static struct symtab *sym_table=nil;
|
static struct symtab *sym_table=nil;
|
||||||
|
|
||||||
char *malloc();
|
char *Malloc();
|
||||||
|
|
||||||
static struct symbol **search_sym(tree, name)
|
static struct symbol **search_sym(tree, name)
|
||||||
struct symbol **tree;
|
struct symbol **tree;
|
||||||
|
@ -46,7 +46,7 @@ struct symbol *insert(name, type, arr_siz, info)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
ps= (struct symbol *) malloc(sizeof *ps);
|
ps= (struct symbol *) Malloc(sizeof *ps);
|
||||||
|
|
||||||
ps->s_name=name;
|
ps->s_name=name;
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ void sym_down()
|
||||||
{
|
{
|
||||||
register struct symtab *ps;
|
register struct symtab *ps;
|
||||||
|
|
||||||
ps= (struct symtab *) malloc(sizeof *ps);
|
ps= (struct symtab *) Malloc(sizeof *ps);
|
||||||
|
|
||||||
ps->local=nil;
|
ps->local=nil;
|
||||||
ps->global=sym_table;
|
ps->global=sym_table;
|
||||||
|
@ -117,13 +117,13 @@ static void sym_destroy(ps) register struct symbol *ps;
|
||||||
while (par!=nil) {
|
while (par!=nil) {
|
||||||
junk=par;
|
junk=par;
|
||||||
par=par->pr_next;
|
par=par->pr_next;
|
||||||
free(junk);
|
free((char *)junk);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
if ((ps->s_type&T_TYPE)==T_CONST)
|
if ((ps->s_type&T_TYPE)==T_CONST)
|
||||||
destroy(ps->s_info.t_const);
|
destroy(ps->s_info.t_const);
|
||||||
free(ps->s_name);
|
free((char *)(ps->s_name));
|
||||||
free(ps);
|
free((char *)ps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ void pars_add(aapars, type, var)
|
||||||
{
|
{
|
||||||
register struct par_list *pl;
|
register struct par_list *pl;
|
||||||
|
|
||||||
pl= (struct par_list *) malloc(sizeof *pl);
|
pl= (struct par_list *) Malloc(sizeof *pl);
|
||||||
|
|
||||||
pl->pr_type=type;
|
pl->pr_type=type;
|
||||||
pl->pr_var=var;
|
pl->pr_var=var;
|
||||||
|
@ -204,4 +204,5 @@ int form_offsets(pars) register struct par_list *pars;
|
||||||
return offset+ ((var->s_type&T_ARR) ? pz : vz);
|
return offset+ ((var->s_type&T_ARR) ? pz : vz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return pz;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue