Beispiel #1
0
mpdm_t do_test_mpsl_file(char *file, mpdm_t inc)
{
    static mpdm_t v = NULL;

    do_set(&v, mpsl_compile_file(MPDM_MBS(file), inc));

    printf("Compile file: ");
    do_test(file, v != NULL);
    return (v);
}
Beispiel #2
0
mpdm_t _do_test_mpsl(char *code, int line)
{
    static mpdm_t v = NULL;

    do_set(&v, mpsl_compile(MPDM_MBS(code), NULL));

    printf("Compile: ");
    _do_test(code, v != NULL, line);
    return (v);
}
Beispiel #3
0
/**
 * 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]));
}
Beispiel #4
0
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);
}
Beispiel #5
0
/**
 * mpsl_startup - Initializes MPSL.
 *
 * Initializes the Minimum Profit Scripting Language. Returns 0 if
 * everything went OK.
 */
int mpsl_startup(void)
{
    mpdm_t r;
    mpdm_t m;

    /* startup MPDM */
    mpdm_startup();

    r = mpdm_root();

    /* creates INC, unless already defined */
    if (mpdm_hget_s(r, L"INC") == NULL)
        mpdm_hset_s(r, L"INC", MPDM_A(0));

    /* the TRUE value */
    mpdm_hset_s(r, L"TRUE", MPDM_I(1));

    /* standard file descriptors */
    mpdm_hset_s(r, L"STDIN",    MPDM_F(stdin));
    mpdm_hset_s(r, L"STDOUT",   MPDM_F(stdout));
    mpdm_hset_s(r, L"STDERR",   MPDM_F(stderr));

    /* home and application directories */
    mpdm_hset_s(r, L"HOMEDIR",  mpdm_home_dir());
    mpdm_hset_s(r, L"APPDIR",   mpdm_app_dir());

    /* fill now the MPSL hash */
    m = MPDM_H(0);
    mpdm_hset_s(r, L"MPSL", m);

    /* store things there */
    mpdm_hset_s(m, L"VERSION",  MPDM_MBS(VERSION));
    mpdm_hset_s(m, L"OPCODE",   mpsl_build_opcodes());
    mpdm_hset_s(m, L"LC",       MPDM_H(0));
    mpdm_hset_s(m, L"CORE",     mpsl_build_funcs());

    mpdm_dump_1 = mpsl_dump_1;

    return 0;
}