Skip to content

Commit 7af099f

Browse files
committed
move IsDisposed checking into the hypervisor
1 parent d1f727d commit 7af099f

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

src/Lib/Internal/ExecutableScript.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,25 @@
22

33
public abstract class ExecutableScript : IDisposable
44
{
5-
public bool IsDisposed { get; protected set; }
6-
75
public abstract ReadOnlySpan<byte> Code { get; }
86

97
public abstract ReadOnlySpan<Value> Constants { get; }
108

11-
public virtual byte GetByteAt(int idx) => Code[idx];
12-
13-
public int GetMaskedByteAt(int idx) => GetByteAt(idx) & 0xFF;
9+
public abstract void Dispose();
1410

15-
public StringSegment Execute(StarscriptHypervisor hypervisor)
16-
{
17-
if (IsDisposed)
18-
throw new ObjectDisposedException(nameof(ExecutableScript), "Cannot execute a disposed Script.");
11+
public virtual byte GetByteAt(int idx) => Code[idx];
1912

20-
return hypervisor.Run(this);
21-
}
2213

23-
public StringSegment Execute(StarscriptHypervisor hypervisor, ValueMap locals)
24-
{
25-
if (IsDisposed)
26-
throw new ObjectDisposedException(nameof(ExecutableScript), "Cannot execute a disposed Script.");
14+
public bool IsDisposed { get; protected set; }
2715

28-
return hypervisor.Run(this, locals);
29-
}
16+
public int GetMaskedByteAt(int idx) => GetByteAt(idx) & 0xFF;
3017

31-
public StringSegment Execute(StarscriptHypervisor hypervisor, IStarscriptObject obj)
32-
{
33-
if (IsDisposed)
34-
throw new ObjectDisposedException(nameof(ExecutableScript), "Cannot execute a disposed Script.");
18+
public StringSegment Execute(StarscriptHypervisor hypervisor)
19+
=> hypervisor.Run(this);
3520

36-
return hypervisor.Run(this, obj);
37-
}
21+
public StringSegment Execute(StarscriptHypervisor hypervisor, ValueMap locals)
22+
=> hypervisor.Run(this, locals);
3823

39-
public abstract void Dispose();
24+
public StringSegment Execute(StarscriptHypervisor hypervisor, IStarscriptObject obj)
25+
=> hypervisor.Run(this, obj);
4026
}

src/Lib/Public/Hypervisor/Starscript.HV.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ public partial class StarscriptHypervisor
88
{
99
internal StringSegment RunImpl(ExecutableScript script, StringBuilder sb)
1010
{
11+
if (script.IsDisposed)
12+
throw new ObjectDisposedException(script.GetType().FullName, "Cannot execute a disposed Script.");
13+
1114
_stack.Clear();
1215

1316
sb.Length = 0;

0 commit comments

Comments
 (0)