View Source cure_cli (cure v0.1.0)
Cure Programming Language - Command Line Interface
This module provides a comprehensive command-line interface for the Cure programming language compiler. It handles argument parsing, file compilation, and the complete compilation pipeline from Cure source code to BEAM bytecode.
Features
- Complete CLI Interface: Argument parsing with support for all compiler options
 - Full Compilation Pipeline: Lexing → Parsing → Type Checking → Optimization → Code Generation
 - Error Handling: Comprehensive error reporting with optional debug information
 - Multiple Output Formats: Support for different output directories and file formats
 - Integration Ready: Designed for use with build systems and IDEs
 
Usage
cure input.cure                    # Compile with defaults
cure input.cure -o output.beam     # Specify output file
cure input.cure --verbose          # Enable verbose output
cure input.cure --no-optimize      # Disable optimizations
Command Line Options
-o, --output FILE- Output .beam file path-d, --output-dir DIR- Output directory (default:_build/ebin)--verbose- Enable verbose compilation output--no-debug- Disable debug information in output--no-warnings- Suppress compiler warnings--no-type-check- Skip type checking phase--no-optimize- Disable type-directed optimizations--help, -h- Show help information--version, -v- Show version information
Environment Variables
CURE_DEBUG=1- Enable detailed debug output including stack traces
Error Codes
0- Success1- Compilation or runtime error2- Usage error (invalid arguments)
Summary
Functions
Verify that all required Cure compiler modules are available.
Compile a .cure file with default compilation options.
Compile a .cure file with specified compilation options.
Convert CLI compilation options to code generation options.
Ensure that the Cure standard library is available and compiled.
Extract module information from an Abstract Syntax Tree.
Display comprehensive help information for the Cure compiler.
Main entry point for the Cure compiler when used as an escript.
Display version and system information for the Cure compiler.
Functions
Verify that all required Cure compiler modules are available.
This function checks for the presence of core compiler modules to ensure the Cure installation is complete and functional.
Required Modules
cure_lexer- Tokenization enginecure_parser- AST generationcure_typechecker- Type checking systemcure_codegen- Code generation
Returns
ok- All required modules are present{error, {missing_modules, List}}- Some modules are missing
Side Effects
Prints warning messages if modules are missing, including
instructions to run make all to build the complete compiler.
Usage
This function is called internally to validate the compiler state before attempting compilation operations.
Compile a .cure file with default compilation options.
Arguments
Filename- Path to the .cure source file to compile
Returns
{ok, OutputFile}- Successful compilation with output file path{error, Reason}- Compilation failed with error details
Examples
compile_file("examples/hello.cure").
% => {ok, "_build/ebin/hello.beam"}
  Compile a .cure file with specified compilation options.
This is the main compilation entry point that supports all compiler features including type checking, optimizations, and custom output options.
Arguments
Filename- Path to the .cure source file to compileOptions- Compilation options record with fields:output_file- Custom output file path (optional)output_dir- Output directory (default: "_build/ebin")debug_info- Include debug information (default: true)warnings- Show warnings (default: true)verbose- Verbose output (default: false)type_check- Enable type checking (default: true)optimize- Enable optimizations (default: true)fsm_runtime- Include FSM runtime (default: true)
Returns
{ok, OutputFile}- Successful compilation{error, Reason}- Compilation error with detailed reason
Compilation Pipeline
The function executes a complete 5-stage pipeline:
- Lexical Analysis - Tokenize source code
 - Parsing - Build Abstract Syntax Tree
 - Type Checking - Verify types and constraints (optional)
 - Optimization - Type-directed optimizations (optional)
 - Code Generation - Generate BEAM bytecode
 
Examples
% Compile with verbose output
Options = #compile_options{verbose = true},
compile_file("src/math.cure", Options).
% Compile without optimizations  
Options = #compile_options{optimize = false},
compile_file("debug.cure", Options).
% Custom output file
Options = #compile_options{output_file = "custom.beam"},
compile_file("input.cure", Options).
  Convert CLI compilation options to code generation options.
This function transforms the user-facing compilation options into the internal format expected by the code generation modules.
Arguments
Options- Compilation options record
Returns
- List of 
{Key, Value}tuples for the code generator 
Option Mapping
debug_info→{debug_info, true}optimize→{optimize, 1}warnings→{warnings, true}fsm_runtime→{fsm_integration, true}
Ensure that the Cure standard library is available and compiled.
This function checks if the standard library BEAM files exist, and if not, attempts to compile them automatically.
Arguments
Options- Compilation options including verbosity settings
Returns
ok- Standard library is available{error, Reason}- Standard library compilation failed
Side Effects
- May invoke 
make stdlibto compile missing standard library - Prints progress messages if verbose mode is enabled
 
Extract module information from an Abstract Syntax Tree.
Extracts comprehensive metadata from compiled modules including:
- Module name
 - Exported functions with arities
 - Imported modules
 - Type definitions
 - FSM definitions
 - Function count
 
Arguments
AST- Abstract Syntax Tree from the parser (list of items or single module_def)
Returns
- Map with module information:
name- Module name (atom or 'unknown')exports- List of exported function specs with name/arityimports- List of imported module namesfunctions- List of function names defined in moduletypes- List of type definition namesfsms- List of FSM definition namesfunction_count- Total number of functionstype_count- Total number of typesfsm_count- Total number of FSMstype- Module type ('module' or 'unknown')
 
Example
AST = cure_parser:parse_file("MyModule.cure"),
Info = get_module_info(AST),
% => #{name => 'MyModule', exports => [{hello, 1}], ...}
  Display comprehensive help information for the Cure compiler.
Outputs usage instructions, command-line options, examples, and environment variables to assist users in using the compiler effectively.
Output Format
- Usage: Basic command syntax
 - Arguments: Required input file specification
 - Options: All available command-line flags with descriptions
 - Examples: Common usage patterns
 - Environment: Relevant environment variables
 
Main entry point for the Cure compiler when used as an escript.
This function processes command line arguments and orchestrates the entire compilation process. It handles all user-facing errors and exits with appropriate status codes.
Arguments
Args- List of command line arguments as strings
Exit Codes
0- Successful compilation1- Compilation error or internal error2- Usage error (invalid arguments)
Examples
% These calls happen automatically when using the CLI:
main(["input.cure"]).
main(["input.cure", "-o", "output.beam"]).
main(["--help"]).Error Handling
All exceptions are caught and converted to user-friendly error messages.
When CURE_DEBUG=1 is set, full stack traces are displayed for debugging.
Display version and system information for the Cure compiler.
Shows the current Cure compiler version, Erlang/OTP version, and a brief description of the Cure programming language.
Output Information
- Cure Version: Current compiler version (from 
?CURE_VERSION) - Erlang/OTP Version: Version of the runtime platform
 - Description: Brief overview of Cure language features
 
Example Output
Cure Programming Language Compiler v0.1.0
Built with Erlang/OTP 25
Cure is a dependently-typed functional programming language
for the BEAM virtual machine with built-in finite state machines.