ref: b4943376dca886cda04f3cc2c955499a2bb13294
parent: b9d3ca5753cc1922236fc733605bc8b3caabc8c1
author: qwx <qwx@sciops.net>
date: Sun Oct 26 13:58:07 EDT 2025
awk: reduce size of Cell type by 8 bytes by rearranging fields
--- a/sys/src/cmd/awk/awk.h
+++ b/sys/src/cmd/awk/awk.h
@@ -58,10 +58,10 @@
typedef struct Cell {uchar ctype; /* OCELL, OBOOL, OJUMP, etc. */
uchar csub; /* CCON, CTEMP, CFLD, etc. */
+ short tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
char *nval; /* name, for variables only */
char *sval; /* string value */
Awkfloat fval; /* value as number */
- int tval; /* type info: STR|NUM|ARR|FCN|FLD|CON|DONTFREE */
struct Cell *cnext; /* ptr to next if chained */
} Cell;
--- a/sys/src/cmd/awk/lib.c
+++ b/sys/src/cmd/awk/lib.c
@@ -49,8 +49,8 @@
int argno = 1; /* current input argument number */
extern Awkfloat *AARGC;
-static Cell dollar0 = { OCELL, CFLD, nil, "", 0.0, REC|STR|DONTFREE };-static Cell dollar1 = { OCELL, CFLD, nil, "", 0.0, FLD|STR|DONTFREE };+static Cell dollar0 = { OCELL, CFLD, REC|STR|DONTFREE, nil, "", 0.0 };+static Cell dollar1 = { OCELL, CFLD, FLD|STR|DONTFREE, nil, "", 0.0 };void recinit(unsigned int n)
{--- a/sys/src/cmd/awk/run.c
+++ b/sys/src/cmd/awk/run.c
@@ -36,23 +36,23 @@
Node *winner = nil; /* root of parse tree */
Cell *tmps; /* free temporary cells for execution */
-static Cell truecell ={ OBOOL, BTRUE, 0, 0, 1.0, NUM };+static Cell truecell ={ OBOOL, BTRUE, NUM, 0, 0, 1.0 };Cell *True = &truecell;
-static Cell falsecell ={ OBOOL, BFALSE, 0, 0, 0.0, NUM };+static Cell falsecell ={ OBOOL, BFALSE, NUM, 0, 0, 0.0 };Cell *False = &falsecell;
-static Cell breakcell ={ OJUMP, JBREAK, 0, 0, 0.0, NUM };+static Cell breakcell ={ OJUMP, JBREAK, NUM, 0, 0, 0.0 };Cell *jbreak = &breakcell;
-static Cell contcell ={ OJUMP, JCONT, 0, 0, 0.0, NUM };+static Cell contcell ={ OJUMP, JCONT, NUM, 0, 0, 0.0 };Cell *jcont = &contcell;
-static Cell nextcell ={ OJUMP, JNEXT, 0, 0, 0.0, NUM };+static Cell nextcell ={ OJUMP, JNEXT, NUM, 0, 0, 0.0 };Cell *jnext = &nextcell;
-static Cell nextfilecell ={ OJUMP, JNEXTFILE, 0, 0, 0.0, NUM };+static Cell nextfilecell ={ OJUMP, JNEXTFILE, NUM, 0, 0, 0.0 };Cell *jnextfile = &nextfilecell;
-static Cell exitcell ={ OJUMP, JEXIT, 0, 0, 0.0, NUM };+static Cell exitcell ={ OJUMP, JEXIT, NUM, 0, 0, 0.0 };Cell *jexit = &exitcell;
-static Cell retcell ={ OJUMP, JRET, 0, 0, 0.0, NUM };+static Cell retcell ={ OJUMP, JRET, NUM, 0, 0, 0.0 };Cell *jret = &retcell;
-static Cell tempcell ={ OCELL, CTEMP, 0, "", 0.0, NUM|STR|DONTFREE };+static Cell tempcell ={ OCELL, CTEMP, NUM|STR|DONTFREE, 0, "", 0.0 };Node *curnode = nil; /* the node being executed, for debugging */
@@ -224,7 +224,7 @@
Cell *call(Node **a, int) /* function call. very kludgy and fragile */
{- static Cell newcopycell = { OCELL, CCOPY, 0, "", 0.0, NUM|STR|DONTFREE };+ static Cell newcopycell = { OCELL, CCOPY, NUM|STR|DONTFREE, 0, "", 0.0 };int i, ncall, ndef;
Node *x;
Cell *args[NARGS], *oargs[NARGS]; /* BUG: fixed size arrays */
--
⑨