Skip to content

Commit

Permalink
Update to new comment syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Jun 17, 2024
1 parent 232611b commit b92753d
Show file tree
Hide file tree
Showing 21 changed files with 3,235 additions and 3,216 deletions.
6 changes: 3 additions & 3 deletions projects/valkyrie-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ documentation = "https://docs.rs/valkyrie-ffi"
license = "MPL-2.0"

[dependencies]
nyar-wasm = "0.0.6"
nyar-wasm = "0.0.7"
anyhow = "1.0.83"
wit-component = "0.207.0"
wit-parser = "0.207.0"
wit-component = "0.208.1"
wit-parser = "0.208.1"
tracing = "0.1.40"
convert_case = "0.6.0"

Expand Down
6 changes: 3 additions & 3 deletions projects/valkyrie-ffi/src/imports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ impl ValkyrieFFI {
resolved.push_dir(directory.as_ref())?;
Ok(Self { cache: resolved })
}
pub fn new_wasm(binary: &[u8]) -> anyhow::Result<Self> {
pub fn new_wasm(binary: &[u8], alias: &str) -> anyhow::Result<Self> {
let wasm = wit_component::decode(binary)?;
println!("decoding");
match wasm {
DecodedWasm::WitPackage(resolved, id) => {
println!("package: {:?}", id);
println!("package `{alias}`: {:?}", id);
Ok(Self { cache: resolved })
}
DecodedWasm::Component(resolved, id) => {
println!("world: {:?}", id);
println!("world `{alias}`: {:?}", id);
Ok(Self { cache: resolved })
}
}
Expand Down
16 changes: 8 additions & 8 deletions projects/valkyrie-ffi/src/imports/visit_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl ValkyrieFFI {
fn export_resource<'a, W: Write>(&self, file: &mut W, ctx: TypeContext<'a>) -> std::fmt::Result {
match &ctx.def.name {
Some(wasi_name) => {
writeln!(file, "#import(\"{}\", \"{}\")", ctx.namespace, wasi_name)?;
writeln!(file, "import(\"{}\", \"{}\")", ctx.namespace, wasi_name)?;
writeln!(file, "resource class {} {{", wasi_name.to_case(Case::UpperCamel))?;
for function in ctx.interface.functions.values() {
function
Expand Down Expand Up @@ -85,7 +85,7 @@ impl WriteDefine for Docs {
for _ in 0..ctx {
w.write_str(" ")?
}
writeln!(w, "? {}", line)?
writeln!(w, "#? {}", line)?
}
Ok(())
}
Expand All @@ -112,10 +112,10 @@ impl WriteDefine for Enum {

fn write_define<'a, W: Write>(&self, w: &mut W, ctx: Self::Context<'a>) -> std::fmt::Result {
// Name is not required
writeln!(w, "enumerate {} {{", ctx.wasi_name.to_case(Case::UpperCamel))?;
writeln!(w, "enums {} {{", ctx.wasi_name.to_case(Case::UpperCamel))?;
for variant in self.cases.iter() {
variant.docs.write_define(w, 1)?;
writeln!(w, " #export(\"{}\")", variant.name)?;
writeln!(w, " export(\"{}\")", variant.name)?;
writeln!(w, " {},", variant.name.to_case(Case::UpperCamel))?;
}
w.write_str("}\n\n")
Expand All @@ -130,7 +130,7 @@ impl WriteDefine for Flags {
w.write_str("{\n")?;
for field in self.flags.iter() {
field.docs.write_define(w, 1)?;
writeln!(w, " #export(\"{}\")", field.name)?;
writeln!(w, " export(\"{}\")", field.name)?;
writeln!(w, " {},", field.name.to_case(Case::Snake))?;
}
w.write_str("}\n\n")
Expand All @@ -143,7 +143,7 @@ impl WriteDefine for Variant {
w.write_str("{\n")?;
for variant in self.cases.iter() {
variant.docs.write_define(w, 1)?;
writeln!(w, " #export(\"{}\")", variant.name)?;
writeln!(w, " export(\"{}\")", variant.name)?;
write!(w, " {}", variant.name.to_case(Case::UpperCamel))?;
match variant.ty {
Some(s) => {
Expand All @@ -165,14 +165,14 @@ impl WriteReference for Results {
fn write_reference<'a, W: Write>(&self, w: &mut W, ctx: Self::Context<'a>) -> std::fmt::Result {
match self {
Self::Named(outputs) => {
w.write_str(" -> (")?;
w.write_str(": (")?;
for _ in outputs {
unimplemented!()
}
w.write_str(")")
}
Self::Anon(v) => {
w.write_str(" -> ")?;
w.write_str(": ")?;
v.write_reference(w, ctx)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl WriteDefine for Function {
impl ValkyrieFFI {
fn export_free<W: Write>(&self, function: &Function, namespace: &str, w: &mut W) -> std::fmt::Result {
function.docs.write_define(w, 0)?;
writeln!(w, "#import(\"{}\", \"{}\")", namespace, function.name)?;
writeln!(w, "import(\"{}\", \"{}\")", namespace, function.name)?;
write!(w, "micro {}(", function.name.to_case(Case::Snake))?;
for (i, (key, ty)) in function.params.iter().enumerate() {
if i != 0 {
Expand All @@ -54,7 +54,7 @@ impl ValkyrieFFI {
fn export_method<W: Write>(&self, function: &Function, head: &str, namespace: &str, w: &mut W) -> std::fmt::Result {
function.docs.write_define(w, 1)?;

writeln!(w, " #import(\"{}\", \"{}\")", namespace, function.name)?;
writeln!(w, " import(\"{}\", \"{}\")", namespace, function.name)?;
write!(w, " {}(self", function.name.trim_start_matches(&head).to_case(Case::Snake))?;
for (key, ty) in function.params.iter().skip(1) {
write!(w, ", {}: ", self.parameter_name(key))?;
Expand All @@ -66,7 +66,7 @@ impl ValkyrieFFI {
}
fn export_static<W: Write>(&self, function: &Function, head: &str, namespace: &str, w: &mut W) -> std::fmt::Result {
function.docs.write_define(w, 1)?;
writeln!(w, " #import(\"{}\", \"{}\")", namespace, function.name)?;
writeln!(w, " import(\"{}\", \"{}\")", namespace, function.name)?;
write!(w, " {}(", function.name.trim_start_matches(&head).to_case(Case::Snake))?;
for (i, (key, ty)) in function.params.iter().enumerate() {
if i != 0 {
Expand Down
10 changes: 4 additions & 6 deletions projects/valkyrie-ffi/tests/homestar/host.vk
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
namespace host;

class Time {
seconds: u64,
milliseconds: u32,
nanoseconds: u32,
}

⍝? Get current time in sub-seconds.
#import("homestar:host/helpers", "get-current-time")
micro get_current_time() -> Time {}
import("homestar:host/helpers", "get-current-time")
micro get_current_time() -> Time { }

⍝? Basic `print` helper.
#import("homestar:host/helpers", "print")
micro print(msg: Utf8Text) -> () {}
import("homestar:host/helpers", "print")
micro print(msg: utf8) -> () { }

8 changes: 3 additions & 5 deletions projects/valkyrie-ffi/tests/homestar/legion.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"name": "homestar.host",
"version": "0.0.1",
"description": "Legion",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jonathan Hersh",
"description": "Legion",
"binary": "file://c/real/path/sha.256.wasm",
"license": "MIT",
"dependencies": {
}
}
}
2 changes: 1 addition & 1 deletion projects/valkyrie-ffi/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ fn load_deps() {
fn load_wasm() {
let here = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests");
let file = std::fs::read(here.join("host.wasm")).unwrap();
let resolved = ValkyrieFFI::new_wasm(&file).unwrap();
let resolved = ValkyrieFFI::new_wasm(&file, "homestar").unwrap();
resolved.generate(here).unwrap();
}
23 changes: 23 additions & 0 deletions projects/valkyrie-ffi/tests/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Currently, `wasmtime`'s error in wat text files are based on the compilation offset.

When an error occurs, it is very confusing where the error occurred.

I would like to attach some source language location information to point out the error location.

Similar to:

```wat
;; @url: file://path/position.wasm:line:column
(type $test-type (externref))
;; @url: file://path/position.wasm:offset
(func $test-function
;; @file: main.rs:12:24
(block $test-block
)
)
```

`binaryen` supports similar features
like: https://github.com/WebAssembly/binaryen/blob/921644ca65afbafb84fb82d58dacc4a028e2d720/test/lit/debug/full.wat#L49-L64

Loading

0 comments on commit b92753d

Please sign in to comment.