From 790dee561c7260eddae93cea0f1864b4a1d1c78b Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Tue, 7 Sep 2021 19:51:35 +0200 Subject: [PATCH] Made memory conditional --- BasicNumber.cs | 4 ++++ Functions/Memory.cs | 2 ++ Parser.cs | 5 ++++- Program.cs | 11 ++++++++++- Test.basic | 5 ----- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/BasicNumber.cs b/BasicNumber.cs index 354544a..bb777ba 100644 --- a/BasicNumber.cs +++ b/BasicNumber.cs @@ -79,10 +79,14 @@ namespace SuperBASIC { return runtime.GetRegister(); } +#if MEMORY else { return Functions.Memory.MemoryGet((short)operand); } +#else + return 0; +#endif } public static implicit operator float(BasicNumber v) => v.GetValue(); diff --git a/Functions/Memory.cs b/Functions/Memory.cs index a2e059f..7250df1 100644 --- a/Functions/Memory.cs +++ b/Functions/Memory.cs @@ -4,6 +4,7 @@ using System.Text; namespace SuperBASIC.Functions { +#if MEMORY static class Memory { internal static float[] memory = new float[Int16.MaxValue]; @@ -53,4 +54,5 @@ namespace SuperBASIC.Functions throw new Memory.BadMemoryAccess("Could not access requested memory"); } } +#endif } diff --git a/Parser.cs b/Parser.cs index 8753877..327ea76 100644 --- a/Parser.cs +++ b/Parser.cs @@ -79,6 +79,7 @@ namespace SuperBASIC c.bytecode.Add(new BasicNumber(runtime, opcode)); foreach (string elem in components.AsSpan(1)) { +#if MEMORY if (elem.StartsWith("M")) { try @@ -93,7 +94,9 @@ namespace SuperBASIC throw new ParseException($"Cannot parse {elem} as argument to memory address\n\tExpected 'M' followed by an integer lower than {Int16.MaxValue}\n\tat line {lineIndex}"); } } - else if (elem == "$") + else +#endif + if (elem == "$") { c.bytecode.Add(new BasicNumber(runtime)); } diff --git a/Program.cs b/Program.cs index c557c6f..8007d3f 100644 --- a/Program.cs +++ b/Program.cs @@ -10,15 +10,24 @@ namespace SuperBASIC try { Library lib = new Library(); +#if MEMORY lib.AddFunction(new Functions.MemoryLoad(), 1, "MEMLOAD"); lib.AddFunction(new Functions.MemoryStore(), 2, "MEMSTORE"); +#endif lib.AddFunction(new Functions.Print(), 1, "PRINT"); lib.AddFunction(new Functions.Multiply(), 2, "MULTIPLY"); lib.AddFunction(new Functions.Compare(), 2, "COMPARE"); lib.AddFunction(new Functions.Pi(), 0, "PI"); lib.AddFunction(new Functions.Euler(), 0, "EULER"); Runtime r = new Runtime(lib); - r.OpenFile(Directory.GetCurrentDirectory() + "\\Test.basic"); + if (args.Length <= 1) + { + r.OpenFile(Directory.GetCurrentDirectory() + "\\Test.basic"); + } + else + { + r.OpenFile(args[1]); + } r.Run(); } catch (Parser.ParseException e) { diff --git a/Test.basic b/Test.basic index a7e7862..d4bff56 100644 --- a/Test.basic +++ b/Test.basic @@ -1,9 +1,4 @@ EULER MULTIPLY $ $ -MEMSTORE 0 $ COMPARE $ 7.3890557 -PRINT $ -MULTIPLY 2 3 -PRINT $ -MEMLOAD 0 PRINT $ \ No newline at end of file