Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Sep 18, 2024
1 parent 38543d3 commit 5278aa7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
35 changes: 28 additions & 7 deletions src/vm/const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ pub fn eval_as_immediate(
[GenericArg::Value(value)] => Value::Felt(value.into()),
_ => unreachable!(),
},
CoreTypeConcrete::NonZero(info) => inner(registry, &info.ty, inner_data),
CoreTypeConcrete::NonZero(_) => match inner_data {
// Copied from the sierra to casm lowering
// NonZero is the same type as the inner type in native.
[GenericArg::Type(inner_ty)] => {
let inner_type = registry.get_type(inner_ty).unwrap();
let const_inner_type = match inner_type {
CoreTypeConcrete::Const(inner) => inner,
_ => unreachable!(),
};

inner(registry, &const_inner_type.inner_ty, &const_inner_type.inner_data)
}
_ => unreachable!(),
},
CoreTypeConcrete::Sint8(_) => match inner_data {
[GenericArg::Value(value)] => Value::I8(value.try_into().unwrap()),
_ => unreachable!(),
Expand All @@ -70,6 +83,14 @@ pub fn eval_as_immediate(
},
CoreTypeConcrete::Uint128(_) => match inner_data {
[GenericArg::Value(value)] => Value::U128(value.try_into().unwrap()),
x => unreachable!("{:?}", x),
},
CoreTypeConcrete::Uint64(_) => match inner_data {
[GenericArg::Value(value)] => Value::U64(value.try_into().unwrap()),
x => unreachable!("{:?}", x),
},
CoreTypeConcrete::Uint16(_) => match inner_data {
[GenericArg::Value(value)] => Value::U16(value.try_into().unwrap()),
_ => unreachable!(),
},
CoreTypeConcrete::Struct(_) => {
Expand All @@ -80,14 +101,14 @@ pub fn eval_as_immediate(
GenericArg::Type(const_field_ty) => {
let field_type = registry.get_type(const_field_ty).unwrap();

match &field_type {
CoreTypeConcrete::Const(const_ty) => {
let field_value =
inner(registry, &const_ty.inner_ty, &const_ty.inner_data);
fields.push(field_value);
}
let const_field_type = match &field_type {
CoreTypeConcrete::Const(inner) => inner,
_ => unreachable!(),
};

let field_value =
inner(registry, &const_field_type.inner_ty, &const_field_type.inner_data);
fields.push(field_value);
}
_ => unreachable!(),
}
Expand Down
4 changes: 1 addition & 3 deletions src/vm/uint252.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ pub fn eval_divmod(

let lhs = u256_to_biguint(lhs_lo, lhs_hi);

let [Value::Struct(rhs)]: [Value; 1] = rhs.try_into().unwrap() else {
panic!()
};


let [Value::U128(rhs_lo), Value::U128(rhs_hi)]: [Value; 2] = rhs.try_into().unwrap() else {
panic!()
Expand Down

0 comments on commit 5278aa7

Please sign in to comment.