From f411e2d569770f7e08ab97a3693ba5332d0c94a1 Mon Sep 17 00:00:00 2001 From: Ian Piumarta Date: Sat, 1 Feb 2025 10:16:10 +0900 Subject: [PATCH] be more relaxed about pointer comparisons --- main.leg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.leg b/main.leg index dabe814..dbca0fd 100644 --- a/main.leg +++ b/main.leg @@ -1,6 +1,6 @@ # main.leg -- C parser + interpreter # -# Last edited: 2025-02-01 10:02:43 by piumarta on xubuntu +# Last edited: 2025-02-01 10:15:19 by piumarta on xubuntu %{ ; @@ -3319,12 +3319,12 @@ int compare(oop a, oop b) if (a == b) return 0; type_t ta = getType(a), tb = getType(b); if (ta == tb) { - switch (getType(a)) { + switch (ta) { case Integer: return CMP(_integerValue(a), _integerValue(b)); case Float: return CMP( _floatValue(a), _floatValue(b)); case Pointer: { oop ba = get(a, Pointer,base), bb = get(b, Pointer,base); - if (ba != bb) fatal("comparing pointers to different objects"); + if (ba != bb) return CMP((intptr_t)ba, (intptr_t)bb); int oa = get(a, Pointer,offset), ob = get(b, Pointer,offset); return CMP(oa, ob); }