@shd101wyy/yo 0.1.14 → 0.1.16

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 (60) hide show
  1. package/README.md +43 -1
  2. package/out/cjs/index.cjs +581 -601
  3. package/out/cjs/yo-cli.cjs +739 -733
  4. package/out/cjs/yo-lsp.cjs +11615 -0
  5. package/out/esm/index.mjs +530 -550
  6. package/out/types/src/cache.d.ts +2 -0
  7. package/out/types/src/codegen/exprs/return.d.ts +1 -1
  8. package/out/types/src/codegen/types/generation.d.ts +0 -2
  9. package/out/types/src/codegen/utils/index.d.ts +2 -8
  10. package/out/types/src/doc/extractor.d.ts +4 -0
  11. package/out/types/src/evaluator/builtins/rc-fns.d.ts +0 -5
  12. package/out/types/src/evaluator/context.d.ts +7 -3
  13. package/out/types/src/evaluator/trait-checking.d.ts +2 -0
  14. package/out/types/src/evaluator/types/object.d.ts +2 -1
  15. package/out/types/src/evaluator/types/struct.d.ts +2 -1
  16. package/out/types/src/evaluator/types/utils.d.ts +3 -8
  17. package/out/types/src/evaluator/values/impl.d.ts +9 -1
  18. package/out/types/src/expr.d.ts +1 -2
  19. package/out/types/src/function-value.d.ts +1 -0
  20. package/out/types/src/lsp/completion.d.ts +3 -0
  21. package/out/types/src/lsp/definition.d.ts +3 -0
  22. package/out/types/src/lsp/diagnostics.d.ts +6 -0
  23. package/out/types/src/lsp/document-manager.d.ts +31 -0
  24. package/out/types/src/lsp/folding.d.ts +3 -0
  25. package/out/types/src/lsp/hover.d.ts +3 -0
  26. package/out/types/src/lsp/inlay-hints.d.ts +3 -0
  27. package/out/types/src/lsp/references.d.ts +3 -0
  28. package/out/types/src/lsp/rename.d.ts +16 -0
  29. package/out/types/src/lsp/server.d.ts +1 -0
  30. package/out/types/src/lsp/signature-help.d.ts +3 -0
  31. package/out/types/src/lsp/symbols.d.ts +3 -0
  32. package/out/types/src/lsp/utils.d.ts +11 -0
  33. package/out/types/src/tests/lsp.test.d.ts +1 -0
  34. package/out/types/src/tests/version.test.d.ts +1 -0
  35. package/out/types/src/types/creators.d.ts +2 -3
  36. package/out/types/src/types/definitions.d.ts +3 -6
  37. package/out/types/src/types/guards.d.ts +5 -2
  38. package/out/types/src/types/tags.d.ts +0 -1
  39. package/out/types/src/version-cache.d.ts +7 -0
  40. package/out/types/src/version.d.ts +5 -0
  41. package/out/types/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +3 -1
  43. package/scripts/build-site.ts +32 -15
  44. package/scripts/check-liburing.js +2 -2
  45. package/std/imm/list.yo +254 -0
  46. package/std/imm/map.yo +917 -0
  47. package/std/imm/set.yo +179 -0
  48. package/std/imm/sorted_map.yo +595 -0
  49. package/std/imm/sorted_set.yo +202 -0
  50. package/std/imm/string.yo +667 -0
  51. package/std/imm/vec.yo +456 -0
  52. package/std/prelude.yo +22 -5
  53. package/std/sync/channel.yo +92 -44
  54. package/std/sync/cond.yo +5 -1
  55. package/std/sync/mutex.yo +5 -1
  56. package/std/sync/once.yo +2 -1
  57. package/std/sync/rwlock.yo +2 -1
  58. package/std/sync/waitgroup.yo +2 -1
  59. package/out/types/src/codegen/exprs/arc.d.ts +0 -5
  60. package/out/types/src/evaluator/calls/arc.d.ts +0 -15
package/std/imm/set.yo ADDED
@@ -0,0 +1,179 @@
1
+ //! Persistent immutable hash set using a Hash Array Mapped Trie (HAMT).
2
+ //!
3
+ //! `Set(T)` is a thin wrapper around `Map(T, bool)`, backed by `atomic object`
4
+ //! nodes for thread-safe structural sharing. All mutations return new sets,
5
+ //! leaving the original unchanged.
6
+ //!
7
+ //! Elements must implement `Eq`, `Hash`, and `Send`.
8
+ //!
9
+ //! # Examples
10
+ //!
11
+ //! ```rust
12
+ //! { Set } :: import "std/imm/set";
13
+ //!
14
+ //! s := Set(i32).new();
15
+ //! s = s.insert(i32(1));
16
+ //! s = s.insert(i32(2));
17
+ //! assert(s.contains(i32(1)), "set contains 1");
18
+ //! assert((s.len() == usize(2)), "two elements");
19
+ //! ```
20
+
21
+ { Map } :: import "./map.yo";
22
+ { List } :: import "./list.yo";
23
+
24
+ /// Persistent immutable hash set backed by a HAMT.
25
+ ///
26
+ /// Wraps `Map(T, bool)` internally. The bool values are always `true`.
27
+ Set :: (fn(comptime(T) : Type, where(T <: (Eq(T), Hash, Send))) -> comptime(Type))(
28
+ struct(_inner : Map(T, bool))
29
+ );
30
+
31
+ impl(forall(T : Type), where(T <: (Eq(T), Hash, Send)), Set(T),
32
+ /// Create an empty set.
33
+ new : (fn() -> Self)(
34
+ Self(_inner: Map(T, bool).new())
35
+ ),
36
+
37
+ /// Number of elements.
38
+ len : (fn(self: Self) -> usize)(self._inner.len()),
39
+
40
+ /// Check if the set is empty.
41
+ is_empty : (fn(self: Self) -> bool)(self._inner.is_empty()),
42
+
43
+ /// Check if the set contains `elem`.
44
+ contains : (fn(self: Self, elem: T) -> bool)(
45
+ self._inner.contains_key(elem)
46
+ ),
47
+
48
+ /// Return a new set with `elem` added.
49
+ insert : (fn(self: Self, elem: T) -> Self)(
50
+ Self(_inner: self._inner.insert(elem, true))
51
+ ),
52
+
53
+ /// Return a new set with `elem` removed.
54
+ remove : (fn(self: Self, elem: T) -> Self)(
55
+ Self(_inner: self._inner.remove(elem))
56
+ ),
57
+
58
+ /// Return the union of two sets (`self ∪ other`).
59
+ union : (fn(self: Self, other: Self) -> Self)(
60
+ Self(_inner: self._inner.merge(other._inner))
61
+ ),
62
+
63
+ /// Return the intersection of two sets (`self ∩ other`).
64
+ intersection : (fn(self: Self, other: Self) -> Self)({
65
+ elems := self.to_list();
66
+ (result : Self) = Self.new();
67
+ (cur : List(T)) = elems;
68
+ (done : bool) = false;
69
+ while runtime(!(done)), {
70
+ match(cur.head(),
71
+ .Some(elem) => {
72
+ if(other.contains(elem), {
73
+ result = result.insert(elem);
74
+ });
75
+ cur = cur.tail();
76
+ },
77
+ .None => {
78
+ done = true;
79
+ }
80
+ );
81
+ };
82
+ result
83
+ }),
84
+
85
+ /// Return the difference (`self \ other`).
86
+ difference : (fn(self: Self, other: Self) -> Self)({
87
+ elems := self.to_list();
88
+ (result : Self) = Self.new();
89
+ (cur : List(T)) = elems;
90
+ (done : bool) = false;
91
+ while runtime(!(done)), {
92
+ match(cur.head(),
93
+ .Some(elem) => {
94
+ if(!(other.contains(elem)), {
95
+ result = result.insert(elem);
96
+ });
97
+ cur = cur.tail();
98
+ },
99
+ .None => {
100
+ done = true;
101
+ }
102
+ );
103
+ };
104
+ result
105
+ }),
106
+
107
+ /// Check if `self` is a subset of `other`.
108
+ is_subset : (fn(self: Self, other: Self) -> bool)({
109
+ if((self.len() > other.len()), {
110
+ return false;
111
+ });
112
+ elems := self.to_list();
113
+ (cur : List(T)) = elems;
114
+ (result : bool) = true;
115
+ while runtime((result && !(cur.is_empty()))), {
116
+ match(cur.head(),
117
+ .Some(elem) => {
118
+ if(!(other.contains(elem)), {
119
+ result = false;
120
+ });
121
+ cur = cur.tail();
122
+ },
123
+ .None => ()
124
+ );
125
+ };
126
+ result
127
+ }),
128
+
129
+ /// Check if two sets are disjoint.
130
+ is_disjoint : (fn(self: Self, other: Self) -> bool)({
131
+ (smaller : Self) = cond(
132
+ (self.len() <= other.len()) => self,
133
+ true => other
134
+ );
135
+ (larger : Self) = cond(
136
+ (self.len() <= other.len()) => other,
137
+ true => self
138
+ );
139
+ elems := smaller.to_list();
140
+ (cur : List(T)) = elems;
141
+ (result : bool) = true;
142
+ while runtime((result && !(cur.is_empty()))), {
143
+ match(cur.head(),
144
+ .Some(elem) => {
145
+ if(larger.contains(elem), {
146
+ result = false;
147
+ });
148
+ cur = cur.tail();
149
+ },
150
+ .None => ()
151
+ );
152
+ };
153
+ result
154
+ }),
155
+
156
+ /// Collect all elements into a List.
157
+ to_list : (fn(self: Self) -> List(T))(
158
+ self._inner.keys()
159
+ ),
160
+
161
+ /// Create a set from a slice of elements.
162
+ from_slice : (fn(s: Slice(T)) -> Self)({
163
+ (result : Self) = Self.new();
164
+ i := usize(0);
165
+ slen := s.len();
166
+ while (i < slen), (i = (i + usize(1))), {
167
+ result = result.insert((s.ptr() &+ i).*);
168
+ };
169
+ result
170
+ })
171
+ );
172
+
173
+ impl(forall(T : Type), where(T <: (Eq(T), Hash, Send)), Set(T), Eq(Set(T))(
174
+ (==) : (fn(lhs: Self, rhs: Self) -> bool)(
175
+ (lhs._inner == rhs._inner)
176
+ )
177
+ ));
178
+
179
+ export Set;