# HG changeset patch # User Michael Pavone # Date 1406529817 25200 # Node ID 5f44ac1bcbd6b90f82f1b3d32043497d2b62f519 # Parent 8a0f1447c034330bb0d9fc04c6e5c33980138208 Add support for a special notFirst? variable so that globals can be initialized on startup only. This allows for state that persists between turns diff -r 8a0f1447c034 -r 5f44ac1bcbd6 code/gqc.tp --- 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