Skip to content

Commit

Permalink
feat: add without insert index check for dict attributes
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Oct 23, 2023
1 parent 70b3625 commit d648f12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kclvm/runtime/src/value/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,12 @@ pub unsafe extern "C" fn kclvm_dict_is_override_attr(
) -> kclvm_bool_t {
let p = ptr_as_ref(p);
let key = c2str(key);
matches!(
let is_override_op = matches!(
p.dict_get_attr_operator(key),
Some(ConfigEntryOperationKind::Override)
) as kclvm_bool_t
);
let without_index = matches!(p.dict_get_insert_index(key), Some(-1) | None);
(is_override_op && without_index) as kclvm_bool_t
}

#[no_mangle]
Expand Down
11 changes: 11 additions & 0 deletions kclvm/runtime/src/value/val_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ impl ValueRef {
}
}

/// Dict get value e.g., {k1 = v1, k2 = v2}.get_attr_operator(k1) == Some(ConfigEntryOperationKind::Override)
pub fn dict_get_insert_index(&self, key: &str) -> Option<i32> {
match &*self.rc.borrow() {
Value::dict_value(ref dict) => Some(*dict.insert_indexs.get(key).unwrap_or(&-1)),
Value::schema_value(ref schema) => {
Some(*schema.config.insert_indexs.get(key).unwrap_or(&-1))
}
_ => None,
}
}

/// Dict get entry e.g., {k1: v1, k2, v2}.get_entry(k1) == {k1: v1}
pub fn dict_get_entry(&self, key: &str) -> Option<ValueRef> {
match &*self.rc.borrow() {
Expand Down

0 comments on commit d648f12

Please sign in to comment.