Beispiel #1
0
NODE(sl_node_var_t, var)
{
    size_t frame;
    sl_compile_state_t* xcs = cs;
    size_t index = 0xCAFE;
    SLVAL err;
    frame = 0;
    while(xcs) {
        if(sl_st_lookup(xcs->vars, (sl_st_data_t)node->name, (sl_st_data_t*)&index)) {
            if(frame == 0) {
                op_mov(cs, index, dest);
            } else {
                op_get_outer(cs, frame, index, dest);
                mark_upper_scopes_as_closure_unsafe(cs, frame);
            }
            return;
        }
        xcs = xcs->parent;
        frame++;
    }
    err = sl_make_formatted_string(cs->vm, "Undefined variable %QV", node->name);
    err = sl_make_error2(cs->vm, cs->vm->lib.NameError, err);
    sl_error_add_frame(cs->vm, err, sl_make_cstring(cs->vm, "<compiler>"), sl_make_cstring(cs->vm, (char*)cs->section->filename), sl_make_int(cs->vm, node->base.line));
    sl_throw(cs->vm, err);
}
Beispiel #2
0
void
sl_lex_error(sl_lex_state_t* st, char* text, int lineno)
{
    SLVAL msg = sl_make_formatted_string(st->vm, "Unexpected character '%s'", text);
    SLVAL err = sl_make_error2(st->vm, st->vm->lib.SyntaxError, msg);
    sl_error_add_frame(st->vm, err, sl_make_cstring(st->vm, "<lexer>"), sl_make_cstring(st->vm, (char*)st->filename), sl_make_int(st->vm, lineno));
    sl_throw(st->vm, err);
}
Beispiel #3
0
static SLVAL
sl_class_to_s(sl_vm_t* vm, SLVAL self)
{
    sl_class_t* klass = get_class(vm, self);
    sl_class_t* object = (sl_class_t*)sl_get_ptr(vm->lib.Object);
    if(klass == object || sl_get_ptr(klass->extra->in) == (sl_object_t*)object) {
        return sl_id_to_string(vm, klass->extra->name);
    } else {
        return sl_make_formatted_string(vm, "%V::%I", sl_class_to_s(vm, klass->extra->in), klass->extra->name);
    }
}
Beispiel #4
0
static SLVAL
method_inspect(sl_vm_t* vm, SLVAL method)
{
    sl_method_t* methp = (sl_method_t*)sl_get_ptr(method);
    if(!(methp->base.user_flags & SL_FLAG_METHOD_INITIALIZED)) {
        return sl_object_inspect(vm, method);
    }

    return sl_make_formatted_string(vm, "#<Method: %V#%I(%d)>",
        methp->extra->klass, methp->extra->name, methp->arity);
}
Beispiel #5
0
static void
unexpected(sl_parse_state_t* ps, sl_token_t* tok)
{
    SLVAL err;
    if(tok->type != SL_TOK_END) {
        err = sl_make_formatted_string(ps->vm, "Unexpected %QV", tok->str);
    } else {
        err = sl_make_cstring(ps->vm, "Unexpected end of file");
    }
    error(ps, err, tok);
}
Beispiel #6
0
SLID
sl_id_make_setter(sl_vm_t* vm, SLID id)
{
    SLVAL str = sl_make_formatted_string(vm, "%I=", id);
    return sl_intern2(vm, str);
}