Пример #1
0
    public InteractiveContext(DyaOptions options)
    {
        Options      = options;
        BuildOptions = CreateBuildOptions(options);
        var nofn = options.FileNames is null || options.FileNames.Length == 0 || string.IsNullOrWhiteSpace(options.FileNames[0]);

        var lookup = FileLookup.Create(BuildOptions,
                                       nofn ? Environment.CurrentDirectory ! : Path.GetDirectoryName(options.FileNames ![0]) !, options.Paths);
Пример #2
0
        public InteractiveContext(DyaOptions options)
        {
            Options      = options;
            BuildOptions = CreateBuildOptions(options);

            var lookup = FileLookup.Create(
                options.FileNames == null || options.FileNames.Length == 0 || string.IsNullOrWhiteSpace(options.FileNames[0])
                    ? Environment.CurrentDirectory
                    : Path.GetDirectoryName(options.FileNames[0]), options.Paths);

            Linker = new DyIncrementalLinker(lookup, BuildOptions, options.UserArguments);
        }
Пример #3
0
        public override uint GetOrCreateFileId(string filename)
        {
            // check the filename exists
            if (!FileLookup.TryGetValue(filename, out var id))
            {
                id = unchecked ((uint)--CurrentId);
                FileLookup.Add(filename, id);
                return(id);
            }

            return(id);
        }
Пример #4
0
        public override uint GetOrCreateFileId(string filename)
        {
            // check the filename exists
            if (!FileLookup.TryGetValue(filename, out var id))
            {
                // attempt to take an id from the pool
                if (_unusedIds.Count > 0)
                {
                    id = _unusedIds.Dequeue();
                    FileLookup.Add(filename, id);
                    return(id);
                }

                // TODO verify the best way of handling this
                throw new Exception("Out of unused Ids - SEND HELP!");
            }

            return(id);
        }
Пример #5
0
        private static IList <FunSet> Compile(IEnumerable <string> files, BuilderOptions buildOptions, out List <BuildMessage> warns)
        {
            var funColl = new List <FunSet>();

            warns = new List <BuildMessage>();

            foreach (var file in files)
            {
                var linker = new DyLinker(FileLookup.Create(Path.GetDirectoryName(file)), buildOptions);
                var cres   = linker.Make(SourceBuffer.FromFile(file));
                var funs   = new FunSet();
                funs.Funs     = new Dictionary <string, DyFunction>(StringComparer.OrdinalIgnoreCase);
                funs.FileName = file;

                if (!cres.Success)
                {
                    throw new DyBuildException(cres.Messages);
                }

                warns.AddRange(cres.Messages.Where(m => m.Type == BuildMessageType.Warning));
                var ctx = DyMachine.CreateExecutionContext(cres.Value);
                funs.Context = ctx;
                DyMachine.Execute(ctx);

                foreach (var v in DyMachine.DumpVariables(ctx))
                {
                    if (v.Value is DyFunction fn)
                    {
                        funs.Funs.Remove(v.Name);
                        funs.Funs.Add(v.Name, fn);
                    }
                }

                funColl.Add(funs);
            }

            return(funColl);
        }
Пример #6
0
    public static DyObject?Eval(SourceBuffer buffer, BuilderOptions options, FileLookup lookup, object?args = null)
    {
        DyTuple?tup = null;

        if (args is not null)
        {
            var arr = args.GetType().GetProperties().Select(pi =>
                                                            new DyLabel(pi.Name, TypeConverter.ConvertFrom(pi.GetValue(args)))).ToArray();
            tup = new DyTuple(arr);
        }

        var linker = new DyLinker(lookup ?? FileLookup.Default, options ?? BuilderOptions.Default(), tup);
        var result = linker.Make(buffer);

        if (!result.Success)
        {
            throw new DyBuildException(result.Messages);
        }

        var ctx     = DyMachine.CreateExecutionContext(result.Value !);
        var result2 = DyMachine.Execute(ctx);

        return(result2.Value);
    }
Пример #7
0
 private void fileButton_Click(object sender, RoutedEventArgs e)
 {
     var drv = timeSheetDataGrid.SelectedItem as DataRowView;
     var diary = drv.Row as dsTimeSheetDataSet.ttFileDiaryRow;
     var lookup = new FileLookup(this);
     var ttFile = timeSheetDataSet.ttFile;
     lookup.setFilesList(ttFile);
     lookup.ShowDialog();
     var file = lookup.SelectedFile;
     if (file == null || file.FileID == diary.FileID)
     return;
     copyRowToFileTable(file);
     copyRowToFileDropTable(file);
     diary.FileID = file.FileID;
     calcExtraColumns(diary);
 }
Пример #8
0
 public DyIncrementalLinker(FileLookup lookup, BuilderOptions options, DyTuple?args) : base(lookup, options, args)
 {
 }