int main(){ Node* stack=(Node*)malloc(sizeof(Node)); int size=5; stack->top=-1; stack->top1=size; stack->capacity=size; stack->Array=(int*)malloc(sizeof(int)*stack->capacity); int i; for(i=0;i<size;i++){ if(i<3){ Push(stack,i+5); }else{ Push1(stack,i+10); } } printf("\nIndex : %d ",stack->top); printf("Popped stack1 : %d",stack->Array[stack->top--]); printf("\nIndex : %d ",stack->top1); printf("Popped stack2 : %d",stack->Array[stack->top1++]); return 0; }
long wordcode_interp(unsigned int* code) { long * sp; unsigned int * pc; unsigned int instr; int extra_args = 0; sp = stack + STACKSIZE; pc = code; while (1) { instr = *pc++; switch (Opcode) { case WCALL1: case WCALL1_pop1: { long arg = Op1; Adjust1; Push3((long)pc, extra_args, arg); pc += Imm16s; extra_args = 0; break; } case WCONST: case WCONST_pop1: { Adjust1; Push1(Imm24s); break; } case WBRANCHIF: case WBRANCHIF_pop1: { long arg = Op1; Adjust1; if (arg) pc += Imm16s; break; } case WCALL3: { unsigned int ext = *pc++; long arg1 = Extraop1(ext); long arg2 = Extraop2(ext); long arg3 = Extraop3(ext); Adjustbyte1; Push5((long)pc, extra_args, arg3, arg2, arg1); pc += Imm16s; extra_args = 2; break; } case WRETURN: { long res = Op1; Adjustbyte2; if (extra_args > 0) { printf("Over-application.\n"); exit(2); } else { extra_args = sp[0]; pc = (unsigned int *) sp[1]; sp += 1; *sp = res; } break; } case WBRANCH: { Adjustbyte1; pc += Imm16s; break; } case WLTINT: { long arg1 = Op1, arg2 = Op2; Adjustbyte3; Push1(arg1 < arg2); break; } case WADDINT: { long arg1 = Op1, arg2 = Op2; Adjustbyte3; Push1(arg1 + arg2); break; } case WOFFSETINT: { long arg = Op1; Adjustbyte2; Push1(arg + Imm8s); break; } case WDUP: { long arg = Op1; Push1(arg); break; } case WGRAB: { int required = Byte1; if (extra_args >= required) { extra_args -= required; } else { printf("Partial application.\n"); exit(2); } break; } case WSTOP: { long res = Op1; Adjustbyte2; return res; break; } } } }