BadScript 2
Loading...
Searching...
No Matches
BadLockExpression.cs
Go to the documentation of this file.
6
11
16{
21
25 private readonly BadExpression[] m_Block;
26
34 BadSourcePosition position,
35 BadExpression lockExpression,
36 BadExpression[] block) : base(false, position)
37 {
38 LockExpression = lockExpression;
39 m_Block = block;
40 }
41
45 public IEnumerable<BadExpression> Block => m_Block;
46
47
49 public override IEnumerable<BadExpression> GetDescendants()
50 {
51 foreach (BadExpression expression in LockExpression.GetDescendantsAndSelf())
52 {
53 yield return expression;
54 }
55
56 foreach (BadExpression expression in m_Block)
57 {
58 foreach (BadExpression e in expression.GetDescendantsAndSelf())
59 {
60 yield return e;
61 }
62 }
63 }
64
66 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
67 {
68 BadObject lockObj = BadObject.Null;
69
70 foreach (BadObject o in LockExpression.Execute(context))
71 {
72 lockObj = o;
73
74 yield return o;
75 }
76
77 lockObj = lockObj.Dereference();
78
79 if (lockObj is not BadArray && lockObj is not BadTable && lockObj is BadClass)
80 {
81 throw new BadRuntimeException("Lock object must be of type Array, Object or Class", Position);
82 }
83
84 while (!BadLockList.Instance.TryAquire(lockObj))
85 {
86 yield return BadObject.Null;
87 }
88
89 if (m_Block.Length != 0)
90 {
91 foreach (BadObject o in context.Execute(m_Block))
92 {
93 yield return o;
94 }
95 }
96
98 }
99}
Describes a specific position inside a source file.
Base Implementation for all Expressions used inside the Script.
IEnumerable< BadExpression > GetDescendantsAndSelf()
Returns all Descendants of the Expression and the Expression itself.
BadSourcePosition Position
The source Position of the Expression.
IEnumerable< BadObject > Execute(BadExecutionContext context)
Evaluates the Expression within the current Execution Context.
BadLockExpression(BadSourcePosition position, BadExpression lockExpression, BadExpression[] block)
Constructor of the Lock Expression.
readonly BadExpression LockExpression
The Expression to lock on.
override IEnumerable< BadExpression > GetDescendants()
override IEnumerable< BadObject > InnerExecute(BadExecutionContext context)
IEnumerable< BadExpression > Block
The Block Body.
The Lock List that is used to store all locks.
static readonly BadLockList Instance
Instance of the Lock List.
bool TryAquire(BadObject lockObj)
Tries to aquire a lock on the given object.
void Release(BadObject lockObj)
Releases the lock on the given object.
The Execution Context. Every execution of a script needs a context the script is running in....
Implements a Dynamic List/Array for the BadScript Language.
Definition BadArray.cs:17
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
Implements a Table Structure for the BadScript Language.
Definition BadTable.cs:14
Implements a Type Instance in the BadScript Language.
Definition BadClass.cs:11
Contains Shared Data Structures and Functionality.
Contains the Locking Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.