/* ::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 */ }
/* $end */ cx_void web_server_post(web_server _this, cx_event e) { /* $begin(::cortex::web::server::post) */ cx_uint32 size = 0; cx_observableEvent e2; cx_lock(_this); /* Check if there is already another event in the queue for the same object. * if so, replace event with latest update. */ if ((e2 = web_server_findRelatedEvent(_this, cx_observableEvent(e)))) { cx_llReplace(_this->events, e2, e); cx_free(e2); } else { cx_llAppend(_this->events, e); } size = cx_llSize(_this->events); cx_unlock(_this); /* If queue is getting big, slow down publisher */ if (size > 100) { cx_sleep(0, 10000000); } /* $end */ }
/* ::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 */ }
cx_word Fast_Initializer_offset(Fast_StaticInitializer _this, cx_uint32 variable) { cx_word result, base; cx_uint16 fp = Fast_Initializer(_this)->fp; Fast_InitializerFrame *frame = &Fast_Initializer(_this)->frames[fp?fp-1:0]; Fast_StaticInitializerFrame *baseFrame = &(_this->frames[fp?fp-1:0]); Fast_InitializerFrame *thisFrame = &Fast_Initializer(_this)->frames[fp]; result = 0; base = baseFrame->ptr[variable]; if (!base) { Fast_Parser_error(yparser(), "parser error: base is zero in offset calculation"); goto error; } /* Switch on current type */ switch(frame->type->kind) { case CX_PRIMITIVE: result = base; break; case CX_COMPOSITE: if (fp) { result = base + thisFrame->member->offset; } else { result = base; } break; case CX_ITERATOR: result = base; break; case CX_COLLECTION: { if (fp) { cx_uint32 elementSize = cx_type_sizeof(cx_collection(frame->type)->elementType); switch(cx_collection(frame->type)->kind) { case CX_SEQUENCE: ((cx_objectSeq*)base)->length++; ((cx_objectSeq*)base)->buffer = cx_realloc(((cx_objectSeq*)base)->buffer, ((cx_objectSeq*)base)->length * elementSize); base = (cx_word)((cx_objectSeq*)base)->buffer; case CX_ARRAY: result = base + thisFrame->location * cx_type_sizeof(cx_collection(frame->type)->elementType); memset((void*)result, 0, elementSize); break; case CX_LIST: { if (cx_collection_elementRequiresAlloc(cx_collection(frame->type))) { result = (cx_word)cx_calloc(elementSize); } if (!*(cx_ll*)base) { *(cx_ll*)base = cx_llNew(); } cx_llAppend(*(cx_ll*)base, (void*)result); if (!result) { result = (cx_word)cx_llGetPtr(*(cx_ll*)base, cx_llSize(*(cx_ll*)base)-1); } break; } case CX_MAP: { cx_type keyType = cx_map(frame->type)->keyType; if (!thisFrame->isKey) { if (cx_collection_elementRequiresAlloc(cx_collection(frame->type))) { result = (cx_word)cx_calloc(elementSize); } if (!*(cx_rbtree*)base) { *(cx_rbtree*)base = cx_rbtreeNew(frame->type); } cx_rbtreeSet(*(cx_rbtree*)base, (void*)_this->frames[fp].keyPtr[variable], (void*)result); if (!result) { if (_this->frames[fp].keyPtr[variable]) { result = (cx_word)cx_rbtreeGetPtr(*(cx_rbtree*)base, (void*)_this->frames[fp].keyPtr[variable]); } else { Fast_Parser_error(yparser(), "cannot set element without keyvalue"); goto error; } } } else { result = (cx_word)cx_calloc(cx_type_sizeof(keyType)); _this->frames[fp].keyPtr[variable] = result; thisFrame->isKey = FALSE; } break; } } } else { result = base; } break; } default: { cx_id id; Fast_Parser_error(yparser(), "invalid initializer type '%s'", Fast_Parser_id(frame->type, id)); break; } } return result; error: return 0; }