BadScript 2
Loading...
Searching...
No Matches
BadForExpressionCompiler.cs
Go to the documentation of this file.
3
5
9public class BadForExpressionCompiler : BadExpressionCompiler<BadForExpression>
10{
12 public override void Compile(BadExpressionCompileContext context, BadForExpression expression)
13 {
14 context.Emit(BadOpCode.CreateScope, expression.Position, "ForLoop", BadObject.Null);
15 context.Compile(expression.VarDef);
16 int conditionJump = context.InstructionCount;
17 context.Compile(expression.Condition);
18 int endJump = context.EmitEmpty();
19 int loopScopeStart = context.InstructionCount;
20 context.Emit(
21 BadOpCode.CreateScope,
22 expression.Position,
23 "ForLoopBody",
25 BadScopeFlags.Breakable | BadScopeFlags.Continuable
26 );
27 int setBreakInstruction = context.EmitEmpty();
28 int setContinueInstruction = context.EmitEmpty();
29 context.Compile(expression.Body);
30 context.Emit(BadOpCode.DestroyScope, expression.Position);
31 int continueJump = context.InstructionCount;
32 context.Compile(expression.VarIncrement);
33 context.Emit(BadOpCode.JumpRelative, expression.Position, conditionJump - context.InstructionCount - 1);
34 int endJumpPos = context.InstructionCount - endJump - 1;
35 context.ResolveEmpty(endJump, BadOpCode.JumpRelativeIfFalse, expression.Position, endJumpPos);
36 context.Emit(BadOpCode.DestroyScope, expression.Position);
37 context.ResolveEmpty(setBreakInstruction, BadOpCode.SetBreakPointer, expression.Position, context.InstructionCount - loopScopeStart);
38 context.ResolveEmpty(setContinueInstruction, BadOpCode.SetContinuePointer, expression.Position, continueJump - loopScopeStart - 1);
39 }
40}
BadSourcePosition Position
The source Position of the Expression.
BadExpression VarDef
The Variable Definition part of the for loop.
BadExpression Condition
The Exit Condition of the For Loop.
BadExpression VarIncrement
The Variable Modifier Expression of the For Loop.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
override void Compile(BadExpressionCompileContext context, BadForExpression expression)
Contains the Loop Expressions for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
BadOpCode
Defines the Operations that the BadVirtualMachine can execute.
Definition BadOpCode.cs:7
BadScopeFlags
Defines Different Behaviours for the Current Scope.
void ResolveEmpty(int index, BadOpCode code, BadSourcePosition position, params object[] args)