feat(lang,stdlib): 64-bit long type + 64-bit Hash variants (issue #17)
Some checks are pending
docs / build-and-deploy (push) Waiting to run
Some checks are pending
docs / build-and-deploy (push) Waiting to run
Add `long`, a 64-bit signed integer primitive (i64), threaded through codegen: llty; int<->long coercion (coerce_code/to_long) at let/assign/ return/call-args; i64 arithmetic + comparison promotion in emit_bin; unary negate/~; print via %lld and str()/interpolation via @fn_long_str. Editor vocabulary (syntax header, TextMate grammar, formatter, LSP) synced; check-vocabulary green. Numeric literals stay i32 — build large values by widening (documented on the type page). Complete the Hash.* namespace (issue #17) with both 32- and 64-bit algorithms: Hash.of/fnv1a/crc32/mix/combine (32-bit) and Hash.of64/fnv1a_64/mix64 (64-bit, returning long). Deterministic and C-free; CRC-32 (poly 0xEDB88320) and FNV vectors verified against reference implementations. Tests: selfhost/tests/{hash,long}.ludic. Docs: docs/language/hash/*, type-long.md. Seed reseeded; C-free bootstrap fixpoint holds; 23 selfhost + 45 regression + 29 tooling checks green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
a38195128f
commit
2002e977d9
27 changed files with 14007 additions and 12105 deletions
35
selfhost/tests/hash.ludic
Normal file
35
selfhost/tests/hash.ludic
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
program T {
|
||||
entry {
|
||||
# ---- Hash.* — deterministic non-cryptographic hashing ----
|
||||
# FNV-1a 32-bit (printed as a signed i32).
|
||||
print(Hash.fnv1a("")) # 0x811c9dc5 -> -2128831035
|
||||
print(Hash.fnv1a("a")) # -468965076
|
||||
print(Hash.fnv1a("grass_tile")) # 114400290
|
||||
print(Hash.of("grass_tile")) # Hash.of is the FNV-1a default -> same
|
||||
|
||||
# CRC-32 (IEEE) — known-answer check vectors.
|
||||
print(Hash.crc32("")) # 0
|
||||
print(Hash.crc32("123456789")) # 0xCBF43926 -> -873187034
|
||||
print(Hash.crc32("The quick brown fox jumps over the lazy dog")) # 1095738169
|
||||
|
||||
# fmix32 avalanche of a single int.
|
||||
print(Hash.mix(0)) # 0
|
||||
print(Hash.mix(1)) # 1364076727
|
||||
print(Hash.mix(-1)) # -2114883783
|
||||
|
||||
# combine folds several ints into one seed: deterministic + order-sensitive.
|
||||
print(Hash.combine(123, 456)) # -845898438
|
||||
print(Hash.combine(123, 456)) # same input -> same hash
|
||||
print(Hash.combine(1, 2, 3)) # -78065325
|
||||
print(Hash.combine(3, 2, 1)) # -78057399 (order matters)
|
||||
|
||||
# ---- 64-bit variants (return `long`) ----
|
||||
print(Hash.fnv1a_64("")) # 0xcbf29ce484222325 -> -3750763034362895579
|
||||
print(Hash.fnv1a_64("a")) # 0xaf63dc4c8601ec8c -> -5808556873153909620
|
||||
print(Hash.fnv1a_64("grass_tile")) # -4100651535478758590
|
||||
print(Hash.of64("grass_tile")) # Hash.of64 is the 64-bit default -> same
|
||||
print(Hash.mix64(0)) # 0
|
||||
print(Hash.mix64(1)) # -5451962507482445012
|
||||
print(Hash.mix64(-1)) # 7256831767414464289
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue