File: dict.inl

package info (click to toggle)
gnu-smalltalk 3.2.4-2.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,688 kB
  • ctags: 14,104
  • sloc: ansic: 87,424; sh: 22,729; asm: 8,465; perl: 4,513; cpp: 3,548; xml: 1,669; awk: 1,581; yacc: 1,357; makefile: 1,237; lisp: 855; lex: 843; sed: 258; objc: 124
file content (1603 lines) | stat: -rw-r--r-- 44,987 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
/******************************** -*- C -*- ****************************
 *
 *	Dictionary Support Module Inlines.
 *
 *
 ***********************************************************************/

/***********************************************************************
 *
 * Copyright 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009
 * Free Software Foundation, Inc.
 * Written by Steve Byrne.
 *
 * This file is part of GNU Smalltalk.
 *
 * GNU Smalltalk is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2, or (at your option) any later 
 * version.
 * 
 * Linking GNU Smalltalk statically or dynamically with other modules is
 * making a combined work based on GNU Smalltalk.  Thus, the terms and
 * conditions of the GNU General Public License cover the whole
 * combination.
 *
 * In addition, as a special exception, the Free Software Foundation
 * give you permission to combine GNU Smalltalk with free software
 * programs or libraries that are released under the GNU LGPL and with
 * independent programs running under the GNU Smalltalk virtual machine.
 *
 * You may copy and distribute such a system following the terms of the
 * GNU GPL for GNU Smalltalk and the licenses of the other code
 * concerned, provided that you include the source code of that other
 * code when and as the GNU GPL requires distribution of source code.
 *
 * Note that people who make modified versions of GNU Smalltalk are not
 * obligated to grant this special exception for their modified
 * versions; it is their choice whether to do so.  The GNU General
 * Public License gives permission to release a modified version without
 * this exception; this exception also makes it possible to release a
 * modified version which carries forward this exception.
 *
 * GNU Smalltalk is distributed in the hope that it will be usefui, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You shouid have received a copy of the GNU General Public License along with
 * GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  
 *
 ***********************************************************************/

/* Scramble the bits of X.  */
static inline uintptr_t scramble (uintptr_t x);

/* Return a pointer to the first item in the OrderedCollection,
   ORDEREDCOLLECTIONOOP.  */
static inline OOP *ordered_collection_begin (OOP orderedCollectionOOP);

/* Return a pointer just beyond the last item in the OrderedCollection,
   ORDEREDCOLLECTIONOOP.  */
static inline OOP *ordered_collection_end (OOP orderedCollectionOOP);

/* Checks to see if TESTEDOOP is a subclass of CLASS_OOP, returning
   true if it is.  */
static inline mst_Boolean is_a_kind_of (OOP testedOOP,
					OOP class_oop);

/* Stores the VALUE Object (which must be an appropriate Integer for
   byte or word objects) into the INDEX-th indexed instance variable
   of the Object pointed to by OOP.  Returns whether the INDEX is
   correct and the VALUE has the appropriate class and/or range.  */
static inline mst_Boolean index_oop_put_spec (OOP oop,
				              gst_object object,
				              size_t index,
					      OOP value,
				              intptr_t instanceSpec);

/* Stores the VALUE Object (which must be an appropriate Integer for
   byte or word objects) into the INDEX-th indexed instance variable
   of the Object pointed to by OOP.  Returns whether the INDEX is
   correct and the VALUE has the appropriate class and/or range.  */
static inline mst_Boolean index_oop_put (OOP oop,
					 size_t index,
					 OOP value);

/* Stores the VALUE Object (which must be an appropriate Integer for
   byte or word objects and if accessing indexed instance variables)
   into the INDEX-th instance variable of the Object pointed to by
   OOP.  */
static inline void inst_var_at_put (OOP oop,
				    int index,
				    OOP value);

/* Returns the INDEX-th instance variable of the Object pointed to by
   OOP.  No range checks are done in INDEX.  */
static inline OOP inst_var_at (OOP oop,
			       int index);

/* Returns the number of instance variables (both fixed and indexed) in OOP.  */
static inline int oop_num_fields (OOP oop);

/* Fill OOPCOUNT pointers to OOPs, starting at OOPPTR,
   with OOPs for the NIL object.  */
static inline void nil_fill (OOP * oopPtr,
			     size_t oopCount);

/* Returns a new, uninitialized instance of CLASS_OOP with
   NUMINDEXFIELDS indexable fields.  Returns an OOP for a newly
   allocated instance of CLASS_OOP, with NUMINDEXFIELDS fields.  The
   object data is returned, the OOP is stored in P_OOP.  The OOP is
   adjusted to reflect any variance in size (such as a string that's
   shorter than a word boundary).  */
static inline gst_object new_instance_with (OOP class_oop,
					    size_t numIndexFields,
					    OOP *p_oop);

/* Creates a new instance of class CLASS_OOP.  The space is allocated,
   the class and size fields of the class are filled in, and the
   instance is returned.  Its fields are NOT INITIALIZED.  CLASS_OOP
   must represent a class with no indexable fields. An OOP will be
   allocated and stored in P_OOP.  */
static inline gst_object new_instance (OOP class_oop,
				       OOP *p_oop);

/* Returns a new, initialized instance of CLASS_OOP within an
   object of size NUMBYTES.  INSTANCESPEC is used to find the
   number of fixed instance variables and initialize them to
   _gst_nil_oop.  The pointer to the object data is returned,
   the OOP is stored in P_OOP.  The OOP is not adjusted to reflect
   any variance in size (such as a string that's shorter than a word
   boundary).  */
static inline gst_object
instantiate_numbytes (OOP class_oop,
	              OOP *p_oop,
                      intptr_t instanceSpec,
                      size_t numBytes);

/* Returns a new, initialized instance of CLASS_OOP with
   NUMINDEXFIELDS indexable fields.  If the instance contains
   pointers, they are initialized to _gst_nil_oop, else they are set
   to the SmallInteger 0.  The pointer to the object data is returned,
   the OOP is stored in P_OOP.  The OOP is adjusted to reflect any
   variance in size (such as a string that's shorter than a word
   boundary).  */
static inline gst_object instantiate_with (OOP class_oop,
					   size_t numIndexFields,
					   OOP *p_oop);

/* Create and return a new instance of class CLASS_OOP.  CLASS_OOP
   must be a class with no indexable fields.  The named instance
   variables of the new instance are initialized to _gst_nil_oop,
   since fixed-field-only objects can only have pointers. The pointer
   to the object data is returned, the OOP is stored in P_OOP.  */
static inline gst_object instantiate (OOP class_oop,
				      OOP *p_oop);

/* Return the Character object for the Unicode value C.  */
static inline OOP char_new (unsigned codePoint);

/* Answer the associated containing KEYOOP in the Dictionary (or a
   subclass having the same representation) DICTIONARYOOP.  */
static inline OOP dictionary_association_at (OOP dictionaryOOP,
					     OOP keyOOP);

/* Answer the value associated to KEYOOP in the Dictionary (or a
   subclass having the same representation) DICTIONARYOOP.  */
static inline OOP dictionary_at (OOP dictionaryOOP,
				 OOP keyOOP);

/* Creates a new Association object having the
   specified KEY and VALUE.  */
static inline OOP association_new (OOP key,
				   OOP value);

/* Creates a new VariableBinding object having the
   specified KEY and VALUE.  */
static inline OOP variable_binding_new (OOP key,
				        OOP value,
					OOP environment);

/* Returns an Object (an Integer for byte or word objects) containing
   the value of the INDEX-th indexed instance variable of the Object
   pointed to by OOP.  Range checks are done in INDEX and NULL is returned
   if this is the checking fails.  */
static inline OOP index_oop (OOP oop,
			     size_t index);

/* Returns an Object (an Integer for byte or word objects) containing
   the value of the INDEX-th indexed instance variable of the Object
   pointed to by OOP.  Range checks are done in INDEX and NULL is returned
   if this is the checking fails.  OBJECT and INSTANCESPEC are cached
   out of OOP and its class.  */
static inline OOP index_oop_spec (OOP oop,
		                  gst_object object,
		                  size_t index,
		                  intptr_t instanceSpec);

/* Returns the number of valid object instance variables in OOP.  */
static inline int num_valid_oops (OOP oop);

/* Returns whether the SCANNEDOOP points to TARGETOOP.  */
static inline mst_Boolean is_owner (OOP scannedOOP,
				    OOP targetOOP);

/* Converts F to a Smalltalk FloatD, taking care of avoiding alignment
   problems.  */
static inline OOP floatd_new (double f);

/* Converts F to a Smalltalk FloatE.  */
static inline OOP floate_new (double f);

/* Converts F to a Smalltalk FloatQ, taking care of avoiding alignment
   problems.  */
static inline OOP floatq_new (long double f);

/* Returns the address of the data stored in a CObject.  */
static inline PTR cobject_value (OOP oop);

/* Sets the address of the data stored in a CObject.  */
static inline void set_cobject_value (OOP oop, PTR val);

/* Return whether the address of the data stored in a CObject, offsetted
   by OFFSET bytes, is still in bounds.  */
static inline mst_Boolean cobject_index_check (OOP oop, intptr_t offset,
					       size_t size);

/* Answer true if OOP is a SmallInteger or a LargeInteger of an
   appropriate size.  */
static inline mst_Boolean is_c_int_32 (OOP oop);

/* Answer true if OOP is a SmallInteger or a LargeInteger of an
   appropriate size.  */
static inline mst_Boolean is_c_uint_32 (OOP oop);

/* Converts the 32-bit int I to the appropriate SmallInteger or
   LargeInteger.  */
static inline OOP from_c_int_32 (int32_t i);

/* Converts the long int LNG to the appropriate SmallInteger or
   LargePositiveInteger.  */
static inline OOP from_c_uint_32 (uint32_t ui);

/* Converts the OOP (which must be a SmallInteger or a small enough
   LargeInteger) to a long int.  If the OOP was for an unsigned long,
   you can simply cast the result to an unsigned long.  */
static inline int32_t to_c_int_32 (OOP oop);

/* Answer true if OOP is a SmallInteger or a LargeInteger of an
   appropriate size.  */
static inline mst_Boolean is_c_int_64 (OOP oop);

/* Answer true if OOP is a SmallInteger or a LargeInteger of an
   appropriate size.  */
static inline mst_Boolean is_c_uint_64 (OOP oop);

/* Converts the 64-bit int I to the appropriate SmallInteger or
   LargeInteger.  */
static inline OOP from_c_int_64 (int64_t i);

/* Converts the long int LNG to the appropriate SmallInteger or
   LargePositiveInteger.  */
static inline OOP from_c_uint_64 (uint64_t ui);

/* Converts the OOP (which must be a SmallInteger or a small enough
   LargeInteger) to a long int.  If the OOP was for an unsigned long,
   you can simply cast the result to an unsigned long.  */
static inline int64_t to_c_int_64 (OOP oop);


#define TO_C_INT(integer)	to_c_int_32(integer)
#define IS_C_INT(oop)		is_c_int_32(oop)

#if SIZEOF_OOP == 4
#define FROM_C_INT(integer)	FROM_C_LONG((intptr_t) (signed) integer)
#define FROM_C_UINT(integer)	FROM_C_ULONG((uintptr_t) (unsigned) integer)
#define FROM_C_LONG(integer)	from_c_int_32(integer)
#define FROM_C_ULONG(integer)	from_c_uint_32(integer)
#define TO_C_LONG(integer)	to_c_int_32(integer)
#define IS_C_LONG(oop)		is_c_int_32(oop)
#define IS_C_ULONG(oop)		is_c_uint_32(oop)
#else
#define FROM_C_INT(integer)	FROM_INT((intptr_t) (signed) integer)
#define FROM_C_UINT(integer)	FROM_INT((intptr_t) (unsigned) integer)
#define FROM_C_LONG(integer)	from_c_int_64(integer)
#define FROM_C_ULONG(integer)	from_c_uint_64(integer)
#define TO_C_LONG(integer)	to_c_int_64(integer)
#define IS_C_LONG(oop)		is_c_int_64(oop)
#define IS_C_ULONG(oop)		is_c_uint_64(oop)
#endif

#if SIZEOF_OFF_T == 4
#define FROM_OFF_T(integer)    from_c_int_32(integer)
#define TO_OFF_T(integer)      to_c_int_32(integer)
#define IS_OFF_T(oop)          is_c_int_32(oop)
#else
#define FROM_OFF_T(integer)    from_c_int_64(integer)
#define TO_OFF_T(integer)      to_c_int_64(integer)
#define IS_OFF_T(oop)          is_c_int_64(oop)
#endif

/* Answer the INDEX'th instance variable of RECEIVER.  */
#define INSTANCE_VARIABLE(receiver, index) \
  (OOP_TO_OBJ (receiver)->data[index])

/* Store OOP in the INDEX'th instance variable of RECEIVER.  */
#define STORE_INSTANCE_VARIABLE(receiver, index, oop) \
  OOP_TO_OBJ (receiver)->data[index] = (oop)

#define IS_SYMBOL(oop) \
  ( !IS_NIL(oop) && (OOP_CLASS(oop) ==  _gst_symbol_class) )

/* Return the Character object for ASCII value C.  */
#define CHAR_OOP_AT(c)      (&_gst_mem.ot[(int)(c) + CHAR_OBJECT_BASE])

/* Answer the code point of the character OOP, charOOP.  */
#define CHAR_OOP_VALUE(charOOP) \
  TO_INT (((gst_char)OOP_TO_OBJ (charOOP))->codePoint)

/* Answer a pointer to the first character of STRINGOOP.  */
#define STRING_OOP_CHARS(stringOOP) \
  ((gst_uchar *)((gst_string)OOP_TO_OBJ(stringOOP))->chars)

/* Answer the selector extracted by the Message, MESSAGEOOP.  */
#define MESSAGE_SELECTOR(messageOOP) \
  (((gst_message)OOP_TO_OBJ(messageOOP))->selector)

/* Answer the array of arguments extracted by the Message,
   MESSAGEOOP.  */
#define MESSAGE_ARGS(messageOOP) \
  (((gst_message)OOP_TO_OBJ(messageOOP))->args)

/* Answer a new CObject pointing to COBJPTR.  */
#define COBJECT_NEW(cObjPtr, typeOOP, defaultClassOOP) \
  (_gst_c_object_new_base(_gst_nil_oop, (uintptr_t) cObjPtr, \
		          typeOOP, defaultClassOOP))

/* Answer the offset component of the a CObject, COBJ (*not* an OOP,
   but an object pointer).  */
#define COBJECT_OFFSET_OBJ(cObj) \
  ( ((uintptr_t *) cObj) [TO_INT(cObj->objSize) - 1])

/* Sets to VALUE the offset component of the CObject, COBJ (*not* an
   OOP, but an object pointer).  */
#define SET_COBJECT_OFFSET_OBJ(cObj, value) \
  ( ((uintptr_t *) cObj) [TO_INT(cObj->objSize) - 1] = (uintptr_t)(value))

/* Answer the superclass of the Behavior, CLASS_OOP.  */
#define SUPERCLASS(class_oop) \
  (((gst_class)OOP_TO_OBJ(class_oop))->superclass)

/* Answer the number of fixed instance variables in OOP.  */
#define OOP_FIXED_FIELDS(oop) \
  (OOP_INSTANCE_SPEC(oop) >> ISP_NUMFIXEDFIELDS)

/* Answer the number of fixed instance variables in instances of
   OOP.  */
#define CLASS_FIXED_FIELDS(oop) \
  (CLASS_INSTANCE_SPEC(oop) >> ISP_NUMFIXEDFIELDS)

/* Answer the number of indexed instance variables in OOP (if any).  */
#define NUM_INDEXABLE_FIELDS(oop) \
	(IS_INT(oop) ? 0 : oop_num_fields(oop) - OOP_FIXED_FIELDS(oop))

/* Answer the INDEX-th indexed instance variable in ARRAYOOP.  */
#define ARRAY_AT(arrayOOP, index) \
	( OOP_TO_OBJ(arrayOOP)->data[(index)-1] )

/* Store VALUE as the INDEX-th indexed instance variable of
   ARRAYOOP.  */
#define ARRAY_AT_PUT(arrayOOP, index, value) \
	( OOP_TO_OBJ(arrayOOP)->data[index-1] = value )

/* Answer the number of associations stored in DICTIONARYOOP.  */
#define DICTIONARY_SIZE(dictionaryOOP) \
  (TO_INT(((gst_dictionary)OOP_TO_OBJ(dictionaryOOP))->tally))


/* Adds the key KEYOOP, associated with VALUEOOP, to the
   Dictionary (or a subclass sharing the same representation)
   DICTIONARYOOP.  */
#define DICTIONARY_AT_PUT(dictionaryOOP, keyOOP, valueOOP) \
  (_gst_dictionary_add((dictionaryOOP), association_new((keyOOP), (valueOOP))))

/* Adds the key KEYOOP, associated with VALUEOOP, to the
   Dictionary (or a subclass sharing the same representation)
   DICTIONARYOOP.  */
#define NAMESPACE_AT_PUT(dictionaryOOP, keyOOP, valueOOP) \
  (_gst_dictionary_add((dictionaryOOP), \
	variable_binding_new((keyOOP), (valueOOP), (dictionaryOOP))))

/* Adds the key KEYOOP, associated with VALUEOOP, to the
   Dictionary (or a subclass sharing the same representation)
   DICTIONARYOOP.  */
#define DICTIONARY_AT_PUT(dictionaryOOP, keyOOP, valueOOP) \
  (_gst_dictionary_add((dictionaryOOP), \
	association_new((keyOOP), (valueOOP))))

/* Answer whether OOP is a metaclass.  */
#define IS_A_METACLASS(oop) \
  (IS_OOP(oop) && OOP_CLASS(oop) == _gst_metaclass_class)

/* Answer whether OOP is a class, that is, the instance of the
   metaclass.  */
#define IS_A_CLASS(oop) \
  (IS_OOP(oop) && \
   IS_OOP(OOP_CLASS(oop)) && \
   OOP_CLASS(OOP_CLASS(oop)) == _gst_metaclass_class)

/* Answer the sole instance of the metaclass, METACLASSOOP.  */
#define METACLASS_INSTANCE(metaclassOOP) \
  (((gst_metaclass)OOP_TO_OBJ(metaclassOOP))->instanceClass)

/* Answer the value stored in the Association, ASSOCIATIONOOP.  */
#define ASSOCIATION_VALUE(associationOOP) \
  (((gst_association)OOP_TO_OBJ(associationOOP))->value)

/* Change the value stored in the Association, ASSOCIATIONOOP, to
   VALUEOOP.  */
#define SET_ASSOCIATION_VALUE(associationOOP, valueOOP) \
  (((gst_association)OOP_TO_OBJ(associationOOP))->value = valueOOP)

/* Set NAMESPACEOOP to be the namespace in which references to globals
   from methods of CLASS_OOP are resolved.  */
#define SET_CLASS_ENVIRONMENT(class_oop, namespaceOOP) \
  (((gst_class)OOP_TO_OBJ(class_oop))->environment = namespaceOOP)

/* Answer the instance specification for instances of CLASS_OOP.  */
#define CLASS_INSTANCE_SPEC(class_oop) \
  (((gst_class)OOP_TO_OBJ(class_oop))->instanceSpec)

/* Answer the instance specification of the object OBJ (*not* an OOP).  */
#define GET_INSTANCE_SPEC(obj) \
  CLASS_INSTANCE_SPEC((obj)->objClass)

/* Answer the instance specification of OOP.  */
#define OOP_INSTANCE_SPEC(oop) \
  CLASS_INSTANCE_SPEC(OOP_CLASS(oop))

/* Answer whether INDEX is in-bounds for accessing fixed instance variables
   of OOP.  */
#define CHECK_BOUNDS_OF(oop, index) \
  (IS_OOP(oop) && (index >= 1 && index <= OOP_FIXED_FIELDS(oop)))

/* Answer whether indexed instance variables for instances of
   CLASS_OOP are pointers.  */
#define CLASS_IS_UNALIGNED(class_oop) \
  ((CLASS_INSTANCE_SPEC(class_oop) & ISP_ISINDEXABLE) \
   && (CLASS_INSTANCE_SPEC(class_oop) & ISP_INDEXEDVARS) <= GST_ISP_LAST_UNALIGNED)

/* Answer whether instances of CLASS_OOP have indexed instance variables.  */
#define CLASS_IS_INDEXABLE(class_oop) \
  (CLASS_INSTANCE_SPEC(class_oop) & ISP_ISINDEXABLE)

/* Answer whether instances of CLASS_OOP have indexed instance variables.  */
#define CLASS_IS_SCALAR(class_oop) \
  ((CLASS_INSTANCE_SPEC(class_oop) & ISP_ISINDEXABLE) \
   && (CLASS_INSTANCE_SPEC(class_oop) & ISP_INDEXEDVARS) <= GST_ISP_LAST_SCALAR)

/* Answer the size in bytes of the object data for OOP.  */
#define OBJECT_SIZE_BYTES(obj) \
  (SIZE_TO_BYTES (TO_INT (obj->objSize)) - sizeof (gst_object_header))

/* Answer the size in bytes of the object data for OOP.  */
#define OOP_SIZE_BYTES(oop) \
  OBJECT_SIZE_BYTES (OOP_TO_OBJ (oop))

/* Return the number of word-addressed (pointers or words) instance
   variables, both fixed and indexed), in OOP.  Use instead of 
   NUM_OOPS if you know OOP is not a byte object.  */
#define NUM_WORDS(obj) \
  ((size_t) (TO_INT((obj)->objSize) - OBJ_HEADER_SIZE_WORDS))

/* Return the number of pointer instance variables (both fixed and
   indexed), in the object OBJ.  */
#define NUM_OOPS(obj) \
  ((size_t) (COMMON (CLASS_IS_SCALAR ((obj)->objClass)) \
    ? (CLASS_INSTANCE_SPEC((obj)->objClass) >> ISP_NUMFIXEDFIELDS) \
    : NUM_WORDS(obj) \
  ))


#define FLOATE_OOP_VALUE(floatOOP) \
	(((gst_floate)OOP_TO_OBJ(floatOOP))->value)

OOP
floate_new (double f)
{
  gst_floate floatObject;
  OOP floatOOP;

  floatObject = (gst_floate) new_instance_with 
    (_gst_floate_class, sizeof (float), &floatOOP);

  floatObject->value = f;
  MAKE_OOP_READONLY (floatOOP, true);
  return (floatOOP);
}

#if (ALIGNOF_DOUBLE <= SIZEOF_OOP)
#define FLOATD_OOP_VALUE(floatOOP) \
	(((gst_floatd)OOP_TO_OBJ(floatOOP))->value)

#else
#define FLOATD_OOP_VALUE(floatOOP) \
	floatd_oop_value(floatOOP)

static inline double
floatd_oop_value (floatOOP)
     OOP floatOOP;
{
  gst_object obj;
  double d;

  /* we may not be aligned properly...fetch things out the hard way */
  obj = OOP_TO_OBJ (floatOOP);
  memcpy (&d, obj->data, sizeof (double));
  return (d);
}
#endif

OOP
floatd_new (double f)
{
  OOP floatOOP;
#if (ALIGNOF_DOUBLE <= SIZEOF_OOP)
  gst_floatd floatObject;

  floatObject = (gst_floatd) new_instance_with 
    (_gst_floatd_class, sizeof (double), &floatOOP);

  floatObject->value = f;
#else
  gst_object obj;

  obj = new_instance_with (_gst_floatd_class, sizeof (double), &floatOOP);

  memcpy (&obj->data, &f, sizeof (double));
#endif

  MAKE_OOP_READONLY (floatOOP, true);
  return (floatOOP);
}

#if (ALIGNOF_LONG_DOUBLE <= SIZEOF_OOP)
#define FLOATQ_OOP_VALUE(floatOOP) \
	(((gst_floatq)OOP_TO_OBJ(floatOOP))->value)

#else
#define FLOATQ_OOP_VALUE(floatOOP) \
	floatq_oop_value(floatOOP)

static inline long double
floatq_oop_value (floatOOP)
     OOP floatOOP;
{
  gst_object obj;
  long double d;

  /* we may not be aligned properly...fetch things out the hard way */
  obj = OOP_TO_OBJ (floatOOP);
  memcpy (&d, obj->data, sizeof (long double));
  return (d);
}
#endif

OOP
floatq_new (long double f)
{
  OOP floatOOP;
  gst_object obj = new_instance_with (_gst_floatq_class, 16, &floatOOP);

#if defined __i386__ || defined __x86_64__
  /* Two bytes (six on x86-64) of 80-bit long doubles are unused.  */
  memcpy (&obj->data, &f, 10);
  memset (((char *)obj->data) + 10, 0, 6);
#else
  memcpy (&obj->data, &f, sizeof (long double));
  memset (((char *)obj->data) + sizeof (long double), 0,
	  16 - sizeof (long double));
#endif

  MAKE_OOP_READONLY (floatOOP, true);
  return (floatOOP);
}

OOP
char_new (unsigned codePoint)
{
  gst_char charObject;
  OOP charOOP;

  if (codePoint <= 127)
    return CHAR_OOP_AT (codePoint);
  if UNCOMMON (codePoint > 0x10FFFF)
    codePoint = 0xFFFD;

  charObject = (gst_char) new_instance (_gst_unicode_character_class, &charOOP);

  charObject->codePoint = FROM_INT (codePoint);
  MAKE_OOP_READONLY (charOOP, true);
  return (charOOP);
}

uintptr_t
scramble (uintptr_t x)
{
#if SIZEOF_OOP == 8
  x ^= (x >> 31) | ( x << 33);
#endif
  x ^= (x << 10) | (x >> 22);
  x ^= (x << 6)  | (x >> 26);
  x ^= (x << 16) | (x >> 16);

  return x & MAX_ST_INT;
}


mst_Boolean
is_a_kind_of (OOP testedOOP,
	      OOP class_oop)
{
  do
    {
      if (testedOOP == class_oop)
	return (true);
      testedOOP = SUPERCLASS (testedOOP);
    }
  while (!IS_NIL (testedOOP));

  return (false);
}


void
nil_fill (OOP * oopPtr,
	  size_t oopCount)
{
  REGISTER (3, OOP nilObj);

  nilObj = _gst_nil_oop;
  while (oopCount >= 8)
    {
      oopPtr[0] = oopPtr[1] = oopPtr[2] = oopPtr[3] =
        oopPtr[4] = oopPtr[5] = oopPtr[6] = oopPtr[7] = nilObj;
      oopPtr += 8;
      oopCount -= 8;
    }

  if (oopCount & 4)
    {
      oopPtr[0] = oopPtr[1] = oopPtr[2] = oopPtr[3] = nilObj;
      oopPtr += 4;
    }

  if (oopCount & 2)
    {
      oopPtr[0] = oopPtr[1] = nilObj;
      oopPtr += 2;
    }

  if (oopCount & 1)
    oopPtr[0] = nilObj;
}

gst_object
new_instance_with (OOP class_oop,
		   size_t numIndexFields,
		   OOP *p_oop)
{
  size_t numBytes, alignedBytes;
  intptr_t instanceSpec;
  gst_object p_instance;

  instanceSpec = CLASS_INSTANCE_SPEC (class_oop);
  numBytes = sizeof (gst_object_header)
    + SIZE_TO_BYTES(instanceSpec >> ISP_NUMFIXEDFIELDS)
    + (numIndexFields << _gst_log2_sizes[instanceSpec & ISP_SHAPE]);

  alignedBytes = ROUNDED_BYTES (numBytes);
  p_instance = _gst_alloc_obj (alignedBytes, p_oop);
  INIT_UNALIGNED_OBJECT (*p_oop, alignedBytes - numBytes);

  p_instance->objClass = class_oop;
  (*p_oop)->flags |= (class_oop->flags & F_UNTRUSTED);

  return p_instance;
}


gst_object
new_instance (OOP class_oop,
	      OOP *p_oop)
{
  size_t numBytes;
  intptr_t instanceSpec;
  gst_object p_instance;

  instanceSpec = CLASS_INSTANCE_SPEC (class_oop);
  numBytes = sizeof (gst_object_header) + 
    SIZE_TO_BYTES(instanceSpec >> ISP_NUMFIXEDFIELDS);

  p_instance = _gst_alloc_obj (numBytes, p_oop);
  p_instance->objClass = class_oop;
  (*p_oop)->flags |= (class_oop->flags & F_UNTRUSTED);

  return p_instance;
}


gst_object
instantiate_numbytes (OOP class_oop,
	              OOP *p_oop,
                      intptr_t instanceSpec,
                      size_t numBytes)
{
  gst_object p_instance;
  int n;
  OOP src, *dest;

  p_instance = _gst_alloc_obj (numBytes, p_oop);
  p_instance->objClass = class_oop;
  (*p_oop)->flags |= (class_oop->flags & F_UNTRUSTED);

  n = instanceSpec >> ISP_NUMFIXEDFIELDS;
  if UNCOMMON (n == 0)
    return p_instance;

  src = _gst_nil_oop;
  dest = p_instance->data;
  dest[0] = src;
  if UNCOMMON (n == 1)
    return p_instance;

  dest[1] = src;
  if UNCOMMON (n == 2)
    return p_instance;

  dest[2] = src;
  if UNCOMMON (n == 3)
    return p_instance;

  dest += 3;
  n -= 3;
  do
    *dest++ = src;
  while (--n > 0);
  return p_instance;
}

gst_object
instantiate_with (OOP class_oop,
		  size_t numIndexFields,
		  OOP *p_oop)
{
  size_t numBytes, indexedBytes, alignedBytes;
  intptr_t instanceSpec;
  gst_object p_instance;

  instanceSpec = CLASS_INSTANCE_SPEC (class_oop);
#ifndef OPTIMIZE
  if (!(instanceSpec & ISP_ISINDEXABLE) && numIndexFields != 0)
    _gst_errorf
      ("class without indexed instance variables passed to instantiate_with");
#endif

  indexedBytes = numIndexFields << _gst_log2_sizes[instanceSpec & ISP_SHAPE];
  numBytes = sizeof (gst_object_header)
    + SIZE_TO_BYTES(instanceSpec >> ISP_NUMFIXEDFIELDS)
    + indexedBytes;

  if COMMON ((instanceSpec & ISP_INDEXEDVARS) == GST_ISP_POINTER)
    {
      p_instance = _gst_alloc_obj (numBytes, p_oop);
      p_instance->objClass = class_oop;
      (*p_oop)->flags |= (class_oop->flags & F_UNTRUSTED);
      nil_fill (p_instance->data,
	        (instanceSpec >> ISP_NUMFIXEDFIELDS) + numIndexFields);
    }
  else
    {
      alignedBytes = ROUNDED_BYTES (numBytes);
      p_instance = instantiate_numbytes (class_oop,
                                         p_oop,
                                         instanceSpec,
                                         alignedBytes);
      INIT_UNALIGNED_OBJECT (*p_oop, alignedBytes - numBytes);
      memset (&p_instance->data[instanceSpec >> ISP_NUMFIXEDFIELDS], 0,
	      indexedBytes);
    }

  return p_instance;
}

gst_object
instantiate (OOP class_oop,
	     OOP *p_oop)
{
  size_t numBytes;
  intptr_t instanceSpec;

  instanceSpec = CLASS_INSTANCE_SPEC (class_oop);
  numBytes = sizeof (gst_object_header) + 
    SIZE_TO_BYTES(instanceSpec >> ISP_NUMFIXEDFIELDS);
  return instantiate_numbytes (class_oop,
                               p_oop,
                               instanceSpec, numBytes);
}


OOP *
ordered_collection_begin (OOP orderedCollectionOOP)
{
  gst_ordered_collection oc;

  oc = (gst_ordered_collection) OOP_TO_OBJ (orderedCollectionOOP);
  return &oc->data[TO_INT (oc->firstIndex) - 1];
}

OOP *
ordered_collection_end (OOP orderedCollectionOOP)
{
  gst_ordered_collection oc;

  oc = (gst_ordered_collection) OOP_TO_OBJ (orderedCollectionOOP);
  return &oc->data[TO_INT (oc->lastIndex)];
}


OOP
dictionary_association_at (OOP dictionaryOOP,
			   OOP keyOOP)
{
  gst_object dictionary;
  size_t index, count, numFields, numFixedFields;
  OOP associationOOP;
  gst_association association;

  if UNCOMMON (IS_NIL (dictionaryOOP))
    return (_gst_nil_oop);

  dictionary = OOP_TO_OBJ (dictionaryOOP);
  numFixedFields = OOP_FIXED_FIELDS (dictionaryOOP);
  numFields = NUM_WORDS (dictionary) - numFixedFields;
  index = scramble (OOP_INDEX (keyOOP));
  count = numFields;

  while (count--)
    {
      index &= numFields - 1;
      associationOOP = dictionary->data[numFixedFields + index];
      if COMMON (IS_NIL (associationOOP))
	return (_gst_nil_oop);

      association = (gst_association) OOP_TO_OBJ (associationOOP);

      if COMMON (association->key == keyOOP)
	return (associationOOP);

      /* linear reprobe -- it is simple and guaranteed */
      index++;
    }

  _gst_errorf
    ("Error - searching Dictionary for nil, but it is full!\n");
  abort ();
}

OOP
dictionary_at (OOP dictionaryOOP,
	       OOP keyOOP)
{
  OOP assocOOP;

  assocOOP = dictionary_association_at (dictionaryOOP, keyOOP);

  if UNCOMMON (IS_NIL (assocOOP))
    return (_gst_nil_oop);
  else
    return (ASSOCIATION_VALUE (assocOOP));
}

OOP
association_new (OOP key,
		 OOP value)
{
  gst_association association;
  OOP associationOOP;

  association = (gst_association) new_instance (_gst_association_class,
						&associationOOP);

  association->key = key;
  association->value = value;

  return (associationOOP);
}

OOP
variable_binding_new (OOP key,
		      OOP value,
		      OOP environment)
{
  gst_variable_binding binding;
  OOP bindingOOP;

  binding = (gst_variable_binding)
    new_instance (_gst_variable_binding_class, &bindingOOP);

  binding->key = key;
  binding->value = value;
  binding->environment = environment;

  return (bindingOOP);
}


int
oop_num_fields (OOP oop)
{
  gst_object object;
  intptr_t instanceSpec;
  size_t words, dataBytes, fixed;

  object = OOP_TO_OBJ (oop);
  words = NUM_WORDS (object);

  if COMMON (!(oop->flags & F_BYTE))
    return words;

  instanceSpec = GET_INSTANCE_SPEC (object);
  fixed = instanceSpec >> ISP_NUMFIXEDFIELDS;
  words -= fixed;
  dataBytes = SIZE_TO_BYTES (words) - (oop->flags & EMPTY_BYTES);
  return fixed + (dataBytes >> _gst_log2_sizes[instanceSpec & ISP_SHAPE]);
}


static int
num_valid_oops (OOP oop)
{
  gst_object object;

  object = OOP_TO_OBJ (oop);
  if UNCOMMON (oop->flags & F_CONTEXT)
    {
      gst_method_context ctx;
      intptr_t methodSP;
      ctx = (gst_method_context) object;
      methodSP = TO_INT (ctx->spOffset);
      return ctx->contextStack + methodSP + 1 - object->data;
    }
  else
    return NUM_OOPS (object);
}


/* Returns whether the SCANNEDOOP points to TARGETOOP.  */
mst_Boolean
is_owner (OOP scannedOOP,
	  OOP targetOOP)
{
  gst_object object;
  OOP *scanPtr;
  int n;

  object = OOP_TO_OBJ (scannedOOP);
  if UNCOMMON (object->objClass == targetOOP)
    return true;

  n = num_valid_oops (scannedOOP);

  /* Peel a couple of iterations for optimization.  */
  if (n--)
    {
      scanPtr = object->data;
      if UNCOMMON (*scanPtr++ == targetOOP)
	return true;

      if (n--)
	do
          if UNCOMMON (*scanPtr++ == targetOOP)
	    return true;
	while (n--);
    }

  return false;
}

OOP
index_oop (OOP oop,
	   size_t index)
{
  gst_object object = OOP_TO_OBJ (oop);
  intptr_t instanceSpec = GET_INSTANCE_SPEC (object);
  return index_oop_spec (oop, object, index, instanceSpec);
}

OOP
index_oop_spec (OOP oop,
		gst_object object,
	        size_t index,
		intptr_t instanceSpec)
{
  size_t maxIndex, maxByte;
  char *src;

  if UNCOMMON (index < 1)
    return (NULL);

  index--;

#define DO_INDEX_OOP(type, dest)					\
    /* Find the number of bytes in the object.  */			\
    maxByte = NUM_WORDS (object) * sizeof (PTR);			\
    if (sizeof (type) <= sizeof (PTR))					\
      maxByte -= (oop->flags & EMPTY_BYTES);				\
									\
    index =								\
      index * sizeof(type)						\
      + (instanceSpec >> ISP_NUMFIXEDFIELDS) * sizeof (PTR);		\
									\
    /* Check that we're on bounds.  */					\
    if UNCOMMON (index + sizeof(type) > maxByte)			\
      return (NULL);							\
									\
    /* Use a cast if unaligned accesses are supported, else memcpy.  */	\
    src = ((char *) object->data) + index;				\
    if (sizeof (type) <= sizeof (PTR))					\
      (dest) = *(type *) src;						\
    else								\
      memcpy ((char *) &(dest), src, sizeof (type));

  switch (instanceSpec & ISP_INDEXEDVARS)
    {
      case GST_ISP_SCHAR: {
        int8_t i;
        DO_INDEX_OOP (int8_t, i);
        return FROM_INT (i);
      }

      case GST_ISP_UCHAR: {
        uint8_t i;
        DO_INDEX_OOP (uint8_t, i);
        return FROM_INT (i);
      }

      case GST_ISP_CHARACTER: {
        uint8_t i;
        DO_INDEX_OOP (uint8_t, i);
        return CHAR_OOP_AT (i);
      }

      case GST_ISP_SHORT: {
        uint16_t i;
        DO_INDEX_OOP (int16_t, i);
        return FROM_INT (i);
      }

      case GST_ISP_USHORT: {
        uint16_t i;
        DO_INDEX_OOP (uint16_t, i);
        return FROM_INT (i);
      }

      case GST_ISP_INT: {
        uint32_t i;
        DO_INDEX_OOP (int32_t, i);
        return from_c_int_32 (i);
      }

      case GST_ISP_UINT: {
        uint32_t i;
        DO_INDEX_OOP (uint32_t, i);
        return from_c_uint_32 (i);
      }

      case GST_ISP_FLOAT: {
        float f;
        DO_INDEX_OOP (float, f);
        return floate_new (f);
      }

      case GST_ISP_INT64: {
        uint64_t i;
        DO_INDEX_OOP (int64_t, i);
        return from_c_int_64 (i);
      }

      case GST_ISP_UINT64: {
        uint64_t i;
        DO_INDEX_OOP (uint64_t, i);
        return from_c_uint_64 (i);
      }

      case GST_ISP_DOUBLE: {
        double d;
        DO_INDEX_OOP (double, d);
        return floatd_new (d);
      }

      case GST_ISP_UTF32: {
        uint32_t i;
        DO_INDEX_OOP (uint32_t, i);
        return char_new (i);
      }

      case GST_ISP_POINTER:
        maxIndex = NUM_WORDS (object);
        index += instanceSpec >> ISP_NUMFIXEDFIELDS;
        if UNCOMMON (index >= maxIndex)
	  return (NULL);

        return (object->data[index]);
    }
#undef DO_INDEX_OOP

  return (NULL);
}

mst_Boolean
index_oop_put (OOP oop,
	       size_t index,
	       OOP value)
{
  gst_object object = OOP_TO_OBJ (oop);
  intptr_t instanceSpec = GET_INSTANCE_SPEC (object);
  return index_oop_put_spec (oop, object, index, value, instanceSpec);
}

mst_Boolean
index_oop_put_spec (OOP oop,
		    gst_object object,
		    size_t index,
		    OOP value,
		    intptr_t instanceSpec)
{
  size_t maxIndex;

  if UNCOMMON (index < 1)
    return (false);

  index--;

#define DO_INDEX_OOP_PUT(type, cond, src)				\
    if COMMON (cond)							\
      {									\
        /* Find the number of bytes in the object.  */			\
        size_t maxByte = NUM_WORDS (object) * sizeof (PTR);		\
        if (sizeof (type) <= sizeof (PTR))				\
          maxByte -= (oop->flags & EMPTY_BYTES);			\
									\
        index =								\
          index * sizeof(type)						\
          + (instanceSpec >> ISP_NUMFIXEDFIELDS) * sizeof (PTR);	\
									\
        /* Check that we're on bounds.  */				\
        if UNCOMMON (index + sizeof(type) > maxByte)			\
          return (false);						\
									\
        /* Use a cast if unaligned accesses are ok, else memcpy.  */	\
        if (sizeof (type) <= sizeof (PTR))				\
	  {								\
	    type *destAddr = (type *) (((char *) object->data) + index);\
            *destAddr = (type) (src);					\
	  }								\
        else								\
	  {								\
	    char *destAddr = ((char *) object->data) + index;		\
	    type src_ = (type) (src);					\
            memcpy (destAddr, (char *) &src_, sizeof (type));		\
	  }								\
        return (true);							\
      }

  switch (instanceSpec & ISP_INDEXEDVARS)
    {
      case GST_ISP_SCHAR: {
        DO_INDEX_OOP_PUT (int8_t,
			  IS_INT (value)
			  && TO_INT (value) >= -128
			  && TO_INT (value) <= 127,
			  TO_INT (value));
        return (false);
      }

      case GST_ISP_UCHAR: {
        DO_INDEX_OOP_PUT (uint8_t,
			  IS_INT (value)
			  && TO_INT (value) >= 0
			  && TO_INT (value) <= 255,
			  TO_INT (value));
        return (false);
      }

      case GST_ISP_CHARACTER: {
        DO_INDEX_OOP_PUT (uint8_t,
			  !IS_INT (value)
			  && OOP_CLASS (value) == _gst_char_class,
			  CHAR_OOP_VALUE (value));
        return (false);
      }

      case GST_ISP_SHORT: {
        DO_INDEX_OOP_PUT (uint16_t,
			  IS_INT (value)
			  && TO_INT (value) >= -32768
			  && TO_INT (value) <= 32767,
			  TO_INT (value));
	return (false);
      }

      case GST_ISP_USHORT: {
        DO_INDEX_OOP_PUT (uint16_t,
			  IS_INT (value)
			  && TO_INT (value) >= 0
			  && TO_INT (value) <= 65535,
			  TO_INT (value));
	return (false);
      }

      case GST_ISP_INT: {
        DO_INDEX_OOP_PUT (int32_t, is_c_int_32 (value), to_c_int_32 (value));
	return (false);
      }

      case GST_ISP_UINT: {
        DO_INDEX_OOP_PUT (uint32_t, is_c_uint_32 (value), to_c_int_32 (value));
	return (false);
      }

      case GST_ISP_FLOAT: {
        DO_INDEX_OOP_PUT (float, IS_INT (value), TO_INT (value));
        DO_INDEX_OOP_PUT (float, OOP_CLASS (value) == _gst_floate_class,
			  FLOATE_OOP_VALUE (value));
        DO_INDEX_OOP_PUT (float, OOP_CLASS (value) == _gst_floatd_class,
			  FLOATD_OOP_VALUE (value));
        DO_INDEX_OOP_PUT (float, OOP_CLASS (value) == _gst_floatq_class,
			  FLOATQ_OOP_VALUE (value));
        return (false);
      }

      case GST_ISP_INT64: {
        DO_INDEX_OOP_PUT (int64_t, is_c_int_64 (value), to_c_int_64 (value));
	return (false);
      }

      case GST_ISP_UINT64: {
        DO_INDEX_OOP_PUT (uint64_t, is_c_uint_64 (value), to_c_int_64 (value));
	return (false);
      }

      case GST_ISP_DOUBLE: {
        DO_INDEX_OOP_PUT (double, IS_INT (value), TO_INT (value));
        DO_INDEX_OOP_PUT (double, OOP_CLASS (value) == _gst_floatd_class,
			  FLOATD_OOP_VALUE (value));
        DO_INDEX_OOP_PUT (double, OOP_CLASS (value) == _gst_floate_class,
			  FLOATE_OOP_VALUE (value));
        DO_INDEX_OOP_PUT (double, OOP_CLASS (value) == _gst_floatq_class,
			  FLOATQ_OOP_VALUE (value));
        return (false);
      }

      case GST_ISP_UTF32: {
        DO_INDEX_OOP_PUT (uint32_t,
			  !IS_INT (value)
			  && (OOP_CLASS (value) == _gst_unicode_character_class
			      || (OOP_CLASS (value) == _gst_char_class
			          && CHAR_OOP_VALUE (value) <= 127)),
			  CHAR_OOP_VALUE (value));
        return (false);
      }

      case GST_ISP_POINTER:
        maxIndex = NUM_WORDS (object);
        index += instanceSpec >> ISP_NUMFIXEDFIELDS;
        if UNCOMMON (index >= maxIndex)
	  return (false);

        object->data[index] = value;
        return (true);
    }
#undef DO_INDEX_OOP_PUT

  return (false);
}

OOP
inst_var_at (OOP oop,
	     int index)
{
  gst_object object;

  object = OOP_TO_OBJ (oop);
  return (object->data[index - 1]);
}

void
inst_var_at_put (OOP oop,
		 int index,
		 OOP value)
{
  gst_object object;

  object = OOP_TO_OBJ (oop);
  object->data[index - 1] = value;
}


mst_Boolean
is_c_int_32 (OOP oop)
{
  gst_byte_array ba;

  if COMMON (IS_INT (oop))
#if SIZEOF_OOP == 4
    return (true);
#else
    return (TO_INT (oop) >= INT_MIN && TO_INT (oop) < INT_MAX);
#endif

  ba = (gst_byte_array) OOP_TO_OBJ (oop);
  if (COMMON (ba->objClass == _gst_large_positive_integer_class)
      || ba->objClass == _gst_large_negative_integer_class)
    return (NUM_INDEXABLE_FIELDS (oop) == 4);

  return (false);
}

mst_Boolean
is_c_uint_32 (OOP oop)
{
  gst_byte_array ba;

  if COMMON (IS_INT (oop))
#if SIZEOF_OOP == 4
    return (TO_INT (oop) >= 0);
#else
    return (TO_INT (oop) >= 0 && TO_INT (oop) < UINT_MAX);
#endif

  ba = (gst_byte_array) OOP_TO_OBJ (oop);
  if COMMON (ba->objClass == _gst_large_positive_integer_class)
    {
      switch (NUM_INDEXABLE_FIELDS (oop))
	{
	case 4:
	  return (true);
	case 5:
	  return (ba->bytes[4] == 0);
	}
    }

  return (false);
}

int32_t
to_c_int_32 (OOP oop)
{
  gst_byte_array ba;

  if COMMON (IS_INT (oop))
    return (TO_INT (oop));

  ba = (gst_byte_array) OOP_TO_OBJ (oop);
  return ((int32_t) ((((uint32_t) ba->bytes[3]) << 24) +
		     (((uint32_t) ba->bytes[2]) << 16) +
		     (((uint32_t) ba->bytes[1]) << 8) +
		      ((uint32_t) ba->bytes[0])));
}

OOP
from_c_int_32 (int32_t i)
{
  gst_byte_array ba;
  OOP oop;
  const uint32_t ui = (uint32_t) i;

  if COMMON (i >= MIN_ST_INT && i <= MAX_ST_INT)
    return (FROM_INT (i));

  if (i < 0)
    ba = (gst_byte_array) new_instance_with (_gst_large_negative_integer_class, 
					     4, &oop);
  else
    ba = (gst_byte_array) new_instance_with (_gst_large_positive_integer_class, 
					     4, &oop);

  ba->bytes[0] = (gst_uchar) ui;
  ba->bytes[1] = (gst_uchar) (ui >> 8);
  ba->bytes[2] = (gst_uchar) (ui >> 16);
  ba->bytes[3] = (gst_uchar) (ui >> 24);
  return (oop);
}

OOP
from_c_uint_32 (uint32_t ui)
{
  gst_byte_array ba;
  OOP oop;

  if COMMON (ui <= MAX_ST_INT)
    return (FROM_INT (ui));

  if UNCOMMON (((intptr_t) ui) < 0)
    {
      ba = (gst_byte_array) 
        new_instance_with (_gst_large_positive_integer_class, 
			   5, &oop);

      ba->bytes[4] = 0;
    }
  else
    ba = (gst_byte_array) 
      new_instance_with (_gst_large_positive_integer_class, 
	 		 4, &oop);

  ba->bytes[0] = (gst_uchar) ui;
  ba->bytes[1] = (gst_uchar) (ui >> 8);
  ba->bytes[2] = (gst_uchar) (ui >> 16);
  ba->bytes[3] = (gst_uchar) (ui >> 24);

  return (oop);
}


mst_Boolean
is_c_int_64 (OOP oop)
{
  gst_byte_array ba;

  if COMMON (IS_INT (oop))
    return (true);

  ba = (gst_byte_array) OOP_TO_OBJ (oop);
  if (ba->objClass == _gst_large_negative_integer_class)
    return (NUM_INDEXABLE_FIELDS (oop) == 8);

  else if COMMON (ba->objClass == _gst_large_positive_integer_class)
    {
      switch (NUM_INDEXABLE_FIELDS (oop))
	{
	case 8:
	  return (true);
	case 9:
	  return (ba->bytes[8] == 0);
	}
    }

  return (false);
}

mst_Boolean
is_c_uint_64 (OOP oop)
{
  gst_byte_array ba;

  if COMMON (IS_INT (oop))
    return (TO_INT (oop) >= 0);

  ba = (gst_byte_array) OOP_TO_OBJ (oop);
  if COMMON (ba->objClass == _gst_large_positive_integer_class)
    {
      switch (NUM_INDEXABLE_FIELDS (oop))
	{
	case 8:
	  return (true);
	case 9:
	  return (ba->bytes[8] == 0);
	}
    }

  return (false);
}

int64_t
to_c_int_64 (OOP oop)
{
  gst_byte_array ba;

  if COMMON (IS_INT (oop))
    return (TO_INT (oop));

  ba = (gst_byte_array) OOP_TO_OBJ (oop);
  return ((int64_t) (
		   (((uint64_t) ba->bytes[7]) << 56) +
		   (((uint64_t) ba->bytes[6]) << 48) +
		   (((uint64_t) ba->bytes[5]) << 40) +
		   (((uint64_t) ba->bytes[4]) << 32) +
		   (((uint64_t) ba->bytes[3]) << 24) +
		   (((uint64_t) ba->bytes[2]) << 16) +
		   (((uint64_t) ba->bytes[1]) << 8) +
		   ((uint64_t) ba->bytes[0])));
}

OOP
from_c_int_64 (int64_t i)
{
  gst_byte_array ba;
  OOP oop;
  const uint64_t ui = (uint64_t) i;

  if COMMON (i >= MIN_ST_INT && i <= MAX_ST_INT)
    return (FROM_INT (i));

  if (i < 0)
    ba = (gst_byte_array) new_instance_with (_gst_large_negative_integer_class, 
					     8, &oop);
  else
    ba = (gst_byte_array) new_instance_with (_gst_large_positive_integer_class, 
					     8, &oop);

  ba->bytes[0] = (gst_uchar) ui;
  ba->bytes[1] = (gst_uchar) (ui >> 8);
  ba->bytes[2] = (gst_uchar) (ui >> 16);
  ba->bytes[3] = (gst_uchar) (ui >> 24);
  ba->bytes[4] = (gst_uchar) (ui >> 32);
  ba->bytes[5] = (gst_uchar) (ui >> 40);
  ba->bytes[6] = (gst_uchar) (ui >> 48);
  ba->bytes[7] = (gst_uchar) (ui >> 56);

  return (oop);
}

OOP
from_c_uint_64 (uint64_t ui)
{
  gst_byte_array ba;
  OOP oop;

  if COMMON (ui <= MAX_ST_INT)
    return (FROM_INT (ui));

  if UNCOMMON (((int64_t) ui) < 0)
    {
      ba = (gst_byte_array) 
        new_instance_with (_gst_large_positive_integer_class, 
			   9, &oop);

      ba->bytes[8] = 0;
    }
  else
    ba = (gst_byte_array) 
      new_instance_with (_gst_large_positive_integer_class, 
	 		 8, &oop);

  ba->bytes[0] = (gst_uchar) ui;
  ba->bytes[1] = (gst_uchar) (ui >> 8);
  ba->bytes[2] = (gst_uchar) (ui >> 16);
  ba->bytes[3] = (gst_uchar) (ui >> 24);
  ba->bytes[4] = (gst_uchar) (ui >> 32);
  ba->bytes[5] = (gst_uchar) (ui >> 40);
  ba->bytes[6] = (gst_uchar) (ui >> 48);
  ba->bytes[7] = (gst_uchar) (ui >> 56);

  return (oop);
}

static inline PTR
cobject_value (OOP oop)
{
  gst_cobject cObj = (gst_cobject) OOP_TO_OBJ (oop);
  if (IS_NIL (cObj->storage))
    return (PTR) COBJECT_OFFSET_OBJ (cObj);
  else
    {
      gst_uchar *baseAddr = ((gst_byte_array) OOP_TO_OBJ (cObj->storage))->bytes;
      return (PTR) (baseAddr + COBJECT_OFFSET_OBJ (cObj));
    }
}

/* Sets the address of the data stored in a CObject.  */
static inline void
set_cobject_value (OOP oop, PTR val)
{
  gst_cobject cObj = (gst_cobject) OOP_TO_OBJ (oop);
  cObj->storage = _gst_nil_oop;
  SET_COBJECT_OFFSET_OBJ (cObj, (uintptr_t) val);
}
  

/* Return whether the address of the data stored in a CObject, offsetted
   by OFFSET bytes, is still in bounds.  */
static inline mst_Boolean cobject_index_check (OOP oop, intptr_t offset,
					       size_t size)
{
  gst_cobject cObj = (gst_cobject) OOP_TO_OBJ (oop);
  OOP baseOOP = cObj->storage;
  intptr_t maxOffset;
  if (IS_NIL (baseOOP))
    return true;
  
  offset += COBJECT_OFFSET_OBJ (cObj);
  if (offset < 0)
    return false;

  maxOffset = SIZE_TO_BYTES (NUM_WORDS (OOP_TO_OBJ (baseOOP)));
  if (baseOOP->flags & F_BYTE)
    maxOffset -= (baseOOP->flags & EMPTY_BYTES);

  return (offset + size - 1 < maxOffset);
}