Example #1
0
            public void FormatMethod(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                String methodName = GetMethodName(formatterContext);

                sw.AppendLine($"public void {methodName}()");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    FormatMethodBody(sw, formatterContext, executionContext);

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append("else if(");
     ((JPF)_list[0]).Format(sw, formatterContext, services);
     sw.AppendLine(")");
     FormatBranch(sw, formatterContext, services, GetBodyInstructions());
 }
Example #3
0
        public static void FormatGlobalSet <T>(GlobalVariableId <T> globalVariable, IJsmExpression value, Int32[] knownVariables, ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext) where T : unmanaged
        {
            sw.Append("G");

            if (knownVariables == null || Array.BinarySearch(knownVariables, globalVariable.VariableId) < 0)
            {
                sw.Append("[");
                sw.Append(globalVariable.VariableId.ToString(CultureInfo.InvariantCulture));
                sw.Append("]");
                sw.Append(" = ");
                sw.Append("(");
                sw.Append(GlobalVariableId <T> .TypeName);
                sw.Append(")");
            }
            else
            {
                sw.Append(GlobalVariableId <T> .TypeName);
                sw.Append("[");
                sw.Append(globalVariable.VariableId.ToString(CultureInfo.InvariantCulture));
                sw.Append("]");
                sw.Append(" = ");
            }

            value.Format(sw, formatterContext, executionContext);
            sw.AppendLine(";");
        }
Example #4
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append($"R{_index.ResultId}");
     sw.Append(" = ");
     _value.Format(sw, formatterContext, services);
     sw.AppendLine(";");
 }
Example #5
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append("while(");
     ((JPF)_list[0]).Format(sw, formatterContext, services);
     sw.AppendLine(")");
     FormatBranch(sw, formatterContext, services, _list.Skip(1));
 }
Example #6
0
            protected void FormatBranch(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext, IEnumerable <IJsmInstruction> items)
            {
                sw.AppendLine("{");
                sw.Indent++;

                var state = sw.RememberState();

                FormatItems(sw, formatterContext, executionContext, items);
                if (!state.IsChanged)
                {
                    sw.AppendLine("// do nothing");
                }

                sw.Indent--;
                sw.AppendLine("}");
            }
Example #7
0
        public static void FormatMonologue(ScriptWriter sw, String message)
        {
            if (!sw.HasWhiteLine)
            {
                sw.AppendLine();
            }

            foreach (String str in SplitMonologue(message))
            {
                if (String.IsNullOrEmpty(str))
                {
                    continue;
                }

                sw.Append("// ");
                sw.AppendLine(str);
            }
        }
Example #8
0
                    public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
                    {
                        sw.Append("if(");
                        Jpf.Format(sw, formatterContext, services);
                        sw.AppendLine(")");
                        FormatBranch(sw, formatterContext, services, GetBodyInstructions());

                        foreach (var item in _aggregator.EnumerateElseBlocks())
                        {
                            item.Format(sw, formatterContext, services);
                        }
                    }
Example #9
0
 private static void FormatItems(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext, IEnumerable <IJsmInstruction> items)
 {
     foreach (var item in items)
     {
         if (item is IFormattableScript formattable)
         {
             formattable.Format(sw, formatterContext, executionContext);
         }
         else
         {
             sw.AppendLine(item.ToString());
         }
     }
 }
Example #10
0
            public void FormatType(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                formatterContext.GetObjectScriptNamesById(Id, out String typeName, out _);
                sw.AppendLine($"public sealed class {typeName}");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    if (Scripts.Count > 0)
                    {
                        FormatConstructor(typeName, sw, formatterContext, executionContext);

                        foreach (var script in Scripts.Skip(1))
                        {
                            sw.AppendLine();
                            script.FormatMethod(sw, formatterContext, executionContext);
                        }
                    }

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
Example #11
0
            private void FormatConstructor(String typeName, ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                sw.AppendLine($"private readonly {nameof(IServices)} _ctx;");
                sw.AppendLine();

                sw.AppendLine($"public {typeName}({nameof(IServices)} executionContext)");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    sw.AppendLine("_ctx = executionContext;");
                    Scripts[0].FormatMethodBody(sw, formatterContext, executionContext);

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
Example #12
0
 public virtual void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine(this.ToString());
 }
Example #13
0
 public void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"goto LABEL{_label};");
 }
Example #14
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"return {nameof(IRET)}({Unknown});");
 }
Example #15
0
        public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
        {
            formatterContext.GetObjectScriptNamesById(_scriptId, out String typeName, out String methodName);

            sw.AppendLine($"{nameof(REQEW)}(priority: {_priority}, GetObject<{typeName}>().{methodName}());");
        }
Example #16
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"R{ResultVariable.ResultId} = {nameof(Rnd)}.{nameof(Rnd.NextByte)}();");
 }
Example #17
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"// ScriptId: {Label}");
 }
Example #18
0
        public static void FormatAnswers(ScriptWriter sw, String message, IJsmExpression top, IJsmExpression bottom, IJsmExpression begin, IJsmExpression cancel)
        {
            if (!(top is IConstExpression t) || !(bottom is IConstExpression b))
            {
                FormatMonologue(sw, message);
                return;
            }

            if (!sw.HasWhiteLine)
            {
                sw.AppendLine();
            }

            // Question
            //☞ Answer 1
            //   Answer 2
            //   Answer 3
            //☜ Answer 4

            Int32 to = t.Int32();
            Int32 bo = b.Int32();
            Int32 be = -1;
            Int32 ca = -1;

            if (begin is IConstExpression beg)
            {
                be = beg.Int32();
            }

            if (cancel is IConstExpression can)
            {
                ca = can.Int32();
            }

            String[] lines = SplitMonologue(message);

            for (Int32 i = 0; i < lines.Length; i++)
            {
                sw.Append("//");
                if (i >= to && i <= bo)
                {
                    if (i == be)
                    {
                        sw.Append("☞ ");
                    }
                    else if (i == ca)
                    {
                        sw.Append("☜ ");
                    }
                    else
                    {
                        sw.Append("   ");
                    }
                }
                else
                {
                    sw.Append(" ");
                }

                sw.AppendLine(lines[i]);
            }
        }
Example #19
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine("else");
     FormatBranch(sw, formatterContext, services, GetBodyInstructions());
 }