From 5173f8b105e2895f91dde7d1e1664a3d3e956511 Mon Sep 17 00:00:00 2001 From: Aster Date: Wed, 13 Mar 2024 15:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix=20missing=20method=20of=20re?= =?UTF-8?q?source=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../valkyrie-types/src/structures/display.rs | 6 ++ .../src/structures/stage1_mir.rs | 6 -- projects/valkyrie-types/tests/component.wat | 96 +++++++++++++++---- .../tests/source/io/InputStream.vk | 2 +- .../tests/source/io/OutputStream.vk | 6 +- 5 files changed, 86 insertions(+), 30 deletions(-) diff --git a/projects/valkyrie-types/src/structures/display.rs b/projects/valkyrie-types/src/structures/display.rs index edd7c119..15cbe7a8 100644 --- a/projects/valkyrie-types/src/structures/display.rs +++ b/projects/valkyrie-types/src/structures/display.rs @@ -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 for ResolveState { + fn add_assign(&mut self, rhs: ValkyrieClass) { + self.items.insert(rhs.symbol.clone(), ModuleItem::Structure(rhs)); + } +} diff --git a/projects/valkyrie-types/src/structures/stage1_mir.rs b/projects/valkyrie-types/src/structures/stage1_mir.rs index 329102b0..e17f7fee 100644 --- a/projects/valkyrie-types/src/structures/stage1_mir.rs +++ b/projects/valkyrie-types/src/structures/stage1_mir.rs @@ -42,12 +42,6 @@ impl Hir2Mir for ClassDeclaration { } } -impl AddAssign 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 = (); diff --git a/projects/valkyrie-types/tests/component.wat b/projects/valkyrie-types/tests/component.wat index ef5550c8..29ee6aac 100644 --- a/projects/valkyrie-types/tests/component.wat +++ b/projects/valkyrie-types/tests/component.wat @@ -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))) )) @@ -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")) @@ -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 )) diff --git a/projects/valkyrie-types/tests/source/io/InputStream.vk b/projects/valkyrie-types/tests/source/io/InputStream.vk index d50523bb..56797a5b 100644 --- a/projects/valkyrie-types/tests/source/io/InputStream.vk +++ b/projects/valkyrie-types/tests/source/io/InputStream.vk @@ -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 >; } diff --git a/projects/valkyrie-types/tests/source/io/OutputStream.vk b/projects/valkyrie-types/tests/source/io/OutputStream.vk index 2c5e8964..675aa4b8 100644 --- a/projects/valkyrie-types/tests/source/io/OutputStream.vk +++ b/projects/valkyrie-types/tests/source/io/OutputStream.vk @@ -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 >; }