BadScript 2
Loading...
Searching...
No Matches
IBadExpressionCompiler.cs
Go to the documentation of this file.
3
5
6public readonly struct BadExpressionCompileContext
7{
8 public BadCompiler Compiler { get; }
9
10 private readonly List<BadInstruction> m_Instructions = new List<BadInstruction>();
11
12 public int InstructionCount => m_Instructions.Count;
13
14 private readonly List<int> m_EmptyInstructions = new List<int>();
15
17 {
18 if (m_EmptyInstructions.Count > 0)
19 {
20 throw new BadCompilerException("Unresolved Empty Instructions!");
21 }
22
23 return m_Instructions.ToArray();
24 }
25
27 {
28 Compiler = compiler;
29 }
30
31 public void Compile(BadExpression expr)
32 {
33 Compiler.Compile(this, expr);
34 }
35
36 public void Compile(IEnumerable<BadExpression> exprs, bool clearStack = true)
37 {
38 Compiler.Compile(this, exprs, clearStack);
39 }
40
41 public void Emit(BadInstruction instruction)
42 {
43 m_Instructions.Add(instruction);
44 }
45
46 public int EmitEmpty()
47 {
48 int i = m_Instructions.Count;
51
52 return i;
53 }
54
55 public void ResolveEmpty(int index, BadOpCode code, BadSourcePosition position, params object[] args)
56 {
57 if (m_EmptyInstructions.Contains(index))
58 {
59 m_Instructions[index] = new BadInstruction(code, position, args);
60 m_EmptyInstructions.Remove(index);
61 }
62 else
63 {
64 throw new BadCompilerException("Invalid Empty Instruction Index!");
65 }
66 }
67
68 public void EmitRange(IEnumerable<BadInstruction> instructions)
69 {
70 m_Instructions.AddRange(instructions);
71 }
72
73 public void Emit(BadOpCode code, BadSourcePosition position, params object[] args)
74 {
75 Emit(new BadInstruction(code, position, args));
76 }
77}
78
82public interface IBadExpressionCompiler
83{
91}
Describes a specific position inside a source file.
Base Implementation for all Expressions used inside the Script.
Gets thrown when a Compiler is not able to compile a specific BadExpression.
Implements the Compile for the BadVirtualMachine.
void Compile(BadExpressionCompileContext context, BadExpression expression)
Compiles the given BadExpression into a set of BadInstructions.
void Compile(BadExpressionCompileContext context, BadExpression expression)
Compiles the given BadExpression into a set of BadInstructions.
Contains Shared Data Structures and Functionality.
Contains the Expressions for the BadScript2 Language.
BadOpCode
Defines the Operations that the BadVirtualMachine can execute.
Definition BadOpCode.cs:7
Implements a single instruction for the BadVirtualMachine.
void ResolveEmpty(int index, BadOpCode code, BadSourcePosition position, params object[] args)
void Emit(BadOpCode code, BadSourcePosition position, params object[] args)