Committed the other changes done during a failed attempt of else

Mon, 30 Jul 2012 11:34:57 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 30 Jul 2012 11:34:57 +0300
changeset 40
9e4f785501db
parent 39
07b7ab8080cf
child 41
47e686c96d8f

Committed the other changes done during a failed attempt of else

databuffer.h file | annotate | diff | comparison | revisions
parser.cxx file | annotate | diff | comparison | revisions
scriptreader.h file | annotate | diff | comparison | revisions
--- a/databuffer.h	Mon Jul 30 11:14:02 2012 +0300
+++ b/databuffer.h	Mon Jul 30 11:34:57 2012 +0300
@@ -138,10 +138,8 @@
 		if (!other)
 			return;
 		
-		for (unsigned int x = 0; x < other->writesize; x++) {
-			unsigned char c = *(other->buffer+x);
-			Write<unsigned char> (c);
-		}
+		for (unsigned int x = 0; x < other->writesize; x++)
+			Write<unsigned char> (*(other->buffer+x));
 		
 		// Merge its marks and references
 		unsigned int u = 0;
@@ -162,6 +160,14 @@
 		delete other;
 	}
 	
+	// Clones this databuffer to a new one and returns it.
+	DataBuffer* Clone () {
+		DataBuffer* other = new DataBuffer;
+		for (unsigned int x = 0; x < writesize; x++)
+			other->Write<unsigned char> (*(buffer+x));
+		return other;
+	}
+	
 	// ====================================================================
 	// Adds a mark to the buffer. A mark is a reference to a particular
 	// position in the bytecode. The actual permanent position cannot
@@ -229,6 +235,12 @@
 			return;
 		marks[mark]->pos = writesize;
 	}
+	
+	// Dump the buffer (for debugging purposes)
+	void Dump() {
+		for (unsigned int x = 0; x < writesize; x++)
+			printf ("%d. [%d]\n", x, *(buffer+x));
+	}
 };
 
 #endif // __DATABUFFER_H__
\ No newline at end of file
--- a/parser.cxx	Mon Jul 30 11:14:02 2012 +0300
+++ b/parser.cxx	Mon Jul 30 11:34:57 2012 +0300
@@ -64,13 +64,13 @@
 bool g_stateSpawnDefined = false;
 bool g_GotMainLoop = false;
 unsigned int g_BlockStackCursor = 0;
+DataBuffer* g_IfExpression = NULL;
 
 // ============================================================================
 // Main parser code. Begins read of the script file, checks the syntax of it
 // and writes the data to the object file via ObjWriter - which also takes care
 // of necessary buffering so stuff is written in the correct order.
 void ScriptReader::BeginParse (ObjWriter* w) {
-	g_BlockStackCursor = 0;
 	while (Next()) {
 		if (!token.icompare ("state")) {
 			MUST_TOPLEVEL
@@ -206,7 +206,7 @@
 			// Condition
 			MustNext ("(");
 			
-			// Read the expression and write it.
+			// Read the expression and write it. Store it to memory too for else statements.
 			MustNext ();
 			DataBuffer* c = ParseExpression (TYPE_INT);
 			w->WriteBuffer (c);
@@ -214,18 +214,9 @@
 			MustNext (")");
 			MustNext ("{");
 			
-			// Add a mark - to here temporarily - and add a reference to it.
-			// Upon a closing brace, the mark will be adjusted.
-			unsigned int marknum = w->AddMark (MARKTYPE_IF, "");
-			
 			// Use DH_IFNOTGOTO - if the expression is not true, we goto the mark
 			// we just defined - and this mark will be at the end of the block.
-			w->Write<word> (DH_IFNOTGOTO);
-			w->AddReference (marknum);
-			
-			// Store it in the block stack
-			g_BlockStackCursor++;
-			blockstack[g_BlockStackCursor] = marknum;
+			AddBlockMark (w, DH_IFNOTGOTO);
 			continue;
 		}
 		
@@ -562,4 +553,18 @@
 	retbuf->Write<word> (var->index);
 	
 	return retbuf;
+}
+
+void ScriptReader::AddBlockMark (ObjWriter* w, word dataheader) {
+	// Add a mark - to here temporarily - and add a reference to it.
+	// Upon a closing brace, the mark will be adjusted.
+	unsigned int marknum = w->AddMark (MARKTYPE_IF, "");
+	
+	// Write the header and store reference to the mark
+	w->Write<word> (dataheader);
+	w->AddReference (marknum);
+	
+	// Store it in the block stack
+	g_BlockStackCursor++;
+	blockstack[g_BlockStackCursor] = marknum;
 }
\ No newline at end of file
--- a/scriptreader.h	Mon Jul 30 11:14:02 2012 +0300
+++ b/scriptreader.h	Mon Jul 30 11:34:57 2012 +0300
@@ -99,6 +99,7 @@
 	DataBuffer* ParseAssignment (ScriptVar* var);
 	int ParseOperator (bool peek = false);
 	DataBuffer* ParseExprValue (int reqtype);
+	void AddBlockMark (ObjWriter* w, word dataheader);
 	
 	// preprocessor.cxx:
 	void PreprocessDirectives ();

mercurial