@@ -910,17 +910,23 @@ static ptrdiff_t compare_numbers(NUMBER n1, NUMBER n2)
910
910
911
911
static ptrdiff_t compare_objects (ANY ob1 , ANY ob2 )
912
912
{
913
- if (ob1 .type != ob2 .type ) return ob1 .type - ob2 .type ;
914
- switch (ob1 .type )
913
+ if (ob1 .type != ob2 .type ) return ( ptrdiff_t ) ob1 .type - ( ptrdiff_t ) ob2 .type ;
914
+ else switch (ob1 .type )
915
915
{
916
916
case number : return compare_numbers (unbox_NUMBER (ob1 ), unbox_NUMBER (ob2 ));
917
- case boolean : return unbox_BOOLEAN (ob1 ) - unbox_BOOLEAN (ob2 );
918
- case string : return strcmp (unbox_STRING (ob1 ), unbox_STRING (ob2 ));
917
+ case boolean : return ( ptrdiff_t ) unbox_BOOLEAN (ob1 ) - ( ptrdiff_t ) unbox_BOOLEAN (ob2 );
918
+ case string : return ( ptrdiff_t ) strcmp (unbox_STRING (ob1 ), unbox_STRING (ob2 ));
919
919
case symbol : return unbox_SYMBOL (ob1 ) - unbox_SYMBOL (ob2 );
920
920
case list : return compare_lists (unbox_LIST (ob1 ), unbox_LIST (ob2 ));
921
921
case block : return compare_blocks (unbox_BLOCK (ob1 ), unbox_BLOCK (ob2 ));
922
922
case box : return (char * )unbox_BOX (ob1 ) - (char * )unbox_BOX (ob2 );
923
923
default : return 0 ; // really shouldn't happen
924
+ /* NOTE
925
+ * The garbage collector *will* reorder objects in memory,
926
+ * which means that the relative addresses of blocks and boxes
927
+ * *will* change - which is why these can't be used to index tables
928
+ * for example.
929
+ */
924
930
}
925
931
}
926
932
@@ -2133,7 +2139,7 @@ static TABLE ___table (BLOCK expr)
2133
2139
stack .start = stack .top ;
2134
2140
// Eval expr
2135
2141
call_block (expr );
2136
- // Move to a list .
2142
+ // Move to a table .
2137
2143
TABLE d = NULL ;
2138
2144
size_t len = stack_length ();
2139
2145
if unlikely (len & 1 ) throw_error ("Table initialiser must be key-value pairs" );
@@ -2179,7 +2185,7 @@ static TABLE ___insert(ANY key, ANY value, TABLE d)
2179
2185
D -> right = d -> right ;
2180
2186
D -> left = ___insert (key , value , d -> left );
2181
2187
}
2182
- else if (diff > 0 )
2188
+ else // if (diff > 0)
2183
2189
{
2184
2190
D -> key = d -> key ;
2185
2191
D -> value = d -> value ;
0 commit comments