Refactor unnamed tuple into a struct
This commit is contained in:
parent
ce75909b8b
commit
5e8bb3acfc
99
exp/Exp.cs
Normal file
99
exp/Exp.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using imm;
|
||||||
|
|
||||||
|
namespace exp;
|
||||||
|
|
||||||
|
|
||||||
|
abstract public record class Exp<T> : imm.Versioned<Exp<T>>
|
||||||
|
{
|
||||||
|
protected Exp()
|
||||||
|
:
|
||||||
|
base()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract public T exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
public record class ConstantExp<T>( T value ) : Exp<T>
|
||||||
|
{
|
||||||
|
public override T exec() => value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record class VarExp<T> : Exp<T>
|
||||||
|
{
|
||||||
|
|
||||||
|
public T val = default!;
|
||||||
|
|
||||||
|
public VarExp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override T exec() => val;
|
||||||
|
|
||||||
|
public VarExp<T> set( T newVal )
|
||||||
|
{
|
||||||
|
return this with { val = newVal };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ref struct RefHolder<T>
|
||||||
|
{
|
||||||
|
public T val = default!;
|
||||||
|
|
||||||
|
public RefHolder()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public RefHolder( T initial )
|
||||||
|
{
|
||||||
|
val = initial;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
public record class Op<T>( EntityId id, Func<Entity, T> fn,
|
||||||
|
[CallerMemberName] string dbgMethod = "",
|
||||||
|
[CallerFilePath] string dbgPath = "",
|
||||||
|
[CallerLineNumber] int dbgLine = 0,
|
||||||
|
[CallerArgumentExpression("fn")]
|
||||||
|
string dbgExp = ""
|
||||||
|
) : Exp<T>
|
||||||
|
{
|
||||||
|
public override T exec()
|
||||||
|
{
|
||||||
|
var ent = ent.Entity.Get( id );
|
||||||
|
if( ent == null )
|
||||||
|
throw new System.Exception( $"Op<{typeof(T).Name}>: Entity {id} not found" );
|
||||||
|
|
||||||
|
return fn( ent );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public record class StackExp<T>( VarExp<T> BaseVal ) : Exp<T>
|
||||||
|
{
|
||||||
|
public VarExp<T> ModValue = BaseVal;
|
||||||
|
|
||||||
|
public ImmutableArray<Exp<T>> Adds = ImmutableArray<Exp<T>>.Empty;
|
||||||
|
public ImmutableArray<Exp<T>> Mults = ImmutableArray<Exp<T>>.Empty;
|
||||||
|
|
||||||
|
public override T exec()
|
||||||
|
{
|
||||||
|
return ModValue.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// //
|
||||||
|
|
||||||
|
|
||||||
@ -55,6 +55,7 @@ public struct SourceLoc
|
|||||||
readonly string _reason = "";
|
readonly string _reason = "";
|
||||||
readonly string _dbgName = "";
|
readonly string _dbgName = "";
|
||||||
readonly string _dbgPath = "";
|
readonly string _dbgPath = "";
|
||||||
|
readonly string _dbgFile = "";
|
||||||
readonly int _dbgLine = -1;
|
readonly int _dbgLine = -1;
|
||||||
|
|
||||||
public SourceLoc( string reason, string dbgName, string dbgPath, int dbgLine )
|
public SourceLoc( string reason, string dbgName, string dbgPath, int dbgLine )
|
||||||
@ -63,8 +64,12 @@ public struct SourceLoc
|
|||||||
_dbgName = dbgName;
|
_dbgName = dbgName;
|
||||||
_dbgPath = dbgPath;
|
_dbgPath = dbgPath;
|
||||||
_dbgLine = dbgLine;
|
_dbgLine = dbgLine;
|
||||||
|
|
||||||
|
_dbgFile = log.whatFile( dbgPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string ToLogString() => $"{_dbgFile}.{_dbgName}";
|
||||||
|
|
||||||
static public SourceLoc Record(
|
static public SourceLoc Record(
|
||||||
string reason = "",
|
string reason = "",
|
||||||
[CallerMemberName] string dbgName = "",
|
[CallerMemberName] string dbgName = "",
|
||||||
@ -285,8 +290,8 @@ static public class log
|
|||||||
static ImmutableDictionary<int, string> s_files = ImmutableDictionary<int, string>.Empty;
|
static ImmutableDictionary<int, string> s_files = ImmutableDictionary<int, string>.Empty;
|
||||||
|
|
||||||
#region Util
|
#region Util
|
||||||
static public (string, string, int) record( [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 )
|
static public SourceLoc loc( [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 )
|
||||||
=> (dbgName, dbgPath, dbgLine);
|
=> new SourceLoc( "", dbgName, dbgPath, dbgLine );
|
||||||
|
|
||||||
|
|
||||||
static public string whatFile( string path )
|
static public string whatFile( string path )
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user