Skip to content

Commit 2981285

Browse files
committed
feat(const): ADR-0174 D7a — scalar constants sweep (Math/TAU, BYTES/SIZE, File separators, Pattern flags)
Smell-audited: 1: StaticFieldValue gains a generic comptime-const .string variant (File/separator) instead of a one-off singleton — the generic arm is the finished form; no other smell. - Math/TAU (clj-oracle 6.283185307179586); Long/Integer BYTES+SIZE; Double MIN_NORMAL+BYTES+SIZE; File separator "/" / separatorChar / pathSeparator ":" / pathSeparatorChar (POSIX — the shipped targets); Pattern's 9 JVM flag bit-mask constants (compile-with-flags lands in D7b with the inline-subset mapping).
1 parent 37d9ee9 commit 2981285

8 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/eval/analyzer/analyzer.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ fn staticFieldValue(rt: *Runtime, sf: *const @import("../../runtime/type_descrip
396396
.float => |f| Value.initFloat(f),
397397
.bool => |b| Value.initBoolean(b),
398398
.char => |c| Value.initChar(c),
399+
.string => |s| try string_collection.alloc(rt, s),
399400
.singleton => |s| switch (s) {
400401
.empty_queue => try @import("../../runtime/collection/persistent_queue.zig").emptyQueue(rt),
401402
.locale_us => try @import("../../runtime/locale.zig").singleton(rt, .us),

src/runtime/java/io/File.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,23 @@ pub const ___HOST_EXTENSION: host_api.Extension = .{
373373
.init = &initFile,
374374
};
375375

376+
/// Path separators (ADR-0174 D7). POSIX values — cljw ships Mac/Linux;
377+
/// a Windows build would flip these with the target (same source of truth
378+
/// as System.zig's staticProperty table).
379+
const file_static_fields = [_]type_descriptor.TypeDescriptor.StaticField{
380+
.{ .name = "separator", .value = .{ .string = "/" } },
381+
.{ .name = "separatorChar", .value = .{ .char = '/' } },
382+
.{ .name = "pathSeparator", .value = .{ .string = ":" } },
383+
.{ .name = "pathSeparatorChar", .value = .{ .char = ':' } },
384+
};
385+
376386
var descriptor: type_descriptor.TypeDescriptor = .{
377387
.fqcn = "java.io.File",
378388
.kind = .native,
379389
.field_layout = null,
380390
.protocol_impls = &.{},
381391
.method_table = &.{},
392+
.static_fields = &file_static_fields,
382393
.parent = null,
383394
.meta = .nil_val,
384395
};

src/runtime/java/lang/Double.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ const double_static_fields = [_]type_descriptor.TypeDescriptor.StaticField{
224224
// Unbiased binary exponent bounds of a normal double (int constants).
225225
.{ .name = "MAX_EXPONENT", .value = .{ .int = 1023 } },
226226
.{ .name = "MIN_EXPONENT", .value = .{ .int = -1022 } },
227+
.{ .name = "MIN_NORMAL", .value = .{ .float = std.math.floatMin(f64) } },
228+
.{ .name = "BYTES", .value = .{ .int = 8 } },
229+
.{ .name = "SIZE", .value = .{ .int = 64 } },
227230
};
228231

229232
var descriptor: type_descriptor.TypeDescriptor = .{

src/runtime/java/lang/Integer.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ pub const ___HOST_EXTENSION: host_api.Extension = .{
360360
const integer_static_fields = [_]type_descriptor.TypeDescriptor.StaticField{
361361
.{ .name = "MAX_VALUE", .value = .{ .int = 2147483647 } },
362362
.{ .name = "MIN_VALUE", .value = .{ .int = -2147483648 } },
363+
.{ .name = "BYTES", .value = .{ .int = 4 } },
364+
.{ .name = "SIZE", .value = .{ .int = 32 } },
363365
};
364366

365367
var descriptor: type_descriptor.TypeDescriptor = .{

src/runtime/java/lang/Long.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ pub const ___HOST_EXTENSION: host_api.Extension = .{
344344
const long_static_fields = [_]type_descriptor.TypeDescriptor.StaticField{
345345
.{ .name = "MAX_VALUE", .value = .{ .int = std.math.maxInt(i64) } },
346346
.{ .name = "MIN_VALUE", .value = .{ .int = std.math.minInt(i64) } },
347+
.{ .name = "BYTES", .value = .{ .int = 8 } },
348+
.{ .name = "SIZE", .value = .{ .int = 64 } },
347349
};
348350

349351
var descriptor: type_descriptor.TypeDescriptor = .{

src/runtime/java/lang/Math.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ pub const ___HOST_EXTENSION: host_api.Extension = .{
612612
const math_static_fields = [_]type_descriptor.TypeDescriptor.StaticField{
613613
.{ .name = "PI", .value = .{ .float = std.math.pi } },
614614
.{ .name = "E", .value = .{ .float = std.math.e } },
615+
.{ .name = "TAU", .value = .{ .float = std.math.tau } },
615616
};
616617

617618
var descriptor: type_descriptor.TypeDescriptor = .{

src/runtime/java/util/regex/Pattern.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,30 @@ pub const ___HOST_EXTENSION: host_api.Extension = .{
211211
.init = &initPattern,
212212
};
213213

214+
/// The JVM Pattern flag constants (ADR-0174 D7). Values are the JVM's
215+
/// exact bit masks. `Pattern/compile` (2-arg) honours the inline-expressible
216+
/// subset {CASE_INSENSITIVE, MULTILINE, DOTALL, COMMENTS}; the others raise
217+
/// (cljw's regex engine has no canonical-equivalence / explicit-unicode-case
218+
/// modes — an honest error beats a silently-ignored flag).
219+
const pattern_static_fields = [_]type_descriptor.TypeDescriptor.StaticField{
220+
.{ .name = "UNIX_LINES", .value = .{ .int = 0x01 } },
221+
.{ .name = "CASE_INSENSITIVE", .value = .{ .int = 0x02 } },
222+
.{ .name = "COMMENTS", .value = .{ .int = 0x04 } },
223+
.{ .name = "MULTILINE", .value = .{ .int = 0x08 } },
224+
.{ .name = "LITERAL", .value = .{ .int = 0x10 } },
225+
.{ .name = "DOTALL", .value = .{ .int = 0x20 } },
226+
.{ .name = "UNICODE_CASE", .value = .{ .int = 0x40 } },
227+
.{ .name = "CANON_EQ", .value = .{ .int = 0x80 } },
228+
.{ .name = "UNICODE_CHARACTER_CLASS", .value = .{ .int = 0x100 } },
229+
};
230+
214231
var descriptor: type_descriptor.TypeDescriptor = .{
215232
.fqcn = "java.util.regex.Pattern",
216233
.kind = .native,
217234
.field_layout = null,
218235
.protocol_impls = &.{},
219236
.method_table = &.{},
237+
.static_fields = &pattern_static_fields,
220238
.parent = null,
221239
.meta = .nil_val,
222240
};

src/runtime/type_descriptor.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ pub const TypeDescriptor = struct {
221221
float: f64,
222222
bool: bool, // Boolean/TRUE, Boolean/FALSE (ADR-0061 amendment)
223223
char: u21, // Character/MIN_VALUE, MAX_VALUE, the surrogate bounds
224+
/// A comptime-const string constant (File/separator, …) — lifted to a
225+
/// cljw String Value at analyze time (ADR-0174 D7).
226+
string: []const u8,
224227
singleton: Singleton,
225228
/// A host-enum constant (ADR-0161 / D-510): `enum_idx` is `@intFromEnum`
226229
/// of `host_enum.Idx` (RoundingMode/ChronoUnit/DayOfWeek/Month), `ordinal`

0 commit comments

Comments
 (0)