Practical guides for converting Pascal code to Rust, including type mappings and conversion plans.
Last Updated: 2025-11-24
This directory contains practical conversion guides, type mapping references, and specific conversion plans for transforming the Pascal codebase into idiomatic Rust.
Recommended conversion sequence based on dependency analysis
Topological ordering of the 96 Pascal units to ensure dependencies are converted first.
Conversion Phases:
-
Foundation Units (Convert First):
- RECORDS.PAS ✅ Complete (Sprint 5)
- COMMON.PAS
- CONFIG.PAS ✅ Complete (Sprint 4)
- INIT.PAS
-
Core Services:
- USER.PAS ✅ Complete (Sprint 6)
- AUTH.PAS ✅ Complete (Sprint 6)
- SESSION.PAS
- DATABASE.PAS
-
I/O Layer:
- COMMS.PAS (high-risk)
- FOSSIL.PAS (high-risk)
- SERIAL.PAS
-
Business Logic:
- MESSAGE.PAS
- FILE.PAS
- DOOR.PAS
- MENU.PAS
-
UI Layer:
- ANSI.PAS
- TERMINAL.PAS
- SCREEN.PAS
Critical Path: Foundation → Core Services → I/O Layer → Business Logic → UI Layer
Comprehensive Pascal to Rust type mappings
Complete reference for converting Pascal types to Rust equivalents.
Basic Types:
- Byte → u8
- ShortInt → i8
- Word → u16
- Integer → i16
- LongInt → i32
- Char → u8 (ASCII) or char (Unicode)
- Boolean → bool
- Real → f32
- String → String or &str
Structured Types:
- Array → [T; N] or Vec
- Record → struct
- Set → BitFlags or HashSet
- File → std::fs::File
- Text → std::io::BufReader/Writer
Pointer Types:
- Pointer → Box, Rc, Arc
- ^ (Pascal pointer) → &T, &mut T, *const T, *mut T
Special Cases:
- String[N] → String (heap) or [u8; N+1] (stack)
- PChar → *const c_char or CString
- Variant records → enum with data
Type system reconciliation and migration notes
Handling complex type system differences between Pascal and Rust.
Topics:
-
String Handling:
- Pascal length-prefixed strings
- Null-terminated C strings
- Rust UTF-8 strings
- Conversion strategies
-
Memory Layout:
- Record packing in Pascal
- Struct alignment in Rust
- repr(C) for binary compatibility
- Padding and size considerations
-
Pointer Semantics:
- Pascal pointer arithmetic
- Rust references and lifetimes
- Unsafe pointer operations
- Safe abstractions
-
Type Safety:
- Pascal weak typing
- Rust strong typing
- Newtype pattern for type safety
- From/Into trait implementations
Quick reference cheat sheet for common conversions
Fast lookup guide for everyday conversion patterns.
Categories:
- Variable declarations
- Function definitions
- Control flow (if/case/for/while)
- String operations
- File I/O
- Error handling
- Memory management
- Array/collection operations
Format: Side-by-side Pascal and Rust examples.
Example:
{ Pascal }
procedure DoSomething(var x: Integer);
begin
Inc(x);
end;// Rust
fn do_something(x: &mut i32) {
*x += 1;
}Binary data format specifications for Impulse 7.1
Detailed documentation of all binary file formats used by Impulse.
File Formats:
-
USER.LST: User database format
- PascalUserRec structure (293 bytes)
- Field layouts and offsets
- String encoding
- Binary compatibility requirements
-
MESSAGE.DAT: Message base format
- JAM format specification
- Hudson format specification
- Message header structure
- Index file format
-
FILE.DAT: File area catalog
- FileEntry structure
- File description format
- Upload/download tracking
-
CONFIG.DAT: BBS configuration
- BbsConfig structure
- Default values
- Validation rules
Conversion Strategy:
- Use binrw crate for binary I/O
- repr(C) for layout control
- Explicit padding for alignment
- Endianness handling
- Round-trip testing
Detailed conversion plan for RECORDS.PAS ✅ Complete
Post-completion reference documenting the RECORDS.PAS conversion.
Completed Sprint 5:
- 11 Pascal record types converted
- 195 tests implemented
- Binary compatibility validated
- Round-trip serialization tested
Conversion Approach:
- Modern Rust types (User, FileEntry, Message, BbsConfig)
- Pascal compatibility types (PascalUserRec, etc.)
- Conversion traits (from_pascal, to_pascal)
- Serialization support (serde, binrw)
Lessons Learned:
- Start with type definitions
- Implement Pascal compatibility layer
- Comprehensive serialization tests
- Document binary format explicitly
- Read Analysis: Check pascal-unit-analysis.md
- Check Dependencies: Verify all dependencies converted
- Review Types: Consult type-mapping.md
- Assess Risk: Check risk-assessment docs
- Plan Tests: Identify test cases
- Semantic Rewrite: Understand intent, not literal translation
- Modern Idioms: Use Rust best practices
- Type Safety: Leverage Rust's type system
- Error Handling: Use Result<T, E> not error codes
- Documentation: rustdoc for all public APIs
- Tests: Unit tests for all functionality
- Code Review: Minimum 2 reviewers
- Integration Tests: Test with dependent modules
- Binary Compatibility: Validate data format compatibility
- Performance: Benchmark against Pascal (if relevant)
- Documentation: Update conversion docs
Unit Tests:
- Test each function in isolation
- Cover edge cases and error conditions
- Property-based tests for invariants
Integration Tests:
- Test module interactions
- Validate data flow
- Ensure API contracts met
Compatibility Tests:
- Read Pascal-generated files
- Write files Pascal can read
- Round-trip serialization
- Binary format validation
Regression Tests:
- Compare behavior to Pascal reference
- Test vectors from original
- Edge cases from original code
- Analysis - Pascal source code analysis
- Risk Assessment - Conversion risks
- Planning - Sprint plans and schedule
- Implementation - Development guides