Пример #1
0
        protected override bool Initialize0(GameDifficulty difficulty, DiagnosticsReport diagnosticsReport)
        {
            // difficulty is ignored for this game -> set to default
            Difficulty = GameDifficulty.Medium;

            // to set the logical valve states in the initialization of the subsystems we need up-to-date physical data
            Physical.ForcePipesUpdate();

            RunningFansCount = 0;
            foreach (PipeSystem pipes in systems)
            {
                // reset valves
                pipes.Initialize(Physical);
                RunningFansCount += pipes.RunningFansCount;

                // reset fans
                foreach (Fan f in pipes.Fans())
                {
                    //bool oldState = physical.GetFanState(f.row, f.position);
                    Physical.SetFanState(f.Row, f.PositionInRow, f.IsRunning);
                }
            }

            return(true);
        }
Пример #2
0
        public static BoundModule DoBinding(Root root, SymbolTable symbols, DiagnosticsReport diagnostics)
        {
            var pass = new Binder(diagnostics, symbols);

            pass.Run(root);
            return(pass.Module);
        }
Пример #3
0
        IEnumerable <IBatchProcessor> _GetProcessors()
        {
            var htmlReporter = HtmlReport.ConstructFor(StoryCache.Stories);

            if (htmlReporter != null)
            {
                yield return(htmlReporter);
            }

            var htmlMetroReporter = HtmlMetroReport.ConstructFor(StoryCache.Stories);

            if (htmlMetroReporter != null)
            {
                yield return(htmlMetroReporter);
            }

            var markDown = MarkDownReport.ConstructFor(StoryCache.Stories);

            if (markDown != null)
            {
                yield return(markDown);
            }

            var diagnostics = DiagnosticsReport.ConstructFor(StoryCache.Stories);

            if (diagnostics != null)
            {
                yield return(diagnostics);
            }

            foreach (var addedProcessor in _addedProcessors)
            {
                yield return(addedProcessor);
            }
        }
Пример #4
0
        /*
         * public IFanInfo GetFanInfo(int i) {
         *  foreach (PipeSystem ps in systems) {
         *      if (i < ps.fans.Count)
         *          return ps.fans[i];
         *      i -= ps.fans.Count;
         *  }
         *  throw new ArgumentException(i.ToString() + " " + FanCount);
         * }
         *
         * public IValveInfo GetValveInfo(int i) {
         *  foreach (PipeSystem ps in systems) {
         *      if (i < ps.valves.Count)
         *          return ps.valves[i];
         *      i -= ps.valves.Count;
         *  }
         *  throw new ArgumentException(i.ToString() + " " + ValveCount);
         * }
         */

        public override bool CompensateTechnicalFailures(DiagnosticsReport report, List <string> affectedComponents)
        {
            //if (affectedComponents.Count == 1 && affectedComponents[0] == "valves")
            //    return true;

            return(false);
        }
Пример #5
0
        protected override bool Initialize0(GameDifficulty difficulty, DiagnosticsReport diagnosticsReport)
        {
            // query hole states from physical interface
            int[] currentHoleStates = new int[HoleCount];
            for (int i = 0; i < HoleCount; i++)
            {
                currentHoleStates[i] = Physical.GetHoleState(i);
            }

            scenario = DynamiteScenario.ChooseScenario(difficulty, wall, currentHoleStates);
            Log.Info("Dynamite scenario '{0}' selected.", scenario.Name);
            lastInstructionsSolvedState = new bool[scenario.InstructionCount];

            for (int i = 0; i < lastHoleStates.Length; i++)
            {
                lastHoleStates[i] = -1;
            }

            for (int i = 0; i < TriggersGame.ButtonCount; i++)
            {
                Physical.SetLEDColor(i, Color.black);
            }

            return(true);
        }
Пример #6
0
        public override IType UnaryOperation(UnaryOperator op, SourceRange source, DiagnosticsReport diagnostics)
        {
            if (op is UnaryOperator.LogicalNot)
            {
                return(new BoolType(source));
            }

            return(base.UnaryOperation(op, source, diagnostics));
        }
Пример #7
0
        public override IType UnaryOperation(UnaryOperator op, SourceRange source, DiagnosticsReport diagnostics)
        {
            if (op is UnaryOperator.Negate)
            {
                return(new FloatType(source));
            }

            return(base.UnaryOperation(op, source, diagnostics));
        }
Пример #8
0
        public void RunDiagnostics(DiagnosticsReport result)
        {
            int brokenValves = 0;

            foreach (bool[] row in state.pipes.valves_broken)
            {
                brokenValves += row.Count(true);
            }
            if (brokenValves > 0)
            {
                result.AddAffectedGameComponent(pipes, "valves");
            }
        }
Пример #9
0
 public override IType FieldAccess(string fieldName, SourceRange source, DiagnosticsReport diagnostics)
 {
     if (Parser.CaseInsensitiveComparer.Equals(fieldName, "x") ||
         Parser.CaseInsensitiveComparer.Equals(fieldName, "y") ||
         Parser.CaseInsensitiveComparer.Equals(fieldName, "z"))
     {
         return(new FloatType(source));
     }
     else
     {
         return(new ErrorType(source, diagnostics, $"Unknown field '{fieldName}'"));
     }
 }
Пример #10
0
        private static DiagnosticsReport ParseAndIdentify(string source, NativeDB?nativeDB = null)
        {
            using var sourceReader = new StringReader($@"
                {source}");
            var d = new DiagnosticsReport();
            var p = new Parser(sourceReader, "test.sc");

            p.Parse(d);

            var globalSymbols = GlobalSymbolTableBuilder.Build(p.OutputAst, d);

            IdentificationVisitor.Visit(p.OutputAst, d, globalSymbols, nativeDB ?? NativeDB.Empty);
            return(d);
        }
Пример #11
0
 public void RunDiagnostics(DiagnosticsReport report)
 {
     if (simulateTechnicalFailures)
     {
         report.AddAffectedRoomComponent("everything", true);
         report.AddAffectedGameComponent(Ets.Room.GetGame <PipesGame>(), "valves");
         report.AddAffectedGameComponent(Ets.Room.GetGame <CratesGame>(), "buttons");
         report.AddAffectedGameComponent(Ets.Room.GetGame <CratesGame>(), "screens");
         report.AddAffectedGameComponent(Ets.Room.GetGame <DynamiteGame>(), "hole_0_1");
         report.AddAffectedGameComponent(Ets.Room.GetGame <DynamiteGame>(), "hole_2_1");
         report.AddAffectedGameComponent(Ets.Room.GetGame <TriggersGame>(), "trigger_0");
         report.AddAffectedGameComponent(Ets.Room.GetGame <TriggersGame>(), "trigger_4");
     }
 }
Пример #12
0
 public CodeGenerator(TextWriter sink, Program program, GlobalSymbolTable symbols, DiagnosticsReport diagnostics, NativeDB nativeDB)
 {
     Sink             = sink;
     Program          = program;
     Symbols          = symbols;
     Diagnostics      = diagnostics;
     NativeDB         = nativeDB;
     Strings          = new();
     stmtEmitter      = new(this);
     valueEmitter     = new(this);
     addressEmitter   = new(this);
     optimizer        = new();
     funcInstructions = new();
 }
Пример #13
0
            static int P(string s)
            {
                var d = new DiagnosticsReport();

                using var r = new StringReader(@$ "
                    SCRIPT_HASH {s}
                    SCRIPT test
                    ENDSCRIPT
                ");
                var parser = new Parser(r, "test.sc");

                parser.Parse(d);
                Assert.False(d.HasErrors || d.HasWarnings);
                return(parser.OutputAst.ScriptHash);
            }
Пример #14
0
        private static DiagnosticsReport TypeCheck(string source)
        {
            using var sourceReader = new StringReader(source);
            var d = new DiagnosticsReport();
            var p = new Parser(sourceReader, "test.sc");

            p.Parse(d);

            var globalSymbols = GlobalSymbolTableBuilder.Build(p.OutputAst, d);

            IdentificationVisitor.Visit(p.OutputAst, d, globalSymbols, NativeDB.Empty);
            TypeChecker.Check(p.OutputAst, d, globalSymbols);

            return(d);
        }
Пример #15
0
        public async Task RenderHighpassEffectGroupAndAmplifyEdges()
        {
            using (var source = KnownImages.MikikoLynn.ImageSource)
                using (var highpassEffect = new HighpassEffectGroup(14, true, 2)
                {
                    Source = source
                })
                    using (var sourceWithAmplifiedEdges = new BlendEffect(source, highpassEffect, BlendFunction.Hardlight, 0.4))
                        using (var renderer = new JpegRenderer(sourceWithAmplifiedEdges))
                        {
                            DiagnosticsReport.BeginProbe(sourceWithAmplifiedEdges);

                            var buffer = await renderer.RenderAsync();

                            // This should hit the inline blending (fast) path, make sure it did.
                            var blendEffectReport = await DiagnosticsReport.EndProbeAsync(sourceWithAmplifiedEdges);

                            Assert.AreEqual(1, (int)blendEffectReport.Properties["inlineblend_count"]);

                            ImageResults.Instance.SaveToPicturesLibrary(buffer);
                        }
        }
Пример #16
0
        private void Parse(DiagnosticsReport diagnostics, IAssemblySource.ConsumeLineDelegate consumeLine)
        {
            var inputStream = new LightInputStream(Input.ReadToEnd());

            var lexer = new ScAsmLexer(inputStream)
            {
                TokenFactory = new LightTokenFactory()
            };

            lexer.RemoveErrorListeners();
            lexer.AddErrorListener(new SyntaxErrorListener <int>(diagnostics));
            var tokens = new CommonTokenStream(lexer);
            var parser = new ScAsmParser(tokens)
            {
                BuildParseTree = false
            };

            parser.AddParseListener(new ParseListener(this, parser, consumeLine));
            parser.RemoveErrorListeners();
            parser.AddErrorListener(new SyntaxErrorListener <IToken>(diagnostics));

            parser.program();
        }
Пример #17
0
        private static void Parse(string filePath, NativeDB nativeDB)
        {
            using var r = new StreamReader(filePath);
            var d  = new DiagnosticsReport();
            var sw = Stopwatch.StartNew();
            var p  = new Parser(r, filePath)
            {
                UsingResolver = new FileUsingResolver()
            };

            p.Parse(d);
            sw.Stop();
            Console.WriteLine(sw.Elapsed);
            //d.PrintAll(Console.Out);

            var globalSymbols = GlobalSymbolTableBuilder.Build(p.OutputAst, d);

            IdentificationVisitor.Visit(p.OutputAst, d, globalSymbols, nativeDB);
            TypeChecker.Check(p.OutputAst, d, globalSymbols);
            //d.PrintAll(Console.Out);
            ;

            if (!d.HasErrors)
            {
                Console.WriteLine("CodeGen...");
                using var sink = new StringWriter();
                new CodeGenerator(sink, p.OutputAst, globalSymbols, d, nativeDB).Generate();
                var s = sink.ToString();
                ;
                using var reader = new StringReader(s);
                var assembler = Assembler.Assemble(reader, Path.ChangeExtension(filePath, "scasm"), nativeDB, options: new() { IncludeFunctionNames = true });
                assembler.Diagnostics.PrintAll(Console.Out);
                ;
            }
            d.PrintAll(Console.Out);
            ;
        }
Пример #18
0
        /// <summary>
        /// See <see cref="Game.Initialize0(GameDifficulty)"/>
        /// </summary>
        protected override bool Initialize0(GameDifficulty difficulty, DiagnosticsReport diagnosticsReport)
        {
            // set up game configuration for specified difficulty
            switch (difficulty)
            {
            case GameDifficulty.Medium:
                scenario = TriggersGameScenario.CreateDefault();
                break;

            case GameDifficulty.Easy:
                scenario = TriggersGameScenario.CreateEasy();
                break;

            case GameDifficulty.Hard:
                scenario = TriggersGameScenario.CreateHard();
                break;

            default:
                throw new NotImplementedException(difficulty.ToString());
            }

            Log.Verbose("Created trigger game with solution " + scenario);
            return(true);
        }
Пример #19
0
 public override bool CompensateTechnicalFailures(DiagnosticsReport report, List <string> affectedComponents)
 {
     return(false);
 }
Пример #20
0
        public override IType BinaryOperation(BinaryOperator op, IType rhs, SourceRange source, DiagnosticsReport diagnostics)
        {
            if (rhs is FloatType)
            {
                IType?ty = op switch
                {
                    BinaryOperator.Add or BinaryOperator.Subtract or
                    BinaryOperator.Multiply or BinaryOperator.Divide or BinaryOperator.Modulo
                    => new FloatType(source),

                    BinaryOperator.Equals or BinaryOperator.NotEquals or
                    BinaryOperator.LessThan or BinaryOperator.LessThanOrEqual or
                    BinaryOperator.GreaterThan or BinaryOperator.GreaterThanOrEqual
                    => new BoolType(source),
                    _ => null,
                };

                if (ty is not null)
                {
                    return(ty);
                }
            }

            return(base.BinaryOperation(op, rhs, source, diagnostics));
        }
Пример #21
0
 public IType Indexing(IType index, SourceRange source, DiagnosticsReport diagnostics) => this;
Пример #22
0
 public SyntaxErrorListener(DiagnosticsReport diagnostics) => this.diagnostics = diagnostics;
 public SecondPass(DiagnosticsReport diagnostics, SymbolTable symbols)
     : base(diagnostics, symbols)
 {
 }
Пример #24
0
 internal TechnicalFailuresNotification(DiagnosticsReport report) : base("TechnicalFailureNotification", roomScope)
 {
     AffectedComponents = report.GetAffectedComponents();
     AffectedGames      = report.GetAffectedGames();
 }
Пример #25
0
        public override IType BinaryOperation(BinaryOperator op, IType rhs, SourceRange source, DiagnosticsReport diagnostics)
        {
            if (rhs is BoolType)
            {
                IType?ty = op switch
                {
                    BinaryOperator.LogicalAnd or BinaryOperator.LogicalOr
                    => new BoolType(source),
                    _ => null,
                };

                if (ty is not null)
                {
                    return(ty);
                }
            }

            return(base.BinaryOperation(op, rhs, source, diagnostics));
        }
Пример #26
0
 public IType UnaryOperation(UnaryOperator op, SourceRange source, DiagnosticsReport diagnostics) => this;
Пример #27
0
 public (IType ReturnType, bool IsConstant) Invocation(IExpression[] args, SourceRange source, DiagnosticsReport diagnostics) => (this, false);
Пример #28
0
 public void Produce(DiagnosticsReport diagnostics, IAssemblySource.ConsumeLineDelegate consumeLine)
 => Parse(diagnostics, consumeLine);
Пример #29
0
            public override (IType ReturnType, bool IsConstant) Invocation(IExpression[] args, SourceRange source, DiagnosticsReport diagnostics)
            {
                if (args.Length != 2)
                {
                    var err = new ErrorType(source, diagnostics, $"Expected 2 arguments, found {args.Length}");
                    if (args.Length < 1)
                    {
                        return(err, false);
                    }
                }

                IType returnType;
                var   arg1 = args[0];

                if (arg1.Type is TypeNameType typeName)
                {
                    if (typeName.TypeDeclaration is EnumDeclaration enumDecl)
                    {
                        returnType = enumDecl.CreateType(source);
                    }
                    else
                    {
                        returnType = new ErrorType(arg1.Source, diagnostics, $"Argument 1: cannot pass non-enum type '{typeName.TypeDeclaration.Name}' to INT_TO_ENUM first parameter");
                    }
                }
                else if (arg1.Type is ErrorType)
                {
                    returnType = arg1.Type;
                }
                else
                {
                    returnType = new ErrorType(arg1.Source, diagnostics, $"Argument 1: cannot pass '{arg1.Type}' to INT_TO_ENUM first parameter, expected enum type name");
                }

                var isConstant = false;

                if (args.Length >= 2)
                {
                    var arg2 = args[1];
                    isConstant = arg2.IsConstant;
                    var param2Ty = new IntType(arg2.Source);
                    if (!param2Ty.CanAssign(arg2.Type !, arg2.IsLValue))
                    {
                        diagnostics.AddError($"Argument  2: cannot pass '{arg2.Type}' as second parameter '{TypePrinter.ToString(param2Ty, "value", false)}'", arg2.Source);
                    }
                }

                return(returnType, isConstant);
            }
Пример #30
0
 public IType FieldAccess(string fieldName, SourceRange source, DiagnosticsReport diagnostics) => this;