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 BadExpression lockExpression,
35 BadExpression[] block) : base(false, position)
36 {
37 LockExpression = lockExpression;
38 m_Block = block;
39 }
40
44 public IEnumerable<BadExpression> Block => m_Block;
45
46
48 public override IEnumerable<BadExpression> GetDescendants()
49 {
50 foreach (BadExpression expression in LockExpression.GetDescendantsAndSelf())
51 {
52 yield return expression;
53 }
54
55 foreach (BadExpression expression in m_Block)
56 {
57 foreach (BadExpression e in expression.GetDescendantsAndSelf())
58 {
59 yield return e;
60 }
61 }
62 }
63
65 protected override IEnumerable<BadObject> InnerExecute(BadExecutionContext context)
66 {
67 BadObject lockObj = BadObject.Null;
68
69 foreach (BadObject o in LockExpression.Execute(context))
70 {
71 lockObj = o;
72
73 yield return o;
74 }
75
76 lockObj = lockObj.Dereference(Position);
77
78 if (lockObj is not BadArray && lockObj is not BadTable && lockObj is BadClass)
79 {
80 throw new BadRuntimeException("Lock object must be of type Array, Object or Class", Position);
81 }
82
83 while (!BadLockList.Instance.TryAquire(lockObj))
84 {
85 yield return BadObject.Null;
86 }
87
88 if (m_Block.Length != 0)
89 {
90 foreach (BadObject o in context.Execute(m_Block))
91 {
92 yield return o;
93 }
94 }
95
97 }
98}
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.