private static BitsValue DoSlotExpression(ref CaseContext ctx, SlotExpression expr, IndexerExpression indexer) { int maxLength = expr.Slot == Slots.In ? ctx.Machine.InputCount : expr.Slot == Slots.Memory ? ctx.Machine.Memory.Capacity : throw new LogicEngineException("Invalid slot", expr); GetRange(ref ctx, indexer, maxLength, out var start, out var end); Span <bool> values = stackalloc bool[end - start]; switch (expr.Slot) { case Slots.In: //ctx.Machine.GetInputs(start, values); break; case Slots.Memory: //ctx.Machine.Memory.Read(start, new BitsValue(values)); break; default: throw new LogicEngineException("Invalid slot on expression", expr); } return(new BitsValue(values)); }
private void GetSlotSize(SlotExpression expr) { LoadMachine(); if (expr.Slot == Slots.In) { Generator.Call(Info.OfPropertyGet <IMachine>(nameof(IMachine.InputCount))); } else if (expr.Slot == Slots.Memory) { LoadMemory(); Generator.Call(Info.OfPropertyGet <IMemory>(nameof(IMemory.Capacity))); } else { throw new LogicEngineException("Invalid slot", expr); } }
private void Visit(SlotExpression expr, Index start = default, Index?end = null) { LoadMachine(); if (expr.Slot == Slots.Memory) { LoadMemory(); } LoadIndex(expr, start); // Calculate range length if (end == null) { Generator.Ldc_I4(1); } else { Generator.Dup(); // Duplicate start index for GetInputs parameter // length = -start + end Generator.Neg(); LoadIndex(expr, end.Value); Generator.Add(); } if (expr.Slot == Slots.In) { Generator.Call(Info.OfMethod <IMachine>(nameof(IMachine.GetInputs), "System.Int32,System.Int32")); } else if (expr.Slot == Slots.Memory) { Generator.Call(Info.OfMethod <IMemory>(nameof(IMemory.Read), "System.Int32,System.Int32")); } else { throw new LogicEngineException("Invalid slot", expr); } ValueToReference(); }
private void LoadIndex(SlotExpression expr, Index idx) { if (idx.FromEnd) { GetSlotSize(expr); } if (idx.Value == null) { Generator.Ldc_I4(0); } else { Visit(idx.Value); BitsValueToNumber(); Generator.Conv <int>(); } if (idx.FromEnd) { Generator.Sub(); } }