- Float full stack: literals (fraction/exponent; `0..10` still a range), f64
opcodes 34-41, @table column, WAL bit-exact replay, json fractions in and
shortest-round-trip out. IEEE-quiet — FDIV never traps where DIV does.
- Bytes: a wo_str with its own class id, so alloc/free/copy are shared but no
Text builtin accepts one; len/at/slice/eq/concat, base64 both ways, json
boundary as base64; TEXT_COPY preserves the kind.
- No implicit Int/Float mixing (WO-E201 in the typechecker, not the emitter,
which picks the opcode from one side and would misread the other).
- One IEEE deviation: float_cmp total order (NaN last, -0.0 == +0.0) for
indexes and order-by, keys canonicalized to match. `?Float` nil is a
reserved quiet NaN — the zero word is +0.0, WO_NIL_SCALAR's bits are -2.0.
- Renderer prefers fixed over exponential in 1e-6..1e21: pure shortest makes
a price of 900.0 read `9e+02`. One renderer for interp/json/float_to_text.
- Fixed en route: lexer double-counted the leading digit; is_scalar_shaped
took Float/Bytes as Int-shaped; Bytes ownership needed a shared heap-scalar
predicate or temps never dropped; order-by bit-compared negatives backwards.
- Iteration 17: `kind = "library"` (absent = program; bad value = WO-E109),
entry-less check mode retiring the `--emit` workaround, Go's `internal/` as
WO-E108 at the consumer's `use`. Driver-only; VM/.wob/GC untouched.
- Framework reorg: internal/{parse,serve}.wo; http/form.wo split out to keep
media_type/form_values public (parse.wo had grown public surface).
- Docs: link audit (97 -> 88 broken, conflict markers resolved, 2 duplicate
stories removed), 00-code-review verified 26/27, iterations re-sequenced.
- Also carries the pre-staged pub(read)/using/#if work from the index.
- Gates: corpus 103/0, test_wal 156/0, web-app 26/0, oop-accept ALL MET.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
65 lines
2.1 KiB
Text
65 lines
2.1 KiB
Text
-- Iteration 19, the forcing function: `{"price": 9.99}` used to fail the
|
|
-- whole checked decode because the language had no Float. Now a Float field
|
|
-- decodes fractions and exponents, encodes shortest-round-trip, and an Int
|
|
-- field's strictness is UNCHANGED (a fraction there is still malformed).
|
|
-- A ?Float carries its own nil sentinel, and a Bytes field crosses the JSON
|
|
-- boundary as base64.
|
|
use json
|
|
|
|
class Item {
|
|
name: Text
|
|
price: Float
|
|
discount: ?Float
|
|
blob: Bytes
|
|
}
|
|
|
|
class Counted {
|
|
n: Int
|
|
}
|
|
|
|
fn main() -> Int {
|
|
-- encode: shortest form, a nil ?Float is null, Bytes is base64
|
|
print(json.encode(Item {
|
|
name: "mug",
|
|
price: 9.99,
|
|
discount: nil,
|
|
blob: bytes_of_text("hi")
|
|
}))
|
|
|
|
-- decode a fraction into a Float field: the hole this iteration closes
|
|
let a = json.decode("{\"name\":\"mug\",\"price\":9.99,\"discount\":0.25,\"blob\":\"aGk=\"}") as Item
|
|
if a != nil {
|
|
print("${a.price}")
|
|
let d = a.discount
|
|
if d != nil { print("${d}") }
|
|
print(text_of_bytes(a.blob))
|
|
print(json.encode(a))
|
|
}
|
|
|
|
-- exponent and integer-shaped forms both land in a Float field
|
|
let b = json.decode("{\"name\":\"x\",\"price\":2.5e-3,\"discount\":null,\"blob\":\"\"}") as Item
|
|
if b != nil {
|
|
print("${b.price} ${bytes_len(b.blob)}")
|
|
-- a JSON null in a ?Float field must read back as nil, which is the whole
|
|
-- job of the reserved-NaN sentinel: the zero word would be +0.0
|
|
let bd = b.discount
|
|
if bd == nil { print("null discount read back as nil") }
|
|
}
|
|
let c = json.decode("{\"name\":\"x\",\"price\":42,\"discount\":null,\"blob\":\"\"}") as Item
|
|
if c != nil { print("${c.price}") }
|
|
|
|
-- Int strictness is untouched: a fraction in an Int field is still
|
|
-- malformed, so the checked decode fails whole
|
|
let bad = json.decode("{\"n\":3.7}") as Counted
|
|
if bad == nil { print("int fraction still rejected") }
|
|
|
|
-- a non-finite Float has no JSON literal, so it encodes as null rather
|
|
-- than as invalid JSON
|
|
print(json.encode(Item {
|
|
name: "inf",
|
|
price: 1.0 / 0.0,
|
|
discount: 0.0 / 0.0,
|
|
blob: bytes_of_text("")
|
|
}))
|
|
return 0
|
|
}
|