port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
using System.Diagnostics;
using System.Text;
using Intromat.Model;
using Intromat.Model.Compiler;
namespace Intromat.Nodes.Code
{
public class ForLoopValue : ExecutionValueBase
{
public IStatement? LoopBody { get; set; }
public ITypedExpression<int>? LowerBound { get; set; }
public ITypedExpression<int>? UpperBound { get; set; }
public InlineVariableDefinition<int> CurrentIndex { get; } = new();
public override void Compile(CompilerContext context, StringBuilder sb)
{
Debug.Assert(UpperBound != null, nameof(UpperBound) + " != null");
context.EnterNewScope("For loop");
CurrentIndex.Value = LowerBound;
sb.Append("for (");
CurrentIndex.Compile(context, sb);
sb.Append("; ");
sb.Append(CurrentIndex.VariableName);
sb.Append(" <= ");
UpperBound.Compile(context, sb);
sb.Append("; ++");
sb.Append(CurrentIndex.VariableName);
sb.Append(")\n{\n");
LoopBody?.Compile(context, sb);
sb.Append("\n}\n");
context.LeaveScope();
base.Compile(context, sb);
}
public override void CompileHeader(CompilerContext context, StringBuilder sb)
{
LoopBody?.CompileHeader(context, sb);
base.CompileHeader(context, sb);
}
}
}