private EvaluationResult DoGetOrAdd(Context context, ModuleLiteral env, EvaluationResult key, EvaluationResult?state, Closure factoryClosure) { var helper = new HashingHelper(context.PathTable, recordFingerprintString: false); // Add the qualifier to the key var qualifierId = context.LastActiveModuleQualifier.QualifierId; var qualifierDisplayString = context.ContextTree.FrontEndContext.QualifierTable.GetQualifier(qualifierId).ToDisplayString(StringTable); helper.Add(qualifierDisplayString); if (!TryHashValue(key, helper)) { return(EvaluationResult.Error); } var keyFingerprint = helper.GenerateHash().ToHex(); var thunkCreatedByThisThread = false; // ensure that all concurrent evaluations of the same value cache key will get the same thunk and module var thunkAndModule = context.EvaluationScheduler.ValueCacheGetOrAdd( keyFingerprint, () => { var factoryArgs = state.HasValue ? new Expression[] { new LocalReferenceExpression(SymbolAtom.Create(context.StringTable, "state"), index: factoryClosure.Frame.Length, default) } : CollectionUtilities.EmptyArray <Expression>(); var thunk = new Thunk(ApplyExpression.Create(factoryClosure, factoryArgs, factoryClosure.Location), null); var module = context.LastActiveUsedModule; thunkCreatedByThisThread = true; return(thunk, module); });
private Expression CurrentPathAtomInterpolationExpression(ref ProcessedTagTemplateExpression source, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId) { var expressions = EnumerateTaggedExpressionsForPathAtomInterpolation(source.Head, source.TemplateSpans, escapes, currentQualifierSpaceId); // Expressions could be empty only for the case like a``; if (expressions == null || expressions.Count == 0) { return(null); } return(ApplyExpression.Create(m_pathAtomInterpolateSelectorExpression, expressions.ToArray(), expressions[0].Location)); }
/// <summary> /// Converts string interpolation expression like <code>let x = `${foo}`;</code> /// </summary> public Expression ConvertStringInterpolation(ITemplateExpression source, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId) { var taggedExpressions = EnumerateTaggedExpressionsForStringInterpolation(source, escapes, currentQualifierSpaceId); // There is one corner cases here: // If tagged expression is just a string literal, but has no expressions, we can just return it if (taggedExpressions.Count == 1) { if (taggedExpressions[0] is StringLiteral stringLiteral) { return(stringLiteral); } } var applyExpression = ApplyExpression.Create(m_stringInterpolationSelectorExpression, taggedExpressions.ToArray(), LineInfo(source)); return(new StringLiteralExpression(applyExpression, applyExpression.Location)); }