void mexecute(u16 n, const char *name, int count, fncode fn) /* Effects: Generates code to call function in variable n, with count arguments */ { struct string *mod; int status = module_vstatus(fnglobals(fn), n, &mod); if (!in_glist(n, definable) && !in_glist(n, readable) && !in_glist(n, writable)) { if (status == var_module) { /* Implicitly import protected modules */ if (module_status(fnglobals(fn), mod->str) != module_protected && !all_readable && imported(mod->str) == module_unloaded) log_error("read of global %s (module %s)", name, mod->str); } else if (!all_readable) log_error("read of global %s", name); } if (count == 1) ins2(op_execute_global1, n, fn); else if (count == 2) ins2(op_execute_global2, n, fn); else { /* Could have an op_execute_global */ ins2(op_recall + global_var, n, fn); ins1(op_execute, count, fn); } }
uint16_t importdb(uint16_t start, uint16_t end) { if(end > 1023) return -1; thindb tdb( g_sd ); uint16_t id(-1); database::dbrecord rec,old; uint16_t imported(0); if( tdb.init()) { for( id = start; id <= end; ++id ) { if( !tdb.getParams( id, rec ) || !g_db.getParams(id, old)) { break; } if(!rec.infoequal(old)){ #ifdef VERBOSE serialoutln(F(CMNTS "Importing "), id); #endif if(!g_db.setParams( id, rec )) break; else ++imported; } #ifdef VERBOSE else { serialoutln(F(CMNTS "Skipping "), id); } #endif } if(id != end+1 ) return -1; } return imported; }
void mrecall(u16 n, const char *name, fncode fn) /* Effects: Generate code to recall variable n */ { struct string *mod; struct global_state *gstate = fnglobals(fn); int status = module_vstatus(gstate, n, &mod); if (!in_glist(n, definable) && !in_glist(n, readable) && !in_glist(n, writable)) { if (status == var_module) { /* Implicitly import protected modules */ if (module_status(gstate, mod->str) == module_protected) { if (immutablep(GVAR(gstate, n))) /* Use value */ { ins_constant(GVAR(gstate, n), fn); return; } } else if (!all_readable && imported(mod->str) == module_unloaded) log_error("read of global %s (module %s)", name, mod->str); } else if (!all_readable) log_error("read of global %s", name); } ins2(op_recall + global_var, n, fn); }
be_structure::be_structure(UTL_ScopedName *n, const UTL_Pragmas &p) : AST_Decl (AST_Decl::NT_struct, n, p), UTL_Scope (AST_Decl::NT_struct, n, p), m_isFixedLength (pbtrue), m_elemAlignment (0), m_maxElemAlignment (1), m_elemSize (0), m_canOptimize (pbfalse), m_lastFieldSize (0), m_cppScope (g_feScopeStack.Top()), m_cppType (g_feScopeStack.Top(), *n), m_interface_dependant (pbfalse) { DDS_StdString barScopedName = NameToString(name(), "_"); isAtModuleScope(pbfalse); localName = local_name()->get_string(); enclosingScope = be_Type::EnclosingScopeString(this); m_tc_ctor_val = (DDS_StdString) barScopedName + "_ctor"; m_tc_dtor_val = (DDS_StdString) barScopedName + "_dtor"; m_tc_put_val = (DDS_StdString) barScopedName + "_put"; m_tc_get_val = (DDS_StdString) barScopedName + "_get"; m_tc_assign_val = (DDS_StdString) barScopedName + "_copy"; m_any_op_id = barScopedName; m_nullArg = (DDS_StdString)"*(new " + ScopedName() + ")"; m_typecode->kind = DDS::tk_struct; m_typecode->id = get_decl_pragmas().get_repositoryID()->get_string(); m_typecode->name_of_type = localName; m_marshalInCore = FALSE; InitializeTypeMap(this); if (!imported()) be_CppFwdDecl::Add(be_CppFwdDecl::STRUCT, this, m_cppScope); }
void setup() { bool loginit(false); bool sdinit(false); bool dbinit(false); uint8_t tlpins[] = { INNER_LIGHTS_PINS, OUTER_LIGHTS_PINS }; Serial.begin( BAUDRATE ); #ifdef VERBOSE delay(10); Serial.print(CMNT); for( char c = 0; c < 79; ++c ) Serial.print('>'); Serial.println(); #endif I2c.begin(); I2c.timeOut(1000); g_display.init(); // calls Wire.begin() g_display.print( freeMemory() ); g_loop.init( PIN_INNERLOOP, PIN_OUTERLOOP, LOOP_ACTIVE ); setup433(); g_codeready = false; g_code = 0; #ifdef USE_IOEXTENDER_OUTPUTS g_outputs.set(0xff); #else { uint8_t all_output_pins[8] = { ALL_RAW_OUTPUT_PINS }; g_outputs.init(all_output_pins, RELAY_OFF); } #endif if((sdinit = g_sd.begin( SS, SPI_HALF_SPEED ))) { if( !(loginit = g_logger.init()) ) Serial.println(F("Logger fail")); } else Serial.println(F("SD fail")); dbinit = g_db.init(); g_display.print( ' ' ); g_display.print( sdinit ); g_display.print( ' ' ); g_display.print( loginit ); g_display.print( ' ' ); g_display.print( dbinit ); //runlight for( uint8_t pin = 0; pin < sizeof(tlpins) + 3; ++pin ) { if(pin < sizeof(tlpins)) { g_outputs.set( tlpins[pin], RELAY_ON); } if(pin > 2) g_outputs.set(tlpins[pin-3], RELAY_OFF); delay(150); } if( !loginit ) { delay(100); for( int i = 0; i < 3; ++i ) { g_outputs.set( PIN_IN_RED, RELAY_ON ); g_outputs.set( PIN_OUT_RED, RELAY_ON ); delay( 500 ); g_outputs.set( PIN_IN_RED, RELAY_OFF ); g_outputs.set( PIN_OUT_RED, RELAY_OFF ); delay( 500 ); } } g_clk.init( DS3231_INTCN ); g_timevalid = updatedt(); #ifdef VERBOSE Serial.print(CMNT); Serial.println(F("DS3231 init done.")); #endif g_logger.log( logwriter::INFO, g_time, F("Reset") ); g_display.clear(); if(sdinit) { SdFile f; if(f.open("IMPORT")) { f.close(); g_display.print(F("IMPORTING ")); uint16_t imported(importdb(0, 1023)); if(imported != (uint16_t) -1) { g_display.print(imported); g_sd.remove("IMPORT"); } else g_display.print(F("FAIL")); delay(2000); g_display.clear(); } } #ifdef VERBOSE Serial.print(CMNT); for( char c = 0; c < 79; ++c ) Serial.print('<'); Serial.println(); #endif }
void processinput() { const char *inptr( g_iobuf ); Serial.print(CMNT); Serial.println( g_iobuf ); if( iscommand( inptr, F("dl"))) { g_logger.dump( &Serial ); } else if( iscommand( inptr, F("tl"))) { // truncate log g_logger.truncate(); } else if( iscommand( inptr, F("get") )) { // get database::dbrecord rec; int id( getintparam( inptr )); if( id != -1 && g_db.getParams( id, rec )) { rec.serialize( g_iobuf ); serialoutln( RESP, g_iobuf ); } else Serial.println( F(ERRS "ERR")); } else if( iscommand( inptr, F("set") )) { // set database::dbrecord rec; int id( getintparam( inptr )); if( id != -1 && rec.parse( inptr )) { if( g_db.setParams( id, rec )) Serial.println( F( RESPS "OK")); else Serial.println( F(ERRS "ERR")); } else Serial.println( F(ERRS "ERR")); } else if( iscommand( inptr, F("imp"))) { // import thindb tdb( g_sd ); uint16_t from( getintparam( inptr )); uint16_t to( getintparam( inptr )); if( from == 0xffff ) from = 0; if( to == 0xffff ) to = 1023; uint16_t imported(importdb(from, to)); if( imported != (uint16_t)-1 ) { serialoutln(F(RESPS "OK "), imported); } else serialoutln(F(ERRS "ERR "), imported); } else if( iscommand( inptr, F("dmp"))) { // dump database::dbrecord rec; uint16_t from( getintparam( inptr )); uint16_t to( getintparam( inptr )); uint16_t id; g_iobuf[3] = ' '; if( from == 0xffff ) from = 0; if( to == 0xffff ) to = 1023; for( id = from; id <= to; ++id ) { if( g_db.getParams( id, rec )) { uitohex( g_iobuf, id, 3 ); rec.serialize( g_iobuf + 4 ); serialoutln( RESP, g_iobuf ); } else break; } if( id == to + 1 ) Serial.println( RESP ); else Serial.println( F(ERRS "ERR" )); } else { Serial.println( F(ERRS "CMD")); } g_inidx = 0; }
static int parsepkgdata(char *file, char *pkg, char **pp, char *ep, char **prefixp, char **namep, char **defp) { char *p, *prefix, *name, *def, *edef, *meth; int n, inquote; // skip white space p = *pp; loop: while(p < ep && (*p == ' ' || *p == '\t' || *p == '\n')) p++; if(p == ep || strncmp(p, "$$\n", 3) == 0) return 0; // prefix: (var|type|func|const) prefix = p; if(p + 7 > ep) return -1; if(strncmp(p, "var ", 4) == 0) p += 4; else if(strncmp(p, "type ", 5) == 0) p += 5; else if(strncmp(p, "func ", 5) == 0) p += 5; else if(strncmp(p, "const ", 6) == 0) p += 6; else if(strncmp(p, "import ", 7) == 0) { p += 7; while(p < ep && *p != ' ') p++; p++; name = p; while(p < ep && *p != '\n') p++; if(p >= ep) { fprint(2, "%s: %s: confused in import line\n", argv0, file); nerrors++; return -1; } *p++ = '\0'; imported(pkg, name); goto loop; } else { fprint(2, "%s: %s: confused in pkg data near <<%.40s>>\n", argv0, file, prefix); nerrors++; return -1; } p[-1] = '\0'; // name: a.b followed by space name = p; inquote = 0; while(p < ep) { if (*p == ' ' && !inquote) break; if(*p == '\\') p++; else if(*p == '"') inquote = !inquote; p++; } if(p >= ep) return -1; *p++ = '\0'; // def: free form to new line def = p; while(p < ep && *p != '\n') p++; if(p >= ep) return -1; edef = p; *p++ = '\0'; // include methods on successive lines in def of named type while(parsemethod(&p, ep, &meth) > 0) { *edef++ = '\n'; // overwrites '\0' if(edef+1 > meth) { // We want to indent methods with a single \t. // 6g puts at least one char of indent before all method defs, // so there will be room for the \t. If the method def wasn't // indented we could do something more complicated, // but for now just diagnose the problem and assume // 6g will keep indenting for us. fprint(2, "%s: %s: expected methods to be indented %p %p %.10s\n", argv0, file, edef, meth, meth); nerrors++; return -1; } *edef++ = '\t'; n = strlen(meth); memmove(edef, meth, n); edef += n; } name = expandpkg(name, pkg); def = expandpkg(def, pkg); // done *pp = p; *prefixp = prefix; *namep = name; *defp = def; return 1; }
void QPythonWorker::import(QString name, QJSValue callback) { bool result = qpython->importModule_sync(name); emit imported(result, callback); }
int main() try { adobe::forest<char> forest; adobe::forest<char>::iterator a(forest.insert(forest.begin(), 'a')); a = adobe::trailing_of(a); adobe::forest<char>::iterator b(forest.insert(a, 'b')); adobe::forest<char>::iterator c(forest.insert(a, 'c')); b = adobe::trailing_of(b); forest.insert(b, 'd'); forest.insert(b, 'e'); forest.insert(b, 'f'); forest.insert(adobe::trailing_of(forest.insert(adobe::trailing_of(c), 'g')), 'h'); output(depth_range(forest)); forest_map<char>::type index_map; { adobe::forest<char>::const_preorder_iterator iter(forest.begin()); adobe::forest<char>::const_preorder_iterator last(forest.end()); for (; iter != last; ++iter) { std::cout << *iter << " has_next_sibling : " << std::boolalpha << has_next_sibling(iter.base()) << std::endl; } } build_index_map<char>(index_map, adobe::bitpath_t(), forest.begin()); { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { std::cout << *iter->second << " has index : " << iter->first << std::endl; } } { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { adobe::forest<char>::iterator parent(find_index_parent<char>(index_map, iter->first)); if (parent == adobe::forest<char>::iterator()) { std::cout << *iter->second << " has no parent." << std::endl; } else { std::cout << *iter->second << " has parent : " << *parent << std::endl; } } } { adobe::forest<char>::preorder_iterator iter(forest.begin()); adobe::forest<char>::preorder_iterator last(forest.end()); for (; iter != last; ++iter) { std::cout << *iter << " has index : " << iterator_to_index(forest, iter.base()) << std::endl; } } { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { std::cout << "index " << iter->first << " has value " << *index_to_iterator(forest, iter->first) << std::endl; } } { forest_map<char>::type::const_iterator iter(index_map.begin()); forest_map<char>::type::const_iterator last(index_map.end()); for (; iter != last; ++iter) { adobe::bitpath_t path(iter->first); adobe::vector<unsigned char> exported(path.portable()); adobe::bitpath_t imported(exported); std::cout << "path: " << path << ", round-trip: " << imported << std::endl; } } { adobe::bitpath_t small_path; small_path.push(1); small_path.push(0); small_path.push(1); small_path.push(1); small_path.push(0); adobe::bitpath_t med_path(small_path); med_path.push(0); med_path.push(1); med_path.push(1); med_path.push(0); med_path.push(1); adobe::bitpath_t long_path(med_path); long_path.push(1); long_path.push(0); long_path.push(0); long_path.push(1); long_path.push(1); std::cout << "small_path: " << small_path << std::endl; std::cout << " med_path: " << med_path << std::endl; std::cout << " long_path: " << long_path << std::endl; std::cout << "pass_through(invalid, invalid): " << std::boolalpha << passes_through(adobe::nbitpath(), adobe::nbitpath()) << std::endl; std::cout << "pass_through(invalid, small): " << std::boolalpha << passes_through(adobe::nbitpath(), small_path) << std::endl; std::cout << "pass_through(invalid, med): " << std::boolalpha << passes_through(adobe::nbitpath(), med_path) << std::endl; std::cout << "pass_through(invalid, long): " << std::boolalpha << passes_through(adobe::nbitpath(), long_path) << std::endl; std::cout << "pass_through(small, invalid): " << std::boolalpha << passes_through(small_path, adobe::nbitpath()) << std::endl; std::cout << "pass_through(small, small): " << std::boolalpha << passes_through(small_path, small_path) << std::endl; std::cout << "pass_through(small, med): " << std::boolalpha << passes_through(small_path, med_path) << std::endl; std::cout << "pass_through(small, long): " << std::boolalpha << passes_through(small_path, long_path) << std::endl; std::cout << "pass_through(med, invalid): " << std::boolalpha << passes_through(med_path, adobe::nbitpath()) << std::endl; std::cout << "pass_through(med, small): " << std::boolalpha << passes_through(med_path, small_path) << std::endl; std::cout << "pass_through(med, med): " << std::boolalpha << passes_through(med_path, med_path) << std::endl; std::cout << "pass_through(med, long): " << std::boolalpha << passes_through(med_path, long_path) << std::endl; std::cout << "pass_through(long, invalid): " << std::boolalpha << passes_through(long_path, adobe::nbitpath()) << std::endl; std::cout << "pass_through(long, small): " << std::boolalpha << passes_through(long_path, small_path) << std::endl; std::cout << "pass_through(long, med): " << std::boolalpha << passes_through(long_path, med_path) << std::endl; std::cout << "pass_through(long, long): " << std::boolalpha << passes_through(long_path, long_path) << std::endl; } return 0; } catch(const std::exception& error) { std::cerr << "Exception: " << error.what() << std::endl; return 1; } catch(...) { std::cerr << "Exception: unknown" << std::endl; return 1; }