int MpAmipInterface::channels() { int ret = -1; if(eval_str("var_typ").startsWith("Stereo")) ret = 2; else if(eval_str("var_typ").startsWith("Mono")) ret = 1; return ret; }
void run_repl() { printf("Zeta Read-Eval-Print Loop (REPL). Press Ctrl+C to exit.\n"); printf("\n"); printf("Please note that the Zeta VM is at the early prototype "); printf("stage, language semantics and implementation details will "); printf("change often.\n"); printf("\n"); printf("NOTE: the interpreter is currently *very much incomplete*. It will "); printf("likely crash on you or give cryptic error messages.\n"); printf("\n"); for (;;) { printf("z> "); char* cstr = read_line(); // Evaluate the code string value_t value = eval_str(cstr); free(cstr); // Print the value value_print(value); putchar('\n'); } }
int main(int argc, char** argv) { vm_init(); // Test mode if (argc == 2 && strcmp(argv[1], "--test") == 0) { test_vm(); test_parser(); test_interp(); return 0; } // File name passed if (argc == 2) { char* cstr = read_file(argv[1]); if (cstr == NULL) return -1; // Evaluate the code string eval_str(cstr); free(cstr); } // No file names passed. Read-eval-print loop. if (argc == 1) { run_repl(); } return 0; }
void init_global_environment(env_hashtable *env) { init_primitive_procedures(env); define_pair_procedures(env); /* Parser determines empty brackets as null_object */ eval_str("(define null '())", env); }
QString getAmipString(const char * var) { QString ret; QString s = eval_str(var); QTextCodec *c=mediaplayer_get_codec(); if (c) ret = c->toUnicode(s.toAscii()); else ret=s; return ret; }
QString MpAmipInterface::mrl() { QString ret; QString fn = eval_str("var_fn"); QTextCodec *c=mediaplayer_get_codec(); if (c) ret = c->toUnicode(fn.toAscii()); else ret=fn; if(!ret.startsWith("http://",Qt::CaseInsensitive)) ret.prepend("file://"); return ret; }
/** * @name run_file * @brief reads and runs javascript found in the given file * @param filename - (const char*) filename of the file to run * @retval bool - (true | false) depending on whether running the file was successful */ static inline bool run_file(const char *filename) { char *contents = core_load_url(filename); if (contents) { eval_str(contents); LOG("{core} Evaluated JavaScript from %s", filename); free(contents); return true; } else { LOG("{core} WARNING: Error reading JavaScript from %s", filename); return false; } }
QString getAmipString(const char * var) { QString szRet; QString szString = eval_str(var); QTextCodec * pCodec = mediaplayer_get_codec(); if(pCodec) { #if (QT_VERSION < 0x050000) szRet = pCodec->toUnicode(szString.toLatin1()); #else szRet = pCodec->toUnicode(szString.toUtf8()); #endif } else { szRet = szString; } return szRet; }
std::string cDrawScenarioPoliEval::BuildTextInfoStr() const { const auto& character = mScene->GetCharacter(); tVector com = character->CalcCOM(); tVector com_vel = character->CalcCOMVel(); char buffer[128]; auto poli_eval = std::static_pointer_cast<cScenarioPoliEval>(mScene); double avg_dist = poli_eval->GetAvgDist(); int num_samples = poli_eval->GetNumEpisodes(); sprintf(buffer, "Avg Dist: %.3f (%i)\n", avg_dist, num_samples); std::string eval_str(buffer); std::string info_str = cDrawScenarioSimChar::BuildTextInfoStr(); info_str += eval_str; return info_str; }
QString MpAmipInterface::mrl() { QString szRet; QString szFn = eval_str("var_fn"); QTextCodec * pCodec = mediaplayer_get_codec(); if(pCodec) { #if (QT_VERSION < 0x050000) szRet = pCodec->toUnicode(szFn.toLatin1()); #else szRet = pCodec->toUnicode(szFn.toUtf8()); #endif } else { szRet = szFn; } if(!szRet.startsWith("http://", Qt::CaseInsensitive)) szRet.prepend("file://"); return szRet; }
/* Define procedures cadr, caddr, etc. */ static void define_pair_procedures(env_hashtable *env) { void define_recursive(char *ad_name, char *body, int depth) { char bufa[1000], bufb[1000]; if (depth > 4) return; if (depth > 1) { sprintf(bufa, "(define c%sr (lambda (x) %s))", ad_name, body); eval_str(bufa, env); } sprintf(bufa, "a%s", ad_name); sprintf(bufb, "(car %s)", body); define_recursive(bufa, bufb, depth + 1); sprintf(bufa, "d%s", ad_name); sprintf(bufb, "(cdr %s)", body); define_recursive(bufa, bufb, depth + 1); }
static void define_recursive(buffer *ad_name, buffer *body, int depth, env_hashtable *env) { buffer *expr_buffer, *new_ad_name, *new_body; char *expr_str; if (depth > 4) return; if (depth > 1) { expr_buffer = buffer_nprintf("(define c%br" " (lambda (x) %b))", ad_name, body); expr_str = buffer_to_str(expr_buffer); eval_str(expr_str, env); free(expr_str); free(expr_buffer); } new_ad_name = buffer_nprintf("a%b", ad_name); new_body = buffer_nprintf("(car %b)", body); define_recursive(new_ad_name, new_body, depth + 1, env); buffer_free(new_ad_name); buffer_free(new_body); new_ad_name = buffer_nprintf("d%b", ad_name); new_body = buffer_nprintf("(cdr %b)", body); define_recursive(new_ad_name, new_body, depth + 1, env); buffer_free(new_ad_name); buffer_free(new_body); }
/** * @name core_run * @brief _____ * @retval NONE */ void core_run() { char buf[64]; snprintf(buf, sizeof(buf), "jsio('import %s;')", config_get_entry_point()); eval_str(buf); }
bool MpAmipInterface::getShuffle() { return eval_str("var_shuffle").startsWith("on"); }
bool MpAmipInterface::getRepeat() { return eval_str("var_repeat").startsWith("on"); }