Skip to content

Commit

Permalink
🔧 Fix missing method of resource classes
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Mar 14, 2024
1 parent 2ccef73 commit 5173f8b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 30 deletions.
6 changes: 6 additions & 0 deletions projects/valkyrie-types/src/structures/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ impl Debug for ValkyrieField {
f.debug_struct("Field").field("name", &self.field_name).field("wasi", &self.wasi_alias).finish()
}
}

impl AddAssign<ValkyrieClass> for ResolveState {
fn add_assign(&mut self, rhs: ValkyrieClass) {
self.items.insert(rhs.symbol.clone(), ModuleItem::Structure(rhs));
}
}
6 changes: 0 additions & 6 deletions projects/valkyrie-types/src/structures/stage1_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ impl Hir2Mir for ClassDeclaration {
}
}

impl AddAssign<ValkyrieClass> for ResolveState {
fn add_assign(&mut self, rhs: ValkyrieClass) {
self.items.insert(rhs.symbol.clone(), ModuleItem::Structure(rhs));
}
}

impl Hir2Mir for FieldDeclaration {
type Output = ValkyrieField;
type Context = ();
Expand Down
96 changes: 76 additions & 20 deletions projects/valkyrie-types/tests/component.wat
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@
(import "wasi:io/streams" (instance $wasi:io/streams
(export $std::io::InputStream "input-stream" (type (sub resource)))
(export $std::io::OutputStream "output-stream" (type (sub resource)))
(export "[method]input-stream.read" (func
))
(export "[method]output-stream.blocking-write-and-flush" (func
))
(export "[method]flush" (func
))
(export "[method]output-stream.write" (func
))
))
(alias export $wasi:io/streams "input-stream" (type $std::io::InputStream))
(alias export $wasi:io/streams "output-stream" (type $std::io::OutputStream))
(alias export $wasi:io/streams "[method]input-stream.read" (func $std::io::InputStream::read))
(alias export $wasi:io/streams "[method]output-stream.blocking-write-and-flush" (func $std::io::OutputStream::blocking_write_and_flush))
(alias export $wasi:io/streams "[method]flush" (func $std::io::OutputStream::flush))
(alias export $wasi:io/streams "[method]output-stream.write" (func $std::io::OutputStream::write))
(import "wasi:io/error" (instance $wasi:io/error
(export $std::io::IoError "error" (type (sub resource)))
))
Expand Down Expand Up @@ -77,6 +89,26 @@
(alias export $unstable:debugger/print "print-u32" (func $std::time::print_u32))
(alias export $unstable:debugger/print "print-i64" (func $std::time::print_u64))
(alias export $unstable:debugger/print "print-u8" (func $std::time::print_u8))
(core func $std::io::InputStream::read (canon lower
(func $wasi:io/streams "[method]input-stream.read")
(memory $memory "memory")(realloc (func $memory "realloc"))
string-encoding=utf8
))
(core func $std::io::OutputStream::blocking_write_and_flush (canon lower
(func $wasi:io/streams "[method]output-stream.blocking-write-and-flush")
(memory $memory "memory")(realloc (func $memory "realloc"))
string-encoding=utf8
))
(core func $std::io::OutputStream::flush (canon lower
(func $wasi:io/streams "[method]flush")
(memory $memory "memory")(realloc (func $memory "realloc"))
string-encoding=utf8
))
(core func $std::io::OutputStream::write (canon lower
(func $wasi:io/streams "[method]output-stream.write")
(memory $memory "memory")(realloc (func $memory "realloc"))
string-encoding=utf8
))
(core func $std::io::standard_error (canon lower
(func $wasi:cli/stderr "get-stderr")
(memory $memory "memory")(realloc (func $memory "realloc"))
Expand Down Expand Up @@ -158,29 +190,53 @@
string-encoding=utf8
))
(core module $Main
(import "wasi:cli/stderr" "get-stderr" (func $std::io::standard_error))
(import "wasi:cli/stdin" "get-stdin" (func $std::io::standard_input))
(import "wasi:cli/stdout" "get-stdout" (func $std::io::standard_output))
(import "wasi:random/insecure" "get-insecure-random-bytes" (func $std::random::fast_random_seed))
(import "wasi:random/random" "get-random-u64" (func $std::random::safe_random_seed))
(import "wasi:clock/monotonic-clock" "now" (func $std::time::now))
(import "unstable:debugger/print" "print-bool" (func $std::time::print_bool))
(import "unstable:debugger/print" "print-char" (func $std::time::print_char))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i16))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i32))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i64))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i8))
(import "unstable:debugger/print" "print-u16" (func $std::time::print_u16))
(import "unstable:debugger/print" "print-u32" (func $std::time::print_u32))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_u64))
(import "unstable:debugger/print" "print-u8" (func $std::time::print_u8))




(import "wasi:io/streams" "[method]input-stream.read" (func $std::io::InputStream::read
))
(import "wasi:io/streams" "[method]output-stream.blocking-write-and-flush" (func $std::io::OutputStream::blocking_write_and_flush
))
(import "wasi:io/streams" "[method]flush" (func $std::io::OutputStream::flush
))
(import "wasi:io/streams" "[method]output-stream.write" (func $std::io::OutputStream::write
))
(import "wasi:cli/stderr" "get-stderr" (func $std::io::standard_error
))
(import "wasi:cli/stdin" "get-stdin" (func $std::io::standard_input
))
(import "wasi:cli/stdout" "get-stdout" (func $std::io::standard_output
))
(import "wasi:random/insecure" "get-insecure-random-bytes" (func $std::random::fast_random_seed
))
(import "wasi:random/random" "get-random-u64" (func $std::random::safe_random_seed
))
(import "wasi:clock/monotonic-clock" "now" (func $std::time::now
))
(import "unstable:debugger/print" "print-bool" (func $std::time::print_bool
))
(import "unstable:debugger/print" "print-char" (func $std::time::print_char
))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i16
))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i32
))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i64
))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_i8
))
(import "unstable:debugger/print" "print-u16" (func $std::time::print_u16
))
(import "unstable:debugger/print" "print-u32" (func $std::time::print_u32
))
(import "unstable:debugger/print" "print-i64" (func $std::time::print_u64
))
(import "unstable:debugger/print" "print-u8" (func $std::time::print_u8
))
)
(core instance $main (instantiate $Main
(with "wasi:io/streams" (instance
(export "[method]input-stream.read" (func $std::io::InputStream::read))
(export "[method]output-stream.blocking-write-and-flush" (func $std::io::OutputStream::blocking_write_and_flush))
(export "[method]flush" (func $std::io::OutputStream::flush))
(export "[method]output-stream.write" (func $std::io::OutputStream::write))
))
(with "wasi:io/error" (instance
))
Expand Down
2 changes: 1 addition & 1 deletion projects/valkyrie-types/tests/source/io/InputStream.vk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace package.io

#import("wasi:io/streams", "input-stream")
class InputStream {
#ffi("wasi:io/streams", "[method]input-stream.read")
#import("wasi:io/streams", "[method]input-stream.read")
read(self, len: u64) -> Result< Array< i8 >, StreamError >;
}

Expand Down
6 changes: 3 additions & 3 deletions projects/valkyrie-types/tests/source/io/OutputStream.vk
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace package.io

#import("wasi:io/streams", "output-stream")
class OutputStream {
#ffi("wasi:io/streams", "[method]output-stream.write")
#import("wasi:io/streams", "[method]output-stream.write")
write(mut self, contents: List< u8 >) -> Result< (), StreamError >;

#ffi("wasi:io/streams", "[method]flush")
#import("wasi:io/streams", "[method]flush")
flush(mut self) -> Result< (), StreamError >;

#ffi("wasi:io/streams", "[method]output-stream.blocking-write-and-flush")
#import("wasi:io/streams", "[method]output-stream.blocking-write-and-flush")
blocking_write_and_flush(self, contents: List< u8 >) -> Result< (), StreamError >;
}

Expand Down

0 comments on commit 5173f8b

Please sign in to comment.