The INSERTIONSORT crash, all three rulings (FIX.org 2026-09-20): - (bytes s) allocates a writable copy through the allocator surface — context or (bytes s a), StorageExhausted with retry, a registry note in dev builds (flan_bytes_dup, lowered like vec-new). (bytes-view s) is the old zero-cost reinterpret, renamed, read-only by convention; every in-repo reader swept over to it. (string b) unchanged. - String constants were already read-only on both backends at -O0; now pinned — bytes-copy.flan rows on LLVM/-O0/--x86, and dies_segv rows asserting the write-through-view trap on both backends. - A dev build installs a SIGSEGV/SIGBUS handler by the same dev-only constructor slot that arms the registry: one line naming the address and the innermost frame, then the trap-hook park — stopped, not dead, the daemon serving. No agent: message and re-raise. Release builds untouched. Pinned by trap_park over dev-segv.flan.
96 lines
5.2 KiB
Plaintext
96 lines
5.2 KiB
Plaintext
;;;; index-of-bytes, trim, the two byte classes, and parse-f64.
|
|
;;;;
|
|
;;;; The search cases are the ones a naive loop gets wrong rather than the
|
|
;;;; ones it gets right: a needle that matches only at the very end, one that
|
|
;;;; matches only at index 0, one whose first byte occurs repeatedly before
|
|
;;;; the real match ("aab" in "aaab"), a needle longer than the haystack
|
|
;;;; (which must answer None and must not trap building the window), the
|
|
;;;; empty needle, and a near-miss that shares every byte but the last.
|
|
;;;;
|
|
;;;; The parse-f64 cases are every shape strtod answers a plausible number
|
|
;;;; for and a caller cannot tell from a real one: "", "abc", "1x", ".",
|
|
;;;; "1e", " 1", "0x10" and "nan". Each must be None.
|
|
|
|
(defn show-idx [o (Option i32)] ()
|
|
(print (match o (Some i) i None -1))
|
|
(print " "))
|
|
|
|
(defn show-bool [b bool] ()
|
|
(print (if b "t" "f")))
|
|
|
|
;; Brackets around the result so an empty trim is visible as [] rather than
|
|
;; as nothing at all — the all-whitespace case is otherwise indistinguishable
|
|
;; from a trim that printed the wrong slice of length zero.
|
|
(defn show-trim [s string] ()
|
|
(print "[")
|
|
(print (trim (bytes-view s)))
|
|
(print "]"))
|
|
|
|
(defn main [] i32
|
|
(show-idx (index-of-bytes (bytes-view "hello world") (bytes-view "world"))) ; 6, at the end
|
|
(show-idx (index-of-bytes (bytes-view "hello world") (bytes-view "hello"))) ; 0, at the start
|
|
(show-idx (index-of-bytes (bytes-view "hello world") (bytes-view "o w"))) ; 4, in the middle
|
|
(show-idx (index-of-bytes (bytes-view "banana") (bytes-view "na"))) ; 2, first of two
|
|
(show-idx (index-of-bytes (bytes-view "aaab") (bytes-view "aab"))) ; 1, after false starts
|
|
(println "")
|
|
(show-idx (index-of-bytes (bytes-view "hello") (bytes-view "hellp"))) ; -1, last byte differs
|
|
(show-idx (index-of-bytes (bytes-view "hi") (bytes-view "hiya"))) ; -1, longer, no trap
|
|
(show-idx (index-of-bytes (bytes-view "") (bytes-view "a"))) ; -1, empty haystack
|
|
(show-idx (index-of-bytes (bytes-view "hello") (bytes-view ""))) ; 0, empty needle
|
|
(show-idx (index-of-bytes (bytes-view "") (bytes-view ""))) ; 0, both empty
|
|
(show-idx (index-of-bytes (bytes-view "hello") (bytes-view "hello"))) ; 0, whole string
|
|
(println "")
|
|
|
|
(show-trim " hi ") ; [hi]
|
|
(show-trim "hi") ; [hi] nothing to remove
|
|
(show-trim "\thi\n") ; [hi] tab and newline count
|
|
(show-trim " ") ; [] all whitespace, must not run backwards
|
|
(show-trim "") ; []
|
|
(show-trim " a b ") ; [a b] the inner space survives
|
|
(show-trim " x") ; [x] one-sided
|
|
(show-trim "x ") ; [x]
|
|
(println "")
|
|
|
|
(show-bool (digit? \0)) (show-bool (digit? \9)) (show-bool (digit? \/))
|
|
(show-bool (digit? \:)) (show-bool (digit? \a))
|
|
(println "")
|
|
(show-bool (space? \space)) (show-bool (space? \tab))
|
|
(show-bool (space? \newline)) (show-bool (space? \return))
|
|
(show-bool (space? \a)) (show-bool (space? \0))
|
|
(println "")
|
|
|
|
;; Accepted. The last is the round trip through %g that proves the value and
|
|
;; not merely the acceptance is right.
|
|
(print (match (parse-f64 (bytes-view "0")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "3.5")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "-3.5")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "+0.25")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "1e3")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "1.5E-2")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "12")) (Some v) v None -999.0))
|
|
(println "")
|
|
;; Refused. Every one of these is a number out of strtod, which is the point.
|
|
(print (match (parse-f64 (bytes-view "")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "abc")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "1x")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view ".")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "1e")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "1e+")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view " 1")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "1 ")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "0x10")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "nan")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view "+")) (Some v) v None -999.0))
|
|
(println "")
|
|
;; A trailing dot with no fraction is a C float literal and is accepted; a
|
|
;; leading one is too. Both are here because they are the boundary the
|
|
;; digit counter, not the position, decides.
|
|
(print (match (parse-f64 (bytes-view "1.")) (Some v) v None -999.0)) (print " ")
|
|
(print (match (parse-f64 (bytes-view ".5")) (Some v) v None -999.0))
|
|
(println "")
|
|
|
|
;; Parsing a trimmed field, which is why both exist.
|
|
(print (match (parse-f64 (trim (bytes-view " 2.25 "))) (Some v) v None -999.0))
|
|
(println "")
|
|
0)
|