예제 #1
0
        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);
            });
예제 #2
0
        /// <summary>
        /// Constructor that takes string invocation expression to String.interpolate.
        /// </summary>
        public StringLiteralExpression(ApplyExpression stringInterpolationInvocationExpression, LineInfo location)
            : base(location)
        {
            Contract.Requires(stringInterpolationInvocationExpression != null);

            StringInterpolationInvocationExpression = stringInterpolationInvocationExpression;
        }
예제 #3
0
 internal StackEntry Initialize(FunctionLikeExpression lambda, ModuleLiteral closureEnv, ApplyExpression ambientCall, AbsolutePath path, LineInfo location, DebugInfo debugInfo)
 {
     Lambda             = lambda;
     Env                = closureEnv;
     m_ambientCall      = ambientCall;
     Path               = path;
     InvocationLocation = location;
     DebugInfo          = debugInfo;
     return(this);
 }
예제 #4
0
        /// <nodoc />
        internal void Clear()
        {
            Contract.Requires(Previous == null);

            Lambda        = null;
            Env           = null;
            m_ambientCall = null;
            DebugInfo     = null;

            // Path, LineInfo, Depth do not hold references, so we don't care
        }
예제 #5
0
        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));
        }
예제 #6
0
        /// <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));
        }
예제 #7
0
        public void GetAndEvaluateApplyExpression()
        {
            Machine           machine = new Machine();
            List <Expression> list    = new List <Expression>();

            list.Add(new IntegerExpression(1));
            list.Add(new IntegerExpression(2));
            list.Add(new IntegerExpression(3));

            machine.Push(new CompositeExpression(list));

            Assert.AreEqual(1, machine.StackCount);

            ApplyExpression expression = ApplyExpression.Instance;

            expression.Evaluate(machine);

            Assert.AreEqual(3, machine.StackCount);
            Assert.AreEqual(3, machine.Pop());
            Assert.AreEqual(2, machine.Pop());
            Assert.AreEqual(1, machine.Pop());
        }
예제 #8
0
 /// <nodoc />
 internal StackEntry Initialize(Closure closure, ApplyExpression ambientCall, AbsolutePath path, LineInfo location, DebugInfo debugInfo)
 => Initialize(closure?.Function, closure?.Env, ambientCall, path, location, debugInfo);
예제 #9
0
 /// <nodoc />
 public StringLiteralExpression(DeserializationContext context, LineInfo location)
     : base(location)
 {
     StringInterpolationInvocationExpression = (ApplyExpression)ReadExpression(context);
 }
예제 #10
0
 /// <nodoc />
 public virtual void Visit(ApplyExpression applyExpression)
 {
 }