| 1 | module lexer |
| 2 | |
| 3 | #include "@VMODROOT/lexer/block_scan.h" |
| 4 | |
| 5 | fn C.vile_identifier_run(const_source &u8, length i64) i64 |
| 6 | |
| 7 | fn C.vile_block_non_ascii(const_source &u8) int |
| 8 | fn C.vile_block_string_special(const_source &u8) int |
| 9 | |
| 10 | @[inline] |
| 11 | fn block_non_ascii(source string, start int) bool { |
| 12 | // The private caller's loop established 0 <= start <= len - 16. C borrows |
| 13 | // the immutable source synchronously and retains no pointer or allocation. |
| 14 | return unsafe { C.vile_block_non_ascii(source.str + start) != 0 } |
| 15 | } |
| 16 | |
| 17 | @[inline] |
| 18 | fn block_string_special(source string, start int) bool { |
| 19 | // Identical bounded-load contract to block_non_ascii; no source mutation, |
| 20 | // ownership transfer, or pointer retention crosses this call. |
| 21 | return unsafe { C.vile_block_string_special(source.str + start) != 0 } |
| 22 | } |
| 23 | |
| 24 | @[inline] |
| 25 | fn native_identifier_end(source string, start int) int { |
| 26 | // The private caller supplies 0 <= start <= source.len. C borrows only the |
| 27 | // remaining bytes, retains no pointer, and returns a count within that range. |
| 28 | count := unsafe { C.vile_identifier_run(source.str + start, i64(source.len - start)) } |
| 29 | return start + int(count) |
| 30 | } |
| 31 | |
| 32 | fn C.vile_string_unicode_run(source &u8, length i64) i64 |
| 33 | fn C.vile_comment_unicode_run(source &u8, length i64) i64 |
| 34 | |
| 35 | @[inline] |
| 36 | fn native_string_unicode_end(source string, start int) int { |
| 37 | return start + int(unsafe { C.vile_string_unicode_run(source.str + start, i64(source.len - start)) }) |
| 38 | } |
| 39 | |
| 40 | @[inline] |
| 41 | fn native_comment_unicode_end(source string, start int) int { |
| 42 | return start + int(unsafe { C.vile_comment_unicode_run(source.str + start, i64(source.len - start)) }) |
| 43 | } |
| 44 | |
| 45 | fn C.vile_string_legacy_run(source &u8, length i64) i64 |
| 46 | |
| 47 | @[inline] |
| 48 | fn native_string_legacy_end(source string, start int) int { |
| 49 | // Private caller proves start in0..len. C borrows only remaining bytes. |
| 50 | return start + int(unsafe { C.vile_string_legacy_run(source.str + start, i64(source.len - start)) }) |
| 51 | } |
| 52 | |
| 53 | fn C.vile_comment_ascii_run(source &u8, length i64) i64 |
| 54 | |
| 55 | @[inline] |
| 56 | fn native_comment_ascii_end(source string, start int) int { |
| 57 | // The caller proves an ASCII source and a valid remaining span. The existing |
| 58 | // native loop specializes away Unicode candidates, without copies or views. |
| 59 | return start + int(unsafe { C.vile_comment_ascii_run(source.str + start, i64(source.len - start)) }) |
| 60 | } |
| 61 | |