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 private readonly List<int> m_EmptyInstructions = new List<int>();
15 {
16 if(m_EmptyInstructions.Count > 0)
17 {
18 throw new BadCompilerException("Unresolved Empty Instructions!");
19 }
20
21 return m_Instructions.ToArray();
22 }
24 {
25 Compiler = compiler;
26 }
27
28 public void Compile(BadExpression expr) => Compiler.Compile(this, expr);
29 public void Compile(IEnumerable<BadExpression> exprs, bool clearStack = true) => Compiler.Compile(this, exprs, clearStack);
30
31 public void Emit(BadInstruction instruction)
32 {
33 m_Instructions.Add(instruction);
34 }
35 public int EmitEmpty()
36 {
37 int i = m_Instructions.Count;
40 return i;
41 }
42
43 public void ResolveEmpty(int index, BadOpCode code, BadSourcePosition position, params object[] args)
44 {
45 if(m_EmptyInstructions.Contains(index))
46 {
47 m_Instructions[index] = new BadInstruction(code, position, args);
48 m_EmptyInstructions.Remove(index);
49 }
50 else
51 {
52 throw new BadCompilerException("Invalid Empty Instruction Index!");
53 }
54 }
55
56 public void EmitRange(IEnumerable<BadInstruction> instructions)
57 {
58 m_Instructions.AddRange(instructions);
59 }
60
61 public void Emit(BadOpCode code, BadSourcePosition position, params object[] args)
62 {
63 Emit(new BadInstruction(code, position, args));
64 }
65}
66
70public interface IBadExpressionCompiler
71{
79}
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 Compile(IEnumerable< BadExpression > exprs, bool clearStack=true)
void Emit(BadOpCode code, BadSourcePosition position, params object[] args)