Пример #1
0
Ink_Object *InkNative_Actor_Send(Ink_InterpreteEngine *engine, Ink_ContextChain *context, Ink_ArgcType argc, Ink_Object **argv, Ink_Object *this_p)
{
    if (!checkArgument(engine, argc, argv, 1, INK_STRING)) {
        return NULL_OBJ;
    }

    Ink_Object *sender = new Ink_Object(engine);
    sender->setSlot("->", new Ink_FunctionObject(engine, InkNative_Actor_Send_Sub));
    sender->setSlot("msg", argv[0]);

    return sender;
}
Пример #2
0
Ink_Object *InkNative_Array_Index(Ink_InterpreteEngine *engine, Ink_ContextChain *context, Ink_ArgcType argc, Ink_Object **argv, Ink_Object *this_p)
{
	Ink_Object *base = context->searchSlot(engine, "base");
	Ink_Array *obj = as<Ink_Array>(base);
	Ink_Object *ret;
	Ink_HashTable *hash;
	Ink_ArrayValue::size_type index;

	ASSUME_BASE_TYPE(engine, INK_ARRAY);

	if (!checkArgument(false, argc, argv, 1, INK_NUMERIC)) {
		InkNote_Method_Fallthrough(engine, "[]", INK_ARRAY, INK_OBJECT);
		return InkNative_Object_Index(engine, context, argc, argv, this_p);
	}

	index = getRealIndex(as<Ink_Numeric>(argv[0])->value, obj->value.size());
	if (index < obj->value.size()) {
		if (!obj->value[index]) obj->value[index] = new Ink_HashTable(UNDEFINED);
		for (hash = obj->value[index]; hash->bonding; hash = hash->bonding) ;
		hash->bondee = obj->value[index];
		ret = hash->getValue();
		ret->address = hash;
		ret->setSlot("base", base);
	} else {
		InkWarn_Index_Exceed(engine);
		return UNDEFINED;
	}

	return ret;
}
Пример #3
0
Ink_Object *Ink_HashTableExpression::eval(Ink_InterpreteEngine *engine, Ink_ContextChain *context_chain, Ink_EvalFlag flags)
{
    const char *file_name_back;
    Ink_LineNoType line_num_back;
    SET_LINE_NUM;

    Ink_Object *ret = new Ink_Object(engine), *key;
    Ink_HashTableMapping::size_type i;

    for (i = 0; i < mapping.size(); i++) {
        /* two possibility: 1. identifier key; 2. expression key with brackets */
        if (mapping[i]->name) {
            ret->setSlot(mapping[i]->name->c_str(), mapping[i]->value->eval(engine, context_chain));
            if (INTER_SIGNAL_RECEIVED) {
                RESTORE_LINE_NUM;
                return engine->getInterruptValue();
            }
        } else {
            key = mapping[i]->key->eval(engine, context_chain);
            if (INTER_SIGNAL_RECEIVED) {
                RESTORE_LINE_NUM;
                return engine->getInterruptValue();
            }
            if (key->type != INK_STRING) {
                InkWarn_Hash_Table_Mapping_Expect_String(engine);
                return NULL_OBJ;
            }
            string *tmp = new string(as<Ink_String>(key)->getValue().c_str());
            ret->setSlot(tmp->c_str(),
                         mapping[i]->value->eval(engine, context_chain), true, tmp);
            if (INTER_SIGNAL_RECEIVED) {
                RESTORE_LINE_NUM;
                return engine->getInterruptValue();
            }
        }
    }

    RESTORE_LINE_NUM;
    return ret;
}
Пример #4
0
Ink_Object *InkNative_Object_SetSetter(Ink_InterpreteEngine *engine, Ink_ContextChain *context, Ink_ArgcType argc, Ink_Object **argv, Ink_Object *this_p)
{
	Ink_Object *base = context->searchSlot(engine, "base");
	Ink_HashTable *hash;
	const char *tmp;

	if (!checkArgument(engine, argc, argv, 1, INK_STRING)) {
		return NULL_OBJ;
	}

	tmp = as<Ink_String>(argv[0])->getValue().c_str();
	if (!(hash = base->getSlotMapping(engine, tmp))) {
		string *tmp_p = new string(tmp);
		hash = base->setSlot(tmp_p->c_str(), NULL, tmp_p);
	}

	hash->setter = argc > 1 ? argv[1] : NULL;

	return NULL_OBJ;
}