| 1 | module scheme |
| 2 | |
| 3 | import reader |
| 4 | |
| 5 | // The syntactic reader retains numeric spans. Validate their exact runtime |
| 6 | // values before publishing the one owned byte buffer; no second numeric parser. |
| 7 | fn read_bytevector_datum(doc &reader.Document, id reader.NodeId, path string) !Value { |
| 8 | count := doc.arena.bytevector_length(id)! |
| 9 | mut bytes := []u8{cap: count} |
| 10 | for index in 0 .. count { |
| 11 | item := doc.arena.bytevector_at(id, index)! |
| 12 | occurrence := doc.arena.node(item)! |
| 13 | canonical := doc.arena.node(doc.arena.canonical_id(item)!)! |
| 14 | if canonical.kind != .number { |
| 15 | return EvalError{ message: 'bytevector literal needs exact integers in 0..255', source_path: path, offset: occurrence.start, line: occurrence.line, column: occurrence.column } |
| 16 | } |
| 17 | number := parse_number(number_view(doc.arena.source_text(), canonical.start, canonical.end)) or { |
| 18 | return EvalError{ message: err.msg(), source_path: path, offset: occurrence.start, line: occurrence.line, column: occurrence.column } |
| 19 | } |
| 20 | byte := byte_value(number) or { |
| 21 | return EvalError{ message: err.msg(), source_path: path, offset: occurrence.start, line: occurrence.line, column: occurrence.column } |
| 22 | } |
| 23 | unsafe { (&u8(bytes.data))[index] = byte } |
| 24 | } |
| 25 | unsafe { bytes.len = count } |
| 26 | return owned_bytevector(bytes) |
| 27 | } |
| 28 | |