Skip to content

Conversation

@bpowers
Copy link
Owner

@bpowers bpowers commented Jul 30, 2022

two major pieces here: expanding the lexer + parser to support the full array indexing syntax. Second is supporting the array version of min and max builtins, along with the array-only rank, size, stddev, and sum.

@bpowers bpowers marked this pull request as draft July 30, 2022 16:07
@codecov
Copy link

codecov bot commented Jul 30, 2022

Codecov Report

Attention: 133 lines in your changes are missing coverage. Please review.

Comparison is base (a0ea145) 72.86% compared to head (91a50eb) 77.68%.
Report is 9 commits behind head on main.

❗ Current head 91a50eb differs from pull request most recent head 292a7b2. Consider uploading reports for the commit 292a7b2 to get more accurate results

Files Patch % Lines
src/simlin-engine/src/compiler.rs 17.46% 52 Missing ⚠️
src/simlin-engine/src/builtins.rs 48.64% 38 Missing ⚠️
src/simlin-engine/src/units_check.rs 0.00% 23 Missing ⚠️
src/simlin-engine/src/ast.rs 25.00% 12 Missing ⚠️
src/simlin-engine/src/units_infer.rs 33.33% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #70      +/-   ##
==========================================
+ Coverage   72.86%   77.68%   +4.81%     
==========================================
  Files          25       28       +3     
  Lines        6166     8079    +1913     
==========================================
+ Hits         4493     6276    +1783     
- Misses       1673     1803     +130     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bpowers bpowers force-pushed the sum-and-index-exprs branch 3 times, most recently from 91a50eb to 4e6d550 Compare September 21, 2022 16:15
@bpowers bpowers force-pushed the sum-and-index-exprs branch from 4e6d550 to dfaf219 Compare September 18, 2023 18:49
@bpowers bpowers force-pushed the sum-and-index-exprs branch from 292a7b2 to 45139a4 Compare July 28, 2024 21:23
@bpowers bpowers force-pushed the sum-and-index-exprs branch from 45139a4 to 9904509 Compare November 5, 2024 03:32
@bpowers bpowers force-pushed the sum-and-index-exprs branch 2 times, most recently from 858719d to 60e1d64 Compare March 11, 2025 15:11
@bpowers bpowers force-pushed the sum-and-index-exprs branch 2 times, most recently from 077b3df to b667b0d Compare June 6, 2025 03:24
@bpowers bpowers force-pushed the sum-and-index-exprs branch from b667b0d to 24eaab7 Compare June 6, 2025 03:30
@bpowers bpowers force-pushed the sum-and-index-exprs branch from 42701d3 to ee3d815 Compare June 19, 2025 05:09
bpowers and others added 10 commits June 20, 2025 16:13
This commit implements comprehensive array transposition functionality according
to the XMILE specification, which defines the transpose operator (') as having
the highest arithmetic precedence and reversing all array dimensions.

## Key Changes

### AST and Parser Support
- Added `Transpose` variant to `UnaryOp` enum in ast.rs
- Added `'` (apostrophe) token to lexer and parser (equation.lalrpop, token/mod.rs)
- Implemented `transpose()` method on `DimensionVec` that reverses dimension order
- Updated dimension inference to handle transpose operations correctly

### Compiler and VM Support
- Added AST lowering support for `ast::UnaryOp::Transpose` -> `UnaryOp::Transpose`
- Added `Transpose` opcode to bytecode.rs with VM execution support
- Implemented transpose evaluation in tree-walking interpreter (scalars remain unchanged)
- Updated expression evaluation and array substitution logic
- Added transpose support to pretty printing (outputs `expr'`)

### LaTeX Rendering
- Updated LatexVisitor to handle transpose operations with `expr'` format
- Restructured unary operation handling to support both prefix and suffix operators

### Units Support
- Added transpose handling to units system (transpose preserves units)

### Comprehensive Tests
- Added 5 dimension-level tests: basic 2D transpose, scalar, 1D, 3D, and double transpose
- Added parsing tests for transpose syntax (`a'`)
- Added LaTeX rendering tests
- All tests pass with proper dimension reversal validation

## Technical Details

The implementation follows XMILE v1.0 specification section 3.7.1 which defines
three ways to transpose arrays:
1. Transposition operator (`'`) - implemented here
2. Dimension name reordering - already supported via existing dimension system
3. Dimension position operator (`@`) - future work

For scalars and 1D arrays, transpose is identity operation. For multi-dimensional
arrays, transpose reverses the dimension order (e.g., [A,B,C] becomes [C,B,A]).

## Compliance

This implementation provides the foundation for XMILE-compliant array transposition
while maintaining full backward compatibility with existing functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Split monolithic ast.rs (2,477 lines) into logical modules:
- ast/expr0.rs: Initial parsed expressions (Expr0, IndexExpr0)
- ast/expr1.rs: Builtin-resolved expressions (Expr1, IndexExpr1)
- ast/expr2.rs: Dimension-annotated expressions (Expr, IndexExpr) + dimension types
- ast/mod.rs: Visitors, utilities, and re-exports for backward compatibility

Benefits:
- Improved code organization and navigation
- Logical separation of AST transformation stages
- Dimension types co-located with final expression stage
- Maintained complete API compatibility - all existing imports work unchanged
- All 97 tests continue passing

Updated design/full-array-support.md to document the refactoring and mark
array transposition (item #5) as completed with comprehensive test coverage.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants