i hate []
This commit is contained in:
parent
a196bf0577
commit
e637c944fe
5 changed files with 150 additions and 118 deletions
|
|
@ -76,6 +76,7 @@ enum
|
||||||
TSTRING,
|
TSTRING,
|
||||||
TLIST,
|
TLIST,
|
||||||
TCODE,
|
TCODE,
|
||||||
|
NUMT,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Type
|
struct Type
|
||||||
|
|
@ -211,6 +212,8 @@ void gc(void);
|
||||||
char* getstatus(int);
|
char* getstatus(int);
|
||||||
void* gmalloc(long);
|
void* gmalloc(long);
|
||||||
void indir(Map*, ulong, char, Node*);
|
void indir(Map*, ulong, char, Node*);
|
||||||
|
void initexpr(void);
|
||||||
|
void initprint(void);
|
||||||
void installbuiltin(void);
|
void installbuiltin(void);
|
||||||
void kinit(void);
|
void kinit(void);
|
||||||
int Zfmt(Fmt*);
|
int Zfmt(Fmt*);
|
||||||
|
|
@ -311,4 +314,5 @@ enum
|
||||||
OFMT,
|
OFMT,
|
||||||
OEVAL,
|
OEVAL,
|
||||||
OWHAT,
|
OWHAT,
|
||||||
|
NUMO,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,36 +6,39 @@
|
||||||
#define Extern extern
|
#define Extern extern
|
||||||
#include "acid.h"
|
#include "acid.h"
|
||||||
|
|
||||||
static int fsize[] =
|
static int fsize[256];
|
||||||
|
|
||||||
|
static void
|
||||||
|
initfsize(void)
|
||||||
{
|
{
|
||||||
['A'] 4,
|
fsize['A'] = 4;
|
||||||
['B'] 4,
|
fsize['B'] = 4;
|
||||||
['C'] 1,
|
fsize['C'] = 1;
|
||||||
['D'] 4,
|
fsize['D'] = 4;
|
||||||
['F'] 8,
|
fsize['F'] = 8;
|
||||||
['G'] 8,
|
fsize['G'] = 8;
|
||||||
['O'] 4,
|
fsize['O'] = 4;
|
||||||
['Q'] 4,
|
fsize['Q'] = 4;
|
||||||
['R'] 4,
|
fsize['R'] = 4;
|
||||||
['S'] 4,
|
fsize['S'] = 4;
|
||||||
['U'] 4,
|
fsize['U'] = 4;
|
||||||
['V'] 8,
|
fsize['V'] = 8;
|
||||||
['X'] 4,
|
fsize['X'] = 4;
|
||||||
['Y'] 8,
|
fsize['Y'] = 8;
|
||||||
['W'] 8,
|
fsize['W'] = 8;
|
||||||
['Z'] 8,
|
fsize['Z'] = 8;
|
||||||
['a'] 4,
|
fsize['a'] = 4;
|
||||||
['b'] 1,
|
fsize['b'] = 1;
|
||||||
['c'] 1,
|
fsize['c'] = 1;
|
||||||
['d'] 2,
|
fsize['d'] = 2;
|
||||||
['f'] 4,
|
fsize['f'] = 4;
|
||||||
['g'] 4,
|
fsize['g'] = 4;
|
||||||
['o'] 2,
|
fsize['o'] = 2;
|
||||||
['q'] 2,
|
fsize['q'] = 2;
|
||||||
['r'] 2,
|
fsize['r'] = 2;
|
||||||
['s'] 4,
|
fsize['s'] = 4;
|
||||||
['u'] 2,
|
fsize['u'] = 2;
|
||||||
['x'] 2,
|
fsize['x'] = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
@ -964,55 +967,66 @@ owhat(Node *n, Node *res)
|
||||||
whatis(n->sym);
|
whatis(n->sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
void (*expop[])(Node*, Node*) =
|
void (*expop[NUMO])(Node*, Node*);
|
||||||
|
|
||||||
|
static void
|
||||||
|
initexpop(void)
|
||||||
{
|
{
|
||||||
[ONAME] oname,
|
expop[ONAME] = oname;
|
||||||
[OCONST] oconst,
|
expop[OCONST] = oconst;
|
||||||
[OMUL] omul,
|
expop[OMUL] = omul;
|
||||||
[ODIV] odiv,
|
expop[ODIV] = odiv;
|
||||||
[OMOD] omod,
|
expop[OMOD] = omod;
|
||||||
[OADD] oadd,
|
expop[OADD] = oadd;
|
||||||
[OSUB] osub,
|
expop[OSUB] = osub;
|
||||||
[ORSH] orsh,
|
expop[ORSH] = orsh;
|
||||||
[OLSH] olsh,
|
expop[OLSH] = olsh;
|
||||||
[OLT] olt,
|
expop[OLT] = olt;
|
||||||
[OGT] ogt,
|
expop[OGT] = ogt;
|
||||||
[OLEQ] oleq,
|
expop[OLEQ] = oleq;
|
||||||
[OGEQ] ogeq,
|
expop[OGEQ] = ogeq;
|
||||||
[OEQ] oeq,
|
expop[OEQ] = oeq;
|
||||||
[ONEQ] oeq,
|
expop[ONEQ] = oeq;
|
||||||
[OLAND] oland,
|
expop[OLAND] = oland;
|
||||||
[OXOR] oxor,
|
expop[OXOR] = oxor;
|
||||||
[OLOR] olor,
|
expop[OLOR] = olor;
|
||||||
[OCAND] ocand,
|
expop[OCAND] = ocand;
|
||||||
[OCOR] ocor,
|
expop[OCOR] = ocor;
|
||||||
[OASGN] oasgn,
|
expop[OASGN] = oasgn;
|
||||||
[OINDM] oindm,
|
expop[OINDM] = oindm;
|
||||||
[OEDEC] oeinc,
|
expop[OEDEC] = oeinc;
|
||||||
[OEINC] oeinc,
|
expop[OEINC] = oeinc;
|
||||||
[OPINC] opinc,
|
expop[OPINC] = opinc;
|
||||||
[OPDEC] opinc,
|
expop[OPDEC] = opinc;
|
||||||
[ONOT] onot,
|
expop[ONOT] = onot;
|
||||||
[OIF] 0,
|
expop[OIF] = 0;
|
||||||
[ODO] 0,
|
expop[ODO] = 0;
|
||||||
[OLIST] olist,
|
expop[OLIST] = olist;
|
||||||
[OCALL] ocall,
|
expop[OCALL] = ocall;
|
||||||
[OCTRUCT] octruct,
|
expop[OCTRUCT] = octruct;
|
||||||
[OWHILE] 0,
|
expop[OWHILE] =0;
|
||||||
[OELSE] 0,
|
expop[OELSE] = 0;
|
||||||
[OHEAD] ohead,
|
expop[OHEAD] = ohead;
|
||||||
[OTAIL] otail,
|
expop[OTAIL] = otail;
|
||||||
[OAPPEND] oappend,
|
expop[OAPPEND] = oappend;
|
||||||
[ORET] 0,
|
expop[ORET] = 0;
|
||||||
[OINDEX] oindex,
|
expop[OINDEX] =oindex;
|
||||||
[OINDC] oindc,
|
expop[OINDC] = oindc;
|
||||||
[ODOT] odot,
|
expop[ODOT] = odot;
|
||||||
[OLOCAL] 0,
|
expop[OLOCAL] =0;
|
||||||
[OFRAME] oframe,
|
expop[OFRAME] = oframe;
|
||||||
[OCOMPLEX] 0,
|
expop[OCOMPLEX] =0;
|
||||||
[ODELETE] odelete,
|
expop[ODELETE] = odelete;
|
||||||
[OCAST] ocast,
|
expop[OCAST] = ocast;
|
||||||
[OFMT] ofmt,
|
expop[OFMT] = ofmt;
|
||||||
[OEVAL] oeval,
|
expop[OEVAL] = oeval;
|
||||||
[OWHAT] owhat,
|
expop[OWHAT] = owhat;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
initexpr(void)
|
||||||
|
{
|
||||||
|
initfsize();
|
||||||
|
initexpop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,18 +37,21 @@ keywds[] =
|
||||||
0, 0
|
0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
char cmap[256] =
|
char cmap[256];
|
||||||
|
|
||||||
|
void
|
||||||
|
initcmap(void)
|
||||||
{
|
{
|
||||||
['0'] '\0'+1,
|
cmap['0']= '\0'+1;
|
||||||
['n'] '\n'+1,
|
cmap['n']= '\n'+1;
|
||||||
['r'] '\r'+1,
|
cmap['r']= '\r'+1;
|
||||||
['t'] '\t'+1,
|
cmap['t']= '\t'+1;
|
||||||
['b'] '\b'+1,
|
cmap['b']= '\b'+1;
|
||||||
['f'] '\f'+1,
|
cmap['f']= '\f'+1;
|
||||||
['a'] '\a'+1,
|
cmap['a']= '\a'+1;
|
||||||
['v'] '\v'+1,
|
cmap['v']= '\v'+1;
|
||||||
['\\'] '\\'+1,
|
cmap['\\']= '\\'+1;
|
||||||
['"'] '"'+1,
|
cmap['"']= '"'+1;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -56,6 +59,8 @@ kinit(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
initcmap();
|
||||||
|
|
||||||
for(i = 0; keywds[i].name; i++)
|
for(i = 0; keywds[i].name; i++)
|
||||||
enter(keywds[i].name, keywds[i].terminal);
|
enter(keywds[i].name, keywds[i].terminal);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ main(int argc, char *argv[])
|
||||||
Binit(&bioout, 1, OWRITE);
|
Binit(&bioout, 1, OWRITE);
|
||||||
bout = &bioout;
|
bout = &bioout;
|
||||||
|
|
||||||
|
initexpr();
|
||||||
kinit();
|
kinit();
|
||||||
initialising = 1;
|
initialising = 1;
|
||||||
pushfile(0);
|
pushfile(0);
|
||||||
|
|
|
||||||
|
|
@ -6,39 +6,47 @@
|
||||||
#define Extern extern
|
#define Extern extern
|
||||||
#include "acid.h"
|
#include "acid.h"
|
||||||
|
|
||||||
static char *binop[] =
|
static char *binop[NUMO];
|
||||||
|
|
||||||
|
static void
|
||||||
|
initbinop(void)
|
||||||
{
|
{
|
||||||
[OMUL] "*",
|
binop[OMUL]= "*";
|
||||||
[ODIV] "/",
|
binop[ODIV]= "/";
|
||||||
[OMOD] "%",
|
binop[OMOD]= "%";
|
||||||
[OADD] "+",
|
binop[OADD]= "+";
|
||||||
[OSUB] "-",
|
binop[OSUB]= "-";
|
||||||
[ORSH] ">>",
|
binop[ORSH]= ">>";
|
||||||
[OLSH] "<<",
|
binop[OLSH]= "<<";
|
||||||
[OLT] "<",
|
binop[OLT]= "<";
|
||||||
[OGT] ">",
|
binop[OGT]= ">";
|
||||||
[OLEQ] "<=",
|
binop[OLEQ]= "<=";
|
||||||
[OGEQ] ">=",
|
binop[OGEQ]= ">=";
|
||||||
[OEQ] "==",
|
binop[OEQ]= "==";
|
||||||
[ONEQ] "!=",
|
binop[ONEQ]= "!=";
|
||||||
[OLAND] "&",
|
binop[OLAND]= "&";
|
||||||
[OXOR] "^",
|
binop[OXOR]= "^";
|
||||||
[OLOR] "|",
|
binop[OLOR]= "|";
|
||||||
[OCAND] "&&",
|
binop[OCAND]= "&&";
|
||||||
[OCOR] "||",
|
binop[OCOR]= "||";
|
||||||
[OASGN] " = ",
|
binop[OASGN]= " = ";
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
static char *tabs = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
|
||||||
char *typenames[] =
|
char *typenames[] = {
|
||||||
{
|
"integer",
|
||||||
[TINT] "integer",
|
"float",
|
||||||
[TFLOAT] "float",
|
"string",
|
||||||
[TSTRING] "string",
|
"list",
|
||||||
[TLIST] "list",
|
"code",
|
||||||
[TCODE] "code",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
initprint(void)
|
||||||
|
{
|
||||||
|
initbinop();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
cmp(const void *va, const void *vb)
|
cmp(const void *va, const void *vb)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue