From 07a142321c6fb6494506200b827d97ab76816fe3 Mon Sep 17 00:00:00 2001 From: snaulX Date: Sun, 22 Sep 2019 19:01:39 +0300 Subject: [PATCH] Fix bug with function name and fix other --- wolvm/Stack.cs | 19 +++++++++---------- wolvm/VirtualMachine.cs | 14 ++------------ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/wolvm/Stack.cs b/wolvm/Stack.cs index 1b16483..d6bd3f6 100644 --- a/wolvm/Stack.cs +++ b/wolvm/Stack.cs @@ -1188,6 +1188,7 @@ public static Stack Parse(string stack_code) func.body = buffer.ToString(); stack.functions.Add(func_name, func); current = stack_code[++position]; //skip ']' (peek next char) + buffer.Clear(); if (current == ',') { current = stack_code[++position]; //skip ',' @@ -1216,7 +1217,6 @@ public static Stack Parse(string stack_code) { VirtualMachine.ThrowVMException("Functions`s start not found", VirtualMachine.position - stack_code.Length + position, ExceptionType.BLDSyntaxException); } - buffer.Clear(); } else if (buffer.ToString() == "var") { @@ -1597,21 +1597,20 @@ public void Dispose() public override string ToString() { - string classes_str = "", func_str = "", var_str = ""; - if (classes.Count != 0) + string str = ""; + foreach (KeyValuePair keyValuePair in values) { - classes_str += "class {\n\t"; - classes_str += "}"; + str += keyValuePair.Key + ' ' + keyValuePair.Value + '\n'; } - if (functions.Count != 0) + foreach (KeyValuePair keyValuePair in classes) { - func_str += "func {\n"; + str += keyValuePair.Key + ' ' + keyValuePair.Value + '\n'; } - if (values.Count != 0) + foreach (KeyValuePair keyValuePair in functions) { - var_str += "var {\n"; + str += keyValuePair.Key + ' ' + keyValuePair.Value + '\n'; } - return " {\n\t" + classes_str + func_str + var_str + "\n};"; + return str; } public static Stack operator +(Stack right, Stack left) diff --git a/wolvm/VirtualMachine.cs b/wolvm/VirtualMachine.cs index 04e5ca8..d1aa169 100644 --- a/wolvm/VirtualMachine.cs +++ b/wolvm/VirtualMachine.cs @@ -318,18 +318,8 @@ public static void Run(string input) if (test) { //test stack - foreach (KeyValuePair keyValuePair in mainstack.values) - { - Console.WriteLine(keyValuePair.Key + ' ' + keyValuePair.Value); - } - foreach (KeyValuePair keyValuePair in mainstack.classes) - { - Console.WriteLine(keyValuePair.Key + ' ' + keyValuePair.Value); - } - foreach (KeyValuePair keyValuePair in mainstack.functions) - { - Console.WriteLine(keyValuePair.Key + ' ' + keyValuePair.Value); - } + Console.WriteLine("Info about program in the end.\nMain stack:"); + Console.Write(mainstack.ToString()); Console.WriteLine($"Time of program: {Environment.TickCount - time}"); } return;