bool XEvalNode::applyNode(SchemeThread* schemethread, double curtime) { Console* console=Console::getInstance(); s7_scheme* sc=schemethread->scheme; // console->setEvaling(true); //// console->postAsyncMessage(CommandIDs::ConsoleIsEvaling, 1, true); // install the begin_hook that allows s7 to quit current eval schemethread->setSchemeInterrupt(false); s7_set_begin_hook(sc, cm_begin_hook); s7_pointer val=s7_eval_c_string(sc, (char *)expr.toUTF8()); s7_set_begin_hook(sc,NULL); if (schemethread->isSchemeInterrupt()) { console->printWarning(T("Scheme interrupted!\n")); } else if (val != schemethread->schemeError) { String str=String(s7_object_to_c_string(sc, val)); #ifdef GRACE str << T("\n"); #endif console->printValues(str); } // console->setEvaling(false); //// console->postAsyncMessage(CommandIDs::ConsoleIsEvaling, 0, true); return false; }
bool XSalNode::applyNode(SchemeThread* st, double curtime) { s7_scheme* sc=st->scheme; s7_pointer data=st->schemeNil; Console* console=Console::getInstance(); // cons up token list using reverse order of array for (int i=toks.size()-1; i>=0; i--) { data=s7_cons(sc, s7_make_c_pointer(sc, toks.getUnchecked(i)), data); } // turn data into arglist ("input" ({tok}*) [#t|#f]*) data=s7_cons(sc, s7_make_string(sc, expr.toUTF8()), s7_cons(sc, data, s7_cons(sc, s7_make_boolean(sc, expand), s7_cons(sc, s7_make_boolean(sc, multi), st->schemeNil))) ); // gc protect data cobbled up on the C side int prot = s7_gc_protect(sc, data); s7_pointer retn; st->isSalEval(true); //// console->postAsyncMessage(CommandIDs::ConsoleIsEvaling, 1, true); st->setSchemeInterrupt(false); s7_set_begin_hook(sc, cm_begin_hook); if (vers==TextIDs::Sal1) { // sal only side effects so we never process return values retn=s7_call(sc, s7_name_to_value(sc, "sal"), data); } else { retn=s7_call(sc, s7_name_to_value(sc, "sal2"), data); if (retn != st->schemeError) { //cm_print(retn); String str=String(s7_object_to_c_string(sc, retn)); str << T("\n"); for (int i=0; i<str.length(); i++) if (str[i]==T('(')) str[i]=T('{'); else if (str[i]==T(')')) str[i]=T('}'); console->printValues(str); } } s7_gc_unprotect_at(sc, prot); s7_set_begin_hook(sc, NULL); if (st->isSchemeInterrupt()) { console->printWarning(T("Scheme interrupted!\n")); } st->isSalEval(false); /// console->postAsyncMessage(CommandIDs::ConsoleIsEvaling, 0, true); return false; }
void ReplWindow::evaluate(Glib::ustring &expression) { Scheme *scm = Application::get()->get_scheme(); if (!expression.empty()) { const char *errmsg; s7_pointer old_port, result; int gc_loc = -1; // // Open a port to catch error info // old_port = s7_set_current_error_port(scm, s7_open_output_string(scm)); if (old_port != s7_nil(scm)) { gc_loc = s7_gc_protect(scm, old_port); } result = s7_eval_c_string(scm, expression.data()); errmsg = s7_get_output_string(scm, s7_current_error_port(scm)); append_text( "\n" ); if ((errmsg) && (*errmsg)) { append_text(errmsg); } else { char *result_as_string; result_as_string = s7_object_to_c_string(scm, result); if (result_as_string) { append_text(result_as_string); free(result_as_string); } } s7_close_output_port(scm, s7_current_error_port(scm)); s7_set_current_error_port(scm, old_port); if (gc_loc != -1) s7_gc_unprotect_at(scm, gc_loc); } }