Phase 7i: byte indexing p[i] / p[i] = v (retire peek8/poke8)
Raw byte access is now indexing, not C-style peek/poke: peek8(src, i) -> src[i] (reads a byte, widened to int) poke8(out, j, r) -> out[j] = r (narrows the int to a byte) E_INDEX on a non-slice pointer/string lowers to a `getelementptr i8` + load/zext (read) or trunc/store (write) — byte-identical to the old peek8/poke8, so the migration reproduces the compiler exactly. A "byte" element type (llty i8) drives the widen/narrow. The compiler's own byte work now reads naturally, e.g. `is_slice_ty` is `t[0] == 91 and t[1] == 93`. Subtlety fixed on the way: g_addr_ty (the out-param carrying the indexed element type) must be set AFTER evaluating the index expression, since a member/index in the index would otherwise clobber it — doing it early made a byte read load a full pointer from a byte address and crash the self-compile. Two reseeds: add byte-index support keeping peek8/poke8, then migrate 148 call sites and delete the intrinsics (+ the now-dead emit_gep_i8). Vocabulary drops peek8/poke8. Reseeded (22604 lines); C-free fixpoint holds; goldens identical; 18/18; vocab clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
3aaf983cf5
commit
feb3a71e56
25 changed files with 3309 additions and 3388 deletions
|
|
@ -66,7 +66,7 @@ object LudicVocabulary {
|
|||
"ui_focused", "ui_visible", "key", "reg", "set_reg", "self", "save", "load",
|
||||
"status", "print", "str", "quit",
|
||||
// compiler intrinsics: the floor the Ludic-written runtime stands on
|
||||
"mem_alloc", "mem_realloc", "mem_free", "mem_copy", "mem_set", "peek8", "poke8", "peek32",
|
||||
"mem_alloc", "mem_realloc", "mem_free", "mem_copy", "mem_set", "peek32",
|
||||
"os_argc", "os_arg", "file_stderr", "file_stdout",
|
||||
"poke32", "peekp", "pokep", "peekf", "pokef", "ptr_add",
|
||||
"as_fixed", "as_int", "file_open", "file_read", "file_write",
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@
|
|||
{
|
||||
"comment": "compiler intrinsics — these lower straight to libc or the OS",
|
||||
"name": "support.function.intrinsic.ludic",
|
||||
"match": "\\b(mem_alloc|mem_realloc|mem_free|mem_copy|mem_set|peek8|poke8|peek32|poke32|peekp|pokep|peekf|pokef|ptr_add|as_fixed|as_int|file_open|file_read|file_write|file_seek|file_tell|file_close|read_byte|write_byte|str_len|os_exit|os_time|os_argc|os_arg|file_stderr|file_stdout|is_windowed|game_title|win_open|win_poll|win_present|win_running|win_close)\\b(?=\\s*\\()"
|
||||
"match": "\\b(mem_alloc|mem_realloc|mem_free|mem_copy|mem_set|peek32|poke32|peekp|pokep|peekf|pokef|ptr_add|as_fixed|as_int|file_open|file_read|file_write|file_seek|file_tell|file_close|read_byte|write_byte|str_len|os_exit|os_time|os_argc|os_arg|file_stderr|file_stdout|is_windowed|game_title|win_open|win_poll|win_present|win_running|win_close)\\b(?=\\s*\\()"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@
|
|||
{
|
||||
"comment": "compiler intrinsics — these lower straight to libc or the OS",
|
||||
"name": "support.function.intrinsic.ludic",
|
||||
"match": "\\b(mem_alloc|mem_realloc|mem_free|mem_copy|mem_set|peek8|poke8|peek32|poke32|peekp|pokep|peekf|pokef|ptr_add|as_fixed|as_int|file_open|file_read|file_write|file_seek|file_tell|file_close|read_byte|write_byte|str_len|os_exit|os_time|os_argc|os_arg|file_stderr|file_stdout|is_windowed|game_title|win_open|win_poll|win_present|win_running|win_close)\\b(?=\\s*\\()"
|
||||
"match": "\\b(mem_alloc|mem_realloc|mem_free|mem_copy|mem_set|peek32|poke32|peekp|pokep|peekf|pokef|ptr_add|as_fixed|as_int|file_open|file_read|file_write|file_seek|file_tell|file_close|read_byte|write_byte|str_len|os_exit|os_time|os_argc|os_arg|file_stderr|file_stdout|is_windowed|game_title|win_open|win_poll|win_present|win_running|win_close)\\b(?=\\s*\\()"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -154,8 +154,6 @@ static const LBuiltin LUDIC_INTRINSICS[] = {
|
|||
{"mem_free","mem_free(p: ptr)","Release an allocation."},
|
||||
{"mem_copy","mem_copy(dst: ptr, src: ptr, n: int)","memcpy."},
|
||||
{"mem_set","mem_set(p: ptr, byte: int, n: int)","memset."},
|
||||
{"peek8","peek8(p: ptr, off: int) -> int","Read one byte."},
|
||||
{"poke8","poke8(p: ptr, off: int, v: int)","Write one byte."},
|
||||
{"peek32","peek32(p: ptr, off: int) -> int","Read a 32-bit word."},
|
||||
{"poke32","poke32(p: ptr, off: int, v: int)","Write a 32-bit word."},
|
||||
{"peekp","peekp(p: ptr, off: int) -> ptr","Read a pointer-sized word."},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue