// // tuple // Bytecode set support for tuples // F.J. Alberti // case kNewtuple: { // Push fresh tuple of the specified size byte size = fetch(pc); // tuple size pc += ALIGNMENT(1); int s = MMmalloc(m, size, TYPETAB); if (s == NIL) throw Exception(MERRMEM); // Initialise tuple with values for (int i = 0; i < size; i++) { #if defined(SCOL_DEBUG) checkUnderflow(m); #endif m->tape[s+SizeHeader+size-1-i] = m->top[m->pp++]; } m->top[--m->pp] = s<<1|0x00000001; break; } case kNewtuple1: { // Push fresh singleton int s = MMmalloc(m, 1, TYPETAB); if (s == NIL) throw Exception(MERRMEM); // Initialise singleton's unique value with nil m->tape[s+SizeHeader] = m->top[m->pp]; m->top[m->pp] = s<<1|0x00000001; break; } case kNewtuple2: { // Push fresh pair int s = MMmalloc(m, 2, TYPETAB); if (s == NIL) throw Exception(MERRMEM); // Initialise pair values with nil m->tape[s+SizeHeader+1] = m->top[m->pp++]; m->tape[s+SizeHeader] = m->top[m->pp]; m->top[m->pp] = s<<1|0x00000001; break; } case kGetfield: { int p = m->top[m->pp]; // tuple byte i = fetch(pc); // field index pc += ALIGNMENT(1); if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+i]; break; } case kGetfield0: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader]; break; } case kGetfield1: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+1]; break; } case kGetfield2: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+2]; break; } case kGetfield3: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+3]; break; } case kGetfield4: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+4]; break; } case kGetfield5: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+5]; break; } case kGetfield6: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+6]; break; } case kGetfield7: { int p = m->top[m->pp]; // tuple if (p == NIL) break; m->top[m->pp] = m->tape[(p>>1)+SizeHeader+7]; break; } case kSetfield: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple byte i = fetch(pc); // field index pc += ALIGNMENT(1); if (p == NIL) break; m->tape[(p>>1)+SizeHeader+i] = m->top[m->pp] = val; break; } case kSetfield0: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader] = m->top[m->pp] = val; break; } case kSetfield1: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader+1] = m->top[m->pp] = val; break; } case kSetfield2: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader+2] = m->top[m->pp] = val; break; } case kSetfield3: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader+3] = m->top[m->pp] = val; break; } case kSetfield4: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader+4] = m->top[m->pp] = val; break; } case kSetfield5: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader+5] = m->top[m->pp] = val; break; } case kSetfield6: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader+6] = m->top[m->pp] = val; break; } case kSetfield7: { #if defined(SCOL_DEBUG) checkUnderflow(m) #endif int val = m->top[m->pp++]; // value int p = m->top[m->pp]; // tuple if (p == NIL) break; m->tape[(p>>1)+SizeHeader+7] = m->top[m->pp] = val; break; }