diff --git a/Qrakhen.Qamp.Core/Execution/Runner.cs b/Qrakhen.Qamp.Core/Execution/Runner.cs
index 8e67db6..66e1909 100644
--- a/Qrakhen.Qamp.Core/Execution/Runner.cs
+++ b/Qrakhen.Qamp.Core/Execution/Runner.cs
@@ -10,9 +10,12 @@ namespace Qrakhen.Qamp.Core.Execution;
using Op = OpCode;
+///
+/// Dynamic Pointer able to point to any object implementing the interface.
+///
public class Pointer
{
- public IGetSet Target;
+ protected IGetSet Target;
public long Ptr;
public Pointer(IGetSet target, long pointer = 0)
@@ -21,17 +24,30 @@ public class Pointer
Ptr = pointer;
}
+ ///
+ /// Returns the next item from and increases the pointer by 1.
+ ///
public T Next() => Target.Get(Ptr++);
- public void Set(long position, T value)
- {
- Target.Set(position, value);
- }
+ ///
+ /// Sets the value of at .
+ ///
+ public void Set(long position, T value) => Target.Set(position, value);
- public T Get(long position)
- {
- return Target.Get(position);
- }
+ ///
+ /// Sets the value of at the current location.
+ ///
+ public void Set(T value) => Set(Ptr, value);
+
+ ///
+ /// Gets the value of at .
+ ///
+ public T Get(long position) => Target.Get(position);
+
+ ///
+ /// Gets the value of at the current location.
+ ///
+ public T Get() => Get(Ptr);
}
// this is all a bit cheesy imho
@@ -94,13 +110,13 @@ public class InstructionPtr : Pointer
public class Call
{
public Closure Closure;
- public InstructionPtr Ptr;
+ public InstructionPtr Instruction;
public Pointer StackPtr;
public Call(Closure closure, StackLike stack, long stackOffset)
{
Closure = closure;
- Ptr = new InstructionPtr(Closure.Function.Segment);
+ Instruction = new InstructionPtr(Closure.Function.Segment);
StackPtr = new Pointer(stack, stackOffset);
}
}
@@ -152,10 +168,10 @@ public class Runner : IDisposable
_logger.Method();
Call call = Calls.Peek(-1);
do {
- Op opCode = call.Ptr.Next();
+ Op opCode = call.Instruction.Next();
_logger.Verbose($"OpCode: {opCode}");
switch (opCode) {
- case Op.Constant: Push(call.Ptr.NextConstant()); break;
+ case Op.Constant: Push(call.Instruction.NextConstant()); break;
case Op.Pop: Pop(); break;
case Op.Not: OpNot(); break;
@@ -173,21 +189,21 @@ public class Runner : IDisposable
case Op.BitwiseRight: OpBitwiseRight(); break;
case Op.GetLocal: {
- long slot = call.Ptr.NextDynamic();
+ long slot = call.Instruction.NextDynamic();
_logger.Verbose($"getting slot {slot} which is {call.StackPtr.Get(slot)}");
Push(call.StackPtr.Get(slot));
break;
}
case Op.SetLocal: {
- long slot = call.Ptr.NextDynamic();
+ long slot = call.Instruction.NextDynamic();
_logger.Verbose($"setting stackptr {slot} to {Peek()}");
call.StackPtr.Set(slot, Peek());
break;
}
case Op.DefineGlobal: {
- string? name = call.Ptr.GetString(call.Ptr.NextDynamic())?.Value;
+ string? name = call.Instruction.GetString(call.Instruction.NextDynamic())?.Value;
if (string.IsNullOrEmpty(name))
throw new ExecutionException($"tried to define global variable with empty name");
Globals[name] = Pop();
@@ -196,7 +212,7 @@ public class Runner : IDisposable
}
case Op.SetGlobal: {
- string? name = call.Ptr.GetString(call.Ptr.NextDynamic())?.Value;
+ string? name = call.Instruction.GetString(call.Instruction.NextDynamic())?.Value;
if (string.IsNullOrEmpty(name))
throw new ExecutionException($"tried to set global variable with empty name");
if (!Globals.Has(name))
@@ -206,10 +222,8 @@ public class Runner : IDisposable
break;
}
- // todo: add closure
-
case Op.GetGlobal: {
- string? name = call.Ptr.GetString(call.Ptr.NextDynamic())?.Value;
+ string? name = call.Instruction.GetString(call.Instruction.NextDynamic())?.Value;
if (string.IsNullOrEmpty(name))
throw new ExecutionException($"tried to set global variable with empty name");
if (!Globals.Has(name))
@@ -246,7 +260,7 @@ public class Runner : IDisposable
break;
}
- } while (call.Ptr.Segment.Instructions.Length > call.Ptr.Ptr);
+ } while (call.Instruction.Segment.Instructions.Length > call.Instruction.Ptr);
return ExecutionResult.OK;
}