Skip to content

Commit

Permalink
Support InputStream and OutputStream
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Feb 20, 2024
1 parent 353699e commit 7381b7e
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 33 deletions.
9 changes: 9 additions & 0 deletions projects/valkyrie-std/source/io/InputStream.vk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace package.io;


#ffi("wasi:io/streams", "input-stream")
resource class InputStream {}

#ffi("wasi:cli/stdout", "get-stderr")
function standard_input() -> InputStream {}

11 changes: 11 additions & 0 deletions projects/valkyrie-std/source/io/IoError.vk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace package.io;

#ffi("wasi:io/error", "error")
resource class IoError {}

extends IoError {
#ffi("wasi:io/error", "[method]to-debug-string")
private to_debug_string(self) -> String {

}
}
18 changes: 18 additions & 0 deletions projects/valkyrie-std/source/io/OutputStream.vk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace package.io;


#ffi("wasi:io/streams", "output-stream")
resource class OutputStream {}

extends OutputStream {
#ffi("wasi:io/streams", "write")
function write(data: String) -> void {}
}


#ffi("wasi:cli/stdout", "get-stdout")
function standard_output() -> OutputStream {}

#ffi("wasi:cli/stdout", "get-stdin")
function standard_error() -> OutputStream {}

30 changes: 30 additions & 0 deletions projects/valkyrie-std/source/io/_.vk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace package.io;

#ffi("wasi:io/error", "error")
resource class IoError {}

extends IoError {
#ffi("wasi:io/error", "[method]to-debug-string")
private to_debug_string(self) -> String {

}
}

#ffi("wasi:io/streams", "input-stream")
resource class InputStream {}

#ffi("wasi:cli/stdout", "get-stderr")
function standard_input() -> InputStream {}


#ffi("wasi:io/streams", "output-stream")
resource class OutputStream {}


#ffi("wasi:cli/stdout", "get-stdout")
function standard_output() -> OutputStream {}



#ffi("wasi:cli/stdout", "get-stdin")
function standard_error() -> OutputStream {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ structure LinearCongruential {
}

extends LinearCongruential {
constructor(seed: u64?, a: u64 = 25214903917, b: u64 = 11, c: u64 = 2^48) {
constructor(seed: u64? = null, a: u64 = 25214903917, b: u64 = 11, c: u64 = 2^48) {
self.seed = seed ?? random_seed_safe();
self.a = a;
self.b = b;
Expand Down
18 changes: 9 additions & 9 deletions projects/valkyrie-std/source/random/seeds.vk
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
namespace package.random;

🗨 Get a cryptographically secure random number as a random seed
#ffi("wasi:random", "get-insecure-random-u64")
micro random_seed_fast() : u64 {
#ffi("wasi:random/random", "get-random-u64")
micro random_seed_safe() : u64 {

}

~ Get a cryptographically secure random number as a random seed
#ffi("wasi:random", "get-random-u64")
micro random_seed_safe() : u64 {
🗨 Get a cryptographically secure random number as a random seed
#ffi("wasi:random/random", "get-insecure-random-u64")
micro random_seed_fast() : u64 {

}

🗨 Get a cryptographically secure random number as a random seed
#ffi("wasi:random", "get-random-bytes")
micro random_bytes_safe(length: u64) : Vector<u8> {
#ffi("wasi:random/random", "get-random-bytes")
micro random_bytes_safe(length: u64): Array<u8> {

}

🗨 Get a fast random number seed
#ffi("wasi:random", "get-insecure-random-bytes")
micro random_bytes_fast(length: u64) : Vector<u8> {
#ffi("wasi:random/random", "get-insecure-random-bytes")
micro random_bytes_fast(length: u64): Array<u8> {

}
30 changes: 15 additions & 15 deletions projects/valkyrie-std/source/time/Duration.vk
Original file line number Diff line number Diff line change
Expand Up @@ -48,49 +48,49 @@ extends Duration {
new Self { seconds, nanoseconds: 0 }
}
second(seconds: f64): Duration {
cast_seconds(nanoseconds, 1)
cast_seconds(nanoseconds, 1.0)
}
millisecond(milliseconds: u64): Duration {
cast_seconds(nanoseconds, 1_000)
}
millisecond(milliseconds: f64): Duration {
cast_seconds(nanoseconds, 1_000)
cast_seconds(nanoseconds, 1_000.0)
}
microsecond(microseconds: u64): Duration {
cast_seconds(nanoseconds, 1_000_000)
}
microsecond(microseconds: f64): Duration {
cast_seconds(nanoseconds, 1_000_000)
cast_seconds(nanoseconds, 1_000_000.0)
}
nanosecond(nanoseconds: u64): Duration {
cast_seconds(nanoseconds, 1_000_000_000)
}
nanosecond(nanoseconds: f64): Duration {
cast_seconds(nanoseconds, 1_000_000_000)
cast_seconds(nanoseconds, 1_000_000_000.0)
}
}

private function cast_seconds(time: u32, rate: u32): Duration {
let seconds = time.floor_divide(rate) as u64;
private micro cast_seconds(time: u32, rate: u32): Duration {
let seconds = (time // rate) as u64;
let nanoseconds = time % rate;
new Duration { seconds, nanoseconds };
}

private function cast_seconds(time: u64, rate: u64): Duration {
let seconds = time.floor_divide(rate);
let nanoseconds = (time % rate) as u32;
private micro cast_seconds(time: u64, rate: u64): Duration {
let seconds = time // rate;
let nanoseconds = (time % rate) as 64;
new Duration { seconds, nanoseconds };
}

private function cast_seconds(time: f32, rate: f32): Duration {
let seconds = time.floor_divide(rate) as u64;
let nanoseconds = (nanoseconds % rate).fraction() as u32;
private micro cast_seconds(time: f32, rate: f32): Duration {
let seconds = (time // rate) as u32;
let nanoseconds = (nanoseconds % rate).fraction() as u64;
new Duration { seconds, nanoseconds };
}

private function cast_seconds(time: f64, rate: f64): Duration {
let seconds = time.floor_divide(rate) as u64;
let nanoseconds = (nanoseconds % rate).fraction() as u32;
private micro cast_seconds(time: f64, rate: f64): Duration {
let seconds = (time // rate) as u32;
let nanoseconds = (nanoseconds % rate).fraction() as u64;
new Duration { seconds, nanoseconds };
}

4 changes: 0 additions & 4 deletions projects/valkyrie-std/source/time/time.vk
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
#external class Time {
_secs: u64,
_nanos: u32,
}
4 changes: 0 additions & 4 deletions projects/valkyrie-std/source/time/timezone.vk
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
#native class Duration {
_secs: u64,
_nanos: u32,
}

0 comments on commit 7381b7e

Please sign in to comment.