Esempio n. 1
0
LIU_DEFINE_NATIVE_METHOD(OldDictionary, make) {
    LIU_FIND_LAST_MESSAGE;
    OldDictionary *dict = fork();
    for(int i = 0; i < message->numInputs(); ++i) {
        Node *key = NULL;
        Primitive *primitive = message->input(i)->hasLabel();
        if(!primitive) LIU_THROW(ArgumentException, "missing key in Dictionary initialization");
        if(primitive->hasNext()) LIU_THROW(ArgumentException, "invalid key in Dictionary initialization");
        Message *msg = Message::dynamicCast(primitive->value());
        if(msg) {
            if(msg->inputs(false) || msg->outputs(false) || msg->isEscaped() || msg->isParented()
                    || msg->isEllipsed() || msg->hasCodeInput())
                LIU_THROW(ArgumentException, "invalid key in Dictionary initialization");
            key = Text::make(msg->name());
        } else
            key = primitive->run();
        dict->set(key, message->runInput(i));
    }
    return dict;
}
Esempio n. 2
0
LIU_DEFINE_NATIVE_METHOD(OldDictionary, each) {
    LIU_FIND_LAST_PRIMITIVE;
    Primitive *nextPrimitive = primitive->hasNext();
    if(!nextPrimitive) LIU_THROW(InterpreterException, QString("missing code after an each statement"));
    LIU_FIND_LAST_MESSAGE;
    LIU_CHECK_INPUT_SIZE(2);
    Message *msg = Message::dynamicCast(message->firstInput()->value()->value());
    if(!msg) LIU_THROW(ArgumentException, "first argument should be a message");
    QString valueName = msg->name();
    msg = Message::dynamicCast(message->secondInput()->value()->value());
    if(!msg) LIU_THROW(ArgumentException, "second argument should be a message");
    QString keyName = msg->name();
    Iterator i(this);
    while(i.hasNext()) {
        i.next();
        context()->addOrSetChild(keyName, i.key());
        context()->addOrSetChild(valueName, i.value());
        nextPrimitive->run();
    }
    Primitive::skip(this);
}