nish 0.46.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/docs/AI.md +29 -18
  2. package/package.json +5 -5
  3. package/runtime/gfx/README.md +55 -0
  4. package/runtime/gfx/nish-gfx.c +1063 -0
  5. package/runtime/gfx/nish-gfx.h +221 -0
  6. package/runtime/gfx/nish-gfx.overrides.json +14 -0
  7. package/runtime/nish.d.ts +22 -5
  8. package/runtime/nish.h +1 -0
  9. package/runtime/nish.mjs +1 -0
  10. package/runtime/runtime-bytes.c +167 -7
  11. package/runtime/runtime-net.c +122 -52
  12. package/runtime/runtime-uring.c +150 -69
  13. package/runtime/sqlite/nish-sqlite.c +166 -39
  14. package/scripts/build.sh +88 -3
  15. package/std/README.md +2 -2
  16. package/std/base64.ts +28 -30
  17. package/std/compress/deflate.ts +1371 -704
  18. package/std/crypto/aes.ts +81 -45
  19. package/std/crypto/bcrypt-batch.ts +23 -4
  20. package/std/crypto/bcrypt.ts +36 -11
  21. package/std/crypto/chacha20poly1305.ts +93 -52
  22. package/std/crypto/x25519.ts +7 -4
  23. package/std/host/game.ts +52 -20
  24. package/std/host/ring.ts +115 -31
  25. package/std/host/text.ts +9 -3
  26. package/std/json.ts +83 -0
  27. package/std/math.ts +161 -131
  28. package/std/net/handler.ts +24 -6
  29. package/std/net/http-server.ts +358 -141
  30. package/std/net/http1-server.ts +44 -13
  31. package/std/net/prefork.ts +1 -2
  32. package/std/net/static.ts +7 -2
  33. package/std/random.ts +34 -51
  34. package/std/raster.ts +377 -113
  35. package/std/regex.ts +46 -15
  36. package/std/release.ts +19 -13
  37. package/std/sqlite.ts +380 -16
  38. package/std/synth.ts +20 -3
  39. package/std/temporal.ts +740 -363
  40. package/std/term-io.ts +81 -33
  41. package/std/term-pixels.ts +287 -112
  42. package/std/term-probe.ts +7 -3
  43. package/std/term-rate.ts +142 -66
  44. package/std/term.ts +782 -406
  45. package/std/testing.ts +14 -7
package/std/synth.ts CHANGED
@@ -47,7 +47,15 @@ const SYNTH_SAMPLE_LIMIT: f64 = 2147483647.0
47
47
  */
48
48
  export const synthSilence = (seconds: f64, sampleRate: i32): f64[] => {
49
49
  const want: f64 = seconds * toF64(sampleRate)
50
- const n: i32 = want >= 1.0 && want < SYNTH_SAMPLE_LIMIT ? toI32(want) : 1
50
+ let n: i32 = 1
51
+ if (want >= 1.0 && want < SYNTH_SAMPLE_LIMIT) {
52
+ const k: i32 = toI32(want)
53
+ // Never false: `want` is at least 1 here. The test is what proves the
54
+ // array length is not negative.
55
+ if (k >= 1) {
56
+ n = k
57
+ }
58
+ }
51
59
  const out: f64[] = new Array<f64>(n)
52
60
  out.fill(0.0)
53
61
  return out
@@ -101,11 +109,19 @@ export const synthTone = (
101
109
  }
102
110
  const from: i32 = toI32(start * rate)
103
111
  const n: i32 = toI32(length * rate)
112
+ // Never true: `start` is not negative here. The test is what proves `from + i`
113
+ // stays a sample index.
114
+ if (from < 0) {
115
+ return
116
+ }
117
+ const size: i32 = toI32(out.length)
104
118
  const ratio: f64 = Math.log(f1 / f0)
105
119
  let phase: f64 = 0.0
106
120
  let noise: i32 = SYNTH_NOISE_SEED
107
121
  let held: f64 = 0.0
108
- for (let i: i32 = 0; i < n && from + i < toI32(out.length); i++) {
122
+ // `at` is `from + i`, counted on its own so the test against `size` bounds it.
123
+ let at: i32 = from
124
+ for (let i: i32 = 0; i < n && at < size; i++) {
109
125
  const t: f64 = toF64(i) / rate
110
126
  const f: f64 = f0 * Math.exp((ratio * toF64(i)) / toF64(n))
111
127
  const before: f64 = phase
@@ -128,7 +144,8 @@ export const synthTone = (
128
144
  }
129
145
  const attack: f64 = Math.min(t / 0.002, 1.0)
130
146
  const release: f64 = Math.min((length - t) / 0.005, 1.0)
131
- out[from + i] = out[from + i] + v * volume * attack * release * Math.exp(-t * decay)
147
+ out[at] = out[at] + v * volume * attack * release * Math.exp(-t * decay)
148
+ at = at + 1
132
149
  }
133
150
  }
134
151