Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cargo run --bin ftd -- --wasm hello.ftd | cargo run --bin fastn-runtime -- --stdin
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ members = [
"fastn-cloud",
"fastn-package",
"fastn-issues",
"fastn-runtime"
"fastn-runtime",
"fastn-wasm",
]

[workspace.dependencies]
Expand Down Expand Up @@ -34,6 +35,7 @@ camino = "1"
clap = "4"
colored = "2"
css-color-parser = "0.1"
wasm-encoder = "0.27"
diffy = "0.3"
slotmap = "1"
dioxus-html = { git = "https://github.com/DioxusLabs/dioxus", rev = "fb52673433cc57a70c86185ffa7da5fa3a2394da" }
Expand Down
6 changes: 6 additions & 0 deletions fastn-package/create-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ DROP TABLE IF EXISTS main_package;
CREATE TABLE main_package (
name TEXT NOT NULL PRIMARY KEY
) WITHOUT ROWID;

CREATE TABLE static_files (
name TEXT NOT NULL PRIMARY KEY,
content_type TEXT NOT NULL,
content_hash TEXT NULL,
) WITHOUT ROWID;
40 changes: 40 additions & 0 deletions fastn-runtime/1.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(module
(import "fastn" "create_column" (func $create_column (result externref)))
(import "fastn" "root_container" (func $root_container (result externref)))
(import "fastn" "set_column_width_px" (func $set_column_width_px (param externref i32)))
(import "fastn" "set_column_height_px" (func $set_column_height_px (param externref i32)))

;; fastn.add_child(parent: NodeKey, child: NodeKey)
(import "fastn" "add_child" (func $add_child (param externref externref)))

(func (export "main") (local $column externref) (local $root_container_ externref)
(local.set $root_container_ (call $root_container))

;; -- ftd.column:
(call $foo (local.get $root_container_) (i32.const 100) (i32.const 100))
drop

(call $foo (local.get $root_container_) (i32.const 200) (i32.const 800))
drop
)

(func $foo
(param $root externref)
(param $width i32)
(param $height i32)

(result externref)

(local $column externref)

;; body

(local.set $column (call $create_column))

(call $add_child (local.get $root) (local.get $column))
(call $set_column_width_px (local.get $column) (local.get $width))
(call $set_column_height_px (local.get $column) (local.get $height))

(local.get $column)
)
)
1 change: 1 addition & 0 deletions fastn-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ tokio.workspace = true
bytemuck.workspace = true
wasmtime.workspace = true
async-trait.workspace = true
fastn-wasm = { path = "../fastn-wasm" }
99 changes: 9 additions & 90 deletions fastn-runtime/src/document.rs
Original file line number Diff line number Diff line change
@@ -1,117 +1,36 @@
pub struct Document {
pub taffy: taffy::Taffy,
pub nodes: slotmap::SlotMap<fastn_runtime::NodeKey, fastn_runtime::Element>,
pub root: fastn_runtime::NodeKey,
pub width: u32,
pub height: u32,
// variables, bindings
pub wasm: fastn_runtime::wasm::Wasm,
store: wasmtime::Store<fastn_runtime::Dom>,
pub instance: wasmtime::Instance,
}

/*

// global doc

fn add_wrapper(a: Ref, b: Ref) -> Ref {
let a = doc.get(a);
let b = doc.get(b);
let c = add(a, b);
Ref::new(c)
}

fn add(a: u32, b: u32) -> u32 {
a + b
}

fn handle_event_wrapper(a: Ref, b: Ref) {
let a = doc.get(a);
handle_event(a, b);
}

fn handle_event(a: u32, b: Mut<u32>) {
b.set(a + 1)
}

-- boolean f: true
-- boolean g: hello(v=$f)

-- boolean hello(v):
boolean v:

!v

-- ftd.boolean: $g



let rt = Runtime::new();

let f = rt.create_boolean_id_ref(true);
let hello = rt.create_function(boolean, [Ref::new(boolean)], [], "return !$0");
let g = rt.create_boolean_ref(hello, [f]); // internally update dependency graph

rt.create_boolean_kernel(g); // internally update dependency graph

rt.show();

*/

impl Document {
pub fn new(wat: impl AsRef<[u8]>) -> Document {
let mut nodes = slotmap::SlotMap::with_key();
let mut taffy = taffy::Taffy::new();
let root = nodes.insert(fastn_runtime::Container::outer_column(&mut taffy));
let (store, instance) = fastn_runtime::Dom::create_instance(wat);

Document {
root,
taffy,
nodes,
width: 0,
height: 0,
wasm: fastn_runtime::wasm::Wasm::new(wat),
store,
instance,
}
}

// initial_html() -> server side HTML
// hydrate() -> client side
// event_with_target() -> Vec<DomMutation>

// pub fn create_string_ref(&mut self) -> fastn_runtime::Ref {
// todo!()
// }
//
// pub fn add_text(&mut self, text: fastn_runtime::Callable<String>) -> fastn_runtime::NodeKey {
// let text_style = fastn_runtime::TextStyle::default();
// let taffy = self.taffy.new_leaf(text_style.taffy()).unwrap();
// let t = fastn_runtime::Text {
// taffy,
// text,
// style: text_style,
// };
// self.nodes.insert(fastn_runtime::Element::Text(t))
// }

// if not wasm
pub fn initial_layout(
&mut self,
width: u32,
height: u32,
) -> (fastn_runtime::ControlFlow, Vec<fastn_runtime::Operation>) {
let taffy_root = self.nodes[self.root].taffy();
self.taffy
.compute_layout(
taffy_root,
taffy::prelude::Size {
width: taffy::prelude::points(width as f32),
height: taffy::prelude::points(height as f32),
},
)
.unwrap();
self.width = width;
self.height = height;
dbg!(self.taffy.layout(taffy_root).unwrap());

(fastn_runtime::ControlFlow::WaitForEvent, self.wasm.run())
(
fastn_runtime::ControlFlow::WaitForEvent,
self.store.data_mut().compute_layout(width, height),
)
}

// if not wasm
Expand Down
Loading