@shd101wyy/yo 0.0.32 → 0.1.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shd101wyy/yo",
3
3
  "displayName": "Yo",
4
- "version": "0.0.32",
4
+ "version": "0.1.0",
5
5
  "main": "./out/cjs/index.cjs",
6
6
  "module": "./out/esm/index.mjs",
7
7
  "types": "./out/types/src/index.d.ts",
package/std/build.yo CHANGED
@@ -6,7 +6,7 @@
6
6
  //
7
7
  // Usage in build.yo:
8
8
  // build :: import "std/build";
9
- // build.project({ name: "my-app", root: "./src/lib.yo" });
9
+ // mod :: build.module({ name: "my-app", root: "./src/lib.yo" });
10
10
  // exe :: build.executable({ name: "my-app", root: "./src/main.yo" });
11
11
  // install :: build.step("install", "Build all artifacts");
12
12
  // install.depend_on(exe);
@@ -61,12 +61,6 @@ export target_host;
61
61
  // Usage: build.executable({ name: "app", root: "./src/main.yo" })
62
62
  // Unspecified fields get their default values.
63
63
 
64
- Project :: struct(
65
- name : comptime_string,
66
- (root : comptime_string) ?= "./src/lib.yo"
67
- );
68
- export Project;
69
-
70
64
  Executable :: struct(
71
65
  name : comptime_string,
72
66
  root : comptime_string,
@@ -100,6 +94,26 @@ TestSuite :: struct(
100
94
  );
101
95
  export TestSuite;
102
96
 
97
+ // ── Build module type ────────────────────────────────────────────────
98
+ // Represents a named source module that declares system library requirements.
99
+ // Modules are the unit of reuse across Yo dependencies.
100
+
101
+ BuildModule :: struct(
102
+ name : comptime_string,
103
+ root : comptime_string,
104
+ _dep : comptime_string // dependency name, empty for local modules
105
+ );
106
+ export BuildModule;
107
+
108
+ // ── Import entry type ────────────────────────────────────────────────
109
+ // Pairs an import name with a module for use with add_import/add_import_list.
110
+
111
+ ImportEntry :: struct(
112
+ name : comptime_string,
113
+ module : BuildModule
114
+ );
115
+ export ImportEntry;
116
+
103
117
  // ── Step type ────────────────────────────────────────────────────────
104
118
  // Returned by all build functions. Used to wire dependencies between steps.
105
119
 
@@ -118,6 +132,17 @@ impl(Step,
118
132
  }),
119
133
  link : (fn(comptime(self) : Self, comptime(library) : Step) -> comptime(unit))({
120
134
  __yo_build_link(self.name, library.name);
135
+ }),
136
+ add_import : (fn(comptime(self) : Self, comptime(entry) : ImportEntry) -> comptime(unit))({
137
+ __yo_build_add_import(self.name, entry.name, entry.module.name, entry.module._dep);
138
+ })
139
+ );
140
+
141
+ // ── Build module methods ─────────────────────────────────────────────
142
+
143
+ impl(BuildModule,
144
+ link : (fn(comptime(self) : Self, comptime(library) : Step) -> comptime(unit))({
145
+ __yo_build_module_link(self.name, library.name);
121
146
  })
122
147
  );
123
148
 
@@ -150,10 +175,10 @@ export PathDependency;
150
175
 
151
176
  SystemLibrary :: struct(
152
177
  name : comptime_string,
153
- pkg_config : comptime_string,
154
178
  (fallback_include : comptime_string) ?= "",
155
179
  (fallback_lib : comptime_string) ?= "",
156
- (fallback_link : comptime_string) ?= ""
180
+ (fallback_link : comptime_string) ?= "",
181
+ (defines : comptime_string) ?= ""
157
182
  );
158
183
  export SystemLibrary;
159
184
 
@@ -172,6 +197,12 @@ impl(Dependency,
172
197
  artifact : (fn(comptime(self) : Self, comptime(artifact_name) : comptime_string) -> comptime(Step))({
173
198
  __yo_build_dep_artifact(self.name, artifact_name);
174
199
  Step(name: artifact_name, kind: StepKind.StaticLibrary)
200
+ }),
201
+ // Get a module from the dependency's build.yo.
202
+ // Empty module_name defaults to the sole module if exactly one exists.
203
+ module : (fn(comptime(self) : Self, comptime(module_name) : comptime_string) -> comptime(BuildModule))({
204
+ _encoded :: __yo_build_dep_module(self.name, module_name);
205
+ BuildModule(name: module_name, root: "", _dep: self.name)
175
206
  })
176
207
  );
177
208
 
@@ -179,12 +210,6 @@ impl(Dependency,
179
210
  // All registration functions return a Step value, allowing steps to be
180
211
  // wired together as dependencies via step.depend_on(dep).
181
212
 
182
- // Register project metadata.
183
- project :: (fn(comptime(config) : Project) -> comptime(unit)) {
184
- __yo_build_project(config.name, config.root);
185
- };
186
- export project;
187
-
188
213
  // Register an executable artifact. Returns a Step for dependency wiring.
189
214
  executable :: (fn(comptime(config) : Executable) -> comptime(Step)) {
190
215
  opt_str :: match(config.optimize,
@@ -273,11 +298,27 @@ export path_dependency;
273
298
 
274
299
  // Register a system C library discovered via pkg-config. Returns a Step for linking.
275
300
  system_library :: (fn(comptime(config) : SystemLibrary) -> comptime(Step)) {
276
- __yo_build_system_library(config.name, config.pkg_config, config.fallback_include, config.fallback_lib, config.fallback_link);
301
+ __yo_build_system_library(config.name, config.fallback_include, config.fallback_lib, config.fallback_link, config.defines);
277
302
  Step(name: config.name, kind: StepKind.SystemLibrary)
278
303
  };
279
304
  export system_library;
280
305
 
306
+ // ── Module config type ───────────────────────────────────────────────
307
+
308
+ ModuleConfig :: struct(
309
+ name : comptime_string,
310
+ root : comptime_string
311
+ );
312
+ export ModuleConfig;
313
+
314
+ // Register a named module. Returns a BuildModule for linking system libraries
315
+ // and importing into executables/libraries.
316
+ _module :: (fn(comptime(config) : ModuleConfig) -> comptime(BuildModule)) {
317
+ __yo_build_module(config.name, config.root);
318
+ BuildModule(name: config.name, root: config.root, _dep: "")
319
+ };
320
+ export module : _module;
321
+
281
322
  // Declare a user-configurable build option.
282
323
  // Returns the option value (from CLI -Dname=value, or the default).
283
324
  // Usage: strip :: build.option({ name: "strip", description: "Strip debug symbols", default: "false" });
package/std/thread.yo CHANGED
@@ -8,7 +8,7 @@ extern "Yo",
8
8
  // Low-level runtime types and functions for Thread
9
9
  extern "Yo",
10
10
  __yo_thread_t : Type,
11
- __yo_thread_spawn : (fn(cb : Impl(Fn() -> unit, Send)) -> __yo_thread_t),
11
+ __yo_thread_spawn : (fn(cb : Impl(Fn(using(io : IO)) -> unit, Send)) -> __yo_thread_t),
12
12
  __yo_thread_join : (fn(t : __yo_thread_t) -> unit)
13
13
  ;
14
14
 
@@ -17,8 +17,9 @@ Thread :: struct(
17
17
  handle : __yo_thread_t
18
18
  );
19
19
  impl(Thread,
20
- // Spawn a new OS thread running the given closure
21
- spawn : (fn(cb : Impl(Fn() -> unit, Send)) -> Self)({
20
+ // Spawn a new OS thread running the given closure.
21
+ // The closure receives its own per-thread IO event loop.
22
+ spawn : (fn(cb : Impl(Fn(using(io : IO)) -> unit, Send)) -> Self)({
22
23
  raw := __yo_thread_spawn(cb);
23
24
  Self(raw)
24
25
  }),
package/std/worker.yo CHANGED
@@ -7,9 +7,10 @@
7
7
  // Thread-per-core: By default, one worker thread per CPU core.
8
8
  // Thread affinity: Each task runs on a specific worker thread.
9
9
  // Thread-local GC: Each worker thread has its own GC heap.
10
+ // Per-thread IO: Each worker thread has its own async event loop, shared by all tasks on that thread.
10
11
 
11
12
  extern "Yo",
12
- __yo_worker_spawn : (fn(cb : Impl(Fn() -> unit, Send)) -> unit),
13
+ __yo_worker_spawn : (fn(cb : Impl(Fn(using(io : IO)) -> unit, Send)) -> unit),
13
14
  __yo_worker_get_num_threads : (fn() -> usize),
14
15
  __yo_worker_set_num_threads : (fn(num: usize) -> unit)
15
16
  ;
@@ -17,7 +18,8 @@ extern "Yo",
17
18
  // Spawn a task on the thread pool.
18
19
  // Returns immediately, task runs in background.
19
20
  // Tasks are distributed round-robin to worker threads.
20
- spawn :: (fn(cb : Impl(Fn() -> unit, Send)) -> unit)({
21
+ // The closure receives the worker thread's IO event loop.
22
+ spawn :: (fn(cb : Impl(Fn(using(io : IO)) -> unit, Send)) -> unit)({
21
23
  __yo_worker_spawn(cb);
22
24
  });
23
25