Skip to content

Share window effects BendWin through // @src - #969

Closed
ewoodbury wants to merge 3 commits into
bendlang:mainfrom
ewoodbury:refactor/window-host-src
Closed

ewoodbury wants to merge 3 commits into
bendlang:mainfrom
ewoodbury:refactor/window-host-src

Conversation

@ewoodbury

@ewoodbury ewoodbury commented Sep 21, 2026 •

Copy link
Copy Markdown

The four Window C effects each carried the X11 BendWin struct (with includes) so any one of them compiled alone. A program that imports more than one then pasted that block four times, under an #ifndef BendWin concatenate-guard.

eff_src already skipped a path it had seen. A // @src name.c line now loads a sibling through that same set, so the four effects share window_host.c and a program that imports more than one still emits the type once.

This is the same @src helper as #949 (audio ring). If that lands first, the comp.ts hunk here is identical and drops on rebase

Checks

  • tests/gfx/*.bend --check-only: all check.
  • tests/gfx/window.bend interpret and JS: same #| pin as main (no display / ENOTSUP).
  • Emitted C for window.bend (open+frame+close) and a scratch file that also calls set_title: one BendWin typedef, one <X11/Xlib.h>, no leftover // @src.
  • clang -O1 of those programs with -lX11 -lpthread -lm: exit 0.

Not run: the cluster gates, Metal, a machine with a display.

Runtime, checker, and JS are untouched. Window behavior is unchanged

Window.open, frame, set_title and close each carried the X11 BendWin
struct so any one of them compiled alone. The generated program then
pasted that block four times. eff_src already skipped a path it had
seen; a `// @src name.c` line now loads a sibling through that same
set, and the four effects share window_host.c.
@ewoodbury ewoodbury changed the title The window effects share BendWin through // @src Share window effects BendWin through // @src Sep 21, 2026
@zxv

zxv commented Sep 22, 2026

Copy link
Copy Markdown

Rescuing PR by commenting (github issue)

Comment thread bend2/comp.ts
return fs.readFileSync(path, "utf8");
const dir = path.slice(0, path.lastIndexOf("/"));
return fs.readFileSync(path, "utf8").replace(/^\/\/ @src ([a-z0-9_]+\.c)$/gm,
(_: string, name: string) => eff_src(dir + "/" + name, seen));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Include transitive @src files in published packages. pkg_files() in main.ts only collects direct Bend imports, so an effect containing // @src helper.c builds locally but leaves helper.c out of the package. I reproduced this by rebuilding from the files returned by pkg_files(); compilation fails with ENOENT for the helper. The package collector needs to follow these dependencies too.

Comment thread bend2/comp.ts
return fs.readFileSync(path, "utf8");
const dir = path.slice(0, path.lastIndexOf("/"));
return fs.readFileSync(path, "utf8").replace(/^\/\/ @src ([a-z0-9_]+\.c)$/gm,
(_: string, name: string) => eff_src(dir + "/" + name, seen));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Protect these helpers from output overwrite. The input set in cli_file() only tracks direct imports, so bend main.bend -o helper.c exits 0 and replaces a helper referenced through // @src helper.c with generated C. I reproduced the overwrite with a working custom effect. Add transitive helpers to the protected input set before emitting any output.

eff_src inlines a sibling .c while emitting, but the import list the
CLI walks does not name it. --publish then shipped a package that
could not rebuild, and -o helper.c exited 0 and replaced the helper
with generated C. src_deps follows that same line, transitively.
pkg_files packs those paths; cli_file refuses to overwrite them.
Base stays out of a package, as before.
Same two call sites, one queue, one comment.
@ewoodbury ewoodbury closed this Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants