@pkmn/engine 0.1.0-dev.0cabf16e → 0.1.0-dev.0f9e9648

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 (66) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +47 -4
  3. package/build/pkg/addon/browser.d.ts +1 -1
  4. package/build/pkg/addon/browser.js +6 -2
  5. package/build/pkg/addon/browser.js.map +1 -1
  6. package/build/pkg/addon/node.js +22 -8
  7. package/build/pkg/addon/node.js.map +1 -1
  8. package/build/pkg/addon/wasm.d.ts +2 -0
  9. package/build/pkg/addon/wasm.js +53 -0
  10. package/build/pkg/addon/wasm.js.map +1 -0
  11. package/build/pkg/addon.d.ts +24 -4
  12. package/build/pkg/addon.js +8 -17
  13. package/build/pkg/addon.js.map +1 -1
  14. package/build/pkg/data/layout.json +15 -2
  15. package/build/pkg/data/protocol.json +23 -9
  16. package/build/pkg/gen1.d.ts +15 -18
  17. package/build/pkg/gen1.js +28 -19
  18. package/build/pkg/gen1.js.map +1 -1
  19. package/build/pkg/index.d.ts +37 -100
  20. package/build/pkg/index.js +23 -75
  21. package/build/pkg/index.js.map +1 -1
  22. package/build/tools/debug.js +18 -9
  23. package/build/tools/debug.js.map +1 -1
  24. package/build/tools/display/debug.jsx +18 -7
  25. package/build/tools/display/debug.jsx.map +1 -1
  26. package/build/tools/display/index.js +35 -15
  27. package/build/tools/display/index.js.map +1 -1
  28. package/build/tools/display/ui.jsx +17 -7
  29. package/build/tools/display/ui.jsx.map +1 -1
  30. package/build/tools/display/util.js +16 -1
  31. package/build/tools/display/util.js.map +1 -1
  32. package/build.zig +196 -84
  33. package/package.json +29 -127
  34. package/src/bin/install-pkmn-engine +3 -2
  35. package/src/lib/bindings/c.zig +255 -0
  36. package/src/lib/bindings/node.zig +121 -0
  37. package/src/lib/bindings/wasm.zig +59 -0
  38. package/src/lib/common/array.zig +1 -1
  39. package/src/lib/common/optional.zig +1 -1
  40. package/src/lib/common/options.zig +2 -0
  41. package/src/lib/common/protocol.zig +4 -8
  42. package/src/lib/common/rational.zig +222 -147
  43. package/src/lib/common/rng.zig +1 -3
  44. package/src/lib/common/util.zig +17 -2
  45. package/src/lib/gen1/calc.zig +87 -97
  46. package/src/lib/gen1/chance.zig +34 -18
  47. package/src/lib/gen1/data/moves.zig +2 -4
  48. package/src/lib/gen1/data/species.zig +1 -3
  49. package/src/lib/gen1/data/types.zig +1 -2
  50. package/src/lib/gen1/data.zig +7 -11
  51. package/src/lib/gen1/helpers.zig +4 -11
  52. package/src/lib/gen1/mechanics.zig +66 -50
  53. package/src/lib/gen2/calc.zig +10 -18
  54. package/src/lib/gen2/data/items.zig +1 -3
  55. package/src/lib/gen2/data/moves.zig +2 -4
  56. package/src/lib/gen2/data/species.zig +1 -3
  57. package/src/lib/gen2/data/types.zig +1 -2
  58. package/src/lib/gen2/data.zig +11 -15
  59. package/src/lib/gen2/generated.zig +18 -23
  60. package/src/lib/gen2/helpers.zig +5 -12
  61. package/src/lib/gen2/mechanics.zig +41 -38
  62. package/src/lib/node.zig +3 -116
  63. package/src/lib/pkmn.zig +7 -2
  64. package/src/lib/wasm.zig +13 -9
  65. package/src/tools/display/dom.ts +5 -8
  66. package/src/tools/display/ui.css +0 -5
@@ -7,6 +7,7 @@ pub const Options = struct {
7
7
  log: ?bool = null,
8
8
  chance: ?bool = null,
9
9
  calc: ?bool = null,
10
+ mod: ?bool = null,
10
11
  advance: ?bool = null,
11
12
  ebc: ?bool = null,
12
13
  key: ?bool = null,
@@ -24,6 +25,7 @@ pub const chance = get("chance", false);
24
25
  /// Whether or not damage calculator support is enabled.
25
26
  pub const calc = get("calc", false);
26
27
 
28
+ pub const mod = showdown or get("mod", false);
27
29
  pub const advance = get("advance", true);
28
30
  pub const ebc = get("ebc", true);
29
31
  pub const key = get("key", false);
@@ -1,18 +1,14 @@
1
- const std = @import("std");
2
1
  const builtin = @import("builtin");
3
-
4
- const pkmn = @import("../pkmn.zig");
5
-
6
2
  const data = @import("data.zig");
7
3
  const options = @import("options.zig");
4
+ const pkmn = @import("../pkmn.zig");
5
+ const std = @import("std");
8
6
 
9
7
  const assert = std.debug.assert;
10
- const print = std.debug.print;
11
-
12
8
  const enabled = options.log;
13
-
14
- const Player = data.Player;
15
9
  const ID = data.ID;
10
+ const Player = data.Player;
11
+ const print = std.debug.print;
16
12
 
17
13
  const endian = builtin.cpu.arch.endian();
18
14
  const Endian = std.builtin.Endian;
@@ -15,9 +15,27 @@ const ComptimeFloat =
15
15
 
16
16
  /// Specialization of a rational number used by the engine to compute probabilties.
17
17
  /// For performance reasons the rational is only reduced lazily and thus `reduce` must be
18
- /// invoked explicitly before reading.
18
+ /// invoked explicitly before reading. Note that this laziness means that this implementation
19
+ /// sometimes overflows in places where an eager reduced implementation would not - to achieve
20
+ /// the same behavior as an eager implementation simply call `reduce` after each operation.
19
21
  pub fn Rational(comptime T: type) type {
20
- return extern struct {
22
+ // With floats we can't rely on an overflow bit to let us know when to reduce, so we
23
+ // instead start reducing when we get sufficiently close to the limit of the mantissa
24
+ // (in our domain we expect updates to involve numbers < 2**10, so we should be safe
25
+ // not reducing before we are 2**10 away from "overflowing" the mantissa)
26
+ const o = if (@typeInfo(T) == Float)
27
+ std.math.pow(T, 2, std.math.floatMantissaBits(T) - 10)
28
+ else
29
+ 0;
30
+
31
+ const Err = switch (@typeInfo(T)) {
32
+ Int => error{Overflow},
33
+ Float => error{},
34
+ else => unreachable,
35
+ };
36
+
37
+ // Zig doesn't allow integers > u128 in an extern struct...
38
+ return if (@sizeOf(T) <= 16) extern struct {
21
39
  const Self = @This();
22
40
 
23
41
  /// Numerator. Must always be >= 1. Not guaranteed to be reduced in all cases.
@@ -25,21 +43,8 @@ pub fn Rational(comptime T: type) type {
25
43
  /// Denominator. Must always be >= 1. Not guaranteed to be reduced in all cases.
26
44
  q: T = 1,
27
45
 
28
- // With floats we can't rely on an overflow bit to let us know when to reduce, so we instead
29
- // start reducing when we get sufficiently close to the limit of the mantissa (in our domain
30
- // we expect updates to involve numbers < 2**10, so we should be safe not reducing before we
31
- // are 2**10 away from "overflowing" the mantissa)
32
- const REDUCE = if (@typeInfo(T) == Float)
33
- std.math.pow(T, 2, std.math.floatMantissaBits(T) - 10)
34
- else
35
- 0;
36
-
37
46
  /// Possible error returned by operations on the Rational.
38
- pub const Error = switch (@typeInfo(T)) {
39
- Int => error{Overflow},
40
- Float => error{},
41
- else => unreachable,
42
- };
47
+ pub const Error = Err;
43
48
 
44
49
  /// Resets the rational back to 1.
45
50
  pub fn reset(r: *Self) void {
@@ -50,135 +55,69 @@ pub fn Rational(comptime T: type) type {
50
55
  /// Update the rational by multiplying its numerator by p and its denominator by q.
51
56
  /// Both p and q must be >= 1, and if computable at comptime must have no common factors.
52
57
  pub fn update(r: *Self, p: anytype, q: anytype) Error!void {
53
- // std.debug.print("({d}/{d}) * ", .{ p, q }); // DEBUG
54
- assert(p >= 1);
55
- assert(q >= 1);
56
-
57
- // If our parameters are not fully reduced they may prematurely
58
- // cause overflow/loss of precision after the multiplication below
59
- assert(switch (@typeInfo(@TypeOf(p, q))) {
60
- ComptimeInt, ComptimeFloat => comptime gcd(p, q),
61
- else => 1,
62
- } == 1);
63
-
64
- switch (@typeInfo(T)) {
65
- Int => {
66
- // Greedily attempt to multiply and if it fails, reduce and try again
67
- r.multiplication(p, q) catch |err| switch (err) {
68
- error.Overflow => {
69
- r.reduce();
70
- try r.multiplication(p, q);
71
- },
72
- else => unreachable,
73
- };
74
- },
75
- Float => {
76
- // Reduce in situations where we're likely to start losing precision
77
- if (r.q > REDUCE or r.p > REDUCE) r.reduce();
78
-
79
- r.p *= switch (@typeInfo(@TypeOf(p))) {
80
- Float, ComptimeFloat => p,
81
- else => @floatFromInt(p),
82
- };
83
- r.q *= switch (@typeInfo(@TypeOf(q))) {
84
- Float, ComptimeFloat => q,
85
- else => @floatFromInt(q),
86
- };
87
-
88
- // We should always be dealing with whole numbers
89
- assert(std.math.modf(r.p).fpart == 0);
90
- assert(std.math.modf(r.q).fpart == 0);
91
- },
92
- else => unreachable,
93
- }
58
+ return update_(T, o, r, p, q);
94
59
  }
95
60
 
96
61
  /// Add two rationals using the identity (a/b) + (c/d) = (ad+bc)/(bd).
97
- pub fn add(r: *Self, s: *Self) Error!void {
98
- switch (@typeInfo(T)) {
99
- Int => {
100
- if (r.q == s.q) {
101
- r.p = std.math.add(T, r.p, s.p) catch |err| switch (err) {
102
- error.Overflow => val: {
103
- r.reduce();
104
- s.reduce();
105
- break :val try std.math.add(T, r.p, s.p);
106
- },
107
- else => unreachable,
108
- };
109
- } else {
110
- r.addition(s.p, s.q) catch |err| switch (err) {
111
- error.Overflow => {
112
- r.reduce();
113
- s.reduce();
114
- try r.addition(s.p, s.q);
115
- },
116
- else => unreachable,
117
- };
118
- }
119
- },
120
- Float => {
121
- if (r.q == s.q) {
122
- if (r.p > REDUCE) r.reduce();
123
- if (s.p > REDUCE) s.reduce();
124
-
125
- r.p += s.p;
126
- } else {
127
- // Always reduce to minimize loss of precision from the multiplications
128
- r.reduce();
129
- s.reduce();
62
+ pub fn add(r: *Self, s: anytype) Error!void {
63
+ return add_(T, o, r, s);
64
+ }
130
65
 
131
- r.p = (r.p * s.q) + (r.q * s.p);
132
- r.q *= s.q;
133
- }
66
+ /// Multiplies two rationals.
67
+ pub fn mul(r: *Self, s: anytype) Error!void {
68
+ return mul_(T, o, r, s);
69
+ }
134
70
 
135
- assert(std.math.modf(r.p).fpart == 0);
136
- assert(std.math.modf(r.q).fpart == 0);
137
- },
138
- else => unreachable,
139
- }
71
+ /// Normalize the rational by reducing by the greatest common divisor.
72
+ pub fn reduce(r: *Self) void {
73
+ reduce_(r);
140
74
  }
141
75
 
142
- /// Multiplies two rationals.
143
- pub fn mul(r: *Self, s: *Self) Error!void {
144
- switch (@typeInfo(T)) {
145
- Int => {
146
- r.multiplication(s.p, s.q) catch |err| switch (err) {
147
- error.Overflow => {
148
- r.reduce();
149
- s.reduce();
150
- try r.multiplication(s.p, s.q);
151
- },
152
- else => unreachable,
153
- };
154
- },
155
- Float => {
156
- if (r.q > REDUCE or r.p > REDUCE) r.reduce();
157
- if (s.q > REDUCE or s.p > REDUCE) s.reduce();
76
+ pub fn format(
77
+ self: Self,
78
+ comptime fmt: []const u8,
79
+ opts: std.fmt.FormatOptions,
80
+ writer: anytype,
81
+ ) !void {
82
+ _ = .{ fmt, opts };
83
+ try writer.print("{d}/{d}", .{ self.p, self.q });
84
+ }
85
+ } else struct {
86
+ const Self = @This();
158
87
 
159
- r.p *= s.p;
160
- r.q *= s.q;
88
+ /// Numerator. Must always be >= 1. Not guaranteed to be reduced in all cases.
89
+ p: T = 1,
90
+ /// Denominator. Must always be >= 1. Not guaranteed to be reduced in all cases.
91
+ q: T = 1,
161
92
 
162
- assert(std.math.modf(r.p).fpart == 0);
163
- assert(std.math.modf(r.q).fpart == 0);
164
- },
165
- else => unreachable,
166
- }
93
+ /// Possible error returned by operations on the Rational.
94
+ pub const Error = Err;
95
+
96
+ /// Resets the rational back to 1.
97
+ pub fn reset(r: *Self) void {
98
+ r.p = 1;
99
+ r.q = 1;
167
100
  }
168
101
 
169
- /// Normalize the rational by reducing by the greatest common divisor.
170
- pub fn reduce(r: *Self) void {
171
- const d = gcd(r.p, r.q);
172
- if (d == 1) return;
102
+ /// Update the rational by multiplying its numerator by p and its denominator by q.
103
+ /// Both p and q must be >= 1, and if computable at comptime must have no common factors.
104
+ pub fn update(r: *Self, p: anytype, q: anytype) Error!void {
105
+ return update_(T, o, r, p, q);
106
+ }
173
107
 
174
- assert(@mod(r.p, d) == 0);
175
- assert(@mod(r.q, d) == 0);
108
+ /// Add two rationals using the identity (a/b) + (c/d) = (ad+bc)/(bd).
109
+ pub fn add(r: *Self, s: anytype) Error!void {
110
+ return add_(T, o, r, s);
111
+ }
176
112
 
177
- r.p /= d;
178
- r.q /= d;
113
+ /// Multiplies two rationals.
114
+ pub fn mul(r: *Self, s: anytype) Error!void {
115
+ return mul_(T, o, r, s);
116
+ }
179
117
 
180
- assert(r.p >= 1);
181
- assert(r.q >= 1);
118
+ /// Normalize the rational by reducing by the greatest common divisor.
119
+ pub fn reduce(r: *Self) void {
120
+ reduce_(r);
182
121
  }
183
122
 
184
123
  pub fn format(
@@ -190,22 +129,151 @@ pub fn Rational(comptime T: type) type {
190
129
  _ = .{ fmt, opts };
191
130
  try writer.print("{d}/{d}", .{ self.p, self.q });
192
131
  }
132
+ };
133
+ }
193
134
 
194
- fn multiplication(r: *Self, p: anytype, q: anytype) !void {
195
- r.p = try std.math.mul(T, r.p, p);
196
- r.q = try std.math.mul(T, r.q, q);
197
- }
135
+ fn update_(comptime T: type, comptime o: comptime_int, r: anytype, p: anytype, q: anytype) !void {
136
+ // std.debug.print("({d}/{d}) * ", .{ p, q }); // DEBUG
137
+ assert(p >= 1);
138
+ assert(q >= 1);
198
139
 
199
- fn addition(r: *Self, p: anytype, q: anytype) !void {
200
- // (a/b) + (c/d) = (ad+bc)/(bd)
201
- const d = try std.math.mul(T, r.q, q);
202
- const n1 = try std.math.mul(T, r.p, q);
203
- const n2 = try std.math.mul(T, r.q, p);
140
+ // If our parameters are not fully reduced they may prematurely
141
+ // cause overflow/loss of precision after the multiplication below
142
+ assert(switch (@typeInfo(@TypeOf(p, q))) {
143
+ ComptimeInt, ComptimeFloat => comptime gcd(p, q),
144
+ else => 1,
145
+ } == 1);
204
146
 
205
- r.p = try std.math.add(T, n1, n2);
206
- r.q = d;
207
- }
208
- };
147
+ switch (@typeInfo(T)) {
148
+ Int => {
149
+ // Greedily attempt to multiply and if it fails, reduce and try again
150
+ multiplication(T, r, p, q) catch |err| switch (err) {
151
+ error.Overflow => {
152
+ r.reduce();
153
+ try multiplication(T, r, p, q);
154
+ },
155
+ else => unreachable,
156
+ };
157
+ },
158
+ Float => {
159
+ // Reduce in situations where we're likely to start losing precision
160
+ if (r.q > o or r.p > o) r.reduce();
161
+
162
+ r.p *= switch (@typeInfo(@TypeOf(p))) {
163
+ Float, ComptimeFloat => p,
164
+ else => @floatFromInt(p),
165
+ };
166
+ r.q *= switch (@typeInfo(@TypeOf(q))) {
167
+ Float, ComptimeFloat => q,
168
+ else => @floatFromInt(q),
169
+ };
170
+
171
+ // We should always be dealing with whole numbers
172
+ assert(std.math.modf(r.p).fpart == 0);
173
+ assert(std.math.modf(r.q).fpart == 0);
174
+ },
175
+ else => unreachable,
176
+ }
177
+ }
178
+
179
+ fn add_(comptime T: type, comptime o: comptime_int, r: anytype, s: anytype) !void {
180
+ switch (@typeInfo(T)) {
181
+ Int => {
182
+ if (r.q == s.q) {
183
+ r.p = std.math.add(T, r.p, s.p) catch |err| switch (err) {
184
+ error.Overflow => val: {
185
+ r.reduce();
186
+ s.reduce();
187
+ break :val try std.math.add(T, r.p, s.p);
188
+ },
189
+ else => unreachable,
190
+ };
191
+ } else {
192
+ addition(T, r, s.p, s.q) catch |err| switch (err) {
193
+ error.Overflow => {
194
+ r.reduce();
195
+ s.reduce();
196
+ try addition(T, r, s.p, s.q);
197
+ },
198
+ else => unreachable,
199
+ };
200
+ }
201
+ },
202
+ Float => {
203
+ if (r.q == s.q) {
204
+ if (r.p > o) r.reduce();
205
+ if (s.p > o) s.reduce();
206
+
207
+ r.p += s.p;
208
+ } else {
209
+ // Always reduce to minimize loss of precision from the multiplications
210
+ r.reduce();
211
+ s.reduce();
212
+
213
+ r.p = (r.p * s.q) + (r.q * s.p);
214
+ r.q *= s.q;
215
+ }
216
+
217
+ assert(std.math.modf(r.p).fpart == 0);
218
+ assert(std.math.modf(r.q).fpart == 0);
219
+ },
220
+ else => unreachable,
221
+ }
222
+ }
223
+
224
+ fn mul_(comptime T: type, comptime o: comptime_int, r: anytype, s: anytype) !void {
225
+ switch (@typeInfo(T)) {
226
+ Int => {
227
+ multiplication(T, r, s.p, s.q) catch |err| switch (err) {
228
+ error.Overflow => {
229
+ r.reduce();
230
+ s.reduce();
231
+ try multiplication(T, r, s.p, s.q);
232
+ },
233
+ else => unreachable,
234
+ };
235
+ },
236
+ Float => {
237
+ if (r.q > o or r.p > o) r.reduce();
238
+ if (s.q > o or s.p > o) s.reduce();
239
+
240
+ r.p *= s.p;
241
+ r.q *= s.q;
242
+
243
+ assert(std.math.modf(r.p).fpart == 0);
244
+ assert(std.math.modf(r.q).fpart == 0);
245
+ },
246
+ else => unreachable,
247
+ }
248
+ }
249
+
250
+ fn reduce_(r: anytype) void {
251
+ const d = gcd(r.p, r.q);
252
+ if (d == 1) return;
253
+
254
+ assert(@mod(r.p, d) == 0);
255
+ assert(@mod(r.q, d) == 0);
256
+
257
+ r.p /= d;
258
+ r.q /= d;
259
+
260
+ assert(r.p >= 1);
261
+ assert(r.q >= 1);
262
+ }
263
+
264
+ fn multiplication(comptime T: type, r: anytype, p: anytype, q: anytype) !void {
265
+ r.p = try std.math.mul(T, r.p, p);
266
+ r.q = try std.math.mul(T, r.q, q);
267
+ }
268
+
269
+ fn addition(comptime T: type, r: anytype, p: anytype, q: anytype) !void {
270
+ // (a/b) + (c/d) = (ad+bc)/(bd)
271
+ const d = try std.math.mul(T, r.q, q);
272
+ const n1 = try std.math.mul(T, r.p, q);
273
+ const n2 = try std.math.mul(T, r.q, p);
274
+
275
+ r.p = try std.math.add(T, n1, n2);
276
+ r.q = d;
209
277
  }
210
278
 
211
279
  fn gcd(p: anytype, q: anytype) @TypeOf(p, q) {
@@ -287,7 +355,7 @@ fn doTurn(r: anytype) !void {
287
355
  }
288
356
 
289
357
  test Rational {
290
- inline for (.{ u64, u128, f64 }) |t| {
358
+ inline for (.{ u64, u128, u256, f64 }) |t| {
291
359
  var r: Rational(t) = .{};
292
360
 
293
361
  var c: t = 128;
@@ -360,8 +428,15 @@ pub const BigRational = struct {
360
428
  }
361
429
 
362
430
  /// Adds two rationals.
363
- pub fn add(r: *BigRational, s: *const BigRational) !void {
364
- try r.val.add(r.val, s.val);
431
+ pub fn add(r: *BigRational, s: anytype) !void {
432
+ if (@hasField(@TypeOf(s.*), "val")) {
433
+ try r.val.add(r.val, s.val);
434
+ } else {
435
+ var t = try std.math.big.Rational.init(r.val.p.allocator);
436
+ defer t.deinit();
437
+ try t.setRatio(s.p, s.q);
438
+ try r.val.add(r.val, t);
439
+ }
365
440
  }
366
441
 
367
442
  /// Multiplies two rationals.
@@ -1,10 +1,8 @@
1
- const std = @import("std");
2
-
3
1
  const options = @import("options.zig");
2
+ const std = @import("std");
4
3
 
5
4
  const assert = std.debug.assert;
6
5
  const expectEqual = std.testing.expectEqual;
7
-
8
6
  const showdown = options.showdown;
9
7
 
10
8
  pub fn PRNG(comptime gen: comptime_int) type {
@@ -4,6 +4,7 @@ const expect = std.testing.expect;
4
4
  const expectEqual = std.testing.expectEqual;
5
5
 
6
6
  const Pointer = if (@hasField(std.builtin.Type, "pointer")) .pointer else .Pointer;
7
+ const One = if (@hasField(std.builtin.Type.Pointer.Size, "one")) .one else .One;
7
8
 
8
9
  pub fn PointerType(comptime P: type, comptime C: type) type {
9
10
  return if (@field(@typeInfo(P), @tagName(Pointer)).is_const) *const C else *C;
@@ -35,7 +36,7 @@ pub fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T,
35
36
  }
36
37
 
37
38
  fn BytesAsValueReturnType(comptime T: type, comptime B: type) type {
38
- return CopyPtrAttrs(B, .One, T);
39
+ return CopyPtrAttrs(B, One, T);
39
40
  }
40
41
 
41
42
  fn CopyPtrAttrs(
@@ -44,7 +45,7 @@ fn CopyPtrAttrs(
44
45
  comptime child: type,
45
46
  ) type {
46
47
  const info = @field(@typeInfo(source), @tagName(Pointer));
47
- const args = .{
48
+ const args: std.builtin.Type.Pointer = if (@hasField(std.builtin.Type.Pointer, "sentinel")) .{
48
49
  .size = size,
49
50
  .is_const = info.is_const,
50
51
  .is_volatile = info.is_volatile,
@@ -53,9 +54,23 @@ fn CopyPtrAttrs(
53
54
  .address_space = info.address_space,
54
55
  .child = child,
55
56
  .sentinel = null,
57
+ } else .{
58
+ .size = size,
59
+ .is_const = info.is_const,
60
+ .is_volatile = info.is_volatile,
61
+ .is_allowzero = info.is_allowzero,
62
+ .alignment = info.alignment,
63
+ .address_space = info.address_space,
64
+ .child = child,
65
+ .sentinel_ptr = null,
56
66
  };
57
67
  return @Type(if (@hasField(std.builtin.Type, "pointer"))
58
68
  .{ .pointer = args }
59
69
  else
60
70
  .{ .Pointer = args });
61
71
  }
72
+
73
+ // NOTE: std.meta.FieldType replaced by @FieldType in 0.14.0
74
+ pub fn FieldType(comptime T: type, comptime field: std.meta.FieldEnum(T)) type {
75
+ return std.meta.fieldInfo(T, field).type;
76
+ }