The Prolog Target: Implementation and Usage Guide
UnifyWeaver Educational Series
This book provides a comprehensive guide to UnifyWeaver’s Prolog target, covering implementation principles, practical usage, and advanced features like dialect selection and fallback mechanisms.
Table of Contents
Part 1: Fundamentals
- Introduction to the Prolog Target
- What is the Prolog target?
- Why transpile Prolog to Prolog?
- Use cases and benefits
- Architecture Overview
- The transpilation pipeline
- Core components
- Module structure
- Understanding Prolog Dialects
- SWI-Prolog vs GNU Prolog
- Dialect capabilities and constraints
- When to use each dialect
Part 2: Using the Prolog Target
- Basic Usage
- Your first Prolog transpilation
- Generating executable scripts
- Options and configuration
- Compilation vs Interpretation
- Interpreted scripts (SWI-Prolog)
- Compiled binaries (GNU Prolog)
- Choosing the right mode
- Initialization directives
- Dependency Management
- How dependencies are detected
- Module imports
- Partitioner and data source integration
Part 3: Advanced Features
- The Firewall System
- Security policies for Prolog targets
- Restricting dialect usage
- Network and file access controls
- Dialect Fallback Mechanisms
- Preference-based dialect selection
- Automatic fallback on compilation failure
- Multi-dialect strategies
- Error handling and recovery
- Validation and Compatibility
- Dialect-specific validation
- Detecting incompatible features
- Compatibility warnings
Part 4: Implementation Deep Dive
- Code Generation Pipeline
- From AST to Prolog source
- Shebang and header generation
- User code transpilation
- Entry point generation
- Dialect-Specific Code
- Initialization directives
- Compile commands
- Import strategies
- Header differences
- Compilation Infrastructure
- The compile_script/2 predicate
- Error detection and reporting
- Safe compilation with fallback
- Exit code handling
Part 5: Practical Applications
- Common Patterns
- Standalone scripts
- Compiled executables
- Library integration
- Testing strategies
- Troubleshooting
- Common errors
- Debugging generated code
- Compilation failures
- Performance considerations
- Case Study: Factorial Compilation
- End-to-end example
- Code walkthrough
- Testing and verification
Appendices
How to Use This Book
- Beginners: Start with Part 1 and 2 to understand the basics
- Users: Focus on Part 2 and 3 for practical usage
- Implementers: Part 4 provides deep implementation details
- Everyone: Part 5 shows real-world applications
Each chapter includes:
- Conceptual explanations
- Code examples
- Practical exercises
- Common pitfalls
Version: UnifyWeaver v0.1
Last Updated: 2025-11-17
Navigation