diff --git a/lib/components_guide/collected_repo.ex b/lib/components_guide/collected_repo.ex index 0348574..5da74de 100644 --- a/lib/components_guide/collected_repo.ex +++ b/lib/components_guide/collected_repo.ex @@ -1,10 +1,10 @@ defmodule ComponentsGuide.CollectedRepo do - def has?(_content_id), do: raise(:todo) - def get!(_content_id), do: raise(:todo) + def has?(_content_id), do: raise("todo") + def get!(_content_id), do: raise("todo") - def run_isolated!(_content_id), do: raise(:todo) + def run_isolated!(_content_id), do: raise("todo") - def new_instance_definition(_content_id, _imports), do: raise(:unimplemented) + def new_instance_definition(_content_id, _imports), do: raise("unimplemented") # Replace with a gen server - def start_instance(_instance_definition), do: raise(:unimplemented) + def start_instance(_instance_definition), do: raise("unimplemented") end diff --git a/lib/components_guide/wasm/examples/color_picker/lab_swatch.ex b/lib/components_guide/wasm/examples/color_picker/lab_swatch.ex index 9b286eb..39d1c3e 100644 --- a/lib/components_guide/wasm/examples/color_picker/lab_swatch.ex +++ b/lib/components_guide/wasm/examples/color_picker/lab_swatch.ex @@ -14,11 +14,7 @@ defmodule ComponentsGuide.Wasm.Examples.LabSwatch do # funcp :f32, format_f32(f: F32, ptr: I32), I32 # end - defmodule Math do - use Orb.Import - - defw(powf32(a: F32, b: F32), F32) - end + Orb.importw(ColorConversion.Math, :math) wasm_import(:format, f32: Orb.DSL.funcp(name: :format_f32, params: {F32, I32}, result: I32) diff --git a/lib/components_guide/wasm/examples/examples_html.ex b/lib/components_guide/wasm/examples/examples_html.ex index 3779658..4a9f1fc 100644 --- a/lib/components_guide/wasm/examples/examples_html.ex +++ b/lib/components_guide/wasm/examples/examples_html.ex @@ -293,7 +293,7 @@ defmodule ComponentsGuide.Wasm.Examples.HTML do ~S[] 1 -> - call(:i32toa, @count) + typed_call(I32, :i32toa, [@count]) 2 -> ~S[] diff --git a/lib/components_guide/wasm/examples/examples_wasi.ex b/lib/components_guide/wasm/examples/examples_wasi.ex deleted file mode 100644 index fce830e..0000000 --- a/lib/components_guide/wasm/examples/examples_wasi.ex +++ /dev/null @@ -1,55 +0,0 @@ -defmodule ComponentsGuide.Wasm.Examples.WASI do - alias OrbWasmtime.Instance - - # See https://github.com/bjorn3/browser_wasi_shim/blob/3fbfb16a79d9ae6de6b034c3641746bbdc2a4184/src/wasi.ts#L96 - # See https://github.com/WebAssembly/WASI/blob/33de9e568c35424765e7b10952b181f01a724fca/legacy/preview1/docs.md#-clock_time_getid-clockid-precision-timestamp---resulttimestamp-errno - defmodule Clock do - use Orb - - # export const CLOCKID_REALTIME = 0; - # export const CLOCKID_MONOTONIC = 1; - # export const CLOCKID_PROCESS_CPUTIME_ID = 2; - # export const CLOCKID_THREAD_CPUTIME_ID = 3; - @clockid [ - :realtime, - :monotonic, - :process_cputime_id, - :thread_cputime_id - ] - |> Enum.with_index() - |> Map.new(fn {key, index} -> {key, {:i32_const, index}} end) - - wasm_import(:wasi_unstable, - clock_res_get: Orb.DSL.funcp(name: :clock_res_get, params: [I32, I32], result: I32), - clock_time_get: Orb.DSL.funcp(name: :clock_time_get, params: [I32, I64, I32], result: I32) - ) - - wasm do - end - - import Kernel - - # Write 64-bit number in little-endian format - def clock_res_get(instance, _clockid, address) do - Instance.write_i64(instance, address, 0) - end - - def clock_time_get(instance, clockid, _precision, address) do - {:i32_const, realtime} = @clockid.realtime - {:i32_const, monotonic} = @clockid.monotonic - - case clockid do - ^realtime -> - Instance.write_i64(instance, address, 0) - - ^monotonic -> - Instance.write_i64(instance, address, 0) - - _ -> - Instance.write_i64(instance, address, 0) - end - - 0 - end - end -end diff --git a/lib/components_guide/wasm/examples/podcast_feed/podcast_feed.ex b/lib/components_guide/wasm/examples/podcast_feed/podcast_feed.ex index 6035f0a..e406197 100644 --- a/lib/components_guide/wasm/examples/podcast_feed/podcast_feed.ex +++ b/lib/components_guide/wasm/examples/podcast_feed/podcast_feed.ex @@ -5,7 +5,7 @@ defmodule ComponentsGuide.Wasm.PodcastFeed do use ComponentsGuide.Wasm.PodcastFeed.XMLFormatter, as: XML require SilverOrb.Arena - Memory.pages(10) + Memory.pages(64) SilverOrb.BumpAllocator.export_alloc() diff --git a/test/components_guide/wasm/examples/color_picker_test.exs b/test/components_guide/wasm/examples/color_picker_test.exs index f9bff7b..430e8ba 100644 --- a/test/components_guide/wasm/examples/color_picker_test.exs +++ b/test/components_guide/wasm/examples/color_picker_test.exs @@ -82,7 +82,7 @@ defmodule ComponentsGuide.Wasm.Examples.ColorPickerTest do end test "LabSwatch" do - # IO.puts(LabSwatch.to_wat()) + IO.puts(LabSwatch.to_wat()) # IO.inspect(LabSwatch.to_html()) assert is_binary(LabSwatch.to_wasm()) diff --git a/test/components_guide/wasm/examples/examples_test.exs b/test/components_guide/wasm/examples/examples_test.exs index ba8b192..437fa27 100644 --- a/test/components_guide/wasm/examples/examples_test.exs +++ b/test/components_guide/wasm/examples/examples_test.exs @@ -56,7 +56,7 @@ defmodule ComponentsGuide.Wasm.ExamplesTest do assert HTTPProxy.to_wat() =~ ~S""" (module $HTTPProxy - (import "http" "get" (func $http_get (param i32) (result i32))) + (import "http" "get" (func $ComponentsGuide.Wasm.Examples.HTTPProxy.Fetch.get (param $a i32) (result i32))) (global $input_offset (export "input_offset") (mut i32) (i32.const 65536)) """ end diff --git a/test/components_guide/wasm/examples/podcast_feed_test.exs b/test/components_guide/wasm/examples/podcast_feed_test.exs index bca8b10..4d01a01 100644 --- a/test/components_guide/wasm/examples/podcast_feed_test.exs +++ b/test/components_guide/wasm/examples/podcast_feed_test.exs @@ -106,14 +106,18 @@ defmodule ComponentsGuide.Wasm.PodcastFeed.Test do # assert "Description for 2" = xml_xpath(item1, "//enclosure[1]") end - test "500 episodes" do - inst = Instance.run(PodcastFeed, wasm_imports(episodes_count: 500)) + test "12,000 episodes" do + inst = Instance.run(PodcastFeed, wasm_imports(episodes_count: 12_000)) text_xml_func = Instance.capture(inst, String, :text_xml, 0) text_xml = text_xml_func.() assert text_xml =~ ~S""" """ + + root = xml_parse(text_xml) + items = xml_xpath(root, "//item") + assert 12_000 = length(items) end defp xml_parse(xml) do diff --git a/test/components_guide/wasm/examples/podcast_feed_xml.wasm b/test/components_guide/wasm/examples/podcast_feed_xml.wasm index 34768fa..a68d868 100644 Binary files a/test/components_guide/wasm/examples/podcast_feed_xml.wasm and b/test/components_guide/wasm/examples/podcast_feed_xml.wasm differ diff --git a/test/components_guide/wasm/examples/podcast_feed_xml.wat b/test/components_guide/wasm/examples/podcast_feed_xml.wat index 1e6b740..b2ffe36 100644 --- a/test/components_guide/wasm/examples/podcast_feed_xml.wat +++ b/test/components_guide/wasm/examples/podcast_feed_xml.wat @@ -544,7 +544,7 @@ call 22 call 19 call 18) - (memory (;0;) 12) + (memory (;0;) 66) (global (;0;) (mut i32) (i32.const 65536)) (global (;1;) (mut i32) (i32.const 0)) (global (;2;) (mut i32) (i32.const 0)) diff --git a/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wasm b/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wasm index 7b0fad6..7cb37d1 100644 Binary files a/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wasm and b/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wasm differ diff --git a/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wat b/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wat index 5bf8c3b..a3d3bf9 100644 --- a/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wat +++ b/test/components_guide/wasm/examples/podcast_feed_xml_OPT.wat @@ -411,7 +411,7 @@ call 8 call 7 call 6) - (memory (;0;) 12) + (memory (;0;) 66) (global (;0;) (mut i32) (i32.const 65536)) (global (;1;) (mut i32) (i32.const 0)) (global (;2;) (mut i32) (i32.const 0))