Commit graph

16 commits

Author SHA1 Message Date
Simon Hausmann
03bef6dba3 Fix casting with conditional expressions
The following scenario would fail compiling to C++ because we failed to
determine the return type of the conditional expression:

    Test := Rectangle {
        property<bool> condition;
        property<color> extra_color;
        color: condition ? root.extra_color : 4289374890;
    }

The type of the true branch would be color and the false branch would be
a float. Since they "disagree", ty() on the expression would return
Type::Invalid. This was temporarily worked around in the C++ generator
by always returning the type of the true branch, but that's wrong.

Instead this patch changes maybe_convert_to to apply the Cast expression
to the individual branches, placing the cast only to the numberic
literal and correcting the return value of ty() on the conditional
expression.
2020-06-11 13:38:24 +02:00
Simon Hausmann
63f81e1991 Add basic support for conditional expressions
Todo are automated tests and cleaning up the C++ implementation.
2020-06-10 16:04:15 +02:00
Simon Hausmann
ea52c7c9c9 Fix typo 2020-06-10 12:03:46 +02:00
Simon Hausmann
5bae6e01a5 Prepare for the ability to embed image data
The Image's source property used to be a string. Now it is a Resource
enum, which can either be None or an absolute file path to the image on
disk. This also replaces the internal Image type.

The compiler internally resolves the img bang expression to a resource
reference, which shall remain just an absolute path. For now the target
generator passes that through, but in the future the target generator
may choose a target specific way of embedding the data and thus
generating a different Resource type in the final code (through
compile_expression in the cpp and rust generator).

The C++ binding is a bit messy as cbindgen doesn't really support
exporting enums that can be constructed on the C++ side. So instead we
use cbindgen to merely export the type internally and only use the tag
from it then. The public API is then a custom Resource type that is
meant to be binary compatible.
2020-06-09 22:54:29 +02:00
Olivier Goffart
dc276290e9 Add support for self assignment (+=, -=, ...) 2020-05-28 17:02:06 +02:00
Simon Hausmann
e227f8a46e Use both set() and set_binding() in the rust frontend
When an expression holds just a constant value, then we can avoid creating a binding.
2020-05-28 14:41:15 +02:00
Olivier Goffart
95b671c97c Support for code blocks and signal call 2020-05-28 12:30:08 +02:00
Olivier Goffart
f27816a450 Recurse into the expressions in the passes 2020-05-28 08:01:33 +02:00
Olivier Goffart
486b2ab8f8 Do type checking and convert from number to string 2020-05-27 15:43:45 +02:00
Olivier Goffart
4ea78134d8 Recactor the compiler so there are passes 2020-05-26 09:40:36 +02:00
Olivier Goffart
dee50a6fe8 More fixes to property lookup with components 2020-05-26 08:10:37 +02:00
Olivier Goffart
905f6c7b15 Fix signal lookup for now
Real signal lookup is still not implemented, any identifier for a signal property is considered as a signal
2020-05-25 17:34:38 +02:00
Olivier Goffart
9e4c355fa1 Lookup of quallified id 2020-05-25 17:24:31 +02:00
Simon Hausmann
747cf18fcd Small typo fix
(Unkown -> Unknown)
2020-05-25 16:42:09 +02:00
Olivier Goffart
19eca01dff Lookup of property within the root component 2020-05-25 16:13:17 +02:00
Olivier Goffart
c0a4902240 Rename expressions -> expression_tree
there is already an expressions module in the parser
2020-05-25 15:28:37 +02:00
Renamed from sixtyfps_compiler/expressions.rs (Browse further)