trying to debug stuff
This commit is contained in:
parent
0da1c14ed7
commit
501a4af636
10 changed files with 375 additions and 110 deletions
|
@ -2,5 +2,4 @@ FileVersion = 1
|
|||
|
||||
[Project]
|
||||
Name = "Bofa"
|
||||
TargetType = "BeefLib"
|
||||
StartupObject = "Bofa.Program"
|
||||
|
|
66
src/Bofa.bf
66
src/Bofa.bf
|
@ -5,7 +5,18 @@ using System.Collections;
|
|||
|
||||
class Bofa
|
||||
{
|
||||
private String _line = null; //The actual line
|
||||
private String __line = null; //The actual line
|
||||
private String _line
|
||||
{
|
||||
get
|
||||
{
|
||||
return __line;
|
||||
}
|
||||
set
|
||||
{
|
||||
__line = value;
|
||||
}
|
||||
}
|
||||
private Bofa _lastObject = null; //If we are a container we keep track of the last container inside of us
|
||||
|
||||
public StringView Name;
|
||||
|
@ -136,11 +147,13 @@ class Bofa
|
|||
{
|
||||
if(_line != null)
|
||||
delete _line;
|
||||
|
||||
if(Type == .Text)
|
||||
delete Value.Text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ~this()
|
||||
{
|
||||
if(_line != null)
|
||||
|
@ -183,4 +196,55 @@ class Bofa
|
|||
Value.Object[view] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ref Bofa this[int view]
|
||||
{
|
||||
[Checked]
|
||||
get
|
||||
{
|
||||
Runtime.Assert(Type == .Array);
|
||||
Runtime.Assert(Value.Array.Count > view);
|
||||
return ref Value.Array[view];
|
||||
}
|
||||
|
||||
[Unchecked, Inline]
|
||||
get
|
||||
{
|
||||
return ref Value.Array[view];
|
||||
}
|
||||
|
||||
[Checked]
|
||||
set
|
||||
{
|
||||
Runtime.Assert(Type == .Array);
|
||||
Runtime.Assert(Value.Array.Count > view);
|
||||
Value.Array[view] = value;
|
||||
}
|
||||
|
||||
[Unchecked, Inline]
|
||||
set
|
||||
{
|
||||
Value.Array[view] = value;
|
||||
}
|
||||
}
|
||||
|
||||
///Get the value if the object is a container
|
||||
public Result<Bofa> Get(StringView pKey)
|
||||
{
|
||||
if(Type != .Object)
|
||||
return .Err;
|
||||
if(!Value.Object.ContainsKey(pKey))
|
||||
return .Err;
|
||||
return Value.Object[pKey];
|
||||
}
|
||||
|
||||
///Get the value if the object is a container
|
||||
public Result<Bofa> Get(int pIndex)
|
||||
{
|
||||
if(Type != .Array)
|
||||
return .Err;
|
||||
if(!(Value.Array.Count > pIndex))
|
||||
return .Err;
|
||||
return Value.Array[pIndex];
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ class BofaParser
|
|||
while (reader.Peek() case .Ok) //This might technically cause an issue when there is data added to the stream while we where busy processing, but if you hook this up to a network stream you deserve this happening to you
|
||||
{
|
||||
String l = new .();
|
||||
|
||||
if (reader.ReadLine(l) case .Err)
|
||||
{ //Despite data being here, we cannot read it
|
||||
delete l;
|
||||
|
@ -73,6 +74,7 @@ class BofaParser
|
|||
last.Value.Text.Append(scope $"\n{entry.Data.Text}");
|
||||
else
|
||||
pErrors.Add(entry.Line); //Bad text error
|
||||
delete l;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -82,12 +84,11 @@ class BofaParser
|
|||
pErrors.Add(line);
|
||||
delete entry.Data.Bofa;
|
||||
}
|
||||
}
|
||||
if(entry.Type == .Text)
|
||||
else if (entry.Type == .Text)
|
||||
delete l;
|
||||
}
|
||||
line++;
|
||||
}
|
||||
|
||||
return; //Being done normally
|
||||
}
|
||||
|
||||
|
@ -139,7 +140,6 @@ class BofaParser
|
|||
toReturn.Data.Text = line;
|
||||
toReturn.Depth = depth + 1;
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
//We have now assured, that the object we are handling is seemingly a normal one
|
||||
StringView typeName;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using Bofa.Serialization;
|
||||
|
||||
namespace System
|
||||
{
|
||||
static
|
||||
|
@ -7,4 +9,23 @@ namespace System
|
|||
*(T*)(void*)&v
|
||||
}
|
||||
}
|
||||
|
||||
extension Int : IBofaParseable
|
||||
{
|
||||
public bool Serialize(Bofa.Bofa pTarget)
|
||||
{
|
||||
pTarget.Type = .Integer;
|
||||
pTarget.Typename = "Integer";
|
||||
pTarget.Value.Integer = (.)this;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Deserialize(Bofa.Bofa pInput) mut
|
||||
{
|
||||
if(pInput.Type != .Integer)
|
||||
return false;
|
||||
this = (.)pInput.Value.Integer;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
20
src/Program.bf
Normal file
20
src/Program.bf
Normal file
|
@ -0,0 +1,20 @@
|
|||
namespace Bofa;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
class Program
|
||||
{
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
|
||||
Bofa.Testing.Profiling.Profiling_Depth_Testing();
|
||||
Bofa.Testing.Profiling.Profiling_Depth_Testing_Medium();
|
||||
Bofa.Testing.Profiling.Profiling_Normal();
|
||||
Bofa.Testing.Profiling.Profiling_Normal_Medium();
|
||||
Bofa.Testing.Profiling.Profiling_Normal_Large();
|
||||
Bofa.Testing.Profiling.Profiling_Texts();
|
||||
Bofa.Testing.Profiling.Profiling_Texts_Large();
|
||||
}
|
||||
}
|
13
src/Serialization/BofaIncludeAttribute.bf
Normal file
13
src/Serialization/BofaIncludeAttribute.bf
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace Bofa.Serialization;
|
||||
|
||||
using System;
|
||||
|
||||
struct BofaIncludeAttribute : Attribute
|
||||
{
|
||||
public StringView Name;
|
||||
|
||||
public this(StringView pName)
|
||||
{
|
||||
Name = pName;
|
||||
}
|
||||
}
|
112
src/Serialization/BofaSerializeAttribute.bf
Normal file
112
src/Serialization/BofaSerializeAttribute.bf
Normal file
|
@ -0,0 +1,112 @@
|
|||
namespace Bofa.Serialization;
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using Bofa;
|
||||
|
||||
[AttributeUsage(.Struct | .Class)]
|
||||
struct BofaSerializeAttribute : Attribute, IOnTypeInit
|
||||
{
|
||||
[Comptime]
|
||||
public void OnTypeInit(Type type, Self* prev)
|
||||
{
|
||||
String serializeString = scope .("public bool Serialize(Bofa b)\n{\n");
|
||||
String deserializeString = scope .("public bool Deserialize(Bofa b)\n{\n");
|
||||
|
||||
serializeString.Append("""
|
||||
b.Type = .Object;
|
||||
b.Value.Object = new .();
|
||||
b.Typename = "Object";
|
||||
Bofa toAdd;
|
||||
|
||||
""");
|
||||
|
||||
deserializeString.Append("""
|
||||
if(b.Type != .Object)
|
||||
return false;
|
||||
|
||||
""");
|
||||
|
||||
|
||||
var fields = type.GetFields();
|
||||
for(var f in fields)
|
||||
{
|
||||
if(!f.IsPublic && !f.HasCustomAttribute<BofaIncludeAttribute>())
|
||||
continue;
|
||||
|
||||
bool hasIFace = false;
|
||||
for(var i in f.FieldType.Interfaces)
|
||||
if(i == typeof(IBofaParseable))
|
||||
hasIFace = true;
|
||||
|
||||
//Hardcoded stuff
|
||||
if(f.FieldType == typeof(int))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(int8))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(int16))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(int32))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(int64))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(uint))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(uint8))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(uint16))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(uint32))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(uint64))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(char8))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(char16))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(char32))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(float))
|
||||
hasIFace = true;
|
||||
else if(f.FieldType == typeof(double))
|
||||
hasIFace = true;
|
||||
|
||||
if(!hasIFace)
|
||||
continue;
|
||||
|
||||
|
||||
StringView name;
|
||||
name = f.Name;
|
||||
if(f.HasCustomAttribute<BofaIncludeAttribute>() && f.GetCustomAttribute<BofaIncludeAttribute>() case .Ok(let attr))
|
||||
name = attr.Name;
|
||||
|
||||
serializeString.Append(scope $"""
|
||||
toAdd = new .();
|
||||
toAdd.Name = "{name}";
|
||||
if(!{f.Name}.Serialize(toAdd))
|
||||
\{
|
||||
delete toAdd;
|
||||
return false;
|
||||
\}
|
||||
else
|
||||
b.Value.Object.Add("{name}", toAdd);
|
||||
""");
|
||||
|
||||
deserializeString.Append(scope $"""
|
||||
if(!b.Value.Object.ContainsKey("{name}"))
|
||||
return false;
|
||||
if(!{f.Name}.Deserialize(b.Value.Object["{name}"]))
|
||||
return false;
|
||||
""");
|
||||
|
||||
}
|
||||
|
||||
|
||||
serializeString.Append("\n\treturn true;\n}\n");
|
||||
deserializeString.Append("\n\treturn true;\n}\n");
|
||||
Compiler.EmitTypeBody(type, serializeString);
|
||||
Compiler.EmitTypeBody(type, deserializeString);
|
||||
Compiler.EmitAddInterface(type, typeof(IBofaParseable));
|
||||
}
|
||||
}
|
11
src/Serialization/IBofaParseable.bf
Normal file
11
src/Serialization/IBofaParseable.bf
Normal file
|
@ -0,0 +1,11 @@
|
|||
namespace Bofa.Serialization;
|
||||
|
||||
using System;
|
||||
|
||||
interface IBofaParseable
|
||||
{
|
||||
///Serializes the current state of a bofa object, may allocate subobjects to fill
|
||||
public bool Serialize(Bofa pTarget) mut;
|
||||
///Attempt to restore an object from the bofa input state
|
||||
public bool Deserialize(Bofa pInput) mut;
|
||||
}
|
|
@ -7,7 +7,7 @@ using System.Collections;
|
|||
|
||||
class Fuzzing
|
||||
{
|
||||
[Test(Name = "Fuzzing - 10 * 1000000 random characters")]
|
||||
//[Test(Name = "Fuzzing - 10 * 1000000 random characters")]
|
||||
public static void Fuzzin_Random()
|
||||
{
|
||||
for (int i < 10)
|
||||
|
@ -25,7 +25,7 @@ class Fuzzing
|
|||
}
|
||||
}
|
||||
|
||||
[Test(Name = "Fuzzing - 10 * 10000000 random characters")]
|
||||
//[Test(Name = "Fuzzing - 10 * 10000000 random characters")]
|
||||
public static void Fuzzin_Random_Large()
|
||||
{
|
||||
for (int i < 10)
|
||||
|
|
25
src/Testing/Serialization.bf
Normal file
25
src/Testing/Serialization.bf
Normal file
|
@ -0,0 +1,25 @@
|
|||
namespace Bofa.Testing;
|
||||
|
||||
using System;
|
||||
|
||||
using Bofa;
|
||||
using Bofa.Serialization;
|
||||
|
||||
[BofaSerialize]
|
||||
class Serialization
|
||||
{
|
||||
public int anInteger = (.)1;
|
||||
|
||||
[Test]
|
||||
public static void Test()
|
||||
{
|
||||
Serialization s = scope .();
|
||||
Bofa b = scope .();
|
||||
b.Name = "s";
|
||||
s.Serialize(b);
|
||||
|
||||
Console.WriteLine(b.ToString(.. scope .()));
|
||||
//Console.Read();
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue