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); }
public static BoundModule DoBinding(Root root, SymbolTable symbols, DiagnosticsReport diagnostics) { var pass = new Binder(diagnostics, symbols); pass.Run(root); return(pass.Module); }
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); } }
/* * 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); }
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); }
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)); }
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)); }
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"); } }
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}'")); } }
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); }
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"); } }
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(); }
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); }
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); }
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); } }
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(); }
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); ; }
/// <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); }
public override bool CompensateTechnicalFailures(DiagnosticsReport report, List <string> affectedComponents) { return(false); }
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)); }
public IType Indexing(IType index, SourceRange source, DiagnosticsReport diagnostics) => this;
public SyntaxErrorListener(DiagnosticsReport diagnostics) => this.diagnostics = diagnostics;
public SecondPass(DiagnosticsReport diagnostics, SymbolTable symbols) : base(diagnostics, symbols) { }
internal TechnicalFailuresNotification(DiagnosticsReport report) : base("TechnicalFailureNotification", roomScope) { AffectedComponents = report.GetAffectedComponents(); AffectedGames = report.GetAffectedGames(); }
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)); }
public IType UnaryOperation(UnaryOperator op, SourceRange source, DiagnosticsReport diagnostics) => this;
public (IType ReturnType, bool IsConstant) Invocation(IExpression[] args, SourceRange source, DiagnosticsReport diagnostics) => (this, false);
public void Produce(DiagnosticsReport diagnostics, IAssemblySource.ConsumeLineDelegate consumeLine) => Parse(diagnostics, consumeLine);
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); }
public IType FieldAccess(string fieldName, SourceRange source, DiagnosticsReport diagnostics) => this;