public void Compile(ByteCodeGenerator generator) { var item = new ConditionCompiler(node.Condition).Compile(generator); var elseChain = item.JumpFalse(); Chain thenExit = null; if (!item.IsFalse()) { generator.ResolveChain(item.TrueJumps); generator.PushScope(); new StatementCompiler(node.TrueBranch).Compile(generator); thenExit = generator.Branch(OpCodeValue.@goto); generator.PopScope(); } if (elseChain != null) { generator.ResolveChain(elseChain); if (node.FalseBranch != null) { generator.PushScope(); new StatementCompiler(node.FalseBranch).Compile(generator); generator.PopScope(); } } generator.ResolveChain(thenExit); }
public void Compile(ByteCodeGenerator generator) { var start = generator.EntryPoint(); // Test Condition var item = new ConditionCompiler(node.Expression).Compile(generator); var loopDone = item.JumpFalse(); generator.ResolveChain(item.TrueJumps); // Run Body generator.PushScope(); new StatementCompiler(node.Statement).Compile(generator); generator.ResolveChain(generator.Branch(OpCodeValue.@goto), start); generator.PopScope(); // End generator.ResolveChain(loopDone); }
public void Compile(ByteCodeGenerator generator) { generator.PushScope(); var start = generator.CurrentPC(); new StatementCompiler(node.Initialiser).Compile(generator); var item = new ConditionCompiler(node.Condition).Compile(generator); var loopDone = item.JumpFalse(); generator.ResolveChain(item.TrueJumps); new StatementCompiler(node.Body).Compile(generator); new StatementCompiler(node.Updater).Compile(generator); generator.ResolveChain(generator.Branch(OpCodeValue.@goto), start); generator.PopScope(); generator.ResolveChain(loopDone); }