commit b2c896610d2cc0cf6422e6a0a5e68ebbc4cccdab
parent 86788cffd33e8577180c9662bc470f944352b95c
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Sun, 26 Apr 2026 22:30:10 -0700
cc/cg+parse: address initializer for global pointer (§E.2)
Adds the cc-cg fixture that drives a global int* with a label-ref piece
straight through cg-emit-global, plus the parse fixture that exercises
the same `int *p = &x;` shape via real C source.
The cg surface is unchanged (label-ref pieces were already wired in
§E.1's cg-emit-global rewrite); the parser surface picks up the &IDENT
form via %const-init-piece.
Diffstat:
4 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/tests/cc-cg/50-init-addr.expected-exit b/tests/cc-cg/50-init-addr.expected-exit
@@ -0,0 +1 @@
+7
diff --git a/tests/cc-cg/50-init-addr.scm b/tests/cc-cg/50-init-addr.scm
@@ -0,0 +1,27 @@
+;; tests/cc-cg/50-init-addr.scm — global pointer initialized to address
+;; of another global. §E.2.
+;;
+;; Models:
+;; int x = 7;
+;; int *p = &x;
+;; int main(void) { return *p; }
+;; Runtime: exits 7.
+
+(let* ((cg (cg-init))
+ ;; int x = 7
+ (x (%sym "x" 'var 'static %t-i32 #f))
+ (bvx (make-bytevector 4 0))
+ (_x (bytevector-u8-set! bvx 0 7))
+ ;; int *p = &x -> structured init: a single label-ref to cc__x
+ (p (%sym "p" 'var 'static (%ctype 'ptr 8 8 %t-i32) #f)))
+ (cg-emit-global cg x (list bvx))
+ (cg-emit-global cg p (list (cons 'label-ref "cc__x")))
+ (cg-fn-begin cg "main" '() %t-i32)
+ ;; return *p
+ (cg-push-sym cg p)
+ (cg-load cg) ; rval ptr-to-int (the value of p)
+ (cg-push-deref cg) ; lval int through pointer
+ (cg-load cg) ; rval int
+ (cg-return cg)
+ (cg-fn-end cg)
+ (write-bv-fd 1 (cg-finish cg)))
diff --git a/tests/cc-parse/50-init-addr.c b/tests/cc-parse/50-init-addr.c
@@ -0,0 +1,4 @@
+// tests/cc-parse/50-init-addr.c — global pointer initialized to &global. §E.2.
+int x = 7;
+int *p = &x;
+int main(void) { return *p; }
diff --git a/tests/cc-parse/50-init-addr.expected-exit b/tests/cc-parse/50-init-addr.expected-exit
@@ -0,0 +1 @@
+7