Commit graph

281 commits

Author SHA1 Message Date
Simon Hausmann
be3d0ab369 Provide convenience accessors for public properties in C++
While properties declared in the root component are named as-is and
exposed as Property<T>, their get() function in particular is hard to
use because it requires an EvaluationContext as a parameter.

This patch adds get_foo() and set_foo() accessors for each public
property and hides the evaluation context business for the getter.

The added test uses this right away and adds missing test coverage for
the conditional expression.
2020-06-11 15:45:16 +02:00
Olivier Goffart
8b6bb47af8 Create a type alias for Rc<RefCell<Element>> 2020-06-11 15:28:51 +02:00
Olivier Goffart
708e62800d Test that the tree is well formed for what we expect 2020-06-11 15:01:09 +02:00
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
Olivier Goffart
9c23326c60 Layout for the C++ as well 2020-06-10 19:41:24 +02:00
Olivier Goffart
907bea3d3b Layout for rust 2020-06-10 19:41:24 +02:00
Olivier Goffart
96a372e45d Grid layout in the interpreter
current imploementation is just a prototype
2020-06-10 19:40:47 +02:00
Olivier Goffart
ed69f4c432 WIP layouts 2020-06-10 19:40:47 +02:00
Simon Hausmann
26561beea4 Fix wasm build 2020-06-10 19:36:12 +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
fdbef8c3c4 Add support for parsing conditional expression syntax 2020-06-10 15:40:27 +02:00
Simon Hausmann
1baab9823a Another small typo fix :) 2020-06-10 12:05:44 +02:00
Simon Hausmann
ea52c7c9c9 Fix typo 2020-06-10 12:03:46 +02:00
Simon Hausmann
983c8571e3 Minor cleanup in function naming 2020-06-10 09:27:54 +02:00
Simon Hausmann
f95b31bca4 Fix build 2020-06-09 23:24:38 +02:00
Simon Hausmann
1404cb73ae Add support for embedding resources in the rust generator
This is relatively straight-forward via a pass in the compiler to
collect the resources to embed and then use include_bytes! (once per
resource).

What's really annoying is that the rust resource enum can't store a
&'static [u8] because cbindgen doesn't represent that, probably because
the slice representation isn't guaranteed to stay as it is. So instead
this, for now, uses raw pointers.
2020-06-09 22:54:29 +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
a756b7fa0e Keep a reference to the AST node in the Element structure
So we can give error for elements
2020-06-09 18:20:32 +02:00
Olivier Goffart
c05da294a1 Add GridLayout and Row
The compiler currently lowers them to nothing
2020-06-09 12:46:16 +02:00
Olivier Goffart
0e67a0ecbc Block comments 2020-06-08 10:40:02 +02:00
Olivier Goffart
d1febde6c7 Fix warning in the generated code 2020-06-08 10:07:17 +02:00
Olivier Goffart
9fc60e104f Add another way to load .60 files from a build script 2020-06-05 13:45:38 +02:00
Olivier Goffart
e6681a7087 Move the rust generator to the compiler lib 2020-06-05 10:54:22 +02:00
Olivier Goffart
3651885d87 Move the compiler binary in tools/
And rename sixtyfps_compiler to sixtyfps_compilerlib
2020-06-05 09:23:38 +02:00
Simon Hausmann
8624566e5c Add boilerplate for new testing harness
The objective is to have a bunch of .60 files with annotations inside
and the test harness picks them up and runs them through the Rust and
C++ frontend.
2020-06-05 08:56:16 +02:00
Olivier Goffart
c024f97890 Viewer: use binding when needed 2020-05-30 17:42:17 +02:00
Olivier Goffart
dc276290e9 Add support for self assignment (+=, -=, ...) 2020-05-28 17:02:06 +02:00
Olivier Goffart
38329361b6 Use Property::set in C++ for constant bindings 2020-05-28 14:58:08 +02:00
Olivier Goffart
74898a1386 Make property conneciton binding in the C++
(somehow plus/minus is not working yet)
2020-05-28 14:52:43 +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
f6d1151832 Use the EvaluationContext in the signal handler 2020-05-28 14:26:35 +02:00
Olivier Goffart
e86a7d3192 Merge signal and property declaration
A Signal is just a property of type Type::Signal

Simplifies the code a bit
2020-05-28 12:49:18 +02:00
Olivier Goffart
95b671c97c Support for code blocks and signal call 2020-05-28 12:30:08 +02:00
Simon Hausmann
f2df9293a9 Fix the C++ build
Remove the Optional from the evaluation context passing for property
evaluation. Unfortunately there are nullptr uses left on the C++ side,
that need to be replaced with passing through.
2020-05-28 12:07:11 +02:00
Olivier Goffart
f27816a450 Recurse into the expressions in the passes 2020-05-28 08:01:33 +02:00
Olivier Goffart
92697ec6b0 Add some code to parse statements in blocks (separated with semicolon) 2020-05-28 07:22:08 +02:00
Olivier Goffart
250b0a2e5b Rust macro: get the right span for the diagnostics
Merge the features proc_macro_span and proc_macro_diagnostics, they are the same.
2020-05-27 18:37:45 +02:00
Olivier Goffart
42cddf2925 Add the conversion test 2020-05-27 16:46:31 +02:00
Olivier Goffart
5580b5112f Fix number to string conversion in C++ 2020-05-27 16:18:08 +02:00
Olivier Goffart
486b2ab8f8 Do type checking and convert from number to string 2020-05-27 15:43:45 +02:00
Simon Hausmann
c8b64f5c4b Remove the lowering
The LoweredItem and LoweredComponent contained, in essence, the same
information as the Element and Component in object_tree. Since the
moving declarations pass moved everything to the root element and the
LoweredPropertyDeclarations have been removed as well, this is the last
step.
2020-05-27 14:45:35 +02:00
Simon Hausmann
32990e15e2 Remove LoweredPropertyDeclaration
This type that allowed indexing the property declarations in the hierarchy
to the properties moved to the root is not needed anymore.
For now a simple set remains in the LoweredItem to generate
correct accessor prefixes.
2020-05-27 11:13:58 +02:00
Olivier Goffart
41332a759f Make property reference works in C++ 2020-05-27 10:00:45 +02:00
Simon Hausmann
01fc0df1a2 Revert "Fix C++ build"
This reverts commit 6818ea746f.

The build was fine before this change. We don't call map_name() on the
root declarations, so this can't really happen.
2020-05-27 09:58:55 +02:00
Simon Hausmann
6818ea746f Fix C++ build
Don't rename the declarations in the root element.
2020-05-27 09:56:24 +02:00
Olivier Goffart
c137b4dab5 Add a pass to move all declaration on the top level 2020-05-27 09:37:46 +02:00
Olivier Goffart
3472674262 Add a pass to assign unique id to the elements 2020-05-27 08:20:52 +02:00
Simon Hausmann
e77fe37568 Make it more convenient to deal with diagnostics in the Rust frontend
Provide a ToTokens implementation of Diagnostics by moving the code from the macro.
This makes it easier later to re-use the same logic to return
with diagnostics.
2020-05-26 15:17:18 +02:00
Olivier Goffart
36fb526811 Do inlining in a pass before the lowering 2020-05-26 15:10:27 +02:00
Olivier Goffart
b3d1a7196c Compile fix 2020-05-26 12:15:31 +02:00