private async Task <TaskCompletionSource <ObjectData> > registerAsync(ExecutionContext ctx, EntityInstance typeInstance) { TaskCompletionSource <ObjectData> type_entry; bool existing; lock (this.threadLock) { existing = this.types.TryGetValue(typeInstance, out type_entry); if (!existing) { // creating entry to avoid infinite loop when building static fields of the type we are just building // in future it might be necessary to use Option instead of raw null to have 3 cases // * empty placeholder (type in processing) // * null (type processed, no static fields) // * value with fields type_entry = new TaskCompletionSource <ObjectData>(); this.types.Add(typeInstance, type_entry); } } if (!existing) { ObjectData type_object = await ObjectData.CreateTypeAsync(ctx, typeInstance).ConfigureAwait(false); type_entry.SetResult(type_object); TypeContainerDefinition target = typeInstance.Target.CastTypeContainer(); IEnumerable <VariableDeclaration> static_fields = target.NestedFields.Where(it => it.Modifier.HasStatic); if (static_fields.Any()) { Interpreter.SetupFunctionCallData(ref ctx, typeInstance.TemplateArguments, metaThis: null, functionArguments: null); await ctx.Interpreter.ExecutedAsync(target.NestedFunctions.Single(it => it.IsZeroConstructor() && it.Modifier.HasStatic), ctx).ConfigureAwait(false); } } return(type_entry); }