Skip to content

Commit

Permalink
Load the wasi definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed May 25, 2024
1 parent cf40b9e commit 47744ad
Show file tree
Hide file tree
Showing 21 changed files with 3,984 additions and 30 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/modules/valkyrie.wasi.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions packages/valkyrie-esoteric/source/effect/effect.valkyrie
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
↯effect⟨T⟩
class DivideByZero⟨T⟩ {
dividend: T
builder(dividend: T) {
this.dividend = dividend
}

extract(self) -> (dividend: T) {
(dividend = self.dividend)
}
}

imply⟨T⟩ DivideByZero⟨T⟩: Effect {
type Resume = T,
}



Expand All @@ -25,18 +11,3 @@ loop {
↸unroll(4)
}


function resume_div(a: u32, b: u32) -> i32 {
let good: u32 = catch a / b {
case DivideZero(0): resume -2u32
case DivideZero(a): return -1i32
}
good as i32
}

resume_div(9, 9) # +1, by noraml return
resume_div(0, 9) # 0, by noraml return
resume_div(9, 0) # -1, by early return
resume_div(0, 0) # -2, by resume


Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

class DivideByZero⟨T⟩ {
dividend: T
constructor(dividend: T) {
this.dividend = dividend
}
extractor(self) -> (dividend: T) {
(dividend = self.dividend, )
}
}

imply⟨T⟩ DivideByZero⟨T⟩: Effect + Exception {
type Resume = T,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace! package.primitive;
6 changes: 5 additions & 1 deletion packages/valkyrie-standard/test/auth.vk
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ let b: b | b = 123.4

micro a(a: f32, b) {

}
}




16 changes: 16 additions & 0 deletions packages/valkyrie-standard/test/resume/arithmetic.vk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function resume_div(a: u32, b: u32) -> i32 {
let good: u32 = catch a / b {
case DivideZero(0): resume -2u32
case DivideZero(a): return -1i32
}
good as i32
}


test function test_resume_div() {
resume_div(9, 9) # +1, by noraml return
resume_div(0, 9) # 0, by noraml return
resume_div(9, 0) # -1, by early return
resume_div(0, 0) # -2, by resume
}

181 changes: 181 additions & 0 deletions packages/valkyrie-wasi/source/wasi/blobstore.vk
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
alias typus InputStream = InputStream;
alias typus OutputStream = OutputStream;
#? name of a container, a collection of objects.
#? The container name may be any valid UTF-8 string.
alias typus ContainerName = utf8;
#? name of an object within a container
#? The object name may be any valid UTF-8 string.
alias typus ObjectName = utf8;
#? TODO: define timestamp to include seconds since
#? Unix epoch and nanoseconds
#? https://github.com/WebAssembly/wasi-blob-store/issues/7
alias typus Timestamp = u64;
#? size of an object, in bytes
alias typus ObjectSize = u64;
alias typus Error = utf8;
#? information about a container
class ContainerMetadata {
#? the container's name
name: utf8,
#? date and time container was created
created_at: u64,
}

#? information about an object
class ObjectMetadata {
#? the object's name
name: utf8,
#? the object's parent container
container: utf8,
#? date and time the object was created
created_at: u64,
#? size of the object, in bytes
size: u64,
}

#? identifier for an object that includes its container name
class ObjectId {
container: utf8,
object: utf8,
}

#? A data is the data stored in a data blob. The value can be of any type
#? that can be represented in a byte array. It provides a way to write the value
#? to the output-stream defined in the `wasi-io` interface.
#? Soon: switch to `resource value { ... }`
↯import("wasi:blobstore/types", "outgoing-value")
resource class OutgoingValue {
↯import("wasi:blobstore/types", "[static]outgoing-value.new-outgoing-value")
new_outgoing_value() -> OutgoingValue { }

↯import("wasi:blobstore/types", "[method]outgoing-value.outgoing-value-write-body")
outgoing_value_write_body(self) -> Result<OutputStream, ()> { }

}
#? A incoming-value is a wrapper around a value. It provides a way to read the value
#? from the input-stream defined in the `wasi-io` interface.
#?
#? The incoming-value provides two ways to consume the value:
#? 1. `incoming-value-consume-sync` consumes the value synchronously and returns the
#? value as a list of bytes.
#? 2. `incoming-value-consume-async` consumes the value asynchronously and returns the
#? value as an input-stream.
#? Soon: switch to `resource incoming-value { ... }`
↯import("wasi:blobstore/types", "incoming-value")
resource class IncomingValue {
↯import("wasi:blobstore/types", "[method]incoming-value.incoming-value-consume-sync")
incoming_value_consume_sync(self) -> Result<Array<u8>, utf8> { }

↯import("wasi:blobstore/types", "[method]incoming-value.incoming-value-consume-async")
incoming_value_consume_async(self) -> Result<InputStream, utf8> { }

↯import("wasi:blobstore/types", "[method]incoming-value.size")
size(self) -> u64 { }

}
alias typus IncomingValueAsyncBody = InputStream;
alias typus IncomingValueSyncBody = Array<u8>;
alias typus InputStream = InputStream;
alias typus OutputStream = OutputStream;
alias typus ContainerMetadata = ContainerMetadata;
alias typus Error = utf8;
alias typus IncomingValue = IncomingValue;
alias typus ObjectMetadata = ObjectMetadata;
alias typus ObjectName = utf8;
alias typus OutgoingValue = OutgoingValue;
#? this defines the `container` resource
↯import("wasi:blobstore/container", "container")
resource class Container {
#? returns container name
↯import("wasi:blobstore/container", "[method]container.name")
name(self) -> Result<utf8, utf8> { }

#? returns container metadata
↯import("wasi:blobstore/container", "[method]container.info")
info(self) -> Result<ContainerMetadata, utf8> { }

#? retrieves an object or portion of an object, as a resource.
#? Start and end offsets are inclusive.
#? Once a data-blob resource has been created, the underlying bytes are held by the blobstore service for the lifetime
#? of the data-blob resource, even if the object they came from is later deleted.
↯import("wasi:blobstore/container", "[method]container.get-data")
get_data(self, name: utf8, start: u64, end: u64) -> Result<IncomingValue, utf8> { }

#? creates or replaces an object with the data blob.
↯import("wasi:blobstore/container", "[method]container.write-data")
write_data(self, name: utf8, data: &OutgoingValue) -> Result<(), utf8> { }

#? returns list of objects in the container. Order is undefined.
↯import("wasi:blobstore/container", "[method]container.list-objects")
list_objects(self) -> Result<StreamObjectNames, utf8> { }

#? deletes object.
#? does not return error if object did not exist.
↯import("wasi:blobstore/container", "[method]container.delete-object")
delete_object(self, name: utf8) -> Result<(), utf8> { }

#? deletes multiple objects in the container
↯import("wasi:blobstore/container", "[method]container.delete-objects")
delete_objects(self, names: Array<utf8>) -> Result<(), utf8> { }

#? returns true if the object exists in this container
↯import("wasi:blobstore/container", "[method]container.has-object")
has_object(self, name: utf8) -> Result<bool, utf8> { }

#? returns metadata for the object
↯import("wasi:blobstore/container", "[method]container.object-info")
object_info(self, name: utf8) -> Result<ObjectMetadata, utf8> { }

#? removes all objects within the container, leaving the container empty.
↯import("wasi:blobstore/container", "[method]container.clear")
clear(self) -> Result<(), utf8> { }

}
#? this defines the `stream-object-names` resource which is a representation of stream<object-name>
↯import("wasi:blobstore/container", "stream-object-names")
resource class StreamObjectNames {
#? reads the next number of objects from the stream
#?
#? This function returns the list of objects read, and a boolean indicating if the end of the stream was reached.
↯import("wasi:blobstore/container", "[method]stream-object-names.read-stream-object-names")
read_stream_object_names(self, len: u64) -> Result<(Array<utf8>, bool), utf8> { }

#? skip the next number of objects in the stream
#?
#? This function returns the number of objects skipped, and a boolean indicating if the end of the stream was reached.
↯import("wasi:blobstore/container", "[method]stream-object-names.skip-stream-object-names")
skip_stream_object_names(self, num: u64) -> Result<(u64, bool), utf8> { }

}
alias typus Container = Container;
alias typus Error = utf8;
alias typus ContainerName = utf8;
alias typus ObjectId = ObjectId;
#? creates a new empty container
↯import("wasi:blobstore/blobstore", "create-container")
micro create_container(name: utf8) -> Result<Container, utf8> { }

#? retrieves a container by name
↯import("wasi:blobstore/blobstore", "get-container")
micro get_container(name: utf8) -> Result<Container, utf8> { }

#? deletes a container and all objects within it
↯import("wasi:blobstore/blobstore", "delete-container")
micro delete_container(name: utf8) -> Result<(), utf8> { }

#? returns true if the container exists
↯import("wasi:blobstore/blobstore", "container-exists")
micro container_exists(name: utf8) -> Result<bool, utf8> { }

#? copies (duplicates) an object, to the same or a different container.
#? returns an error if the target container does not exist.
#? overwrites destination object if it already existed.
↯import("wasi:blobstore/blobstore", "copy-object")
micro copy_object(src: ObjectId, dest: ObjectId) -> Result<(), utf8> { }

#? moves or renames an object, to the same or a different container
#? returns an error if the destination container does not exist.
#? overwrites destination object if it already existed.
↯import("wasi:blobstore/blobstore", "move-object")
micro move_object(src: ObjectId, dest: ObjectId) -> Result<(), utf8> { }

66 changes: 66 additions & 0 deletions packages/valkyrie-wasi/source/wasi/cli.vk
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#? Get the POSIX-style environment variables.
#?
#? Each environment variable is provided as a pair of string variable names
#? and string value.
#?
#? Morally, these are a value import, but until value imports are available
#? in the component model, this import function should return the same
#? values each time it is called.
↯import("wasi:cli/environment", "get-environment")
micro get_environment() -> Array<(utf8, utf8)> { }

#? Get the POSIX-style arguments to the program.
↯import("wasi:cli/environment", "get-arguments")
micro get_arguments() -> Array<utf8> { }

#? Return a path that programs should use as their initial current working
#? directory, interpreting `.` as shorthand for this.
↯import("wasi:cli/environment", "initial-cwd")
micro initial_cwd() -> utf8? { }

#? Exit the current instance and any linked instances.
↯import("wasi:cli/exit", "exit")
micro exit(status: Result<(), ()>) -> () { }

#? Run the program.
↯import("wasi:cli/run", "run")
micro run() -> Result<(), ()> { }

alias typus InputStream = InputStream;
↯import("wasi:cli/stdin", "get-stdin")
micro get_stdin() -> InputStream { }

alias typus OutputStream = OutputStream;
↯import("wasi:cli/stdout", "get-stdout")
micro get_stdout() -> OutputStream { }

alias typus OutputStream = OutputStream;
↯import("wasi:cli/stderr", "get-stderr")
micro get_stderr() -> OutputStream { }

#? The input side of a terminal.
↯import("wasi:cli/terminal-input", "terminal-input")
resource class TerminalInput {
}
#? The output side of a terminal.
↯import("wasi:cli/terminal-output", "terminal-output")
resource class TerminalOutput {
}
alias typus TerminalInput = TerminalInput;
#? If stdin is connected to a terminal, return a `terminal-input` handle
#? allowing further interaction with it.
↯import("wasi:cli/terminal-stdin", "get-terminal-stdin")
micro get_terminal_stdin() -> TerminalInput? { }

alias typus TerminalOutput = TerminalOutput;
#? If stdout is connected to a terminal, return a `terminal-output` handle
#? allowing further interaction with it.
↯import("wasi:cli/terminal-stdout", "get-terminal-stdout")
micro get_terminal_stdout() -> TerminalOutput? { }

alias typus TerminalOutput = TerminalOutput;
#? If stderr is connected to a terminal, return a `terminal-output` handle
#? allowing further interaction with it.
↯import("wasi:cli/terminal-stderr", "get-terminal-stderr")
micro get_terminal_stderr() -> TerminalOutput? { }

Loading

0 comments on commit 47744ad

Please sign in to comment.