Crates.io | air-script |
lib.rs | air-script |
version | 0.3.0 |
source | src |
created_at | 2022-11-10 22:24:21.276265 |
updated_at | 2023-07-12 23:57:17.668096 |
description | AirScript language compiler |
homepage | |
repository | https://github.com/0xPolygonMiden/air-script |
max_upload_size | |
id | 712446 |
size | 271,106 |
This crate aggregates all components of the AirScript compiler into a single place. Specifically, it re-exports functionality from the parser, ir, and winterfell code generator crates. Additionally, when compiled as an executable, this crate can be used via a CLI to transpile AIRs defined in AirScript to a specified target language.
An in-depth description of AirScript is available in the full AirScript documentation.
The compiler has three stages, which can be imported and used independently or together.
AirIR
into a specific target language
Example usage:
use air_script::{Air, parse, passes, Pass, transforms, WinterfellCodeGenerator};
use miden_diagnostics::{
term::termcolor::ColorChoice, CodeMap, DefaultEmitter, DiagnosticsHandler,
};
// Used for diagnostics reporting
let codemap = Arc::new(CodeMap::new());
let emitter = Arc::new(DefaultEmitter::new(ColorChoice::Auto));
let diagnostics = DiagnosticsHandler::new(Default::default(), codemap.clone(), emitter);
// Parse into AST
let ast = parse(&diagnostics, codemap, source.as_str()).expect("parsing failed");
// Lower to IR
let air = {
let mut pipeline = transforms::ConstantPropagation::new(&diagnostics)
.chain(transforms::Inlining::new(&diagnostics))
.chain(passes::AstToAir::new(&diagnostics));
pipeline.run(ast).expect("lowering failed")
};
// Generate Rust code targeting the Winterfell prover
let code = WinterfellCodeGenerator::new(&ir).generate().expect("codegen failed");
An example of an AIR defined in AirScript can be found in the examples/
directory.
To run the full transpilation pipeline, the CLI can be used for convenience.
There is a command-line interface available for transpiling AirScript files. Currently, the only available target is Rust code for use with the Winterfell STARK prover library.
To use the CLI, first run:
cargo build --release
Then, run the airc
target with the transpile
. For example:
./target/release/airc transpile examples/example.air
When no output destination is specified, the output file will use the path and name of the input file, replacing the .air
extension with .rs
. For the above example, examples/example.rs
will contain the generated output.
You can use the help
option to see other available options.
./target/release/airc transpile --help