sharplib/exp/Exp.cs

100 lines
1.5 KiB
C#

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();
}
}
/// //