static mpdm_t constant_fold(mpdm_t i) /* tries to fold complex but constant expressions into a literal */ { int n; mpdm_t v; /* get the number opcode */ n = mpdm_ival(mpdm_aget(i, 0)); if (op_table[n].foldable) { /* test if all arguments are literal (opcode 0) */ for (n = 1; n < mpdm_size(i); n++) { mpdm_t t = mpdm_aget(i, n); /* if it's not LITERAL, abort immediately */ if (mpdm_ival(mpdm_aget(t, 0)) != 0) return i; } /* execute the instruction and convert to LITERAL */ v = mpsl_exec_p(i, NULL, NULL); i = mpsl_mkins(L"LITERAL", 1, v, NULL, NULL, NULL); } return i; }
/** * mpsl_set_symbol - Sets value to a symbol. * @s: symbol name * @v: value * @l: local symbol table * * Assigns the value @v to the @s symbol. If the value exists as * a local symbol, it's assigned to it; otherwise, it's set as a global * symbol (and created if it does not exist). */ mpdm_t mpsl_set_symbol(mpdm_t s, mpdm_t v, mpdm_t l) { int n; mpdm_t r, p, w; mpdm_ref(l); mpdm_ref(s); mpdm_ref(v); /* get the local or global symbol table */ if ((r = find_local_symtbl(s, l)) == NULL) r = mpdm_root(); /* splits the path, if needed */ if (MPDM_IS_ARRAY(s)) p = mpdm_ref(s); else p = mpdm_ref(mpdm_split_s(s, L".")); w = r; for (n = 0; w != NULL && n < mpdm_size(p); n++) { /* is executable? run it and take its output */ while (MPDM_IS_EXEC(w)) w = mpdm_exec(w, NULL, NULL); /* last component? */ if (n == mpdm_size(p) - 1) { /* yes; do the setting */ if (MPDM_IS_HASH(w)) w = mpdm_hset(w, mpdm_aget(p, n), v); else if (MPDM_IS_ARRAY(w)) w = mpdm_aset(w, v, mpdm_ival(mpdm_aget(p, n))); } else { if (MPDM_IS_HASH(w)) w = mpdm_hget(w, mpdm_aget(p, n)); else if (MPDM_IS_ARRAY(w)) w = mpdm_aget(w, mpdm_ival(mpdm_aget(p, n))); else { mpdm_void(w); w = NULL; } } } mpdm_unref(p); mpdm_unref(v); mpdm_unref(s); mpdm_unref(l); return w; }
O_TYPE mpsl_exec_i(O_ARGS) /* Executes one MPSL instruction in the MPSL virtual machine. Called from mpsl_exec_p() (which holds the flow control status variable) */ { mpdm_t ret = NULL; mpdm_ref(c); mpdm_ref(a); mpdm_ref(l); /* if aborted or NULL, do nothing */ if (!mpsl_abort && c != NULL) { /* gets the opcode and calls it */ ret = op_table[mpdm_ival(C0)].func(c, a, l, f); if (mpsl_trap_func != NULL) { mpdm_t f = mpsl_trap_func; mpdm_ref(ret); mpsl_trap_func = NULL; mpdm_exec_3(f, c, a, ret, l); mpsl_trap_func = f; mpdm_unrefnd(ret); } } mpdm_unref(l); mpdm_unref(a); mpdm_unref(c); return ret; }
/** string = chr(c); */ static mpdm_t F_chr(F_ARGS) { wchar_t tmp[2]; tmp[0] = (wchar_t) mpdm_ival(mpdm_get_i(a, 0)); tmp[1] = L'\0'; return MPDM_S(tmp); }
void test_abort_and_eval(void) { mpdm_t v; mpdm_t e; mpsl_abort = 0; v = mpdm_ref(mpsl_compile(MPDM_S(L"1000;"), NULL)); do_test("Abort 1", mpdm_ival(mpdm_exec(v, NULL, NULL)) == 1000); /* set global abort function */ mpsl_abort = 1; do_test("Abort 2", mpdm_exec(v, NULL, NULL) == NULL); mpsl_abort = 0; do_test("Abort 3", mpdm_ival(mpdm_exec(v, NULL, NULL)) == 1000); mpdm_unref(v); mpsl_error(NULL); v = mpsl_eval(MPDM_S(L"invalid_code()"), NULL, NULL); e = mpdm_get_wcs(mpdm_root(), L"ERROR"); printf("The following error is OK:\n"); mpdm_dump(e); do_test("eval 1", v == NULL && e != NULL); v = mpsl_eval(MPDM_S(L"undef_func();"), NULL, NULL); e = mpdm_get_wcs(mpdm_root(), L"ERROR"); printf("The following error is also OK:\n"); mpdm_dump(e); do_test("eval 2", v == NULL && e != NULL); v = mpsl_eval(MPDM_S(L"load('unexistent_file.mpsl');"), NULL, NULL); e = mpdm_get_wcs(mpdm_root(), L"ERROR"); printf("The following error is also OK:\n"); mpdm_dump(e); do_test("eval 3", v == NULL && e != NULL); v = mpsl_eval(MPDM_S(L"2000;"), NULL, NULL); e = mpdm_get_wcs(mpdm_root(), L"ERROR"); do_test("eval 4", mpdm_ival(v) == 2000 && e == NULL); }
void test_mpsl3(void) { mpdm_t v; v = do_test_mpsl("v=[10,20]; w=v[0]; w;"); mpdm_dump(v); v = do_test_exec(v, NULL); mpdm_dump(v); /* library functions tests */ v = do_test_mpsl("dump( [1, 2, 3, 4, 5] );"); do_test_exec(v, NULL); v = do_test_mpsl("if(size([2, 3, 4]) == 3) { dump(\"YES\"); } else { dump(\"NO\"); }"); do_test_exec(v, NULL); // v = do_test_mpsl("is_array(1);"); // do_test("is_array 1", !mpdm_is_true(do_test_exec(v, NULL))); // v = do_test_mpsl("is_array([]);"); // do_test("is_array 2", do_test_exec(v, NULL) != NULL); // v = do_test_mpsl("is_array({});"); // do_test("is_array 3", do_test_exec(v, NULL) != NULL); // v = do_test_mpsl("is_hash(1);"); // do_test("is_hash 1", !mpdm_is_true(do_test_exec(v, NULL))); // v = do_test_mpsl("is_hash([]);"); // do_test("is_hash 2", !mpdm_is_true(do_test_exec(v, NULL))); // v = do_test_mpsl("is_hash({});"); // do_test("is_hash 3", do_test_exec(v, NULL) != NULL); /* v = do_test_mpsl("v=splice(\"inventions of life\", NULL, 0, 10); v[1];"); v = do_test_exec(v, NULL); do_test("splice 1", mpdm_cmp(v, MPDM_S(L"inventions")) == 0); v = do_test_mpsl("v[0];"); v = do_test_exec(v, NULL); do_test("splice 2", mpdm_cmp(v, MPDM_S(L" of life")) == 0); */ v = do_test_mpsl("sub func() { if(1 == 1) { return(6); 24; } 12; }"); v = do_test_exec(v, NULL); v = do_test_mpsl("a=func();"); v = do_test_exec(v, NULL); do_test("return 1", mpdm_ival(v) == 6); v = do_test_mpsl("a=func(); 500;"); v = do_test_exec(v, NULL); do_test("return 2", mpdm_ival(v) == 500); v = do_test_mpsl("sub func() { while(1 == 1) { return(6); 24; } 12; }"); v = do_test_exec(v, NULL); v = do_test_mpsl("a=func();"); v = do_test_exec(v, NULL); do_test("return 3", mpdm_ival(v) == 6); v = do_test_mpsl("sub func() { foreach(a, [1 .. 10]) { return(6); 24; } 12; }"); v = do_test_exec(v, NULL); v = do_test_mpsl("a=func();"); v = do_test_exec(v, NULL); do_test("return 4", mpdm_ival(v) == 6); v = do_test_mpsl("a=1; while(a < 10) { a++; } a;"); v = do_test_exec(v, NULL); do_test("while", mpdm_ival(v) == 10); v = do_test_mpsl("a=1; while(a < 10) { if(a == 5) break; a++; } a;"); v = do_test_exec(v, NULL); do_test("break", mpdm_ival(v) == 5); v = do_test_mpsl("b=0; foreach(a, [1, 2, 3, 4]) { dump(a); b += a; } return(b);"); v = do_test_exec(v, NULL); do_test("foreach", mpdm_ival(v) == 10); v = do_test_mpsl("b=0; foreach(a, [1 .. 20]) { dump(a); b += a; } return(b);"); v = do_test_exec(v, NULL); do_test("foreach+range 1", mpdm_ival(v) == 210); v = do_test_mpsl("b=0; foreach(a, [20 .. 1]) { dump(a); b += a; } return(b);"); v = do_test_exec(v, NULL); do_test("foreach+range 2", mpdm_ival(v) == 210); v = do_test_mpsl("print(\"print: \", 1, 2, [1, 2, 3], func(), 4);"); v = do_test_exec(v, NULL); v = do_test_mpsl("'This is\\na string.';"); v = do_test_exec(v, NULL); mpdm_dump(v); v = do_test_mpsl("\"This is\\na string.\";"); v = do_test_exec(v, NULL); mpdm_dump(v); v = do_test_mpsl("sub t(h) { dump(h); dump(h.x); h.x; } H={}; H.x=5; t(H);"); v = do_test_exec(v, NULL); do_test("Accesing a hash's component passed as argument", mpdm_ival(v) == 5); /* mpdm_dump(mpdm_root());*/ }
void test_mpsl2(void) { mpdm_t v; mpdm_t w; /* execution tests */ v = do_test_mpsl("666;"); mpdm_dump(v); v = do_test_exec(v, NULL); do_test("literal number", mpdm_ival(v) == 666); v = do_test_mpsl("\"goodbye\";"); v = do_test_exec(v, NULL); do_test("literal string", mpdm_cmp(v, MPDM_S(L"goodbye")) == 0); v = do_test_mpsl("1 + 3 + 5;"); v = do_test_exec(v, NULL); do_test("mpsl calculator 1", mpdm_rval(v) == 9.0); v = do_test_mpsl("1 + ((3 - 5) * 8);"); v = do_test_exec(v, NULL); do_test("mpsl calculator 2", mpdm_rval(v) == -15.0); /* next value cannot be tested as an exact equality, as rounding errors will manifest */ v = do_test_mpsl("1.5 + ((3.1 - 5.8) * 8.0);"); v = do_test_exec(v, NULL); do_test("mpsl calculator 3", mpdm_rval(v) < -20.0 && mpdm_rval(v) > -21.0); v = do_test_mpsl("2 + 3 * 4;"); v = do_test_exec(v, NULL); do_test("mpsl calculator 4", mpdm_rval(v) == 14.0); v = do_test_mpsl("2 * 3 + 4;"); v = do_test_exec(v, NULL); do_test("mpsl calculator 5", mpdm_rval(v) == 10.0); v = do_test_exec(do_test_mpsl("2 + 3 * 4;"), NULL); mpdm_ref(v); w = do_test_exec(do_test_mpsl("2 + (3 * 4);"), NULL); do_test("mpsl calculator 6 (operator precedence)", mpdm_rval(v) == mpdm_rval(w)); mpdm_unref(v); v = do_test_exec(do_test_mpsl("2 + 3 * 4;"), NULL); mpdm_ref(v); w = do_test_exec(do_test_mpsl("(2 + 3) * 4;"), NULL); do_test("mpsl calculator 7 (operator precedence)", mpdm_rval(v) != mpdm_rval(w)); mpdm_unref(v); v = do_test_mpsl("/* array */ [\"this\", \"one\", \"is\", 666, \"cool\"];"); v = do_test_exec(v, NULL); mpdm_dump(v); do_test("mpsl array", mpdm_ival(mpdm_get_i(v, 3)) == 666); v = do_test_mpsl ("/* hash */ { \"enero\" => \"january\", \"febrero\" => \"february\" };"); v = do_test_exec(v, NULL); mpdm_dump(v); do_test("mpsl hash", mpdm_cmp(mpdm_get(v, MPDM_S(L"febrero")), MPDM_S(L"february")) == 0); v = do_test_mpsl("! 1;"); v = do_test_exec(v, NULL); do_test("boolean not 1", !mpdm_is_true(v)); v = do_test_mpsl("! 0;"); v = do_test_exec(v, NULL); do_test("boolean not 2", v != NULL); v = do_test_mpsl("1 && 3;"); v = do_test_exec(v, NULL); do_test("boolean and 1", mpdm_ival(v) == 3); v = do_test_mpsl("1 && 0;"); v = do_test_exec(v, NULL); do_test("boolean and 2", !mpdm_is_true(v)); v = do_test_mpsl("0 && 1;"); v = do_test_exec(v, NULL); do_test("boolean and 3", !mpdm_is_true(v)); v = do_test_mpsl("1 || 3;"); v = do_test_exec(v, NULL); do_test("boolean or 1", mpdm_ival(v) == 1); v = do_test_mpsl("2 || 0;"); v = do_test_exec(v, NULL); do_test("boolean or 2", mpdm_ival(v) == 2); v = do_test_mpsl("0 || 3;"); v = do_test_exec(v, NULL); do_test("boolean or 3", mpdm_ival(v) == 3); v = do_test_mpsl("6 == 6;"); v = do_test_exec(v, NULL); do_test("numeric == 1", v != NULL); v = do_test_mpsl("8.0 == 8.0;"); v = do_test_exec(v, NULL); do_test("numeric == 2", v != NULL); v = do_test_mpsl("6 == 8;"); v = do_test_exec(v, NULL); do_test("numeric == 3", !mpdm_is_true(v)); v = do_test_mpsl("6 != 6;"); v = do_test_exec(v, NULL); do_test("numeric != 1", !mpdm_is_true(v)); v = do_test_mpsl("8.0 != 8.0;"); v = do_test_exec(v, NULL); do_test("numeric != 2", !mpdm_is_true(v)); v = do_test_mpsl("6 != 8;"); v = do_test_exec(v, NULL); do_test("numeric != 3", v != NULL); v = do_test_mpsl("6 < 6;"); v = do_test_exec(v, NULL); do_test("numeric < 1", !mpdm_is_true(v)); v = do_test_mpsl("8 < 6;"); v = do_test_exec(v, NULL); do_test("numeric < 2", !mpdm_is_true(v)); v = do_test_mpsl("5 < 6;"); v = do_test_exec(v, NULL); do_test("numeric < 3", v != NULL); v = do_test_mpsl("6 > 6;"); v = do_test_exec(v, NULL); do_test("numeric > 1", !mpdm_is_true(v)); v = do_test_mpsl("8 > 6;"); v = do_test_exec(v, NULL); do_test("numeric > 2", v != NULL); v = do_test_mpsl("5 > 6;"); v = do_test_exec(v, NULL); do_test("numeric > 3", !mpdm_is_true(v)); v = do_test_mpsl("6 <= 6;"); v = do_test_exec(v, NULL); do_test("numeric <= 1", v != NULL); v = do_test_mpsl("8 <= 6;"); v = do_test_exec(v, NULL); do_test("numeric <= 2", !mpdm_is_true(v)); v = do_test_mpsl("5 <= 6;"); v = do_test_exec(v, NULL); do_test("numeric <= 3", v != NULL); v = do_test_mpsl("6 >= 6;"); v = do_test_exec(v, NULL); do_test("numeric >= 1", v != NULL); v = do_test_mpsl("8 >= 6;"); v = do_test_exec(v, NULL); do_test("numeric >= 2", v != NULL); v = do_test_mpsl("5 >= 6;"); v = do_test_exec(v, NULL); do_test("numeric >= 3", !mpdm_is_true(v)); v = do_test_mpsl("11 % 6;"); v = do_test_exec(v, NULL); do_test("modulo", mpdm_ival(v) == 5); v = do_test_mpsl("variable=16384;"); mpdm_dump(v); v = do_test_exec(v, NULL); do_test("assign 1", mpdm_ival(v) == 16384); v = do_test_mpsl("array=[10, 20, 30, 40];"); v = do_test_exec(v, NULL); do_test("assign 2", mpdm_ival(mpdm_get_i(v, 2)) == 30); v = do_test_mpsl("a=1; b=2; c=3;"); mpdm_dump(v); v = do_test_exec(v, NULL); v = do_test_mpsl("CACHE={}; CACHE.regex=[]; CACHE.regex[0]=12345;"); v = do_test_exec(v, NULL); v = do_test_mpsl("variable;"); v = do_test_exec(v, NULL); do_test("symval 1", mpdm_ival(v) == 16384); v = do_test_mpsl("variable2=1 + ((3 - 5) * 8); variable2;"); mpdm_dump(v); v = do_test_exec(v, NULL); do_test("symval 2", mpdm_rval(v) == -15); v = do_test_mpsl("variable3=variable2 * 2;"); v = do_test_exec(v, NULL); do_test("symval 3", mpdm_ival(v) == -30); v = do_test_mpsl("sub mysum(a, b) { a + b; }"); mpdm_dump(v); v = do_test_exec(v, NULL); do_test("sub 1", v != NULL); v = do_test_mpsl("sub pi() { 3.1416; }"); mpdm_dump(v); v = do_test_exec(v, NULL); do_test("sub 2", v != NULL); v = do_test_mpsl("var10=pi();"); v = do_test_exec(v, NULL); do_test("exec 1", mpdm_rval(v) == 3.1416); v = do_test_mpsl("var11=pi() * 10000; var11;"); v = do_test_exec(v, NULL); do_test("exec 2", mpdm_rval(v) == 31416); v = do_test_mpsl("mysum(100, 20);"); v = do_test_exec(v, NULL); do_test("exec 3", mpdm_rval(v) == 120.0); v = do_test_mpsl("a = NULL;"); v = do_test_exec(v, NULL); do_test("NULL 1", v == NULL); v = do_test_mpsl("a == NULL;"); v = do_test_exec(v, NULL); do_test("NULL 2", mpdm_ival(v) == 1); v = do_test_mpsl("local a, b; a = 1; b = 2;"); v = do_test_exec(v, NULL); v = do_test_mpsl("a == NULL;"); v = do_test_exec(v, NULL); do_test("local 1", mpdm_ival(v) == 1); v = do_test_mpsl("66 * -1;"); v = do_test_exec(v, NULL); do_test("uminus", mpdm_ival(v) == -66); v = do_test_mpsl("\"test\" eq \"test\";"); v = do_test_exec(v, NULL); do_test("streq 1", mpdm_is_true(v)); v = do_test_mpsl("\"test\" eq \"prueba\";"); v = do_test_exec(v, NULL); do_test("streq 1", !mpdm_is_true(v)); v = do_test_mpsl("a = 6; ++ a;"); v = do_test_exec(v, NULL); do_test("pinc", mpdm_ival(v) == 7); v = do_test_mpsl("a++;"); v = do_test_exec(v, NULL); do_test("sinc", mpdm_ival(v) == 7); v = do_test_mpsl("a += 10;"); v = do_test_exec(v, NULL); do_test("iadd", mpdm_ival(v) == 18); v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a == b) c=1000; c;"); v = do_test_exec(v, NULL); do_test("if 1", mpdm_ival(v) == 3); v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a <= b) c=1000; c;"); v = do_test_exec(v, NULL); do_test("if 2", mpdm_ival(v) == 1000); v = do_test_mpsl("local a, b, c; a=1; b=2; if(a == b) c=1000; else c=2000; c;"); v = do_test_exec(v, NULL); do_test("ifelse", mpdm_ival(v) == 2000); v = do_test_mpsl("local a; a = 0; while(a < 100) { a++; } a;"); v = do_test_exec(v, NULL); do_test("ifelse", mpdm_ival(v) == 100); v = do_test_mpsl("a=mysum(100, 50); a;"); v = do_test_exec(v, NULL); do_test("mysum 1", mpdm_ival(v) == 150); v = do_test_mpsl("a=mysum(2000, 500); a;"); v = do_test_exec(v, NULL); do_test("mysum 2", mpdm_ival(v) == 2500); w = mpdm_ref(MPDM_A(2)); mpdm_set_i(w, MPDM_I(100), 0); mpdm_set_i(w, MPDM_I(50), 1); /* asks for the value of the mysum symbol (the code) */ v = do_test_mpsl("mysum;"); /* executes, so mysum() itself is being returned */ v = do_test_exec(v, NULL); mpdm_dump(v); do_test("mysum 3", mpdm_ival(do_test_exec(v, w)) == 150); mpdm_set_i(w, MPDM_I(75), 1); do_test("mysum 4", mpdm_ival(do_test_exec(v, w)) == 175); /* compiles (and executes) the definition of gcd() */ v = do_test_mpsl ("/* greatest common divisor (Euclid's algorithm) */ sub gcd(m, n) { while (m > 0) { if(n > m) { local t = m; m = n; n = t; } m -= n; } n; }"); do_test_exec(v, NULL); /* gets a pointer to gcd() */ v = do_test_exec(do_test_mpsl("gcd;"), NULL); mpdm_dump(v); /* executes gcd(100, 50); */ mpdm_set_i(w, MPDM_I(50), 1); do_test("gcd() 1", mpdm_ival(do_test_exec(v, w)) == 50); /* executes gcd(100, 75); */ mpdm_set_i(w, MPDM_I(75), 1); do_test("gcd() 2", mpdm_ival(do_test_exec(v, w)) == 25); mpdm_unref(w); /* string concatenation */ w = mpdm_ref(MPDM_S(L"big lebowski")); v = do_test_mpsl("\"big\" ~ \" lebowski\";"); do_test("~ (strcat 1)", mpdm_cmp(do_test_exec(v, NULL), w) == 0); v = do_test_mpsl("\"big\" ~ \" \" ~ \"lebowski\";"); do_test("~ (strcat 2)", mpdm_cmp(do_test_exec(v, NULL), w) == 0); mpdm_unref(w); }
static mpdm_t kde4_drv_form(mpdm_t a, mpdm_t ctxt) { int n; mpdm_t widget_list; QWidget *qlist[100]; mpdm_t r; KDialog *dialog = new KDialog(window); dialog->setModal(true); dialog->setButtons(KDialog::Ok | KDialog::Cancel); widget_list = mpdm_aget(a, 0); KVBox *vb = new KVBox(dialog); dialog->setMainWidget(vb); for (n = 0; n < mpdm_size(widget_list); n++) { mpdm_t w = mpdm_aget(widget_list, n); wchar_t *type; mpdm_t t; KHBox *hb = new KHBox(vb); type = mpdm_string(mpdm_hget_s(w, L"type")); if ((t = mpdm_hget_s(w, L"label")) != NULL) { QLabel *ql = new QLabel(hb); ql->setText(str_to_qstring(mpdm_gettext(t))); } t = mpdm_hget_s(w, L"value"); if (wcscmp(type, L"text") == 0) { mpdm_t h; QComboBox *ql = new QComboBox(hb); ql->setEditable(true); ql->setMinimumContentsLength(30); ql->setMaxVisibleItems(8); if (t != NULL) ql->setEditText(str_to_qstring(t)); qlist[n] = ql; if ((h = mpdm_hget_s(w, L"history")) != NULL) { int i; /* has history; fill it */ h = mp_get_history(h); for (i = mpdm_size(h) - 1; i >= 0; i--) ql->addItem(str_to_qstring(mpdm_aget(h, i))); } } else if (wcscmp(type, L"password") == 0) { QLineEdit *ql = new QLineEdit(hb); ql->setEchoMode(QLineEdit::Password); qlist[n] = ql; } else if (wcscmp(type, L"checkbox") == 0) { QCheckBox *qc = new QCheckBox(hb); if (mpdm_ival(t)) qc->setCheckState(Qt::Checked); qlist[n] = qc; } else if (wcscmp(type, L"list") == 0) { int i; QListWidget *ql = new QListWidget(hb); ql->setMinimumWidth(480); /* use a monospaced font */ ql->setFont(QFont(QString("Mono"))); mpdm_t l = mpdm_hget_s(w, L"list"); for (i = 0; i < mpdm_size(l); i++) ql->addItem(str_to_qstring(mpdm_aget(l, i))); ql->setCurrentRow(mpdm_ival(t)); qlist[n] = ql; } if (n == 0) qlist[n]->setFocus(Qt::OtherFocusReason); } n = dialog->exec(); if (!n) return NULL; r = MPDM_A(mpdm_size(widget_list)); /* fill the return values */ for (n = 0; n < mpdm_size(widget_list); n++) { mpdm_t w = mpdm_aget(widget_list, n); mpdm_t v = NULL; wchar_t *type; type = mpdm_string(mpdm_hget_s(w, L"type")); if (wcscmp(type, L"text") == 0) { mpdm_t h; QComboBox *ql = (QComboBox *) qlist[n]; v = qstring_to_str(ql->currentText()); /* if it has history, add to it */ if ((h = mpdm_hget_s(w, L"history")) != NULL && v != NULL && mpdm_cmp_s(v, L"") != 0) { h = mp_get_history(h); if (mpdm_cmp(v, mpdm_aget(h, -1)) != 0) mpdm_push(h, v); } } else if (wcscmp(type, L"password") == 0) { QLineEdit *ql = (QLineEdit *) qlist[n]; v = qstring_to_str(ql->text()); } else if (wcscmp(type, L"checkbox") == 0) { QCheckBox *qb = (QCheckBox *) qlist[n]; v = MPDM_I(qb->checkState() == Qt::Checked); } else if (wcscmp(type, L"list") == 0) { QListWidget *ql = (QListWidget *) qlist[n]; v = MPDM_I(ql->currentRow()); } mpdm_aset(r, v, n); } return r; }
static mpdm_t F_integer(F_ARGS) { return MPDM_I(mpdm_ival(A0)); }
/** sleep(msecs); */ static mpdm_t F_sleep(F_ARGS) { mpdm_sleep(mpdm_ival(mpdm_get_i(a, 0))); return NULL; }