コード例 #1
0
ファイル: arrays.c プロジェクト: Vuzi/vuziks
return_code arrays_array_pop(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    (void)args;

    if(!o) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.pop) out of its object");
        return RC_ERROR;
    }

    Array* a = (Array*) o->data;

    if(as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.pop) as a constructor");
        return RC_ERROR;
    }

    // Pop avec arguments
    if(args) {
        Variable *key = (Variable*)args->value;

        if(key->type == T_NUM) {
            int val = (int)key->value.v_num;
            int i = array_search(a, val);

            if( i >= 0) {
                // On récupère
                eval_value->type = a->tab_value[i].type;
                eval_value->value = a->tab_value[i].value;

                // On recopie
                for(; i < (int)a->nb_cases + 1; i++) {
                    KEY(a, i) = KEY(a, i+1);
                    VAL(a, i) = VAL(a, i+1);
                }

                a->nb_cases--;
            } else {
                eval_value->type = T_NONEXISTENT;
            }

        } else {
            err_add(E_WARNING, OP_IMPOSSIBLE, "arrays' key can only be numbers");
            return RC_WARNING;
        }
    }
    // Sans argument
    else {
        if(a->nb_cases > 0) {
            eval_value->type = a->tab_value[a->nb_cases - 1].type;
            eval_value->value = a->tab_value[a->nb_cases - 1].value;
            a->nb_cases--;
        } else {
            eval_value->type = T_NONEXISTENT;
        }
    }

    return RC_OK;
}
コード例 #2
0
ファイル: arrays.c プロジェクト: Vuzi/vuziks
return_code arrays_array(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    (void)o;
    (void)args;

    if(!as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (arrays.array) as a function");
        return RC_ERROR;
    }

    // Nouvel objet array
    eval_value->type = T_OBJECT;
    eval_value->value.v_obj = var_new_object(NULL);

    // Nom d'objet : array
    eval_value->value.v_obj->name = "array";
    eval_value->value.v_obj->name_h = ARRAY_HASH;

    // Array en lui même
    Array* ar = xcalloc(1, sizeof(Array));

    eval_value->value.v_obj->data = (void*)ar;

    // Initialisation de l'array
    array_init(ar);

    // Fonction des strings

    Variable *v = var_new("add", str_hash("add"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_add;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    v = var_new("get", str_hash("get"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_get;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    v = var_new("pop", str_hash("pop"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_pop;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    v = var_new("length", str_hash("length"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = arrays_array_length;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    return RC_OK;
}
コード例 #3
0
ファイル: arrays.c プロジェクト: Vuzi/vuziks
return_code arrays_array_get(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    if(!o) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.get) out of its object");
        return RC_ERROR;
    }

    Array* a = (Array*) o->data;

    if(as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.get) as a constructor");
        return RC_ERROR;
    }

    if(args) {
        Variable *v = (Variable*)args->value;

        if(v->type == T_NUM) {
            Variable *ret = array_get(a, (int)v->value.v_num);

            if(ret) {
                // On copie dans le buffer
                eval_value->type = ret->type;
                eval_value->value = ret->value;

                if(eval_value->type == T_OBJECT)
                    eval_value->value.v_obj->n_links++;

            } else {
                // No value
                eval_value->type = T_NONEXISTENT;
            }

            return RC_OK;

        } else {
            err_add(E_WARNING, OP_IMPOSSIBLE, "arrays' key can only be numbers");
            return RC_WARNING;
        }

    } else {
        err_add(E_WARNING, OP_IMPOSSIBLE, "array.get use with no argument");
        return RC_WARNING;
    }
}
コード例 #4
0
ファイル: arrays.c プロジェクト: Vuzi/vuziks
return_code arrays_array_add(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    if(!o) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.add) out of its object");
        return RC_ERROR;
    }

    Array* a = (Array*) o->data;

    if(as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.add) as a constructor");
        return RC_ERROR;
    }

    eval_value->type = T_OBJECT;
    eval_value->value.v_obj = o;
    eval_value->value.v_obj->n_links++;

    if(args) {
        Variable *key = (Variable*)args->value;
        NEXT(args);

        if(args) {
            Variable *val = (Variable*)args->value;

            if(key->type == T_NUM) {
                array_add(a, (int)key->value.v_num, val);
                return RC_OK;
            } else {
                err_add(E_WARNING, OP_IMPOSSIBLE, "arrays' key can only be numbers");
                return RC_WARNING;
            }

        } else {
            err_add(E_WARNING, OP_IMPOSSIBLE, "array.add use with no value to insert");
            return RC_WARNING;
        }
    } else {
        err_add(E_WARNING, OP_IMPOSSIBLE, "array.add use with no argument");
        return RC_WARNING;
    }

}
コード例 #5
0
ファイル: arrays.c プロジェクト: Vuzi/vuziks
return_code arrays_array_length(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    (void)args;

    if(!o) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.length) out of its object");
        return RC_ERROR;
    }

    Array* a = (Array*) o->data;

    if(as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (array.length) as a constructor");
        return RC_ERROR;
    }

    eval_value->type = T_NUM;
    eval_value->value.v_num = (double)a->nb_cases;

    return RC_OK;
}
コード例 #6
0
ファイル: strings.c プロジェクト: Vuzi/vuziks
return_code strings_string_length(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    (void)args;

    if(!o) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (string.length) out of its object");
        return RC_ERROR;
    }

    VK_String* vks = (VK_String*) o->data;

    if(as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (string.length) as a constructor");
        return RC_ERROR;
    }

    eval_value->type = T_NUM;
    eval_value->value.v_num = (double)vks->n;

    return RC_OK;
}
コード例 #7
0
ファイル: strings.c プロジェクト: Vuzi/vuziks
return_code strings_string(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    (void)o;
    (void)args;

    if(!as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (strings.string) as a function");
        return RC_ERROR;
    }

    // Nouvel objet string
    eval_value->type = T_OBJECT;
    eval_value->value.v_obj = var_new_object(NULL);

    // Nom d'objet : string
    eval_value->value.v_obj->name = "string";
    eval_value->value.v_obj->name_h = STRING_HASH;

    // String en lui même
    VK_String* vks = xcalloc(1, sizeof(VK_String));

    eval_value->value.v_obj->data = (void*)vks;

    // Fonction des strings
    Variable *v = var_new("append", str_hash("append"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = strings_string_append;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    v = var_new("length", str_hash("length"), T_FUNCTION_BUILTIN);
    v->value.v_func_builtin = strings_string_length;
    v->container = &eval_value->value.v_obj->ec;
    v->container->object = eval_value->value.v_obj;

    linked_list_push(&(eval_value->value.v_obj->ec.variables), LLT_VARIABLE, (void*)v);

    return RC_OK;
}
コード例 #8
0
ファイル: timing.c プロジェクト: ipeet/ubw32
//! Add a function to be polled
void add_poll( void (*pump)(void* data), void* data ) {
    /* Allocate a node for the poll function */
    struct _poll_n * n = malloc(sizeof(struct _poll_n));
    if( !n ) {
        // Fail to allocate node 
        err_add(ERROR,UWRT_NOMEM,"Add polling event");
        return;
    }

    /* Fill node */
    n->pump = pump;
    n->data = data;

    /* Add to circular poll list */
    if( !_poll_list ) {
        // Special case: empty list
        n->next = n;
        _poll_list = n;
    } else {
        n->next = _poll_list->next;
        _poll_list->next = n;
    }
}
コード例 #9
0
ファイル: strings.c プロジェクト: Vuzi/vuziks
return_code strings_string_append(Object* o, Linked_list *args, Variable* eval_value, int as_constructor) {

    if(!o) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (string.append) out of its object");
        return RC_ERROR;
    }

    VK_String* vks = (VK_String*) o->data;

    if(as_constructor) {
        err_add(E_ERROR, OP_IMPOSSIBLE, "Can't use this built-in function (string.append) as a constructor");
        return RC_ERROR;
    }

    while(args) {
        Variable *v = (Variable*)args->value;

        switch(v->type) {
            // Type autorisées : bool, num, string
            case T_BOOL :
                if(v->value.v_bool) {
                    // Nouvelle alloc et recopie
                    char* tmp = xmalloc((vks->n + 4 + 1)*sizeof(char));
                    strcpy(tmp, vks->s); strcat(tmp, "true");

                    if(vks->s) xfree(vks->s);

                    vks->s = tmp;
                    vks->n = vks->n + 4;
                } else {
                    // Nouvelle alloc et recopie
                    char* tmp = xmalloc((vks->n + 5 + 1)*sizeof(char));
                    strcpy(tmp, vks->s); strcat(tmp, "false");

                    if(vks->s) xfree(vks->s);

                    vks->s = tmp;
                    vks->n = vks->n + 5;
                }
                break;
            case T_NUM : {
                    char buffer[256], *tmp;

                    if(v->value.v_num == (int)v->value.v_num)
                        sprintf(buffer, "%ld", (long int)v->value.v_num);
                    else
                        sprintf(buffer, "%lf", v->value.v_num);

                    // Nouvelle alloc et recopie
                    tmp = xmalloc((vks->n + strlen(buffer) + 1)*sizeof(char));
                    strcpy(tmp, vks->s); strcat(tmp, buffer);

                    if(vks->s) xfree(vks->s);
                    vks->s = tmp;
                    vks->n = vks->n + strlen(buffer);
                    break;
                }
            case T_OBJECT  :
                // Si c'est un string aussi
                if(v->value.v_obj->name_h == o->name_h && !strcmp(v->value.v_obj->name, o->name)) {

                    VK_String* app = (VK_String*)v->value.v_obj->data;

                    // Nouvelle alloc et recopie
                    char* tmp = xmalloc((vks->n + app->n + 1)*sizeof(char));
                    strcpy(tmp, vks->s); strcat(tmp, app->s);

                    if(vks->s) xfree(vks->s);

                    vks->s = tmp;
                    vks->n = vks->n + app->n;

                    break;
                }
            default :
                err_add(E_ERROR, OP_IMPOSSIBLE, "Can't append a %s to a string", language_type_debug(v->type));
                return RC_ERROR;
        }

        NEXT(args);
    }

    // Pour des raisons de chainage on fait faire retourner l'objet à la méthode
    eval_value->type = T_OBJECT;
    eval_value->value.v_obj = o;
    o->n_links++;

    return RC_OK;
}
コード例 #10
0
ファイル: fe_main.c プロジェクト: jesserayadkins/Gyroe
int _18main()
{
    int argc, argv;
    int _4586;
    int _1, _2;

    argv = Command_Line();
    argc = SEQ_PTR(argv)->length;

    RefDS(argv);
    DeRef(_4Argv);
    _4Argv = argv;

    _4Argc = argc;

    DeRefi(_4eudir);

    _4eudir = EGetEnv(NewString("EUDIR"));

    if (IS_ATOM(_4eudir)) {
        if (_4ELINUX) {
            /* eudir = getenv("HOME") */
            DeRefi(_4eudir);
            _4eudir = EGetEnv(_4592);

            if (IS_ATOM(_4eudir)) {
                /* eudir = "euphoria" */
                RefDS(_4595);
                DeRefi(_4eudir);
                _4eudir = _4595;
            }
            else {
                /* eudir = eudir & "/euphoria" */
                Concat((object_ptr)&_4eudir, _4eudir, (s1_ptr)_4596);
            }
        }
        else {
            /* eudir = "\\EUPHORIA" */
            RefDS(_4598);
            DeRefi(_4eudir);
            _4eudir = _4598;
        }
    }

    /* TempErrName = "ex.err" */
    RefDS(_4602);
    DeRefi(_6TempErrName);
    _6TempErrName = _4602;

    _11src_file = _18ProcessOptions();

    if (_11src_file == -1) {
        /* Can't open %s\n */
        err_add(NewString("Can't open "));
        err_add(SEQ_PTR(_4file_name)->base[1]);
        err_add(NewString("\n"));

        /* Output to screen and cleanup. Too early for set_err_stack. */
        _6screen_output(2, error_stack);
        _6Cleanup(1);
    }

    /* main_path = full_path(file_name[1]) */
    DeRef(_4586);
    _2 = (int)SEQ_PTR(_4file_name);
    _4586 = (int)*(((s1_ptr)_2)->base + 1);
    RefDS(_4586);
    RefDS(_4586);
    DeRef(_11main_path);
    _11main_path = _11get_file_path(_4586);

    _15InitGlobals();
    _10InitSymTab();
    _14InitEmit();
    _15InitParser();
    _11InitLex();
    _11read_line();
    _15parser();

    _17BackEnd(); /* Call the backend (be_*.c files) */

    _6Cleanup(0);

    DeRef(argv);
    DeRef(_4586);
    return 0;
}