示例#1
0
文件: network.c 项目: whilke/ColdC
void func_reassign_connection(void) {
    cData       * args;
    Conn * c;
    Obj     * obj;

    /* Accept a objnum. */
    if (!func_init_1(&args, OBJNUM))
        return;

    c = find_connection(cur_frame->object);
    if (c) {
        obj = cache_retrieve(args[0].u.objnum);
        if (!obj)
            THROW((objnf_id, "Object #%l does not exist.", args[0].u.objnum))
        else if (find_connection(obj)) {
            cthrow(perm_id, "Object %O already has a connection.", obj->objnum);
            cache_discard(obj);
            return;
        }
        c->objnum = obj->objnum;
        cache_discard(obj);
        cur_frame->object->conn = NULL;
        pop(1);
        push_int(1);
    } else {
示例#2
0
文件: dict.c 项目: whilke/ColdC
void func_dict_values(void) {
    cData * args;
    cList * values;

    if (!func_init_1(&args, DICT))
	return;

    values = dict_values(DICT1);
    pop(1);
    push_list(values);
    list_discard(values);
}
示例#3
0
文件: dict.c 项目: whilke/ColdC
void func_dict_keys(void) {
    cData * args;
    cList * keys;

    if (!func_init_1(&args, DICT))
	return;

    keys = dict_keys(DICT1);
    pop(1);
    push_list(keys);
    list_discard(keys);
}
示例#4
0
文件: object.c 项目: nrhtr/genesis
INTERNAL cList *add_op_arg(cList * out, Int type, Long op, Method * method)
{
    Obj *obj = method->object;
    cData d;

    switch (type) {
    case INTEGER:
        d.type = INTEGER;
        d.u.val = op;
        break;
    case FLOAT:
        d.type = FLOAT;
        d.u.fval = *((Float *) (&op));
        break;
    case T_ERROR:
        if (op == -1) {
            d.type = INTEGER;
            d.u.val = -1;
        } else {
            d.type = T_ERROR;
            d.u.error = object_get_ident(obj, op);
        }
        break;
    case IDENT:
        d.type = SYMBOL;
        d.u.symbol = object_get_ident(obj, op);
        break;
    case VAR:
        {
            Long id;

            d.type = SYMBOL;

            if (op < method->num_args) {
                op = method->num_args - op - 1;
                id = object_get_ident(obj, method->argnames[op]);
                d.u.symbol = id;
                break;
            }
            op -= method->num_args;

            if (method->rest != -1) {
                if (op == 0) {
                    id = object_get_ident(obj, method->rest);
                    d.u.symbol = id;
                    break;
                }
                op--;
            }

            id = object_get_ident(obj, method->varnames[op]);
            d.u.symbol = id;
            break;
        }
    case STRING:
        d.type = STRING;
        d.u.str = object_get_string(obj, op);
        break;
        /* case JUMP: *//* ignore JUMP */
    default:
        return out;
#if DISABLED                    /* none of these are used as args in op_table */
    case LIST:
    case FROB:
    case DICT:
    case BUFFER:
#endif
    }

    out = list_add(out, &d);
    /* do not discard, we were not using duped data */

    return out;
}

COLDC_FUNC(method_bytecode)
{
    cData *args, d;
    Method *method;
    cList *list;
    register Int x;
    Long *ops;
    Op_info *info;
    Long opcode;

    /* Accept a list of lines of code and a symbol for the name. */
    if (!func_init_1(&args, SYMBOL))
        return;

    method = object_find_method(cur_frame->object->objnum, args[0].u.symbol, FROB_ANY);

    /* keep these for later reference, if its already around */
    if (!method)
        THROW((methodnf_id, "Method %D not found.", &args[0]))

    list = list_new(method->num_opcodes);
    d.type = SYMBOL;
    ops = method->opcodes;
    x = 0;
    while (x < method->num_opcodes) {
        opcode = ops[x];
        info = &op_table[opcode];
        d.type = SYMBOL;
        d.u.symbol = info->symbol;
        list = list_add(list, &d);
        /* dont bother discarding, we didnt dup twice */
        x++;

        if (info->arg1) {
            list = add_op_arg(list, info->arg1, ops[x], method);
            x++;
        }

        if (info->arg2) {
            list = add_op_arg(list, info->arg1, ops[x], method);
            x++;
        }
    }

    pop(1);
    push_list(list);
    list_discard(list);
}