https://www.beeflang.org/docs/language-guide/comptime/:
- struct IfancyToString should be struct IfancyToStringArrtibute (?)
/* Adding this attribute to a type will generate a 'ToString' method using comptime reflection */
[AttributeUsage(.Types)]
struct IFancyToString : Attribute, IOnTypeInit
{
[Comptime]
public void OnTypeInit(Type type, Self* prev)
{
Compiler.EmitTypeBody(type, "public override void ToString(String str)\n{\n");
for (var fieldInfo in type.GetFields())
{
if (!fieldInfo.IsInstanceField)
continue;
if (@fieldInfo.Index > 0)
Compiler.EmitTypeBody(type, "\tstr.Append(\", \");\n");
Compiler.EmitTypeBody(type, scope $"\tstr.AppendF($\"{fieldInfo.Name}={{ {fieldInfo.Name} }}\");\n");
}
Compiler.EmitTypeBody(type, "}");
}
}
- set shoud be set mut (?)
[AttributeUsage(.Field | .StaticField)]
struct RangedAccessorAttribute : this(int minVal, int maxVal), Attribute, IOnFieldInit
{
[Comptime]
public void OnFieldInit(FieldInfo fieldInfo, Self* prev) mut
{
Compiler.EmitTypeBody(fieldInfo.DeclaringType, scope $"""
public {(fieldInfo.IsStatic ? "static" : "")} {fieldInfo.FieldType} Ranged{fieldInfo.Name}
{{
get => {fieldInfo.Name};
set
{{
System.Runtime.Assert((value >= {minVal}) && (value <= {maxVal}));
{fieldInfo.Name} = value;
}}
}}
""");
}
}
/* Creates a 'RangedVal' property wrapping 'Val' that only allows values of 10 through 20 */
[RangedAccessor(10, 20)]
static int Val;
- String emit=scope $"Logger.Log($ " ..." change to String emit=scope $ "Logger.Log(scope $"....),that is ,one more
scope inside Log()
/* Adding this attribute to a method will log method entry and returned Result<T> errors */
[AttributeUsage(.Method)]
struct LogAttribute : Attribute, IOnMethodInit
{
[Comptime]
public void OnMethodInit(MethodInfo method, Self* prev)
{
String emit = scope $"Logger.Log($\"Called {method}";//<---scope $"Logger.Log(scope $\"...
for (var fieldIdx < method.ParamCount)
emit.AppendF($" {{ {method.GetParamName(fieldIdx)} }}");
emit.Append("\\n\");");
Compiler.EmitMethodEntry(method, emit);
if (var genericType = method.ReturnType as SpecializedGenericType)
{
if ((genericType.UnspecializedType == typeof(Result<>)) || (genericType.UnspecializedType == typeof(Result<,>)))
{
Compiler.EmitMethodExit(method, """
if (@return case .Err)
Logger.Log($"Error: {@return}");//<----- Logger.Log(scope $"...
""");
}
}
}
}
BTW,may I ask how to make use of Beefy2D library?I tried a demo with AI help,it compiled,ran but then crashed after a flash of the main window with below error message:
float4 VS(float4 pos : POSITION
**** FATAL APPLICATION ERROR ****
FATAL ERROR
Vertex shader load failed: error X3501: 'VS': entrypoint not found
in C:\Jenkins\workspace\Beef\BeefySysLib\platform\win\DXRenderDevice.cpp:301
Thanks for the help in advance.
https://www.beeflang.org/docs/language-guide/comptime/:
scopeinside Log()BTW,may I ask how to make use of Beefy2D library?I tried a demo with AI help,it compiled,ran but then crashed after a flash of the main window with below error message:
Thanks for the help in advance.