@amritk/nish-x86_64-linux 0.38.0 → 0.40.1

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 (86) hide show
  1. package/INSTALL.md +74 -129
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +455 -65
  4. package/package.json +1 -1
  5. package/runtime/core/host.d.ts +11 -0
  6. package/runtime/core/host.mjs +35 -0
  7. package/runtime/nish.d.ts +320 -33
  8. package/runtime/nish.h +84 -10
  9. package/runtime/nish.mjs +69 -6
  10. package/runtime/node.mjs +117 -0
  11. package/runtime/page-frame.d.ts +123 -0
  12. package/runtime/page-frame.mjs +736 -0
  13. package/runtime/page-game.d.ts +132 -0
  14. package/runtime/page-game.mjs +738 -0
  15. package/runtime/runtime-aes.c +97 -12
  16. package/runtime/runtime-async.c +43 -10
  17. package/runtime/runtime-bytes.c +88 -4
  18. package/runtime/runtime-checksum.c +207 -15
  19. package/runtime/runtime-net.c +64 -3
  20. package/runtime/runtime-os.c +174 -27
  21. package/runtime/runtime-region.c +94 -10
  22. package/runtime/runtime-sandbox.c +404 -17
  23. package/runtime/runtime-sha256.c +11 -4
  24. package/runtime/runtime-wasm.c +437 -0
  25. package/runtime/runtime.c +5 -0
  26. package/runtime/vite.mjs +1 -1
  27. package/scripts/build.sh +42 -8
  28. package/std/README.md +78 -91
  29. package/std/array.ts +36 -3
  30. package/std/collections.ts +51 -0
  31. package/std/compress/checksum.ts +13 -0
  32. package/std/compress/deflate.ts +0 -2
  33. package/std/crypto/hmac.ts +37 -10
  34. package/std/crypto/p256.ts +1629 -2732
  35. package/std/crypto/p384.ts +3 -1
  36. package/std/crypto/pki.ts +151 -13
  37. package/std/crypto/sha256.ts +34 -6
  38. package/std/crypto/x25519.ts +153 -64
  39. package/std/crypto/x509.ts +120 -10
  40. package/std/host/game.ts +273 -0
  41. package/std/input.ts +56 -0
  42. package/std/json-tokenizer.ts +344 -111
  43. package/std/json-typed.ts +256 -12
  44. package/std/json-value.ts +144 -3
  45. package/std/json.ts +63 -8
  46. package/std/net/fetch.ts +22 -4
  47. package/std/net/handler.ts +130 -16
  48. package/std/net/http-server.ts +3382 -0
  49. package/std/net/http1-client-codec.ts +6 -2
  50. package/std/net/http1-codec.ts +636 -162
  51. package/std/net/http1-server.ts +569 -42
  52. package/std/net/http2-cleartext.ts +526 -0
  53. package/std/net/http2-tls.ts +48 -0
  54. package/std/net/http2.ts +131 -14
  55. package/std/net/http3-server.ts +29 -3
  56. package/std/net/http3.ts +180 -7
  57. package/std/net/postgres-async.ts +1304 -86
  58. package/std/net/postgres-carrier.ts +343 -10
  59. package/std/net/postgres.ts +122 -7
  60. package/std/net/prefork.ts +195 -11
  61. package/std/net/quic-datagram.ts +30 -0
  62. package/std/net/quic-listener.ts +38 -12
  63. package/std/net/quic-packet.ts +19 -6
  64. package/std/net/quic-recovery.ts +373 -27
  65. package/std/net/quic-stream.ts +195 -37
  66. package/std/net/quic.ts +516 -22
  67. package/std/net/router.ts +407 -38
  68. package/std/net/serve.ts +1022 -110
  69. package/std/net/tls/codec.ts +110 -32
  70. package/std/net/tls/record-server.ts +37 -7
  71. package/std/net/tls/verify.ts +19 -1
  72. package/std/net/tls-tcp.ts +56 -1
  73. package/std/net/tls.ts +196 -50
  74. package/std/net/url.ts +83 -35
  75. package/std/net/websocket.ts +129 -19
  76. package/std/net/webtransport.ts +185 -1
  77. package/std/raster.ts +837 -0
  78. package/std/regex.ts +69 -47
  79. package/std/region.ts +62 -11
  80. package/std/release.ts +593 -0
  81. package/std/secret.ts +26 -59
  82. package/std/synth.ts +143 -0
  83. package/std/text.ts +233 -0
  84. package/std/threads.ts +298 -0
  85. package/std/yaml-json.ts +368 -28
  86. package/std/yaml.ts +122 -27
package/std/threads.ts CHANGED
@@ -782,6 +782,304 @@ export class AtomicI64 {
782
782
  }
783
783
  }
784
784
 
785
+ /**
786
+ * `length` `i32` counters in one contiguous buffer, each of which a scope's
787
+ * tasks and a parallel body may update together (docs/LANGUAGE.md,
788
+ * "Atomic arrays"). It is `AtomicI32` with the element's index first: each
789
+ * method checks `i` as an array index is checked, so an index out of range
790
+ * stops the program, and is then one indivisible operation on that element.
791
+ * Natively the compiler emits each body itself, as a sequentially consistent
792
+ * `load atomic`, `store atomic`, `atomicrmw` or `cmpxchg` on the element
793
+ * (docs/IR_COOKBOOK.md, "Atomics"), and what is written below is the meaning,
794
+ * which is what runs under Node. `add` and `sub` wrap
795
+ * at 32 bits, as the native instruction does.
796
+ *
797
+ * Choose it over an `AtomicI32[]` when the counters are many or hot: an
798
+ * `AtomicI32[]` is one object per counter, each its own allocation, so
799
+ * neighbouring counters land on several cache lines; here they are adjacent
800
+ * `i32`s, as Rust's `[AtomicI32; N]` is. It reaches a task and a parallel body
801
+ * by the routes `AtomicI32` does, and is refused where it is.
802
+ */
803
+ export class AtomicI32Array {
804
+ /** How many elements the array holds, fixed when it is made. */
805
+ readonly length: i32
806
+ /** The elements; named only by this class's methods, which the compiler emits. */
807
+ private values: i32[]
808
+
809
+ /**
810
+ * An array of `length` elements, each `0`.
811
+ *
812
+ * @param length how many elements; a negative one stops the program, as
813
+ * `new Array` of one does.
814
+ */
815
+ constructor(length: i32) {
816
+ this.length = length
817
+ this.values = new Array<i32>(length)
818
+ this.values.fill(0)
819
+ }
820
+
821
+ /**
822
+ * Element `i`.
823
+ *
824
+ * @param i the element's index, from `0` to `length - 1`.
825
+ * @returns the element at the moment of the read.
826
+ */
827
+ load(i: i32): i32 {
828
+ return this.values[i]
829
+ }
830
+
831
+ /**
832
+ * Sets element `i` to `value`.
833
+ *
834
+ * @param i the element's index, from `0` to `length - 1`.
835
+ * @param value the new value.
836
+ */
837
+ store(i: i32, value: i32): void {
838
+ this.values[i] = value
839
+ }
840
+
841
+ /**
842
+ * Adds `delta` to element `i`, wrapping at 32 bits, and answers the
843
+ * element before.
844
+ *
845
+ * @param i the element's index, from `0` to `length - 1`.
846
+ * @param delta how much to add; a negative one subtracts.
847
+ * @returns the element just before the addition.
848
+ */
849
+ add(i: i32, delta: i32): i32 {
850
+ const old = this.values[i]
851
+ this.values[i] = wrappingAdd(old, delta)
852
+ return old
853
+ }
854
+
855
+ /**
856
+ * Subtracts `delta` from element `i`, wrapping at 32 bits, and answers
857
+ * the element before.
858
+ *
859
+ * @param i the element's index, from `0` to `length - 1`.
860
+ * @param delta how much to subtract; a negative one adds.
861
+ * @returns the element just before the subtraction.
862
+ */
863
+ sub(i: i32, delta: i32): i32 {
864
+ const old = this.values[i]
865
+ this.values[i] = wrappingSub(old, delta)
866
+ return old
867
+ }
868
+
869
+ /**
870
+ * Keeps the smaller of element `i` and `value`, and answers the element
871
+ * before.
872
+ *
873
+ * @param i the element's index, from `0` to `length - 1`.
874
+ * @param value the candidate, stored only when it is below the element.
875
+ * @returns the element just before the update.
876
+ */
877
+ min(i: i32, value: i32): i32 {
878
+ const old = this.values[i]
879
+ if (value < old) {
880
+ this.values[i] = value
881
+ }
882
+ return old
883
+ }
884
+
885
+ /**
886
+ * Keeps the larger of element `i` and `value`, and answers the element
887
+ * before.
888
+ *
889
+ * @param i the element's index, from `0` to `length - 1`.
890
+ * @param value the candidate, stored only when it is above the element.
891
+ * @returns the element just before the update.
892
+ */
893
+ max(i: i32, value: i32): i32 {
894
+ const old = this.values[i]
895
+ if (value > old) {
896
+ this.values[i] = value
897
+ }
898
+ return old
899
+ }
900
+
901
+ /**
902
+ * Sets element `i` to `value` and answers the element before.
903
+ *
904
+ * @param i the element's index, from `0` to `length - 1`.
905
+ * @param value the new value.
906
+ * @returns the value it replaced.
907
+ */
908
+ exchange(i: i32, value: i32): i32 {
909
+ const old = this.values[i]
910
+ this.values[i] = value
911
+ return old
912
+ }
913
+
914
+ /**
915
+ * Sets element `i` to `desired` if it is `expected`, and answers the value
916
+ * it saw.
917
+ *
918
+ * @param i the element's index, from `0` to `length - 1`.
919
+ * @param expected the value the update requires.
920
+ * @param desired the value stored when the element is `expected`.
921
+ * @returns the element seen before the update: `expected` exactly when the
922
+ * update happened.
923
+ */
924
+ compareExchange(i: i32, expected: i32, desired: i32): i32 {
925
+ const old = this.values[i]
926
+ if (old === expected) {
927
+ this.values[i] = desired
928
+ }
929
+ return old
930
+ }
931
+ }
932
+
933
+ /**
934
+ * `length` `i64` counters in one contiguous buffer, each of which a scope's
935
+ * tasks and a parallel body may update together (docs/LANGUAGE.md,
936
+ * "Atomic arrays"). It is `AtomicI64` with the element's index first: each
937
+ * method checks `i` as an array index is checked, so an index out of range
938
+ * stops the program, and is then one indivisible operation on that element.
939
+ * Natively the compiler emits each body itself, as a sequentially consistent
940
+ * `load atomic`, `store atomic`, `atomicrmw` or `cmpxchg` on the element
941
+ * (docs/IR_COOKBOOK.md, "Atomics"), and what is written below is the meaning,
942
+ * which is what runs under Node. Node holds each
943
+ * element as a `number`, so `add` and `sub` are `+` and `-` there, and agree
944
+ * with native while values stay within ±2^53; wrapping at 2^63 is native-only,
945
+ * as it is for `AtomicI64`.
946
+ *
947
+ * Choose it over an `AtomicI64[]` when the counters are many or hot: an
948
+ * `AtomicI64[]` is one object per counter, each its own allocation, so
949
+ * neighbouring counters land on several cache lines; here they are adjacent
950
+ * `i64`s, as Rust's `[AtomicI64; N]` is. It reaches a task and a parallel body
951
+ * by the routes `AtomicI64` does, and is refused where it is.
952
+ */
953
+ export class AtomicI64Array {
954
+ /** How many elements the array holds, fixed when it is made. */
955
+ readonly length: i32
956
+ /** The elements; named only by this class's methods, which the compiler emits. */
957
+ private values: i64[]
958
+
959
+ /**
960
+ * An array of `length` elements, each `0`.
961
+ *
962
+ * @param length how many elements; a negative one stops the program, as
963
+ * `new Array` of one does.
964
+ */
965
+ constructor(length: i32) {
966
+ this.length = length
967
+ this.values = new Array<i64>(length)
968
+ this.values.fill(0)
969
+ }
970
+
971
+ /**
972
+ * Element `i`.
973
+ *
974
+ * @param i the element's index, from `0` to `length - 1`.
975
+ * @returns the element at the moment of the read.
976
+ */
977
+ load(i: i32): i64 {
978
+ return this.values[i]
979
+ }
980
+
981
+ /**
982
+ * Sets element `i` to `value`.
983
+ *
984
+ * @param i the element's index, from `0` to `length - 1`.
985
+ * @param value the new value.
986
+ */
987
+ store(i: i32, value: i64): void {
988
+ this.values[i] = value
989
+ }
990
+
991
+ /**
992
+ * Adds `delta` to element `i` and answers the element before; natively
993
+ * the sum wraps at 64 bits.
994
+ *
995
+ * @param i the element's index, from `0` to `length - 1`.
996
+ * @param delta how much to add; a negative one subtracts.
997
+ * @returns the element just before the addition.
998
+ */
999
+ add(i: i32, delta: i64): i64 {
1000
+ const old = this.values[i]
1001
+ this.values[i] = old + delta
1002
+ return old
1003
+ }
1004
+
1005
+ /**
1006
+ * Subtracts `delta` from element `i` and answers the element before;
1007
+ * natively the difference wraps at 64 bits.
1008
+ *
1009
+ * @param i the element's index, from `0` to `length - 1`.
1010
+ * @param delta how much to subtract; a negative one adds.
1011
+ * @returns the element just before the subtraction.
1012
+ */
1013
+ sub(i: i32, delta: i64): i64 {
1014
+ const old = this.values[i]
1015
+ this.values[i] = old - delta
1016
+ return old
1017
+ }
1018
+
1019
+ /**
1020
+ * Keeps the smaller of element `i` and `value`, and answers the element
1021
+ * before.
1022
+ *
1023
+ * @param i the element's index, from `0` to `length - 1`.
1024
+ * @param value the candidate, stored only when it is below the element.
1025
+ * @returns the element just before the update.
1026
+ */
1027
+ min(i: i32, value: i64): i64 {
1028
+ const old = this.values[i]
1029
+ if (value < old) {
1030
+ this.values[i] = value
1031
+ }
1032
+ return old
1033
+ }
1034
+
1035
+ /**
1036
+ * Keeps the larger of element `i` and `value`, and answers the element
1037
+ * before.
1038
+ *
1039
+ * @param i the element's index, from `0` to `length - 1`.
1040
+ * @param value the candidate, stored only when it is above the element.
1041
+ * @returns the element just before the update.
1042
+ */
1043
+ max(i: i32, value: i64): i64 {
1044
+ const old = this.values[i]
1045
+ if (value > old) {
1046
+ this.values[i] = value
1047
+ }
1048
+ return old
1049
+ }
1050
+
1051
+ /**
1052
+ * Sets element `i` to `value` and answers the element before.
1053
+ *
1054
+ * @param i the element's index, from `0` to `length - 1`.
1055
+ * @param value the new value.
1056
+ * @returns the value it replaced.
1057
+ */
1058
+ exchange(i: i32, value: i64): i64 {
1059
+ const old = this.values[i]
1060
+ this.values[i] = value
1061
+ return old
1062
+ }
1063
+
1064
+ /**
1065
+ * Sets element `i` to `desired` if it is `expected`, and answers the value
1066
+ * it saw.
1067
+ *
1068
+ * @param i the element's index, from `0` to `length - 1`.
1069
+ * @param expected the value the update requires.
1070
+ * @param desired the value stored when the element is `expected`.
1071
+ * @returns the element seen before the update: `expected` exactly when the
1072
+ * update happened.
1073
+ */
1074
+ compareExchange(i: i32, expected: i64, desired: i64): i64 {
1075
+ const old = this.values[i]
1076
+ if (old === expected) {
1077
+ this.values[i] = desired
1078
+ }
1079
+ return old
1080
+ }
1081
+ }
1082
+
785
1083
  /**
786
1084
  * A channel of scalars or strings between a scope's tasks (docs/wp29-thread-surface.md
787
1085
  * §4.4); a string is copied out of the sender's arena at `send` and into the