i hate []

This commit is contained in:
rsc 2004-04-20 01:42:20 +00:00
parent a196bf0577
commit e637c944fe
5 changed files with 150 additions and 118 deletions

View file

@ -76,6 +76,7 @@ enum
TSTRING,
TLIST,
TCODE,
NUMT,
};
struct Type
@ -211,6 +212,8 @@ void gc(void);
char* getstatus(int);
void* gmalloc(long);
void indir(Map*, ulong, char, Node*);
void initexpr(void);
void initprint(void);
void installbuiltin(void);
void kinit(void);
int Zfmt(Fmt*);
@ -311,4 +314,5 @@ enum
OFMT,
OEVAL,
OWHAT,
NUMO,
};

View file

@ -6,36 +6,39 @@
#define Extern extern
#include "acid.h"
static int fsize[] =
static int fsize[256];
static void
initfsize(void)
{
['A'] 4,
['B'] 4,
['C'] 1,
['D'] 4,
['F'] 8,
['G'] 8,
['O'] 4,
['Q'] 4,
['R'] 4,
['S'] 4,
['U'] 4,
['V'] 8,
['X'] 4,
['Y'] 8,
['W'] 8,
['Z'] 8,
['a'] 4,
['b'] 1,
['c'] 1,
['d'] 2,
['f'] 4,
['g'] 4,
['o'] 2,
['q'] 2,
['r'] 2,
['s'] 4,
['u'] 2,
['x'] 2,
fsize['A'] = 4;
fsize['B'] = 4;
fsize['C'] = 1;
fsize['D'] = 4;
fsize['F'] = 8;
fsize['G'] = 8;
fsize['O'] = 4;
fsize['Q'] = 4;
fsize['R'] = 4;
fsize['S'] = 4;
fsize['U'] = 4;
fsize['V'] = 8;
fsize['X'] = 4;
fsize['Y'] = 8;
fsize['W'] = 8;
fsize['Z'] = 8;
fsize['a'] = 4;
fsize['b'] = 1;
fsize['c'] = 1;
fsize['d'] = 2;
fsize['f'] = 4;
fsize['g'] = 4;
fsize['o'] = 2;
fsize['q'] = 2;
fsize['r'] = 2;
fsize['s'] = 4;
fsize['u'] = 2;
fsize['x'] = 2;
};
int
@ -964,55 +967,66 @@ owhat(Node *n, Node *res)
whatis(n->sym);
}
void (*expop[])(Node*, Node*) =
void (*expop[NUMO])(Node*, Node*);
static void
initexpop(void)
{
[ONAME] oname,
[OCONST] oconst,
[OMUL] omul,
[ODIV] odiv,
[OMOD] omod,
[OADD] oadd,
[OSUB] osub,
[ORSH] orsh,
[OLSH] olsh,
[OLT] olt,
[OGT] ogt,
[OLEQ] oleq,
[OGEQ] ogeq,
[OEQ] oeq,
[ONEQ] oeq,
[OLAND] oland,
[OXOR] oxor,
[OLOR] olor,
[OCAND] ocand,
[OCOR] ocor,
[OASGN] oasgn,
[OINDM] oindm,
[OEDEC] oeinc,
[OEINC] oeinc,
[OPINC] opinc,
[OPDEC] opinc,
[ONOT] onot,
[OIF] 0,
[ODO] 0,
[OLIST] olist,
[OCALL] ocall,
[OCTRUCT] octruct,
[OWHILE] 0,
[OELSE] 0,
[OHEAD] ohead,
[OTAIL] otail,
[OAPPEND] oappend,
[ORET] 0,
[OINDEX] oindex,
[OINDC] oindc,
[ODOT] odot,
[OLOCAL] 0,
[OFRAME] oframe,
[OCOMPLEX] 0,
[ODELETE] odelete,
[OCAST] ocast,
[OFMT] ofmt,
[OEVAL] oeval,
[OWHAT] owhat,
expop[ONAME] = oname;
expop[OCONST] = oconst;
expop[OMUL] = omul;
expop[ODIV] = odiv;
expop[OMOD] = omod;
expop[OADD] = oadd;
expop[OSUB] = osub;
expop[ORSH] = orsh;
expop[OLSH] = olsh;
expop[OLT] = olt;
expop[OGT] = ogt;
expop[OLEQ] = oleq;
expop[OGEQ] = ogeq;
expop[OEQ] = oeq;
expop[ONEQ] = oeq;
expop[OLAND] = oland;
expop[OXOR] = oxor;
expop[OLOR] = olor;
expop[OCAND] = ocand;
expop[OCOR] = ocor;
expop[OASGN] = oasgn;
expop[OINDM] = oindm;
expop[OEDEC] = oeinc;
expop[OEINC] = oeinc;
expop[OPINC] = opinc;
expop[OPDEC] = opinc;
expop[ONOT] = onot;
expop[OIF] = 0;
expop[ODO] = 0;
expop[OLIST] = olist;
expop[OCALL] = ocall;
expop[OCTRUCT] = octruct;
expop[OWHILE] =0;
expop[OELSE] = 0;
expop[OHEAD] = ohead;
expop[OTAIL] = otail;
expop[OAPPEND] = oappend;
expop[ORET] = 0;
expop[OINDEX] =oindex;
expop[OINDC] = oindc;
expop[ODOT] = odot;
expop[OLOCAL] =0;
expop[OFRAME] = oframe;
expop[OCOMPLEX] =0;
expop[ODELETE] = odelete;
expop[OCAST] = ocast;
expop[OFMT] = ofmt;
expop[OEVAL] = oeval;
expop[OWHAT] = owhat;
};
void
initexpr(void)
{
initfsize();
initexpop();
}

View file

@ -37,25 +37,30 @@ keywds[] =
0, 0
};
char cmap[256] =
char cmap[256];
void
initcmap(void)
{
['0'] '\0'+1,
['n'] '\n'+1,
['r'] '\r'+1,
['t'] '\t'+1,
['b'] '\b'+1,
['f'] '\f'+1,
['a'] '\a'+1,
['v'] '\v'+1,
['\\'] '\\'+1,
['"'] '"'+1,
cmap['0']= '\0'+1;
cmap['n']= '\n'+1;
cmap['r']= '\r'+1;
cmap['t']= '\t'+1;
cmap['b']= '\b'+1;
cmap['f']= '\f'+1;
cmap['a']= '\a'+1;
cmap['v']= '\v'+1;
cmap['\\']= '\\'+1;
cmap['"']= '"'+1;
};
void
kinit(void)
{
int i;
initcmap();
for(i = 0; keywds[i].name; i++)
enter(keywds[i].name, keywds[i].terminal);
}

View file

@ -76,6 +76,7 @@ main(int argc, char *argv[])
Binit(&bioout, 1, OWRITE);
bout = &bioout;
initexpr();
kinit();
initialising = 1;
pushfile(0);

View file

@ -6,39 +6,47 @@
#define Extern extern
#include "acid.h"
static char *binop[] =
static char *binop[NUMO];
static void
initbinop(void)
{
[OMUL] "*",
[ODIV] "/",
[OMOD] "%",
[OADD] "+",
[OSUB] "-",
[ORSH] ">>",
[OLSH] "<<",
[OLT] "<",
[OGT] ">",
[OLEQ] "<=",
[OGEQ] ">=",
[OEQ] "==",
[ONEQ] "!=",
[OLAND] "&",
[OXOR] "^",
[OLOR] "|",
[OCAND] "&&",
[OCOR] "||",
[OASGN] " = ",
binop[OMUL]= "*";
binop[ODIV]= "/";
binop[OMOD]= "%";
binop[OADD]= "+";
binop[OSUB]= "-";
binop[ORSH]= ">>";
binop[OLSH]= "<<";
binop[OLT]= "<";
binop[OGT]= ">";
binop[OLEQ]= "<=";
binop[OGEQ]= ">=";
binop[OEQ]= "==";
binop[ONEQ]= "!=";
binop[OLAND]= "&";
binop[OXOR]= "^";
binop[OLOR]= "|";
binop[OCAND]= "&&";
binop[OCOR]= "||";
binop[OASGN]= " = ";
};
static char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
char *typenames[] =
{
[TINT] "integer",
[TFLOAT] "float",
[TSTRING] "string",
[TLIST] "list",
[TCODE] "code",
char *typenames[] = {
"integer",
"float",
"string",
"list",
"code",
};
void
initprint(void)
{
initbinop();
}
int
cmp(const void *va, const void *vb)
{