Пример #1
0
static cx_equalityKind cx_collection_compareListWithList(cx_collection t, cx_ll list1, cx_ll list2) {
    cx_equalityKind result = CX_EQ;
    cx_iter iter1, iter2;
    void *e1, *e2;
    cx_type elementType = t->elementType;
    cx_any v1, v2;
    
    iter1 = cx_llIter(list1);
    iter2 = cx_llIter(list2);
    while(cx_iterHasNext(&iter1) && cx_iterHasNext(&iter2)) {
        if (cx_collection_elementRequiresAlloc(t)) {
            e1 = cx_iterNext(&iter1);
            e2 = cx_iterNext(&iter2);
        } else {
            e1 = cx_iterNextPtr(&iter1);
            e2 = cx_iterNextPtr(&iter2);
        }
        v1.type = v2.type = elementType;
        v1.value = e1;
        v2.value = e2;
        result = cx_type_compare(v1, v2);
        if (result != CX_EQ) {
            break;
        }
    }
    
    return result;
}
Пример #2
0
static cx_equalityKind cx_collection_compareArrayWithList(cx_collection t, void *array, cx_uint32 elementSize, cx_ll list) {
    cx_equalityKind result = CX_EQ;
    cx_uint32 i=0;
    cx_iter iter;
    void *e1, *e2;
    cx_type elementType = t->elementType;
    cx_any v1, v2;
    
    iter = cx_llIter(list);
    while(cx_iterHasNext(&iter)) {
        if (cx_collection_elementRequiresAlloc(t)) {
            e1 = cx_iterNext(&iter);
        } else {
            e1 = cx_iterNextPtr(&iter);
        }
        e2 = CX_OFFSET(array, elementSize * i);
        v1.type = v2.type = elementType;
        v1.value = e2;
        v2.value = e1;
        result = cx_type_compare(v1, v2);
        if (result != CX_EQ) {
            break;
        }
        i++;
    }
    
    return result;
}
Пример #3
0
/* ::cortex::Fast::Expression::fromList(list{Expression} list) */
Fast_Expression Fast_Expression_fromList(Fast_Expression_list list) {
/* $begin(::cortex::Fast::Expression::fromList) */
    Fast_Expression result = NULL;

    /* Convert list to comma expression */
    if (list) {
        if (cx_llSize(list) == 1) {
            result = cx_llGet(list, 0);
        } else {
            cx_ll toList = cx_llNew(); /* Copy list */
            cx_iter iter;
            Fast_Expression expr;
            
            result = Fast_Expression(Fast_Comma__create());

            iter = cx_llIter(list);
            while(cx_iterHasNext(&iter)) {
                expr = cx_iterNext(&iter);
                cx_llAppend(toList, expr); cx_keep_ext(result, expr, "add expression from list to comma-expression");
            }
            Fast_Comma(result)->expressions = toList;
            Fast_Parser_collect(yparser(), result);
        }
    }
    
    return result;
/* $end */
}
Пример #4
0
/* ::cortex::Fast::Expression::cleanList(list{Expression} list) */
cx_void Fast_Expression_cleanList(Fast_Expression_list list) {
/* $begin(::cortex::Fast::Expression::cleanList) */
    if (list) {
        cx_iter iter = cx_llIter(list);
        while(cx_iterHasNext(&iter)) {
            cx_free_ext(NULL, cx_iterNext(&iter), "free expression from list");
        }
        cx_llFree(list);
    }
/* $end */
}
Пример #5
0
/* $header(::cortex::web::server::post) */
static cx_observableEvent web_server_findRelatedEvent(web_server _this, cx_observableEvent e) {
    cx_iter iter = cx_llIter(_this->events);
    cx_observableEvent e2;
    while ((cx_iterHasNext(&iter))) {
        e2 = cx_iterNext(&iter);
        if((e2->me == e->me) &&
          (e2->observable == e->observable) &&
          (e2->source == e->source) &&
          (e2->observer == e->observer)) {
            return e2;
        }
    }
    return NULL;
}
Пример #6
0
/* ::cortex::ic::program::popScope() */
cx_void ic_program_popScope(ic_program _this) {
/* $begin(::cortex::ic::program::popScope) */
    if (_this->scope->storages) {
        cx_iter storageIter;
        ic_storage storage;

        storageIter = cx_llIter(_this->scope->storages);
        while(cx_iterHasNext(&storageIter)) {
            storage = cx_iterNext(&storageIter);
            if ((storage->kind == IC_VARIABLE) && !((ic_variable)storage)->isReturn && !((ic_variable)storage)->isParameter) {
                ic_storage_free(storage);
            }
        }
    }

    if (_this->scope->parent) {
        _this->scope = _this->scope->parent;
    }
/* $end */
}
Пример #7
0
/* ::cortex::web::SockJsServer::poll() */
cx_void web_SockJsServer_poll(web_SockJsServer _this) {
/* $begin(::cortex::web::SockJsServer::poll) */
    struct mg_server *server = (struct mg_server *)_this->server;
    mg_poll_server(server, _this->pollTimemoutMillis);
    _this->timeElapsed += _this->pollTimemoutMillis;

    /* Send heartbeats for all live connections every n seconds */
    if (_this->timeElapsed >= (WEB_SOCKJSSERVER_DEFAULT_HEARTBEAT_TIMEOUT * 1000)) {
        cx_ll scope = cx_scopeClaim(_this);
        cx_iter iter = cx_llIter(scope);
        while (cx_iterHasNext(&iter)) {
            cx_object o = cx_iterNext(&iter);
            if (cx_instanceof(cx_type(web_SockJsServer_Connection_o), o)) {
                web_SockJsServer_Connection c = web_SockJsServer_Connection(o);
                mg_websocket_printf((struct mg_connection *)c->conn, WEBSOCKET_OPCODE_TEXT, "h");
            }
        }
        cx_scopeRelease(scope);
        _this->timeElapsed = 0;
    }
/* $end */
}
Пример #8
0
/* ::cortex::Fast::String::toIc(ic::program program,ic::storage storage,bool stored) */
ic_node Fast_String_toIc_v(Fast_String _this, ic_program program, ic_storage storage, cx_bool stored) {
/* $begin(::cortex::Fast::String::toIc) */
    ic_node result = NULL;
    CX_UNUSED(storage);
    CX_UNUSED(stored);

    /* Parse string after parsing script and thus not interfere with parser */
    if (Fast_String_parse(_this)) {
        goto error;
    }

    if (!cx_llSize(_this->elements)) {
        result = (ic_node)ic_literal__create((cx_any){cx_type(cx_string_o), &_this->value, FALSE});
    } else {
        if (stored) {
            cx_iter elementIter;
            Fast_Expression element;
            ic_node icElement1, icElement2;
            cx_uint32 elementCount = cx_llSize(_this->elements);
            cx_bool stored = FALSE;
            ic_node dummy;
            cx_uint32 accPushCount = 0;
            cx_type elementType;

            if (storage && (storage->type != cx_type(cx_string_o))) {
                Fast_Parser_error(yparser(),
                        "storage for string-expression '%s' has invalid type (%s)",
                        _this->value,
                        cx_nameof(storage->type));
                goto error;
            }

            dummy = (ic_node)ic_literal__create((cx_any){cx_type(cx_string_o), NULL, FALSE});

            result = (ic_node)storage;
            elementIter = cx_llIter(_this->elements);
            while(cx_iterHasNext(&elementIter)) {
                ic_accumulator acc = ic_program_pushAccumulator(program, (cx_type)cx_string_o, FALSE, FALSE);
                accPushCount++;
                element = cx_iterNext(&elementIter);

                elementType = Fast_Expression_getType(element);
                if (!elementType) {
                    element = Fast_Expression(Fast_String__create(CX_NULL_STRING));
                } else if (elementType != cx_type(cx_string_o)) {
                    element = Fast_Expression_cast(element, cx_type(cx_string_o), FALSE);
                    if(!element) {
                        goto error;
                    }
                }

                icElement1 = Fast_Node_toIc(Fast_Node(element), program, (ic_storage)acc, TRUE);
                if (!icElement1) {
                    goto error;
                }
                if (elementCount == 1) {
                    if (storage) {
                        IC_2(program, Fast_Node(_this)->line, ic_strcpy, storage, icElement1, IC_DEREF_VALUE, IC_DEREF_VALUE);
                    } else {
                        result = (ic_node)icElement1;
                    }
                    stored = TRUE;
                } else {
                    if (elementCount) {
                        if (cx_iterHasNext(&elementIter)) {
                            ic_accumulator acc = ic_program_pushAccumulator(program, (cx_type)cx_string_o, FALSE, FALSE);
                            accPushCount++;
                            element = cx_iterNext(&elementIter);
                            elementType = Fast_Expression_getType(element);

                            if (!elementType) {
                                element = Fast_Expression(Fast_String__create(CX_NULL_STRING));
                            } else if (elementType && (Fast_Expression_getType(element) != cx_type(cx_string_o))) {
                                element = Fast_Expression_cast(element, cx_type(cx_string_o), FALSE);
                                if (!element) {
                                    goto error;
                                }
                            }

                            icElement2 = Fast_Node_toIc(Fast_Node(element), program, (ic_storage)acc, TRUE);
                            if (!icElement2) {
                                goto error;
                            }
                            IC_2(program, Fast_Node(_this)->line, ic_strcat, icElement1, icElement2, IC_DEREF_VALUE, IC_DEREF_VALUE);
                            elementCount--;
                        }
                    } else {
                        IC_2(program, Fast_Node(_this)->line, ic_strcat, icElement1, dummy, IC_DEREF_VALUE, IC_DEREF_VALUE);
                    }
                }
                elementCount--;
            }

            /* If string is not yet copied, insert copy instruction */
            if (!stored) {
                IC_2(program, Fast_Node(_this)->line, ic_strcpy, storage, dummy, IC_DEREF_VALUE, IC_DEREF_VALUE);
                stored = TRUE;
            }

            while(accPushCount) {
                ic_program_popAccumulator(program);
                accPushCount--;
            }
        }
    }

    return result;
error:
    return NULL;
/* $end */
}