O_TYPE O_blkframe(O_ARGS) /* runs an instruction under a block frame */ { mpdm_t ret; /* no context? create one */ if (l == NULL) l = MPDM_A(0); RF(l); /* create a new local symbol table */ mpdm_push(l, MPDM_H(0)); /* creates the arguments (if any) as local variables */ set_local_symbols(M2, a, l); /* execute instruction */ ret = RF(M1); /* destroy the local symbol table */ mpdm_adel(l, -1); UF(l); return UFND(ret); }
O_TYPE O_list(O_ARGS) /* build list from instructions */ { mpdm_t ret = RF(mpdm_size(c) == 2 ? MPDM_A(0) : M(2)); mpdm_push(ret, M(1)); return UFND(ret); }
/** * mpsl_argv - Fills the ARGV global array. * @argc: number of arguments * @argv: array of string values * * Fills the ARGV global MPSL array with an array of arguments. These * are usually the ones sent to main(). */ void mpsl_argv(int argc, char *argv[]) { int n; mpdm_t ARGV; /* create the ARGV array */ ARGV = mpdm_hset_s(mpdm_root(), L"ARGV", MPDM_A(0)); for (n = 0; n < argc; n++) mpdm_push(ARGV, MPDM_MBS(argv[n])); }
O_TYPE execsym(O_ARGS, int th, int m) { mpdm_t s, v, p, o = NULL, r = NULL; /* gets the symbol name */ s = RF(M1); /* gets the arguments */ p = RF(M2); /* if it's to be called as a method, the object should be inserted into the local symtable before searching the symbol */ if (m && (o = mpdm_aget(p, 0)) && MPDM_IS_HASH(o)) { mpdm_push(l, o); } else m = 0; /* gets the symbol value */ v = GET(s); if (!MPDM_IS_EXEC(v)) { /* not found or NULL value? error */ mpdm_t t, w; char tmp[128]; w = RF(mpdm_join_s(s, L".")); t = RF(MPDM_2MBS((wchar_t *) w->data)); snprintf(tmp, sizeof(tmp), "Undefined function %s()", (char *) t->data); mpsl_error(MPDM_MBS(tmp)); UF(w); UF(t); } else { /* execute */ r = RF(th ? mpdm_exec_thread(v, p, l) : mpdm_exec(v, p, l)); } UF(s); UF(p); /* drop the object from the local symtable */ if (m) mpdm_adel(l, -1); return UFND(r); }
O_TYPE O_range(O_ARGS) /* build list from range of two numeric values */ { double v1 = RM1; double v2 = RM2; mpdm_t r = RF(MPDM_A(0)); if (v1 < v2) while (v1 <= v2) { mpdm_push(r, MPDM_R(v1)); v1 += 1.0; } else while (v1 >= v2) { mpdm_push(r, MPDM_R(v1)); v1 -= 1.0; } UFND(r); return r; }
/** argn = push(a, arg1 [, arg2, ... argn]); */ static mpdm_t F_push(F_ARGS) { int n; mpdm_t r = NULL; for (n = 1; n < mpdm_size(a); n++) { mpdm_unref(r); r = mpdm_push(A0, A(n)); mpdm_ref(r); } return mpdm_unrefnd(r); }
void test_mpsl_file(void) { mpdm_t v; mpdm_t inc; mpsl_trap(NULL); inc = mpdm_ref(MPDM_A(0)); mpdm_push(inc, MPDM_S(L".")); printf("Compiling from file:\n"); v = do_test_mpsl_file("test.mpsl", inc); v = do_test_exec(v, NULL); mpdm_unref(inc); }
/** * mpdm_keys - Returns the keys of a hash. * @h: the hash * * Returns an array containing all the keys of the @h hash. * [Hashes] * [Arrays] */ mpdm_t mpdm_keys(const mpdm_t h) { int c; mpdm_t a, i; printf("Warning: deprecated function mpdm_keys()\n"); mpdm_ref(h); /* create an array with the same number of elements */ a = MPDM_A(0); c = 0; while (mpdm_iterator(h, &c, NULL, &i)) mpdm_push(a, i); mpdm_unref(h); return a; }
static void set_local_symbols(mpdm_t s, mpdm_t v, mpdm_t l) /* sets (or creates) a list of local symbols with a list of values */ { if (l != NULL) { mpdm_t h; mpdm_ref(s); mpdm_ref(v); mpdm_ref(l); /* gets the top local variable frame */ h = mpdm_aget(l, -1); if (MPDM_IS_ARRAY(s) || MPDM_IS_ARRAY(v)) { int n; mpdm_t a; for (n = 0; n < mpdm_size(s); n++) mpdm_hset(h, mpdm_aget(s, n), mpdm_aget(v, n)); if (n < mpdm_size(v)) { /* store the rest of arguments into _ */ a = mpdm_hset_s(h, L"_", MPDM_A(0)); for (; n < mpdm_size(v); n++) mpdm_push(a, mpdm_aget(v, n)); } } else mpdm_hset(h, s, v); mpdm_unref(l); mpdm_unref(v); mpdm_unref(s); } }
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; }