Resolves issue 0090. The `{}` integer formatter mis-rendered both ends of
the 64-bit range:
- `int_to_string` computed the magnitude as `0 - n`, which overflows for
`s64::MIN` (its magnitude is unrepresentable as a positive s64) — the
value stayed negative, the digit loop ran zero times, so only `-`
printed. It now extracts digits straight from `n` (per-digit
`|n % 10|`, `n` truncating toward zero), never negating MIN.
- `any_to_string`'s `case int:` formatted every integer as s64, so a u64
all-ones value printed as `-1`. There was no `uint` type-category to
distinguish signedness. Added an additive `type_is_unsigned(T)`
reflection builtin (static fold + dynamic interp/LLVM paths, mirroring
`type_name`), backed by the new `TypeTable.isUnsignedInt` predicate, and
a `uint_to_string` formatter (unsigned decimal via long-division over
four 16-bit limbs). `case int:` routes through `type_is_unsigned(type)`.
The 16-bit-limb split is factored into a shared `decompose_u16x4`, now
reused by `int_to_hex_string` (no second unsigned-math routine).
Regression: examples/0046-basic-int-formatter-extremes pins both extremes
plus a width spread; unit tests cover `isUnsignedInt`. Docs (specs.md
representation note, readme std API) updated for unsigned/extreme `{}`
behavior. IR snapshots refreshed for the two new std functions.
187 lines
5.2 KiB
Plaintext
187 lines
5.2 KiB
Plaintext
|
|
@__sx_default_context = internal global { { ptr, ptr, ptr }, ptr } { { ptr, ptr, ptr } { ptr null, ptr @__thunk_CAllocator_Allocator_alloc, ptr @__thunk_CAllocator_Allocator_dealloc }, ptr null }
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @out(ptr) #0
|
|
|
|
declare ptr @malloc(i64)
|
|
|
|
declare void @free(ptr)
|
|
|
|
declare ptr @memcpy(ptr, ptr, i64)
|
|
|
|
declare ptr @memset(ptr, i32, i64)
|
|
|
|
; Function Attrs: nounwind
|
|
define internal ptr @CAllocator.alloc(ptr %0, ptr %1, i64 %2) #0 {
|
|
entry:
|
|
%alloca = alloca ptr, align 8
|
|
store ptr %1, ptr %alloca, align 8
|
|
%allocaN = alloca i64, align 8
|
|
store i64 %2, ptr %allocaN, align 8
|
|
%load = load i64, ptr %allocaN, align 8
|
|
%call = call ptr @malloc(i64 %load)
|
|
ret ptr %call
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define internal void @CAllocator.dealloc(ptr %0, ptr %1, ptr %2) #0 {
|
|
entry:
|
|
%alloca = alloca ptr, align 8
|
|
store ptr %1, ptr %alloca, align 8
|
|
%allocaN = alloca ptr, align 8
|
|
store ptr %2, ptr %allocaN, align 8
|
|
%load = load ptr, ptr %allocaN, align 8
|
|
call void @free(ptr %load)
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
declare i64 @GPA.init(ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @GPA.alloc(ptr, ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @GPA.dealloc(ptr, ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @Arena.add_chunk(ptr, ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @Arena.init(ptr sret({ ptr, i64, { ptr, ptr, ptr } }), ptr, ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @Arena.reset(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @Arena.deinit(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @Arena.alloc(ptr, ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @Arena.dealloc(ptr, ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @BufAlloc.init(ptr, ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @BufAlloc.reset(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @BufAlloc.alloc(ptr, ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @BufAlloc.dealloc(ptr, ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @TrackingAllocator.init(ptr sret({ { ptr, ptr, ptr }, i64, i64, i64 }), ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare i64 @TrackingAllocator.leak_count(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @TrackingAllocator.report(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @TrackingAllocator.alloc(ptr, ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @TrackingAllocator.dealloc(ptr, ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @cstring(ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @int_to_string(ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @uint_to_string(ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @bool_to_string(ptr, i1) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @float_to_string(ptr, double) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare void @hex_group(ptr, ptr, i64, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare [4 x i64] @decompose_u16x4(ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @int_to_hex_string(ptr, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @concat(ptr, ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @substr(ptr, ptr, i64, i64) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @xml_escape(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @path_join(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @any_to_string(ptr, [2 x i64]) #0
|
|
|
|
; Function Attrs: nounwind
|
|
declare ptr @build_format(ptr, ptr) #0
|
|
|
|
; Function Attrs: nounwind
|
|
define internal i64 @accept_c(ptr %0) #0 {
|
|
entry:
|
|
%byval.load = load { i64, i64, i64, i64 }, ptr %0, align 8
|
|
%alloca = alloca { i64, i64, i64, i64 }, align 8
|
|
store { i64, i64, i64, i64 } %byval.load, ptr %alloca, align 8
|
|
%load = load { i64, i64, i64, i64 }, ptr %alloca, align 8
|
|
%sg = extractvalue { i64, i64, i64, i64 } %load, 0
|
|
%loadN = load { i64, i64, i64, i64 }, ptr %alloca, align 8
|
|
%sgN = extractvalue { i64, i64, i64, i64 } %loadN, 1
|
|
%add = add i64 %sg, %sgN
|
|
%loadN = load { i64, i64, i64, i64 }, ptr %alloca, align 8
|
|
%sgN = extractvalue { i64, i64, i64, i64 } %loadN, 2
|
|
%addN = add i64 %add, %sgN
|
|
%loadN = load { i64, i64, i64, i64 }, ptr %alloca, align 8
|
|
%sgN = extractvalue { i64, i64, i64, i64 } %loadN, 3
|
|
%addN = add i64 %addN, %sgN
|
|
ret i64 %addN
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define i32 @main() #0 {
|
|
entry:
|
|
%alloca = alloca { i64, i64, i64, i64 }, align 8
|
|
store { i64, i64, i64, i64 } { i64 1, i64 10, i64 100, i64 1000 }, ptr %alloca, align 8
|
|
%load = load { i64, i64, i64, i64 }, ptr %alloca, align 8
|
|
%byval.tmp = alloca { i64, i64, i64, i64 }, align 8
|
|
store { i64, i64, i64, i64 } %load, ptr %byval.tmp, align 8
|
|
%call = call i64 @accept_c(ptr %byval.tmp)
|
|
%icmp = icmp ne i64 %call, 1111
|
|
br i1 %icmp, label %if.then.0, label %if.merge.1
|
|
|
|
if.then.0: ; preds = %entry
|
|
ret i32 1
|
|
|
|
if.merge.1: ; preds = %entry
|
|
ret i32 0
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define internal ptr @__thunk_CAllocator_Allocator_alloc(ptr %0, ptr %1, i64 %2) #0 {
|
|
entry:
|
|
%call = call ptr @CAllocator.alloc(ptr %0, ptr %1, i64 %2)
|
|
ret ptr %call
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define internal void @__thunk_CAllocator_Allocator_dealloc(ptr %0, ptr %1, ptr %2) #0 {
|
|
entry:
|
|
call void @CAllocator.dealloc(ptr %0, ptr %1, ptr %2)
|
|
ret void
|
|
}
|