B/combt: Combinations Template. @Purpose: Code to support the combination kind of value constructor. @------------------------------------------------------------------------------- @p Block Format. A combination is like a list, but simpler; it has a fixed, usually short, size. On the other hand, its entries are not all of the same kind as each other. The short block for a combination is simply a pointer to the long block. This consists of one word to hold the strong kind ID, and then one word for each entry in the combination. Thus, a triple combination uses 4 words. @c Constant COMBINATION_KIND_F = 0; ! Strong kind ID Constant COMBINATION_ITEM_BASE = 1; ! List items begin at this entry @p KOV Support. See the "BlockValues.i6t" segment for the specification of the following routines. @c [ COMBINATION_TY_Support task arg1 arg2 arg3; switch(task) { CREATE_KOVS: return COMBINATION_TY_Create(arg1, arg2); DESTROY_KOVS: COMBINATION_TY_Destroy(arg1); MAKEMUTABLE_KOVS: return 1; COPYKIND_KOVS: return COMBINATION_TY_CopyKind(arg1, arg2); COPYQUICK_KOVS: rtrue; COPYSB_KOVS: BlkValueCopySB1(arg1, arg2); KINDDATA_KOVS: return COMBINATION_TY_KindData(arg1); EXTENT_KOVS: return -1; COPY_KOVS: COMBINATION_TY_Copy(arg1, arg2, arg3); COMPARE_KOVS: return COMBINATION_TY_Compare(arg1, arg2); HASH_KOVS: return COMBINATION_TY_Hash(arg1); DEBUG_KOVS: print " = ", (COMBINATION_TY_Say) arg1; } ! We choose not to respond to: CAST_KOVS, READ_FILE_KOVS, WRITE_FILE_KOVS rfalse; ]; @p Creation. A combination is like a list, but simpler; it has a fixed, usually short, size. On the other hand, its entries are not all of the same kind as each other. Combinations are stored as a fixed-sized block of word entries. The first block is the only header information: a pointer to a further structure in memory, describing the kind. The subsequent blocks are the actual records. Thus, a triple $(x, y, z)$ uses 4 words. @c [ COMBINATION_TY_Create kind sb long_block N i bk v; N = KindBaseArity(kind); long_block = FlexAllocate( (COMBINATION_ITEM_BASE+N)*WORDSIZE, COMBINATION_TY, BLK_FLAG_WORD); BlkValueWrite(long_block, COMBINATION_KIND_F, kind, true); for (i=0: i0) print ", "; bk = KindBaseTerm(kind, i); v = BlkValueRead(comb, i+COMBINATION_ITEM_BASE); if (bk == LIST_OF_TY) LIST_OF_TY_Say(v, 1); else PrintKindValuePair(bk, v); } print ")"; ];