unhardcode 'puts' kinda

This commit is contained in:
IgorCielniak
2025-12-14 18:44:24 +01:00
parent 1dd1ba377b
commit 6efd7c4e19
2 changed files with 9 additions and 1 deletions

BIN
a.out

Binary file not shown.

10
main.py
View File

@@ -871,7 +871,15 @@ class CompileTimeVM:
raise ParseError(f"word '{word.name}' has no asm body")
asm_body = definition.body.strip("\n")
string_mode = word.name == "puts"
# Determine whether this asm uses string semantics (len,addr pairs)
# by scanning the asm body for string-related labels. This avoids
# hardcoding a specific word name (like 'puts') and lets any word
# that expects (len, addr) work the same way.
string_mode = False
if asm_body:
lowered = asm_body.lower()
if any(k in lowered for k in ("data_start", "data_end", "print_buf", "print_buf_end")):
string_mode = True
handles = self._handles