From eae3b70619fd24e43dbf186fb519aeba11a5768f Mon Sep 17 00:00:00 2001 From: Intubun <41478036+Intubun@users.noreply.github.com> Date: Thu, 21 May 2026 12:39:38 +0200 Subject: [PATCH] refactor(tcl-examples): rename TCL scripts, drop dead pcell.tcl, fix comments and naming Rename *-magic.tcl scripts to *-tcl.tcl to match the -tcl.js test naming convention. Delete the old bare-command pcell.tcl (used cellname create, no magic:: prefix) and promote pcell-magic.tcl to pcell.tcl. Fix misleading comment in magicWasm.c: Tclmagic_Init only bootstraps the interpreter; magic:: commands are registered separately by TclmagicRegisterCommands after magicMainInit. Align comment block dashes in TclmagicRegisterCommands to match tclmagic.c style (62 dashes). Replace intubun/tcl references in build scripts and CI with tcltk/tcl to match the actual pinned repo in npm/tcl.ref. Also run both test suites when build.sh is invoked with --test. --- .github/workflows/main-wasm.yml | 2 +- magic/magicWasm.c | 9 +++++--- npm/build.sh | 7 +++--- npm/examples/cif-tcl.js | 2 +- npm/examples/{cif-magic.tcl => cif-tcl.tcl} | 0 npm/examples/drc-tcl.js | 2 +- npm/examples/{drc-magic.tcl => drc-tcl.tcl} | 0 npm/examples/extract-tcl.js | 2 +- .../{extract-magic.tcl => extract-tcl.tcl} | 0 npm/examples/gds-tcl.js | 2 +- npm/examples/{gds-magic.tcl => gds-tcl.tcl} | 0 npm/examples/pcell-magic.tcl | 12 ---------- npm/examples/pcell.js | 2 +- npm/examples/pcell.tcl | 22 +++++-------------- tcltk/tclmagic.c | 13 ++++++----- toolchains/emscripten/build-tcl-wasm.sh | 4 ++-- 16 files changed, 31 insertions(+), 48 deletions(-) rename npm/examples/{cif-magic.tcl => cif-tcl.tcl} (100%) rename npm/examples/{drc-magic.tcl => drc-tcl.tcl} (100%) rename npm/examples/{extract-magic.tcl => extract-tcl.tcl} (100%) rename npm/examples/{gds-magic.tcl => gds-tcl.tcl} (100%) delete mode 100644 npm/examples/pcell-magic.tcl diff --git a/.github/workflows/main-wasm.yml b/.github/workflows/main-wasm.yml index c5282a82..b2d6aa87 100644 --- a/.github/workflows/main-wasm.yml +++ b/.github/workflows/main-wasm.yml @@ -73,7 +73,7 @@ jobs: echo "===== emcc -dM -E - ====="; echo | emcc -dM -E - | sort echo "===== em++ -dM -E - ====="; echo | em++ -dM -E - | sort - # Clone intubun/tcl into a sibling directory at the pinned ref from + # Clone tcltk/tcl into a sibling directory at the pinned ref from # npm/tcl.ref. npm/build.sh would do this on its own, but doing it as # an explicit step makes the resolved SHA visible at the top of the # job log and keeps the build step's output focused on the C build. diff --git a/magic/magicWasm.c b/magic/magicWasm.c index f629a79c..eca5de7f 100644 --- a/magic/magicWasm.c +++ b/magic/magicWasm.c @@ -43,9 +43,12 @@ magicWasmEnsureCadRoot(void) } #ifdef MAGIC_WRAPPER -/* Forward decl — Tclmagic_Init installs all magic Tcl commands and calls - * Tcl_InitStubs(), which sets tclStubsPtr. Without this, any Tcl_X macro - * dereferences a NULL stubs pointer at runtime (crashes the wasm). */ +/* Forward decl — Tclmagic_Init bootstraps the Tcl interpreter (registers + * the magic::initialize command and calls Tcl_InitStubs(), which sets + * tclStubsPtr). Without this, any Tcl_X macro dereferences a NULL stubs + * pointer at runtime (crashes the wasm). The actual magic:: commands + * (magic::load, magic::gds, etc.) are registered separately by + * TclmagicRegisterCommands() after magicMainInit() populates the clients. */ extern int Tclmagic_Init(Tcl_Interp *interp); #endif diff --git a/npm/build.sh b/npm/build.sh index 946a667e..37df8893 100755 --- a/npm/build.sh +++ b/npm/build.sh @@ -21,7 +21,7 @@ # EMSDK_DIR Path to an activated emsdk checkout. # If set, emsdk_env.sh is sourced from there. # If unset, emcc must already be on PATH (e.g. sourced externally). -# TCL_REPO Override the path to the intubun/tcl checkout (default: +# TCL_REPO Override the path to the tcltk/tcl checkout (default: # ../tcl relative to this magic checkout). Used by the TCL # variant only. @@ -29,7 +29,7 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(dirname "$SCRIPT_DIR")" -# The TCL variant builds against a sibling clone of intubun/tcl (pristine — +# The TCL variant builds against a sibling clone of tcltk/tcl (pristine — # magic never modifies it). The build itself happens inside magic under # build-tcl-wasm/, so the TCL source tree stays clean. TCL_REPO="${TCL_REPO:-$(dirname "$REPO_ROOT")/tcl}" @@ -114,7 +114,7 @@ ensure_tcl_built() { # shellcheck source=/dev/null . "$TCL_REF_FILE" fi - : "${TCL_REPO_URL:=https://github.com/intubun/tcl.git}" + : "${TCL_REPO_URL:=https://github.com/tcltk/tcl.git}" : "${TCL_REF:=main}" if [ ! -d "$TCL_REPO/.git" ]; then @@ -210,6 +210,7 @@ esac if [ $OPT_TEST -eq 1 ]; then cd "$SCRIPT_DIR" npm run test + npm run test:tcl fi # --- optional pack ----------------------------------------------------------- diff --git a/npm/examples/cif-tcl.js b/npm/examples/cif-tcl.js index b7e0c031..3a6dbc62 100644 --- a/npm/examples/cif-tcl.js +++ b/npm/examples/cif-tcl.js @@ -10,7 +10,7 @@ export async function run({ magFile = DEFAULT_MAG, tech = DEFAULT_TECH, outputDi const { FS } = magic; const { tech: techName, cell } = loadCell(FS, tech, magFile); - magic.runScript(loadScript('cif-magic.tcl', techName, cell)); + magic.runScript(loadScript('cif-tcl.tcl', techName, cell)); mkdirSync(outputDir, { recursive: true }); const data = vfsRead(FS, `/work/${cell}.cif`); diff --git a/npm/examples/cif-magic.tcl b/npm/examples/cif-tcl.tcl similarity index 100% rename from npm/examples/cif-magic.tcl rename to npm/examples/cif-tcl.tcl diff --git a/npm/examples/drc-tcl.js b/npm/examples/drc-tcl.js index eb7889a9..2651af32 100644 --- a/npm/examples/drc-tcl.js +++ b/npm/examples/drc-tcl.js @@ -12,7 +12,7 @@ export async function run({ magFile = DEFAULT_MAG, tech = DEFAULT_TECH } = {}) { const { FS } = magic; const { tech: techName, cell } = loadCell(FS, tech, magFile); - magic.runScript(loadScript('drc-magic.tcl', techName, cell)); + magic.runScript(loadScript('drc-tcl.tcl', techName, cell)); const summary = output.find(l => /Total DRC errors/i.test(l)); const match = summary?.match(/(\d+)/); diff --git a/npm/examples/drc-magic.tcl b/npm/examples/drc-tcl.tcl similarity index 100% rename from npm/examples/drc-magic.tcl rename to npm/examples/drc-tcl.tcl diff --git a/npm/examples/extract-tcl.js b/npm/examples/extract-tcl.js index 45b5b0c3..193fb2ce 100644 --- a/npm/examples/extract-tcl.js +++ b/npm/examples/extract-tcl.js @@ -10,7 +10,7 @@ export async function run({ magFile = DEFAULT_MAG, tech = DEFAULT_TECH, outputDi const { FS } = magic; const { tech: techName, cell } = loadCell(FS, tech, magFile); - magic.runScript(loadScript('extract-magic.tcl', techName, cell)); + magic.runScript(loadScript('extract-tcl.tcl', techName, cell)); mkdirSync(outputDir, { recursive: true }); diff --git a/npm/examples/extract-magic.tcl b/npm/examples/extract-tcl.tcl similarity index 100% rename from npm/examples/extract-magic.tcl rename to npm/examples/extract-tcl.tcl diff --git a/npm/examples/gds-tcl.js b/npm/examples/gds-tcl.js index a1379442..98bec535 100644 --- a/npm/examples/gds-tcl.js +++ b/npm/examples/gds-tcl.js @@ -10,7 +10,7 @@ export async function run({ magFile = DEFAULT_MAG, tech = DEFAULT_TECH, outputDi const { FS } = magic; const { tech: techName, cell } = loadCell(FS, tech, magFile); - magic.runScript(loadScript('gds-magic.tcl', techName, cell)); + magic.runScript(loadScript('gds-tcl.tcl', techName, cell)); mkdirSync(outputDir, { recursive: true }); const data = vfsRead(FS, `/work/${cell}.gds`); diff --git a/npm/examples/gds-magic.tcl b/npm/examples/gds-tcl.tcl similarity index 100% rename from npm/examples/gds-magic.tcl rename to npm/examples/gds-tcl.tcl diff --git a/npm/examples/pcell-magic.tcl b/npm/examples/pcell-magic.tcl deleted file mode 100644 index a58b8c96..00000000 --- a/npm/examples/pcell-magic.tcl +++ /dev/null @@ -1,12 +0,0 @@ -magic::tech load __TECH__ - -proc make_rect {name width height} { - magic::load $name - magic::box 0 0 $width $height - magic::paint m1 - magic::save /work/$name - magic::gds write /work/$name -} - -make_rect pcell_4x8 4 8 -make_rect pcell_8x4 8 4 diff --git a/npm/examples/pcell.js b/npm/examples/pcell.js index 95c94ac5..b31066fd 100644 --- a/npm/examples/pcell.js +++ b/npm/examples/pcell.js @@ -14,7 +14,7 @@ export async function run({ tech = DEFAULT_TECH, outputDir = DEFAULT_OUT } = {}) const { FS } = magic; FS.mkdirTree('/work'); - magic.runTcl(loadScript('pcell-magic.tcl', tech, '')); + magic.runTcl(loadScript('pcell.tcl', tech, '')); mkdirSync(outputDir, { recursive: true }); diff --git a/npm/examples/pcell.tcl b/npm/examples/pcell.tcl index 91e5ad4b..a58b8c96 100644 --- a/npm/examples/pcell.tcl +++ b/npm/examples/pcell.tcl @@ -1,22 +1,12 @@ -# pcell.tcl — PCell generation test. -# -# Defines a parameterized cell proc and instantiates it with two -# different sizes to verify that Tcl proc definitions, Magic drawing -# commands, and GDS output all work end-to-end in the TCL variant. -# -# __TECH__ is substituted by pcell.js before execution. +magic::tech load __TECH__ -tech load __TECH__ - -# PCell definition: a labelled metal1 rectangle of variable size. proc make_rect {name width height} { - cellname create $name - box 0 0 $width $height - paint m1 - save /work/$name - gds write /work/$name + magic::load $name + magic::box 0 0 $width $height + magic::paint m1 + magic::save /work/$name + magic::gds write /work/$name } -# Instantiate with two different sizes. make_rect pcell_4x8 4 8 make_rect pcell_8x4 8 4 diff --git a/tcltk/tclmagic.c b/tcltk/tclmagic.c index 989e89f6..7132d7ea 100644 --- a/tcltk/tclmagic.c +++ b/tcltk/tclmagic.c @@ -657,12 +657,13 @@ process_rlimit_startup_check(void) } /*------------------------------------------------------*/ -/* Register magic:: commands with the Tcl interpreter. */ -/* Called after Magic's C subsystems are fully */ -/* initialized (i.e. after magicMainInit returns 0) */ -/* so that WindNextClient / WindGetCommandTable return */ -/* populated tables. */ -/*------------------------------------------------------*/ +/*--------------------------------------------------------------*/ +/* Register magic:: commands with the Tcl interpreter. */ +/* Called after Magic's C subsystems are fully */ +/* initialized (i.e. after magicMainInit returns 0) */ +/* so that WindNextClient / WindGetCommandTable return */ +/* populated tables. */ +/*--------------------------------------------------------------*/ void TclmagicRegisterCommands(Tcl_Interp *interp) diff --git a/toolchains/emscripten/build-tcl-wasm.sh b/toolchains/emscripten/build-tcl-wasm.sh index 88c53944..22acd885 100644 --- a/toolchains/emscripten/build-tcl-wasm.sh +++ b/toolchains/emscripten/build-tcl-wasm.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Build intubun/tcl as a static WASM library for linking into magic.wasm. +# Build tcltk/tcl as a static WASM library for linking into magic.wasm. # # This script does NOT modify the TCL source tree — the build is fully # out-of-source. configure is invoked from the build directory inside magic, @@ -53,7 +53,7 @@ fi # not a cryptic `set: pipefail: invalid option name` from bash. if head -1 "$TCL_SRC/unix/configure" | grep -q $'\r'; then echo "Error: $TCL_SRC/unix/configure has CRLF line endings." >&2 - echo " Reclone intubun/tcl with: git -c core.autocrlf=false clone …" >&2 + echo " Reclone tcltk/tcl with: git -c core.autocrlf=false clone …" >&2 exit 1 fi