From b68ec626ab129661999fbdee7e43ede9e3b92d05 Mon Sep 17 00:00:00 2001 From: unknown6656 Date: Thu, 20 Aug 2020 00:02:14 +0200 Subject: [PATCH] Finished implementing the interactive framework (resolves #38) --- new/AutoItInterpreter/AssemblyInfo.cs | 16 +++++++-------- new/AutoItInterpreter/CLI/InteractiveShell.cs | 20 ++++++++++++++++--- new/AutoItInterpreter/CLI/ScriptVisualizer.cs | 8 ++++---- new/AutoItInterpreter/Runtime/AU3Thread.cs | 12 +++++++++-- new/AutoItInterpreter/Runtime/CallFrame.cs | 4 ++-- .../Runtime/ScriptScanner.cs | 3 +++ new/AutoItInterpreter/version.txt | 4 ++-- 7 files changed, 46 insertions(+), 21 deletions(-) diff --git a/new/AutoItInterpreter/AssemblyInfo.cs b/new/AutoItInterpreter/AssemblyInfo.cs index 8bff57eb..4ffc4085 100644 --- a/new/AutoItInterpreter/AssemblyInfo.cs +++ b/new/AutoItInterpreter/AssemblyInfo.cs @@ -1,15 +1,15 @@ ////////////////////////////////////////////////////////////////////////// -// Auto-generated 2020-08-19 23:12:59.967 // +// Auto-generated 2020-08-19 23:50:42.863 // // ANY CHANGES TO THIS DOCUMENT WILL BE LOST UPON RE-GENERATION // ////////////////////////////////////////////////////////////////////////// using System.Reflection; using System; -[assembly: AssemblyVersion("0.6.1574.7352")] -[assembly: AssemblyFileVersion("0.6.1574.7352")] -[assembly: AssemblyInformationalVersion("v.0.6.1574.7352, commit: c9995acd9fab2caa5dfac4aa56a21449b54eabff")] +[assembly: AssemblyVersion("0.6.1581.7352")] +[assembly: AssemblyFileVersion("0.6.1581.7352")] +[assembly: AssemblyInformationalVersion("v.0.6.1581.7352, commit: e6bdbc225381d594326c7089bdc18bdbca7cc53e")] [assembly: AssemblyCompany("Unknown6656")] [assembly: AssemblyCopyright("Copyright © 2018 - 2020, Unknown6656")] [assembly: AssemblyProduct("AutoIt-Interpreter by Unknown6656")] @@ -35,11 +35,11 @@ public static class __module__ /// /// The interpreter's current version. /// - public static Version? InterpreterVersion { get; } = Version.Parse("0.6.1574.7352"); + public static Version? InterpreterVersion { get; } = Version.Parse("0.6.1581.7352"); /// /// The Git hash associated with the current build. /// - public const string GitHash = "c9995acd9fab2caa5dfac4aa56a21449b54eabff"; + public const string GitHash = "e6bdbc225381d594326c7089bdc18bdbca7cc53e"; /// /// The name of the GitHub repository associated with . /// @@ -49,7 +49,7 @@ public static class __module__ /// public const string RepositoryURL = "https://github.com/Unknown6656/AutoIt-Interpreter"; /// - /// The date and time of the current build (2020-08-19 23:12:59.967). + /// The date and time of the current build (2020-08-19 23:50:42.863). /// - public static DateTime DateBuilt { get; } = DateTime.FromFileTimeUtc(0x01d6766d84735200L); + public static DateTime DateBuilt { get; } = DateTime.FromFileTimeUtc(0x01d67672c93dd51bL); } diff --git a/new/AutoItInterpreter/CLI/InteractiveShell.cs b/new/AutoItInterpreter/CLI/InteractiveShell.cs index 9d5e6fe6..cfb118f9 100644 --- a/new/AutoItInterpreter/CLI/InteractiveShell.cs +++ b/new/AutoItInterpreter/CLI/InteractiveShell.cs @@ -7,6 +7,7 @@ using Unknown6656.Controls.Console; using Unknown6656.Imaging; using System.Windows.Forms; +using Unknown6656.AutoIt3.Parser.ExpressionParser; namespace Unknown6656.AutoIt3.CLI { @@ -77,11 +78,14 @@ private set public AU3Thread Thread { get; } + public AU3CallFrame CallFrame { get; } + public InteractiveShell(Interpreter interpreter) { Interpreter = interpreter; Thread = interpreter.CreateNewThread(); + CallFrame = Thread.PushAnonymousCallFrame(); } ~InteractiveShell() => Dispose(disposing: false); @@ -502,9 +506,18 @@ private void ProcessInput() else try { - // TODO : actual processing + CallFrame.InsertReplaceSourceCode(CallFrame.CurrentInstructionPointer, input); + + InterpreterResult? result = CallFrame.ParseCurrentLine(); - _ = Thread; + if (result?.OptionalError is { Message: string error }) + History.Add((new[] { new ScriptToken(0, 0, error.Length, error, TokenType.UNKNOWN) }, InteractiveShellStreamDirection.Error)); + else if (CallFrame.VariableResolver.TryGetVariable(AST.VARIABLE.Discard, VariableSearchScope.Global, out Variable? variable)) + { + string text = variable.Value.ToDebugString(Interpreter); + + History.Add((new[] { new ScriptToken(0, 0, text.Length, text, TokenType.Comment) }, InteractiveShellStreamDirection.Output)); + } } catch { @@ -554,7 +567,8 @@ public void UpdateSuggestions() filter = null; Suggestions.AddRange(from s in suggestions.Distinct() - let text = s + ' ' + let text = s.Trim() + ' ' + where text.Length > 1 let tokens = ScriptVisualizer.TokenizeScript(text)[..^1] let first = tokens[0] where filter is null || first.Content.StartsWith(filter, StringComparison.InvariantCultureIgnoreCase) diff --git a/new/AutoItInterpreter/CLI/ScriptVisualizer.cs b/new/AutoItInterpreter/CLI/ScriptVisualizer.cs index 89bd3ee0..f08d21d9 100644 --- a/new/AutoItInterpreter/CLI/ScriptVisualizer.cs +++ b/new/AutoItInterpreter/CLI/ScriptVisualizer.cs @@ -29,8 +29,8 @@ public static class ScriptVisualizer { // [TokenType.NewLine] = RGBAColor.White, // [TokenType.Whitespace] = RGBAColor.White, - [TokenType.Keyword] = RGBAColor.DodgerBlue, - [TokenType.FunctionCall] = RGBAColor.LightBlue, + [TokenType.Keyword] = RGBAColor.CornflowerBlue, + [TokenType.FunctionCall] = RGBAColor.LightCyan, [TokenType.Identifier] = RGBAColor.White, [TokenType.Comment] = RGBAColor.DarkSeaGreen, [TokenType.Number] = RGBAColor.Moccasin, @@ -96,12 +96,12 @@ void add_token(int length, TokenType type) } else if (line.Match(REGEX_STRING, out match)) add_token(match.Length, TokenType.String); + else if (line.Match(REGEX_KEYWORD, out match)) + add_token(match.Length, TokenType.Keyword); else if (line.Match(REGEX_SYMOBLS, out match)) add_token(match.Length, TokenType.Symbol); else if (line.Match(REGEX_OPERATORS, out match)) add_token(match.Length, TokenType.Operator); - else if (line.Match(REGEX_KEYWORD, out match)) - add_token(match.Length, TokenType.Keyword); else if (line.Match(REGEX_VARIABLE, out match)) add_token(match.Length, TokenType.Variable); else if (line.Match(REGEX_MACRO, out match)) diff --git a/new/AutoItInterpreter/Runtime/AU3Thread.cs b/new/AutoItInterpreter/Runtime/AU3Thread.cs index c4c1f4a6..5e328636 100644 --- a/new/AutoItInterpreter/Runtime/AU3Thread.cs +++ b/new/AutoItInterpreter/Runtime/AU3Thread.cs @@ -119,7 +119,7 @@ public Union Call(ScriptFunction function, Variant[] throw new ObjectDisposedException(nameof(AU3Thread)); CallFrame? old = CurrentFrame; - CallFrame frame = function switch + using CallFrame frame = function switch { AU3Function f => new AU3CallFrame(this, old, f, args), NativeFunction f => new NativeCallFrame(this, old, f, args), @@ -165,10 +165,18 @@ public void Stop(int exitcode) _callstack.TryPop(out CallFrame? frame); frame?.Dispose(); - return CurrentLocation; } + internal AU3CallFrame PushAnonymousCallFrame() + { + AU3CallFrame frame = new AU3CallFrame(this, CurrentFrame, Interpreter.ScriptScanner.AnonymousFunction, Array.Empty()); + + _callstack.Push(frame); + + return frame; + } + /// public override string ToString() => $"0x{ThreadID:x4}{(IsMainThread ? " (main)" : "")} @ {CurrentLocation}"; diff --git a/new/AutoItInterpreter/Runtime/CallFrame.cs b/new/AutoItInterpreter/Runtime/CallFrame.cs index 61bfe157..b0d598b8 100644 --- a/new/AutoItInterpreter/Runtime/CallFrame.cs +++ b/new/AutoItInterpreter/Runtime/CallFrame.cs @@ -465,8 +465,8 @@ private string InsertInternalJumpLabel() return name; } - - private void InsertReplaceSourceCode(int instruction_ptr, params string[] lines) + + internal void InsertReplaceSourceCode(int instruction_ptr, params string[] lines) { int eip = _instruction_pointer; diff --git a/new/AutoItInterpreter/Runtime/ScriptScanner.cs b/new/AutoItInterpreter/Runtime/ScriptScanner.cs index efea3f9d..2d12a6c7 100644 --- a/new/AutoItInterpreter/Runtime/ScriptScanner.cs +++ b/new/AutoItInterpreter/Runtime/ScriptScanner.cs @@ -59,6 +59,8 @@ from frame in thread.CallStack internal ScannedScript SystemScript { get; } + internal AU3Function AnonymousFunction { get; } + public Interpreter Interpreter { get; } public IEnumerable CachedFunctions => _cached_functions.Values; @@ -70,6 +72,7 @@ public ScriptScanner(Interpreter interpreter) { Interpreter = interpreter; SystemScript = new ScannedScript(MainProgram.ASM_FILE, ""); + AnonymousFunction = new AU3Function(SystemScript, "", null); } internal void ScanNativeFunctions() => Interpreter.Telemetry.Measure(TelemetryCategory.ScanScript, delegate diff --git a/new/AutoItInterpreter/version.txt b/new/AutoItInterpreter/version.txt index 044fae44..b91e8ea6 100644 --- a/new/AutoItInterpreter/version.txt +++ b/new/AutoItInterpreter/version.txt @@ -1,2 +1,2 @@ -0.6.1574.7352 -c9995acd9fab2caa5dfac4aa56a21449b54eabff \ No newline at end of file +0.6.1581.7352 +e6bdbc225381d594326c7089bdc18bdbca7cc53e \ No newline at end of file