Skip to content

Commit

Permalink
enum from bounded
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Aug 28, 2024
1 parent 9a23176 commit 6131e94
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/vm/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ use crate::Value;
use cairo_lang_sierra::{
extensions::{
core::{CoreLibfunc, CoreType, CoreTypeConcrete},
enm::{EnumConcreteLibfunc, EnumConcreteType, EnumInitConcreteLibfunc},
enm::{
EnumConcreteLibfunc, EnumConcreteType, EnumFromBoundedIntConcreteLibfunc,
EnumInitConcreteLibfunc,
},
lib_func::SignatureOnlyConcreteLibfunc,
ConcreteLibfunc,
},
program_registry::ProgramRegistry,
};
Expand All @@ -17,7 +21,7 @@ pub fn eval(
) -> EvalAction {
match selector {
EnumConcreteLibfunc::Init(info) => eval_init(registry, info, args),
EnumConcreteLibfunc::FromBoundedInt(_) => todo!(),
EnumConcreteLibfunc::FromBoundedInt(info) => eval_from_bounded_int(registry, info, args),
EnumConcreteLibfunc::Match(info) => eval_match(registry, info, args),
EnumConcreteLibfunc::SnapshotMatch(_) => todo!(),
}
Expand Down Expand Up @@ -50,6 +54,24 @@ pub fn eval_init(
)
}

pub fn eval_from_bounded_int(
_registry: &ProgramRegistry<CoreType, CoreLibfunc>,
info: &EnumFromBoundedIntConcreteLibfunc,
args: Vec<Value>,
) -> EvalAction {
let [Value::BoundedInt { range: _, value }]: [Value; 1] = args.try_into().unwrap() else {
panic!()
};

let enm = Value::Enum {
self_ty: info.branch_signatures()[0].vars[0].ty.clone(),
index: value.try_into().unwrap(),
payload: Box::new(Value::Struct(vec![])),
};

EvalAction::NormalBranch(0, smallvec![enm])
}

pub fn eval_match(
registry: &ProgramRegistry<CoreType, CoreLibfunc>,
info: &SignatureOnlyConcreteLibfunc,
Expand Down

0 comments on commit 6131e94

Please sign in to comment.