Commit graph

58 commits

Author SHA1 Message Date
Olivier Goffart
cd47ef1100 Mark properties that we know are never modified as constant,
so that we don't need to register dependencies when accessing them
2021-12-04 22:00:12 +01:00
Olivier Goffart
dd3fa1c221 Make the BindingMap hold RefCell of the BindingExpression
This will allow later to be able to operate on the binding despite the
element is borrowed.

Since the Binding itself is in a RefCell, the analysis don't need to
be anymore.
To do this change, a small change in the binding_analysis logic was required
which means that we will now detect binding loop if a binding was causing
two binding loop. (before, only one binding loop was detected)
2021-11-11 11:14:59 +01:00
Simon Hausmann
0eb210933e Fix itreem tree offsets of children of chained sub-components
Similar to commit 4eb161b83f this works in C++
by accident but for Rust to compile we need to advance the sub-component
state in the tree builder.
2021-11-05 11:34:41 +01:00
Simon Hausmann
4eb161b83f Fix item tree offsets for chained sub-components
When we have

```
S1 := Rectangle {}
S2 := S1 {}
App := Window {
    S2 {}
}
```

Then the right path to the rectangle is

    offsetof(App, s2) + offsetof(S2, root) + offset(S1, rectangle)

The middle one was left out in C++, where it also probably doesn't matter
because the root is the first member (although it might not always remain that way).

In Rust the FieldOffset type generated won't allow for adding
together without the middle one.

Therefore visit_item() in the generator is changed to bring forward the sub-component
state when following the chain.
2021-11-05 11:04:30 +01:00
Simon Hausmann
7354b17a6a Minor cleanup in ItemTreeBuilder trait
Pass the sub-component as a parameter in enter_component(), as it's needed in the C++
implementation, it's readily available (no need to unwrap again) and Rust will need it, too.
2021-11-04 17:55:39 +01:00
Olivier Goffart
6df78893d6 Use build_item_tree in dynamic_component 2021-11-04 16:40:48 +01:00
Simon Hausmann
d447cd155d Fix missing repeaters in item tree with chained sub-components
The parent commit surfaced this issue, as we now rely on visiting all repeaters
in the build_item_tree call.
2021-11-04 11:03:44 +01:00
Simon Hausmann
e0f3e6b782 Fix the C++ printer demo with disabled inline
For the following reduced test-case the order in how the dynamic nodes
in the item tree were generated (and dyn indices assigned) differed from
the way the visit_dynamic_children slots were generated:

```
Blah := Rectangle {
    for x in 1: Text {
        text: "Should be on the right";
    }
}

MainWindow := Window {
    width: 772px;
    height: 504px;
    Text {
        if (false): TouchArea {
        }
    }
    Blah {
        x: 200px;
    }
}
```

The item tree node was constructed using build_item_tree, which
basically assigned dyn index 0 to the "repater" for the touch area
and "1" to the one for the repeater inside the sub-component.

Afterwards we traversed the element tree - without descending into the
sub-components - to generate the fields and the dispatch in in the
dynamic visitor. Here a subtle order would result in a mismatch of
indices:

recurse_elem_level_order would end up visiting Text, Blah and then
Text's children, assigning the first dynamic index to Blah.

This is now fixed by merging the two iterations into one.
2021-11-04 11:03:44 +01:00
Olivier Goffart
d438374792 Refactor the build_item_tree
Use a trait instead of two functions
2021-11-03 17:46:48 +01:00
Olivier Goffart
ab88e3553e Fix the item tree building for components whose base is a component
We should only visit element that are native item with the visit_item function
2021-11-03 14:59:27 +01:00
Olivier Goffart
6792b7ea23 Fix compilation error 2021-11-03 10:19:44 +01:00
Simon Hausmann
81a13219dc Fix C++ compilation when a component has a sub-component as a base type
Commit da169b0e3c surfaced the issue, which
existed earlier:

In such a scenarion the C++ struct has only one member (the sub-component) and it wasn't initialized,
because we never called visit_sub_component.
2021-11-03 10:15:10 +01:00
Simon Hausmann
da169b0e3c Fix calling focus() in sub-components when inlining is disabled
focus() is implemented by calling set_focus() on the window with the absolute item
index as a parameter. The
generate_item_indices pass generates local item indicies,
which need to made absolute.

Sadly there exists a gap in the item tree between the root element of a sub-component
and its children. Therefore each sub-component gets two members passed to the constructor,
the tree_index and tree_index_of_first_child.
The former is to be used when the local index is zero (indicates the root).
The latter is used as base for any children.
2021-11-03 09:45:35 +01:00
Simon Hausmann
bd971eda25 Fix local item indicies when using sub-components before other children
In a tree like this:

```
SubCompo := Rectangle { Image {} }
MainCompo := Window {
    TouchArea {}
    SubCompo {}
    Text {
        Path {}
    }
}
```

The path element would have a local item index of 4, which is wrong. Right before the path
there would be the child(ren) of the sub-component, which
were not accounted for.
2021-11-03 08:27:49 +01:00
Simon Hausmann
80f1a8ab11 Fix the parent index for sub-components
We never ended up passing the right index but always zero.

Fix by rewriting build_item_tree to be basically the same as build_array_helper,
with two differences:

(1) we maintain absolute and relative children offsets and parent indices
(2) When traversing over the children of an element there are two scenarios: either
  the element is a sub-component, in which case we iterate through the children of the root element,
  or we can use ElementRc's children directly
2021-11-01 17:57:39 +01:00
Simon Hausmann
7de0918f0d Fix the order of how sub-components are emitted into the sub-tree
We need to maintain the order of declaration and the sub-trees
of children need to be emitted before continuing with the parent.

This fixes the tab widget in the galler.y
2021-11-01 15:49:20 +01:00
Simon Hausmann
4316e1baac Fix asserts in item tree generator when using sub-components
There's a check that verifies that the relative item indices match, between what
the item tree building code in the generator sees and the generate_item_indices pass.

The counting of the relative indices was incorrect with regards to the sub-trees.
2021-11-01 13:40:08 +01:00
Simon Hausmann
db64d30a29 First attempt at fixing the item tree for sub-components
By accident the tree was still depth-first instead of level-order. This implementation works better,
by placing the root element of sub-components as
parents and the children into the children space later.

There's still more work to do to clean it up and make work with more complex scenarios.
2021-10-29 19:05:25 +02:00
Simon Hausmann
7a7fb72d8b compiler internal: fix item index generation for sub-components
(1) ... when the root element is a sub-component itself (the initialy child offset is not 1)

(2) when children themselves are sub-components, then they may occupy more entries in the item tree
2021-10-28 15:52:29 +02:00
Simon Hausmann
82b5c3bcce Fix the item index generation to take sub-components into account
A regular element where the base type is a built-in item uses one slot,
while a sub-component expands to multiple nested built-in items.
2021-10-28 15:52:29 +02:00
Olivier Goffart
b42c187ed1 Refactor the way the two-ways biding are represented internaly
Don't put them in a fake expression.
This simplifies a bit the expression handling, and will make
possible to fix analysis that needs a vew into the aliases
2021-08-20 18:26:36 +02:00
Olivier Goffart
8728052578 Fix panic when typing into the line edit in the gallery
The problem was that the item array's parent was not properly
computed. Leading to corrupted item when getting the parent of the
focus item.
2021-08-09 12:00:17 +02:00
Tobias Hunger
b5e0d919f1 Janitor: Fix clippy::single_match 2021-07-30 09:27:48 +02:00
Olivier Goffart
6a32a8b37a Don't error on empty documents 2021-07-29 17:40:20 +02:00
Olivier Goffart
ba32777cab Refactoring: move the animation in the PropertyBinding struct
Since they always belong together.

This will help for issue #193
2021-07-23 15:25:53 +02:00
Olivier Goffart
13bd828b96 Update license date 2021-07-02 15:55:54 +02:00
Olivier Goffart
59b12d20e8 Update sixtyfps_compiler/generator.rs
Co-authored-by: Simon Hausmann <simon.hausmann@sixtyfps.io>
2021-05-20 13:40:51 +02:00
Olivier Goffart
a79a4351b5 Be smarter at detecting the constant property and at not generating bindings
this implies that we need to make sure the property are initialized in
order so that constant properties that depends on other constant properties
are correctly computed
2021-05-20 13:40:51 +02:00
Olivier Goffart
a712f515fa Make the viewport element of the flickable a real Element in the object_tree 2021-04-09 19:14:48 +02:00
Olivier Goffart
c2982d9ab3 Add ability to get the parent item from the vtable
(still untested)
2021-01-26 10:36:37 +01:00
Simon Hausmann
87e0cc7d85 Fix resource embedding doing a wasm build of a project using the sixtyfps! macro
We need to embed resources in wasm builds. Unfortunately we can't detect
that we're called by say wasm-pack and "TARGET"/"HOST" only works inside
build.rs. So instead, to keep things simple, this change always embeds
the image resources when targeting Rust.

The `SIXTYFPS_EMBED_RESOURCES` environment variable can be used to
override this anywhere for any language.

Fixes #130
2020-12-10 15:09:32 +01:00
Olivier Goffart
7f78bea8b5 Fix a bunch of cargo clippy warnings in the compiler 2020-12-07 12:54:38 +01:00
Olivier Goffart
27a6ff1227 Move Type and related concepts in a different module
Leaving only the TypeRegister in the typeregister module
2020-10-23 11:17:14 +02:00
Olivier Goffart
2ee861365c Flickable: expose the viewport property as viewport_*
The code generator forward that the the viewport
2020-09-22 13:52:27 +02:00
Olivier Goffart
8134fe5088 Support for named type as property 2020-09-17 13:14:01 +02:00
Olivier Goffart
58cdaeb8dd Update license header to mention that commertial option are available 2020-08-26 13:23:42 +02:00
Simon Hausmann
2823f32692 Apply license headers to all non-binary/non-json sources 2020-08-17 17:55:20 +02:00
Olivier Goffart
9760cf4969 Begin to implement a Flickable
The implementation is still very rough and will need to be improved
2020-07-30 14:36:21 +02:00
Simon Hausmann
ada5f68908 Add aggregating BuildDiagnostics
This type aggregates different per-file diagnostics into a similar interface,
in preparation for reporting diagnostics from multiple source files.
2020-07-17 12:10:25 +02:00
Simon Hausmann
e914715d88 Rename Diagnostics to FileDiagnostics
As this structure holds the diagnostics just for one file.
2020-07-16 18:25:42 +02:00
Olivier Goffart
f35c12aef1 Fix building of the nodejs frontend for the tests 2020-06-29 10:35:18 +02:00
Simon Hausmann
ba15a768d6 Add the ability to output rust code to the compiler cli 2020-06-29 09:00:35 +02:00
Olivier Goffart
8651acbef4 Small renaming in the cpp generator
Take the component by Rc as this will be usefull when generating repeated expression
2020-06-17 10:50:20 +02:00
Olivier Goffart
9adc55cd70 Partially revert the refactoring that changed the Element::children list
Put the information about RepeatedElement in an Option within the normlal Element
2020-06-15 13:42:11 +02:00
Olivier Goffart
136a90907b Refactor the element children to account for RepeatedElements 2020-06-12 22:24:50 +02:00
Olivier Goffart
8b6bb47af8 Create a type alias for Rc<RefCell<Element>> 2020-06-11 15:28:51 +02:00
Olivier Goffart
e6681a7087 Move the rust generator to the compiler lib 2020-06-05 10:54:22 +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
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