Skip to content

Commit

Permalink
Merge pull request #141 from sine-fdn/num-literal-type-inference
Browse files Browse the repository at this point in the history
Implement limited type inference for numbers
  • Loading branch information
fkettelhoit authored Aug 28, 2024
2 parents cf71661 + 70a73bb commit 7c298f5
Show file tree
Hide file tree
Showing 18 changed files with 840 additions and 1,062 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ The circuits generated by Garble are meant to be executed using a cryptographica
To execute the Millionaire's problem example, first install the `garble` utility, checkout the repository to get the example programs, then run the function inside the repository directory:

```sh
$ cargo install garble_lang
$ cargo install garble_lang --features="bin"
$ git clone [email protected]:sine-fdn/garble-lang.git
$ cd garble-lang
$ garble run garble_examples/millionaires.garble.rs --function=main 10000000u64 10000u64
$ garble run garble_examples/millionaires.garble.rs --function=main 10000000 10000
Richest::IsA
$ garble run garble_examples/millionaires.garble.rs --function=main 100u64 5000000u64
$ garble run garble_examples/millionaires.garble.rs --function=main 100 5000000
Richest::IsB
$ garble run garble_examples/millionaires.garble.rs --function=main 1000u64 1000u64
$ garble run garble_examples/millionaires.garble.rs --function=main 1000 1000
Richest::Tie
```

Expand All @@ -52,8 +52,8 @@ You might need to wrap input or metadata in single quotes if they contain whites

The Garble compiler is relatively straightforward and turns a program `&str` into a `circuit::Circuit` (or aborts with a scan/parse/type error). The different steps and their modules are as follows (with steps 1-4 happening during compile time, step 5 during run time):

1. [`scan.rs`](src/scan.rs) splits a program `&str` into a `token::Token` sequence.
2. [`parse.rs`](src/parse.rs) parses a `token::Token` sequence into an untyped `ast::Program`.
3. [`check.rs`](src/check.rs) type-checks an untyped `ast::Program`, returning a typed `ast::Program`.
4. [`compile.rs`](src/compile.rs) converts a well-typed `ast::Program` into a `circuit::Circuit`.
5. [`eval.rs`](src/eval.rs) executes a `circuit::Circuit` with locally supplied inputs.
1. [`scan.rs`](src/scan.rs) splits a program `&str` into a `token::Token` sequence.
2. [`parse.rs`](src/parse.rs) parses a `token::Token` sequence into an untyped `ast::Program`.
3. [`check.rs`](src/check.rs) type-checks an untyped `ast::Program`, returning a typed `ast::Program`.
4. [`compile.rs`](src/compile.rs) converts a well-typed `ast::Program` into a `circuit::Circuit`.
5. [`eval.rs`](src/eval.rs) executes a `circuit::Circuit` with locally supplied inputs.
2 changes: 1 addition & 1 deletion garble_examples/calculator.garble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn main(values: (u8, u8), op: Op) -> OpResult {
(Op::Mul, (x, y)) => OpResult::Ok(x * y),
(Op::Min, (x, y)) => OpResult::Ok(if x < y { x } else { y }),
(Op::Max, (x, y)) => OpResult::Ok(if x > y { x } else { y }),
(Op::Div, (x, 0u8)) => OpResult::DivByZero,
(Op::Div, (x, 0)) => OpResult::DivByZero,
(Op::Div, (x, y)) => OpResult::Ok(x / y),
}
}
Loading

0 comments on commit 7c298f5

Please sign in to comment.