Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions FadeBasic/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.37] - 2025-03-02

### Changed
- VM register max count increased from `byte` to `ulong`.
- VM heap max size increased from ~ 2^31 to ~ 2^64.

## [0.0.36] - 2025-02-26

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion FadeBasic/CommandSourceGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ static string GetReturnSource(CommandDescriptor descriptor)
sb.AppendLine($"{nameof(VmConverter)}.{nameof(VmConverter.FromStringSpan)}({result}, out var {resultSpan});");
sb.AppendLine($"{VM}.{nameof(VirtualMachine.heap)}.{nameof(VirtualMachine.heap.AllocateString)}({resultSpan}.Length, out var {resultStrPtr});");
sb.AppendLine($"{VM}.{nameof(VirtualMachine.heap)}.{nameof(VirtualMachine.heap.WriteSpan)}({resultStrPtr}, {resultSpan}.Length, {resultSpan});");
sb.AppendLine($"var {ptrIntBytes} = {nameof(BitConverter)}.{nameof(BitConverter.GetBytes)}({resultStrPtr});");
// sb.AppendLine($"var {ptrIntBytes} = {nameof(BitConverter)}.{nameof(BitConverter.GetBytes)}({resultStrPtr});");
sb.AppendLine($"var {ptrIntBytes} = {nameof(VmPtr)}.{nameof(VmPtr.GetBytes)}(ref {resultStrPtr});");
sb.AppendLine($"{nameof(VmUtil)}.{nameof(VmUtil.PushSpan)}(ref {VM}.{nameof(VirtualMachine.stack)}, {ptrIntBytes}, {TypeCodes.STRING});");


Expand Down
1 change: 0 additions & 1 deletion FadeBasic/FadeBasic/FadeBasic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PackageId>FadeBasic.Lang.Core</PackageId>
<Title>FadeBasic Language Core</Title>
<Description>Fade's actually dotnet embeddable Basic. </Description>

</PropertyGroup>

<ItemGroup Label="Net Standard 2.0 Dependencies" Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
2 changes: 1 addition & 1 deletion FadeBasic/FadeBasic/FadeBasicCommandAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class FromVmAttribute : Attribute
public struct RawArg<T>
{
public T value;
public int address;
public ulong address;
public CommandArgRuntimeState state;
}
}
24 changes: 23 additions & 1 deletion FadeBasic/FadeBasic/Json/IJsonable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public interface IJsonable
void ProcessJson(IJsonOperation op);
}

public interface IJsonableSerializationCallbacks : IJsonable
{
void OnAfterDeserialized();
void OnBeforeSerialize();
}

public interface IJsonOperation
{
void Process(IJsonable jsonable);
Expand Down Expand Up @@ -52,7 +58,7 @@ public static class JsonableExtensions
{
var instance = new T();
var op = new JsonReadOp(json);
instance.ProcessJson(op);
op.Process(instance);
return instance;
}

Expand Down Expand Up @@ -376,7 +382,13 @@ public JsonReadOp(JsonData data)

public void Process(IJsonable jsonable)
{

jsonable.ProcessJson(this);

if (jsonable is IJsonableSerializationCallbacks cbr)
{
cbr.OnAfterDeserialized();
}
}

public void IncludeField(string name, ref int fieldValue)
Expand All @@ -390,6 +402,11 @@ public void IncludeField(string name, ref byte fieldValue)
fieldValue = (byte)byteValue;
}

public void IncludeField(string name, ref ulong fieldValue)
{
throw new NotImplementedException();
}

public void IncludeField(string name, ref bool fieldValue)
{
_data.ints.TryGetValue(name, out var byteValue);
Expand Down Expand Up @@ -538,12 +555,17 @@ void IncludePrim<T>(string name, ref T prim) where T : struct
public void Process(IJsonable jsonable)
{
_sb.Append(JsonConstants.OPEN_BRACKET);
if (jsonable is IJsonableSerializationCallbacks cbr)
{
cbr.OnBeforeSerialize();
}
jsonable.ProcessJson(this);
_sb.Append(JsonConstants.CLOSE_BRACKET);
}

public void IncludeField(string name, ref int fieldValue) => IncludePrim(name, ref fieldValue);
public void IncludeField(string name, ref byte fieldValue) => IncludePrim(name, ref fieldValue);
public void IncludeField(string name, ref ulong fieldValue) => IncludePrim(name, ref fieldValue);

public void IncludeField(string name, ref bool fieldValue)
{
Expand Down
6 changes: 3 additions & 3 deletions FadeBasic/FadeBasic/Launch/DebugSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ void AddVariable(DebugVariable local, bool isGlobal)
{
typeCode = variable.typeCode,
name = local.name,
registerAddress = (byte)variable.regAddr,
registerAddress = variable.regAddr,
byteSize = TypeCodes.GetByteSize(variable.typeCode),
structType = structName,
isGlobal = isGlobal
Expand Down Expand Up @@ -730,7 +730,7 @@ void AddVariable(DebugVariable local, bool isGlobal)
var rankExprs = new IExpressionNode[arrayRankCount];
for (var i = 0; i < arrayRankCount; i++)
{
var rankStrideRegAddr = variable.regAddr + arrayRankCount * 2 - (i * 2) ;
var rankStrideRegAddr = variable.regAddr + (ulong)arrayRankCount * 2 - ((ulong)i * 2) ;
var rankSizeRegAddr = rankStrideRegAddr - 1;
var rankSize = _vm.scopeStack.buffer[variable.scopeIndex]
.dataRegisters[rankSizeRegAddr];
Expand Down Expand Up @@ -1010,7 +1010,7 @@ void AddVariable(DebugVariable local, bool isGlobal)
if (synth.typeCode == TypeCodes.STRUCT)
{
var ptr = _vm.dataRegisters[synth.registerAddress];
if (!_vm.heap.TryGetAllocation((int)ptr, out var alloc))
if (!_vm.heap.TryGetAllocation(VmPtr.FromRaw(ptr), out var alloc))
{
return DebugEvalResult.Failed(
$"invalid heap, reg=[{synth.registerAddress}] data=[{ptr}] which is not a valid heap pointer");
Expand Down
13 changes: 7 additions & 6 deletions FadeBasic/FadeBasic/Sdk/Fade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,11 @@ public bool TryGetString(string name, out string value, out string error)
return false;
}

var address = VmUtil.ConvertToInt(scope.dataRegisters[index]);
var address = VmUtil.ConvertToPtr(scope.dataRegisters[index]);
return TryReadString(address, out value, out error);
}

bool TryReadString(int address, out string value, out string error)
bool TryReadString(VmPtr address, out string value, out string error)
{
value = null;
error = null;
Expand Down Expand Up @@ -514,7 +514,7 @@ private bool TryGetArray<T>(string name, ref FadeArray<T> value, out string erro
}


var address = VmUtil.ConvertToInt(scope.dataRegisters[index]);
var address = VmUtil.ConvertToPtr(scope.dataRegisters[index]);
if (!Machine.heap.TryGetAllocation(address, out var allocation))
{
error = "invalid memory address";
Expand Down Expand Up @@ -592,14 +592,14 @@ public bool TryGetObject(string name, out FadeObject value, out string error)
return false;
}

var address = VmUtil.ConvertToInt(scope.dataRegisters[index]);
var address = VmUtil.ConvertToPtr(scope.dataRegisters[index]);
return TryReadObject(address, out value, out error);

}



bool TryReadObject(int address, out FadeObject value, out string error)
bool TryReadObject(VmPtr address, out FadeObject value, out string error)
{
value = null;
error = null;
Expand Down Expand Up @@ -663,7 +663,8 @@ void ReadMember(ref VmAllocation allocation, int offset, FadeObject value, strin
value.doubleFloatFields[fieldName] = BitConverter.ToDouble(memory, member.Offset + offset);
break;
case TypeCodes.STRING:
var strPtr = BitConverter.ToInt32(memory, member.Offset + offset);
var strPtr = allocation.ptr + member.Offset + offset;
// var strPtr = BitConverter.ToInt32(memory, member.Offset + offset);
TryReadString(strPtr, out var strValue, out _);
value.stringFields[fieldName] = strValue;
break;
Expand Down
Loading
Loading