Skip to content

Commit

Permalink
Feat: added dump command
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdelahunt committed Aug 28, 2021
1 parent df36999 commit c40d516
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
3 changes: 2 additions & 1 deletion kasic/Commands/CommandRegister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static CommandRegister()

// string
RegisterCommand(new Replace());

RegisterCommand(new Dump());

// IO
RegisterCommand(new Write());

Expand Down
36 changes: 36 additions & 0 deletions kasic/Commands/Dump.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using kasic.Kasic;
using kasic.Logging;
using kasic.Memory;
using kasic.Utils;
using OperationResult;
using System.Web;

namespace kasic.Commands
{
public class Dump : Command
{
public Dump() : base("dump")
{
CommandSettings = new CommandSettings()
{
MinArgs = 0,
MaxArgs = 0,
ArgumentList = new ArgumentList(new List<KasicType>()),
ReturnType = KasicType.STRING,
};
}

public override Result<IReturnObject, KasicError> Run(Context context, Arguments arguments, List<string> flags)
{
var json =JsonSerializer.Serialize(
Heap.Dump, typeof(List<HeapObject>),
new JsonSerializerOptions() {WriteIndented = flags.Contains("-i")}
);
return new ReturnObject(this, json);
}
}
}
14 changes: 9 additions & 5 deletions kasic/Memory/Heap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Serialization;
using kasic.Commands;
using kasic.Kasic;
using kasic.Logging;
Expand Down Expand Up @@ -81,14 +82,17 @@ public static HeapObject GetByObjectId(int id)
Debug.Assert(heap.Count > id && id != -1);
return heap[id];
}

public static List<HeapObject> Dump => heap;
}

[Serializable]
public struct HeapObject
{
public int ObjectId;
public string Name;
public KasicType Type;
public object Data;
public bool Const;
public int ObjectId { get; set; }
public string Name { get; set; }
public KasicType Type { get; set; }
public object Data { get; set; }
public bool Const { get; set; }
}
}

0 comments on commit c40d516

Please sign in to comment.