/// <inheritdoc /> protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame) { if (ReturnExpression == null) { frame.ReturnStatementWasEvaluated = true; return(EvaluationResult.Undefined); } var value = ReturnExpression.Eval(context, env, frame); frame.ReturnStatementWasEvaluated = true; return(value); }
private static EvaluationResult IsProperSupersetOf(Context context, OrderedSet receiver, EvaluationResult arg, EvaluationStackFrame captures) { var set = Converter.ExpectSet(arg, new ConversionContext(pos: 1)); return(EvaluationResult.Create(receiver.IsProperSupersetOf(set))); }
private static EvaluationResult ToArray(Context context, OrderedSet receiver, EvaluationStackFrame captures) { var entry = context.TopStack; return(EvaluationResult.Create(ArrayLiteral.CreateWithoutCopy(receiver.ToArray(), entry.InvocationLocation, entry.Path))); }
private static EvaluationResult DumpCallStack(Context context, ModuleLiteral env, EvaluationStackFrame args) { var message = Args.AsStringOptional(args, 0) ?? string.Empty; var location = context.TopStack.InvocationLocation.AsUniversalLocation(env, context); var stack = context.GetStackTraceAsString(location); context.Logger.DebugDumpCallStack(context.FrontEndContext.LoggingContext, location.AsLoggingLocation(), message, stack); return(EvaluationResult.Undefined); }
private static EvaluationResult Launch(Context context, ModuleLiteral env, EvaluationStackFrame args) { Debugger.Launch(); return(EvaluationResult.Undefined); }
private static EvaluationResult GetKind(Context context, StaticDirectory receiver, EvaluationStackFrame captures) { return(EvaluationResult.Create(receiver.Kind)); }
private static EvaluationResult HasFile(Context context, StaticDirectory receiver, EvaluationResult arg, EvaluationStackFrame captures) { var path = GetPathFromArgument(context, receiver, arg); if (receiver.TryGetFileArtifact(path, out var _)) { return(EvaluationResult.True); } return(EvaluationResult.False); }
/// <inheritdoc /> protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame) { throw new NotImplementedException( I($"Current type '{GetType()}' does not implement '{nameof(DoEval)}' operation")); }
/// <inheritdoc /> protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame) { throw new NotImplementedException(); }
/// <summary> /// Append is the default for an array /// </summary> protected override MergeFunction GetDefaultMergeFunction(Context context, EvaluationStackFrame captures) => MergeAppend();
/// <summary> /// A regular array never has a custom merge function defined /// </summary> protected override MergeFunction TryGetCustomMergeFunction(Context context, EvaluationStackFrame captures) => null;
/// <inheritdoc/> public override EvaluationResult Merge(Context context, EvaluationStackFrame captures, EvaluationResult right) { var mergeFunction = GetMergeFunction(context, captures, this, right); return(mergeFunction(EvaluationResult.Create(this), right)); }
/// <inheritdoc /> protected override EvaluationResult DoEval(Context context, ModuleLiteral env, EvaluationStackFrame frame) { return(EvalStatements(context, env, Statements, frame)); }
/// <nodoc/> public EvaluationState(int threadId, Node node, Context context, ModuleLiteral env, EvaluationStackFrame args) : base(threadId) { Node = node; Context = context; Env = env; // Debugger has to move the stack frame to evaluation heap to prolong the lifetime of the frame. Args = args.Detach().Frame.Select(f => f.Value).ToArray(); }
private static EvaluationResult GetFiles(Context context, StaticDirectory receiver, EvaluationResult argument, EvaluationStackFrame captures) { ArrayLiteral args = Converter.ExpectArrayLiteral(argument); var result = new EvaluationResult[args.Length]; for (int i = 0; i < args.Length; i++) { var arg = args[i]; AbsolutePath path; if (arg.Value is AbsolutePath absolutePath) { path = absolutePath; } else { var stringTable = context.FrontEndContext.StringTable; var pathTable = context.FrontEndContext.PathTable; Converter.ExpectPathFragment(stringTable, arg, out PathAtom pathAtom, out RelativePath relativePath, new ConversionContext(pos: 1)); path = receiver.Root.Path; path = pathAtom.IsValid ? path.Combine(pathTable, pathAtom) : path.Combine(pathTable, relativePath); } if (receiver.TryGetFileArtifact(path, out FileArtifact file)) { result[i] = EvaluationResult.Create(file); } else { throw new FileNotFoundInStaticDirectoryException(path.ToString(context.PathTable), new ErrorContext(objectCtx: arg.Value, pos: i)); } } return(EvaluationResult.Create(ArrayLiteral.CreateWithoutCopy(result, context.TopStack.InvocationLocation, context.TopStack.Path))); }
private static EvaluationResult Equals(Context context, PathAtom receiver, EvaluationResult fragment, EvaluationResult ignoreCase, EvaluationStackFrame captures) { var stringTable = context.FrontEndContext.StringTable; PathAtom otherAtom = Converter.ExpectPathAtomFromStringOrPathAtom(stringTable, fragment, new ConversionContext(pos: 1)); if (!ignoreCase.IsUndefined) { bool ignoreCaseBool = Converter.ExpectBool(ignoreCase, new ConversionContext(pos: 2)); if (ignoreCaseBool) { return(EvaluationResult.Create(receiver.CaseInsensitiveEquals(stringTable, otherAtom))); } } // By default comparison is case sensitive return(EvaluationResult.Create(receiver.Equals(otherAtom))); }
private EvaluationResult EnsureContents(Context context, StaticDirectory receiver, EvaluationResult arg, EvaluationStackFrame captures) { // Check the kind. For now this only works on Full and Partial Sealed directories // This needs to be extended (just like getFile and getFiles) to opaque and sourcesealed directories. var stringTable = context.FrontEndContext.StringTable; var pathTable = context.FrontEndContext.PathTable; switch (receiver.SealDirectoryKind) { case SealDirectoryKind.Full: case SealDirectoryKind.Partial: // Supported since we have static directory. break; default: // For the other types we will need to schedule a pip in the graph that actually validates at runtime the file is there // either on disk for sourcesealed, or in the opaque collection by using FileContentManager.ListSealedDirectoryContents throw new DirectoryNotSupportedException(receiver.Root.Path.ToString(pathTable)); } var obj = Converter.ExpectObjectLiteral(arg); var subFolder = Converter.ExtractRelativePath(obj, m_subFolder); var filterPath = receiver.Root.Path.Combine(pathTable, subFolder); var fileContents = new List <FileArtifact>(); foreach (var sealedFile in receiver.Contents) { if (sealedFile.Path.IsWithin(pathTable, filterPath)) { fileContents.Add(sealedFile); } } var sortedFileContents = SortedReadOnlyArray <FileArtifact, OrdinalFileArtifactComparer> .CloneAndSort(fileContents, OrdinalFileArtifactComparer.Instance); if (!context.GetPipConstructionHelper().TrySealDirectory( directoryRoot: filterPath, contents: sortedFileContents, outputDirectorycontents: CollectionUtilities.EmptySortedReadOnlyArray <DirectoryArtifact, OrdinalDirectoryArtifactComparer>(OrdinalDirectoryArtifactComparer.Instance), kind: SealDirectoryKind.Partial, tags: null, description: null, patterns: null, sealedDirectory: out var sealedDirectoryArtifact, scrub: false)) { // Error has been logged return(EvaluationResult.Error); } var result = new StaticDirectory(sealedDirectoryArtifact, SealDirectoryKind.Partial, sortedFileContents.WithCompatibleComparer(OrdinalPathOnlyFileArtifactComparer.Instance)); return(EvaluationResult.Create(result)); }
/// <summary> /// Implements relative path interpolation /// </summary> private static EvaluationResult Interpolate(Context context, ModuleLiteral env, EvaluationStackFrame args) { Args.CheckArgumentIndex(args, 1); var stringTable = context.FrontEndContext.StringTable; PathAtom pathAtom = Converter.ExpectPathAtomFromStringOrPathAtom(stringTable, args[0], new ConversionContext(pos: 1)); var rest = Args.AsArrayLiteral(args, 1); for (int i = 0; i < rest.Length; i++) { pathAtom = pathAtom.Concat( stringTable, Converter.ExpectPathAtomFromStringOrPathAtom( stringTable, rest[i], new ConversionContext(pos: i + 1, objectCtx: rest))); } return(EvaluationResult.Create(pathAtom)); }
private static EvaluationResult GetContent(Context context, StaticDirectory receiver, EvaluationStackFrame captures) { GetProvenance(context, out AbsolutePath path, out LineInfo lineInfo); // Can't use content directly, because there is no IS-A relationship between collection // of value types and collection of objects. So need to box everything any way. var content = receiver.Contents.SelectArray(x => EvaluationResult.Create(x)); return(EvaluationResult.Create(ArrayLiteral.CreateWithoutCopy(content, lineInfo, path))); }
private static EvaluationResult GetExtension(Context context, PathAtom receiver, EvaluationStackFrame captures) { var stringTable = context.FrontEndContext.StringTable; PathAtom result = receiver.GetExtension(stringTable); return(result.IsValid ? EvaluationResult.Create(result) : EvaluationResult.Undefined); }
private static EvaluationResult AssertFileExistence(Context context, StaticDirectory receiver, EvaluationResult arg, EvaluationStackFrame captures) { var path = GetPathFromArgument(context, receiver, arg); // This function is not exposed to non-opaque directories, so we could just assert here. But just in case (e.g. some casts can force things), // throw a handled exception if (!receiver.SealDirectoryKind.IsOpaqueOutput()) { throw new InvalidOutputAssertionUnderOpaqueDirectoryException(path.ToString(context.PathTable), new ErrorContext(objectCtx: arg.Value, pos: 0)); } if (!path.IsWithin(context.PathTable, receiver.Root.Path)) { // If the path is not within the directory, we already know it is not there throw new FileNotFoundInStaticDirectoryException(path.ToString(context.PathTable), new ErrorContext(objectCtx: arg.Value, pos: 0)); } if (!context.GetPipConstructionHelper().TryAssertOutputExistenceInOpaqueDirectory(receiver.Root, path, out FileArtifact fileArtifact)) { throw new InvalidOutputAssertionUnderOpaqueDirectoryException(path.ToString(context.PathTable), new ErrorContext(objectCtx: arg.Value, pos: 0)); } return(EvaluationResult.Create(fileArtifact)); }
private static EvaluationResult HasExtension(Context context, PathAtom receiver, EvaluationStackFrame captures) { var stringTable = context.FrontEndContext.StringTable; return(EvaluationResult.Create(receiver.GetExtension(stringTable).IsValid)); }
private static EvaluationResult ExpandPaths(Context context, ModuleLiteral env, EvaluationStackFrame args) { var str = Args.AsString(args, 0); var pathTable = context.FrontEndContext.PathTable; return(EvaluationResult.Create(s_expandPathsRegex.Replace( str, m => { var relPath = RelativePath.Create(context.FrontEndContext.StringTable, m.Groups[1].Value); var absPath = context.LastActiveUsedPath.GetParent(pathTable).Combine(pathTable, relPath); return absPath.ToString(pathTable); }))); }
private static EvaluationResult ChangeExtension(Context context, PathAtom receiver, EvaluationResult extension, EvaluationStackFrame captures) { var stringTable = context.FrontEndContext.StringTable; // An empty string is not a valid PathAtom, but in this case it indicates to remove the extension // this maps to passing an invalid path atom to PathAtom.ChangeExtension var atom = extension.Value as string == string.Empty ? PathAtom.Invalid : Converter.ExpectPathAtomFromStringOrPathAtom(stringTable, extension, new ConversionContext(pos: 1)); return(EvaluationResult.Create(atom.IsValid ? receiver.ChangeExtension(stringTable, atom) : receiver.RemoveExtension(stringTable))); }
private static EvaluationResult WriteLine(Context context, ModuleLiteral env, EvaluationStackFrame args) { return(WriteToConsoleImpl(context, args)); }
private static EvaluationResult Concat(Context context, PathAtom receiver, EvaluationResult fragment, EvaluationStackFrame captures) { var stringTable = context.FrontEndContext.StringTable; PathAtom atom = Converter.ExpectPathAtomFromStringOrPathAtom(stringTable, fragment, new ConversionContext(pos: 1)); return(EvaluationResult.Create(receiver.Concat(stringTable, atom))); }
private static EvaluationResult Add(Context context, OrderedSet receiver, EvaluationResult arg, EvaluationStackFrame captures) { var argArray = Converter.ExpectArrayLiteral(arg, new ConversionContext(pos: 1)); for (int i = 0; i < argArray.Length; ++i) { EvaluationResult elem = argArray[i]; if (elem.IsUndefined) { throw new UndefinedSetItemException(new ErrorContext(objectCtx: argArray, pos: i)); } } return(EvaluationResult.Create(receiver.AddRange(argArray.Values))); }
private static EvaluationResult GetFile(Context context, StaticDirectory receiver, EvaluationResult arg, EvaluationStackFrame captures) { var path = GetPathFromArgument(context, receiver, arg); if (receiver.TryGetFileArtifact(path, out FileArtifact file)) { return(EvaluationResult.Create(file)); } throw new FileNotFoundInStaticDirectoryException(path.ToString(context.PathTable), new ErrorContext(objectCtx: arg.Value, pos: 0)); }
private static EvaluationResult Contains(Context context, OrderedSet receiver, EvaluationResult arg, EvaluationStackFrame captures) { if (arg.IsUndefined) { throw new UndefinedSetItemException(new ErrorContext(pos: 1)); } return(EvaluationResult.Create(receiver.Contains(arg))); }
/// <inheritdoc /> public override EvaluationResult Apply(Context context, T receiver, EvaluationResult[] args, EvaluationStackFrame captures) { return(m_function(context, receiver, args, captures)); }