From e86f463de67aac4d25552e9ae1025e0a1c4bf5d1 Mon Sep 17 00:00:00 2001 From: Qrakhen Date: Tue, 18 Nov 2025 00:00:50 +0100 Subject: [PATCH] add array declarations --- Qrakhen.Qamp.CLI/Program.cs | 113 +++++++++++++++++++++++++- Qrakhen.Qamp.Core/Execution/Runner.cs | 24 ++++-- 2 files changed, 128 insertions(+), 9 deletions(-) diff --git a/Qrakhen.Qamp.CLI/Program.cs b/Qrakhen.Qamp.CLI/Program.cs index 3a61e3b..f799d96 100644 --- a/Qrakhen.Qamp.CLI/Program.cs +++ b/Qrakhen.Qamp.CLI/Program.cs @@ -2,8 +2,10 @@ using Qrakhen.Qamp.Core; using Qrakhen.Qamp.Core.Execution; using Qrakhen.Qamp.Core.Logging; +using System.Diagnostics; +using System.Linq.Expressions; using System.Text; - +/* // do args here too, keep console, etc. output with exit, all the spicy things // if no file is given for example in args just keep cli live until quit @@ -33,6 +35,115 @@ void Init(string[] args) Init(args); +void git(string path, string cmd) +{ + Console.WriteLine($" > git {cmd}"); + ProcessStartInfo info = new ProcessStartInfo{ + WorkingDirectory = path, + FileName = "git", + Arguments = cmd + }; + Process.Start(info)?.WaitForExit(); +} + +void del(string path, string cmd) +{ + Console.WriteLine($" > git {cmd}"); + ProcessStartInfo info = new ProcessStartInfo{ + WorkingDirectory = path, + FileName = "del", + Arguments = $"{cmd} /F /Q /S" + }; + Process.Start(info)?.WaitForExit(); +} + +string x = @"C:\Users\filos\projects"; +string[] check = ["node_modules", "bin", "obj", "Library"]; +int scanx(string path) +{ + foreach (var dir in Directory.EnumerateDirectories(path)) { + try { + var name = dir.Replace(path, "").Replace(@"\", ""); + if (!check.Contains(name)) { + scanx(dir); + } else { + Console.WriteLine(dir + " (" + (Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length) + " files)"); + if ((Directory.GetFiles(dir).Length + Directory.GetDirectories(dir).Length) == 0) { + Console.WriteLine(" skipped (0 files)"); + continue; + } + if (name == "Library") { + if (!Directory.Exists(path + "\\Assets")) { + Console.WriteLine(" skipped (not a definite unity library folder)"); + continue; + } + } + Console.Write(name == "Library" ? " y/n?" : ""); + do { + char c = name == "Library" ? Console.ReadKey(true).KeyChar : 'y'; + if (c == 'y') { + Directory.Delete(dir, true); + break; + } else if (c == 'n') { + break; + } else { + Console.WriteLine(string.Join("\n", Directory.EnumerateDirectories(dir).Select(_ => $" + {_}"))); + Console.WriteLine(string.Join("\n", Directory.EnumerateFiles(dir).Select(_ => $" - {_}"))); + } + } while (true); + } + } catch(Exception e) { Console.WriteLine("ERROR: " + e.Message); } + } + return 0; +} + +scanx(x); +return; + + +string path = @"C:\Users\filos\projects"; +string[] ignore = ["node_modules", "bin", "obj", "Debug", "Build", ".vs"]; +int scan(string path) +{ + foreach (var dir in Directory.EnumerateDirectories(path)) { + var name = dir.Replace(path, "").Replace(@"\", ""); + if (ignore.Contains(name)) + continue; + if (name == ".git") { + Console.WriteLine(path); + git(path, "status"); + Console.Write("y/n? "); + do { + char c = (char)Console.Read(); + if (c == 'y') { + Console.Write(" origin [master]? "); + string t = Console.ReadLine() ?? "master"; + if (string.IsNullOrEmpty(t)) + t = "master"; + + git(path, "add ."); + git(path, "commit -m \"backup commit\""); + git(path, "push origin " + t); + break; + } else if (c == 'n') { + break; + } else if (c > '0' && c < '9') { + return (48 - c); + } + } while (true); + } else { + int e = scan(dir); + if (e < 0) + return e+1; + } + } + return 0; +} + +scan(path); +return; +*/ + List Ignored = [ '\0', '\b' ]; LoggerService.Default = LogLevel.Error; List History = []; diff --git a/Qrakhen.Qamp.Core/Execution/Runner.cs b/Qrakhen.Qamp.Core/Execution/Runner.cs index 2913e4d..7492aa5 100644 --- a/Qrakhen.Qamp.Core/Execution/Runner.cs +++ b/Qrakhen.Qamp.Core/Execution/Runner.cs @@ -91,11 +91,11 @@ public class Runner : IDisposable } switch (opCode) { - case Op.Null: Push(Value.Void); break; - case Op.Constant: Push(call.Instruction.NextConstant()); break; - case Op.Pop: Pop(); break; - case Op.True: Push(Value.True); break; - case Op.False: Push(Value.False); break; + case Op.Null: Push(Value.Void); break; + case Op.Constant: Push(call.Instruction.NextConstant()); break; + case Op.Pop: Pop(); break; + case Op.True: Push(Value.True); break; + case Op.False: Push(Value.False); break; case Op.GetGlobal: { string? name = call.Instruction.GetStringConstant(call.Instruction.NextDynamic())?.Value; @@ -193,7 +193,14 @@ public class Runner : IDisposable } case Op.Array: { - // essentially collect all pushed values and create an array, no? + int length = (int)call.Instruction.NextDynamic(); + Value[] values = new Value[length]; + for (int i = length - 1; i >= 0; i--) { + values[i] = Pop(); + } + var array = new Values.Objects.Array(values); + Value value = Obj.Create(array); + Push(value); break; } @@ -280,7 +287,7 @@ public class Runner : IDisposable break; } - case Op.Return: + case Op.Return: { Value result = Pop(); CloseOuters(call.StackPtr.Branch()); Calls.Pop(); @@ -292,7 +299,8 @@ public class Runner : IDisposable Push(result); call = Calls.Peek(); break; - + } + case Op.Class: { Push(Obj.Create(new Class(call.Instruction.NextString().Value!))); break;