Skip to content

Commit

Permalink
LLR: More work
Browse files Browse the repository at this point in the history
Fix animations and public fields and callbacks
  • Loading branch information
ogoffart committed Jan 12, 2022
1 parent 2d31ec2 commit a11714f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
8 changes: 7 additions & 1 deletion sixtyfps_compiler/llr/expression.rs
Expand Up @@ -233,7 +233,13 @@ impl Expression {
Type::Function { return_type, .. } => *return_type,
_ => unreachable!(),
},
Self::CallBackCall { .. } => todo!(),
Self::CallBackCall { callback, .. } => {
if let Type::Callback { return_type, .. } = ctx.property_ty(callback) {
return_type.as_ref().map_or(Type::Void, |x| (**x).clone())
} else {
Type::Invalid
}
}
Self::ExtraBuiltinFunctionCall { .. } => todo!(),
Self::PropertyAssignment { .. } => Type::Void,
Self::ModelDataAssignment { .. } => Type::Void,
Expand Down
32 changes: 30 additions & 2 deletions sixtyfps_compiler/llr/lower_expression.rs
Expand Up @@ -385,7 +385,8 @@ pub fn lower_animation(a: &PropertyAnimation, ctx: &ExpressionContext<'_>) -> Op
name: "state".into(),
value: Box::new(lower_expression(state_ref, ctx)?),
};
let mut get_anim = llr_Expression::default_value_for_type(&animation_ty())?;
let animation_ty = animation_ty();
let mut get_anim = llr_Expression::default_value_for_type(&animation_ty)?;
for tr in animations.iter().rev() {
let condition = lower_expression(
&tr.condition(tree_Expression::ReadLocalVariable {
Expand All @@ -400,7 +401,34 @@ pub fn lower_animation(a: &PropertyAnimation, ctx: &ExpressionContext<'_>) -> Op
false_expr: Some(Box::new(get_anim)),
}
}
Some(Animation::Transition(llr_Expression::CodeBlock(vec![set_state, get_anim])))
let result = llr_Expression::Struct {
// This is going to be a tuple
ty: Type::Struct {
fields: IntoIterator::into_iter([
("0".to_string(), animation_ty),
("1".to_string(), Type::Duration),
])
.collect(),
name: None,
node: None,
},
values: IntoIterator::into_iter([
("0".to_string(), get_anim),
(
"1".to_string(),
llr_Expression::StructFieldAccess {
base: llr_Expression::ReadLocalVariable {
name: "state".into(),
ty: state_ref.ty(),
}
.into(),
name: "change_time".into(),
},
),
])
.collect(),
};
Some(Animation::Transition(llr_Expression::CodeBlock(vec![set_state, result])))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion sixtyfps_compiler/llr/lower_to_item_tree.rs
Expand Up @@ -463,7 +463,7 @@ fn lower_global(
init_values,
const_properties,
public_properties,
exported: global.exported_global_names.borrow().is_empty(),
exported: !global.exported_global_names.borrow().is_empty(),
aliases: global.global_aliases(),
is_builtin,
}
Expand Down

0 comments on commit a11714f

Please sign in to comment.