Crate cranefack[][src]

Expand description

Basic usage

Run program with interpreter

    use cranefack::{parse, optimize_with_config, OptimizeConfig, Interpreter};

    // Parse program
    let mut program = parse("++[<].")?;

    // Optimize with optimization level 2
    optimize_with_config(&mut program, &OptimizeConfig::o2());

    // Create new interpreter reading from stdin and writing to stdout
    let mut interpreter = Interpreter::new(std::io::stdin(), std::io::stdout());

    // Execute program
    interpreter.execute(&program);

Run program with jit

    use cranefack::{parse, optimize_with_config, OptimizeConfig, CompiledJitModule};

    // Parse program
    let mut program = parse("++[<].")?;

    // Create optimization config for level 2
    let opt_level = OptimizeConfig::o2();

    // Optimize with optimization level 2
    optimize_with_config(&mut program, &opt_level);

    // Compile program into module
    let module = CompiledJitModule::new(&program, &opt_level)?;

    // Execute compiled module reading from stdin and writing to stdout
    module.execute(std::io::stdin(), std::io::stdout());

Structs

CompiledJitModule

A compiled program that can be executed

Interpreter

Interpreter to execute a program

OptimizeConfig

Configuration to control optimization of the program

Program

An executable program

Warning

Warning found in a call to analyze

Enums

CompilerError

Jit compilation error

ParserError

Error type for parser related errors

RuntimeError

Runtime errors for interpreter invocations

WarningType

WarningType found in a call to analyze

Traits

CraneFackError

Trait all internal errors must implement

Functions

analyze

Analyze program for possible errors

compile_to_rust

Compile program into a rust file that can be compiled with rustc

optimize

Optimize program with level 2

optimize_with_config

Optimize program

parse

Parse the input source file into an abstract representation