Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Does it matter legally, if I share this without cause or license?
- */
- int16_t wheel( int16_t a, unsigned char b)
- {
- int16_t stack[7];
- int16_t tmp;
- int depth;
- enum primitives { end, unfold, dup2, flip, swap, dup, mult, minus,
- add2, add1 };
- int code[] = { unfold,dup2,flip,swap,dup,mult,swap,dup,mult,
- minus,swap,minus,mult,add2,swap,add1,mult,flip, end };
- int pc;
- depth=0;
- stack[depth++]=a;
- stack[depth++]=b;
- for (pc=0; end != code[pc] ; pc++ ) {
- switch(code[pc]) {
- case dup:
- tmp=stack[depth];
- depth++;
- stack[depth]=tmp;
- break;
- case dup2:
- tmp=stack[depth];
- stack[depth+1]=stack[depth-1];
- depth+=2;
- stack[depth]=tmp;
- break;
- case swap:
- tmp=stack[depth];
- stack[depth]=stack[depth-1];
- stack[depth-1]=tmp;
- break;
- case unfold:
- tmp=stack[depth];
- stack[depth]=stack[depth-1];
- depth++;
- stack[depth]=tmp;
- break;
- case flip:
- {
- unsigned char uc;
- union {
- unsigned char uc[2];
- int16_t i;
- } f;
- f.i=stack[depth];
- uc=f.uc[0];
- f.uc[0]=f.uc[1];
- f.uc[1]=uc;
- stack[depth]=f.i;
- }
- break;
- case mult:
- tmp=(stack[depth-1] * stack[depth]);
- depth--;
- stack[depth]=tmp;
- break;
- case minus:
- tmp=(stack[depth-1] - stack[depth]);
- depth--;
- stack[depth]=tmp;
- break;
- case add1:
- stack[depth]++;
- break;
- case add2:
- stack[depth]+=2;
- }
- }
- return stack[depth];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement