19
19
20
20
namespace RazorEnhanced . UOS
21
21
{
22
- //
23
-
24
-
25
22
public class UOSScriptError : Exception
26
23
{
27
24
public ASTNode Node ;
@@ -84,11 +81,21 @@ public UOSArgumentError(ASTNode node, string error) : base(node, error) { }
84
81
public UOSArgumentError ( string line , int lineNumber , ASTNode node , string error ) : base ( line , lineNumber , node , error ) { }
85
82
}
86
83
84
+ public class UOSStopError : UOSScriptError
85
+ {
86
+ public UOSStopError ( ASTNode node , string error ) : base ( node , error ) { }
87
+ public UOSStopError ( string line , int lineNumber , ASTNode node , string error ) : base ( line , lineNumber , node , error ) { }
88
+ }
89
+
87
90
88
91
89
92
90
93
91
94
95
+ /// <summary>
96
+ /// This class contains all the methods available for the UOS scripts (.uos)
97
+ /// The following classes and commands ARE NOT available in python.
98
+ /// </summary>
92
99
public class UOSteamEngine
93
100
{
94
101
static bool DEFAULT_ISOLATION = false ;
@@ -104,13 +111,13 @@ public class UOSteamEngine
104
111
private bool m_UseIsolation = DEFAULT_ISOLATION ;
105
112
private Namespace m_Namespace ;
106
113
private Interpreter m_Interpreter ;
107
- private Script m_Script ;
114
+ private UOSCompiledScript m_Compiled ;
108
115
109
116
private Action < string > m_OutputWriter ;
110
117
private Action < string > m_ErrorWriter ;
111
118
112
119
public void SetTrace ( UOSTracebackDelegate traceDelegate ) {
113
- m_Script . OnTraceback += traceDelegate ;
120
+ m_Compiled . OnTraceback += traceDelegate ;
114
121
}
115
122
116
123
public void SetStdout ( Action < string > stdoutWriter )
@@ -123,7 +130,7 @@ public void SetStderr(Action<string> stderrWriter)
123
130
m_ErrorWriter = stderrWriter ;
124
131
}
125
132
126
- public Script Script { get { return m_Script ; } }
133
+ public UOSCompiledScript Compiled { get { return m_Compiled ; } }
127
134
public Interpreter Interpreter { get { return m_Interpreter ; } }
128
135
public Namespace Namespace {
129
136
get { return m_Namespace ; }
@@ -144,10 +151,7 @@ public bool UseIsolation {
144
151
}
145
152
}
146
153
147
- public class StopException : Exception
148
- {
149
- public StopException ( ) : base ( "Stop encountered" ) { }
150
- }
154
+
151
155
152
156
// useOnceIgnoreList
153
157
private readonly List < int > m_serialUseOnceIgnoreList ;
@@ -210,10 +214,11 @@ internal List<string> AllKeywords()
210
214
}
211
215
212
216
217
+
213
218
214
219
public UOSteamEngine ( )
215
220
{
216
- m_mutex = new Mutex ( ) ;
221
+ // m_mutex = new Mutex();
217
222
m_serialUseOnceIgnoreList = new List < int > ( ) ;
218
223
219
224
m_Loaded = false ;
@@ -335,16 +340,16 @@ public bool Load(string content, string filename = "")
335
340
336
341
public bool Load ( ASTNode root , string filename = "" )
337
342
{
338
- m_mutex . WaitOne ( ) ;
343
+ // m_mutex.WaitOne();
339
344
340
345
m_Loaded = false ;
341
- m_Script = null ;
346
+ m_Compiled = null ;
342
347
try
343
348
{
344
349
InitInterpreter ( true ) ;
345
350
346
- m_Script = new Script ( root , this ) ;
347
- m_Script . Filename = filename ;
351
+ m_Compiled = new UOSCompiledScript ( root , this ) ;
352
+ m_Compiled . Filename = filename ;
348
353
349
354
350
355
UpdateNamespace ( ) ;
@@ -354,44 +359,41 @@ public bool Load(ASTNode root, string filename = "")
354
359
SendError ( $ "UOSEngine: fail to load script:\n { e . Message } ") ;
355
360
}
356
361
357
- m_mutex . ReleaseMutex ( ) ;
362
+ // m_mutex.ReleaseMutex();
358
363
return m_Loaded ;
359
364
}
360
365
361
366
public bool Execute ( bool editorMode = false )
362
367
{
363
368
if ( ! m_Loaded ) { return false ; }
364
-
365
- m_mutex . WaitOne ( ) ;
369
+ Execute ( ) ;
370
+ /* m_mutex.WaitOne();
366
371
try
367
372
{
368
373
Execute();
369
374
}
370
- catch ( UOSteamEngine . StopException )
375
+ catch (UOSStopError e )
371
376
{
372
- if ( ! editorMode && m_Script . Filename != "" ) {
373
- Misc . ScriptStop ( m_Script . Filename ) ;
374
- }
377
+ EnhancedScript.Service.CurrentScript().Stop();
375
378
}
376
379
catch (Exception e)
377
380
{
378
- if ( ! editorMode && m_Script . Filename != "" ) {
379
- Misc . ScriptStop ( m_Script . Filename ) ;
380
- }
381
- throw ;
381
+ EnhancedScript.Service.CurrentScript().Stop();
382
+ throw e;
382
383
}
383
384
finally
384
385
{
385
- m_mutex . ReleaseMutex ( ) ;
386
- }
386
+ //m_mutex.ReleaseMutex();
387
+ }
388
+ */
387
389
return true ;
388
390
}
389
391
390
392
private void UpdateNamespace ( ) {
391
393
var ns = Namespace . GlobalNamespace ;
392
394
if ( m_UseIsolation && m_Namespace == Namespace . GlobalNamespace )
393
395
{
394
- ns = Namespace . Get ( Path . GetFileNameWithoutExtension ( Script . Filename ) ) ;
396
+ ns = Namespace . Get ( Path . GetFileNameWithoutExtension ( Compiled . Filename ) ) ;
395
397
}
396
398
if ( ns != m_Namespace ) {
397
399
m_Namespace = ns ;
@@ -5185,12 +5187,12 @@ internal ASTNode Node
5185
5187
get ; set ;
5186
5188
}
5187
5189
5188
- internal Script _script
5190
+ internal UOSCompiledScript _script
5189
5191
{
5190
5192
get ; set ;
5191
5193
}
5192
5194
5193
- public Argument ( Script script , ASTNode node )
5195
+ public Argument ( UOSCompiledScript script , ASTNode node )
5194
5196
{
5195
5197
Node = node ;
5196
5198
_script = script ;
@@ -5381,8 +5383,8 @@ public override int GetHashCode()
5381
5383
return base . GetHashCode ( ) ;
5382
5384
}
5383
5385
}
5384
- public delegate bool UOSTracebackDelegate ( Script script , ASTNode node , Scope scope ) ;
5385
- public class Script
5386
+ public delegate bool UOSTracebackDelegate ( UOSCompiledScript script , ASTNode node , Scope scope ) ;
5387
+ public class UOSCompiledScript
5386
5388
{
5387
5389
bool Debug { get ; set ; }
5388
5390
public string Filename ;
@@ -5396,7 +5398,7 @@ public class Script
5396
5398
5397
5399
private Scope _scope ;
5398
5400
5399
- public Script ( )
5401
+ public UOSCompiledScript ( )
5400
5402
{
5401
5403
Debug = false ;
5402
5404
}
@@ -5472,7 +5474,7 @@ private Argument[] ConstructArguments(ref ASTNode node)
5472
5474
// scripts to a bytecode. That would allow more errors
5473
5475
// to be caught with better error messages, as well as
5474
5476
// make the scripts execute more quickly.
5475
- public Script ( ASTNode root , UOSteamEngine engine )
5477
+ public UOSCompiledScript ( ASTNode root , UOSteamEngine engine )
5476
5478
{
5477
5479
// Set current to the first statement
5478
5480
_root = root ;
@@ -6062,7 +6064,7 @@ public bool ExecuteNext()
6062
6064
case ASTNodeType . STOP :
6063
6065
Engine . Interpreter . StopScript ( ) ;
6064
6066
_statement = null ;
6065
- throw ( new UOSteamEngine . StopException ( ) ) ;
6067
+ throw new UOSStopError ( node , "Found stop keyword." ) ;
6066
6068
break ;
6067
6069
case ASTNodeType . REPLAY :
6068
6070
_statement = _statement . Parent . FirstChild ( ) ;
@@ -6573,7 +6575,7 @@ public class Interpreter
6573
6575
6574
6576
// Lists
6575
6577
private UOSteamEngine m_Engine ;
6576
- private Script m_Script = null ;
6578
+ private UOSCompiledScript m_Script = null ;
6577
6579
6578
6580
private bool m_Suspended = false ;
6579
6581
private ManualResetEvent m_SuspendedMutex ;
@@ -6870,7 +6872,7 @@ public bool StartScript()
6870
6872
if ( m_Script != null )
6871
6873
return false ;
6872
6874
6873
- m_Script = m_Engine . Script ;
6875
+ m_Script = m_Engine . Compiled ;
6874
6876
_executionState = ExecutionState . RUNNING ;
6875
6877
Suspended = false ;
6876
6878
m_Script . Init ( ) ;
0 commit comments