Browse Source

Made memory conditional

master
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
790dee561c
5 changed files with 20 additions and 7 deletions
  1. +4
    -0
      BasicNumber.cs
  2. +2
    -0
      Functions/Memory.cs
  3. +4
    -1
      Parser.cs
  4. +10
    -1
      Program.cs
  5. +0
    -5
      Test.basic

+ 4
- 0
BasicNumber.cs View File

@ -79,10 +79,14 @@ namespace SuperBASIC
{ {
return runtime.GetRegister(); return runtime.GetRegister();
} }
#if MEMORY
else else
{ {
return Functions.Memory.MemoryGet((short)operand); return Functions.Memory.MemoryGet((short)operand);
} }
#else
return 0;
#endif
} }
public static implicit operator float(BasicNumber v) => v.GetValue(); public static implicit operator float(BasicNumber v) => v.GetValue();

+ 2
- 0
Functions/Memory.cs View File

@ -4,6 +4,7 @@ using System.Text;
namespace SuperBASIC.Functions namespace SuperBASIC.Functions
{ {
#if MEMORY
static class Memory static class Memory
{ {
internal static float[] memory = new float[Int16.MaxValue]; internal static float[] memory = new float[Int16.MaxValue];
@ -53,4 +54,5 @@ namespace SuperBASIC.Functions
throw new Memory.BadMemoryAccess("Could not access requested memory"); throw new Memory.BadMemoryAccess("Could not access requested memory");
} }
} }
#endif
} }

+ 4
- 1
Parser.cs View File

@ -79,6 +79,7 @@ namespace SuperBASIC
c.bytecode.Add(new BasicNumber(runtime, opcode)); c.bytecode.Add(new BasicNumber(runtime, opcode));
foreach (string elem in components.AsSpan(1)) foreach (string elem in components.AsSpan(1))
{ {
#if MEMORY
if (elem.StartsWith("M")) if (elem.StartsWith("M"))
{ {
try 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}"); 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)); c.bytecode.Add(new BasicNumber(runtime));
} }

+ 10
- 1
Program.cs View File

@ -10,15 +10,24 @@ namespace SuperBASIC
try try
{ {
Library lib = new Library(); Library lib = new Library();
#if MEMORY
lib.AddFunction(new Functions.MemoryLoad(), 1, "MEMLOAD"); lib.AddFunction(new Functions.MemoryLoad(), 1, "MEMLOAD");
lib.AddFunction(new Functions.MemoryStore(), 2, "MEMSTORE"); lib.AddFunction(new Functions.MemoryStore(), 2, "MEMSTORE");
#endif
lib.AddFunction(new Functions.Print(), 1, "PRINT"); lib.AddFunction(new Functions.Print(), 1, "PRINT");
lib.AddFunction(new Functions.Multiply(), 2, "MULTIPLY"); lib.AddFunction(new Functions.Multiply(), 2, "MULTIPLY");
lib.AddFunction(new Functions.Compare(), 2, "COMPARE"); lib.AddFunction(new Functions.Compare(), 2, "COMPARE");
lib.AddFunction(new Functions.Pi(), 0, "PI"); lib.AddFunction(new Functions.Pi(), 0, "PI");
lib.AddFunction(new Functions.Euler(), 0, "EULER"); lib.AddFunction(new Functions.Euler(), 0, "EULER");
Runtime r = new Runtime(lib); 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(); r.Run();
} catch (Parser.ParseException e) } catch (Parser.ParseException e)
{ {

+ 0
- 5
Test.basic View File

@ -1,9 +1,4 @@
EULER EULER
MULTIPLY $ $ MULTIPLY $ $
MEMSTORE 0 $
COMPARE $ 7.3890557 COMPARE $ 7.3890557
PRINT $
MULTIPLY 2 3
PRINT $
MEMLOAD 0
PRINT $ PRINT $

Loading…
Cancel
Save