mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-04 09:06:41 +02:00
- Fix code editor resize problems
- Fix crash when using `get` our `out` multiple times with the same variable name - Show the name of the file in which the error occured
This commit is contained in:
@@ -42,41 +42,55 @@ namespace YesNt.Interpreter.Statements
|
||||
}
|
||||
|
||||
[Statement("out", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Yellow)]
|
||||
public void GetOutParameter(string name)
|
||||
public void GetOutParameter(string args)
|
||||
{
|
||||
if (RuntimeInfo.OutParametersStack.Count == 0)
|
||||
{
|
||||
RuntimeInfo.Exit("No out parameter in stack", true);
|
||||
RuntimeInfo.Exit("No out argument in stack", true);
|
||||
return;
|
||||
}
|
||||
|
||||
RuntimeInfo.Variables.Add(name, RuntimeInfo.OutParametersStack.Pop());
|
||||
if (RuntimeInfo.Variables.ContainsKey(args))
|
||||
{
|
||||
RuntimeInfo.Variables[args] = RuntimeInfo.OutParametersStack.Pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
RuntimeInfo.Variables.Add(args, RuntimeInfo.OutParametersStack.Pop());
|
||||
}
|
||||
}
|
||||
|
||||
[Statement("get", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Yellow)]
|
||||
public void GetInParameter(string args)
|
||||
{
|
||||
if (RuntimeInfo.FunctionCallStack.Count == 0)
|
||||
if (!RuntimeInfo.IsInFunction)
|
||||
{
|
||||
RuntimeInfo.Exit("No function in stack", true);
|
||||
RuntimeInfo.Exit("Statement not allowed outside of function", true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (RuntimeInfo.FunctionCallStack.Peek().Arguemtns.Count == 0)
|
||||
{
|
||||
RuntimeInfo.Exit("No in parameter in stack", true);
|
||||
RuntimeInfo.Exit("No in argument in stack", true);
|
||||
return;
|
||||
}
|
||||
|
||||
RuntimeInfo.Variables.TryAdd(args, RuntimeInfo.FunctionCallStack.Peek().Arguemtns.Pop());
|
||||
if (RuntimeInfo.Variables.ContainsKey(args))
|
||||
{
|
||||
RuntimeInfo.Variables[args] = RuntimeInfo.FunctionCallStack.Peek().Arguemtns.Pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
RuntimeInfo.Variables.Add(args, RuntimeInfo.FunctionCallStack.Peek().Arguemtns.Pop());
|
||||
}
|
||||
}
|
||||
|
||||
[Statement("put", SearchMode.StartOfLine, SpaceAround.End, ConsoleColor.Yellow)]
|
||||
public void AddOutParameter(string args)
|
||||
{
|
||||
if (RuntimeInfo.FunctionCallStack.Count == 0)
|
||||
if (!RuntimeInfo.IsInFunction)
|
||||
{
|
||||
RuntimeInfo.Exit("No function in stack", true);
|
||||
RuntimeInfo.Exit("Statement not allowed outside of function", true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +102,7 @@ namespace YesNt.Interpreter.Statements
|
||||
{
|
||||
if (!RuntimeInfo.IsInFunction)
|
||||
{
|
||||
RuntimeInfo.Exit("Not in function", true);
|
||||
RuntimeInfo.Exit("Statement not allowed outside of function", true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
using YesNt.Interpreter.Attributes;
|
||||
using YesNt.Interpreter.Enums;
|
||||
using YesNt.Interpreter.Runtime;
|
||||
using YesNt.Interpreter.Utilities;
|
||||
|
||||
namespace YesNt.Interpreter.Statements
|
||||
@@ -41,8 +42,9 @@ namespace YesNt.Interpreter.Statements
|
||||
public void RunTask(string line)
|
||||
{
|
||||
int lineNumer = RuntimeInfo.LineNumber;
|
||||
List<string> lines = RuntimeInfo.Lines.GetRange(0, RuntimeInfo.Lines.Count);
|
||||
lines[lineNumer] = line;
|
||||
List<Line> lines = RuntimeInfo.Lines.GetRange(0, RuntimeInfo.Lines.Count);
|
||||
|
||||
lines[lineNumer].Content = line;
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
YesNtInterpreter interpreter = new YesNtInterpreter();
|
||||
@@ -73,7 +75,12 @@ namespace YesNt.Interpreter.Statements
|
||||
try
|
||||
{
|
||||
RuntimeInfo.Lines.RemoveAt(0);
|
||||
RuntimeInfo.Lines.InsertRange(RuntimeInfo.LineNumber, File.ReadAllLines(path));
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
|
||||
for (int i = 0; i < lines.Length; i++)
|
||||
{
|
||||
RuntimeInfo.Lines.Add(new Line(lines[i], Path.GetFileName(path), i));
|
||||
}
|
||||
RuntimeInfo.LineNumber--;
|
||||
}
|
||||
catch
|
||||
|
||||
Reference in New Issue
Block a user