changeset 70:5f44ac1bcbd6

Add support for a special notFirst? variable so that globals can be initialized on startup only. This allows for state that persists between turns
author Michael Pavone <pavone@retrodev.com>
date Sun, 27 Jul 2014 23:43:37 -0700
parents 8a0f1447c034
children 920f02a880fc
files code/gqc.tp
diffstat 1 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/code/gqc.tp	Sun Jul 27 23:19:23 2014 -0700
+++ b/code/gqc.tp	Sun Jul 27 23:43:37 2014 -0700
@@ -88,7 +88,8 @@
 	error <- :msg {
 		(file stderr) write: "Error - " . msg . "\n"
 	}
-	_nextVar <- 0
+	//0 is used for the special notFirst? variable
+	_nextVar <- 1
 	//a and b are reserved for int/return values
 	//h is reserved as a stack pointer
 	_allTemp <- [
@@ -741,6 +742,20 @@
 				outer <- res yield
 				functions <- dict hash
 				syms <- symbols table
+				
+				//define symbols for the special notFirst? variable
+				syms define: "notFirst?" (mem: 0)
+				//use it to skip global init on subsequent runthroughs
+				prog add: (inst: "JEQ" #[
+					"main"
+					(mem: 0)
+					1
+				])
+				prog add: (inst: "MOV" #[
+					(mem: 0)
+					1
+				])
+				
 				//define symbols for all registers
 				//for low level shenanigans
 				i <- 0