void Interpreter::swap() { StackVar upVar = _stack.top(); VarType upType = _typeStack.top(); popVar(); StackVar downVar = _stack.top(); VarType downType = _typeStack.top(); popVar(); pushVar(upType, upVar); pushVar(downType, downVar); }
int borrowBook() { Var *varList = pushVar(); printf("\n... Borrowing Books ...\n"); currentLimit = borrowLimit - holdNum; if (0 > currentLimit - borrowNum) { printf("You have exceeded your borrowing limit!\n"); popVar(varList); return -1; } currentLimit -= borrowNum; holdNum += borrowNum; if (1 == borrowNum) printf("You've just borrowed [%d] book!\n", borrowNum); else printf("You've just borrowed [%d] books!\n", borrowNum); if (1 == currentLimit) printf("Now you can borrow [%d] more book.\n", currentLimit); else printf("Now you can borrow [%d] more books.\n", currentLimit); /* set the value for return */ varList[HOLDNUM].val.i = holdNum; popVar(varList); return holdNum; }
int returnBook() { Var *varList = pushVar(); printf("\n... Returning Books ...\n"); printf("Thank you, %s! ", name); holdNum -= returnNum; if (1 == returnNum) printf("You've just returned [%d] book!\n", returnNum); else printf("You've just returned [%d] books!\n", returnNum); currentLimit = borrowLimit - holdNum; if (1 == currentLimit) printf("Now you can borrow [%d] more book.\n", currentLimit); else printf("Now you can borrow [%d] more books.\n", currentLimit); /* set the value for return */ varList[HOLDNUM].val.i = holdNum; popVar(varList); return holdNum; }
void Interpreter::pushDouble(double d) { StackVar var; var.d = d; pushVar(VT_DOUBLE, var); //cout << "__PUSHED DOUBLE" << d << endl; }
void Interpreter::pushInt(int64_t i) { StackVar var; var.i = i; pushVar(VT_INT, var); //cout << "__PUSHED INT" << i << endl; }
void professor() { Var *varList = pushVar(); borrowLimit = 10; printf("Dear Professor %s, you can borrow [%d] books in total! Enjoy the books!\n", name, borrowLimit); staff(); popVar(varList); }
int32 opcodeType8() { int opcode = getByteFromScript(); if (!opcode) return (-21); if (opcode > 0x100) return (-21); if (opcode < ARRAYSIZE(opcodeTablePtr) && opcodeTablePtr[opcode]) { pushVar(opcodeTablePtr[opcode]()); return (0); } else { warning("Unsupported opcode %d in opcode type 8", opcode); pushVar(0); // exit(1); } return 0; }
void staff() { Var *varList = pushVar(); holdNum = returnBook(); if (0 <= holdNum) printf("[Number of books borrowed: %d]\n", holdNum); else printf("ERROR! You are trying to return more books than you've borrowed!\n"); holdNum = borrowBook(); if (0 <= holdNum) printf("[Number of books borrowed: %d]\n", holdNum); else printf("ERROR! You are trying to borrow more books than your borrowing limit!\n"); popVar(varList); }
void genbf_init_declarator(struct init_declarator *a) { struct type *vt; int i; /* push this variable */ pushVar(genbf_declarator2_get_identifier(a->v1->v2), 1); /* then use genbf_declarator to get its type */ vt = genbf_declarator(a->v1, NULL); curvar->type = vt; curvar->width = vt->size; /* and push it in BF */ for (i = 0; i < curvar->width; i++) BF_PUSH; if (a->assign) { UNIMPL("init_declarator with assignment"); } }
void library(char *_name, char *_id, int _holdNum, int _returnNum, int _borrowNum) { /* initialize all global variables */ name = realloc(name, strlen(_name)+1); strncpy(name, _name, strlen(_name)+1); id = realloc(id, strlen(_id)+1); strncpy(id, _id, strlen(_id)+1); holdNum = _holdNum; returnNum = _returnNum; borrowNum = _borrowNum; Var *varList = pushVar(); printf("\n** Dear %s, welcome to the CUHK Library **\n", name); printf("[Number of books borrowed: %d]\n", holdNum); if (id[0] == 'p') professor(); else staff(); popVar(varList); }
void Interpreter::loadString() { StackVar var; var.strId = getNext2Bytes(); pushVar(VT_STRING, var); }