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