/* ::cortex::web::DDPServer::Session::connected() */ cx_void web_DDPServer_Session_connected(web_DDPServer_Session _this) { /* $begin(::cortex::web::DDPServer::Session::connected) */ int msgLength = snprintf(NULL, 0, "{\"msg\":\"connected\",\"session\":\"%s\"}", cx_nameof(_this)); cx_string msg = cx_malloc(msgLength + 1); sprintf(msg, "{\"msg\":\"connected\",\"session\":\"%s\"}", cx_nameof(_this)); web_SockJsServer_Connection_send(_this->conn, msg); cx_dealloc(msg); /* $end */ }
/* $end */ cx_int16 cx_function_init(cx_function _this) { /* $begin(::cortex::lang::function::init) */ cx_functionLookup_t walkData; cx_ll scope; scope = cx_scopeClaim(cx_parentof(_this)); walkData.f = _this; walkData.error = FALSE; cx_signatureName(cx_nameof(_this), walkData.name); cx_llWalk(scope, cx_functionLookupWalk, &walkData); if (walkData.error) { goto error; } cx_scopeRelease(scope); /* Parse arguments */ if (cx_function_parseArguments(_this)) { goto error; } return 0; error: _this->parameters.length = 0; return -1; /* $end */ }
static cx_int16 serializeItem(cx_serializer s, cx_value *info, void *userData) { cx_json_ser_t *data = userData; cx_member member = info->is.member.t; cx_string name = cx_nameof(member); if (data->itemCount && !cx_ser_appendstr(data, ",")) { goto finished; } if (info->kind == CX_MEMBER) { if (!cx_ser_appendstr(data, "\"%s\":", name)) { goto finished; } } if (cx_serializeValue(s, info, userData)) { goto error; } data->itemCount += 1; return 0; error: return -1; finished: return 1; }
cx_int16 cx_type_bindMetaprocedure(cx_type _this, cx_metaprocedure procedure) { cx_function* f; cx_int32 d = 0; /* Check if function is overloaded */ if ((f = cx_vtableLookup(&_this->metaprocedures, cx_nameof(procedure), NULL, &d))) { if (d) { cx_function(*f)->overloaded = TRUE; /* Flag found and passed function as overloaded. */ cx_function(procedure)->overloaded = TRUE; } else { if (*f != cx_function(procedure)) { /* Overriding metaprocedures is not allowed. */ cx_id id, id2; cx_error("definition of metaprocedure '%s' conflicts with existing metaprocedure '%s'", cx_fullname(*f, id), cx_fullname(procedure, id2)); goto error; } } } if (cx_vtableInsert(&_this->metaprocedures, cx_function(procedure))) { cx_keep_ext(_this, procedure, "Bind metaprocedure to type."); } return 0; error: return -1; }
Fast_Call Fast_createCallFromExpr(Fast_Expression f, Fast_Expression arguments) { Fast_Call result = NULL; Fast_Expression instance = NULL; cx_id name; cx_object scope = yparser()->scope; Fast_CallBuilder builder; if (Fast_Node(f)->kind == Fast_StorageExpr) { switch(Fast_Storage(f)->kind) { case Fast_ObjectStorage: { cx_object o = Fast_Object(f)->value; cx_signatureName(cx_nameof(o), name); scope = cx_parentof(o); break; } case Fast_LocalStorage: strcpy(name, Fast_Local(f)->name); break; case Fast_MemberStorage: instance = Fast_Member(f)->lvalue; strcpy(name, Fast_String(Fast_Member(f)->rvalue)->value); break; case Fast_ElementStorage: result = Fast_Call(Fast_DelegateCall__create(NULL, arguments, f)); break; default: Fast_Parser_error(yparser(), "'%s' expression is not callable", cx_nameof(cx_enum_constant(Fast_storageKind_o, Fast_Storage(f)->kind))); goto error; } } if (!result) { Fast_CallBuilder__init(&builder, name, arguments, instance, scope, yparser()->block); result = Fast_CallBuilder_build(&builder); Fast_CallBuilder__deinit(&builder); } return result; error: return NULL; }
/* ::cortex::ic::program::getMember(storage base,member m) */ ic_member ic_program_getMember(ic_program _this, ic_storage base, cx_member m) { /* $begin(::cortex::ic::program::getMember) */ cx_id name; ic_member result; sprintf(name, "%s.%s", base->name, cx_nameof(m)); result = ic_member(ic_scope_lookupStorage(base->scope, name, FALSE)); if (!result) { result = ic_member__create(base, m); ic_scope_addStorage(_this->scope, ic_storage(result)); } return result; /* $end */ }
static int cx_functionLookupWalk(cx_object o, void* userData) { cx_functionLookup_t* data; cx_int32 d; data = userData; if (o != data->f) { if ((cx_class_instanceof(cx_procedure_o, cx_typeof(o)))) { if (cx_overload(o, cx_nameof(data->f), &d, FALSE)) { data->error = TRUE; goto finish; } /* Check if function matches */ if (!d) { cx_id id, id2; cx_error("function '%s' conflicts with existing declaration '%s'", cx_fullname(data->f, id), cx_fullname(o, id2)); data->error = TRUE; goto finish; } else { cx_id id; /* Get name of function */ cx_signatureName(cx_nameof(o), id); /* Set overloading flags if a function with same name is found. */ if (!strcmp(data->name, id)) { cx_function(o)->overloaded = TRUE; data->f->overloaded = TRUE; } } } } return 1; finish: return 0; }
/* ::cortex::lang::type::nameof() */ cx_string cx_type_nameof(cx_any _this) { /* $begin(::cortex::lang::type::nameof) */ cx_string result = NULL; if (_this.value) { result = cx_nameof(_this.value); if(result) { result = cx_strdup(result); } } else { result = cx_strdup("null"); } return result; /* $end */ }
static int serializeMetaWalkScopeAction(cx_object o, void* userData) { if (!cx_ser_appendstr(userData, "{")) { goto finished; } cx_string name = cx_nameof(o); if (name) { if (!cx_appendStringAttr("name", name, userData)) { goto finished; } } else { if (!cx_ser_appendstr(userData, "\"name\":\"::\",")) { goto finished; } } cx_id type_fullname; cx_fullname(cx_typeof(o), type_fullname); if (!cx_appendStringAttr("type", type_fullname, userData)) { goto finished; } char states[sizeof("V|DCL|DEF")]; dbsh_stateStr(o, states); if (!cx_ser_appendstr(userData, "\"states\":\"%s\",", states)) { goto finished; } char attributes[sizeof("S|W|O|P")]; dbsh_attrStr(o, attributes); if (!cx_ser_appendstr(userData, "\"attributes\":\"%s\",", attributes)) { goto finished; } cx_uint32 scopeSize = cx_scopeSize(o); if (!cx_ser_appendstr(userData, "\"childCount\":%"PRId32"", scopeSize)) { goto finished; } if (!cx_ser_appendstr(userData, "},")) { goto finished; } return 1; finished: return 0; }
/* $header(::cortex::lang::function::init) */ static cx_int16 cx_function_parseArguments(cx_function object) { object->parameters = cx_function_stringToParameterSeq(cx_nameof(object), cx_parentof(object)); return object->parameters.length == (cx_uint32)-1; }
/* ::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 */ }
/* Define object */ static void cx_defineObject(cx_object o) { if (cx_define(o)) { cx_error("construction of builtin-object '%s' failed.", cx_nameof(o)); } }
static cx_int16 serializeMeta(cx_serializer s, cx_value* v, void* userData) { CX_UNUSED(s); cx_json_ser_t *data = userData; cx_object o = cx_valueValue(v); if (!data->serializeMeta) { goto error; } if (!cx_ser_appendstr(userData, "{")) { goto finished; } cx_string name = cx_nameof(o); if (name) { if (!cx_appendStringAttr("name", name, userData)) { goto finished; } } else { if (!cx_ser_appendstr(userData, "\"name\":\"::\",")) { goto finished; } } cx_id type_fullname; cx_fullname(cx_typeof(o), type_fullname); if (!cx_appendStringAttr("type", type_fullname, userData)) { goto finished; } if (cx_checkAttr(o, CX_ATTR_PERSISTENT)) { cx_time t = cx_timestampof(o); if (!cx_ser_appendstr(data, "\"timestamp\":\"%d.%.9d\",", t.tv_sec, t.tv_nsec)) { goto finished; } } char states[sizeof("V|DCL|DEF")]; dbsh_stateStr(o, states); if (!cx_ser_appendstr(data, "\"states\":\"%s\",", states)) { goto finished; } char attributes[sizeof("S|W|O|P")]; dbsh_attrStr(o, attributes); if (!cx_ser_appendstr(data, "\"attributes\":\"%s\",", attributes)) { goto finished; } cx_id parent_fullname; cx_fullname(cx_parentof(o), parent_fullname); if (!cx_ser_appendstr(data, "\"parent\":\"%s\",", parent_fullname)) { goto finished; } cx_uint32 scopeSize = cx_scopeSize(o); if (!cx_ser_appendstr(data, "\"childCount\":%"PRId32"", scopeSize)) { goto finished; } if (!cx_ser_appendstr(data, "}")) { goto finished; } return 0; error: return -1; finished: return 1; }