BadScript 2
Loading...
Searching...
No Matches
BadTryCatchExpressionCompiler.cs
Go to the documentation of this file.
1
using
BadScript2.Parser.Expressions.Block
;
2
using
BadScript2.Runtime.Objects
;
3
4
namespace
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.Block
;
5
9
public
class
BadTryCatchExpressionCompiler
:
BadExpressionCompiler
<BadTryCatchExpression>
10
{
12
public
override
void
Compile
(
BadExpressionCompileContext
context,
BadTryCatchExpression
expression)
13
{
14
context.
Emit
(
BadOpCode
.CreateScope, expression.
Position
,
"TryScope"
,
BadObject
.
Null
,
BadScopeFlags
.CaptureThrow);
15
int
setThrowInstruction = context.
EmitEmpty
();
16
context.
Compile
(expression.
TryExpressions
);
17
context.
Emit
(
BadOpCode
.DestroyScope, expression.
Position
);
18
int
jumpToEnd = context.
EmitEmpty
();
19
int
catchStart = context.
InstructionCount
;
20
if
(expression.
CatchExpressions
.Any())
// If there are catch expressions, compile them
21
{
22
context.
Emit
(
BadOpCode
.CreateScope, expression.
Position
,
"CatchScope"
,
BadObject
.
Null
);
23
context.
Emit
(
BadOpCode
.DefVar, expression.
Position
, expression.
ErrorName
,
true
);
24
context.
Emit
(
BadOpCode
.Swap, expression.
Position
);
25
context.
Emit
(
BadOpCode
.Assign, expression.
Position
);
26
context.
Compile
(expression.
CatchExpressions
);
27
context.
Emit
(
BadOpCode
.DestroyScope, expression.
Position
);
28
}
29
else
30
{
31
// If there are no catch expressions, we need to clean up the exception from the stack
32
context.
Emit
(
BadOpCode
.Pop, expression.
Position
);
33
}
34
context.
ResolveEmpty
(setThrowInstruction,
BadOpCode
.SetThrowPointer, expression.
Position
, catchStart - 1);
35
context.
ResolveEmpty
(jumpToEnd,
BadOpCode
.JumpRelative, expression.
Position
, context.
InstructionCount
- catchStart);
36
if
(expression.
FinallyExpressions
.Any())
// If there are finally expressions, compile them
37
{
38
context.
Emit
(
BadOpCode
.CreateScope, expression.
Position
,
"FinallyScope"
,
BadObject
.
Null
);
39
context.
Compile
(expression.
FinallyExpressions
);
40
context.
Emit
(
BadOpCode
.DestroyScope, expression.
Position
);
41
}
42
43
}
44
}
BadScript2.Parser.Expressions.BadExpression.Position
BadSourcePosition Position
The source Position of the Expression.
Definition
BadExpression.cs:165
BadScript2.Parser.Expressions.Block.BadTryCatchExpression
Implements the Try Catch Statement Expression.
Definition
BadTryCatchExpression.cs:13
BadScript2.Parser.Expressions.Block.BadTryCatchExpression.CatchExpressions
IEnumerable< BadExpression > CatchExpressions
The Catch Block.
Definition
BadTryCatchExpression.cs:57
BadScript2.Parser.Expressions.Block.BadTryCatchExpression.TryExpressions
IEnumerable< BadExpression > TryExpressions
The Try Block.
Definition
BadTryCatchExpression.cs:62
BadScript2.Parser.Expressions.Block.BadTryCatchExpression.ErrorName
readonly string ErrorName
The Variable name of the Exception inside the catch block.
Definition
BadTryCatchExpression.cs:17
BadScript2.Parser.Expressions.Block.BadTryCatchExpression.FinallyExpressions
IEnumerable< BadExpression > FinallyExpressions
The Finally Block.
Definition
BadTryCatchExpression.cs:67
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.BadTryCatchExpressionCompiler
Compiles the BadTryCatchExpression.
Definition
BadTryCatchExpressionCompiler.cs:10
BadScript2.Runtime.VirtualMachine.Compiler.ExpressionCompilers.Block.BadTryCatchExpressionCompiler.Compile
override void Compile(BadExpressionCompileContext context, BadTryCatchExpression expression)
Definition
BadTryCatchExpressionCompiler.cs:12
BadScript2.Parser.Expressions.Block
Contains the Block Expressions for the BadScript2 Language.
Definition
BadIfExpression.cs:11
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
BadTryCatchExpressionCompiler.cs
Generated by
1.9.8