Skip to content

Commit

Permalink
Finished implementing the interactive framework (resolves #38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown6656 committed Aug 19, 2020
1 parent e6bdbc2 commit b68ec62
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 21 deletions.
16 changes: 8 additions & 8 deletions new/AutoItInterpreter/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -35,11 +35,11 @@ public static class __module__
/// <summary>
/// The interpreter's current version.
/// </summary>
public static Version? InterpreterVersion { get; } = Version.Parse("0.6.1574.7352");
public static Version? InterpreterVersion { get; } = Version.Parse("0.6.1581.7352");
/// <summary>
/// The Git hash associated with the current build.
/// </summary>
public const string GitHash = "c9995acd9fab2caa5dfac4aa56a21449b54eabff";
public const string GitHash = "e6bdbc225381d594326c7089bdc18bdbca7cc53e";
/// <summary>
/// The name of the GitHub repository associated with <see cref="RepositoryURL"/>.
/// </summary>
Expand All @@ -49,7 +49,7 @@ public static class __module__
/// </summary>
public const string RepositoryURL = "https://github.com/Unknown6656/AutoIt-Interpreter";
/// <summary>
/// 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).
/// </summary>
public static DateTime DateBuilt { get; } = DateTime.FromFileTimeUtc(0x01d6766d84735200L);
public static DateTime DateBuilt { get; } = DateTime.FromFileTimeUtc(0x01d67672c93dd51bL);
}
20 changes: 17 additions & 3 deletions new/AutoItInterpreter/CLI/InteractiveShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Unknown6656.Controls.Console;
using Unknown6656.Imaging;
using System.Windows.Forms;
using Unknown6656.AutoIt3.Parser.ExpressionParser;

namespace Unknown6656.AutoIt3.CLI
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions new/AutoItInterpreter/CLI/ScriptVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 10 additions & 2 deletions new/AutoItInterpreter/Runtime/AU3Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Union<InterpreterError, Variant> 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),
Expand Down Expand Up @@ -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<Variant>());

_callstack.Push(frame);

return frame;
}

/// <inheritdoc/>
public override string ToString() => $"0x{ThreadID:x4}{(IsMainThread ? " (main)" : "")} @ {CurrentLocation}";

Expand Down
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/Runtime/CallFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions new/AutoItInterpreter/Runtime/ScriptScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ from frame in thread.CallStack

internal ScannedScript SystemScript { get; }

internal AU3Function AnonymousFunction { get; }

public Interpreter Interpreter { get; }

public IEnumerable<ScriptFunction> CachedFunctions => _cached_functions.Values;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions new/AutoItInterpreter/version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0.6.1574.7352
c9995acd9fab2caa5dfac4aa56a21449b54eabff
0.6.1581.7352
e6bdbc225381d594326c7089bdc18bdbca7cc53e

0 comments on commit b68ec62

Please sign in to comment.