Exemplo n.º 1
0
static CRB_Value
eval_identifier_expression(CRB_Interpreter *inter,
        LocalEnvironment *env, Expression *expr)
{
    CRB_Value v;
    Variable *vp;

    vp = crb_search_local_variable(env, expr->u.identifier);
    if(vp != NULL){
        v = vp->value;
    } else {
        vp = search_global_variable_from_env(inter, env, expr->u.identifier);
        if(vp != NULL){
            v = vp->value;
        } else {
            crb_runtime_error(expr->line_number, VARIABLE_NOT_FOUND_ERR,
                    STRING_MESSAGE_ARGUMENT,
                    "name", expr->u.identifier,
                    MESSAGE_ARGUMENT_END);
        }
    }
    refer_if_string(&v);

    return v;
}
Exemplo n.º 2
0
static CRB_Value
eval_assign_expression(CRB_Interpreter *inter, LocalEnvironment *env,
                        char *identifier, Expression *expression)
{
    CRB_Value   v;
    Variable    *left;

    v = eval_expression(inter, env, expression);

    left = crb_search_local_variable(env, identifier);
    if(left == NULL){
        left = search_global_variable_from_env(inter, env, identifier);
    }
    if(left != NULL){
        release_if_string(&left->vaule);
        left->value = v;
        release_if_string(&v);
    } else {
        if(env != NULL){
            crb_add_local_variable(env, identifier, &v);
        } else {
            CRB_add_global_variable(inter, identifier, &v);
        } 
        refer_if_string(&v);
    }

    return v;
}
Exemplo n.º 3
0
static void
eval_identifier_expression(SIMCAR_Interpreter *inter,
                           SIMCAR_LocalEnvironment *env, Expression *expr)
{
    SIMCAR_Value   v;
    Variable    *vp;

    vp = crb_search_local_variable(env, expr->u.identifier);
    if (vp != NULL) {
        v = vp->value;
    } else {
        vp = search_global_variable_from_env(inter, env, expr->u.identifier);
        if (vp != NULL) {
            v = vp->value;
        } else {
            crb_runtime_error(expr->line_number, VARIABLE_NOT_FOUND_ERR,
                              STRING_MESSAGE_ARGUMENT,
                              "name", expr->u.identifier,
                              MESSAGE_ARGUMENT_END);
        }
    }
    push_value(inter, &v);
}
Exemplo n.º 4
0
static SIMCAR_Value *
get_identifier_lvalue(SIMCAR_Interpreter *inter, SIMCAR_LocalEnvironment *env,
                      char *identifier)
{
    Variable *new_var;
    Variable *left;

    left = crb_search_local_variable(env, identifier);
    if (left == NULL) {
        left = search_global_variable_from_env(inter, env, identifier);
    }
    if (left != NULL)
        return &left->value;

    if (env != NULL) {
        new_var = crb_add_local_variable(env, identifier);
        left = new_var;
    } else {
        new_var = crb_add_global_variable(inter, identifier);
        left = new_var;
    }

    return &left->value;
}