aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acid
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-20 01:42:20 +0000
committerrsc <devnull@localhost>2004-04-20 01:42:20 +0000
commite637c944febf271252e59742aa108d6e0a527eb7 (patch)
treee4ace5415b3b978ceca3685d2ea3eebe855a9b76 /src/cmd/acid
parenta196bf0577767d97165f01186b32b0913430a1fe (diff)
downloadplan9port-e637c944febf271252e59742aa108d6e0a527eb7.tar.gz
plan9port-e637c944febf271252e59742aa108d6e0a527eb7.tar.bz2
plan9port-e637c944febf271252e59742aa108d6e0a527eb7.zip
i hate []
Diffstat (limited to 'src/cmd/acid')
-rw-r--r--src/cmd/acid/acid.h4
-rw-r--r--src/cmd/acid/expr.c176
-rw-r--r--src/cmd/acid/lex.c29
-rw-r--r--src/cmd/acid/main.c1
-rw-r--r--src/cmd/acid/print.c62
5 files changed, 152 insertions, 120 deletions
diff --git a/src/cmd/acid/acid.h b/src/cmd/acid/acid.h
index ae835ef9..a26781c0 100644
--- a/src/cmd/acid/acid.h
+++ b/src/cmd/acid/acid.h
@@ -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,
};
diff --git a/src/cmd/acid/expr.c b/src/cmd/acid/expr.c
index 46e522bf..18b68f4e 100644
--- a/src/cmd/acid/expr.c
+++ b/src/cmd/acid/expr.c
@@ -6,36 +6,39 @@
#define Extern extern
#include "acid.h"
-static int fsize[] =
-{
- ['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,
+static int fsize[256];
+
+static void
+initfsize(void)
+{
+ 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*) =
-{
- [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,
+void (*expop[NUMO])(Node*, Node*);
+
+static void
+initexpop(void)
+{
+ 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();
+}
+
diff --git a/src/cmd/acid/lex.c b/src/cmd/acid/lex.c
index 40f6400e..db11eb1c 100644
--- a/src/cmd/acid/lex.c
+++ b/src/cmd/acid/lex.c
@@ -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);
}
diff --git a/src/cmd/acid/main.c b/src/cmd/acid/main.c
index 9c57ae6a..89bca4c3 100644
--- a/src/cmd/acid/main.c
+++ b/src/cmd/acid/main.c
@@ -76,6 +76,7 @@ main(int argc, char *argv[])
Binit(&bioout, 1, OWRITE);
bout = &bioout;
+ initexpr();
kinit();
initialising = 1;
pushfile(0);
diff --git a/src/cmd/acid/print.c b/src/cmd/acid/print.c
index 00d7b737..96021037 100644
--- a/src/cmd/acid/print.c
+++ b/src/cmd/acid/print.c
@@ -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)
{