diff --git a/exp/Exp.cs b/exp/Exp.cs new file mode 100644 index 0000000..bb86539 --- /dev/null +++ b/exp/Exp.cs @@ -0,0 +1,99 @@ +using System.Collections.Immutable; +using System.Runtime.CompilerServices; +using imm; + +namespace exp; + + +abstract public record class Exp : imm.Versioned> +{ + protected Exp() + : + base() + { + + } + + abstract public T exec(); +} + +public record class ConstantExp( T value ) : Exp +{ + public override T exec() => value; +} + +public record class VarExp : Exp +{ + + public T val = default!; + + public VarExp() + { + } + + public override T exec() => val; + + public VarExp set( T newVal ) + { + return this with { val = newVal }; + } +} + +public ref struct RefHolder +{ + public T val = default!; + + public RefHolder() + { + } + + public RefHolder( T initial ) + { + val = initial; + } +} + + +/* + +public record class Op( EntityId id, Func fn, + [CallerMemberName] string dbgMethod = "", + [CallerFilePath] string dbgPath = "", + [CallerLineNumber] int dbgLine = 0, + [CallerArgumentExpression("fn")] + string dbgExp = "" +) : Exp +{ + 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( VarExp BaseVal ) : Exp +{ + public VarExp ModValue = BaseVal; + + public ImmutableArray> Adds = ImmutableArray>.Empty; + public ImmutableArray> Mults = ImmutableArray>.Empty; + + public override T exec() + { + return ModValue.exec(); + } +} + + + + + + +/// // + + diff --git a/logging/Log.cs b/logging/Log.cs index 2077aa1..839a030 100644 --- a/logging/Log.cs +++ b/logging/Log.cs @@ -55,6 +55,7 @@ public struct SourceLoc readonly string _reason = ""; readonly string _dbgName = ""; readonly string _dbgPath = ""; + readonly string _dbgFile = ""; readonly int _dbgLine = -1; public SourceLoc( string reason, string dbgName, string dbgPath, int dbgLine ) @@ -63,8 +64,12 @@ public struct SourceLoc _dbgName = dbgName; _dbgPath = dbgPath; _dbgLine = dbgLine; + + _dbgFile = log.whatFile( dbgPath ); } + public string ToLogString() => $"{_dbgFile}.{_dbgName}"; + static public SourceLoc Record( string reason = "", [CallerMemberName] string dbgName = "", @@ -285,8 +290,8 @@ static public class log static ImmutableDictionary s_files = ImmutableDictionary.Empty; #region Util - static public (string, string, int) record( [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) - => (dbgName, dbgPath, dbgLine); + static public SourceLoc loc( [CallerMemberName] string dbgName = "", [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = -1 ) + => new SourceLoc( "", dbgName, dbgPath, dbgLine ); static public string whatFile( string path )