<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -113,42 +113,8 @@ typedef enum { False = 0, True = 1 } Boolean;
 
 #define ELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
 
-// TODO:  Bascially all of these globals are going into the struct that
-// represents an instance of a Pez interpreter.  Furthermore, most are going
-// away when we add the GC.
-
-// This is the big global state area.  I'm preparing to wrap it all in a struct.
-// {
-
-/*  Local variables  */
-
-static char *instream = NULL;	// Current input stream line
-static long tokint;		// Scanned integer
-static pez_real tokreal;	// Scanned real number
-#ifdef ALIGNMENT
-Exported pez_real rbuf0, rbuf1, rbuf2;	// Real temporary buffers
-#endif
-
-// Circular buffer.
-#define MAX_IO_STREAMS 10
-static pez_stackitem output_stk[MAX_IO_STREAMS] =
-	{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
-static pez_stackitem input_stk[MAX_IO_STREAMS] =
-	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-static int output_idx = 0;
-static int input_idx = 0;
-#define output_stream output_stk[output_idx]
-#define input_stream input_stk[input_idx]
-
-// Like above...
-#define MAX_REGEXES 10
-static regex_t regexes[MAX_REGEXES];
-#define MAX_REGEX_MATCHES 20 // Hey, they're small.
-static regmatch_t regex_matches[MAX_REGEX_MATCHES];
-static int regex_idx = 0;
-
-// }
-// And that's the end of the wacky global state...I hope.
+#define output_stream p-&gt;output_stk[p-&gt;output_idx]
+#define input_stream p-&gt;input_stk[p-&gt;input_idx]
 
 #ifdef COPYRIGHT
 #ifndef HIGHC
@@ -425,12 +391,13 @@ static int lex(pez_instance *p, char **cp, char token_buffer[])
 			if(sscanf(token_buffer, &quot;%li%c&quot;, &amp;tokint, &amp;tc) == 1)
 				return TokInt;
 #else
-			tokint = strtoul(token_buffer, &amp;tcp, 0);
+			p-&gt;tokint = strtoul(token_buffer, &amp;tcp, 0);
 			if(*tcp == 0) {
 				return TokInt;
 			}
 #endif
-			if(sscanf(token_buffer, &quot;%lf%c&quot;, &amp;tokreal, &amp;tc) == 1) {
+			if(sscanf(token_buffer, &quot;%lf%c&quot;,
+						&amp;p-&gt;tokreal, &amp;tc) == 1) {
 				return TokReal;
 			}
 		}
@@ -1430,8 +1397,8 @@ prim P_regex(pez_instance *p)
 
 	Sl(2);
 
-	regfree(regexes + regex_idx);
-	regex_idx = (regex_idx + 1) % MAX_REGEXES;
+	regfree(p-&gt;regexes + p-&gt;regex_idx);
+	p-&gt;regex_idx = (p-&gt;regex_idx + 1) % MAX_REGEXES;
 
 	if(S0) {
 		if(strchr((char *)S0, 'i'))
@@ -1440,8 +1407,8 @@ prim P_regex(pez_instance *p)
 			flags |= REG_NEWLINE;
 	}
 
-	problem = regcomp(regexes + regex_idx, (char *)S1, flags);
-	S1 = problem ? 0 : (pez_stackitem)(regexes + regex_idx);
+	problem = regcomp(p-&gt;regexes + p-&gt;regex_idx, (char *)S1, flags);
+	S1 = problem ? 0 : (pez_stackitem)(p-&gt;regexes + p-&gt;regex_idx);
 	Pop;
 	return;
 }
@@ -1457,7 +1424,7 @@ prim P_rmatch(pez_instance *p)
 	Sl(2);
 
 	match = !regexec((regex_t *)S0, (char *)S1,
-			MAX_REGEX_MATCHES, regex_matches, 0);
+			MAX_REGEX_MATCHES, p-&gt;regex_matches, 0);
 	S1 = match ? Truth : Falsity;
 	Pop;
 }
@@ -1472,8 +1439,8 @@ prim P_rmatch(pez_instance *p)
    valid; check the offset to be sure if an optional part matched.)
 */
 #define PUSH_RX(fname,n) prim fname(pez_instance *p) { So(2); \
-	Push = regex_matches[n].rm_eo - regex_matches[n].rm_so;\
-	Push = regex_matches[n].rm_so;\
+		Push = p-&gt;regex_matches[n].rm_eo - p-&gt;regex_matches[n].rm_so;\
+		Push = p-&gt;regex_matches[n].rm_so;\
 	}
 PUSH_RX(P_money0, 0)
 PUSH_RX(P_money1, 1)
@@ -2059,7 +2026,7 @@ prim P_words(pez_instance *p)
 prim P_tooutput(pez_instance *p)
 {
 	Sl(1);
-	output_idx = (output_idx + 1) % MAX_IO_STREAMS;
+	p-&gt;output_idx = (p-&gt;output_idx + 1) % MAX_IO_STREAMS;
 	output_stream = S0;
 	Pop;
 }
@@ -2071,7 +2038,7 @@ prim P_tooutput(pez_instance *p)
 prim P_toinput(pez_instance *p)
 {
 	Sl(1);
-	input_idx = (input_idx + 1) % MAX_IO_STREAMS;
+	p-&gt;input_idx = (p-&gt;input_idx + 1) % MAX_IO_STREAMS;
 	input_stream = S0;
 	Pop;
 }
@@ -2084,7 +2051,7 @@ prim P_outputto(pez_instance *p)
 {
 	So(1);
 	Push = output_stream;
-	output_idx = (output_idx + MAX_IO_STREAMS - 1) % MAX_IO_STREAMS;
+	p-&gt;output_idx = (p-&gt;output_idx + MAX_IO_STREAMS - 1) % MAX_IO_STREAMS;
 }
 
 /*
@@ -2095,7 +2062,7 @@ prim P_inputto(pez_instance *p)
 {
 	So(1);
 	Push = input_stream;
-	input_idx = (input_idx + MAX_IO_STREAMS - 1) % MAX_IO_STREAMS;
+	p-&gt;input_idx = (p-&gt;input_idx + MAX_IO_STREAMS - 1) % MAX_IO_STREAMS;
 }
 
 /*
@@ -2206,7 +2173,7 @@ prim P_evaluate(pez_instance *p)
 	pez_statemark mk;
 	pez_int scomm = p-&gt;comment;	// Stack comment pending state
 	pez_dictword **sip = p-&gt;ip;		// Stack instruction pointer
-	char *sinstr = instream;	// Stack input stream
+	char *sinstr = p-&gt;instream;	// Stack input stream
 	char *estring;
 
 	Sl(1);
@@ -2227,7 +2194,7 @@ prim P_evaluate(pez_instance *p)
 	}
 	p-&gt;comment = scomm;	// Unstack comment pending status
 	p-&gt;ip = sip;		// Unstack instruction pointer
-	instream = sinstr;	// Unstack input stream
+	p-&gt;instream = sinstr;	// Unstack input stream
 	So(1);
 	Push = es;		// Return eval status on top of stack
 }
@@ -3067,7 +3034,7 @@ prim P_tick(pez_instance *p)
 	   report an error.  Since we can't call back to the
 	   calling program for more input, we're stuck. */
 
-	token = lex(p, &amp;instream, token_buffer);	// Scan for next token
+	token = lex(p, &amp;p-&gt;instream, token_buffer);	// Scan for next token
 	if(token != TokNull) {
 		if(token == TokWord) {
 			pez_dictword *di;
@@ -4272,6 +4239,15 @@ extern pez_instance *pez_init()
 	p-&gt;ltempstr = max(PATH_MAX, 4096);// Temporary string buffer length
 	p-&gt;base = 10;
 	p-&gt;broken = Falsity;
+	p-&gt;instream = NULL;
+
+	for(i = 0; i &lt; MAX_IO_STREAMS; i++) {
+		p-&gt;output_stk[i] = 1;
+		p-&gt;input_stk[i] = 0;
+	}
+	p-&gt;output_idx = 0;
+	p-&gt;input_idx = 0;
+	p-&gt;regex_idx = 0;
 
 	pez_primdef(p, primt);  // Define primitive words
 	p-&gt;dictprot = p-&gt;dict;  // Set protected mark in dictionary, now that we
@@ -4373,7 +4349,7 @@ extern pez_instance *pez_init()
 	// going away when interpreter instances are implemented and
 	// memory management gets overhauled.  Until then:  hackery.
 	for(i = 0; i &lt; MAX_REGEXES; i++)
-		regcomp(regexes + i, &quot;&quot;, REG_EXTENDED);
+		regcomp(p-&gt;regexes + i, &quot;.*&quot;, REG_EXTENDED);
 
 #ifdef FILEIO
 	{
@@ -4549,7 +4525,7 @@ int pez_load(pez_instance *p, FILE *fp)
 	pez_statemark mk;
 	pez_int scomm = p-&gt;comment;	// Stack comment pending state
 	pez_dictword **sip = p-&gt;ip;	// Stack instruction pointer
-	char *sinstr = instream;	// Stack input stream
+	char *sinstr = p-&gt;instream;	// Stack input stream
 	int lineno = 0;		// Current line number
 
 	p-&gt;errline = 0;	// Reset line number of error
@@ -4575,7 +4551,7 @@ int pez_load(pez_instance *p, FILE *fp)
 	}
 	p-&gt;comment = scomm;	// Unstack comment pending status
 	p-&gt;ip = sip;		// Unstack instruction pointer
-	instream = sinstr;	// Unstack input stream
+	p-&gt;instream = sinstr;	// Unstack input stream
 	return es;
 }
 
@@ -4783,7 +4759,7 @@ int pez_eval(pez_instance *p, char *sp)
 
 #undef Memerrs
 #define Memerrs p-&gt;evalstat
-	instream = sp;
+	p-&gt;instream = sp;
 	p-&gt;evalstat = PEZ_SNORM;	 // Set normal evaluation status
 #ifdef BREAK
 	p-&gt;broken = False;		 // Reset asynchronous break
@@ -4804,7 +4780,7 @@ int pez_eval(pez_instance *p, char *sp)
 #endif				// PROLOGUE
 
 	while((p-&gt;evalstat == PEZ_SNORM) &amp;&amp;
-		(token = lex(p, &amp;instream, token_buffer)) != TokNull) {
+		(token = lex(p, &amp;p-&gt;instream, token_buffer)) != TokNull) {
 		pez_dictword *di;
 
 		switch (token) {
@@ -4857,16 +4833,16 @@ int pez_eval(pez_instance *p, char *sp)
 
 		case TokInt:
 			if(state)
-				pez_heap_int(p, tokint);
+				pez_heap_int(p, p-&gt;tokint);
 			else
-				pez_stack_int(p, tokint);
+				pez_stack_int(p, p-&gt;tokint);
 			break;
 
 		case TokReal:
 			if(state)
-				pez_heap_real(p, tokreal);
+				pez_heap_real(p, p-&gt;tokreal);
 			else
-				pez_stack_real(p, tokreal);
+				pez_stack_real(p, p-&gt;tokreal);
 			break;
 
 		case TokString:</diff>
      <filename>pez.c</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,12 @@
 
 #include &lt;config.h&gt;
 
+#include &lt;regex.h&gt;
+
+#define MAX_IO_STREAMS 10
+#define MAX_REGEXES 10
+#define MAX_REGEX_MATCHES 20 // Hey, they're small.
+
 typedef long pez_int;		// Stack integer type
 typedef double pez_real;	// Real number type
 typedef long pez_stackitem;
@@ -76,6 +82,11 @@ struct pez_inst {
 	pez_int ctickpend;	// Waiting for the object of a [']?
 	pez_int cbrackpend;	// Waiting for the object of a [COMPILE]?
 
+	// Lexing:
+	char *instream;		// Current input stream line
+	pez_int tokint;		// Scanned integer
+	pez_real tokreal;	// Scanned real number
+
 	// Running code:
 	pez_dictword *curword;	// Current word being executed
 	pez_dictword **ip;	// Instruction pointer
@@ -113,6 +124,26 @@ struct pez_inst {
 	pez_dictword **wback;	// Walkback trace buffer
 	pez_dictword **wbptr;	// Walkback trace pointer
 
+	// I/O, as code running in Pez sees it:
+	pez_stackitem output_stk[MAX_IO_STREAMS];
+	pez_stackitem input_stk[MAX_IO_STREAMS];
+	int output_idx;
+	int input_idx;
+
+	// Regexes:
+	regex_t regexes[MAX_REGEXES];
+	regmatch_t regex_matches[MAX_REGEX_MATCHES];
+	int regex_idx;
+
+	/* 
+	   These are temporary buffers, for the case where an architecture 
+	   1.  requires floats to be aligned
+	   2.  has floats that are larger than longs (as everything on the stack
+	       is long-aligned)
+	   We memcpy floats from the stack into the buffers before using them.
+	*/
+	pez_real rbuf0, rbuf1, rbuf2;	
+
 	pez_int argc;
 	char **argv;	// The argv that the pez program sees.
 };</diff>
      <filename>pez.h</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>354894904d7b3146e65e02858c0a5bf74f1fe67e</id>
    </parent>
  </parents>
  <author>
    <name>Pete Elmore</name>
    <email>1337p337@gmail.com</email>
  </author>
  <url>http://github.com/pete/pez/commit/f5dea87ca449fc1267b59f76cb1d4d6e0534a855</url>
  <id>f5dea87ca449fc1267b59f76cb1d4d6e0534a855</id>
  <committed-date>2009-10-26T21:34:40-07:00</committed-date>
  <authored-date>2009-10-26T21:34:40-07:00</authored-date>
  <message>That's the last of the global state.</message>
  <tree>095a686044d2b2928b7034e54b5052a2fe2b85b6</tree>
  <committer>
    <name>Pete Elmore</name>
    <email>1337p337@gmail.com</email>
  </committer>
</commit>
