diff --git a/main.py b/main.py index e1a91f1..98c28d4 100644 --- a/main.py +++ b/main.py @@ -4436,9 +4436,21 @@ class FunctionEmitter: escaped = path.replace("\\", "\\\\").replace('"', '\\"') self.text.append(f'%line {line}+{increment} "{escaped}"') - def set_location(self, loc: Optional[SourceLocation]) -> None: + def set_location(self, loc) -> None: if not self.debug_enabled: return + # Defensive: if loc is a Token, convert to SourceLocation, did not have a better solution, works for me + if loc is not None and not hasattr(loc, 'path') and hasattr(loc, 'line') and hasattr(loc, 'column'): + # Assume self has a reference to the parser or a location_for_token function + # If not, fallback to generic source path + try: + loc = self.location_for_token(loc) + except Exception: + from pathlib import Path + loc = type('SourceLocation', (), {})() + loc.path = Path('') + loc.line = getattr(loc, 'line', 0) + loc.column = getattr(loc, 'column', 0) if loc is None: if self._current_loc is None: return diff --git a/stdlib/utils.sl b/stdlib/utils.sl index f1ef28f..6ab9742 100644 --- a/stdlib/utils.sl +++ b/stdlib/utils.sl @@ -2,7 +2,7 @@ #strcmp [*, addr, len, addr | len] -> [* | bool] word strcmp >r nip r> for - 2dup c@ swap c@ != if drop drop 0 ret end + 2dup c@ swap c@ != if drop drop 0 rdrop ret end 1 + swap 1 + end drop drop 1