Skip to content

Commit

Permalink
Add Sint32 & Sint64 types & libfuncs (#383)
Browse files Browse the repository at this point in the history
* Push progress

* Parse Sint8 result value

* Improve sub test + fix how signed values are compared against vm values

* Clippy

* Improve testing

* Fix

* Try stuff

* Fix typos

* Fix test values

* Add test & fix wide_mul

* First draft of diff libfunc

* Improve test

* Remove old code

* Add test

* Add Sint16 type + libfuncs

* fmt

* Push progress

* Remove uneeded intermidiate variables

* Update code

* Update code

* Add tests for i64 libfuncs

* Adjust test values

* Fix cairo programs

* fmt

* Remove old file

* Fix comment

* Fix comments

* Update code
  • Loading branch information
fmoletta authored Dec 15, 2023
1 parent 3f6f705 commit 3c6d762
Show file tree
Hide file tree
Showing 31 changed files with 2,225 additions and 190 deletions.
36 changes: 33 additions & 3 deletions src/jit_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,39 @@ pub fn execute(

params_ptrs.push(next.to_jit(&arena, registry, param_type_id)?);
}
CoreTypeConcrete::Sint32(_) => todo!(),
CoreTypeConcrete::Sint64(_) => todo!(),
CoreTypeConcrete::Sint128(_) => todo!(),
CoreTypeConcrete::Sint32(_) => {
let next = params_it
.next()
.ok_or_else(|| make_missing_parameter(param_type_id))?;

if !matches!(next, JITValue::Sint32(_)) {
Err(make_unexpected_value_error("JITValue::Sint32".to_string()))?;
}

params_ptrs.push(next.to_jit(&arena, registry, param_type_id)?);
}
CoreTypeConcrete::Sint64(_) => {
let next = params_it
.next()
.ok_or_else(|| make_missing_parameter(param_type_id))?;

if !matches!(next, JITValue::Sint64(_)) {
Err(make_unexpected_value_error("JITValue::Sint64".to_string()))?;
}

params_ptrs.push(next.to_jit(&arena, registry, param_type_id)?);
}
CoreTypeConcrete::Sint128(_) => {
let next = params_it
.next()
.ok_or_else(|| make_missing_parameter(param_type_id))?;

if !matches!(next, JITValue::Sint128(_)) {
Err(make_unexpected_value_error("JITValue::Sint128".to_string()))?;
}

params_ptrs.push(next.to_jit(&arena, registry, param_type_id)?);
}
CoreTypeConcrete::NonZero(info) => {
let next = params_it
.next()
Expand Down
10 changes: 8 additions & 2 deletions src/libfuncs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub mod nullable;
pub mod pedersen;
pub mod poseidon;
pub mod sint16;
pub mod sint32;
pub mod sint64;
pub mod sint8;
pub mod snapshot_take;
pub mod stark_net;
Expand Down Expand Up @@ -207,8 +209,12 @@ where
CoreConcreteLibfunc::Sint16(info) => {
self::sint16::build(context, registry, entry, location, helper, metadata, info)
}
CoreConcreteLibfunc::Sint32(_) => todo!(),
CoreConcreteLibfunc::Sint64(_) => todo!(),
CoreConcreteLibfunc::Sint32(info) => {
self::sint32::build(context, registry, entry, location, helper, metadata, info)
}
CoreConcreteLibfunc::Sint64(info) => {
self::sint64::build(context, registry, entry, location, helper, metadata, info)
}
CoreConcreteLibfunc::Sint128(_) => todo!(),
CoreConcreteLibfunc::Bytes31(_) => todo!(),
}
Expand Down
4 changes: 2 additions & 2 deletions src/libfuncs/sint16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ mod test {
fn i16_const_min() {
let program = load_cairo!(
fn run_test() -> i16 {
0_i16
-32768_i16
}
);

run_program_assert_output(&program, "run_test", &[], &[0i16.into()]);
run_program_assert_output(&program, "run_test", &[], &[i16::MIN.into()]);
}

#[test]
Expand Down
Loading

0 comments on commit 3c6d762

Please sign in to comment.