#ifndef RENESASBOARD #include #include #endif /*RENESASBOARD*/ #include #include #include "engine.h" #include "heap.h" #include "show.h" #include "debug.h" #include "within.h" #define STACKSIZE 10000 #define HEAPSIZE 10000 #define WIRESIZE 200000 #define nWires 10 #define nBoxes 4 #define nCons 9 uint16 wireCnt() { return nWires; } uint16 boxCnt() { return nBoxes; } wire_t wire[nWires]; box_t box[nBoxes]; STACK stack[STACKSIZE]; HEAP heap[HEAPSIZE + WIRESIZE]; /* box uses the bottom, while wires steal memory from the top */ #ifdef SUPPORT_DEBUG const char *boxName[nBoxes] = { "vending", "change", "output", "input" }; const char *wireName[nWires] = { "vending1->output0", "change1->vending5", "change0->vending4", "vending3->vending3", "vending2->vending2", "input0->vending1", "vending0->vending0", "change2->change2", "vending5->change1", "vending4->change0" }; const char *conName[nCons] = { "CHECKING", "CHANGE", "INPUT", "RELEASE", "CHECK", "ADD", "BAD_COIN", "FAIL", "OK" }; const char *getBoxName(box_t *b) { return boxName[b - box]; } const char *getWireName(wire_t *w) { return wireName[w - wire]; } const char *getConName(uint16 c) { if(c >= nCons) return "?"; return conName[c]; } #else const char *getBoxName(box_t *b) { return NULL; } const char *getWireName(wire_t *w) { return NULL; } const char *getConName(uint16 c) { return NULL; } #endif /*SUPPORT_DEBUG*/ /* Constant Strings */ const char *str_0 = "NO CHANGE\n"; const char *str_1 = "PURCHASE MADE\n"; const char *str_2 = "NOT ENOUGH CREDIT\n"; const char *str_3 = "CHECKING CHANGE\n"; const char *str_4 = "GETTING CHANGE\n"; const char *str_5 = "*"; const char *str_6 = "p; "; const char *str_7 = "CREDIT "; const char *str_8 = "\n"; int exitCode; char **arguments; /* NULL terminated */ extern char **environ; /* NULL terminated */ #include #include #include int16 fd0 = -1; void ioGrpInit0() { if(fd0 != -1) return; fd0 = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in sin; struct hostent *host = gethostbyname("localhost"); memcpy(&sin.sin_addr.s_addr, host->h_addr, host->h_length); sin.sin_family = AF_INET; sin.sin_port = htons(5000); if (connect(fd0, (struct sockaddr *)&sin, sizeof(sin)) < 0) { #ifndef NDEBUG perror("connect"); #endif close(fd0); fd0 = -1; } } #include /* for STDERR_FILENO */ void ioInit2() { ioGrpInit0(); /* @TODO check the fd0 and panic if -1 */ } void ioOutput2() { HEAP *ptr = wire[0].available; if(ptr->tag == TSTR) { char *str = (char*)(ptr+1); int len = strlen(str); if(write(fd0, str, len) != len) { write(STDERR_FILENO, "\n", 16); exit(1); } } else { char buff[1000001]; int len = textValue(buff, 1000000, ptr); if(len != -1) { buff[len] = '\0'; if(write(fd0, buff, len) != len) { write(STDERR_FILENO, "\n", 16); exit(1); } } else { write(fd0, "\n", 21); write(STDERR_FILENO, "\n", 21); exit(1); } } wireConsume(wire+0); } /* requires compile with -pthread */ #include #include "textread.h" /* Note to self: * - this is not strictly thread safe as within the main thread * wire[5].availableFlag is read without any locking. * box[0].state is read/writen without any locking. * - on a single processor machine we will be okay, we _may_ be okay in general... */ pthread_mutex_t lock3; pthread_cond_t condition3; pthread_t thread3; void *ioMain3(void *arg) { textin_t *ti = (textin_t*)malloc(sizeofTextFile()); setTextSourceFile(ti, fd0); setTextType(ti, "t2ci"); while(!isTextClosed(ti)) { if(!parseText(ti, wire[5].available)) { wire[5].available[0].tag = TCON + (isTextEOF(ti) ? EndOfFile : InternalError); wire[5].available[1].lv = 0; closeText(ti); } pthread_mutex_lock(&lock3); wire[5].availableFlag = TRUE; if(box[0].state == BlockedIn) box[0].state = RunnableIn; while(wire[5].availableFlag ) pthread_cond_wait(&condition3, &lock3); pthread_mutex_unlock(&lock3); } free(ti); return NULL; } void ioInit3() { uint32 size; ioGrpInit0(); /* @TODO check the fd0 and panic if -1 */ checkType("t2ci", &size); /* @TODO check the result and panic if FALSE */ hpLimit -= size; /* Allocate the necessary heap for the typed input */ wire[5].available = hpLimit; hpLimit -= size; /* Allocate the necessary heap for the typed input */ wire[5].pending = hpLimit; pthread_mutex_init(&lock3, NULL); pthread_cond_init(&condition3, NULL); pthread_create(&thread3, NULL, &ioMain3, NULL); /* @TODO tell this thread to ignore signals */ } HEAP *ioRead3() { return wire[5].available; } void ioConsume3() { HEAP *temp; pthread_mutex_lock(&lock3); temp = wire[5].available; wire[5].available = wire[5].pending; /* swap the heaps around */ wire[5].pending = temp; wire[5].availableFlag = FALSE; pthread_mutex_unlock(&lock3); pthread_cond_signal(&condition3); } /* * prepare the engine * */ void engineInit() { uint16 i; hpLimit = heap + HEAPSIZE + WIRESIZE; spLimit = STACKSIZE; initWithin(); updateCurrentTime(); for(i=0;i */ wireOutput(wire+6); } if(wire[0].pendingFlag) { /* wire to output */ wireOutput(wire+0); updateCurrentTime(); boxBegin(box+2); ioOutput2(); updateCurrentTime(); boxEnd(box+2); } if(wire[4].pendingFlag) { /* wire to */ wireOutput(wire+4); } if(wire[3].pendingFlag) { /* wire to */ wireOutput(wire+3); } if(wire[9].pendingFlag) { /* wire to change */ wireOutput(wire+9); if(box[1].state == BlockedIn) box[1].state = RunnableIn; } if(wire[8].pendingFlag) { /* wire to change */ wireOutput(wire+8); if(box[1].state == BlockedIn) box[1].state = RunnableIn; } box[0].blockPattern = 0x8000; box[0].state = RunnableIn; } } /* box change */ if(box[1].state == RunnableOut) { uint16 blocking = box[1].blockPattern; if(blocking) { blocking = 0x0000; if(wire[2].availableFlag && wire[2].pendingFlag) blocking |= 0x0001; if(wire[1].availableFlag && wire[1].pendingFlag) blocking |= 0x0002; if(wire[7].availableFlag && wire[7].pendingFlag) blocking |= 0x0004; box[1].blockPattern = blocking; box[1].state = BlockedOut; } if(!blocking) { if(wire[2].pendingFlag) { /* wire to vending */ wireOutput(wire+2); if(box[0].state == BlockedIn) box[0].state = RunnableIn; } if(wire[1].pendingFlag) { /* wire to vending */ wireOutput(wire+1); if(box[0].state == BlockedIn) box[0].state = RunnableIn; } if(wire[7].pendingFlag) { /* wire to */ wireOutput(wire+7); } box[1].blockPattern = 0x8000; box[1].state = RunnableIn; } } } /* * main function of the engine * */ void engineRun() { if(setjmp(excJmp) == 0) goto vending_init; /* next init */ __humeHandle: #ifdef SUPPORT_DEBUG { exception_e exc = stack[sp-4].hp->tag - TCON; dumpException(stderr, exc); debugException(exc); } #endif /* No handlers */ currentBox->state = Dead; #ifdef SUPPORT_DEBUG dumpBox(stderr, currentBox); #endif /*SUPPORT_DEBUG*/ return; /* terminate on unhandled exception */ __humeNext: switch(currentBox - box) { case 0: goto change; /* next box */ case 1: goto __humeSuperstep; /* exit run */ case 2: goto __humeSuperstep; /* exit run */ case 3: goto __humeSuperstep; /* exit run */ } return; /* unreachable code? */ /* * Main scheduling loop * */ __humeSuperstep: currentBox = NULL; /* so the debugger knows we are superstep-ing */ output(); schedules++; if((nSchedules != 0) && (schedules > nSchedules)) return; goto vending; /* next box */ /* * Function call return (i.e. goto ) * */ __humeReturn: switch(pc) { case 40: goto __humeReturn_40; case 44: goto __humeReturn_44; case 76: goto __humeReturn_76; case 103: goto __humeReturn_103; case 121: goto __humeReturn_121; case 135: goto __humeReturn_135; case 140: goto __humeReturn_140; case 171: goto __humeReturn_171; case 175: goto __humeReturn_175; case 179: goto __humeReturn_179; case 196: goto __humeReturn_196; case 210: goto __humeReturn_210; case 226: goto __humeReturn_226; case 231: goto __humeReturn_231; case 264: goto __humeReturn_264; case 270: goto __humeReturn_270; case 292: goto __humeReturn_292; case 314: goto __humeReturn_314; case 316: goto __humeReturn_316; case 381: goto __humeReturn_381; case 416: goto __humeReturn_416; case 442: goto __humeReturn_442; case 462: goto __humeReturn_462; case 483: goto __humeReturn_483; case 487: goto __humeReturn_487; default: throwException(InternalError); } /* * function f_values * - rules=1 * */ f_values: /* -------------- 3: CreateFrame 0 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(0); rp = sp; f_values_0: /* -------------- 6: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 7: MatchedRule */ sp = rp; /* -------------- 8: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 9: MkInt 2 */ stack[inc_sp()].hp = mkInt(2); /* -------------- 10: MkInt 5 */ stack[inc_sp()].hp = mkInt(5); /* -------------- 11: MkInt 10 */ stack[inc_sp()].hp = mkInt(10); /* -------------- 12: MkInt 20 */ stack[inc_sp()].hp = mkInt(20); /* -------------- 13: MkInt 50 */ stack[inc_sp()].hp = mkInt(50); /* -------------- 14: MkInt 100 */ stack[inc_sp()].hp = mkInt(100); /* -------------- 15: MkInt 200 */ stack[inc_sp()].hp = mkInt(200); /* -------------- 16: MkVector 8 */ { HEAP *tup = mkVector(8); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } /* -------------- 17: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ /* * function f_showCredit * - rules=1 * */ f_showCredit: /* -------------- 21: CreateFrame 1 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(1); rp = sp; f_showCredit_0: /* -------------- 24: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 25: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 26: MatchedRule */ sp = rp; /* -------------- 27: MkString "\n" */ stack[inc_sp()].hp = mkString((char*)str_8); /* -------------- 28: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 29: CallPrim "show" */ { HEAP *arg = stack[--sp].hp; stack[sp++].hp = show(arg); } /* -------------- 30: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 31: MkString "CREDIT " */ stack[inc_sp()].hp = mkString((char*)str_7); /* -------------- 32: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 33: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ /* * function f_release * - rules=2 * */ f_release: /* -------------- 37: CreateFrame 4 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(4); rp = sp; f_release_0: /* -------------- 40: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 41: MatchInt 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep[1].lv != 0) { goto f_release_1; /* next rule */ } } /* -------------- 42: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 43: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 45: MatchedRule */ sp = rp; /* -------------- 46: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 47: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 48: MkTuple 2 */ { HEAP *tup = mkTup(2); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } /* -------------- 49: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ f_release_1: /* -------------- 52: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 53: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 54: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 55: MatchVar 2 */ stack[VAR(2)] = stack[--mp]; /* -------------- 56: MatchVar 3 */ stack[VAR(3)] = stack[--mp]; /* -------------- 57: MatchedRule */ sp = rp; /* -------------- 58: Call "l_release_1_0" */ stack[inc_sp()].pc = 40; /* __humeReturn_40 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto l_release_1_0; __humeReturn_40: /* -------------- 59: Goto "ln_release_1_0" */ goto ln_release_1_0; /* * function l_release_1_0 * - rules=1 * */ l_release_1_0: /* -------------- 62: CreateFrame 1 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(1); rp = sp; /* -------------- 63: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 64: Call "f_values" */ stack[inc_sp()].pc = 44; /* __humeReturn_44 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_44: /* -------------- 65: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 66: PushVarF 1 0 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 0)]; } /* -------------- 67: CallPrim "div" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; int32 denom; #ifndef NDEBUG if(arg1->tag != TINT || arg2->tag != TINT) throwException(InternalError); #endif /*NDEBUG*/ denom = (arg2+1)->lv; if(denom == 0.0) throwException(DivisionByZero); stack[sp++].hp = mkInt((arg1+1)->lv / denom); } /* -------------- 68: MakeVar 0 */ stack[VAR(0)] = stack[--sp]; /* -------------- 69: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 70: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 71: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 72: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 73: CallPrim ">" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg2, arg1, FALSE, TRUE)); } /* -------------- 74: If "t_release_1_1" */ if(stack[--sp].hp[1].lv == TRUE) goto t_release_1_1; /* -------------- 75: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 76: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 77: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 78: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 79: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 80: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 81: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 82: CallPrim "-" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv - (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv - (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 83: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 84: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 85: CallPrim "update" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; HEAP *arg3 = stack[--sp].hp; /* Rebased to 1 */ if(arg2->tag == TINT && arg1->tag == TVECTOR) { int32 index = (arg2+1)->lv; if(index > 0 && index <= (arg1+1)->lv) { uint32 vsize = (arg1+1)->lv; HEAP *vec = hp; memcpy(vec, arg1, sizeof(HEAP)*(vsize+2)); /* clone the vector */ hp += vsize+2; (vec+1+index)->hp = arg3; /* insert new value */ stack[sp++].hp = vec; } else throwException(IndexOutOfBounds); /* @TODO list, string , tuple ? */ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 86: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 87: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 88: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 89: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 90: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 91: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 92: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 93: CallPrim "update" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; HEAP *arg3 = stack[--sp].hp; /* Rebased to 1 */ if(arg2->tag == TINT && arg1->tag == TVECTOR) { int32 index = (arg2+1)->lv; if(index > 0 && index <= (arg1+1)->lv) { uint32 vsize = (arg1+1)->lv; HEAP *vec = hp; memcpy(vec, arg1, sizeof(HEAP)*(vsize+2)); /* clone the vector */ hp += vsize+2; (vec+1+index)->hp = arg3; /* insert new value */ stack[sp++].hp = vec; } else throwException(IndexOutOfBounds); /* @TODO list, string , tuple ? */ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 94: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 95: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 96: Call "f_values" */ stack[inc_sp()].pc = 76; /* __humeReturn_76 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_76: /* -------------- 97: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 98: CallPrim "*" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv * (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv * (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 99: PushVarF 1 0 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 0)]; } /* -------------- 100: CallPrim "-" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv - (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv - (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 101: TailCall "f_release_0" 4 1 4 */ slp = stack[PREV_LINK()].sp; /* function = (func_t *)stack[PREV_FN()]; no longer needed */ fp = stack[PREV_FP()].sp; stack[ARG(0)] = stack[sp-1]; stack[ARG(1)] = stack[sp-2]; stack[ARG(2)] = stack[sp-3]; stack[ARG(3)] = stack[sp-4]; sp = fp+4; rp = sp; goto f_release_0; t_release_1_1: /* -------------- 105: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 106: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 107: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 108: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 109: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 110: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 111: CallPrim "update" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; HEAP *arg3 = stack[--sp].hp; /* Rebased to 1 */ if(arg2->tag == TINT && arg1->tag == TVECTOR) { int32 index = (arg2+1)->lv; if(index > 0 && index <= (arg1+1)->lv) { uint32 vsize = (arg1+1)->lv; HEAP *vec = hp; memcpy(vec, arg1, sizeof(HEAP)*(vsize+2)); /* clone the vector */ hp += vsize+2; (vec+1+index)->hp = arg3; /* insert new value */ stack[sp++].hp = vec; } else throwException(IndexOutOfBounds); /* @TODO list, string , tuple ? */ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 112: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 113: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 114: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 115: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 116: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 117: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 118: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 119: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 120: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 121: CallPrim "update" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; HEAP *arg3 = stack[--sp].hp; /* Rebased to 1 */ if(arg2->tag == TINT && arg1->tag == TVECTOR) { int32 index = (arg2+1)->lv; if(index > 0 && index <= (arg1+1)->lv) { uint32 vsize = (arg1+1)->lv; HEAP *vec = hp; memcpy(vec, arg1, sizeof(HEAP)*(vsize+2)); /* clone the vector */ hp += vsize+2; (vec+1+index)->hp = arg3; /* insert new value */ stack[sp++].hp = vec; } else throwException(IndexOutOfBounds); /* @TODO list, string , tuple ? */ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 122: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 123: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 124: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 125: PushVarF 1 3 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 3)]; } /* -------------- 126: Call "f_values" */ stack[inc_sp()].pc = 103; /* __humeReturn_103 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_103: /* -------------- 127: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 128: CallPrim "*" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv * (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv * (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 129: PushVarF 1 0 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 0)]; } /* -------------- 130: CallPrim "-" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv - (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv - (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 131: TailCall "f_release_0" 4 1 4 */ slp = stack[PREV_LINK()].sp; /* function = (func_t *)stack[PREV_FN()]; no longer needed */ fp = stack[PREV_FP()].sp; stack[ARG(0)] = stack[sp-1]; stack[ARG(1)] = stack[sp-2]; stack[ARG(2)] = stack[sp-3]; stack[ARG(3)] = stack[sp-4]; sp = fp+4; rp = sp; goto f_release_0; n_release_1_1: /* -------------- 134: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ ln_release_1_0: /* -------------- 138: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ /* * function f_MAXCOINS * - rules=1 * */ f_MAXCOINS: /* -------------- 142: CreateFrame 0 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(0); rp = sp; f_MAXCOINS_0: /* -------------- 145: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 146: MatchedRule */ sp = rp; /* -------------- 147: MkInt 8 */ stack[inc_sp()].hp = mkInt(8); /* -------------- 148: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ /* * function f_showChange * - rules=1 * */ f_showChange: /* -------------- 152: CreateFrame 2 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(2); rp = sp; f_showChange_0: /* -------------- 155: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 156: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 157: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 158: MatchedRule */ sp = rp; /* -------------- 159: Call "f_MAXCOINS" */ stack[inc_sp()].pc = 121; /* __humeReturn_121 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_MAXCOINS; __humeReturn_121: /* -------------- 160: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 161: CallPrim ">" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg2, arg1, FALSE, TRUE)); } /* -------------- 162: If "t_showChange_0_0" */ if(stack[--sp].hp[1].lv == TRUE) goto t_showChange_0_0; /* -------------- 163: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 164: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 165: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 166: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 167: CallPrim "==" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg1, arg2, TRUE, FALSE)); } /* -------------- 168: If "t_showChange_0_1" */ if(stack[--sp].hp[1].lv == TRUE) goto t_showChange_0_1; /* -------------- 169: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 170: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 171: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 172: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 173: Call "f_showChange" */ stack[inc_sp()].pc = 135; /* __humeReturn_135 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_showChange; __humeReturn_135: /* -------------- 174: Slide 2 */ { STACK tos = stack[sp-1]; sp = sp - 3; stack[inc_sp()] = tos; } /* -------------- 175: MkString "p; " */ stack[inc_sp()].hp = mkString((char*)str_6); /* -------------- 176: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 177: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 178: Call "f_values" */ stack[inc_sp()].pc = 140; /* __humeReturn_140 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_140: /* -------------- 179: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 180: CallPrim "show" */ { HEAP *arg = stack[--sp].hp; stack[sp++].hp = show(arg); } /* -------------- 181: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 182: MkString "*" */ stack[inc_sp()].hp = mkString((char*)str_5); /* -------------- 183: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 184: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 185: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 186: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 187: CallPrim "show" */ { HEAP *arg = stack[--sp].hp; stack[sp++].hp = show(arg); } /* -------------- 188: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 189: Goto "n_showChange_0_1" */ goto n_showChange_0_1; t_showChange_0_1: /* -------------- 192: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 193: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 194: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 195: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 196: TailCall "f_showChange_0" 2 0 2 */ stack[ARG(0)] = stack[sp-1]; stack[ARG(1)] = stack[sp-2]; sp = fp+2; rp = sp; goto f_showChange_0; n_showChange_0_1: /* -------------- 199: Goto "n_showChange_0_0" */ goto n_showChange_0_0; t_showChange_0_0: /* -------------- 202: MkString "\n" */ stack[inc_sp()].hp = mkString((char*)str_8); n_showChange_0_0: /* -------------- 205: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ /* * function f_check * - rules=2 * */ f_check: /* -------------- 209: CreateFrame 3 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(3); rp = sp; f_check_0: /* -------------- 212: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 213: MatchInt 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep[1].lv != 0) { goto f_check_1; /* next rule */ } } /* -------------- 216: MatchedRule */ sp = rp; /* -------------- 217: MkCon "OK" 0 */ stack[inc_sp()].hp = mkCon(40, 0); /* -------------- 218: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ f_check_1: /* -------------- 221: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 222: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 223: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 224: MatchVar 2 */ stack[VAR(2)] = stack[--mp]; /* -------------- 225: MatchedRule */ sp = rp; /* -------------- 226: Call "f_MAXCOINS" */ stack[inc_sp()].pc = 171; /* __humeReturn_171 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_MAXCOINS; __humeReturn_171: /* -------------- 227: PushVar 2 */ stack[inc_sp()] = stack[VAR(2)]; /* -------------- 228: CallPrim ">" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg2, arg1, FALSE, TRUE)); } /* -------------- 229: If "t_check_1_0" */ if(stack[--sp].hp[1].lv == TRUE) goto t_check_1_0; /* -------------- 230: Call "l_check_1_1" */ stack[inc_sp()].pc = 175; /* __humeReturn_175 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto l_check_1_1; __humeReturn_175: /* -------------- 231: Goto "ln_check_1_1" */ goto ln_check_1_1; /* * function l_check_1_1 * - rules=2 * */ l_check_1_1: /* -------------- 234: CreateFrame 1 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(1); rp = sp; /* -------------- 235: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 236: Call "f_values" */ stack[inc_sp()].pc = 179; /* __humeReturn_179 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_179: /* -------------- 237: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 238: PushVarF 1 0 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 0)]; } /* -------------- 239: CallPrim "div" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; int32 denom; #ifndef NDEBUG if(arg1->tag != TINT || arg2->tag != TINT) throwException(InternalError); #endif /*NDEBUG*/ denom = (arg2+1)->lv; if(denom == 0.0) throwException(DivisionByZero); stack[sp++].hp = mkInt((arg1+1)->lv / denom); } /* -------------- 240: MakeVar 0 */ stack[VAR(0)] = stack[--sp]; /* -------------- 241: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 242: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 243: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 244: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 245: CallPrim ">" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg2, arg1, FALSE, TRUE)); } /* -------------- 246: If "t_check_1_2" */ if(stack[--sp].hp[1].lv == TRUE) goto t_check_1_2; /* -------------- 247: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 248: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 249: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 250: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 251: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 252: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 253: Call "f_values" */ stack[inc_sp()].pc = 196; /* __humeReturn_196 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_196: /* -------------- 254: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 255: CallPrim "*" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv * (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv * (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 256: PushVarF 1 0 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 0)]; } /* -------------- 257: CallPrim "-" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv - (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv - (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 258: TailCall "f_check_0" 3 1 3 */ slp = stack[PREV_LINK()].sp; /* function = (func_t *)stack[PREV_FN()]; no longer needed */ fp = stack[PREV_FP()].sp; stack[ARG(0)] = stack[sp-1]; stack[ARG(1)] = stack[sp-2]; stack[ARG(2)] = stack[sp-3]; sp = fp+3; rp = sp; goto f_check_0; t_check_1_2: /* -------------- 262: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 263: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 264: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 265: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 266: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 267: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 268: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 269: PushVarF 1 2 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 2)]; } /* -------------- 270: Call "f_values" */ stack[inc_sp()].pc = 210; /* __humeReturn_210 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_210: /* -------------- 271: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 272: CallPrim "*" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv * (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv * (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 273: PushVarF 1 0 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 0)]; } /* -------------- 274: CallPrim "-" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv - (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv - (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 275: TailCall "f_check_0" 3 1 3 */ slp = stack[PREV_LINK()].sp; /* function = (func_t *)stack[PREV_FN()]; no longer needed */ fp = stack[PREV_FP()].sp; stack[ARG(0)] = stack[sp-1]; stack[ARG(1)] = stack[sp-2]; stack[ARG(2)] = stack[sp-3]; sp = fp+3; rp = sp; goto f_check_0; n_check_1_2: /* -------------- 278: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ ln_check_1_1: /* -------------- 282: Goto "n_check_1_0" */ goto n_check_1_0; t_check_1_0: /* -------------- 285: MkCon "FAIL" 0 */ stack[inc_sp()].hp = mkCon(39, 0); n_check_1_0: /* -------------- 288: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ /* * function f_add * - rules=1 * */ f_add: /* -------------- 292: CreateFrame 3 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(3); rp = sp; f_add_0: /* -------------- 295: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 296: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 297: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 298: MatchVar 2 */ stack[VAR(2)] = stack[--mp]; /* -------------- 299: MatchedRule */ sp = rp; /* -------------- 300: Call "f_MAXCOINS" */ stack[inc_sp()].pc = 226; /* __humeReturn_226 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_MAXCOINS; __humeReturn_226: /* -------------- 301: PushVar 2 */ stack[inc_sp()] = stack[VAR(2)]; /* -------------- 302: CallPrim ">" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg2, arg1, FALSE, TRUE)); } /* -------------- 303: If "t_add_0_0" */ if(stack[--sp].hp[1].lv == TRUE) goto t_add_0_0; /* -------------- 304: PushVar 2 */ stack[inc_sp()] = stack[VAR(2)]; /* -------------- 305: Call "f_values" */ stack[inc_sp()].pc = 231; /* __humeReturn_231 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_values; __humeReturn_231: /* -------------- 306: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 307: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 308: CallPrim "==" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg1, arg2, TRUE, FALSE)); } /* -------------- 309: If "t_add_0_1" */ if(stack[--sp].hp[1].lv == TRUE) goto t_add_0_1; /* -------------- 310: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 311: PushVar 2 */ stack[inc_sp()] = stack[VAR(2)]; /* -------------- 312: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 313: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 314: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 315: TailCall "f_add_0" 3 0 3 */ stack[ARG(0)] = stack[sp-1]; stack[ARG(1)] = stack[sp-2]; stack[ARG(2)] = stack[sp-3]; sp = fp+3; rp = sp; goto f_add_0; t_add_0_1: /* -------------- 319: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 320: PushVar 2 */ stack[inc_sp()] = stack[VAR(2)]; /* -------------- 321: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 322: CallPrim "@" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; /* Rebased to one */ if(arg2->tag == TINT) { int32 index = (arg2+1)->lv; if((arg1->tag == TVECTOR) || (arg1->tag == TTUP)) { if(index > 0 && index <= (arg1+1)->lv) { stack[sp++].hp = (arg1+1+index)->hp; } else throwException(IndexOutOfBounds); #ifdef SUPPORT_STRING } else if(arg1->tag == TSTR) { char *arr = (char*)(arg1+1); if((index > 0) && (index <= strlen(arr))) { stack[sp++].hp = mkChar(arr[index-1]); } else throwException(IndexOutOfBounds); #endif /*SUPPORT_STRING*/ } else if(arg1->tag >= TCON) { /* assume they are lists */ uint32 cnt = 1; while(arg1[1].lv == 2) { /* assume size=2 is a cons */ if(cnt == index) { stack[sp++].hp = arg1[2].hp; cnt = 0; /* indicate success */ break; } cnt++; arg1 = arg1[3].hp; } if(cnt != 0) throwException(IndexOutOfBounds); } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 323: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 324: PushVar 2 */ stack[inc_sp()] = stack[VAR(2)]; /* -------------- 325: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 326: CallPrim "update" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; HEAP *arg3 = stack[--sp].hp; /* Rebased to 1 */ if(arg2->tag == TINT && arg1->tag == TVECTOR) { int32 index = (arg2+1)->lv; if(index > 0 && index <= (arg1+1)->lv) { uint32 vsize = (arg1+1)->lv; HEAP *vec = hp; memcpy(vec, arg1, sizeof(HEAP)*(vsize+2)); /* clone the vector */ hp += vsize+2; (vec+1+index)->hp = arg3; /* insert new value */ stack[sp++].hp = vec; } else throwException(IndexOutOfBounds); /* @TODO list, string , tuple ? */ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } n_add_0_1: /* -------------- 329: Goto "n_add_0_0" */ goto n_add_0_0; t_add_0_0: /* -------------- 332: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 333: Raise "BAD_COIN" */ setException(38, stack[--sp].hp); goto __humeHandle; n_add_0_0: /* -------------- 336: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ /* * box change * - rules=3 * - nInputs=3 nOutputs=3 * */ change: /* -------------- 339: Label "change" */ if(box[1].state != RunnableIn) goto __humeSuperstep; /* exit run */ currentBox = box + 1; hp = heap; sp = 0; fp = 0; slp = 0; hpSoftLimit = heap + 152; spSoftLimit = 48; /* -------------- 340: Extension.CopyAllInputs */ stack[inc_sp()].hp = wireRead(wire+7); /* wire from */ stack[inc_sp()].hp = wireRead(wire+8); /* wire from vending */ stack[inc_sp()].hp = wireRead(wire+9); /* wire from vending */ /* -------------- 343: Push 3 */ inc_spn(3); /* -------------- 344: CreateFrame 2 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(2); rp = sp; change_0: /* -------------- 348: Extension.AvailSet 0 1 2 */ if(!wire[9].availableFlag || !wire[8].availableFlag || !wire[7].availableFlag) { goto change_1; /* next rule */ } /* -------------- 347: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 349: MatchCon "ADD" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+37) { goto change_1; /* next rule */ } } /* -------------- 351: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 353: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 357: MatchedRule */ sp = rp; /* -------------- 354: Extension.ConsumeSet 0 1 2 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+9); box[0].blockPattern &= 0xffef; if(!box[0].blockPattern) box[0].state = RunnableOut; wireConsume(wire+8); box[0].blockPattern &= 0xffdf; if(!box[0].blockPattern) box[0].state = RunnableOut; wireConsume(wire+7); #ifdef SUPPORT_DEBUG boxBegin(box+1); #endif /*SUPPORT_DEBUG*/ /* -------------- 358: Call "l_change_0_0" */ stack[inc_sp()].pc = 264; /* __humeReturn_264 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto l_change_0_0; __humeReturn_264: /* -------------- 359: Goto "ln_change_0_0" */ goto ln_change_0_0; /* * function l_change_0_0 * - rules=1 * */ l_change_0_0: /* -------------- 362: CreateFrame 1 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(1); rp = sp; /* -------------- 363: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 364: PushVarF 1 1 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 1)]; } /* -------------- 365: PushVarF 1 0 */ { SP lfp = slp; lfp = stack[PREV_LINKF(lfp)].sp; stack[inc_sp()] = stack[VARF(lfp, 0)]; } /* -------------- 366: Call "f_add" */ stack[inc_sp()].pc = 270; /* __humeReturn_270 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_add; __humeReturn_270: /* -------------- 367: Slide 3 */ { STACK tos = stack[sp-1]; sp = sp - 4; stack[inc_sp()] = tos; } /* -------------- 368: MakeVar 0 */ stack[VAR(0)] = stack[--sp]; /* -------------- 369: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 370: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 371: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 372: MkTuple 3 */ { HEAP *tup = mkTup(3); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } /* -------------- 373: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ ln_change_0_0: /* -------------- 377: Unpack */ { HEAP *nodep = stack[--sp].hp; uint32 i; uint32 size = nodep[1].lv; for (i = 0; i < size; i++) stack[inc_sp()].hp = nodep[1+size-i].hp; mp = sp; } change_exit: /* -------------- 378: CheckOutputs */ updateCurrentTime(); boxEnd(box+1); wireSetPending(wire+2, 10000, stack[sp-1].hp); /* wire to vending */ wireSetPending(wire+1, 10000, stack[sp-2].hp); /* wire to vending */ wireSetPending(wire+7, 10000, stack[sp-3].hp); /* wire to */ box[1].state = RunnableOut; goto __humeSuperstep; /* exit run */ change_1: /* -------------- 386: Extension.AvailSet 0 1 2 */ if(!wire[9].availableFlag || !wire[8].availableFlag || !wire[7].availableFlag) { goto change_2; /* next rule */ } /* -------------- 385: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 387: MatchCon "CHECK" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+36) { goto change_2; /* next rule */ } } /* -------------- 389: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 391: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 395: MatchedRule */ sp = rp; /* -------------- 392: Extension.ConsumeSet 0 1 2 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+9); box[0].blockPattern &= 0xffef; if(!box[0].blockPattern) box[0].state = RunnableOut; wireConsume(wire+8); box[0].blockPattern &= 0xffdf; if(!box[0].blockPattern) box[0].state = RunnableOut; wireConsume(wire+7); #ifdef SUPPORT_DEBUG boxBegin(box+1); #endif /*SUPPORT_DEBUG*/ /* -------------- 396: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 397: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 398: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 399: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 400: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 401: Call "f_check" */ stack[inc_sp()].pc = 292; /* __humeReturn_292 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_check; __humeReturn_292: /* -------------- 402: Slide 3 */ { STACK tos = stack[sp-1]; sp = sp - 4; stack[inc_sp()] = tos; } /* -------------- 405: Goto "change_exit" */ goto change_exit; change_2: /* -------------- 413: Extension.AvailSet 0 1 2 */ if(!wire[9].availableFlag || !wire[8].availableFlag || !wire[7].availableFlag) { box[1].state = BlockedIn; goto __humeSuperstep; /* exit run */ } /* -------------- 412: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 414: MatchCon "RELEASE" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+35) { box[1].state = BlockedIn; goto __humeSuperstep; /* exit run */ } } /* -------------- 416: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 418: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 422: MatchedRule */ sp = rp; /* -------------- 419: Extension.ConsumeSet 0 1 2 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+9); box[0].blockPattern &= 0xffef; if(!box[0].blockPattern) box[0].state = RunnableOut; wireConsume(wire+8); box[0].blockPattern &= 0xffdf; if(!box[0].blockPattern) box[0].state = RunnableOut; wireConsume(wire+7); #ifdef SUPPORT_DEBUG boxBegin(box+1); #endif /*SUPPORT_DEBUG*/ /* -------------- 423: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 424: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 425: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 426: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 427: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 428: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 429: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 430: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 431: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 432: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 433: MkVector 8 */ { HEAP *tup = mkVector(8); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } /* -------------- 434: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 435: Call "f_release" */ stack[inc_sp()].pc = 314; /* __humeReturn_314 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_release; __humeReturn_314: /* -------------- 436: Slide 4 */ { STACK tos = stack[sp-1]; sp = sp - 5; stack[inc_sp()] = tos; } /* -------------- 437: Call "c_change_2_0" */ stack[inc_sp()].pc = 316; /* __humeReturn_316 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto c_change_2_0; __humeReturn_316: /* -------------- 438: Slide 1 */ { STACK tos = stack[sp-1]; sp = sp - 2; stack[inc_sp()] = tos; } /* -------------- 439: Goto "cn_change_2_0" */ goto cn_change_2_0; c_change_2_0: /* * function change_2_0 * - rules=1 * */ change_2_0: /* -------------- 444: CreateFrame 2 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(2); rp = sp; change_2_0_0: /* -------------- 447: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 448: MatchTuple 2 */ --mp; /* -------------- 449: CopyArg 0 */ stack[inc_sp()] = stack[ARG(0)]; /* -------------- 450: Unpack */ { HEAP *nodep = stack[--sp].hp; uint32 i; uint32 size = nodep[1].lv; for (i = 0; i < size; i++) stack[inc_sp()].hp = nodep[1+size-i].hp; mp = sp; } /* -------------- 451: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 452: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 454: MatchedRule */ sp = rp; /* -------------- 455: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 456: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 457: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 458: MkTuple 3 */ { HEAP *tup = mkTup(3); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } /* -------------- 459: Return */ pc = stack[RET_PC()].pc; slp = stack[PREV_LINK()].sp; stack[RET_VALUE()] = stack[sp-1]; sp = RET_VALUE()+1; fp = stack[PREV_FP()].sp; goto __humeReturn; /* pc */ cn_change_2_0: /* -------------- 463: Unpack */ { HEAP *nodep = stack[--sp].hp; uint32 i; uint32 size = nodep[1].lv; for (i = 0; i < size; i++) stack[inc_sp()].hp = nodep[1+size-i].hp; mp = sp; } /* -------------- 464: Goto "change_exit" */ goto change_exit; /* * box vending * - rules=6 * - nInputs=6 nOutputs=6 * */ vending: /* -------------- 470: Label "vending" */ if(box[0].state != RunnableIn) goto change; /* next box */ currentBox = box + 0; hp = heap; sp = 0; fp = 0; slp = 0; hpSoftLimit = heap + 294; spSoftLimit = 47; /* -------------- 471: Extension.CopyAllInputs */ stack[inc_sp()].hp = wireRead(wire+1); /* wire from change */ stack[inc_sp()].hp = wireRead(wire+2); /* wire from change */ stack[inc_sp()].hp = wireRead(wire+3); /* wire from */ stack[inc_sp()].hp = wireRead(wire+4); /* wire from */ stack[inc_sp()].hp = ioRead3(); { const int16 type = stack[sp-1].hp->tag - TCON; /* Stream exception? */ if((type >= BUILTIN_EXCEPTIONS_OFFSET) && (type < USER_CONSTRUCTORS_OFFSET)) { ioConsume3(); /* Consume, otherwise forever receive exceptions */ throwException(type); } } stack[inc_sp()].hp = wireRead(wire+6); /* wire from */ /* -------------- 477: Push 3 */ inc_spn(3); /* -------------- 478: CreateFrame 2 */ if(slp == 0) slp = sp + 1; stack[inc_sp()].sp = fp; fp = sp; inc_spn(2); rp = sp; vending_0: /* -------------- 482: Extension.AvailSet 0 1 2 */ if(!wire[6].availableFlag || !wire[5].availableFlag || !wire[4].availableFlag) { goto vending_1; /* next rule */ } /* -------------- 481: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 483: MatchCon "INPUT" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+34) { goto vending_1; /* next rule */ } } /* -------------- 485: MatchTuple 2 */ --mp; /* -------------- 487: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 488: MatchNone */ --mp; /* -------------- 489: MatchNone */ --mp; /* -------------- 490: MatchNone */ --mp; /* -------------- 491: CopyArg 1 */ stack[inc_sp()] = stack[ARG(1)]; /* -------------- 492: Unpack */ { HEAP *nodep = stack[--sp].hp; uint32 i; uint32 size = nodep[1].lv; for (i = 0; i < size; i++) stack[inc_sp()].hp = nodep[1+size-i].hp; mp = sp; } /* -------------- 493: MatchChar 'c' */ { HEAP *nodep = stack[--mp].hp; if(nodep[1].lv != 'c') { goto vending_1; /* next rule */ } } /* -------------- 494: MatchInt 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep[1].lv != 0) { goto vending_1; /* next rule */ } } /* -------------- 499: MatchedRule */ sp = rp; /* -------------- 496: Extension.ConsumeSet 0 1 2 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+6); ioConsume3(); box[3].blockPattern &= 0xfffe; if(!box[3].blockPattern) box[3].state = RunnableOut; wireConsume(wire+4); #ifdef SUPPORT_DEBUG boxBegin(box+0); #endif /*SUPPORT_DEBUG*/ /* -------------- 500: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 501: MkCon "RELEASE" 0 */ stack[inc_sp()].hp = mkCon(35, 0); /* -------------- 502: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 503: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 504: MkString "GETTING CHANGE\n" */ stack[inc_sp()].hp = mkString((char*)str_4); /* -------------- 505: MkCon "CHANGE" 0 */ stack[inc_sp()].hp = mkCon(33, 0); vending_exit: /* -------------- 508: CheckOutputs */ updateCurrentTime(); boxEnd(box+0); wireSetPending(wire+6, 10000, stack[sp-1].hp); /* wire to */ wireSetPending(wire+0, 10000, stack[sp-2].hp); /* wire to output */ wireSetPending(wire+4, 10000, stack[sp-3].hp); /* wire to */ wireSetPending(wire+3, 10000, stack[sp-4].hp); /* wire to */ wireSetPending(wire+9, 10000, stack[sp-5].hp); /* wire to change */ wireSetPending(wire+8, 10000, stack[sp-6].hp); /* wire to change */ box[0].state = RunnableOut; goto change; /* next box */ vending_1: /* -------------- 519: Extension.AvailSet 0 1 2 */ if(!wire[6].availableFlag || !wire[5].availableFlag || !wire[4].availableFlag) { goto vending_2; /* next rule */ } /* -------------- 518: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 520: MatchCon "INPUT" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+34) { goto vending_2; /* next rule */ } } /* -------------- 522: MatchTuple 2 */ --mp; /* -------------- 524: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 525: MatchNone */ --mp; /* -------------- 526: MatchNone */ --mp; /* -------------- 527: MatchNone */ --mp; /* -------------- 528: CopyArg 1 */ stack[inc_sp()] = stack[ARG(1)]; /* -------------- 529: Unpack */ { HEAP *nodep = stack[--sp].hp; uint32 i; uint32 size = nodep[1].lv; for (i = 0; i < size; i++) stack[inc_sp()].hp = nodep[1+size-i].hp; mp = sp; } /* -------------- 530: MatchChar 'c' */ { HEAP *nodep = stack[--mp].hp; if(nodep[1].lv != 'c') { goto vending_2; /* next rule */ } } /* -------------- 531: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 536: MatchedRule */ sp = rp; /* -------------- 533: Extension.ConsumeSet 0 1 2 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+6); ioConsume3(); box[3].blockPattern &= 0xfffe; if(!box[3].blockPattern) box[3].state = RunnableOut; wireConsume(wire+4); #ifdef SUPPORT_DEBUG boxBegin(box+0); #endif /*SUPPORT_DEBUG*/ /* -------------- 537: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 538: MkCon "ADD" 0 */ stack[inc_sp()].hp = mkCon(37, 0); /* -------------- 539: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 540: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 541: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 542: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 543: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 544: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 545: CallPrim "+" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv + (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv + (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 546: Call "f_showCredit" */ stack[inc_sp()].pc = 381; /* __humeReturn_381 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_showCredit; __humeReturn_381: /* -------------- 547: Slide 1 */ { STACK tos = stack[sp-1]; sp = sp - 2; stack[inc_sp()] = tos; } /* -------------- 548: MkCon "INPUT" 0 */ stack[inc_sp()].hp = mkCon(34, 0); /* -------------- 551: Goto "vending_exit" */ goto vending_exit; vending_2: /* -------------- 562: Extension.AvailSet 0 1 2 */ if(!wire[6].availableFlag || !wire[5].availableFlag || !wire[4].availableFlag) { goto vending_3; /* next rule */ } /* -------------- 561: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 563: MatchCon "INPUT" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+34) { goto vending_3; /* next rule */ } } /* -------------- 565: MatchTuple 2 */ --mp; /* -------------- 567: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 568: MatchNone */ --mp; /* -------------- 569: MatchNone */ --mp; /* -------------- 570: MatchNone */ --mp; /* -------------- 571: CopyArg 1 */ stack[inc_sp()] = stack[ARG(1)]; /* -------------- 572: Unpack */ { HEAP *nodep = stack[--sp].hp; uint32 i; uint32 size = nodep[1].lv; for (i = 0; i < size; i++) stack[inc_sp()].hp = nodep[1+size-i].hp; mp = sp; } /* -------------- 573: MatchChar 'd' */ { HEAP *nodep = stack[--mp].hp; if(nodep[1].lv != 'd') { goto vending_3; /* next rule */ } } /* -------------- 574: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 579: MatchedRule */ sp = rp; /* -------------- 576: Extension.ConsumeSet 0 1 2 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+6); ioConsume3(); box[3].blockPattern &= 0xfffe; if(!box[3].blockPattern) box[3].state = RunnableOut; wireConsume(wire+4); #ifdef SUPPORT_DEBUG boxBegin(box+0); #endif /*SUPPORT_DEBUG*/ /* -------------- 580: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 581: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 582: CallPrim ">" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; stack[sp++].hp = mkBool(cmpPrim(arg2, arg1, FALSE, TRUE)); } /* -------------- 583: If "t_vending_2_0" */ if(stack[--sp].hp[1].lv == TRUE) goto t_vending_2_0; /* -------------- 584: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 585: MkCon "CHECK" 0 */ stack[inc_sp()].hp = mkCon(36, 0); /* -------------- 586: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 587: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 588: MkString "CHECKING CHANGE\n" */ stack[inc_sp()].hp = mkString((char*)str_3); /* -------------- 589: MkCon "CHECKING" 0 */ stack[inc_sp()].hp = mkCon(32, 0); /* -------------- 590: MkTuple 6 */ { HEAP *tup = mkTup(6); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } /* -------------- 591: Goto "n_vending_2_0" */ goto n_vending_2_0; t_vending_2_0: /* -------------- 594: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 595: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 596: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 597: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 598: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 599: Call "f_showCredit" */ stack[inc_sp()].pc = 416; /* __humeReturn_416 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_showCredit; __humeReturn_416: /* -------------- 600: Slide 1 */ { STACK tos = stack[sp-1]; sp = sp - 2; stack[inc_sp()] = tos; } /* -------------- 601: MkString "NOT ENOUGH CREDIT\n" */ stack[inc_sp()].hp = mkString((char*)str_2); /* -------------- 602: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 603: MkCon "INPUT" 0 */ stack[inc_sp()].hp = mkCon(34, 0); /* -------------- 604: MkTuple 6 */ { HEAP *tup = mkTup(6); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } n_vending_2_0: /* -------------- 607: Unpack */ { HEAP *nodep = stack[--sp].hp; uint32 i; uint32 size = nodep[1].lv; for (i = 0; i < size; i++) stack[inc_sp()].hp = nodep[1+size-i].hp; mp = sp; } /* -------------- 608: Goto "vending_exit" */ goto vending_exit; vending_3: /* -------------- 619: Extension.AvailSet 0 2 3 4 */ if(!wire[6].availableFlag || !wire[4].availableFlag || !wire[3].availableFlag || !wire[2].availableFlag) { goto vending_4; /* next rule */ } /* -------------- 618: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 620: MatchCon "CHECKING" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+32) { goto vending_4; /* next rule */ } } /* -------------- 621: MatchNone */ --mp; /* -------------- 623: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 625: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 627: MatchCon "OK" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+40) { goto vending_4; /* next rule */ } } /* -------------- 633: MatchedRule */ sp = rp; /* -------------- 629: Extension.ConsumeSet 0 2 3 4 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+6); wireConsume(wire+4); wireConsume(wire+3); wireConsume(wire+2); box[1].blockPattern &= 0xfffe; if(!box[1].blockPattern) box[1].state = RunnableOut; #ifdef SUPPORT_DEBUG boxBegin(box+0); #endif /*SUPPORT_DEBUG*/ /* -------------- 634: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 635: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 636: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 637: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 638: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 639: CallPrim "-" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv - (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv - (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 640: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 641: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 642: CallPrim "-" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TINT && arg2->tag == TINT) { stack[sp++].hp = mkInt((arg1+1)->lv - (arg2+1)->lv); #ifdef SUPPORT_FLOAT } else if (arg1->tag == TFLOAT && arg2->tag == TFLOAT) { stack[sp++].hp = mkFloat((arg1+1)->fv - (arg2+1)->fv); #endif /*SUPPORT_FLOAT*/ } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 643: Call "f_showCredit" */ stack[inc_sp()].pc = 442; /* __humeReturn_442 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_showCredit; __humeReturn_442: /* -------------- 644: Slide 1 */ { STACK tos = stack[sp-1]; sp = sp - 2; stack[inc_sp()] = tos; } /* -------------- 645: MkString "PURCHASE MADE\n" */ stack[inc_sp()].hp = mkString((char*)str_1); /* -------------- 646: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 647: MkCon "INPUT" 0 */ stack[inc_sp()].hp = mkCon(34, 0); /* -------------- 650: Goto "vending_exit" */ goto vending_exit; vending_4: /* -------------- 661: Extension.AvailSet 0 2 3 4 */ if(!wire[6].availableFlag || !wire[4].availableFlag || !wire[3].availableFlag || !wire[2].availableFlag) { goto vending_5; /* next rule */ } /* -------------- 660: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 662: MatchCon "CHECKING" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+32) { goto vending_5; /* next rule */ } } /* -------------- 663: MatchNone */ --mp; /* -------------- 665: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 667: MatchAny */ --mp; /* -------------- 669: MatchCon "FAIL" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+39) { goto vending_5; /* next rule */ } } /* -------------- 675: MatchedRule */ sp = rp; /* -------------- 671: Extension.ConsumeSet 0 2 3 4 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+6); wireConsume(wire+4); wireConsume(wire+3); wireConsume(wire+2); box[1].blockPattern &= 0xfffe; if(!box[1].blockPattern) box[1].state = RunnableOut; #ifdef SUPPORT_DEBUG boxBegin(box+0); #endif /*SUPPORT_DEBUG*/ /* -------------- 676: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 677: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 678: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 679: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 680: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 681: Call "f_showCredit" */ stack[inc_sp()].pc = 462; /* __humeReturn_462 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_showCredit; __humeReturn_462: /* -------------- 682: Slide 1 */ { STACK tos = stack[sp-1]; sp = sp - 2; stack[inc_sp()] = tos; } /* -------------- 683: MkString "NO CHANGE\n" */ stack[inc_sp()].hp = mkString((char*)str_0); /* -------------- 684: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 685: MkCon "INPUT" 0 */ stack[inc_sp()].hp = mkCon(34, 0); /* -------------- 688: Goto "vending_exit" */ goto vending_exit; vending_5: /* -------------- 699: Extension.AvailSet 0 2 5 */ if(!wire[6].availableFlag || !wire[4].availableFlag || !wire[1].availableFlag) { goto change; /* next box */ } /* -------------- 698: MatchRule */ mp = ARG(0)+1; sp = rp; /* -------------- 700: MatchCon "CHANGE" 0 */ { HEAP *nodep = stack[--mp].hp; if(nodep->tag != TCON+33) { goto change; /* next box */ } } /* -------------- 701: MatchNone */ --mp; /* -------------- 703: MatchVar 0 */ stack[VAR(0)] = stack[--mp]; /* -------------- 704: MatchNone */ --mp; /* -------------- 705: MatchNone */ --mp; /* -------------- 707: MatchVar 1 */ stack[VAR(1)] = stack[--mp]; /* -------------- 711: MatchedRule */ sp = rp; /* -------------- 708: Extension.ConsumeSet 0 2 5 */ #ifdef SUPPORT_DEBUG updateCurrentTime(); #endif /*SUPPORT_DEBUG*/ wireConsume(wire+6); wireConsume(wire+4); wireConsume(wire+1); box[1].blockPattern &= 0xfffd; if(!box[1].blockPattern) box[1].state = RunnableOut; #ifdef SUPPORT_DEBUG boxBegin(box+0); #endif /*SUPPORT_DEBUG*/ /* -------------- 712: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 713: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 714: MkNone */ stack[inc_sp()].hp = NULL; /* -------------- 715: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 716: PushVar 0 */ stack[inc_sp()] = stack[VAR(0)]; /* -------------- 717: Call "f_showCredit" */ stack[inc_sp()].pc = 483; /* __humeReturn_483 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_showCredit; __humeReturn_483: /* -------------- 718: Slide 1 */ { STACK tos = stack[sp-1]; sp = sp - 2; stack[inc_sp()] = tos; } /* -------------- 719: MkInt 1 */ stack[inc_sp()].hp = mkInt(1); /* -------------- 720: PushVar 1 */ stack[inc_sp()] = stack[VAR(1)]; /* -------------- 721: Call "f_showChange" */ stack[inc_sp()].pc = 487; /* __humeReturn_487 */ inc_sp(); stack[inc_sp()].sp = slp; slp = sp + 1; goto f_showChange; __humeReturn_487: /* -------------- 722: Slide 2 */ { STACK tos = stack[sp-1]; sp = sp - 3; stack[inc_sp()] = tos; } /* -------------- 723: CallPrim "++" */ { HEAP *arg1 = stack[--sp].hp; HEAP *arg2 = stack[--sp].hp; if(arg1->tag == TSTR && arg2->tag == TSTR) { char *s1 = (char *) (arg1+1); char *s2 = (char *) (arg2+1); stack[sp++].hp = mkCatString(s1, s2); } else if(arg1->tag >= TCON && arg2->tag >= TCON) { /* assume they are lists */ HEAP *p = arg1; HEAP *r; HEAP **u = &r; while(p[1].lv == 2) { /* assume size=2 is a cons, copy the cons ':' cells of the 1st list */ *u = mkCon(1, 2); setHeap(p[2].hp); u = (HEAP**)(hp++); p = p[3].hp; } *u = stack[sp].hp; /* set the tail of last to the 2nd list */ stack[sp++].hp = r; } else if(arg1->tag == TVECTOR && arg2->tag == TVECTOR) { HEAP *vec = mkVector((arg1+1)->lv + (arg2+1)->lv); hp += (arg1+1)->lv + (arg2+1)->lv; memcpy(vec+2, arg1+2, sizeof(HEAP)*((arg1+1)->lv)); /* copy the first vector body */ memcpy(vec+2+(arg1+1)->lv, arg2+2, sizeof(HEAP)*((arg2+1)->lv)); /* copy the second vector body */ stack[sp++].hp = vec; } #ifndef NDEBUG else throwException(InternalError); #endif /*NDEBUG*/ } /* -------------- 724: MkCon "INPUT" 0 */ stack[inc_sp()].hp = mkCon(34, 0); /* -------------- 727: Goto "vending_exit" */ goto vending_exit; /* * init change_init * - nOutputs=3 * */ change_init: /* -------------- 751: Label "change_init" */ currentBox = box + 1; hp = heap; sp = 0; fp = 0; slp = 0; hpSoftLimit = heap + 152; spSoftLimit = 48; /* -------------- 752: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 753: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 754: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 755: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 756: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 757: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 758: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 759: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 760: MkVector 8 */ { HEAP *tup = mkVector(8); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); setHeap(stack[--sp].hp); stack[inc_sp()].hp = tup; } /* -------------- 761: Write 2 */ wireSetPending(wire+7, 10000, stack[--sp].hp); /* wire to */ /* -------------- 762: Schedule */ box[1].state = RunnableOut; goto __humeSuperstep; /* exit init */ /* * init vending_init * - nOutputs=6 * */ vending_init: /* -------------- 767: Label "vending_init" */ currentBox = box + 0; hp = heap; sp = 0; fp = 0; slp = 0; hpSoftLimit = heap + 294; spSoftLimit = 47; /* -------------- 768: MkCon "INPUT" 0 */ stack[inc_sp()].hp = mkCon(34, 0); /* -------------- 769: Write 0 */ wireSetPending(wire+6, 10000, stack[--sp].hp); /* wire to */ /* -------------- 770: MkInt 0 */ stack[inc_sp()].hp = mkInt(0); /* -------------- 771: Write 2 */ wireSetPending(wire+4, 10000, stack[--sp].hp); /* wire to */ /* -------------- 772: Schedule */ box[0].state = RunnableOut; goto change_init; /* next init */ } int main2(int argc, char *argv[]) { arguments = argv; /* only useful for boxes that read main_args */ exitCode = 0; /* only useful for boxes that write to main_exit */ engineInit(); #ifdef SUPPORT_DEBUG debugInit("/tmp_mnt/3/staff/greg/EmBounded/EmBounded/local/hwu/Budapest/vending.ham"); #endif /*SUPPORT_DEBUG*/ engineRun(); #ifdef SUPPORT_DEBUG { uint16 i; dumpState(stderr); for(i=0;i