/* ::cortex::web::DDPServer::Session::onUpdate() */ cx_void web_DDPServer_Session_onUpdate(web_DDPServer_Session _this, cx_object *observable, cx_object *source) { /* $begin(::cortex::web::DDPServer::Session::onUpdate) */ CX_UNUSED(_this); CX_UNUSED(observable); CX_UNUSED(source); /* $end */ }
int ddsMain(int argc, char* argv[]) { /* $begin(main) */ /* Insert code that must be run when component is loaded */ CX_UNUSED(argc); CX_UNUSED(argv); return 0; /* $end */ }
/* ::cortex::Fast::Expression::serialize(type dstType,word dst) */ cx_int16 Fast_Expression_serialize_v(Fast_Expression _this, cx_type dstType, cx_word dst) { /* $begin(::cortex::Fast::Expression::serialize) */ CX_UNUSED(_this); CX_UNUSED(dstType); CX_UNUSED(dst); cx_assert(0, "call to pure virtual function Fast::Expression::serialize"); return 0; /* $end */ }
/* ::cortex::io::file::write(sequence{octet,0} data) */ cx_uint32 io_file_write(io_file _this, cx_octet_seq data) { /* $begin(::cortex::io::file::write) */ CX_UNUSED(_this); CX_UNUSED(data); cx_trace("io::File::write not yet implemented."); return -1; /* $end */ }
/* ::cortex::Fast::SignedInteger::toIc(ic::program program,ic::storage storage,bool stored) */ ic_node Fast_SignedInteger_toIc_v(Fast_SignedInteger _this, ic_program program, ic_storage storage, cx_bool stored) { /* $begin(::cortex::Fast::SignedInteger::toIc) */ ic_node result; CX_UNUSED(storage); CX_UNUSED(stored); CX_UNUSED(program); result = (ic_node)ic_literal__create((cx_any){Fast_Expression_getType(Fast_Expression(_this)), &_this->value, FALSE}); return result; /* $end */ }
/* This function is the entrypoint for the library and * loads definitions of the 'web' scope */ int cortexmain(int argc, char* argv[]) { CX_UNUSED(argc); CX_UNUSED(argv); int result = web_load(); /* $begin(cortexmain) */ /* Insert user-code here */ /* $end */ return result; }
/* This function is the entrypoint for the library and * loads definitions of the 'ic' scope */ int cortexmain(int argc, char* argv[]) { CX_UNUSED(argc); CX_UNUSED(argv); int result = ic_load(); /* $begin(cortexmain) */ if (cx_threadTlsKey(&IC_PROGRAM_KEY, NULL)) { return -1; } /* $end */ return result; }
int idlMain(int argc, char* argv[]) { /* $begin(main) */ /* Insert code that must be run when component is loaded */ CX_UNUSED(argc); CX_UNUSED(argv); if (cx_threadTlsKey(&idl_PARSER_KEY, NULL)) { return -1; } /* Register corto extension */ cx_loaderRegister("idl", idl_loadFile, NULL); return 0; /* $end */ }
/* ::cortex::Fast::Element::toIc(ic::program program,ic::storage storage,bool stored) */ ic_node Fast_Element_toIc_v(Fast_Element _this, ic_program program, ic_storage storage, cx_bool stored) { /* $begin(::cortex::Fast::Element::toIc) */ ic_element result; ic_node lvalue, rvalue; CX_UNUSED(stored); CX_UNUSED(storage); /* Get lvalue & rvalue */ lvalue = Fast_Node_toIc(Fast_Node(_this->lvalue), program, NULL, TRUE); rvalue = Fast_Node_toIc(Fast_Node(_this->rvalue), program, NULL, TRUE); result = ic_program_getElement(program, ic_storage(lvalue), rvalue); return (ic_node)result; /* $end */ }
static cx_int16 cx_ser_construct(cx_serializer s, cx_value *info, void *userData) { cx_compare_ser_t *data = userData; cx_bool compare = FALSE; CX_UNUSED(s); cx_type t1 = cx_valueType(info); cx_type t2 = cx_valueType(&data->value); /* If types are different, validate whether comparison should take place */ if (t1 != t2) { /* Certain types of collections can be compared with each other as long as their elementTypes * are equal */ if ((t1->kind == CX_COLLECTION) && (t1->kind == t2->kind)) { switch(cx_collection(t1)->kind) { case CX_ARRAY: case CX_SEQUENCE: case CX_LIST: switch(cx_collection(t2)->kind) { case CX_ARRAY: case CX_SEQUENCE: case CX_LIST: if (cx_collection(t1)->elementType == cx_collection(t2)->elementType) { compare = TRUE; } break; case CX_MAP: compare = FALSE; break; } break; case CX_MAP: if (cx_collection(t2)->kind == CX_MAP) { if (cx_collection(t1)->elementType == cx_collection(t2)->elementType) { if (cx_map(t1)->keyType == cx_map(t2)->keyType) { compare = TRUE; } } } break; } } else { if ((!t1->reference && (t1->kind == CX_VOID)) && (t2->reference || ((t2->kind == CX_PRIMITIVE) && (cx_primitive(t2)->kind == CX_TEXT)))) { compare = TRUE; } if ((!t2->reference && (t2->kind == CX_VOID)) && (t1->reference || ((t1->kind == CX_PRIMITIVE) && (cx_primitive(t1)->kind == CX_TEXT)))) { compare = TRUE; } } } else { compare = TRUE; } data->result = compare ? CX_EQ : CX_NEQ; data->base = cx_valueValue(info); return !compare; }
/* ::cortex::io::file::readText() */ cx_string io_file_readText(io_file _this) { /* $begin(::cortex::io::file::readText) */ CX_UNUSED(_this); cx_trace("io::File::readText not yet implemented."); return NULL; /* $end */ }
/* Parse an IDL file */ int idl_loadFile(cx_string file, int argc, char* argv[], void* udata) { idl_Parser p; CX_UNUSED(udata); CX_UNUSED(argc); CX_UNUSED(argv); /* Parse IDL */ p = idl_ParserCreate(file, NULL); if (!p) { goto error; } idl_Parser_parse(p); cx_release(p); return 0; error: return -1; }
/* ::cortex::Fast::report(string kind,string filename,uint32 line,uint32 column,string error,string token) */ cx_void Fast_report(cx_string kind, cx_string filename, cx_uint32 line, cx_uint32 column, cx_string error, cx_string token) { /* $begin(::cortex::Fast::report) */ CX_UNUSED(token); if(filename) { cx_print("%s:%d:%d: %s: %s", filename, line, column, kind, error); } else { cx_print("%d:%d: %s: %s", line, column, kind, error); } /* $end */ }
/* ::cortex::Fast::Member::toIc(ic::program program,ic::storage storage,bool stored) */ ic_node Fast_Member_toIc_v(Fast_Member _this, ic_program program, ic_storage storage, cx_bool stored) { /* $begin(::cortex::Fast::Member::toIc) */ ic_member result = NULL; cx_member member; ic_node lvalue; CX_UNUSED(stored); CX_UNUSED(storage); /* Get lvalue & rvalue */ lvalue = Fast_Node_toIc(Fast_Node(_this->lvalue), program, NULL, FALSE); if (Fast_Node(_this->rvalue)->kind == Fast_LiteralExpr) { if (Fast_Literal(_this->rvalue)->kind == Fast_Text) { cx_type t = Fast_Expression_getType(_this->lvalue); if (cx_instanceof(cx_type(cx_interface_o), t)) { cx_interface baseType = cx_interface(t); member = cx_interface_resolveMember(baseType, Fast_String(_this->rvalue)->value); } else { cx_id id; Fast_Parser_error(yparser(), "cannot resolve members on non-interface type '%s'", Fast_Parser_id(t, id)); goto error; } } else { Fast_Parser_error(yparser(), "dynamic resolving of members not yet supported."); goto error; } } else { Fast_Parser_error(yparser(), "dynamic resolving of members not yet supported."); goto error; } if (member) { result = ic_program_getMember(program, ic_storage(lvalue), member); } return (ic_node)result; error: return NULL; /* $end */ }
static cx_int16 cx_ser_reference(cx_serializer s, cx_value *info, void *userData) { cx_compare_ser_t *data = userData; void *_this = cx_valueValue(info); void *value = (void*)((cx_word)cx_valueValue(&data->value) + ((cx_word)_this - (cx_word)data->base)); CX_UNUSED(s); if (*(cx_object*)_this != *(cx_object*)value) { data->result = CX_NEQ; } else { data->result = CX_EQ; } return data->result != CX_EQ; }
/* ::cortex::io::file::readAll() */ cx_octet_seq io_file_readAll(io_file _this) { /* $begin(::cortex::io::file::readAll) */ cx_octet_seq result; CX_UNUSED(_this); result.length = 0; result.buffer = NULL; cx_trace("io::File::readAll not yet implemented."); return result; /* $end */ }
static cx_int16 serializeScopeMeta(cx_serializer s, cx_value* v, void* userData) { CX_UNUSED(s); /* should we receive s for scalability or should we dismiss it? */ int last; size_t sizeBefore, sizeAfter; cx_json_ser_t *data = userData; sizeBefore = strlen(data->buffer); cx_object object = cx_valueValue(v); last = cx_scopeWalk(object, serializeMetaWalkScopeAction, userData); sizeAfter = strlen(data->buffer); if (sizeAfter && sizeBefore < sizeAfter) { data->buffer[sizeAfter - 1] = '\0'; } return last; }
static cx_int16 serializePrimitive(cx_serializer s, cx_value *v, void *userData) { CX_UNUSED(s); cx_type type = cx_valueType(v); cx_json_ser_t *data = userData; cx_int16 result; cx_string valueString; switch (cx_primitive(type)->kind) { case CX_BINARY: result = serializeBinary(v, &valueString); break; case CX_BITMASK: result = serializeBitmask(v, &valueString); break; case CX_BOOLEAN: result = serializeBoolean(v, &valueString); break; case CX_ENUM: result = serializeEnum(v, &valueString); break; case CX_CHARACTER: case CX_TEXT: result = serializeText(v, &valueString); break; case CX_UINTEGER: case CX_INTEGER: case CX_FLOAT: result = serializeNumber(v, &valueString); break; case CX_ALIAS: result = serializeAlias(v, &valueString); break; } if (result) { goto error; } if (!cx_ser_appendstr(data, "%s", valueString)) { goto finished; } cx_dealloc(valueString); return 0; finished: cx_dealloc(valueString); return 1; error: return -1; }
cx_err cx_logv(cx_err kind, unsigned int level, char* fmt, va_list arg, FILE* f) { char buff[CX_MAX_LOG + 1]; unsigned int written; size_t n = 0; cx_string alloc = NULL; cx_string msg = buff; va_list argcpy; va_copy(argcpy, arg); /* Make copy of arglist in * case vsnprintf needs to be called twice */ CX_UNUSED(level); if ((n = (vsnprintf(buff, CX_MAX_LOG, fmt, arg) + 1)) > CX_MAX_LOG) { alloc = cx_malloc(n + 2); vsnprintf(alloc, n, fmt, argcpy); msg = alloc; } n = strlen(msg); /* Set last error without \n */ cx_setLasterror(msg); strcat(msg, "\n"); n++; if (cx_getEcho() || ((kind == CX_CRITICAL) || (kind == CX_ASSERT))){ if ((written = fwrite(msg, 1, n, f)) != n) { fprintf(f, "Error in cx_logv: number of bytes written (%u)"\ " does not match length of message (%zu).\n", written, n); } } if (alloc) { cx_dealloc(alloc); } return kind; }
static cx_int16 serializeReference(cx_serializer s, cx_value *v, void *userData) { CX_UNUSED(s); cx_json_ser_t *data; void *o; cx_object object; cx_id id; data = userData; o = cx_valueValue(v); object = *(cx_object*)o; if (object) { if (cx_checkAttr(object, CX_ATTR_SCOPED) || (cx_valueObject(v) == object)) { cx_uint32 length; cx_fullname(object, id); /* Escape value */ cx_string escapedValue = cx_malloc((length = stresc(NULL, 0, id)) + 1); stresc(escapedValue, length, id); if (!cx_ser_appendstr(data, "\"@R %s\"", escapedValue)) { cx_dealloc(escapedValue); goto finished; } cx_dealloc(escapedValue); } else { cx_ser_appendstr(data, "\"anonymous\""); } } else { if (!cx_ser_appendstrbuff(data, "null")) { goto finished; } } return 0; finished: return 1; }
/* Serialize dependencies on references */ cx_int16 cx_genDepReference(cx_serializer s, cx_value* info, void* userData) { cx_object o; g_depWalk_t data; CX_UNUSED(s); data = userData; o = *(cx_object*)cx_valueValue(info); if (o && g_mustParse(data->data->g, o)) { cx_member m; m = NULL; if (info->kind == CX_MEMBER) { m = info->is.member.t; if (!m->type->reference) { m = NULL; } } /* Add dependency on item */ if (m) { cx_depresolver_depend(data->data->resolver, data->o, CX_DEFINED, o, m->state); } else { cx_depresolver_depend(data->data->resolver, data->o, CX_DEFINED, o, CX_DEFINED); } /* Include dependencies on anonymous types */ if (!cx_checkAttr(o, CX_ATTR_SCOPED)) { cx_genDepBuildAction(o, data->data); } } return 0; }
/* ::cortex::Fast::New::toIc(ic::program program,ic::storage storage,bool stored) */ ic_node Fast_New_toIc_v(Fast_New _this, ic_program program, ic_storage storage, cx_bool stored) { /* $begin(::cortex::Fast::New::toIc) */ ic_node type, attrs, result; CX_UNUSED(stored); if (storage) { result = (ic_node)storage; } else { result = (ic_node)ic_program_pushAccumulator(program, Fast_Expression_getType(Fast_Expression(_this)), TRUE, FALSE); } type = (ic_node)ic_object__create(Fast_Expression(_this)->type); if (_this->attributes) { attrs = Fast_Node_toIc(Fast_Node(_this->attributes), program, NULL, TRUE); } else { attrs = NULL; } IC_3(program, Fast_Node(_this)->line, ic_new, result, type, attrs, IC_DEREF_ADDRESS, IC_DEREF_ADDRESS, IC_DEREF_VALUE) return result; /* $end */ }
/* Free values in collection */ static int cx_clearFreeValues(void* o, void* udata) { CX_UNUSED(udata); cx_dealloc(o); return 1; }
/* Compare collections */ static cx_int16 cx_ser_collection(cx_serializer s, cx_value *info, void* userData) { cx_type t1, t2; void *v1, *v2; cx_equalityKind result = CX_EQ; cx_uint32 size1 = 0, size2 = 0; cx_compare_ser_t *data = userData; cx_any a1, a2; CX_UNUSED(s); /* If this function is reached, collection-types are either equal or comparable. When the * base-object was a collection, the collection type can be different. When the base-object * was a composite type, the collection type has to be equal, since different composite * types are considered non-comparable. */ t1 = cx_valueType(info); v1 = cx_valueValue(info); /* Verify whether current serialized object is the base-object */ if (info->parent) { t2 = t1; v2 = (void*)((cx_word)cx_valueValue(&data->value) + ((cx_word)v1 - (cx_word)data->base)); } else { t2 = cx_valueType(&data->value); v2 = cx_valueValue(&data->value); } /* Prepare any structures for determining sizes of collections */ a1.type = t1; a1.value = v1; a2.type = t2; a2.value = v2; if ((size1 = cx_collection_size(a1)) == (size2 = cx_collection_size(a2))) { void *array1=NULL, *array2=NULL; cx_ll list1=NULL, list2=NULL; cx_uint32 elementSize=0, mem=0; elementSize = cx_type_sizeof(cx_collection(t1)->elementType); switch(cx_collection(t1)->kind) { case CX_ARRAY: array1 = v1; elementSize = cx_type_sizeof(cx_collection(t1)->elementType); mem = cx_collection(t1)->max * elementSize; break; case CX_SEQUENCE: array1 = ((cx_objectSeq*)v1)->buffer; elementSize = cx_type_sizeof(cx_collection(t1)->elementType); mem = ((cx_objectSeq*)v1)->length * elementSize; break; case CX_LIST: list1 = *(cx_ll*)v1; break; case CX_MAP: break; } switch(cx_collection(t2)->kind) { case CX_ARRAY: array2 = v2; break; case CX_SEQUENCE: array2 = ((cx_objectSeq*)v2)->buffer; break; case CX_LIST: list2 = *(cx_ll*)v2; break; case CX_MAP: break; } if (array1) { if (array2) { result = memcmp(array1,array2,mem); /* TODO: do a serialized compare */ } else if (list2) { result = cx_collection_compareArrayWithList(cx_collection(t1), array1, elementSize, list2); } } else if (list1) { if (array2) { result = cx_collection_compareArrayWithList(cx_collection(t1), array2, elementSize, list1); /* Reverse result */ if (result != CX_EQ) { if (result == CX_GT) { result = CX_LT; } else { result = CX_GT; } } } else if (list2) { result = cx_collection_compareListWithList(cx_collection(t1), list1, list2); } } } else { result = size1 > size2 ? CX_GT : CX_LT; } data->result = result < 0 ? -1 : result > 0 ? 1 : 0; return data->result != CX_EQ; }
static cx_int16 cx_ser_primitive(cx_serializer s, cx_value *info, void *userData) { cx_equalityKind result = CX_EQ; cx_compare_ser_t *data = userData; cx_type type = cx_valueType(info); void *_this = cx_valueValue(info); void *value = (void*)((cx_word)cx_valueValue(&data->value) + ((cx_word)_this - (cx_word)data->base)); CX_UNUSED(s); switch(cx_primitive(type)->kind) { case CX_BINARY: switch(cx_primitive(type)->width) { case CX_WIDTH_8: result = CX_COMPARE(cx_octet, _this, value); break; case CX_WIDTH_16: result = CX_COMPARE(cx_uint16, _this, value); break; case CX_WIDTH_32: result = CX_COMPARE(cx_uint32, _this, value); break; case CX_WIDTH_64: result = CX_COMPARE(cx_uint64, _this, value); break; case CX_WIDTH_WORD: result = CX_COMPARE(cx_word, _this, value); break; } break; case CX_BOOLEAN: result = CX_COMPARE(cx_bool, _this, value); break; case CX_CHARACTER: result = CX_COMPARE(cx_char, _this, value); break; case CX_INTEGER: switch(cx_primitive(type)->width) { case CX_WIDTH_8: result = CX_COMPARE(cx_int8, _this, value); break; case CX_WIDTH_16: result = CX_COMPARE(cx_int16, _this, value); break; case CX_WIDTH_32: result = CX_COMPARE(cx_int32, _this, value); break; case CX_WIDTH_64: result = CX_COMPARE(cx_int64, _this, value); break; case CX_WIDTH_WORD: result = CX_COMPARE(intptr_t, _this, value); break; } break; case CX_UINTEGER: switch(cx_primitive(type)->width) { case CX_WIDTH_8: result = CX_COMPARE(cx_uint8, _this, value); break; case CX_WIDTH_16: result = CX_COMPARE(cx_uint16, _this, value); break; case CX_WIDTH_32: result = CX_COMPARE(cx_uint32, _this, value); break; case CX_WIDTH_64: result = CX_COMPARE(cx_uint64, _this, value); break; case CX_WIDTH_WORD: result = CX_COMPARE(uintptr_t, _this, value); break; } break; case CX_FLOAT: switch(cx_primitive(type)->width) { case CX_WIDTH_32: result = CX_COMPARE(cx_float32, _this, value); break; case CX_WIDTH_64: result = CX_COMPARE(cx_float64, _this, value); break; default: break; } break; case CX_TEXT: { cx_string thisStr = *(cx_string*)_this; cx_string valueStr = *(cx_string*)value; if (thisStr && valueStr) { result = strcmp(thisStr, valueStr); } else { result = !(thisStr == valueStr); } break; } case CX_ENUM: case CX_BITMASK: result = CX_COMPARE(cx_int32, _this, value); break; case CX_ALIAS: result = CX_COMPARE(cx_word, _this, value); break; } data->result = result; return data->result != CX_EQ; }
/* ::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 */ }
/* ::cortex::Fast::New::hasSideEffects() */ cx_bool Fast_New_hasSideEffects_v(Fast_New _this) { /* $begin(::cortex::Fast::New::hasSideEffects) */ CX_UNUSED(_this); return TRUE; /* $end */ }
static void cx_list_appendAction(cx_ll list, void *value, void *userData) { CX_UNUSED(userData); cx_llAppend(list, value); }
static void cx_list_insertAction(cx_ll list, void *value, void *userData) { CX_UNUSED(userData); cx_llInsert(list, value); }
void cx_list_insertListAction(cx_ll list, void *value, void *userData) { cx_list_insertWalk_t *data = userData; CX_UNUSED(list); cx_iterInsert(&data->iter, value); cx_iterNext(&data->iter); }