new expression
Demonstrates new with Uint8Array and AudioContext: the same source compiles on every Tish target; only the JavaScript target emits browser-native new.
Features used
None (secure mode).
What it does
new Uint8Array(4)— on non-JS targets, a host stub (numeric array of zeros, not a real typed array).new Uint8Array(...[4])— same stub path with a spread argument list.new AudioContext()— on non-JS targets, a stub context (e.g.sampleRate, no real audio).
For browser-accurate behavior, compile with --target js so the output uses real new Uint8Array / new AudioContext.
Node.js / Bun: validate emitted new
src/node-bun-new-patterns.tish is JS-target only: it exercises constructors that exist as globals in modern Node (18+ for fetch/Headers) and Bun, so you can confirm the transpiler’s new output actually runs.
After tish build … --target js, run node dist/node-bun-new.js or bun dist/node-bun-new.js; each line should end with true.
mkdir -p dist
tish build src/node-bun-new-patterns.tish --target js -o dist/node-bun-new.js
node dist/node-bun-new.jsUse a tish binary built from this repository (e.g. cargo build --release -p tishlang from tish/, then invoke ../../target/release/tish). If which tish points to an older install, JS output can be wrong (for example let epoch = new; instead of new Date(0)).
With npm scripts (from this directory, tish on PATH): npm run verify:js:node or npm run verify:js:bun. After upgrading tish, remove stale output: rm -rf dist.
Other Node/Bun patterns you may add locally (not in the sample file): new Promise(...), new (require("node:events").EventEmitter)(), TextDecoder, DataView, WeakMap, URLSearchParams, Blob — all depend on how much of that surface you want to support in Tish call/member lowering.
Local development
From this directory (Tish repo root is ../..):
# Interpreter
cargo run -p tishlang --manifest-path ../../Cargo.toml --release -- run src/main.tish
# Native binary
cargo run -p tishlang --manifest-path ../../Cargo.toml --release -- build src/main.tish -o new-demo
./new-demo
# JavaScript (real `new` in output)
cargo run -p tishlang --manifest-path ../../Cargo.toml --release -- build src/main.tish --target js -o new-demo.jsWith the tish CLI installed: tish run src/main.tish, tish build src/main.tish -o new-demo, and tish build src/main.tish --target js -o new-demo.js.
Deploy
Same as other examples; see the examples README. This sample is primarily for learning new semantics across targets.