static int fast_interp(uint8 *msg, unsigned nbytes, Atom a, int fail_pid) { /* msg += (msg[off]:nbits & mask) << shift */ # define do_shift(aligned, unchecked) do { \ if(!load_lhs(&off, msg, nbytes, ir, aligned, unchecked)) \ continue; \ off <<= ir->u.shift.shift; \ if(off >= nbytes) \ break; \ if((pid = fast_interp(msg+off, nbytes-off,a->kids.lh_first, a->pid)))\ return pid; \ } while(0) /* msg[off]:nbits & mask == val */ # define do_eq(aligned, unchecked) do { \ assert(!a->ht); \ if(!load_lhs(&lhs, msg, nbytes, ir, aligned, unchecked)) \ break; \ if(lhs != ir->u.eq.val) \ break; \ if((pid = fast_interp(msg, nbytes, a->kids.lh_first, a->pid))) \ return pid; \ } while(0) # define do_deq(aligned, unchecked) do { \ Atom hte; \ \ assert(a->ht); \ if(!load_lhs(&lhs, msg, nbytes, ir, aligned, unchecked)) \ break; \ if(!(hte = ht_lookup(a->ht, lhs))) \ break; \ if((pid = fast_interp(msg, nbytes, hte->kids.lh_first, hte->pid)))\ return pid; \ } while(0) unsigned lhs, off, pid; struct ir *ir; for(; a; a = a->sibs.le_next) { ir = &a->ir; switch((state_t)a->code[0]) { case EQ: do_eq(0, 0); break; case EQ_UNCHECKED: do_eq(0, 1); break; case EQ_ALIGNED: do_eq(1, 0); break; case EQ_ALIGNED_UNCHECKED: do_eq(1, 1); break; case EQ_HASH: do_deq(0, 0); break; case EQ_ALIGNED_HASH: do_deq(1, 0); break; case EQ_UNCHECKED_HASH: do_deq(0, 1); break; case EQ_ALIGNED_UNCHECKED_HASH: do_deq(1, 1); break; case SHIFT: do_shift(0, 0); break; case SHIFT_UNCHECKED: do_shift(0, 1); break; case SHIFT_ALIGNED: do_shift(1, 0); break; case SHIFT_ALIGNED_UNCHECKED: do_shift(1, 1); break; default: fatal(Bogus op); } } return fail_pid; }
virtual Vasp *tx_work(const Argument &arg) { OpParam p(thisName(),1); p.tilt.fill = (I)fill; p.tilt.mode = (I)inter; Vasp *ret = do_shift(p); return ret; }
/* * rotn_decrypt -- * A simple decryption example that passes data through unchanged. */ static int rotn_decrypt(WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) { ROTN_ENCRYPTOR *rotn_encryptor = (ROTN_ENCRYPTOR *)encryptor; size_t mylen; uint32_t i; (void)session; /* Unused */ /* * For certain tests, force an error we can recognize. */ if (rotn_encryptor->force_error) return (-1000); /* * Make sure it is big enough. */ mylen = src_len - (CHKSUM_LEN + IV_LEN); if (dst_len < mylen) return (rotn_error(rotn_encryptor, session, ENOMEM, "decrypt buffer not big enough")); /* * !!! Most implementations would verify the checksum here. */ /* * Copy the encrypted data to the destination buffer and then * decrypt the destination buffer. */ i = CHKSUM_LEN + IV_LEN; memcpy(&dst[0], &src[i], mylen); /* * Depending on whether we have a secret key or not, * call the common rotate or shift function on the text portion * of the destination buffer. Send in dst_len as the length of * the text. */ /* * !!! Most implementations would need the IV too. */ if (rotn_encryptor->shift_len == 0) do_rotate((char *)dst, mylen, 26 - rotn_encryptor->rot_N); else do_shift(&dst[0], mylen, rotn_encryptor->shift_back, rotn_encryptor->shift_len); *result_lenp = mylen; return (0); }
/* * rotn_encrypt -- * A simple encryption example that passes data through unchanged. */ static int rotn_encrypt(WT_ENCRYPTOR *encryptor, WT_SESSION *session, uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, size_t *result_lenp) { ROTN_ENCRYPTOR *rotn_encryptor = (ROTN_ENCRYPTOR *)encryptor; uint32_t i; (void)session; /* Unused */ if (dst_len < src_len + CHKSUM_LEN + IV_LEN) return (rotn_error(rotn_encryptor, session, ENOMEM, "encrypt buffer not big enough")); /* * !!! Most implementations would verify any needed * checksum and initialize the IV here. */ i = CHKSUM_LEN + IV_LEN; memcpy(&dst[i], &src[0], src_len); /* * Depending on whether we have a secret key or not, * call the common rotate or shift function on the text portion * of the destination buffer. Send in src_len as the length of * the text. */ if (rotn_encryptor->shift_len == 0) do_rotate((char *)dst + i, src_len, rotn_encryptor->rot_N); else do_shift(&dst[i], src_len, rotn_encryptor->shift_forw, rotn_encryptor->shift_len); /* * Checksum the encrypted buffer and add the IV. */ i = 0; make_checksum(&dst[i]); i += CHKSUM_LEN; make_iv(&dst[i]); *result_lenp = dst_len; return (0); }
static double eval_rpn(int *equat) { int i; double temx, temy, temz; union /* WARNING -- ASSUMES 32 bit int and 64 bit double */ { struct { int int1; int int2; } pieces; struct { double z; } num; } encoder; while ((i = *equat++) != ENDEXP) { switch (i) { case NUMSYM: encoder.pieces.int2 = *equat++; encoder.pieces.int1 = *equat++; PUSH(encoder.num.z); break; case ENDFUN: i = *equat++; uptr -= i; break; case MYIF: { int ijmp; temx = POP; ijmp = *equat++; if (temx == 0.0) equat += ijmp; break; } case MYTHEN: { int ijmp = *equat++; equat += ijmp; break; } case MYELSE: break; case ENDDELSHFT: temx = POP; temy = POP; temz = POP; PUSH(do_delay_shift(temx, temy, temz)); break; case ENDDELAY: temx = POP; temy = POP; PUSH(do_delay(temx, temy)); break; case ENDSHIFT: temx = POP; temy = POP; PUSH(do_shift(temx, temy)); break; case ENDISHIFT: temx = POP; temy = POP; PUSH(do_ishift(temx, temy)); break; case SUMSYM: { int high; int low; int ijmp; double sum; temx = POP; high = (int)temx; temx = POP; low = (int)temx; ijmp = *equat++; sum = 0.0; if (low <= high) { for (int is = low; is <= high; is++) { constants.elems[SumIndex] = (double)is; sum += eval_rpn(equat); } } equat += ijmp; PUSH(sum); break; } case ENDSUM: return (POP); case INDXCOM: PUSH(0.0); break; default: { int it = i / MAXTYPE; int in = i % MAXTYPE; switch (it) { case FUN1TYPE: PUSH(expr_fun1[in](POP)); break; case FUN2TYPE: switch (in) { case 0: temx = POP; temy = POP; PUSH(temx + temy); break; case 1: temx = POP; temy = POP; PUSH(temy - temx); break; case 2: temx = POP; temy = POP; PUSH(temx * temy); break; case 3: temx = POP; if (temx == 0.0) temx = DOUB_EPS; temy = POP; PUSH(temy / temx); break; default: temx = POP; temy = POP; PUSH(expr_fun2[in](temy, temx)); break; } break; case CONTYPE: PUSH(constants.elems[in]); break; case NETTYPE: PUSH(network_value(POP, in)); break; case TABTYPE: PUSH(lookup(POP, in)); break; case USTACKTYPE: /* ram: so this means ustacks really do need to be of USTACKTYPE */ PUSH(ustack[uptr - 1 - in]); break; case KERTYPE: PUSH(ker_val(in)); break; case VARTYPE: PUSH(variables.elems[in]); break; /* indexes for shift and delay operators... */ case SCONTYPE: PUSH((double)(COM(CONTYPE, in))); break; case SVARTYPE: PUSH((double)(COM(VARTYPE, in))); break; case UFUNTYPE: i = *equat++; for (int j = 0; j < i; j++) { ustack[uptr] = POP; uptr++; } PUSH(eval_rpn(ufuns.elems[in].rpn)); break; } break; } } } return (POP); }
int main(void) { // EXT_MEM_INIT; usart0_init(USART_RS485_SLAVE, 38400); usart0_setprotocol_modbus(); usart1_init(USART_RS232, 115200); USART1_SET_8N1; USART1_RX_INT_DISABLE; timer_init(); kbd_init(); shift_init(); sensor_init(); menu_init(); menu_items_init(); beep_init(); GLOBAL_INT_ENABLE; beep_ms(1000); _delay_ms(500); beep_ms(200); _delay_ms(200); beep_ms(200); _delay_ms(200); lcd_init(); for (;;) { //do_kbd(); do_lcd(); do_shift(); do_sensor(); menu_doitem(); process_usart(); process_soft_controls(); process_siren(); //process_foil(); //process_kbd(); // simple process foil soft_sensors = sensors; if (TEST_SOFT_CONTROL(SOFT_CONTROL_BUNKER_MOTOR) && TEST_SENSOR(SENSOR_END_OF_FOIL)) SOFT_CONTROL_OFF(SOFT_CONTROL_BUNKER_MOTOR); /* if (!TEST_SENSOR(SENSOR_END_OF_FOIL) && TEST_SENSOR(SENSOR_SEC_REEL)) SOFT_CONTROL_ON(SOFT_CONTROL_BUNKER_MOTOR); */ } return 0; }
char * shift_string (List *stack) { return do_shift (stack, 1); }
void * shift (List *stack) { return do_shift (stack, 0); }