Skip to content

Commit

Permalink
refactored code (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown6656 committed Mar 14, 2021
1 parent 8505c82 commit 9cacdce
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/Runtime/AU3Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class AU3Thread
, IEquatable<AU3Thread>
{
private static volatile int _tid = 0;
private readonly ConcurrentStack<CallFrame> _callstack = new ConcurrentStack<CallFrame>();
private readonly ConcurrentStack<CallFrame> _callstack = new();
private volatile bool _running = false;
private int? _override_exitcode = null;

Expand Down Expand Up @@ -175,7 +175,7 @@ public void Stop(int exitcode)

internal AU3CallFrame PushAnonymousCallFrame()
{
AU3CallFrame frame = new AU3CallFrame(this, CurrentFrame, Interpreter.ScriptScanner.AnonymousFunction, Array.Empty<Variant>());
AU3CallFrame frame = new(this, CurrentFrame, Interpreter.ScriptScanner.AnonymousFunction, Array.Empty<Variant>());

_callstack.Push(frame);

Expand Down
68 changes: 34 additions & 34 deletions new/AutoItInterpreter/Runtime/CallFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,45 +248,45 @@ public sealed class AU3CallFrame
: CallFrame
{
private const RegexOptions _REGEX_OPTIONS = RegexOptions.IgnoreCase | RegexOptions.Compiled;
private static readonly Regex REGEX_INTERNAL_LABEL = new Regex(@"^§\w+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_VARIABLE = new Regex(@"\$([^\W\d]|[^\W\d]\w*)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_GOTO = new Regex(@"^goto\s+(?<label>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WHILE = new Regex(@"^while\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WEND = new Regex(@"^wend$", _REGEX_OPTIONS);
private static readonly Regex REGEX_NEXT = new Regex(@"^next$", _REGEX_OPTIONS);
internal static readonly Regex REGEX_EXIT = new Regex(@"^exit(\b\s*(?<code>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_RETURN = new Regex(@"^return(\b\s*(?<value>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FOR = new Regex(@"^for\s+.+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORTO = new Regex(@"^for\s+(?<start>.+)\s+to\s+(?<stop>.+?)(\s+step\s+(?<step>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN = new Regex(@"^for\s+(?<variable>.+)\s+in\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN_VARIABLES = new Regex(@"^\$(?<key>[^\W\d]|[^\W\d]\w*)\s*,\s*\$(?<value>[^\W\d]|[^\W\d]\w*)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WITH = new Regex(@"^with\s+(?<variable>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDWITH = new Regex(@"^endwith$", _REGEX_OPTIONS);
private static readonly Regex REGEX_REDIM = new Regex(@"^redim\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DO = new Regex(@"^do$", _REGEX_OPTIONS);
private static readonly Regex REGEX_UNTIL = new Regex(@"^until\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_IF = new Regex(@"^(?<elif>else)?if\s+(?<condition>.+)\s+then$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ELSE = new Regex(@"^else$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDIF = new Regex(@"^endif$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DECLARATION_MODIFIER = new Regex(@"^(local|static|global|const|dim|enum|step)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENUM_STEP = new Regex(@"^(?<op>[+\-*]?)(?<step>\d+)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_INCLUDE = new Regex(@"^include?\s+(?<open>[""'<])(?<path>(?:(?!\k<close>).)+)(?<close>[""'>])$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUELOOP_EXITLOOP = new Regex(@"^(?<mode>continue|exit)loop\s*(?<level>.+)?\s*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SELECT = new Regex(@"^select$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSELECT = new Regex(@"^endselect$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SWITCH = new Regex(@"^switch\b\s*(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSWITCH = new Regex(@"^endswitch$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CASE = new Regex(@"^case\b\s*(?<expression>.+)*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUECASE = new Regex(@"^continuecase$", _REGEX_OPTIONS);
private static readonly Regex REGEX_INTERNAL_LABEL = new(@"^§\w+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_VARIABLE = new(@"\$([^\W\d]|[^\W\d]\w*)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_GOTO = new(@"^goto\s+(?<label>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WHILE = new(@"^while\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WEND = new(@"^wend$", _REGEX_OPTIONS);
private static readonly Regex REGEX_NEXT = new(@"^next$", _REGEX_OPTIONS);
internal static readonly Regex REGEX_EXIT = new(@"^exit(\b\s*(?<code>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_RETURN = new(@"^return(\b\s*(?<value>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FOR = new(@"^for\s+.+$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORTO = new(@"^for\s+(?<start>.+)\s+to\s+(?<stop>.+?)(\s+step\s+(?<step>.+))?$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN = new(@"^for\s+(?<variable>.+)\s+in\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_FORIN_VARIABLES = new(@"^\$(?<key>[^\W\d]|[^\W\d]\w*)\s*,\s*\$(?<value>[^\W\d]|[^\W\d]\w*)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_WITH = new(@"^with\s+(?<variable>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDWITH = new(@"^endwith$", _REGEX_OPTIONS);
private static readonly Regex REGEX_REDIM = new(@"^redim\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DO = new(@"^do$", _REGEX_OPTIONS);
private static readonly Regex REGEX_UNTIL = new(@"^until\s+(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_IF = new(@"^(?<elif>else)?if\s+(?<condition>.+)\s+then$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ELSE = new(@"^else$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDIF = new(@"^endif$", _REGEX_OPTIONS);
private static readonly Regex REGEX_DECLARATION_MODIFIER = new(@"^(local|static|global|const|dim|enum|step)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENUM_STEP = new(@"^(?<op>[+\-*]?)(?<step>\d+)\b", _REGEX_OPTIONS);
private static readonly Regex REGEX_INCLUDE = new(@"^include?\s+(?<open>[""'<])(?<path>(?:(?!\k<close>).)+)(?<close>[""'>])$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUELOOP_EXITLOOP = new(@"^(?<mode>continue|exit)loop\s*(?<level>.+)?\s*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SELECT = new(@"^select$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSELECT = new(@"^endselect$", _REGEX_OPTIONS);
private static readonly Regex REGEX_SWITCH = new(@"^switch\b\s*(?<expression>.+)$", _REGEX_OPTIONS);
private static readonly Regex REGEX_ENDSWITCH = new(@"^endswitch$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CASE = new(@"^case\b\s*(?<expression>.+)*$", _REGEX_OPTIONS);
private static readonly Regex REGEX_CONTINUECASE = new(@"^continuecase$", _REGEX_OPTIONS);

private readonly ConcurrentDictionary<string, IEnumerator<(Variant key, Variant value)>> _iterators = new();
private readonly ConcurrentStack<Variable> _withcontext_stack = new ConcurrentStack<Variable>();
private readonly ConcurrentStack<bool> _if_stack = new ConcurrentStack<bool>();
private readonly ConcurrentStack<Variable> _withcontext_stack = new();
private readonly ConcurrentStack<bool> _if_stack = new();
private readonly ConcurrentStack<string> _while_stack = new();
private readonly ConcurrentStack<(Variant? switch_expression, bool case_handled)> _switchselect_stack = new();

private volatile int _instruction_pointer = 0;
private List<(SourceLocation LineLocation, string LineContent)> _line_cache;
private readonly List<(SourceLocation LineLocation, string LineContent)> _line_cache;


/// <summary>
Expand Down Expand Up @@ -1073,7 +1073,7 @@ FunctionReturnValue process_success(bool success)
else
return WellKnownError("error.invalid_case_expr", expression);
return (InterpreterError)case_expr;
return (InterpreterError)case_expr!;
},
[REGEX_CONTINUECASE] = _ =>
{
Expand Down
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/Runtime/DelegateBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private DelegateBuilder()
return new UserFunctionCallback(ptr);
}
}
catch (Exception ex)
catch
{
}

Expand Down Expand Up @@ -217,7 +217,7 @@ ParameterBuilder ProcessParameter(int index, TYPE type)
return new NativeDelegateWrapper(@delegate, @params!, rettype, inv);
}
}
catch (Exception ex)
catch
{
}

Expand Down

0 comments on commit 9cacdce

Please sign in to comment.