GLConstArrayWrapper(OS * p_os, int offs, int req_values = 0): os(p_os) { bool valid_type = os->isArray(offs) || os->isObject(offs); int param_size = valid_type ? os->getLen(offs) : 0; src_size = req_values > 0 ? req_values : param_size; if(src_size < 1) { OS_ASSERT(false); src = NULL; return; } src = (T*)os->malloc(sizeof(*src) * src_size OS_DBG_FILEPOS); int i = 0; os->pushStackValue(offs); for(; i < param_size && os->nextIteratorStep(); i++) { src[i] = (T)os->toNumber(-1); os->pop(2); } os->pop(); for(; i < src_size; i++) { src[i] = (T)0; } }
int _tmain(int argc, _TCHAR* argv[]) { // craete ObjectScript instance OS * os = OS::create(); // run program os->require("../../examples-os/run_os_prog.os"); // release the ObjectScript instance os->release(); return 0; }
static void wrapper_glutTimerFunc(int p1) { OS_ASSERT(instance); if(instance) { OS * os = instance->os; GlutFunc * timer = instance->getTimerById(p1); if(timer) { os->pushValueById(timer->func); os->pushNull(); timer->release(os); os->call(0, 0); } } }
int ConfigFile::Write(const char *name){ Section *s; s=&head; bool first=true; File *fp=os.GetFile(name); if(fp->OpenWrite()){ while(s!=NULL){ string str; s->Write(&str); fp->WriteStr((char*)str.c_str()); s=s->GetNext(); } modified=false; delete fp; return true; }else{ printf("\nFailed to save config file %s\n",name); delete fp; return false; } }
ConfigFile::ConfigFile(const char *name, bool newfile) { filename=name; lastaccess=NULL; printf ("Use config file %s\n", filename.c_str()); if(!newfile){ File *fp=os.GetFile(filename.c_str()); char line[1024]; string section; section=""; if(fp->OpenRead()){ while(fp->ReadLine(line,1023)!=NULL) { if(line[0]=='['){ //new section char *ptr=strchr(line,']'); if(ptr!=NULL) *ptr='\0'; section=(&line[1]); }else{ //normal line head.AddLineToSection(line,(char*)section.c_str()); } } } delete fp; }; }
static void wrapper_glutJoystickFunc(unsigned int p1, int p2, int p3, int p4) { OS_ASSERT(instance); if(instance) { OS * os = instance->os; os->pushValueById(instance->glutJoystickFunc); os->pushNull(); os->pushNumber(p1); os->pushNumber(p2); os->pushNumber(p3); os->pushNumber(p4); os->call(4, 0); } }
void addNewProcesses(istream &in, OS& os) { string process_declaration = ""; getline(in, process_declaration); while (getline(in, process_declaration)) { istringstream iss(process_declaration); string process_name = ""; size_t begin_time = 0; size_t duration = 0; size_t io_begin = 0; size_t io_duration = 0; iss >> process_name >> begin_time >> duration; process_ptr p(new Process(process_name, begin_time, duration)); while (iss >> io_begin >> io_duration) p->addIO(io_ptr(new IO(io_begin, io_duration))); os.addProcess(p); } }
int _tmain(int argc, _TCHAR* argv[]) { // craete ObjectScript instance OS * os = OS::create(); registerTestClass(os); registerNewTestClass(os); initMyModule(os); os->setGlobal(def("getcwd", getcwdString)); os->setGlobal(def("printTestStruct", printTestStruct)); os->setGlobal(def("changeTestStruct", changeTestStruct)); // run program os->require("../../examples-os/bind.os"); // release the ObjectScript instance os->release(); return 0; }
int main(int argc, char *argv[]) #endif { if(argc < 2){ printf("ObjctScript " OS_VERSION " Copyright (C) 2012-2013 Evgeniy Golovin ([email protected])\n"); printf("Latest version and source code: https://github.com/unitpoint/objectscript\n"); printf("\n"); printf("Usage: %s script.os [args]\n", argv[0]); exit(1); } // create ObjectScript instance #if 0 class MyOS: public OS { public: MyOS(){} void initPreScript() { setSetting(OS_SETTING_CREATE_TEXT_EVAL_OPCODES, true); OS::initPreScript(); } }; OS * os = OS::create(new MyOS()); #else OS * os = OS::create(); #endif #ifndef OS_CURL_DISABLED initCurlLibrary(os); #endif #ifndef OS_SQLITE3_DISABLED initSqlite3Library(os); #endif #ifndef OS_REGEXP_DISABLED initRegexpLibrary(os); #endif // save allocated memory at start point int start_mem_usage = os->getAllocatedBytes(); // set needed settings os->setSetting(OS_SETTING_CREATE_DEBUG_INFO, true); os->setSetting(OS_SETTING_CREATE_TEXT_OPCODES, true); os->setSetting(OS_SETTING_CREATE_COMPILED_FILE, true); // create program arguments os->newObject(); for(int i = 0; i < argc; i++){ os->pushStackValue(-1); os->pushNumber(i-1); os->pushString(getString(os, argv[i])); os->setProperty(); } // we can use the program arguments as global arg variable inside of our script os->setGlobal("arg"); // set global getTimeSec function so we can check time inside of our script os->setGlobal(def("getTimeSec", getTimeSec)); // run main stript // os->require("c:\\Sources\\OS\\proj.win32\\profile_benchmark\\scripts\\n-body.os"); // getString(os, argv[1])); // os->require("c:\\Sources\\OS\\unit-tests-os\\operators.os"); // getString(os, argv[1])); // os->require(getString(os, argv[1])); #if 1 os->require(getString(os, argv[1]), true, 0, OS_SOURCECODE_AUTO); #else os->compileFile(getString(os, argv[1])); os->pushNull(); os->call(); #endif { int mem_allocated = os->getAllocatedBytes()/1024; int mem_cached = os->getCachedBytes()/1024; // run gc full step os->gcFull(); int after_mem_allocated = os->getAllocatedBytes()/1024; int after_mem_cached = os->getCachedBytes()/1024; // output some debug memory usage info printf("\n\n[before GC] memory used: %d Kb, cached: %d Kb, allocated: %d Kb\n[after GC] memory used: %d Kb, cached: %d Kb, allocated: %d Kb\n", mem_allocated - mem_cached, mem_cached, mem_allocated, after_mem_allocated - after_mem_cached, after_mem_cached, after_mem_allocated ); #ifdef OS_DEBUG printf("\nNotice: debug build uses much more memory than release build\n"); #endif } // release the ObjectScript instance os->release(); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { if(argc < 2){ printf("ObjctScript " OS_VERSION " Copyright (C) 2012 Evgeniy Golovin ([email protected])\n"); printf("Latest version and source code: https://github.com/unitpoint/objectscript\n"); printf("\n"); printf("Usage: %s script [args]\n", argv[0]); exit(1); } // craete ObjectScript instance OS * os = OS::create(); // save allocated memory at start point int start_mem_usage = os->getAllocatedBytes(); // set needed settings os->setSetting(OS_SETTING_CREATE_DEBUG_INFO, true); os->setSetting(OS_SETTING_CREATE_DEBUG_OPCODES, true); os->setSetting(OS_SETTING_CREATE_COMPILED_FILE, true); // create program arguments os->newObject(); for(int i = 0; i < argc; i++){ os->pushStackValue(-1); os->pushNumber(i-1); os->pushString(getString(os, argv[i])); os->setProperty(); } // we can use the program arguments as global arg variable inside of our script os->setGlobal("arg"); // set global getTimeSec function so we can check time inside of our script os->pushCFunction(OS_getTimeSec); os->setGlobal("getTimeSec"); // run main stript os->require(getString(os, argv[1])); { int mem_allocated = os->getAllocatedBytes()/1024; int mem_cached = os->getCachedBytes()/1024; // run gc full step os->gcFull(); int after_mem_allocated = os->getAllocatedBytes()/1024; int after_mem_cached = os->getCachedBytes()/1024; // output some debug memory usage info printf("\n\n[before GC] memory used: %d Kb, cached: %d Kb, allocated: %d Kb\n[after GC] memory used: %d Kb, cached: %d Kb, allocated: %d Kb\n", mem_allocated - mem_cached, mem_cached, mem_allocated, after_mem_allocated - after_mem_cached, after_mem_cached, after_mem_allocated ); #ifdef OS_DEBUG printf("\nNotice: debug build uses much more memory than release build\n"); #endif } // release the ObjectScript instance os->release(); return 0; }
int main(int argc, char * argv[]) #endif { initStartTime(); printf("ObjectScript FastCGI Process Manager %s\n", OS_FCGI_VERSION); printf("%s\n", OS_COPYRIGHT); printf("%s\n", OS_OPENSOURCE); if(FCGX_Init()){ // #ifdef _MSC_VER printf("Error: initialization is failed\n"); // #endif exit(1); } int threads; { OS * os = OS::create(); #ifdef _MSC_VER const char * config_flename = "conf\\etc\\os-fcgi\\conf.os"; if(!os->isFileExist(config_flename)){ config_flename = "..\\..\\conf\\etc\\os-fcgi\\conf.os"; // os->isFileExist(config_flename); } #else const char * config_flename = "/etc/os-fcgi/conf.os"; #endif os->require(config_flename, false, 1); threads = (os->getProperty(-1, "threads"), os->popInt()); OS::String listen = (os->getProperty(-1, "listen"), os->popString(":9000")); os->release(); int listen_queue_backlog = 400; listen_socket = FCGX_OpenSocket(listen, listen_queue_backlog); if(listen_socket < 0){ printf("Error: listen address is incorrect %s\n", listen.toChar()); // log("listen_socket < 0 \n"); exit(1); } // #ifdef _MSC_VER printf("listen: %s\n", listen.toChar()); // #endif } #ifndef _MSC_VER const int MAX_THREAD_COUNT = 64; if(threads < 1){ threads = 1; }else if(threads > MAX_THREAD_COUNT){ threads = MAX_THREAD_COUNT; } printf("threads: %d\n", threads); demonize(); pthread_t id[MAX_THREAD_COUNT]; for(int i = 1; i < threads; i++){ pthread_create(&id[i], NULL, doit, NULL); } #else threads = 1; printf("threads: %d\n", threads); #endif doit(NULL); return 0; }
int main() { /*cout << "MFT "<<sizeof(MFT) << endl; cout << "BLOCK "<<sizeof(Block) << endl; cout << "BLOCKs " << _AllBlocksCount << endl; cout << "Entity " << sizeof(Entity) << endl;*/ string command; OS os; while (true) { cout << os.GetCurrentFolder() << "> "; cin >> command; if (command == "exit") break; else if (command == "dir") os.ShowFiles(); else if (command == "mkfolder") os.CreateEntity(_FOLDER); else if (command == "mkfile") os.CreateEntity(_FILE); else if (command == "rm") os.Remove(); else if (command == "format") os.Format(); else if (command == "cd") os.ChangeFolder(); else if (command == "move") os.Move(); else if (command == "paste") os.Paste(); else if (command == "open") os.OpenFile(); else if (command == "cls") system("cls"); else cout << " Unknown command" << endl; } return 0; }
int _tmain(int argc, _TCHAR* argv[]) { // craete ObjectScript instance OS * os = OS::create(); /* Part 1: let's simulate following OS code: print("10 * (3+2) = ", 10 * (3+2)) */ // prepare function call os->getGlobal("print"); // #1 - stack values, it's print function from standart library os->pushNull(); // #2 - null, it's function this, each call of function must have this // push the first argument os->pushString("10 * (3+2) = "); // #3 - we have 3 stack values here // prepare second argument os->pushNumber(10); // #4 os->pushNumber(3); // #5 os->pushNumber(2); // #6 os->runOp(OP_ADD); // #5 - 3+2 os->runOp(OP_MUL); // #4 - 10 * (3+2) // we have 4 stack values here: // #1 - function // #2 - function this, it's null here // #3 - string "10 * (3+2) = " // #4 - number, it's result of 10 * (3+2), it's 50 // we are ready to call function with arguments os->call(2); // call function with 2 arguments // #0 - called function remove all used stack values // please see console to view output of this example /* Part 2: let's simulate following OS code: bar = {firsname="James", lastname="Bond"} bar.profession = "actor" print bar */ os->newObject(); // #1 - new object os->pushStackValue(-1); // #2 - the same object, -1 - is relative pointer to the top stack value os->pushString("firsname"); // #3 - property key os->pushString("James"); // #4 - property value os->setProperty(); // #1 - setProperty uses 3 stack values and pop them // second way of same functionality os->pushString("Bond"); // #2 - property value os->setProperty(-2, "lastname"); // #1 os->setGlobal("bar"); // #0 - assign object value to global bar variable, pop value // let's do bar.profession = "actor" os->getGlobal("bar"); // #1 - our global a variable os->pushString("actor"); // #2 - property value os->setProperty(-2, "profession"); // #1 os->pop(); // #0 // let's do print bar os->getGlobal("print"); // #1 os->pushNull(); // #2 os->getGlobal("bar"); // #3 os->call(1); // #0 /* Part 3: let's simulate following OS code: print(concat(5, " big differences")) */ os->getGlobal("print"); // #1 - print function os->pushNull(); // #2 - this for print os->getGlobal("concat"); // #3 - concat function os->pushNull(); // #4 - this for concat os->pushNumber(5); // #5 os->pushString(" big differences"); // #6 // call concat function with 2 arguments and 1 requested result value // the call pops 2 arguments + 1 this + 1 function and pushes 1 result value os->call(2, 1); // #3 - result is already at the top of stack // call print function with 1 arguments and 0 requested result values os->call(1); // #0 // release the ObjectScript instance os->release(); return 0; }
~GLConstArrayWrapper() { os->free(src); }