/* local op, a, b, c, test = jit.util.bytecode(func, pc) */ static int ju_bytecode(lua_State *L) { Proto *pt = check_LCL(L)->l.p; int pc = luaL_checkint(L, 2); if (pc >= 1 && pc <= pt->sizecode) { Instruction ins = pt->code[pc-1]; OpCode op = GET_OPCODE(ins); if (pc > 1 && (((int)OP_SETLIST) << POS_OP) == (pt->code[pc-2] & (MASK1(SIZE_OP,POS_OP) | MASK1(SIZE_C,POS_C)))) { lua_pushstring(L, luaP_opnames[OP_SETLIST]); lua_pushnumber(L, (lua_Number)ins); /* Fake extended op. */ return 1; } if (op >= NUM_OPCODES) return 0; /* Just in case. */ lua_pushstring(L, luaP_opnames[op]); lua_pushinteger(L, GETARG_A(ins)); switch (getOpMode(op)) { case iABC: { int b = GETARG_B(ins), c = GETARG_C(ins); switch (getBMode(op)) { case OpArgN: lua_pushnil(L); break; case OpArgK: if (ISK(b)) b = -1-INDEXK(b); case OpArgR: case OpArgU: lua_pushinteger(L, b); break; } switch (getCMode(op)) { case OpArgN: lua_pushnil(L); break; case OpArgK: if (ISK(c)) c = -1-INDEXK(c); case OpArgR: case OpArgU: lua_pushinteger(L, c); break; } lua_pushboolean(L, testTMode(op)); return 5; } case iABx: { int bx = GETARG_Bx(ins); lua_pushinteger(L, getBMode(op) == OpArgK ? -1-bx : bx); return 3; } case iAsBx: lua_pushinteger(L, GETARG_sBx(ins)); return 3; } } return 0; }
int main(int argc, char* argv[]) { int a = NUM_OPCODES; int b = MASK1(2, 3); int c = MASK0(2,3); lua_State* L; struct Smain s; int i = doargs(argc, argv); argc -= i; argv += i; if (argc <= 0) usage("no input files given"); L = lua_open(); if (L == NULL) fatal("not enough memory for state"); s.argc = argc; s.argv = argv; if (lua_cpcall(L, pmain, &s) != 0) fatal(lua_tostring(L, -1)); lua_close(L); return EXIT_SUCCESS; }
void attachPcInterrupt( uint8_t pin, void (*callback)(void), uint8_t mode ) { #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 uint8_t port; #endif uint8_t bitMask; uint8_t changeMask; uint8_t risingMask; uint8_t fallingMask; pcint_entry_p hole; pcint_entry_p entry; changeMask = 0; risingMask = 0; fallingMask = 0; bitMask = digitalPinToBitMask( pin ); switch ( mode ) { case CHANGE: changeMask = bitMask; break; case FALLING: fallingMask = bitMask; break; case RISING: risingMask = bitMask; break; default: return; } #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 port = digitalPinToPort( pin ); #endif tryAgain: hole = 0; entry = pcint; for ( uint8_t i=0; i < NUMBER_PIN_CHANGE_INTERRUPT_HANDLERS; ++i ) { uint8_t SaveSREG = SREG; cli(); if ( (hole == 0) && (entry->callback == 0) ) { hole = entry; } else { if ( #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 (port == entry->port) && #endif (changeMask == entry->changeMask) && (risingMask == entry->risingMask) && (fallingMask == entry->fallingMask) && (callback == entry->callback) ) { SREG = SaveSREG; return; } } SREG = SaveSREG; ++entry; } if ( hole == 0 ) return; uint8_t SaveSREG = SREG; cli(); if ( hole->callback == 0 ) { #if NUMBER_PIN_CHANGE_INTERRUPT_PORTS > 1 hole->port = port; #endif hole->changeMask = changeMask; hole->risingMask = risingMask; hole->fallingMask = fallingMask; hole->callback = callback; #if defined( __AVR_ATtinyX4__ ) if ( port == PORT_A_ID ) { GIMSK |= MASK1( PCIE0 ); if ( (PCMSK0 & bitMask) == 0 ) { previousPinValue0 |= (PINA & bitMask); PCMSK0 |= bitMask; } } else // if ( port = PORT_ID_B ) { GIMSK |= MASK1( PCIE1 ); if ( (PCMSK1 & bitMask) == 0 ) { previousPinValue1 |= (PINB & bitMask); PCMSK1 |= bitMask; } } #endif #if defined( __AVR_ATtinyX5__ ) || defined( __AVR_ATtiny2313__ ) GIMSK |= MASK1( PCIE ); if ( (PCMSK & bitMask) == 0 ) { previousPinValue0 |= (PINB & bitMask); PCMSK |= bitMask; } #endif } else { SREG = SaveSREG; goto tryAgain; } SREG = SaveSREG; }
static int any_set_or_all_clr(BITS *bits, unsigned long masks) { return (bits->mask & MASK0(masks)) || (~bits->mask & MASK1(masks)) == MASK1(masks); }
static int all_clr_and_any_clr(BITS *bits, unsigned long masks) { return (~bits->mask & MASK1(masks)) && (~bits->mask & MASK0(masks)) == MASK0(masks); }
static int any_set_and_any_clr(BITS *bits, unsigned long masks) { return (bits->mask & MASK0(masks)) && (~bits->mask & MASK1(masks)); }
static int all_set_and_any_set(BITS *bits, unsigned long masks) { return (bits->mask & MASK1(masks)) && (bits->mask & MASK0(masks)) == MASK0(masks); }