UnifyWeaver

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

  1. Introduction to the Prolog Target
    • What is the Prolog target?
    • Why transpile Prolog to Prolog?
    • Use cases and benefits
  2. Architecture Overview
    • The transpilation pipeline
    • Core components
    • Module structure
  3. Understanding Prolog Dialects
    • SWI-Prolog vs GNU Prolog
    • Dialect capabilities and constraints
    • When to use each dialect

Part 2: Using the Prolog Target

  1. Basic Usage
    • Your first Prolog transpilation
    • Generating executable scripts
    • Options and configuration
  2. Compilation vs Interpretation
    • Interpreted scripts (SWI-Prolog)
    • Compiled binaries (GNU Prolog)
    • Choosing the right mode
    • Initialization directives
  3. Dependency Management
    • How dependencies are detected
    • Module imports
    • Partitioner and data source integration

Part 3: Advanced Features

  1. The Firewall System
    • Security policies for Prolog targets
    • Restricting dialect usage
    • Network and file access controls
  2. Dialect Fallback Mechanisms
    • Preference-based dialect selection
    • Automatic fallback on compilation failure
    • Multi-dialect strategies
    • Error handling and recovery
  3. Validation and Compatibility
    • Dialect-specific validation
    • Detecting incompatible features
    • Compatibility warnings

Part 4: Implementation Deep Dive

  1. Code Generation Pipeline
    • From AST to Prolog source
    • Shebang and header generation
    • User code transpilation
    • Entry point generation
  2. Dialect-Specific Code
    • Initialization directives
    • Compile commands
    • Import strategies
    • Header differences
  3. Compilation Infrastructure
    • The compile_script/2 predicate
    • Error detection and reporting
    • Safe compilation with fallback
    • Exit code handling

Part 5: Practical Applications

  1. Common Patterns
    • Standalone scripts
    • Compiled executables
    • Library integration
    • Testing strategies
  2. Troubleshooting
    • Common errors
    • Debugging generated code
    • Compilation failures
    • Performance considerations
  3. Case Study: Factorial Compilation
    • End-to-end example
    • Code walkthrough
    • Testing and verification

Appendices


How to Use This Book

Each chapter includes:


Version: UnifyWeaver v0.1 Last Updated: 2025-11-17


📖 Book 11: Prolog Target Next: Chapter 1: Introduction to the Prolog Target →