1
0
forked from alex-eg/sex

count a unit among its own imports

Two modules importing each other with pub hand the unit its own
interface back, and its types were defined twice.
This commit is contained in:
2026-10-19 14:18:56 +03:00
parent 4bdc0e57a7
commit b285174a22
6 changed files with 45 additions and 2 deletions

View File

@@ -33,6 +33,9 @@
;;; book its siblings page, with `pub', and spine, without. A pub macro
;;; of page's expands into a private one, which crosses with it.
;;;
;;; Two modules may import each other with `pub': cycle/a and cycle/b,
;;; whose interfaces each import the other back.
;;;
;;; make check-modules
(import scheme
@@ -99,6 +102,16 @@
'("pages 2 3" "number 2")
(output-of (built "shelf-app")))
(test-assert "modules importing each other with pub compile"
(and (output-of sexc "cycle/a.sex" "-c" "-o" (built "cycle-a.o"))
(output-of sexc "cycle/b.sex" "-c" "-o" (built "cycle-b.o"))
(output-of sexc "cycle-app.sex" "-o" (built "cycle-app")
"--" (built "cycle-a.o") (built "cycle-b.o"))))
(test "and the app runs through them"
'("cycle 1 2")
(output-of (built "cycle-app")))
(test "the app runs through both"
'("hello, world"
"hello, sex"

View File

@@ -0,0 +1,7 @@
(include stdio.h)
(import cycle/a)
(pub fn main () int
(var b rb (make-rb 1 2))
(printf "cycle %d %d\n" (. b a x) (. b y))
(return 0))

View File

@@ -0,0 +1,8 @@
;;; Each imports the other with pub, so either one compiled pastes the
;;; other's interface, which imports it back. b holds an ra by value, so
;;; ra is defined before b is imported, as C needs it in one unit
(pub record ra ((x int)))
(pub import b)
(pub fn make-ra ((x int)) ra (return #(ra : x)))

View File

@@ -0,0 +1,5 @@
(pub import a)
(pub record rb ((a ra) (y int)))
(pub fn make-rb ((x int) (y int)) rb (return #(rb : (make-ra x) y)))