Skip to content

Commit

Permalink
Fixed 'If' and 'For ... To ... Step ... Next' (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown6656 committed Jun 22, 2020
1 parent cf930a5 commit 1f1bd64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
12 changes: 6 additions & 6 deletions new/AutoItInterpreter/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

//////////////////////////////////////////////////////////////////////////
// Autogenerated 2020-06-22 17:43:42.285 //
// Autogenerated 2020-06-22 18:21:05.936 //
// ANY CHANGES TO THIS DOCUMENT WILL BE LOST UPON RE-GENERATION //
//////////////////////////////////////////////////////////////////////////

using System.Reflection;
using System;

[assembly: AssemblyVersion("0.5.599.20174")]
[assembly: AssemblyFileVersion("0.5.599.20174")]
[assembly: AssemblyInformationalVersion("02cd5b96fee68cf1a7258572694611544cbca05f")]
[assembly: AssemblyVersion("0.5.605.20174")]
[assembly: AssemblyFileVersion("0.5.605.20174")]
[assembly: AssemblyInformationalVersion("cf930a56b251e95e4478d9b572d5fac6e0afc80f")]
[assembly: AssemblyCompany("Unknown6656")]
[assembly: AssemblyCopyright("Copyright © 2018 - 2020, Unknown6656")]
[assembly: AssemblyProduct("AutoIt3 Interpreter by Unknown6656")]
Expand All @@ -20,6 +20,6 @@ public static class __module__
public static string Author { get; } = "Unknown6656";
public static string Year { get; } = "2018 - 2020";
public static string Copyright { get; } = "Copyright © 2018 - 2020, Unknown6656";
public static Version? InterpreterVersion { get; } = Version.Parse("0.5.599.20174");
public static string GitHash { get; } = "02cd5b96fee68cf1a7258572694611544cbca05f";
public static Version? InterpreterVersion { get; } = Version.Parse("0.5.605.20174");
public static string GitHash { get; } = "cf930a56b251e95e4478d9b572d5fac6e0afc80f";
}
39 changes: 27 additions & 12 deletions new/AutoItInterpreter/Runtime/AU3Thread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -567,21 +567,24 @@ private InterpreterResult PushBlockStatement(BlockStatementType statement)
if (depth == 0)
{
Variable temp = VariableResolver.CreateTemporaryVariable();
string first = '$' + temp.Name;
string last = '$' + temp.Name;
temp.Value = true;
temp.Value = Variant.False;
_line_cache.RemoveAt(_instruction_pointer);
_line_cache.InsertRange(_instruction_pointer, new[] {
(CurrentLocation, $"If {last} Then"),
(CurrentLocation, $"ExitLoop"),
(CurrentLocation, $"Else"),
(CurrentLocation, $"{counter} += {step}"),
(CurrentLocation, $"WEnd"),
(CurrentLocation, $"If {counter} == {m.Groups["stop"]} Then"),
(CurrentLocation, $"{last} = True"),
(CurrentLocation, $"EndIf"),
(CurrentLocation, $"EndIf"),
(CurrentLocation, $"Until False"),
});
_instruction_pointer = eip_for;
_line_cache.RemoveAt(_instruction_pointer);
_line_cache.InsertRange(_instruction_pointer, new[] {
(CurrentLocation, $"While ({first} Or ({counter} <> {m.Groups["stop"].Value}))"),
(CurrentLocation, $"{first} = False"),
});
_line_cache[_instruction_pointer] = (CurrentLocation, "Do");
_instruction_pointer--;
return InterpreterResult.OK;
Expand Down Expand Up @@ -665,13 +668,14 @@ private InterpreterResult PushBlockStatement(BlockStatementType statement)
if (condition.Is(out InterpreterError? error))
return error;
if (condition.As<Variant>().ToBoolean())
_if_stack.Push(true);
else
{
_if_stack.Push(false);
bool cond = condition.As<Variant>().ToBoolean();
MoveToEndOf(BlockStatementType.If);
_if_stack.Push(cond);
if (!cond)
MoveToEndOf(BlockStatementType.If);
}
return InterpreterResult.OK;
Expand Down Expand Up @@ -758,18 +762,29 @@ private InterpreterResult PushBlockStatement(BlockStatementType statement)
else if (type is BlockStatementType.If)
while (MoveNext())
{
bool @if = false;

if (CurrentLineContent.Match(REGEX_IF, out Match m))
{
@if = true;

if (m.Groups["elif"].Length > 0)
--depth;
else
++depth;
}
else if (CurrentLineContent.Match(REGEX_ELSE, out Match _))
--depth;
else if (CurrentLineContent.Match(REGEX_ENDIF, out Match _))
--depth;

if (depth == 0)
{
if (@if)
--_instruction_pointer;

break;
}
}

// TODO : other block types
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.5.599.20174
02cd5b96fee68cf1a7258572694611544cbca05f
0.5.605.20174
cf930a56b251e95e4478d9b572d5fac6e0afc80f

0 comments on commit 1f1bd64

Please sign in to comment.