@shd101wyy/yo 0.0.23 → 0.0.25

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 (97) hide show
  1. package/out/cjs/index.cjs +560 -520
  2. package/out/cjs/yo-cli.cjs +598 -558
  3. package/out/esm/index.mjs +551 -511
  4. package/out/types/src/codegen/exprs/arc.d.ts +5 -0
  5. package/out/types/src/codegen/types/generation.d.ts +2 -0
  6. package/out/types/src/codegen/utils/index.d.ts +8 -1
  7. package/out/types/src/evaluator/builtins/rc-fns.d.ts +5 -0
  8. package/out/types/src/evaluator/calls/arc.d.ts +15 -0
  9. package/out/types/src/evaluator/calls/trait-type.d.ts +8 -1
  10. package/out/types/src/evaluator/context.d.ts +11 -1
  11. package/out/types/src/evaluator/types/utils.d.ts +8 -3
  12. package/out/types/src/evaluator/utils/closure.d.ts +7 -1
  13. package/out/types/src/evaluator/values/impl.d.ts +8 -0
  14. package/out/types/src/expr.d.ts +6 -0
  15. package/out/types/src/test-runner.d.ts +2 -0
  16. package/out/types/src/types/creators.d.ts +2 -1
  17. package/out/types/src/types/definitions.d.ts +10 -0
  18. package/out/types/src/types/guards.d.ts +2 -1
  19. package/out/types/src/types/tags.d.ts +1 -0
  20. package/out/types/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +1 -1
  22. package/std/collections/array_list.yo +80 -10
  23. package/std/collections/btree_map.yo +120 -2
  24. package/std/collections/deque.yo +98 -6
  25. package/std/collections/hash_map.yo +137 -1
  26. package/std/collections/hash_set.yo +85 -1
  27. package/std/collections/linked_list.yo +61 -1
  28. package/std/collections/priority_queue.yo +70 -1
  29. package/std/crypto/md5.yo +4 -4
  30. package/std/crypto/random.yo +3 -3
  31. package/std/crypto/sha256.yo +8 -7
  32. package/std/encoding/base64.yo +6 -6
  33. package/std/encoding/hex.yo +27 -22
  34. package/std/encoding/json.yo +185 -186
  35. package/std/encoding/utf16.yo +2 -2
  36. package/std/fmt/display.yo +1 -1
  37. package/std/fmt/writer.yo +2 -4
  38. package/std/fs/dir.yo +5 -5
  39. package/std/fs/file.yo +21 -13
  40. package/std/fs/metadata.yo +4 -4
  41. package/std/fs/temp.yo +3 -3
  42. package/std/fs/types.yo +1 -1
  43. package/std/fs/walker.yo +1 -1
  44. package/std/net/addr.yo +2 -2
  45. package/std/net/dns.yo +21 -20
  46. package/std/net/errors.yo +1 -1
  47. package/std/net/tcp.yo +134 -100
  48. package/std/net/udp.yo +51 -42
  49. package/std/os/env.yo +21 -23
  50. package/std/os/signal.yo +10 -9
  51. package/std/prelude.yo +158 -22
  52. package/std/string/string.yo +99 -1
  53. package/std/sync/once.yo +1 -1
  54. package/std/{io → sys}/advise.yo +1 -1
  55. package/std/sys/bufio/buf_reader.yo +300 -0
  56. package/std/sys/bufio/buf_writer.yo +168 -0
  57. package/std/{io → sys}/clock.yo +1 -1
  58. package/std/{io → sys}/constants.yo +1 -1
  59. package/std/{io → sys}/copy.yo +1 -1
  60. package/std/{io → sys}/dir.yo +6 -6
  61. package/std/{io → sys}/dns.yo +3 -3
  62. package/std/{io → sys}/errors.yo +1 -1
  63. package/std/{io → sys}/events.yo +1 -1
  64. package/std/{io → sys}/externs.yo +1 -1
  65. package/std/{io → sys}/fallocate.yo +1 -1
  66. package/std/{io → sys}/fcntl.yo +1 -1
  67. package/std/{io → sys}/file.yo +1 -1
  68. package/std/{io → sys}/future.yo +1 -1
  69. package/std/{io → sys}/iov.yo +1 -1
  70. package/std/{io → sys}/lock.yo +1 -1
  71. package/std/{io → sys}/mmap.yo +1 -1
  72. package/std/{io → sys}/path.yo +1 -1
  73. package/std/{io → sys}/perm.yo +3 -3
  74. package/std/{io → sys}/pipe.yo +1 -1
  75. package/std/{io → sys}/process.yo +1 -1
  76. package/std/{io → sys}/seek.yo +1 -1
  77. package/std/{io → sys}/signal.yo +1 -1
  78. package/std/{io → sys}/signals.yo +1 -1
  79. package/std/{io → sys}/socket.yo +1 -1
  80. package/std/{io → sys}/socketpair.yo +1 -1
  81. package/std/{io → sys}/sockinfo.yo +1 -1
  82. package/std/{io → sys}/statfs.yo +2 -2
  83. package/std/{io → sys}/statx.yo +1 -1
  84. package/std/{io → sys}/sysinfo.yo +1 -1
  85. package/std/{io → sys}/tcp.yo +3 -3
  86. package/std/{io → sys}/temp.yo +1 -1
  87. package/std/{io → sys}/time.yo +2 -2
  88. package/std/{io → sys}/timer.yo +1 -1
  89. package/std/{io → sys}/tty.yo +1 -1
  90. package/std/{io → sys}/udp.yo +4 -4
  91. package/std/{io → sys}/umask.yo +1 -1
  92. package/std/{io → sys}/unix.yo +1 -1
  93. package/std/time/datetime.yo +18 -23
  94. package/std/time/instant.yo +13 -11
  95. package/std/url/url.yo +533 -0
  96. package/std/math/functions.yo +0 -74
  97. package/std/math/random.yo +0 -94
@@ -118,4 +118,73 @@ impl(forall(T : Type), PriorityQueue(T),
118
118
  })
119
119
  );
120
120
 
121
- export PriorityQueue;
121
+ /**
122
+ * Value iterator for PriorityQueue - yields elements in heap (arbitrary) order
123
+ * Note: This iterates in internal storage order, NOT sorted order.
124
+ */
125
+ PriorityQueueIter :: (fn(comptime(T) : Type) -> comptime(Type))(
126
+ struct(
127
+ _data : ArrayList(T),
128
+ _index : usize
129
+ )
130
+ );
131
+
132
+ impl(forall(T : Type), PriorityQueueIter(T), Iterator(
133
+ Item : T,
134
+ next : (fn(self : *(Self)) -> Option(T))(
135
+ cond(
136
+ (self._index >= self._data.len()) => .None,
137
+ true => {
138
+ value := self._data.get(self._index).unwrap();
139
+ self._index = (self._index + usize(1));
140
+ .Some(value)
141
+ }
142
+ )
143
+ )
144
+ ));
145
+
146
+ impl(forall(T : Type), PriorityQueue(T),
147
+ into_iter : (fn(self : Self) -> PriorityQueueIter(T))(
148
+ PriorityQueueIter(T)(_data: self._data, _index: usize(0))
149
+ )
150
+ );
151
+
152
+ /**
153
+ * Pointer iterator for PriorityQueue - yields pointers to elements in heap order
154
+ */
155
+ PriorityQueueIterPtr :: (fn(comptime(T) : Type) -> comptime(Type))(
156
+ struct(
157
+ _data : ArrayList(T),
158
+ _index : usize
159
+ )
160
+ );
161
+
162
+ impl(forall(T : Type), PriorityQueueIterPtr(T), Iterator(
163
+ Item : *(T),
164
+ next : (fn(self : *(Self)) -> Option(*(T)))(
165
+ cond(
166
+ (self._index >= self._data.len()) => .None,
167
+ true =>
168
+ match(self._data._ptr,
169
+ .Some(ptr) => {
170
+ element_ptr := (ptr &+ self._index);
171
+ self._index = (self._index + usize(1));
172
+ .Some(element_ptr)
173
+ },
174
+ .None => .None
175
+ )
176
+ )
177
+ )
178
+ ));
179
+
180
+ impl(forall(T : Type), PriorityQueue(T),
181
+ iter : (fn(self : *(Self)) -> PriorityQueueIterPtr(T))(
182
+ PriorityQueueIterPtr(T)(_data: self.*._data, _index: usize(0))
183
+ )
184
+ );
185
+
186
+ export
187
+ PriorityQueue,
188
+ PriorityQueueIter,
189
+ PriorityQueueIterPtr
190
+ ;
package/std/crypto/md5.yo CHANGED
@@ -51,8 +51,8 @@ _rotl32 :: (fn(x: u32, n: u32) -> u32)(
51
51
  );
52
52
 
53
53
  _le32 :: (fn(p: *(u8)) -> u32)(
54
- (u32(p.*) | (u32((p &+ usize(1)).*) << u32(8)) |
55
- (u32((p &+ usize(2)).*) << u32(16)) | (u32((p &+ usize(3)).*) << u32(24)))
54
+ ((u32(p.*) | (u32((p &+ usize(1)).*) << u32(8))) |
55
+ ((u32((p &+ usize(2)).*) << u32(16)) | (u32((p &+ usize(3)).*) << u32(24))))
56
56
  );
57
57
 
58
58
  _md5_block :: (fn(block: *(u8), h: *(u32)) -> unit)({
@@ -74,7 +74,7 @@ _md5_block :: (fn(block: *(u8), h: *(u32)) -> unit)({
74
74
  g = (((i * usize(5)) + usize(1)) % usize(16));
75
75
  },
76
76
  (i < usize(48)) => {
77
- fv = (b ^ c ^ d);
77
+ fv = ((b ^ c) ^ d);
78
78
  g = (((i * usize(3)) + usize(5)) % usize(16));
79
79
  },
80
80
  true => {
@@ -104,7 +104,7 @@ md5 :: (fn(data: ArrayList(u8)) -> Array(u8, usize(16)))({
104
104
  // Process full blocks
105
105
  i := usize(0);
106
106
  while ((i + usize(64)) <= n), (i = (i + usize(64))), {
107
- chunk_ptr := *(u8)(data.ptr().unwrap()) &+ i;
107
+ chunk_ptr := (*(u8)(data.ptr().unwrap()) &+ i);
108
108
  _md5_block(chunk_ptr, h_ptr);
109
109
  };
110
110
  // Final block(s) with padding
@@ -93,12 +93,12 @@ random_f64 :: (fn() -> f64)(
93
93
 
94
94
  // Return a random integer in the half-open range [min, max).
95
95
  random_range :: (fn(min: i64, max: i64) -> i64)({
96
- span := i64((max - min));
96
+ span := (max - min);
97
97
  cond(
98
98
  (span <= i64(0)) => min,
99
99
  true => {
100
- r := i64(random_u64());
101
- (min + (r % span))
100
+ r := random_u64();
101
+ (min + i64((r % u64(span))))
102
102
  }
103
103
  )
104
104
  });
@@ -39,7 +39,7 @@ _rotr32 :: (fn(x: u32, n: u32) -> u32)(
39
39
  );
40
40
 
41
41
  _ch :: (fn(e: u32, f: u32, g: u32) -> u32)( ((e & f) ^ ((~e) & g)) );
42
- _maj :: (fn(a: u32, b: u32, c: u32) -> u32)( ((a & b) ^ (a & c) ^ (b & c)) );
42
+ _maj :: (fn(a: u32, b: u32, c: u32) -> u32)( (((a & b) ^ (a & c)) ^ (b & c)) );
43
43
  _ep0 :: (fn(a: u32) -> u32)( ((_rotr32(a, u32(2)) ^ _rotr32(a, u32(13))) ^ _rotr32(a, u32(22))) );
44
44
  _ep1 :: (fn(e: u32) -> u32)( ((_rotr32(e, u32(6)) ^ _rotr32(e, u32(11))) ^ _rotr32(e, u32(25))) );
45
45
  _sg0 :: (fn(x: u32) -> u32)( ((_rotr32(x, u32(7)) ^ _rotr32(x, u32(18))) ^ (x >> u32(3))) );
@@ -53,15 +53,16 @@ _sha256_block :: (fn(block: *(u8), h: *(u32)) -> unit)({
53
53
  while (i < usize(16)), (i = (i + usize(1))), {
54
54
  off := (i * usize(4));
55
55
  w(i) = (
56
- ((u32((block &+ off).*) << u32(24)) |
57
- (u32((block &+ (off + usize(1))).*) << u32(16)) |
58
- (u32((block &+ (off + usize(2))).*) << u32(8)) |
59
- u32((block &+ (off + usize(3))).*)
60
- )
56
+ (((u32((block &+ off).*) << u32(24)) |
57
+ (u32((block &+ (off + usize(1))).*) << u32(16))) |
58
+ ((u32((block &+ (off + usize(2))).*) << u32(8)) |
59
+ u32((block &+ (off + usize(3))).*)))
61
60
  );
62
61
  };
63
62
  while (i < usize(64)), (i = (i + usize(1))), {
64
- w(i) = ((((_sg1(w((i - usize(2)))) + w((i - usize(7)))) + _sg0(w((i - usize(15))))) + w((i - usize(16))));
63
+ s1 := _sg1(w((i - usize(2))));
64
+ s0 := _sg0(w((i - usize(15))));
65
+ w(i) = (((s1 + w((i - usize(7)))) + s0) + w((i - usize(16))));
65
66
  };
66
67
  // Compression
67
68
  a := (h &+ usize(0)).*;
@@ -30,8 +30,8 @@ _encode_with :: (fn(data: ArrayList(u8), alpha: str, pad: bool) -> String)({
30
30
  i := usize(0);
31
31
  while (i < n), (i = (i + usize(3))), {
32
32
  b0 := data.get(i).unwrap();
33
- b1 := cond((i + usize(1)) < n => data.get((i + usize(1))).unwrap(), true => u8(0));
34
- b2 := cond((i + usize(2)) < n => data.get((i + usize(2))).unwrap(), true => u8(0));
33
+ b1 := cond(((i + usize(1)) < n) => data.get((i + usize(1))).unwrap(), true => u8(0));
34
+ b2 := cond(((i + usize(2)) < n) => data.get((i + usize(2))).unwrap(), true => u8(0));
35
35
 
36
36
  out.push(alpha.bytes(usize((b0 >> u8(2)))));
37
37
  out.push(alpha.bytes(usize(((b0 & u8(3)) << u8(4)) | (b1 >> u8(4)))));
@@ -87,22 +87,22 @@ _decode_char :: (fn(c: u8, alpha: str) -> Result(u8, EncodingError))({
87
87
  _decode_with :: (fn(s: str, alpha: str) -> Result(ArrayList(u8), EncodingError))({
88
88
  // Strip trailing padding
89
89
  len := s.len();
90
- while ((len > usize(0)) && (s.bytes((len - usize(1))) == _PAD)), (len = (len - usize(1))), {};
90
+ while ((len > usize(0)) && (s.bytes((len - usize(1))) == _PAD)), (len = (len - usize(1))), ();
91
91
  out := ArrayList(u8).with_capacity(((len * usize(3)) / usize(4)));
92
92
  i := usize(0);
93
93
  while (i < len), (i = (i + usize(4))), {
94
94
  c0_r := _decode_char(s.bytes(i), alpha);
95
95
  c1_r := cond(
96
96
  ((i + usize(1)) < len) => _decode_char(s.bytes((i + usize(1))), alpha),
97
- true => .Ok(u8(0))
97
+ true => Result(u8, EncodingError).Ok(u8(0))
98
98
  );
99
99
  c2_r := cond(
100
100
  ((i + usize(2)) < len) => _decode_char(s.bytes((i + usize(2))), alpha),
101
- true => .Ok(u8(0))
101
+ true => Result(u8, EncodingError).Ok(u8(0))
102
102
  );
103
103
  c3_r := cond(
104
104
  ((i + usize(3)) < len) => _decode_char(s.bytes((i + usize(3))), alpha),
105
- true => .Ok(u8(0))
105
+ true => Result(u8, EncodingError).Ok(u8(0))
106
106
  );
107
107
  match(c0_r,
108
108
  .Err(e) => { return .Err(e); },
@@ -29,19 +29,23 @@ export EncodingError;
29
29
  _HEX_CHARS :: "0123456789abcdef";
30
30
 
31
31
  // Encode bytes as lowercase hexadecimal.
32
- hex_encode :: (fn(data: ArrayList(u8)) -> String)({
32
+ _hex_encode_impl :: (fn(data: ArrayList(u8), hex_chars: str) -> String)({
33
33
  out := ArrayList(u8).with_capacity((data.len() * usize(2)));
34
34
  i := usize(0);
35
35
  while (i < data.len()), (i = (i + usize(1))), {
36
36
  b := data.get(i).unwrap();
37
37
  hi := usize(((b >> u8(4)) & u8(0xF)));
38
38
  lo := usize((b & u8(0xF)));
39
- out.push(_HEX_CHARS.bytes(hi));
40
- out.push(_HEX_CHARS.bytes(lo));
39
+ out.push(hex_chars.bytes(hi));
40
+ out.push(hex_chars.bytes(lo));
41
41
  };
42
42
  String.from_bytes(out)
43
43
  });
44
44
 
45
+ hex_encode :: (fn(data: ArrayList(u8)) -> String)(
46
+ _hex_encode_impl(data, _HEX_CHARS)
47
+ );
48
+
45
49
  export hex_encode;
46
50
 
47
51
  // ============================================================================
@@ -60,28 +64,29 @@ _hex_nibble :: (fn(c: u8) -> Result(u8, EncodingError))(
60
64
  // Decode a hexadecimal string into bytes.
61
65
  hex_decode :: (fn(s: str) -> Result(ArrayList(u8), EncodingError))({
62
66
  cond(
63
- (((s.len() % usize(2)) != usize(0))) => .Err(.OddLength),
64
- true => {
65
- out := ArrayList(u8).with_capacity((s.len() / usize(2)));
66
- i := usize(0);
67
- while (i < s.len()), (i = (i + usize(2))), {
68
- hi_r := _hex_nibble(s.bytes(i));
69
- lo_r := _hex_nibble(s.bytes((i + usize(1))));
70
- match(hi_r,
67
+ (((s.len() % usize(2)) != usize(0))) => {
68
+ return .Err(.OddLength);
69
+ },
70
+ true => ()
71
+ );
72
+ out := ArrayList(u8).with_capacity((s.len() / usize(2)));
73
+ i := usize(0);
74
+ while (i < s.len()), (i = (i + usize(2))), {
75
+ hi_r := _hex_nibble(s.bytes(i));
76
+ lo_r := _hex_nibble(s.bytes((i + usize(1))));
77
+ match(hi_r,
78
+ .Err(e) => { return .Err(e); },
79
+ .Ok(hi) => {
80
+ match(lo_r,
71
81
  .Err(e) => { return .Err(e); },
72
- .Ok(hi) => {
73
- match(lo_r,
74
- .Err(e) => { return .Err(e); },
75
- .Ok(lo) => {
76
- out.push(((hi << u8(4)) | lo));
77
- }
78
- );
82
+ .Ok(lo) => {
83
+ out.push(((hi << u8(4)) | lo));
79
84
  }
80
85
  );
81
- };
82
- .Ok(out)
83
- }
84
- )
86
+ }
87
+ );
88
+ };
89
+ .Ok(out)
85
90
  });
86
91
 
87
92
  export hex_decode;