Skip to content

Commit

Permalink
feat: cairo1 run sierra program
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 committed Jan 8, 2024
1 parent b020f11 commit 0c4bcba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: `cairo1-run` accepts Sierra programs [#1544](https://github.com/lambdaclass/cairo-vm/pull/1544)

#### [1.0.0-rc0] - 2024-1-5

* feat: Use `ProjectivePoint` from types-rs in ec_op builtin impl [#1532](https://github.com/lambdaclass/cairo-vm/pull/1532)
Expand Down
2 changes: 1 addition & 1 deletion cairo1-run/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Now that you have the dependencies necessary to run the tests, you can run:
make test
```

To execute a cairo 1 program
To execute a cairo 1 program (you can also execute Sierra program)
```bash
cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo
```
Expand Down
19 changes: 13 additions & 6 deletions cairo1-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,20 @@ impl FileWriter {
fn run(args: impl Iterator<Item = String>) -> Result<Vec<MaybeRelocatable>, Error> {
let args = Args::try_parse_from(args)?;

let compiler_config = CompilerConfig {
replace_ids: true,
..CompilerConfig::default()
// Try to parse the file as a sierra program
let file = std::fs::read_to_string(&args.filename)?;
let sierra_program = match cairo_lang_sierra::ProgramParser::new().parse(&file) {
Ok(program) => program.into(),

Check warning on line 178 in cairo1-run/src/main.rs

View check run for this annotation

Codecov / codecov/patch

cairo1-run/src/main.rs#L178

Added line #L178 was not covered by tests
Err(_) => {
// If it fails, try to compile it as a cairo program
let compiler_config = CompilerConfig {
replace_ids: true,
..CompilerConfig::default()
};
compile_cairo_project_at_path(&args.filename, compiler_config)
.map_err(|err| Error::SierraCompilation(err.to_string()))?
}
};
let sierra_program = (*compile_cairo_project_at_path(&args.filename, compiler_config)
.map_err(|err| Error::SierraCompilation(err.to_string()))?)
.clone();

let metadata_config = Some(Default::default());

Expand Down

0 comments on commit 0c4bcba

Please sign in to comment.