void Debugger::handleInvoke(Interpreter interpreter, const Arabica::DOM::Element<std::string>& invokeElem, const std::string& invokeId, Breakpoint::When when, Breakpoint::Action action) { if (!interpreter.isRunning()) return; boost::shared_ptr<DebugSession> session = getSession(interpreter); if (!session) return; Breakpoint breakpointTemplate; breakpointTemplate.when = when; breakpointTemplate.action = action; std::list<Breakpoint> qualifiedBreakpoints = getQualifiedInvokeBreakpoints(interpreter, invokeElem, invokeId, breakpointTemplate); session->checkBreakpoints(qualifiedBreakpoints); }
int main() { Interpreter inter; inter.statement_analyzer ("var s=4;"); inter.statement_analyzer ("var g=5-2*s;"); inter.statement_analyzer ("print g;"); inter.statement_analyzer ("print \"\n\";"); inter.statement_analyzer ("pause;"); }
void inkamath_test() { Interpreter<complex<double>> p; queue<string> s; s.push("[pi, e]"); s.push("A=[a a; a a]"); s.push("a=[1 2;3 4]"); s.push("A"); s.push("exp(x)_n=exp(x)_(n-1)+x^n/!n"); s.push("exp(1)"); s.push("cos(x)=(exp(i*x)+exp(-i*x))/2"); s.push("sin(x)=(exp(i*x)-exp(-i*x))/(2*i)"); s.push("sin(pi/6)"); while(!s.empty()) { cout << ">> " << s.front() << endl; if(s.front()=="q") break; // quit interpreter cout << p.Eval(s.front()) << endl << endl; s.pop(); } }
bool canHandleOpcodes(CodeBlock* codeBlock) { Interpreter* interpreter = codeBlock->globalData()->interpreter; Instruction* instructionsBegin = codeBlock->instructions().begin(); unsigned instructionCount = codeBlock->instructions().size(); for (unsigned bytecodeOffset = 0; bytecodeOffset < instructionCount; ) { switch (interpreter->getOpcodeID(instructionsBegin[bytecodeOffset].u.opcode)) { #define DEFINE_OP(opcode, length) \ case opcode: \ if (!canHandleOpcode(opcode)) \ return false; \ bytecodeOffset += length; \ break; FOR_EACH_OPCODE_ID(DEFINE_OP) #undef DEFINE_OP default: ASSERT_NOT_REACHED(); break; } } return true; }
void computePreciseJumpTargets(CodeBlock* codeBlock, Vector<unsigned, 32>& out) { ASSERT(out.isEmpty()); // We will derive a superset of the jump targets that the code block thinks it has. // So, if the code block claims there are none, then we are done. if (!codeBlock->numberOfJumpTargets()) return; for (unsigned i = codeBlock->numberOfExceptionHandlers(); i--;) out.append(codeBlock->exceptionHandler(i).target); Interpreter* interpreter = codeBlock->vm()->interpreter; Instruction* instructionsBegin = codeBlock->instructions().begin(); unsigned instructionCount = codeBlock->instructions().size(); for (unsigned bytecodeOffset = 0; bytecodeOffset < instructionCount;) { OpcodeID opcodeID = interpreter->getOpcodeID(instructionsBegin[bytecodeOffset].u.opcode); getJumpTargetsForBytecodeOffset(codeBlock, interpreter, instructionsBegin, bytecodeOffset, out); bytecodeOffset += opcodeLengths[opcodeID]; } std::sort(out.begin(), out.end()); // We will have duplicates, and we must remove them. unsigned toIndex = 0; unsigned fromIndex = 0; unsigned lastValue = UINT_MAX; while (fromIndex < out.size()) { unsigned value = out[fromIndex++]; if (value == lastValue) continue; out[toIndex++] = value; lastValue = value; } out.resize(toIndex); }
int main() { plan(8); Interpreter universe; String value = universe.value_of("test"); ok(value, "value"); is(value, "test", "value == \"test\""); isnt(value, "tset", "value != \"tset\""); is(value, std::string("test"), "value = std::string(\"test\")"); is(value.length(), 4u, "length(value) == 4"); note("value.replace(2, 2, value)"); value.replace(2, 2, value); is(value, "tetest", "value = \"tetest\""); note("value.insert(2, \"st\")"); value.insert(2, "st"); is(value, "testtest", "value == \"testest\""); note("value = \"test\""); value = "test"; is(value, "test", "value == \"test\""); return exit_status(); }
void Debugger::handleInvoke(Interpreter& interpreter, const XERCESC_NS::DOMElement* invokeElem, const std::string& invokeId, Breakpoint::When when, Breakpoint::Action action) { InterpreterImpl* impl = interpreter.getImpl().get(); std::shared_ptr<DebugSession> session = getSession(impl); if (!session) return; if (!session->_isRunning) return; Breakpoint breakpointTemplate; breakpointTemplate.when = when; breakpointTemplate.action = action; std::list<Breakpoint> qualifiedBreakpoints = getQualifiedInvokeBreakpoints(impl, invokeElem, invokeId, breakpointTemplate); session->checkBreakpoints(qualifiedBreakpoints); }
void PostponeElement::Resubmitter::onStableConfiguration(Interpreter interpreter) { std::list<Postponed>::iterator eventIter = _postponedEvents.begin(); bool dispatched = false; while(eventIter != _postponedEvents.end()) { try { // LOG(INFO) << "Reevaluating: >> " << eventIter->first << " <<"; if ((!dispatched || eventIter->chaining) && interpreter.getDataModel().evalAsBool(eventIter->until)) { // LOG(INFO) << " -> is TRUE"; eventIter->event.name += ".postponed"; interpreter.receive(eventIter->event, true); _postponedEvents.erase(eventIter++); dispatched = true; } // LOG(INFO) << " -> is FALSE"; } catch (Event e) { LOG(ERROR) << "Syntax error while evaluating until attribute of postpone element:" << std::endl << e << std::endl; _postponedEvents.erase(eventIter++); continue; } eventIter++; } // LOG(ERROR) << _postponedEvents.size() << " Postponess remaining"; }
int main(void){ vector<int>b; set<int> a; b.push_back(1); b.push_back(2); b.push_back(1); b.push_back(2); a.insert(b.begin(), b.end()); Interpreter interpreter; //AUXInsertInto* newwww = static_cast<AUXInsertInto*>(neww); API api; fstream fp; //fp.open("/Users/jason/Desktop/file", ios::in|ios::binary); //freopen("/Users/jason/Desktop/file", "r", stdin); while (true) { cout<<">>"; AUX* neww = interpreter.dealInput(); if(neww->quit) return 0; api.chooseCommand(neww); cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@"<<endl; } cout<<"haha"; }
void Debugger::handleMicrostep(Interpreter interpreter, Breakpoint::When when) { if (!interpreter.isRunning()) return; boost::shared_ptr<DebugSession> session = getSession(interpreter); if (!session) return; std::list<Breakpoint> breakpoints; Breakpoint breakpoint; breakpoint.when = when; breakpoint.subject = Breakpoint::MICROSTEP; breakpoints.push_back(breakpoint); session->checkBreakpoints(breakpoints); }
void Debugger::handleMicrostep(Interpreter& interpreter, Breakpoint::When when) { InterpreterImpl* impl = interpreter.getImpl().get(); std::shared_ptr<DebugSession> session = getSession(impl); if (!session) return; if (!session->_isRunning) return; std::list<Breakpoint> breakpoints; Breakpoint breakpoint; breakpoint.when = when; breakpoint.subject = Breakpoint::MICROSTEP; breakpoints.push_back(breakpoint); session->checkBreakpoints(breakpoints); }
std::list<Breakpoint> getQualifiedInvokeBreakpoints(Interpreter interpreter, const Arabica::DOM::Element<std::string>& invokeElem, const std::string invokeId, Breakpoint breakpointTemplate) { std::list<Breakpoint> breakpoints; Breakpoint bp = breakpointTemplate; // copy base as template bp.subject = Breakpoint::INVOKER; bp.element = invokeElem; bp.invokeId = invokeId; if (HAS_ATTR(invokeElem, "type")) { bp.invokeType = ATTR(invokeElem, "type"); } else if (HAS_ATTR(invokeElem, "typeexpr")) { bp.invokeType = interpreter.getDataModel().evalAsString(ATTR(invokeElem, "typeexpr")); } breakpoints.push_back(bp); return breakpoints; }
void Debugger::handleEvent(Interpreter interpreter, const Event& event, Breakpoint::When when) { if (!interpreter.isRunning()) return; boost::shared_ptr<DebugSession> session = getSession(interpreter); if (!session) return; std::list<Breakpoint> breakpoints; Breakpoint breakpoint; breakpoint.when = when; breakpoint.eventName = event.name; breakpoint.subject = Breakpoint::EVENT; breakpoints.push_back(breakpoint); session->checkBreakpoints(breakpoints); }
void Debugger::handleEvent(Interpreter& interpreter, const Event& event, Breakpoint::When when) { InterpreterImpl* impl = interpreter.getImpl().get(); std::shared_ptr<DebugSession> session = getSession(impl); if (!session) return; if (!session->_isRunning) return; std::list<Breakpoint> breakpoints; Breakpoint breakpoint; breakpoint.when = when; breakpoint.eventName = event.name; breakpoint.subject = Breakpoint::EVENT; breakpoints.push_back(breakpoint); session->checkBreakpoints(breakpoints); }
void Debugger::handleExecutable(Interpreter& interpreter, const XERCESC_NS::DOMElement* execContentElem, Breakpoint::When when) { std::shared_ptr<DebugSession> session = getSession(interpreter.getImpl().get()); if (!session) return; if (!session->_isRunning) return; std::list<Breakpoint> breakpoints; Breakpoint breakpoint; breakpoint.when = when; breakpoint.element = execContentElem; breakpoint.executableName = X(execContentElem->getLocalName()).str(); breakpoint.subject = Breakpoint::EXECUTABLE; breakpoints.push_back(breakpoint); session->checkBreakpoints(breakpoints); }
void Debugger::handleExecutable(Interpreter interpreter, const Arabica::DOM::Element<std::string>& execContentElem, Breakpoint::When when) { if (!interpreter.isRunning()) return; boost::shared_ptr<DebugSession> session = getSession(interpreter); if (!session) return; std::list<Breakpoint> breakpoints; Breakpoint breakpoint; breakpoint.when = when; breakpoint.element = execContentElem; breakpoint.executableName = execContentElem.getLocalName(); breakpoint.subject = Breakpoint::EXECUTABLE; breakpoints.push_back(breakpoint); session->checkBreakpoints(breakpoints); }
int main() { welcome(); vector<Condition> conditions; Table tableinfor; Index indexinfor; Row insertValue; Data datas; char command[COMLEN] = ""; char input[INPUTLEN] = ""; char word[WORDLEN] = ""; short int ComEnd = 0; FILE *stream; stream=freopen("D:\\test.txt","r",stdin); /*FILE *fileout; fileout=freopen("result.txt","w",stdout);*/ //int count = 0; while(1) { strcpy(command, "");//command���� ComEnd = 0; cout<<" Adward's Database >>"; while(!ComEnd) { /* count ++; if(count % 100 == 0) cout << count/100 << "%" << endl;*/ gets(input); if(IsComEnd(input)) ComEnd = 1; strcat(command, input); AddSeperator(command); } parsetree.Parse(command); Execute(); } getchar(); return 0; }
static bool runWithScripts(GlobalObject* globalObject, const Vector<UString>& fileNames, bool dump) { Vector<char> script; if (dump) BytecodeGenerator::setDumpsGeneratedCode(true); #if ENABLE(OPCODE_SAMPLING) Interpreter* interpreter = globalObject->globalData()->interpreter; interpreter->setSampler(new SamplingTool(interpreter)); #endif bool success = true; for (size_t i = 0; i < fileNames.size(); i++) { UString fileName = fileNames[i]; if (!fillBufferWithContentsOfFile(fileName, script)) return false; // fail early so we can catch missing files #if ENABLE(OPCODE_SAMPLING) interpreter->sampler()->start(); #endif Completion completion = evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(script.data(), fileName)); success = success && completion.complType() != Throw; if (dump) { if (completion.complType() == Throw) printf("Exception: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); else printf("End: %s\n", completion.value()->toString(globalObject->globalExec()).ascii()); } globalObject->globalExec()->clearException(); #if ENABLE(OPCODE_SAMPLING) interpreter->sampler()->stop(); #endif } #if ENABLE(OPCODE_SAMPLING) interpreter->sampler()->dump(globalObject->globalExec()); delete interpreter->sampler(); #endif return success; }
/** * \brief Program mapujacy uzytkownikow do odpowiednich CI * * \author Przemyslaw Piorkowski <*****@*****.**> * */ int main() { std::cout << "Map users to cell in process..." << std::endl; Connection * conn; Interpreter * interpreter = new Interpreter(); int dataSize; try { conn = new Connection(4000, 1024); } catch(SocketException& e) { std::cout << e.what() << std::endl; return -1; } /** * Glowna petla programu odpowiedzialna za odbior i przetworzenie danych. * W przyszlosci tutaj rodzial na watki dla kazdego przychodzacego pakietu. */ while(1) { dataSize = conn->receiveData(); std::cout << "Rozmiar odebranych danych " << dataSize << std::endl; interpreter->loadBuffer(conn->getBuffer(), dataSize); interpreter->interpreteData(); std::cout << "Version : " << interpreter->getVersion() << std::endl; std::cout << "Count : " << interpreter->getMessagesCounter() << std::endl; std::cout << "Length : " << interpreter->getLength() << std::endl; std::cout << "Writing data to file \n" << std::endl; interpreter->writeBufferToFile(); } return 0; }
int main(int argc, char** argv) { using namespace uscxml; std::set_terminate(customTerminate); #if defined(HAS_SIGNAL_H) && !defined(WIN32) signal(SIGPIPE, SIG_IGN); #endif if (argc < 2) { printUsageAndExit(); } google::InitGoogleLogging(argv[0]); google::LogToStderr(); HTTPServer::getInstance(8088, 8089); #ifndef _WIN32 opterr = 0; #endif int option; while ((option = getopt(argc, argv, "vl:p:")) != -1) { switch(option) { case 'l': google::InitGoogleLogging(optarg); break; case 'p': uscxml::Factory::setDefaultPluginPath(optarg); break; case '?': break; default: printUsageAndExit(); break; } } #if 0 while(true) { Interpreter interpreter = Interpreter::fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test235.scxml"); interpreter.interpret(); } #else DirectoryWatch* watcher = new DirectoryWatch(argv[optind], true); watcher->updateEntries(true); std::map<std::string, struct stat> entries = watcher->getAllEntries(); StatusMonitor vm; std::map<std::string, struct stat>::iterator entryIter = entries.begin(); while(entryIter != entries.end()) { if (!boost::ends_with(entryIter->first, ".scxml")) { entryIter++; continue; } startedAt = time(NULL); lastTransitionAt = time(NULL); LOG(INFO) << "Processing " << entryIter->first; Interpreter interpreter = Interpreter::fromURL(std::string(argv[optind]) + PATH_SEPERATOR + entryIter->first); if (interpreter) { // interpreter.setCmdLineOptions(argc, argv); interpreter.addMonitor(&vm); interpreter.start(); int now = time(NULL); while(now - startedAt < 20 && now - lastTransitionAt < 2) { // let the interpreter run for a bit tthread::this_thread::sleep_for(tthread::chrono::seconds(1)); now = time(NULL); } } entryIter++; } delete watcher; #endif return EXIT_SUCCESS; }
Variable* add(Variable* A, Variable* B) { if(A == NULL || B == NULL) { interpreter.error("Error: Void variable in addition.\n"); return NULL; } TypeEnum a = A->getType(); TypeEnum b = B->getType(); if(a != b && !(a == FLOAT && b == INT) && !(b == FLOAT && a == INT)) { interpreter.error("Error: Types do not match in addition: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str()); return NULL; } if(a == STRING) { String* C = static_cast<String*>(A); String* D = static_cast<String*>(B); String* R = new String("<temp>"); R->setValue(C->getValue() + D->getValue()); return R; } else if(a == INT) { Int* C = static_cast<Int*>(A); if(b == INT) { Int* D = static_cast<Int*>(B); Int* R = new Int; R->setValue(C->getValue() + D->getValue()); return R; } else { Float* D = static_cast<Float*>(B); Float* R = new Float; R->setValue(C->getValue() + D->getValue()); return R; } } else if(a == FLOAT) { Float* C = static_cast<Float*>(A); Float* R = new Float; if(b == INT) { Int* D = static_cast<Int*>(B); R->setValue(C->getValue() + D->getValue()); } else { Float* D = static_cast<Float*>(B); R->setValue(C->getValue() + D->getValue()); } return R; } else if(a == BOOL) { interpreter.error("Error: Addition operation not defined for type 'bool'.\n"); return NULL; } else if(a == MACRO) { Macro* C = static_cast<Macro*>(A); Macro* D = static_cast<Macro*>(B); Macro* R = new Macro; R->setValue(C->getValue() + D->getValue()); return R; } else if(a == ARRAY) { Array* C = static_cast<Array*>(A); Array* D = static_cast<Array*>(B); a = C->getValueType(); b = D->getValueType(); if(a != b) { interpreter.error("Error: Types do not match in addition: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str()); return NULL; } vector<Variable*> va = C->getValue(); vector<Variable*>& vb = D->getValue(); for(vector<Variable*>::iterator e = vb.begin(); e != vb.end(); e++) { va.push_back(*e); } Array* arr = new Array("<temp>", va, a); return arr; } else if(a == LIST) { List* C = static_cast<List*>(A); List* D = static_cast<List*>(B); list<Variable*> va = C->getValue(); list<Variable*>& vb = D->getValue(); for(list<Variable*>::iterator e = vb.begin(); e != vb.end(); e++) { va.push_back(*e); } List* lst = new List("<temp>", va); return lst; } else if(a == FUNCTION) { Function* C = static_cast<Function*>(A); Function* D = static_cast<Function*>(B); Function* R = new Function("<temp>", FN_NONE); R->setValue(C->getValue() + D->getValue()); return R; } else if(a == PROCEDURE) { Procedure* C = static_cast<Procedure*>(A); Procedure* D = static_cast<Procedure*>(B); Procedure* R = new Procedure("<temp>"); R->setValue(C->getValue() + D->getValue()); return R; } return A; }
Variable* add_assign(Variable* A, Variable* B) { if(A == NULL || B == NULL) { interpreter.error("Error: Void variable in assignment.\n"); return NULL; } if(!A->reference) { interpreter.error("Error: Assigning value to a non-reference variable.\n"); return NULL; } TypeEnum a = A->getType(); TypeEnum b = B->getType(); bool mismatch = false; if(a == STRING) { if(b != STRING) mismatch = true; else { String* C = static_cast<String*>(A); String* D = static_cast<String*>(B); C->setValue(C->getValue() + D->getValue()); } } else if(a == INT) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Int* C = static_cast<Int*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); C->setValue(C->getValue() + D->getValue()); } else if(b == INT) { Int* D = static_cast<Int*>(B); C->setValue(C->getValue() + D->getValue()); } else { Float* D = static_cast<Float*>(B); C->setValue(C->getValue() + D->getValue()); } } } else if(a == FLOAT) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Float* C = static_cast<Float*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); C->setValue(C->getValue() + D->getValue()); } else if(b == INT) { Int* D = static_cast<Int*>(B); C->setValue(C->getValue() + D->getValue()); } else { Float* D = static_cast<Float*>(B); C->setValue(C->getValue() + D->getValue()); } } } else if(a == BOOL) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Bool* C = static_cast<Bool*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); C->setValue(C->getValue() + D->getValue()); } else if(b == INT) { Int* D = static_cast<Int*>(B); C->setValue(C->getValue() + D->getValue()); } else { Float* D = static_cast<Float*>(B); C->setValue(C->getValue() + D->getValue()); } } } else if(a == MACRO) { interpreter.error("Error: Addition operation not defined for type 'macro'.\n"); return NULL; } else if(a == ARRAY) { if(b == ARRAY) { Array* C = static_cast<Array*>(A); Array* D = static_cast<Array*>(B); a = C->getValueType(); b = C->getValueType(); if(a != b) { interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str()); return NULL; } C->push_back(D->getValue()); } else { Array* C = static_cast<Array*>(A); if(b == C->getValueType()) { C->push_back(B); } else mismatch = true; } } else if(a == LIST) { // Lists must be concatenated a different way... List* C = static_cast<List*>(A); C->push_back(B); } else if(a == FUNCTION) { interpreter.error("Error: Addition operation not defined for type 'function'.\n"); return NULL; } else if(a == PROCEDURE) { interpreter.error("Error: Addition operation not defined for type 'procedure'.\n"); return NULL; } if(mismatch) { interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str()); return NULL; } return A; }
Variable* assign(Variable* A, Variable* B) { if(A == NULL || B == NULL) { interpreter.error("Error: Void variable in assignment.\n"); return NULL; } if(!A->reference) { interpreter.error("Error: Assigning value to a non-reference variable.\n"); return NULL; } TypeEnum a = A->getType(); TypeEnum b = B->getType(); bool mismatch = false; if(a == STRING) { if(b != STRING) mismatch = true; else { String* C = static_cast<String*>(A); String* D = static_cast<String*>(B); C->setValue(D->getValue()); } } else if(a == INT) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Int* C = static_cast<Int*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); C->setValue(D->getValue()); } else if(b == INT) { Int* D = static_cast<Int*>(B); C->setValue(D->getValue()); } else { Float* D = static_cast<Float*>(B); C->setValue(D->getValue()); } } } else if(a == FLOAT) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Float* C = static_cast<Float*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); C->setValue(D->getValue()); } else if(b == INT) { Int* D = static_cast<Int*>(B); C->setValue(D->getValue()); } else { Float* D = static_cast<Float*>(B); C->setValue(D->getValue()); } } } else if(a == BOOL) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Bool* C = static_cast<Bool*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); C->setValue(D->getValue()); } else if(b == INT) { Int* D = static_cast<Int*>(B); C->setValue(D->getValue()); } else { Float* D = static_cast<Float*>(B); C->setValue(D->getValue()); } } } else if(a == MACRO) { if(b != MACRO) mismatch = true; else { Macro* C = static_cast<Macro*>(A); Macro* D = static_cast<Macro*>(B); C->setValue(D->getValue()); } } else if(a == ARRAY) { if(b != ARRAY) mismatch = true; else { Array* C = static_cast<Array*>(A); Array* D = static_cast<Array*>(B); a = C->getValueType(); b = D->getValueType(); if(a != b) { interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str()); return NULL; } C->setValue(D->getValue()); } } else if(a == LIST) { if(b != LIST) mismatch = true; else { List* C = static_cast<List*>(A); List* D = static_cast<List*>(B); C->setValue(D->getValue()); } } else if(a == FUNCTION) { if(b != FUNCTION) mismatch = true; else { Function* C = static_cast<Function*>(A); Function* D = static_cast<Function*>(B); C->setValue(D->getValue()); } } else if(a == PROCEDURE) { if(b != PROCEDURE) mismatch = true; else { Procedure* C = static_cast<Procedure*>(A); Procedure* D = static_cast<Procedure*>(B); C->setValue(D->getValue()); } } if(mismatch) { interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str()); return NULL; } return A; }
Bool* comparison(Variable* A, Variable* B, OperatorEnum oper) { if(A == NULL || B == NULL) { interpreter.error("Error: Void variable in assignment.\n"); return NULL; } TypeEnum a = A->getType(); TypeEnum b = B->getType(); bool mismatch = false; if(a == STRING) { if(b != STRING) mismatch = true; else { String* C = static_cast<String*>(A); String* D = static_cast<String*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } else if(a == INT) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Int* C = static_cast<Int*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } else if(b == INT) { Int* D = static_cast<Int*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } else { Float* D = static_cast<Float*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } } else if(a == FLOAT) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Float* C = static_cast<Float*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } else if(b == INT) { Int* D = static_cast<Int*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } else { Float* D = static_cast<Float*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } } else if(a == BOOL) { if(b != BOOL && b != INT && b != FLOAT) mismatch = true; else { Bool* C = static_cast<Bool*>(A); if(b == BOOL) { Bool* D = static_cast<Bool*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } else if(b == INT) { Int* D = static_cast<Int*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } else { Float* D = static_cast<Float*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case AND: return new Bool(C->getValue() && D->getValue()); case OR: return new Bool(C->getValue() || D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } } else if(a == MACRO) { if(b != MACRO) mismatch = true; else { Macro* C = static_cast<Macro*>(A); Macro* D = static_cast<Macro*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } else if(a == ARRAY) { if(b != ARRAY) mismatch = true; else { Array* C = static_cast<Array*>(A); Array* D = static_cast<Array*>(B); a = C->getValueType(); b = C->getValueType(); if(a != b) { interpreter.error("Error: Types do not match in assignment: Array<%s> vs Array<%s>\n", C->getValueTypeString().c_str(), D->getValueTypeString().c_str()); return NULL; } switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } else if(a == LIST) { if(b != LIST) mismatch = true; else { List* C = static_cast<List*>(A); List* D = static_cast<List*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } else if(a == FUNCTION) { if(b != FUNCTION) mismatch = true; else { Function* C = static_cast<Function*>(A); Function* D = static_cast<Function*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } else if(a == PROCEDURE) { if(b != PROCEDURE) mismatch = true; else { Procedure* C = static_cast<Procedure*>(A); Procedure* D = static_cast<Procedure*>(B); switch(oper) { case EQUALS: return new Bool(C->getValue() == D->getValue()); case NOT_GREATER: case LESS_EQUAL: return new Bool(C->getValue() <= D->getValue()); case NOT_LESS: case GREATER_EQUAL: return new Bool(C->getValue() >= D->getValue()); case LESS: return new Bool(C->getValue() < D->getValue()); case GREATER: return new Bool(C->getValue() > D->getValue()); case NOT_EQUALS: return new Bool(C->getValue() != D->getValue()); default: UI_debug_pile("Pile Error: Bad operator passed to comparison().\n"); return NULL; } } } //if(mismatch) { interpreter.error("Error: Types do not match in assignment: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str()); return NULL; } return NULL; }
Variable* subtract(Variable* A, Variable* B) { if(A == NULL || B == NULL) { interpreter.error("Error: Void variable in subtraction.\n"); return NULL; } TypeEnum a = A->getType(); TypeEnum b = B->getType(); if(a != b && !(a == FLOAT && b == INT) && !(b == FLOAT && a == INT)) { interpreter.error("Error: Types do not match in subtraction: %s vs %s\n", A->getTypeString().c_str(), B->getTypeString().c_str()); return NULL; } if(a == STRING) { interpreter.error("Error: Subtraction operation not defined for type 'string'.\n"); return NULL; } else if(a == INT) { Int* C = static_cast<Int*>(A); if(b == INT) { Int* D = static_cast<Int*>(B); Int* R = new Int; R->setValue(C->getValue() - D->getValue()); return R; } else { Float* D = static_cast<Float*>(B); Float* R = new Float; R->setValue(C->getValue() - D->getValue()); return R; } } else if(a == FLOAT) { Float* C = static_cast<Float*>(A); Float* R = new Float; if(b == INT) { Int* D = static_cast<Int*>(B); R->setValue(C->getValue() - D->getValue()); } else { Float* D = static_cast<Float*>(B); R->setValue(C->getValue() - D->getValue()); } return R; } else if(a == BOOL) { interpreter.error("Error: Subtraction operation not defined for type 'bool'.\n"); return NULL; } else if(a == MACRO) { interpreter.error("Error: Subtraction operation not defined for type 'macro'.\n"); return NULL; } else if(a == ARRAY) { interpreter.error("Error: Subtraction operation not defined for type 'array'.\n"); return NULL; } else if(a == LIST) { interpreter.error("Error: Subtraction operation not defined for type 'list'.\n"); return NULL; } else if(a == FUNCTION) { interpreter.error("Error: Subtraction operation not defined for type 'function'.\n"); return NULL; } else if(a == PROCEDURE) { interpreter.error("Error: Subtraction operation not defined for type 'procedure'.\n"); return NULL; } return A; }
int ConsoleInterpreter::termOut (lua_State *L) { Interpreter *interp = GetInterpreter (L); interp->term_out (L); return 0; }
void Link::execute(Interpreter& interpreter) { interpreter.pushPolizElement(*this); }
PointerCheckInjector(Interpreter& I) : m_Interp(I), m_Sema(I.getCI()->getSema()), m_Context(I.getCI()->getASTContext()), m_clingthrowIfInvalidPointerCache(0) {}
int main() { TEST_START(65); Interpreter universe; is_convertible<Scalar, int>("is_convertible<Scalar, int>()"); is_convertible<Scalar, unsigned>("is_convertible<Scalar, unsigned>()"); is_convertible<Scalar, long>("is_convertible<Scalar, long>()"); is_convertible<Scalar, unsigned long>("is_convertible<Scalar, unsigned long>()"); is_convertible<Scalar, double>("is_convertible<Scalar, double>()"); is_convertible<Scalar, float>("is_convertible<Scalar, float>()"); is_convertible<Scalar, long double>("is_convertible<Scalar, long float>()"); TRY_DECL(Scalar value = universe.value_of(1), "Definition of value"); note("value = universe.value_of(1)"); is(value, 1, "value == 1"); is(value, 1u, "value == 1u"); is(value, 1l, "value == 1l"); is(value, "1", "value == \"1\""); is(value, about(1.0), "value == 1.0"); isnt(value, about(2.0), "value != 2.0"); is(value, about(1.0f), "value == 1.0f"); isnt(value, about(2.0f), "value != 2.0f"); is(static_cast<int>(value), 1, "(int)value == 1"); ok(value > 0, "value > 0"); ok(value < 2, "value < 2"); not_ok(value != 1, "not: value != 1"); not_ok(value != "1", "not: value != \"1\""); ok(value + 1, "value + 1"); not_ok(value - 1 != 0, "not: value - 1"); ok(value * 1, "value * 1"); ok(value / 1, "value / 1"); value += 2; note("value += 2"); is(value, 3, "value == 3"); isnt(value, 4, "value != 4"); value *= 3; note("value *= 2"); is(value, 9, "value == 9"); value -= 1; note("value -= 1"); is(value, 8, "value == 8"); value %= 5; note("value %= 5"); is(value, 3, "value == 3"); value /= 3; note("value /= 3"); is(value, 1, "value == 1"); TRY_DECL(int foo = value, "int foo = value"); ok(foo == 1, "foo == 1"); value = 1; note("value = 1"); is(value, 1, "value == 1"); is(value, 1u, "value == 1u"); is(value, 1l, "value == 1l"); is(value, "1", "value == \"1\""); ok(value + 1, "value + 1"); not_ok(value - 1, "not: value - 1"); ok(value * 1, "value * 1"); ok(value / 1, "value / 1"); value = 1u; note("value = 1u"); is(value, 1, "value == 1"); is(value, 1u, "value == 1u"); is(value, 1l, "value == 1l"); is(value, "1", "value == \"1\""); ok(value + 1, "value + 1"); not_ok(value - 1, "not: value - 1"); ok(value * 1, "value * 1"); ok(value / 1, "value / 1"); ok(value > 0, "value > 0"); ok(value < 2, "value < 2"); not_ok(value != 1, "not: value != 1"); value = "1"; note("value = \"1\""); is(value, 1, "value == 1"); is(value, 1u, "value == 1u"); is(value, 1l, "value == 1l"); is(value, "1", "value == \"1\""); ok(value > 0, "value > 0"); ok(value < 2, "value < 2"); not_ok(value != 1, "not: value != 1"); ok(value + 1, "value + 1"); not_ok(value - 1, "not: value - 1"); ok(value * 1, "value * 1"); ok(value / 1, "value / 1"); is(++value, 2, "++value == 2"); is(--value, 1, "--value == 1"); TEST_END; }
MMISessionManager::MMISessionManager(Interpreter interpreter) : _protoInterpreter(interpreter) { bool success = HTTPServer::registerServlet(interpreter.getName(), this); assert(success); _factory = new Factory(Factory::getInstance()); _factory->registerIOProcessor(new MMIIOProcessor(this)); }