Przeglądaj źródła

Made memory conditional

master
Ludovic 'Archivist' Lagouardette 3 lat temu
rodzic
commit
790dee561c
5 zmienionych plików z 20 dodań i 7 usunięć
  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 Wyświetl plik

@ -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();

+ 2
- 0
Functions/Memory.cs Wyświetl plik

@ -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
}

+ 4
- 1
Parser.cs Wyświetl plik

@ -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));
}

+ 10
- 1
Program.cs Wyświetl plik

@ -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)
{

+ 0
- 5
Test.basic Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz