BadScript 2
Loading...
Searching...
No Matches
BadWhileExpressionCompiler.cs
Go to the documentation of this file.
1
using
BadScript2.Parser.Expressions.Block.Loop
;
2
using
BadScript2.Runtime.Objects
;
3
4
namespace
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.Block
;
5
9
public
class
BadWhileExpressionCompiler
:
BadExpressionCompiler
<BadWhileExpression>
10
{
12
public
override
void
Compile
(
BadExpressionCompileContext
context,
BadWhileExpression
expression)
13
{
14
int
start = context.
InstructionCount
;
15
context.
Compile
(expression.
Condition
);
16
int
endJump = context.
EmitEmpty
();
17
int
loopScopeStart = context.
InstructionCount
;
18
//Break And continue pointers are relative to the "CreateScope" instruction
19
//If break instruction is encountered
20
// Jump to loopScopeStart + offset to after loop(the destroy scope instruction is omitted because the vm handles the scopes)
21
context.
Emit
(
22
BadOpCode
.CreateScope,
23
expression.
Position
,
24
"WhileScope"
,
25
BadObject
.
Null
,
26
BadScopeFlags
.Breakable |
BadScopeFlags
.Continuable
27
);
28
int
setBreakInstruction = context.
EmitEmpty
();
29
int
setContinueInstruction = context.
EmitEmpty
();
30
context.
Compile
(expression.
Body
);
31
context.
Emit
(
BadOpCode
.DestroyScope, expression.
Position
);
32
//Jump back up to the loop condition
33
int
continueJump = context.
InstructionCount
;
34
context.
Emit
(
BadOpCode
.JumpRelative, expression.
Position
, start - context.
InstructionCount
- 1);
35
36
//Set the end jump to the end of the loop
37
context.
ResolveEmpty
(endJump,
BadOpCode
.JumpRelativeIfFalse, expression.
Position
, context.
InstructionCount
- endJump - 1);
38
//address to the end of the loop(relative to the create scope instruction)
39
context.
ResolveEmpty
(setBreakInstruction,
BadOpCode
.SetBreakPointer, expression.
Position
, context.
InstructionCount
- loopScopeStart - 1);
40
//Address to start of the condition(relative to the start of the loop)
41
context.
ResolveEmpty
(setContinueInstruction,
BadOpCode
.SetContinuePointer, expression.
Position
, continueJump - loopScopeStart - 1);
42
}
43
}
BadScript2.Parser.Expressions.BadExpression.Position
BadSourcePosition Position
The source Position of the Expression.
Definition
BadExpression.cs:165
BadScript2.Parser.Expressions.Block.Loop.BadWhileExpression
Implements the While Expression.
Definition
BadWhileExpression.cs:16
BadScript2.Parser.Expressions.Block.Loop.BadWhileExpression.Condition
BadExpression Condition
The Loop Condition.
Definition
BadWhileExpression.cs:45
BadScript2.Parser.Expressions.Block.Loop.BadWhileExpression.Body
IEnumerable< BadExpression > Body
The Loop Body.
Definition
BadWhileExpression.cs:40
BadScript2.Runtime.Objects.BadObject
The Base Class for all BadScript Objects.
Definition
BadObject.cs:14
BadScript2.Runtime.Objects.BadObject.Null
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition
BadObject.cs:28
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.BadExpressionCompiler
Compiles a BadScript Expression of type T.
Definition
BadExpressionCompiler.cs:11
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.Block.BadWhileExpressionCompiler
Compiles the BadWhileExpression.
Definition
BadWhileExpressionCompiler.cs:10
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.Block.BadWhileExpressionCompiler.Compile
override void Compile(BadExpressionCompileContext context, BadWhileExpression expression)
Definition
BadWhileExpressionCompiler.cs:12
BadScript2.Parser.Expressions.Block.Loop
Contains the Loop Expressions for the BadScript2 Language.
Definition
BadForEachExpression.cs:13
BadScript2.Runtime.Objects
Contains the Runtime Objects.
Definition
BadArray.cs:10
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.Block
Contains Block Expression Compilers.
Definition
BadForEachExpressionCompiler.cs:12
BadScript2.Runtime.VirtualMachine.BadOpCode
BadOpCode
Defines the Operations that the BadVirtualMachine can execute.
Definition
BadOpCode.cs:7
BadScript2.Runtime.BadScopeFlags
BadScopeFlags
Defines Different Behaviours for the Current Scope.
Definition
BadScopeFlags.cs:8
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.BadExpressionCompileContext
Definition
IBadExpressionCompiler.cs:7
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.BadExpressionCompileContext.ResolveEmpty
void ResolveEmpty(int index, BadOpCode code, BadSourcePosition position, params object[] args)
Definition
IBadExpressionCompiler.cs:43
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.BadExpressionCompileContext.Emit
void Emit(BadInstruction instruction)
Definition
IBadExpressionCompiler.cs:31
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.BadExpressionCompileContext.EmitEmpty
int EmitEmpty()
Definition
IBadExpressionCompiler.cs:35
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.BadExpressionCompileContext.Compile
void Compile(BadExpression expr)
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.BadExpressionCompileContext.InstructionCount
int InstructionCount
Definition
IBadExpressionCompiler.cs:12
src
BadScript2
Runtime
VirtualMachine
Compiler
ExpressionCompilers
Block
BadWhileExpressionCompiler.cs
Generated by
1.9.8